# Fastapi Mcp Router

> Expose MCP tools from your FastAPI app without adopting a separate framework.

- **Type:** MCP server
- **Install:** `agentstack add mcp-rcrsr-fastapi-mcp-router`
- **Verified:** Yes — security-reviewed for prompt injection and unsafe behavior
- **Seller:** [rcrsr](https://agentstack.voostack.com/s/rcrsr)
- **Installs:** 0
- **Category:** [Cloud & Infrastructure](https://agentstack.voostack.com/c/cloud-infrastructure)
- **Latest version:** 0.1.0
- **License:** MIT
- **Upstream author:** [rcrsr](https://github.com/rcrsr)
- **Source:** https://github.com/rcrsr/fastapi-mcp-router

## Install

```sh
agentstack add mcp-rcrsr-fastapi-mcp-router
```

Requires the [AgentStack CLI](https://agentstack.voostack.com/docs/cli). Works with Claude Code, Cursor, and any MCP-compatible agent.

## About

# fastapi-mcp-router

[](https://github.com/rcrsr/fastapi-mcp-router/actions/workflows/ci.yml)
[](https://pypi.org/project/fastapi-mcp-router/)
[](https://pypi.org/project/fastapi-mcp-router/)
[](https://github.com/rcrsr/fastapi-mcp-router/blob/main/LICENSE)

Add MCP to your existing FastAPI app. Register tools, resources, and prompts with decorators. Use `Depends()`, `Request`, and `BackgroundTasks` the same way you already do.

## Why fastapi-mcp-router

- **It's just an `APIRouter`.** Mount it like any other router. No separate framework, no new server process.
- **Your DI still works.** `Depends()`, `Request`, `BackgroundTasks` — same patterns, same middleware.
- **2 dependencies.** FastAPI and Pydantic. Nothing else.
- **No lock-in.** Tools are regular async functions. Call them from tests, CLI scripts, or other endpoints without MCP.
- **Lambda-ready.** Stateless mode + Mangum. No adapter layer.

**Use FastMCP instead** if you need STDIO transport, OpenAPI spec imports, or managed hosting.

## Install

```bash
pip install fastapi-mcp-router
```

## Quick Start

```python
from fastapi import FastAPI
from fastapi_mcp_router import MCPRouter

app = FastAPI()
mcp = MCPRouter()

@mcp.tool()
async def write_message(payload: str) -> dict:
    """Write coordination message."""
    return {"success": True, "message_id": "msg-123"}

@mcp.resource("project://{project_id}/config")
async def project_config(project_id: str) -> dict:
    return {"project_id": project_id, "env": "production"}

@mcp.prompt()
async def review_code(file_path: str, language: str = "python") -> list[dict]:
    return [{"role": "user", "content": f"Review {file_path} ({language})"}]

app.include_router(mcp, prefix="/mcp")
```

That's it. Your FastAPI app now speaks MCP over Streamable HTTP.

## What You Get

- **Full MCP 2025-06-18 spec** — tools, resources, prompts, sampling, logging, completions, elicitation
- **Streamable HTTP** — JSON or SSE response based on `Accept` header
- **Streaming tools** — return `AsyncGenerator` for incremental results
- **Session management** — in-memory and Redis stores for stateful connections
- **Progress reporting** — inject `ProgressCallback` into tool signatures
- **Auth** — `auth_validator` callback + OAuth 2.1 PRM (RFC 9728)
- **OpenTelemetry** — opt-in spans and counters via `pip install fastapi-mcp-router[otel]`
- **Lambda-ready** — stateless mode works with Mangum, no adapter overhead

## Documentation

- [Quick Start](docs/quickstart.md) — installation, first tool, stateful mode, auth, Lambda
- [Guide](docs/guide.md) — resources, prompts, streaming, sessions, telemetry
- [API Reference](docs/reference.md) — all exports, types, and configuration options

## License

MIT

## Source & license

This open-source MCP server is cataloged on AgentStack and links to its original source — we do not rehost the code.

- **Author:** [rcrsr](https://github.com/rcrsr)
- **Source:** [rcrsr/fastapi-mcp-router](https://github.com/rcrsr/fastapi-mcp-router)
- **License:** MIT

Install and usage instructions live in the source repository linked above.

## Pricing

- **Free** — Free

## Security capabilities

Automated source analysis of v0.1.0 — what this tool can access:

- **Network access:** no
- **Filesystem access:** no
- **Shell / process execution:** no
- **Environment & secrets:** no
- **Dynamic code execution:** no

*"Yes" means the capability is present in the source — more access means more to trust, not that it is unsafe.*


## Versions

- **0.1.0** — security scan: passed — Imported from the upstream source.

## Links

- Listing page: https://agentstack.voostack.com/l/mcp-rcrsr-fastapi-mcp-router
- Seller: https://agentstack.voostack.com/s/rcrsr
- Browse the marketplace: https://agentstack.voostack.com/browse

---
Listed on AgentStack — the marketplace for AI agent skills and MCP servers. Every listing is security-reviewed. Creators keep 70%.
