Custom OpenAPI MCP Server

Custom OpenAPI MCP Server

Dynamically fetches and exposes OpenAPI/Swagger documentation as tools for AI assistants, enabling them to explore and interact with any REST API.

Category
访问服务器

README

Custom OpenAPI MCP Server

A powerful Model Context Protocol (MCP) server that dynamically fetches and exposes OpenAPI/Swagger documentation as tools for AI assistants like GitHub Copilot and Claude. This server enables AI models to understand and interact with any REST API by automatically parsing OpenAPI specifications.

Features

  • 🚀 Dynamic API Discovery: Automatically fetches and parses OpenAPI/Swagger specifications from any URL
  • 🔍 Intelligent Endpoint Exploration: List and filter endpoints by tags for organized API navigation
  • 📖 Detailed Documentation: Get comprehensive endpoint descriptions, parameters, and response schemas
  • 💡 Smart Code Generation: Generate realistic request examples based on OpenAPI schemas
  • ⚡ Real-time Integration: Works seamlessly with GitHub Copilot, Claude, and other MCP-compatible AI tools
  • 🛠️ Zero Configuration: Works out of the box with sensible defaults

Tools Provided

1. list_endpoints_by_tag

Lists all endpoints grouped by OpenAPI tags, providing a high-level overview of API functionality.

Parameters:

  • tag (string): OpenAPI tag name (e.g., "Authentication", "Users", "Orders")

Example Output:

GET /auth/login: Authenticate user with credentials
POST /auth/refresh: Refresh authentication token
DELETE /auth/logout: Logout and invalidate session

2. describe_endpoint

Provides detailed information about a specific endpoint including parameters, request body, and responses.

Parameters:

  • path (string): API endpoint path (e.g., "/users/{id}")
  • method (string): HTTP method (e.g., "GET", "POST", "PUT", "DELETE")

Example Output:

### POST /users
Create a new user account

**Parameters**
- `x-api-key` (header) **required** – string

**Request Body**
- application/json
  - schema: UserCreateRequest

**Responses**
- 201: User created successfully
- 400: Invalid request data
- 409: User already exists

3. generate_request_example

Generates sample JSON request bodies based on OpenAPI schemas, perfect for testing and development.

Parameters:

  • path (string): API endpoint path
  • method (string): HTTP method

Example Output:

{
  "username": "string",
  "email": "string",
  "password": "string",
  "profile": {
    "firstName": "string",
    "lastName": "string",
    "age": 0
  }
}

Installation

Prerequisites

  • Node.js 18+
  • npm or yarn
  • An MCP-compatible AI assistant (GitHub Copilot, Claude Desktop, etc.)

Quick Start

  1. Clone and Install

    git clone <your-repo-url>
    cd custom-mcp
    npm install
    
  2. Configure Environment (Optional)

    cp .env.example .env
    # Edit .env to set your API documentation URL
    
  3. Test the Server

    npm start
    

GitHub Copilot Integration

{
  "mcpServers": {
    "custom-openapi": {
      "command": "node",
      "args": ["/absolute/path/to/custom-mcp/index.js"],
      "env": {
        "API_DOCS_URL": "https://your-api.com/swagger.json"
      }
    }
  }
}

For macOS/Linux (~/.config/github-copilot/mcp.json):

{
  "servers": {
    "custom-openapi": {
      "type": "stdio",
      "command": "node",
      "args": ["/absolute/path/to/custom-mcp/index.js"],
      "env": {
        "API_DOCS_URL": "https://your-api.com/swagger.json"
      }
    }
  }
}

For Windows (%APPDATA%\github-copilot\mcp.json):

{
  "servers": {
    "custom-openapi": {
      "type": "stdio",
      "command": "node",
      "args": ["C:\\path\\to\\custom-mcp\\index.js"],
      "env": {
        "API_DOCS_URL": "https://your-api.com/swagger.json"
      }
    }
  }
}

Claude Desktop Integration

Add to your Claude Desktop MCP configuration (claude_desktop_config.json):

{
  "mcpServers": {
    "custom-openapi": {
      "command": "node",
      "args": ["/absolute/path/to/custom-mcp/index.js"],
      "env": {
        "API_DOCS_URL": "https://your-api.com/swagger.json"
      }
    }
  }
}

Configuration

Environment Variables

Variable Description Default
API_DOCS_URL URL to OpenAPI/Swagger JSON specification Petstore demo API

