handleMcpRequest

View as MarkdownOpen in Claude

Handle an incoming MCP JSON-RPC 2.0 request. This method is called automatically by the /mcp endpoint when enableMcpServer() is active. It supports the initialize, notifications/initialized, tools/list, tools/call, and ping methods.

You typically do not need to call this directly — it is invoked by the Hono route handler.

Parameters

body
Record<string, unknown>Required

The parsed JSON-RPC 2.0 request body, containing jsonrpc, method, params, and id fields.

Returns

Promise<Record<string, unknown>> — The JSON-RPC 2.0 response object.

Example

import { AgentBase } from '@signalwire/sdk';
const agent = new AgentBase({ name: 'assistant', route: '/assistant' });
agent.enableMcpServer();
// Manually invoke (normally handled by the /mcp endpoint)
const response = await agent.handleMcpRequest({
jsonrpc: '2.0',
id: 1,
method: 'tools/list',
params: {},
});
console.log(response);