Skip to main content

Transform any FastAPI server into an MCP server

Project description

gmcp - Transform FastAPI to MCP

gmcp automatically converts any FastAPI server into an MCP (Model Context Protocol) server, exposing all API endpoints as tools that Claude can use.

Features

  • 🚀 Zero Configuration: Just provide a FastAPI server URL
  • 🔄 Auto-Discovery: Automatically discovers all endpoints via OpenAPI schema
  • 🛠️ Full Support: Handles GET, POST, PUT, PATCH, DELETE methods
  • 📝 Schema Aware: Preserves parameter types, descriptions, and validation
  • 🔐 Authentication: Supports Bearer tokens, API keys, Basic auth, and custom headers
  • 🔒 Secure: Environment variable support for sensitive credentials
  • Fast: Efficient async HTTP client built on httpx

Installation

# Install in development mode
pip install -e .

Usage

Basic Usage

Testing (list available tools):

# Test that gmcp can discover tools
gmcp --list-tools http://localhost:5000

Running as MCP server:

gmcp automatically detects when it's run from an interactive terminal and will show helpful instructions instead of starting the server. To use it as an MCP server, configure it in Claude Code (see below).

If you need to force MCP server mode (e.g., for testing with another MCP client):

gmcp --force http://localhost:5000

Configure in Claude Code

Add to ~/.claude/mcp_settings.json:

Basic (no auth):

{
  "mcpServers": {
    "my-fastapi-server": {
      "command": "gmcp",
      "args": ["http://localhost:5000"]
    }
  }
}

With Authentication:

{
  "mcpServers": {
    "my-api": {
      "command": "gmcp",
      "args": [
        "http://api.example.com",
        "--auth-type", "bearer",
        "--auth-token", "$API_TOKEN"
      ],
      "env": {
        "API_TOKEN": "your-token-here"
      }
    }
  }
}

See AUTH.md for complete authentication documentation.

Example

If your FastAPI server has these endpoints:

@app.get("/users/{user_id}")
async def get_user(user_id: int):
    return {"id": user_id, "name": "John"}

@app.post("/users")
async def create_user(name: str, email: str):
    return {"id": 123, "name": name, "email": email}

gmcp will automatically create MCP tools:

  • get_users_user_id - Get a user by ID
  • create_users - Create a new user

Claude can then call these tools directly!

How It Works

  1. Fetch Schema: gmcp fetches the OpenAPI schema from /openapi.json
  2. Parse Endpoints: Converts each endpoint into an MCP tool definition
  3. Proxy Requests: When tools are called, gmcp makes HTTP requests to FastAPI
  4. Return Results: Responses are formatted and returned to Claude

Requirements

  • Python 3.10+
  • A running FastAPI server with OpenAPI enabled (default)

Development

Project Structure

gmcp/
├── src/
│   └── gmcp/
│       ├── __init__.py
│       └── server.py      # Main MCP server implementation
├── examples/
│   ├── sample_api.py      # Example FastAPI server
│   └── test_gmcp.sh       # Test script
├── pyproject.toml
└── README.md

Testing

See examples/ directory for a sample FastAPI server and test script.

Documentation

  • QUICKSTART.md - Get started in 5 minutes
  • AUTH.md - Authentication guide (Bearer, API keys, Basic auth)
  • USAGE.md - Detailed usage guide and troubleshooting

License

MIT

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

gmcp-0.2.1.tar.gz (13.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

gmcp-0.2.1-py3-none-any.whl (7.7 kB view details)

Uploaded Python 3

File details

Details for the file gmcp-0.2.1.tar.gz.

File metadata

  • Download URL: gmcp-0.2.1.tar.gz
  • Upload date:
  • Size: 13.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for gmcp-0.2.1.tar.gz
Algorithm Hash digest
SHA256 fde686fc6fbdaa4e1b8517b8dd7404d3a006a50582d3eec611422375f81ad91f
MD5 b0106ae17389aefd0d0da5da79651ee0
BLAKE2b-256 13780b259769bd2126c9d3b0f51f6bbbbc046a1e2181b115178941d38ec9a2cf

See more details on using hashes here.

Provenance

The following attestation bundles were made for gmcp-0.2.1.tar.gz:

Publisher: publish.yml on gaurav98095/gmcp

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file gmcp-0.2.1-py3-none-any.whl.

File metadata

  • Download URL: gmcp-0.2.1-py3-none-any.whl
  • Upload date:
  • Size: 7.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for gmcp-0.2.1-py3-none-any.whl
Algorithm Hash digest
SHA256 db9e0fc221add8e23c89d3ddad6187fe2a3f75352c518831f42f46df6c75618c
MD5 c926fc591cf05b8061cdcf5941e73203
BLAKE2b-256 a24785935c8b0673439b213a2793f20339d6702c46a59bd254a29535dba6fd28

See more details on using hashes here.

Provenance

The following attestation bundles were made for gmcp-0.2.1-py3-none-any.whl:

Publisher: publish.yml on gaurav98095/gmcp

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page