Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/2013xile/openapi2mcptools
OpenAPI specifications => MCP (Model Context Protocol) tools
https://github.com/2013xile/openapi2mcptools
mcp mcp-server mcp-tools modelcontextprotocol openapi
Last synced: 22 days ago
JSON representation
OpenAPI specifications => MCP (Model Context Protocol) tools
- Host: GitHub
- URL: https://github.com/2013xile/openapi2mcptools
- Owner: 2013xile
- License: mit
- Created: 2024-12-08T17:26:31.000Z (28 days ago)
- Default Branch: main
- Last Pushed: 2024-12-09T15:30:42.000Z (27 days ago)
- Last Synced: 2024-12-09T16:20:50.150Z (27 days ago)
- Topics: mcp, mcp-server, mcp-tools, modelcontextprotocol, openapi
- Language: TypeScript
- Homepage:
- Size: 33.2 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# 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
```ts
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.
```ts
export type RequestConfig = {
url?: string;
method?: string;
headers?: any;
params?: any;
data?: any;
}export interface HTTPClient {
request: (requestConfig: RequestConfig) => Promise<{ data: any }>;
}
```Example:
```ts
import axios from axios;
import { Converter } from 'openapi2mcptools';const converter = new Converter({
httpClient: axios
});
```