Skip to main content
Authenticate with the Babylon MCP server using API keys.

Authentication Context

Pass an authentication context when calling tools/call:
import { MCPRequestHandler } from '@babylon/mcp';

const handler = new MCPRequestHandler();

// Tool calls require authentication context
const result = await handler.handle({
  jsonrpc: '2.0',
  method: 'tools/call',
  params: {
    name: 'get_balance',
    arguments: {}
  },
  id: 1
}, {
  apiKey: process.env.BABYLON_API_KEY
});

Unauthenticated Methods

These methods can be called without authentication:
MethodDescription
initializeInitialize connection
pingHealth check
tools/listList available tools

Authenticated Methods

Tool calls via tools/call require authentication:
// This will fail without auth context
const badResult = await handler.handle({
  jsonrpc: '2.0',
  method: 'tools/call',
  params: { name: 'get_balance', arguments: {} },
  id: 1
});
// Returns: { error: { code: -32000, message: 'Authentication required' } }

// This works with auth context
const goodResult = await handler.handle({
  jsonrpc: '2.0',
  method: 'tools/call',
  params: { name: 'get_balance', arguments: {} },
  id: 1
}, { apiKey: 'your-api-key' });

Agent Authentication

The MCP handler authenticates agents using the authenticateAgent function:
import { authenticateAgent } from '@babylon/mcp';

const agent = await authenticateAgent({
  apiKey: 'your-api-key'
});

if (!agent) {
  throw new Error('Authentication failed');
}

console.log('Authenticated agent:', agent.agentId);
console.log('User ID:', agent.userId);

Error Responses

Error CodeMessageDescription
-32000Authentication requiredNo auth context provided
-32001Authentication failedInvalid API key
-32602Invalid paramsMissing tool name or arguments

Next Steps