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 library
pip install gmcp
# Install in development mode
git clone https://github.com/gaurav98095/gmcp.git
cd gmcp
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.2.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.2-py3-none-any.whl (7.8 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: gmcp-0.2.2.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.2.tar.gz
Algorithm Hash digest
SHA256 2dfb351df7439041f77e532e6f3ffefa022930009e3b8785eddf05b596ee5312
MD5 4f84dfdb707a6cb8eae843a1ef27d1ce
BLAKE2b-256 b2700cbf59c77dbbd7fbfd2448ab0ebb23b11fa5712500d4864c6bf0bad34e76

See more details on using hashes here.

Provenance

The following attestation bundles were made for gmcp-0.2.2.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.2-py3-none-any.whl.

File metadata

  • Download URL: gmcp-0.2.2-py3-none-any.whl
  • Upload date:
  • Size: 7.8 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.2-py3-none-any.whl
Algorithm Hash digest
SHA256 4eef43fbe32611db93ac961bf2b4b79248480b27fa89fdcabf52a2de618ac6fd
MD5 99b8e4f11b5badbcb1bd7ecbe6264944
BLAKE2b-256 1558c4f9b4b12b5e384bba5db65cbbf974fe94359b29abcba79c474310e0a440

See more details on using hashes here.

Provenance

The following attestation bundles were made for gmcp-0.2.2-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