2O

2013xile/openapi2mcptools

开发工具

本页由 AI 翻译,技术细节请以原文为准。 查看原文

19 stars 6 forks 质量 38 趋势 22MIT

OpenAPI 规格 QQ MCP( 模式上下文协议) 工具

概览

- 用于将OpenAPI规格转换为MCP工具的实用库。 - 加快根据OPENAPI规格开发MCP服务器。 为 http 客户端设置 BaseURL,页眉等.

概述(AI 翻译)

  • 用于将OpenAPI规格转换为MCP工具的实用库。
  • 加快根据OPENAPI规格开发MCP服务器。

□ 使用量

□ 自定义客户端

为 http 客户端设置 [[T0], [[T1]等.

示例

本页由 AI 翻译,技术细节请以原文为准。

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

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;
}

Example:

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

const converter = new Converter({
  httpClient: axios
});
在 GitHub 查看完整 README

安装

This server does not publish a one-line install command.

Open the repository installation guide 新手?先看 mcpskill.org 教程 →