FastMCP

sgthun/FastMCP

3.1

If you are the rightful owner of FastMCP and would like to certify it and/or have it hosted online, please leave a comment on the right or send an email to dayong@mcphub.com.

FastMCP is a helper tool designed to expose selected FastAPI routes as an MCP server using Streamable HTTP transport.

FastMCP (incubator)

FastMCP is a tiny helper to expose selected FastAPI routes as an MCP server using the Streamable HTTP transport. It’s written to be copied out as a standalone library later.

Highlights:

  • Introspects a FastAPI app and turns routes into MCP tools
  • Filter by tags to build different MCP “personas” on different ports
  • Optional approval workflow: queue tool calls for human approval via a pluggable store and a minimal portal

This incubator lives under FastMCP/ in this repo for bootstrapping and will be extracted to its own package.

Quick start (in this repo)

  • The entrypoint FastMCP/http_server.py loads the kitchen FastAPI app and exposes an MCP server on port 8091 by default.
  • Configure via env:
    • FASTMCP_HTTP_PORT: port to listen on (default 8091)
    • FASTMCP_TAGS: comma-separated FastAPI route tags to include (optional)
    • FASTMCP_REQUIRE_APPROVAL: true/false to enable approval queue (optional)

When approvals are enabled, a simple portal is mounted under /portal to approve/decline/modify queued requests.

Adding per-route MCP metadata

Attach attributes to your route endpoint functions to customize the exposed tool:

  • mcp_enable: bool (default True)
  • mcp_name: str (defaults to route name or path-derived)
  • mcp_description: str
  • mcp_tags: Iterable[str] (merged with FastAPI route tags)
  • mcp_requires_approval: bool (overrides global default for this route)

Example:

@router.post("/do_something", tags=["automation"])
async def do_something(payload: Payload):
    do_something.mcp_name = "do_something_tool"
    do_something.mcp_description = "Does something important"
    do_something.mcp_tags = ["automation", "safe"]
    do_something.mcp_requires_approval = True
    return {"ok": True}

Approval store

  • InMemoryApprovalStore provides a simple testing store.
  • Implement the ApprovalStore interface to back the queue with your datastore of choice.

Notes

  • This MCP server proxies calls back into the FastAPI app using its TestClient. For production, consider delegating to the app’s HTTP API over the network.
  • The tool input schema is a generic object. Future versions may infer request models to generate JSONSchemas.
  • This is an incubator; APIs may change when extracted.