Function: createMcpRouter()
createMcpRouter(
server,options):Router<DefaultState,DefaultContext>
Defined in: index.ts:60
Creates a Koa router configured to handle MCP protocol requests
Parameters
server
McpServer
The MCP server instance with registered tools and resources
options
McpRouterOptions = {}
Configuration options for the router
Returns
Router<DefaultState, DefaultContext>
A Koa Router instance configured for MCP
Example
import { App, bodyParser } from '@ttoss/http-server';
import { createMcpRouter, Server as McpServer, z } from '@ttoss/http-server-mcp';
const mcpServer = new McpServer({
name: 'my-server',
version: '1.0.0',
});
mcpServer.registerTool(
'hello',
{
description: 'Say hello',
inputSchema: { name: z.string() },
},
async ({ name }) => ({
content: [{ type: 'text', text: `Hello, ${name}!` }],
})
);
const app = new App();
app.use(bodyParser());
const mcpRouter = createMcpRouter(mcpServer);
app.use(mcpRouter.routes());
app.listen(3000);