FastMCP API can turn typed Python functions into tools, resources, and prompts with generated schemas.
What the Python SDK provides
You can use it to:- Create MCP servers with
FastMCP - Build lower-level servers for custom protocol behavior
- Define typed tools, resources, and prompts
- Build MCP clients with
ClientSession - Use
stdioand Streamable HTTP - Access logging, progress, sampling, and elicitation through request context
- Implement authentication for remote servers
Install the SDK
The official repository recommendsuv for project management:
pip:
Build a minimal MCP server
Createserver.py:
Add a resource
FastMCP uses URI templates for dynamic resources:greeting://Ada to receive Hello, Ada!.
Add a prompt
Build a minimal MCP client
Createclient.py:
add.
Use context in a tool
A handler can request a FastMCP context object to access request-scoped features.Organize a production server
A maintainable project can separate MCP definitions from business services:Choose a transport
For a remote server, follow the SDK version’s current Streamable HTTP and authentication guidance. Do not use legacy SSE for a new deployment unless compatibility requires it.
Read MCP transports and Remote MCP servers.
Production safeguards
- Validate model-provided and client-provided input.
- Authenticate and authorize each protected operation.
- Use timeouts for HTTP and database calls.
- Apply concurrency and rate limits.
- Avoid blocking the event loop in async handlers.
- Return safe, actionable errors.
- Keep credentials out of prompts, results, and logs.
- Add health checks, metrics, tracing, and audit events.
- Pin and regularly update dependencies.
Test with MCP Inspector
Run:When to use 0mcp instead
If your server primarily exposes an existing API, 0mcp can remove the need to write and operate the MCP translation layer yourself. 0mcp supports:- OpenAPI 3.x and Swagger 2.0 import
- Direct REST API-to-MCP conversion without an OpenAPI document
- GraphQL API-to-MCP conversion
- Hosted MCP endpoints, tools, resources, and prompts
- Playground testing, versioning, rollback, analytics, and logs
When to use Python
Python is a strong choice when the server needs:- Data processing
- Machine-learning libraries
- Existing Python business logic
- Rapid service development
- Async HTTP or database integrations