loading…
Search for a command to run...
loading…
Production-ready library for converting OpenAPI specifications into MCP tool definitions
Production-ready library for converting OpenAPI specifications into MCP tool definitions
Convert OpenAPI specifications into MCP tool definitions with automatic parameter conflict resolution
npm version License: Apache 2.0 TypeScript Node.js
When converting OpenAPI specs to MCP tools, you hit parameter conflicts -- the same name appears in different locations (path, query, body). This library resolves them automatically and gives you an explicit mapper for building HTTP requests.
The Problem:
paths:
/users/{id}:
post:
parameters:
- name: id # path
in: path
requestBody:
content:
application/json:
schema:
properties:
id: # body -- CONFLICT!
type: string
The Solution:
{
inputSchema: {
properties: {
pathId: { type: "string" }, // Automatically renamed
bodyId: { type: "string" } // Automatically renamed
}
},
mapper: [
{ inputKey: "pathId", type: "path", key: "id" },
{ inputKey: "bodyId", type: "body", key: "id" }
]
}
Now you know exactly how to build the HTTP request.
$ref resolutionx-frontmcp extensionnpm install mcp-from-openapi
# or
yarn add mcp-from-openapi
# or
pnpm add mcp-from-openapi
import { OpenAPIToolGenerator } from 'mcp-from-openapi';
// Load an OpenAPI spec
const generator = await OpenAPIToolGenerator.fromURL('https://api.example.com/openapi.json');
// Generate MCP tools
const tools = await generator.generateTools();
// Each tool has everything you need
tools.forEach((tool) => {
console.log(tool.name); // "createUser"
console.log(tool.inputSchema); // Combined schema for all params
console.log(tool.outputSchema); // Response schema
console.log(tool.mapper); // How to build the HTTP request
console.log(tool.metadata); // Auth, servers, tags, etc.
});
The mapper tells you how to convert tool inputs into an HTTP request:
function buildRequest(tool: McpOpenAPITool, input: Record<string, any>) {
let path = tool.metadata.path;
const query = new URLSearchParams();
const headers: Record<string, string> = {};
let body: Record<string, any> | undefined;
for (const m of tool.mapper) {
const value = input[m.inputKey];
if (value === undefined) continue;
switch (m.type) {
case 'path':
path = path.replace(`{${m.key}}`, encodeURIComponent(value));
break;
case 'query':
query.set(m.key, String(value));
break;
case 'header':
headers[m.key] = String(value);
break;
case 'body':
if (!body) body = {};
body[m.key] = value;
break;
}
}
const baseUrl = tool.metadata.servers?.[0]?.url ?? '';
const qs = query.toString();
return {
url: `${baseUrl}${path}${qs ? '?' + qs : ''}`,
method: tool.metadata.method.toUpperCase(),
headers,
body: body ? JSON.stringify(body) : undefined,
};
}
| Document | Description |
|---|---|
| Getting Started | Loading specs, generating tools, building requests |
| Configuration | LoadOptions, GenerateOptions, RefResolutionOptions |
| Parameter Conflicts | How conflict detection and resolution works |
| Response Schemas | Output schemas, status codes, oneOf unions |
| Security | SecurityResolver, all auth types, custom resolvers |
| SSRF Prevention | Ref resolution security, blocked IPs and hosts |
| Format Resolution | Format-to-schema enrichment (uuid, date-time, email, int32, etc.) |
| Naming Strategies | Custom tool naming and conflict resolvers |
| SchemaBuilder | JSON Schema utility methods |
| Error Handling | Error classes, context, and patterns |
| x-frontmcp Extension | Custom OpenAPI extension for MCP annotations |
| API Reference | Complete types, interfaces, and exports |
| Examples | MCP server, Zod, filtering, security, and more |
| Architecture | System overview, data flow, design patterns |
zod@^4.0.0Contributions are welcome! Please see our issues page.
Добавь это в claude_desktop_config.json и перезапусти Claude Desktop.
{
"mcpServers": {
"from-openapi": {
"command": "npx",
"args": [
"-y",
"mcp-from-openapi"
]
}
}
}