Skip to main content

Function: openApiToTools()

openApiToTools(args): OpenApiTool[]

Defined in: http-server-mcp-openapi/src/openApiToTools.ts:182

Derives MCP tools from OpenAPI document(s). Each tool's handler resolves the incoming args into a concrete HTTP request and delegates execution to callApi. Register the result with registerTools from @ttoss/http-server-mcp — one MCP tool each, or deferred.

Parameters​

ParameterType
argsOpenApiToToolsArgs

Returns​

OpenApiTool[]

One OpenApiTool per translatable operation.

Example​

import { McpServer, registerTools } from '@ttoss/http-server-mcp';
import { openApiToTools } from '@ttoss/http-server-mcp-openapi';

const server = new McpServer({ name: 'my-api', version: '1.0.0' });

const tools = openApiToTools({
spec: myOpenApiDocument,
callApi: async ({ method, url, body, headers }) => {
const res = await fetch(`https://api.example.com${url}`, {
method,
headers: { ...headers, 'Content-Type': 'application/json' },
body: body ? JSON.stringify(body) : undefined,
});
return res.json();
},
});

registerTools({ server, tools });