OpenAPI MCP Server

OpenAPI MCP Server

Dynamically exposes any OpenAPI/Swagger API as tools for AI assistants, automatically generating MCP tools from OpenAPI specs with authentication support.

Category
Visit Server

README

OpenAPI MCP Server

A Model Context Protocol (MCP) server that dynamically exposes OpenAPI/Swagger APIs as tools for AI assistants.

Overview

This MCP server automatically generates tools from OpenAPI specifications, allowing AI assistants to interact with any API that has an OpenAPI/Swagger definition. Each API endpoint becomes a callable tool with proper parameter handling and authentication support.

Features

  • Dynamic Tool Generation: Automatically creates MCP tools from OpenAPI operations
  • Multiple Authentication Methods: Supports Bearer tokens, custom headers, and API keys
  • Flexible Spec Loading: Load OpenAPI specs from local files or URLs
  • Full HTTP Method Support: GET, POST, PUT, DELETE, PATCH operations
  • Parameter Handling: Supports path, query, header parameters and request bodies
  • Error Handling: Comprehensive error reporting and logging

Installation

  1. Clone this repository
  2. Create a virtual environment (recommended):
    python -m venv myenv
    source myenv/bin/activate  # On Windows: myenv\Scripts\activate
    
  3. Install dependencies:
    pip install -r requirements.txt
    

Why Use a Virtual Environment?

Using a virtual environment is strongly recommended because:

  • Isolation: Keeps project dependencies separate from system Python packages
  • Version Control: Ensures consistent package versions across different machines
  • Clean Development: Prevents conflicts between different projects' dependencies
  • Easy Cleanup: Simply delete the virtual environment folder to remove all packages

Virtual Environment Commands

Creating and activating:

# Create virtual environment
python -m venv myenv

# Activate on macOS/Linux
source myenv/bin/activate

# Activate on Windows
myenv\Scripts\activate

# Activate on Windows (PowerShell)
myenv\Scripts\Activate.ps1

Deactivating:

deactivate

Verifying activation:

# Check if virtual environment is active
which python  # On macOS/Linux
where python  # On Windows

# Should show path to your virtual environment's Python

Usage

Basic Usage

Run the server with a local OpenAPI spec file:

python openapi-mcp-server.py petstore.yaml

Or using environment variables:

export OPENAPI_SPEC_PATH=petstore.yaml
python openapi-mcp-server.py

Configuration

The server can be configured using environment variables:

  • OPENAPI_SPEC_PATH: Path or URL to the OpenAPI specification
  • OPENAPI_BASE_URL: Override the base URL from the spec (optional)
  • API_KEY: Bearer token for API authentication (optional)

Authentication

The server supports multiple authentication methods:

  1. Bearer Token: Set via API_KEY environment variable
  2. Custom Headers: Pass auth parameters in tool calls:
    • _auth_profileId: For X-IHR-Profile-ID header
    • _auth_sessionId: For X-IHR-Session-ID header
    • _auth_token: For Authorization Bearer token

MCP Integration

To use this server with an MCP client, add it to your MCP configuration:

{
  "mcpServers": {
    "openapi": {
      "command": "python",
      "args": ["/path/to/openapi-mcp-server.py"],
      "env": {
        "OPENAPI_SPEC_PATH": "/path/to/your-api-spec.yaml",
        "OPENAPI_BASE_URL": "https://api.example.com",
        "API_KEY": "your-api-key"
      }
    }
  }
}

How It Works

  1. Spec Loading: The server loads and parses the OpenAPI specification
  2. Tool Generation: Each API operation becomes an MCP tool with:
    • Name from operationId
    • Description from operation description or summary
    • Input schema generated from parameters and request body
  3. Tool Execution: When a tool is called:
    • Path parameters are substituted
    • Query parameters are added to the URL
    • Headers are set (including auth)
    • Request body is sent as JSON
    • Response is returned as formatted JSON

Example Tools

For a typical OpenAPI spec, the server might generate tools like:

  • getPetById: Fetch a pet by ID
  • addPet: Add a new pet to the store
  • updatePet: Update an existing pet
  • deletePet: Delete a pet

Each tool will have appropriate parameters based on the API definition.

Development

Testing

The repository includes several utility scripts:

  • test-mcp-server.py: Test the MCP server functionality
  • inspect-mcp-api.py: Inspect available MCP APIs
  • check-mcp-install.py: Verify MCP installation
  • mcp-openapi-generator-python.py: Generate Python code from OpenAPI specs

Logging

The server includes comprehensive logging. Set the log level via the standard Python logging configuration.

Requirements

  • Python 3.7+
  • Dependencies listed in requirements.txt:
    • mcp>=0.1.0
    • httpx>=0.25.0
    • pyyaml>=6.0
    • pydantic>=2.0.0

License

[Specify your license here]

Contributing

[Add contribution guidelines if applicable]

Recommended Servers

playwright-mcp

playwright-mcp

A Model Context Protocol server that enables LLMs to interact with web pages through structured accessibility snapshots without requiring vision models or screenshots.

Official
Featured
TypeScript
Magic Component Platform (MCP)

Magic Component Platform (MCP)

An AI-powered tool that generates modern UI components from natural language descriptions, integrating with popular IDEs to streamline UI development workflow.

Official
Featured
Local
TypeScript
Audiense Insights MCP Server

Audiense Insights MCP Server

Enables interaction with Audiense Insights accounts via the Model Context Protocol, facilitating the extraction and analysis of marketing insights and audience data including demographics, behavior, and influencer engagement.

Official
Featured
Local
TypeScript
VeyraX MCP

VeyraX MCP

Single MCP tool to connect all your favorite tools: Gmail, Calendar and 40 more.

Official
Featured
Local
graphlit-mcp-server

graphlit-mcp-server

The Model Context Protocol (MCP) Server enables integration between MCP clients and the Graphlit service. Ingest anything from Slack to Gmail to podcast feeds, in addition to web crawling, into a Graphlit project - and then retrieve relevant contents from the MCP client.

Official
Featured
TypeScript
Kagi MCP Server

Kagi MCP Server

An MCP server that integrates Kagi search capabilities with Claude AI, enabling Claude to perform real-time web searches when answering questions that require up-to-date information.

Official
Featured
Python
Neon Database

Neon Database

MCP server for interacting with Neon Management API and databases

Official
Featured
E2B

E2B

Using MCP to run code via e2b.

Official
Featured
Exa Search

Exa Search

A Model Context Protocol (MCP) server lets AI assistants like Claude use the Exa AI Search API for web searches. This setup allows AI models to get real-time web information in a safe and controlled way.

Official
Featured
Qdrant Server

Qdrant Server

This repository is an example of how to create a MCP server for Qdrant, a vector search engine.

Official
Featured