Supported OpenAPI Sources

  • ✅ OpenAPI 3.0+ specifications
  • ✅ Swagger 2.0 specifications
  • ✅ Local files (file:// URLs)
  • ✅ Remote HTTPS endpoints
  • ✅ APIs with CORS enabled
  • ✅ JSON and YAML formats

Example API URLs

# Petstore Demo (default)
API_DOCS_URL=https://petstore.swagger.io/v2/swagger.json

# Local development server
API_DOCS_URL=http://localhost:3000/api/docs/json

# Production API
API_DOCS_URL=https://api.yourcompany.com/v1/openapi.json

# Local file
API_DOCS_URL=file:///path/to/your/openapi.json

Usage Examples

Once integrated with your AI assistant, you can use natural language to explore APIs:

"Show me all authentication endpoints"
→ Uses list_endpoints_by_tag with tag="Authentication"

"How do I create a new user?"
→ Uses describe_endpoint for POST /users

"Generate an example request for user registration"
→ Uses generate_request_example for POST /users/register

Architecture

┌─────────────────┐    ┌──────────────────┐    ┌─────────────────┐
│   AI Assistant  │◄──►│  MCP Server      │◄──►│  OpenAPI Spec   │
│ (Copilot/Claude)│    │  (This Project)  │    │  (Remote/Local) │
└─────────────────┘    └──────────────────┘    └─────────────────┘

Core Components

  • index.js: Server bootstrap and OpenAPI spec fetching
  • tools.js: MCP tool definitions and OpenAPI parsing logic
  • package.json: Dependencies and project metadata
  • mcp.json: Example MCP client configuration

Example of current configration

alt text alt text

Troubleshooting

Common Issues

Server fails to start:

# Check if the API URL is accessible
curl -s "https://your-api.com/swagger.json" | jq .

# Verify Node.js version
node --version  # Should be 18+

No tools appear in AI assistant:

  • Verify the absolute path in mcp.json is correct
  • Restart your AI assistant after configuration changes
  • Check the server logs for errors

Schema parsing errors:

  • Ensure your OpenAPI spec is valid JSON/YAML
  • Test with a minimal spec first
  • Check for unsupported OpenAPI extensions

Validation

Test your OpenAPI specification:

# Using swagger-codegen
npx swagger-codegen-cli validate -i https://your-api.com/swagger.json

# Using online validator
curl -X POST "https://validator.swagger.io/validator/debug" \
  -H "Content-Type: application/json" \
  -d '{"url":"https://your-api.com/swagger.json"}'

Contributing

  1. Fork the repository
  2. Create a feature branch (git checkout -b feature/amazing-feature)
  3. Commit your changes (git commit -m 'Add amazing feature')
  4. Push to the branch (git push origin feature/amazing-feature)
  5. Open a Pull Request

License

This project is licensed under the MIT License - see the LICENSE file for details.

Acknowledgments


推荐服务器

Baidu Map

Baidu Map

百度地图核心API现已全面兼容MCP协议,是国内首家兼容MCP协议的地图服务商。

官方
精选
JavaScript
Playwright MCP Server

Playwright MCP Server

一个模型上下文协议服务器,它使大型语言模型能够通过结构化的可访问性快照与网页进行交互,而无需视觉模型或屏幕截图。

官方
精选
TypeScript
Magic Component Platform (MCP)

Magic Component Platform (MCP)

一个由人工智能驱动的工具,可以从自然语言描述生成现代化的用户界面组件,并与流行的集成开发环境(IDE)集成,从而简化用户界面开发流程。

官方
精选
本地
TypeScript
Audiense Insights MCP Server

Audiense Insights MCP Server

通过模型上下文协议启用与 Audiense Insights 账户的交互,从而促进营销洞察和受众数据的提取和分析,包括人口统计信息、行为和影响者互动。

官方
精选
本地
TypeScript
VeyraX

VeyraX

一个单一的 MCP 工具,连接你所有喜爱的工具:Gmail、日历以及其他 40 多个工具。

官方
精选
本地
graphlit-mcp-server

graphlit-mcp-server

模型上下文协议 (MCP) 服务器实现了 MCP 客户端与 Graphlit 服务之间的集成。 除了网络爬取之外,还可以将任何内容(从 Slack 到 Gmail 再到播客订阅源)导入到 Graphlit 项目中,然后从 MCP 客户端检索相关内容。

官方
精选
TypeScript
Kagi MCP Server

Kagi MCP Server

一个 MCP 服务器,集成了 Kagi 搜索功能和 Claude AI,使 Claude 能够在回答需要最新信息的问题时执行实时网络搜索。

官方
精选
Python
e2b-mcp-server

e2b-mcp-server

使用 MCP 通过 e2b 运行代码。

官方
精选
Neon MCP Server

Neon MCP Server

用于与 Neon 管理 API 和数据库交互的 MCP 服务器

官方
精选
Exa MCP Server

Exa MCP Server

模型上下文协议(MCP)服务器允许像 Claude 这样的 AI 助手使用 Exa AI 搜索 API 进行网络搜索。这种设置允许 AI 模型以安全和受控的方式获取实时的网络信息。

官方
精选