mcpField
F
fastapi-mcp

fastapi-mcp

Local
github.com/KimiJLDeveloper Tools0Updated 77w ago

About fastapi-mcp

A Python example that mounts an MCP server within an existing FastAPI web app and includes a sample MCP client. It is intended for developers exploring this integration pattern.

Key features

  1. 01Mount an MCP server in FastAPI
  2. 02Sample MCP client
  3. 03Docker-based server startup

Use cases

  1. 01Explore hosting an MCP server in a FastAPI app
  2. 02Run the included client to test MCP communication

MCP support

Mounts an MCP server on a FastAPI app and includes a sample client demonstrating communication. The README notes that the server currently only works when mounted at the root path.

Configuration

Local server config is the same for every client. Copy it into your client’s MCP config file.

mcp.json · Universal config
{
"mcpServers": {
"fastapi": {
"command": "docker",
"args": [
"run",
"-i",
"--rm",
"build"
]
}
}
}
Run commanddocker run -i --rm build

Local servers need a runtime on your machine (e.g. Node.js 18+). Config file locations differ by client; see your client’s docs.

Packages
ocibuild

Tools

No tool list yet

Local servers expose tools only once running on your machine, and the maintainer has not provided a tool list.

Details

From the project README

Description

Simple example web app + client showing Model Context Protocol server mounted on an existing fastapi server

Model Context Protocol

FastAPI Mounting

Files

./src/main.py -> main fastapi server app

./src/mcp.py -> mcp sub server app logic

./client/client.py -> sample client showing some communication logic using mcp client lib

Set up

Using Docker to start server

docker build -t fastapi-mcp .
docker run -p 8000:8000 --net=host fastapi-mcp

Set up python environment & run client

pip install -r requirements.txt
python client/client.py

# to run server as well without docker
uvicorn src.main:app

Known Issues

MCP server can only be mounted on root '/'

GitHub Issue

Limitations on MCP python sdk that currently only allows for MCP server to work when mounted on root /

Comments

Markdown supported

New to MCP?

From what the protocol is to installing your first server, these answers cover most first questions.

An open protocol that defines how AI applications connect to external tools and data in a uniform way. Clients talk to the model; MCP servers provide tools, resources and prompt templates. They exchange standard messages, so one server can be reused by many clients.