Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

mcpgen

Turn any API into an MCP server. Takes an OpenAPI spec and serves it as a fully functional Model Context Protocol server — single binary, zero config.

Install

go install github.com/dhruvgupta/mcpgen/cmd/mcpgen@latest

Or build from source:

git clone https://github.com/dhruvgupta/mcpgen.git
cd mcpgen
make build

Usage

Serve an API as MCP server (stdio)

mcpgen serve --openapi ./petstore.yaml

Serve with auth

# Static auth token
mcpgen serve --openapi ./api.json --auth "Bearer sk-xxx"

# Auth from environment variable
mcpgen serve --openapi ./api.json --auth-env API_KEY

# Custom header name
mcpgen serve --openapi ./api.json --auth-env API_KEY --auth-header "X-API-Key"

SSE transport

mcpgen serve --openapi ./api.json --transport sse --port 3100

Filter endpoints

# Only include specific paths
mcpgen serve --openapi ./api.json --pick "/users,/orders"

# Exclude paths
mcpgen serve --openapi ./api.json --exclude "/admin,/internal"

# Only specific HTTP methods
mcpgen serve --openapi ./api.json --methods "GET,POST"

Preview tools without serving

mcpgen list --openapi ./petstore.yaml

Import a single curl command

mcpgen serve --curl 'curl -X POST https://api.example.com/data -H "Authorization: Bearer token" -d "{\"key\":\"value\"}'

Generate a standalone project

mcpgen init my-server --from-openapi ./api.json

Claude Desktop Integration

Add to your Claude Desktop config (~/Library/Application Support/Claude/claude_desktop_config.json):

{
  "mcpServers": {
    "myapi": {
      "command": "mcpgen",
      "args": ["serve", "--openapi", "./spec.json", "--auth-env", "API_KEY"]
    }
  }
}

How It Works

  1. Parses your OpenAPI 3.x spec (JSON or YAML, local file or URL)
  2. Converts each endpoint into an MCP tool ({method}_{path})
  3. Serves tools over MCP stdio or SSE transport
  4. When a tool is called, makes the actual HTTP request to the API and returns the response

Tool Naming

Each API endpoint becomes an MCP tool named {method}_{path_segments}:

Endpoint Tool Name
GET /v1/users get_v1_users
POST /v1/users post_v1_users
GET /v1/users/{id} get_v1_users_id
DELETE /v1/users/{id}/posts delete_v1_users_id_posts

License

MIT

About

Turn any API into an MCP server. Single Go binary. Zero config.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages