MCP OpenAPI Template

MCP OpenAPI Template

A template for building MCP servers from OpenAPI specifications, enabling automatic conversion of any REST API into LLM-accessible tools with built-in authentication and validation.

Category
Visit Server

README

MCP OpenAPI Template

A template for building MCP (Model Context Protocol) servers from OpenAPI specifications.

This template provides a production-ready foundation for creating MCP servers that expose any REST API with an OpenAPI specification to LLM-powered tools.

Features

  • Dynamic Tool Generation: Automatically creates MCP tools from OpenAPI specs
  • Auth Gateway Integration: Centralized authentication via Auth Gateway
  • Dual Transport: Supports both stdio (local) and sse (remote) transports
  • Configurable Validation: Customizable ID patterns and input validation
  • Tool Policies: Risk-based policies for blocking/logging operations
  • Docker Ready: Production-ready Dockerfile and docker-compose

Quick Start

1. Clone/Use Template

# Using GitHub template feature (recommended)
# Click "Use this template" on GitHub

# Or clone directly
git clone https://github.com/jesusperezdeveloper/mcp_openapi_template my-api-mcp
cd my-api-mcp

2. Initialize Your Service

python -m scripts.init_service \
  --name "github" \
  --display-name "GitHub" \
  --base-url "https://api.github.com" \
  --openapi-url "https://raw.githubusercontent.com/github/rest-api-description/main/descriptions/api.github.com/api.github.com.json"

3. Configure Auth Gateway

Edit .env with your Auth Gateway credentials:

AUTH_GATEWAY_URL=https://your-auth-gateway.com
AUTH_GATEWAY_API_KEY=your-api-key

4. Download OpenAPI Spec

python -m scripts.fetch_openapi

5. Run the Server

# Local mode (stdio)
PYTHONPATH=vendor python -m src.server

# Remote mode (SSE)
MCP_TRANSPORT=sse PYTHONPATH=vendor python -m src.server

Project Structure

mcp_openapi_template/
├── src/
│   ├── server.py           # Main MCP server
│   ├── config.py           # Configuration loader
│   ├── openapi_tools.py    # Dynamic tool generator
│   ├── auth_gateway.py     # Auth Gateway integration
│   ├── validation.py       # Input validation
│   └── tool_policies.py    # Risk policies
├── config/
│   ├── service.yaml        # Service configuration
│   ├── mcp.local.json      # Local MCP config
│   └── mcp.remote.json     # Remote MCP config
├── scripts/
│   ├── fetch_openapi.py    # Download OpenAPI spec
│   └── init_service.py     # Initialize new service
├── examples/
│   └── trello/             # Complete Trello example
├── openapi/                # OpenAPI specs (downloaded)
├── vendor/mcp/             # Vendorized MCP SDK
├── Dockerfile
└── docker-compose.yml

Configuration

service.yaml

The main configuration file (config/service.yaml) defines:

service:
  name: "myservice"
  display_name: "My Service"

api:
  base_url: "https://api.example.com"
  openapi_spec_url: "https://api.example.com/openapi.json"
  tool_prefix: "myservice"

auth:
  gateway_endpoint: "/credentials/myservice"
  credentials_format:
    - name: "api_key"
      query_param: "key"

validation:
  id_pattern: "^[a-zA-Z0-9]+$"

policies:
  blocked_patterns:
    - "delete_organization"

Environment Variables

Variable Required Description
AUTH_GATEWAY_URL Yes Auth Gateway URL
AUTH_GATEWAY_API_KEY Yes API Key for Auth Gateway
API_BASE_URL No Override API base URL
MCP_TRANSPORT No stdio (default) or sse
MCP_PORT No Port for SSE mode (default: 8000)

Authentication Flow

  1. User obtains JWT from Auth Gateway (login)
  2. User calls set_auth_token(jwt) in the MCP
  3. MCP fetches API credentials from Auth Gateway
  4. Credentials are cached for the session
  5. User can now use all available tools

Adding Custom Helper Tools

See examples/trello/helpers.py for a complete example of adding user-friendly wrapper tools.

# In src/helpers.py
def register_helper_tools(mcp, auth_params, client_factory, require_auth):
    @mcp.tool(description="My custom tool")
    async def my_tool(param: str) -> dict:
        require_auth()
        # Implementation
        pass

Docker Deployment

# Build with OpenAPI spec
docker build \
  --build-arg OPENAPI_SPEC_URL="https://api.example.com/openapi.json" \
  -t my-mcp .

# Run
docker run -p 8000:8000 --env-file .env my-mcp

Examples

See the examples/ directory for complete configurations:

  • Trello: Full configuration with helper tools, validation, and policies

License

MIT

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

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
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
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
VeyraX MCP

VeyraX MCP

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

Official
Featured
Local
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
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
Qdrant Server

Qdrant Server

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

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
Neon Database

Neon Database

MCP server for interacting with Neon Management API and databases

Official
Featured