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

1import { AgentBase } from '@signalwire/sdk';
2
3const agent = new AgentBase({ name: 'assistant', route: '/assistant' });
4agent.enableMcpServer();
5
6// Manually invoke (normally handled by the /mcp endpoint)
7const response = await agent.handleMcpRequest({
8 jsonrpc: '2.0',
9 id: 1,
10 method: 'tools/list',
11 params: {},
12});
13console.log(response);