FastMCP
hybrid server
The server is able to function both locally and remotely, depending on the configuration or use case.
Integrations
Supports loading environment variables from .env files when installing or running an MCP server
Mentioned as an optional dependency that can be included when deploying MCP servers
Mentioned as an optional dependency that can be included when deploying MCP servers
MCP Python SDK
Python implementation of the Model Context Protocol (MCP)
Table of Contents
- Overview
- Installation
- Quickstart
- What is MCP?
- Core Concepts
- Running Your Server
- Examples
- Advanced Usage
- Documentation
- Contributing
- License
Overview
The Model Context Protocol allows applications to provide context for LLMs in a standardized way, separating the concerns of providing context from the actual LLM interaction. This Python SDK implements the full MCP specification, making it easy to:
- Build MCP clients that can connect to any MCP server
- Create MCP servers that expose resources, prompts and tools
- Use standard transports like stdio and SSE
- Handle all MCP protocol messages and lifecycle events
Installation
We recommend using uv to manage your Python projects:
Alternatively:
Quickstart
Let's create a simple MCP server that exposes a calculator tool and some data:
You can install this server in Claude Desktop and interact with it right away by running:
Alternatively, you can test it with the MCP Inspector:
What is MCP?
The Model Context Protocol (MCP) lets you build servers that expose data and functionality to LLM applications in a secure, standardized way. Think of it like a web API, but specifically designed for LLM interactions. MCP servers can:
- Expose data through Resources (think of these sort of like GET endpoints; they are used to load information into the LLM's context)
- Provide functionality through Tools (sort of like POST endpoints; they are used to execute code or otherwise produce a side effect)
- Define interaction patterns through Prompts (reusable templates for LLM interactions)
- And more!
Core Concepts
Server
The FastMCP server is your core interface to the MCP protocol. It handles connection management, protocol compliance, and message routing:
Resources
Resources are how you expose data to LLMs. They're similar to GET endpoints in a REST API - they provide data but shouldn't perform significant computation or have side effects:
Tools
Tools let LLMs take actions through your server. Unlike resources, tools are expected to perform computation and have side effects:
Prompts
Prompts are reusable templates that help LLMs interact with your server effectively:
Images
FastMCP provides an Image
class that automatically handles image data:
Context
The Context object gives your tools and resources access to MCP capabilities:
Running Your Server
Development Mode
The fastest way to test and debug your server is with the MCP Inspector:
Claude Desktop Integration
Once your server is ready, install it in Claude Desktop:
Direct Execution
For advanced scenarios like custom deployments:
Run it with:
Examples
Echo Server
A simple server demonstrating resources, tools, and prompts:
SQLite Explorer
A more complex example showing database integration:
Advanced Usage
Low-Level Server
For more control, you can use the low-level server implementation directly. This gives you full access to the protocol and allows you to customize every aspect of your server:
Writing MCP Clients
The SDK provides a high-level client interface for connecting to MCP servers:
MCP Primitives
The MCP protocol defines three core primitives that servers can implement:
Primitive | Control | Description | Example Use |
---|---|---|---|
Prompts | User-controlled | Interactive templates invoked by user choice | Slash commands, menu options |
Resources | Application-controlled | Contextual data managed by the client application | File contents, API responses |
Tools | Model-controlled | Functions exposed to the LLM to take actions | API calls, data updates |
Server Capabilities
MCP servers declare capabilities during initialization:
Capability | Feature Flag | Description |
---|---|---|
prompts | listChanged | Prompt template management |
resources | subscribe listChanged | Resource exposure and updates |
tools | listChanged | Tool discovery and execution |
logging | - | Server logging configuration |
completion | - | Argument completion suggestions |
Documentation
- Model Context Protocol documentation
- Model Context Protocol specification
- Officially supported servers
Contributing
We are passionate about supporting contributors of all levels of experience and would love to see you get involved in the project. See the contributing guide to get started.
License
This project is licensed under the MIT License - see the LICENSE file for details.
This server cannot be installed
FastMCP is a comprehensive MCP server allowing secure and standardized data and functionality exposure to LLM applications, offering resources, tools, and prompt management for efficient LLM interactions.
- Table of Contents
- Overview
- Installation
- Quickstart
- What is MCP?
- Core Concepts
- Running Your Server
- Examples
- Advanced Usage
- Documentation
- Contributing
- License