Function: registerOpenApiTools()
registerOpenApiTools(
args):ToolDefinition[]
Defined in: registerOpenApiTools.ts:74
Derives MCP tools from OpenAPI document(s) and registers each on the given
MCP server. Every tool's handler resolves the incoming camelCase args into a
concrete HTTP request and delegates execution to callApi.
Parameters
| Parameter | Type |
|---|---|
args | RegisterOpenApiToolsArgs |
Returns
The list of ToolDefinition that were registered.
Example
import { McpServer } from '@ttoss/http-server-mcp';
import { registerOpenApiTools } from '@ttoss/http-server-mcp-openapi';
const server = new McpServer({ name: 'my-api', version: '1.0.0' });
registerOpenApiTools({
server,
spec: myOpenApiDocument,
callApi: async ({ method, url, body }) => {
const res = await fetch(`https://api.example.com${url}`, {
method,
headers: { 'Content-Type': 'application/json' },
body: body ? JSON.stringify(body) : undefined,
});
return res.json();
},
});