
A directory listing describing a cancellation-letter and mailing-address service. The configured public GitHub repository returned 404 during source verification.

An example FastAPI server that exposes its endpoints as MCP tools using fastapi-mcp, with a LangChain client and Cursor configuration for testing.
FastAPI MCP Server Example is cataloged as an MCP server attributed to sdcalvo. An example FastAPI server that exposes its endpoints as MCP tools using fastapi-mcp, with a LangChain client and Cursor configuration for testing. It is categorized under developer tools. See the capability inspector for recorded interfaces and their independent review status; consult upstream documentation for the current interface.
Installation configuration is not reviewed. No executable setup is offered for this entry; inspect the source repository before proceeding.
Catalog license label: Not specified. Check the source repository's current license and terms before using, modifying or distributing this software.
Capability definitions are not reviewed. Unreviewed imports are not exposed as trusted interfaces.
No reviewed records to display. This does not establish that upstream lacks this capability.
No reviewed records to display. This does not establish that upstream lacks this capability.
No reviewed records to display. This does not establish that upstream lacks this capability.
Email delivery is not connected. This page does not collect email addresses or create subscriptions.
Browse the registry for current listings instead.
Reviews for FastAPI MCP Server Example are not available yet
Review publishing and storage are not connected. This page does not collect or publish ratings or comments, including after sign-in.
The README lists read_root__get and greet_user_greet__name__get as the tools visible in the MCP Inspector.
It must be created and mounted after the FastAPI routes you want to expose are defined, or the tools will not be discovered.
README.md · 6179cfdf228d · Fetched 2026-11-13 13:50:05 UTC
Original upstream text, without AI rewriting. Scripts, forms and unsafe links are filtered for safety.
Showing the last retrieved documentation snapshot; check the source for current changes.
Example project demonstrating how to expose FastAPI endpoints as Model Context Protocol (MCP) tools using
fastapi-mcp. Includes a basic LangChain agent (langchain_client.py) that connects to the local FastAPI server via HTTP/SSE usinglangchain-mcp-adaptersto discover and use the exposed tools.
Before you begin, ensure you have the following installed:
uv: The Python package manager used in this project. (Installation Instructions)npx (used to run the optional MCP Inspector). You can download Node.js (which includes npm) from nodejs.org..env file.This project demonstrates setting up a basic FastAPI application and exposing its endpoints as Model Context Protocol (MCP) tools using the fastapi-mcp library. It also includes a LangChain agent client that connects to and uses these tools, and covers configuring Cursor to connect as well.
Clone the Repository:
git clone <your-repo-url>
cd <repo-directory>
Install uv: If you don't have it, install the uv package manager (see Project Setup below for command).
Set up Environment & Install Dependencies:
uv init # If pyproject.toml doesn't exist
uv venv # Create virtual environment (.venv)
# Install all project dependencies
uv pip install fastapi "uvicorn[standard]" fastapi-mcp langchain-mcp-adapters langgraph langchain-openai python-dotenv
Create .env File: Create a file named .env in the project root directory and add your OpenAI API key:
OPENAI_API_KEY=your_openai_api_key_here
Run the FastAPI MCP Server: Open a terminal and run:
uvicorn main:app --reload --port 8000
Keep this terminal running.
(Alternatively, you can use the Python: FastAPI MCP debug configuration defined in .vscode/launch.json within VS Code / Cursor to run the server with the debugger attached.)
Run the LangChain Client: Open a second terminal and run:
uv run python langchain_client.py
The client will connect to the server, discover tools, and run a query using the agent.
(Optional) Test Server with MCP Inspector: Before running the LangChain client, or for more direct testing, you can use the official MCP Inspector tool:
npx @modelcontextprotocol/inspector
(npx comes with Node.js/npm. If this command fails, ensure Node.js is installed and accessible in your PATH.)http://127.0.0.1:8000/mcpread_root__get and greet_user_greet__name__get.name for greet_user), and click "Run Tool".(Optional) Test greet_user with LangChain Client: The greet_user endpoint and the corresponding test query (query2) in langchain_client.py are currently active. Simply run the LangChain client (Step 6) and observe the second part of its execution where it should attempt to greet the user 'LangChain'.
@app.get("/greet/{name}") endpoint in main.py and the query2 section in langchain_client.py)To build a simple FastAPI server with MCP capabilities for learning and testing purposes, runnable locally and connectable from MCP clients like the Cursor editor's agent.
uv, a fast Python package installer and resolver written in Rust.
irm https://astral.sh/uv/install.ps1 | iexuv init (Creates pyproject.toml)uv venv (Creates and manages .venv)uv:
# Specific commands used during development (covered by the combined install in Getting Started):
# uv pip install fastapi "uvicorn[standard]" fastapi-mcp
# uv pip install langchain-mcp-adapters langgraph langchain-openai python-dotenv
This installs FastAPI, the Uvicorn ASGI server, fastapi-mcp, LangChain components, and python-dotenv into the .venv virtual environment.main.py)A simple FastAPI app was created with endpoints:
/: Returns a welcome message./greet/{name}: Returns a personalized greeting (currently commented out).Crucially, the fastapi-mcp integration happens after the FastAPI route definitions:
from fastapi import FastAPI
from fastapi_mcp import FastApiMCP
app = FastAPI(...)
# --- Define FastAPI routes (@app.get, @app.post, etc.) ---
@app.get("/")
async def read_root():
# ... endpoint logic ...
# --- Initialize and mount fastapi-mcp AFTER routes ---
mcp = FastApiMCP(app)
mcp.mount() # Exposes tools under /mcp by default
uvicorn main:app --reload --port 8000launch.json file was created in .vscode to run the app with the debugger attached.langchain_client.py).env file for the OPENAI_API_KEY.langchain-mcp-adapters (MultiServerMCPClient) to connect to the running FastAPI server at http://127.0.0.1:8000/mcp via SSE..cursor/mcp.json file was created in the project root:
{
"mcpServers": {
"local-fastapi-mcp": {
"url": "http://127.0.0.1:8000/mcp"
}
}
}
uv Basics: uv init, uv venv, and uv pip install provide a fast way to set up a Python project environment.fastapi-mcp Initialization Order: The FastApiMCP(app) instance must be created and mcp.mount() must be called after the FastAPI routes (@app.get, etc.) that you want to expose as tools are defined. Otherwise, the tools won't be discovered.uvicorn) can hold ports. On Windows, netstat -ano | findstr "<PORT>" can find the Process ID (PID), and taskkill /F /PID <PID> can terminate it. Sometimes a short wait or restarting the IDE is needed for the OS to fully release the port.url key in .cursor/mcp.json connects Cursor to HTTP-based MCP servers (like the one provided by fastapi-mcp).mcp_local-fastapi-mcp_read_root__get) rather than a generic tool-calling function. Explicitly asking the agent in chat to "Use the tool..." works once the connection is established and the tool is discovered.This section summarizes features and concepts from the fastapi-mcp documentation that we haven't implemented yet but are useful to know.
fastapi-mcp supports using FastAPI dependencies for auth and also includes OAuth 2 support.
Basic Token Passthrough:
No special server config needed initially.
The MCP client needs to send the Authorization header. This can often be done via a bridge like mcp-remote:
{
"mcpServers": {
"remote-example": {
"command": "npx",
"args": [
"mcp-remote",
"http://localhost:8000/mcp",
"--header",
"Authorization:${AUTH_HEADER}"
]
},
"env": {
"AUTH_HEADER": "Bearer <your-token>"
}
}
}
To require auth on the MCP server side, add dependencies to AuthConfig:
from fastapi import Depends
from fastapi_mcp import FastApiMCP, AuthConfig
# Assuming verify_auth is your FastAPI dependency that checks the token
mcp = FastApiMCP(
app,
auth_config=AuthConfig(
dependencies=[Depends(verify_auth)],
),
)
OAuth 2 Flow:
AuthConfig with provider details (issuer, URLs, client ID/secret).setup_proxies=True is often needed to handle incompatibilities between standard OAuth providers and MCP client expectations (like missing dynamic registration, scope handling).
mcp = FastApiMCP(
app,
auth_config=AuthConfig(
issuer=f"https://auth.example.com/",
authorize_url=f"https://auth.example.com/authorize",
oauth_metadata_url=f"https://auth.example.com/.well-known/oauth-authorization-server",
audience="my-audience",
client_id="my-client-id",
client_secret="my-client-secret",
dependencies=[Depends(verify_auth)],
setup_proxies=True, # Creates compatibility endpoints
),
)
mcp-remote often requires specifying a fixed port (mcp-remote ... 8080) so the callback URL (http://127.0.0.1:8080/oauth/callback) can be configured in the OAuth provider.operation_id.read_user_users__user_id__get).operation_ids on FastAPI routes for clearer MCP tool names:
@app.get("/users/{user_id}", operation_id="get_user_info")
async def read_user(user_id: int):
# ...
If FastAPI routes are added after mcp.mount() is called, they won't be automatically included.
Solution: Call mcp.setup_server() again after defining the new routes.
app = FastAPI()
mcp = FastApiMCP(app)
mcp.mount()
@app.get("/new/endpoint", operation_id="new_tool")
async def new_endpoint(): ...
# Refresh the tools
mcp.setup_server()
@modelcontextprotocol/inspector tool can be used to test MCP servers:
# Run the inspector
npx @modelcontextprotocol/inspector
# Connect to your server URL (e.g., http://127.0.0.1:8000/mcp)
# Use the UI to list and run tools.
You can mount the MCP server created from one FastAPI app (api_app) onto a different FastAPI app (mcp_app) for separate deployment:
api_app = FastAPI()
# ... define API endpoints ...
mcp_app = FastAPI()
mcp = FastApiMCP(api_app) # Create from api_app
mcp.mount(mcp_app) # Mount onto mcp_app
# Run separately:
# uvicorn main:api_app --port 8001
# uvicorn main:mcp_app --port 8000
FastApiMCP initialization:
mcp = FastApiMCP(
app,
name="My Custom MCP Name",
description="Description for the server."
)
mcp = FastApiMCP(
app,
describe_all_responses=True,
describe_full_response_schema=True
)
include_operations, exclude_operations, include_tags, exclude_tags during FastApiMCP initialization.This project was developed with the assistance of AI pair programming tools, including Google's Gemini model integrated into Cursor and OpenAI's ChatGPT for research and documentation retrieval. Their contributions were invaluable throughout the process.
Claim this server with your GitHub account to request manual ownership verification.
Link to the catalog listing for FastAPI MCP Server Example from your README. This badge does not certify ownership, compatibility or security.
[](https://awesome-mcp.com/servers/sse-mcp-and-langchain-client-example)Public repository statistics could not be verified. Check the configured source address; unavailable counts are not zero.
Separate sources, scopes and periods. Never combined or treated as installations, active users or security reviews.
No reviewed package or image identity; download statistics are not listed yet.
Alternative and complementary servers in the same category

A directory listing describing a cancellation-letter and mailing-address service. The configured public GitHub repository returned 404 during source verification.

A hosted MCP service for browsing and searching through Singapore mobile-network proxies.

A directory listing describing a Markdown-to-PDF service. The configured public GitHub repository returned 404 during source verification.