OPENAPI Specifications => MCP (Model Context Protocol) Tools

by 2013xile

19 stars
456 downloads
Not rated
GitHub

About

A utility library that converts OpenAPI specifications into MCP tools, enabling faster development of MCP servers based on OpenAPI definitions. It is designed for developers who want to expose REST APIs as tools in the Model Context Protocol ecosystem.

Details

Author
2013xile
GitHub stars
19
Downloads
456
Categories
Other, API

- Converts OpenAPI specs into MCP tool definitions
- Supports custom base URL and HTTP client
- Provides both tool list and tool caller functions
- Works seamlessly with StdioServerTransport
- Enables rapid MCP server development from APIs

Install the package and import the Converter class. Instantiate it with optional baseURL and httpClient, then call converter.load({ specs }) to load OpenAPI specifications. Retrieve the tool list via converter.getToolsList() and the tool caller via converter.getToolsCaller(). Use these with an MCP server (e.g., StdioServerTransport) to handle tool listing and execution.

OPENAPI Specifications => MCP (Model Context Protocol) Tools

- 🔧 An utility library for converting OpenAPI specifications to MCP tools.
- 🚀 Faster the development of MCP servers based on OPENAPI specifications.

Usage

import { Server } from '@modelcontextprotocol/sdk/server/index.js';
import { StdioServerTransport } from '@modelcontextprotocol/sdk/server/stdio.js';
import {
  CallToolRequestSchema,
  ListToolsRequestSchema,
} from '@modelcontextprotocol/sdk/types.js';
import { Converter } from 'openapi2mcptools';

const converter = new Converter({
baseURL, // optional
httpClient // optional
});
await converter.load({
// specs
});
const tools = converter.getToolsList();
const toolCaller = converter.getToolsCaller();

const server = new Server(
{
name: 'mcp-server-openapi',
version: '1.0.0',
},
{
capabilities: {
tools: {},
},
},
);

// Define available tools
server.setRequestHandler(ListToolsRequestSchema, async () => {
return {
tools,
};
});

// Handle tool execution
server.setRequestHandler(CallToolRequestSchema, async (request) => {
return await toolCaller(request);
});

const transport = new StdioServerTransport();
await server.connect(transport);

Custom client

Set baseURL, headers, etc for http client.

export type RequestConfig = {
  url?: string;
  method?: string;
  headers?: any;
  params?: any;
  data?: any;
}

export interface HTTPClient {
request: (requestConfig: RequestConfig) => Promise<{ data: any }>;
}

Example:

import axios from axios;
import { Converter } from 'openapi2mcptools';

const converter = new Converter({
httpClient: axios
});

No reviews yet — be the first

Sign in to leave a review

Use Google, GitHub, or an email account so ratings stay tied to real people.

Email sign in

No reviews posted yet.