Spaces:
Running
Running
Jeremiah Lowin commited on
Commit ยท
ae8354f
1
Parent(s): 83a905a
Update docs for clarity
Browse files- README.md +194 -597
- docs/getting-started/installation.mdx +37 -5
- docs/getting-started/welcome.mdx +16 -8
README.md
CHANGED
|
@@ -12,6 +12,17 @@
|
|
| 12 |
<a href="https://trendshift.io/repositories/13266" target="_blank"><img src="https://trendshift.io/api/badge/repositories/13266" alt="jlowin%2Ffastmcp | Trendshift" style="width: 250px; height: 55px;" width="250" height="55"/></a>
|
| 13 |
</div>
|
| 14 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 15 |
The [Model Context Protocol (MCP)](https://modelcontextprotocol.io) is a new, standardized way to provide context and tools to your LLMs, and FastMCP makes building MCP servers and clients simple and intuitive. Create tools, expose resources, define prompts, and connect components with clean, Pythonic code.
|
| 16 |
|
| 17 |
```python
|
|
@@ -29,64 +40,50 @@ if __name__ == "__main__":
|
|
| 29 |
mcp.run()
|
| 30 |
```
|
| 31 |
|
| 32 |
-
|
| 33 |
Run the server locally:
|
| 34 |
```bash
|
| 35 |
fastmcp run server.py
|
| 36 |
```
|
| 37 |
|
| 38 |
-
|
|
|
|
|
|
|
| 39 |
|
|
|
|
| 40 |
|
| 41 |
<!-- omit in toc -->
|
| 42 |
## Table of Contents
|
| 43 |
|
| 44 |
- [What is MCP?](#what-is-mcp)
|
| 45 |
- [Why FastMCP?](#why-fastmcp)
|
| 46 |
-
- [
|
| 47 |
-
- [Servers](#servers)
|
| 48 |
-
- [Clients](#clients)
|
| 49 |
-
- [What's New in v2?](#whats-new-in-v2)
|
| 50 |
-
- [Documentation](#documentation)
|
| 51 |
-
- [Installation](#installation)
|
| 52 |
-
- [Quickstart](#quickstart)
|
| 53 |
- [Core Concepts](#core-concepts)
|
| 54 |
- [The `FastMCP` Server](#the-fastmcp-server)
|
| 55 |
- [Tools](#tools)
|
| 56 |
-
- [Resources](#resources)
|
| 57 |
- [Prompts](#prompts)
|
| 58 |
- [Context](#context)
|
| 59 |
-
- [Images](#images)
|
| 60 |
- [MCP Clients](#mcp-clients)
|
| 61 |
-
- [Client Methods](#client-methods)
|
| 62 |
-
- [Transport Options](#transport-options)
|
| 63 |
-
- [LLM Sampling](#llm-sampling)
|
| 64 |
-
- [Roots Access](#roots-access)
|
| 65 |
- [Advanced Features](#advanced-features)
|
| 66 |
- [Proxy Servers](#proxy-servers)
|
| 67 |
- [Composing MCP Servers](#composing-mcp-servers)
|
| 68 |
- [OpenAPI \& FastAPI Generation](#openapi--fastapi-generation)
|
| 69 |
-
- [Handling `stderr`](#handling-stderr)
|
| 70 |
- [Running Your Server](#running-your-server)
|
| 71 |
-
- [Development Mode (Recommended for Building \& Testing)](#development-mode-recommended-for-building--testing)
|
| 72 |
-
- [Claude Desktop Integration (For Regular Use)](#claude-desktop-integration-for-regular-use)
|
| 73 |
-
- [Direct Execution (For Advanced Use Cases)](#direct-execution-for-advanced-use-cases)
|
| 74 |
-
- [Server Object Names](#server-object-names)
|
| 75 |
-
- [Examples](#examples)
|
| 76 |
- [Contributing](#contributing)
|
| 77 |
-
|
| 78 |
-
|
| 79 |
-
|
| 80 |
-
|
| 81 |
-
|
| 82 |
|
|
|
|
| 83 |
|
| 84 |
## What is MCP?
|
| 85 |
|
| 86 |
The [Model Context Protocol (MCP)](https://modelcontextprotocol.io) 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:
|
| 87 |
|
| 88 |
-
- Expose data through **Resources** (
|
| 89 |
-
- Provide functionality through **Tools** (
|
| 90 |
- Define interaction patterns through **Prompts** (reusable templates)
|
| 91 |
- And more!
|
| 92 |
|
|
@@ -96,8 +93,9 @@ FastMCP provides a high-level, Pythonic interface for building and interacting w
|
|
| 96 |
|
| 97 |
The MCP protocol is powerful but implementing it involves a lot of boilerplate - server setup, protocol handlers, content types, error management. FastMCP handles all the complex protocol details and server management, so you can focus on building great tools. It's designed to be high-level and Pythonic; in most cases, decorating a function is all you need.
|
| 98 |
|
| 99 |
-
FastMCP
|
| 100 |
|
|
|
|
| 101 |
|
| 102 |
๐ **Fast:** High-level interface means less code and faster development
|
| 103 |
|
|
@@ -107,675 +105,274 @@ FastMCP aims to be:
|
|
| 107 |
|
| 108 |
๐ **Complete:** FastMCP aims to provide a full implementation of the core MCP specification for both servers and clients
|
| 109 |
|
| 110 |
-
##
|
| 111 |
-
|
| 112 |
-
### Servers
|
| 113 |
-
- **Create** servers with minimal boilerplate using intuitive decorators
|
| 114 |
-
- **Proxy** existing servers to modify configuration or transport
|
| 115 |
-
- **Compose** servers into complex applications
|
| 116 |
-
- **Generate** servers from OpenAPI specs or FastAPI objects
|
| 117 |
-
|
| 118 |
-
### Clients
|
| 119 |
-
- **Interact** with MCP servers programmatically
|
| 120 |
-
- **Connect** to any MCP server using any transport
|
| 121 |
-
- **Test** your servers without manual intervention
|
| 122 |
-
- **Innovate** with core MCP capabilities like LLM sampling
|
| 123 |
-
|
| 124 |
|
| 125 |
-
|
| 126 |
-
|
| 127 |
-
FastMCP 1.0 made it so easy to build MCP servers that it's now part of the [official Model Context Protocol Python SDK](https://github.com/modelcontextprotocol/python-sdk)! For basic use cases, you can use the upstream version by importing `mcp.server.fastmcp.FastMCP` (or installing `fastmcp=1.0`).
|
| 128 |
-
|
| 129 |
-
Based on how the MCP ecosystem is evolving, FastMCP 2.0 builds on that foundation to introduce a variety of new features (and more experimental ideas). It adds advanced features like proxying and composing MCP servers, as well as automatically generating them from OpenAPI specs or FastAPI objects. FastMCP 2.0 also introduces new client-side functionality like LLM sampling.
|
| 130 |
-
|
| 131 |
-
|
| 132 |
-
## Documentation
|
| 133 |
-
|
| 134 |
-
๐ FastMCP's documentation is available at [gofastmcp.com](https://gofastmcp.com).
|
| 135 |
-
|
| 136 |
-
---
|
| 137 |
-
|
| 138 |
-
### Installation
|
| 139 |
-
|
| 140 |
-
We strongly recommend installing FastMCP with [uv](https://docs.astral.sh/uv/), as it is required for deploying servers via the CLI:
|
| 141 |
|
| 142 |
```bash
|
| 143 |
uv pip install fastmcp
|
| 144 |
```
|
| 145 |
|
| 146 |
-
|
| 147 |
-
|
| 148 |
-
For development, install with:
|
| 149 |
-
```bash
|
| 150 |
-
# Clone the repo first
|
| 151 |
-
git clone https://github.com/jlowin/fastmcp.git
|
| 152 |
-
cd fastmcp
|
| 153 |
-
# Install with dev dependencies
|
| 154 |
-
uv sync
|
| 155 |
-
```
|
| 156 |
-
|
| 157 |
-
### Quickstart
|
| 158 |
-
|
| 159 |
-
Let's create a simple MCP server that exposes a calculator tool and some data:
|
| 160 |
-
|
| 161 |
-
```python
|
| 162 |
-
# server.py
|
| 163 |
-
from fastmcp import FastMCP
|
| 164 |
-
|
| 165 |
-
# Create an MCP server
|
| 166 |
-
mcp = FastMCP("Demo")
|
| 167 |
-
|
| 168 |
-
# Add an addition tool
|
| 169 |
-
@mcp.tool()
|
| 170 |
-
def add(a: int, b: int) -> int:
|
| 171 |
-
"""Add two numbers"""
|
| 172 |
-
return a + b
|
| 173 |
-
|
| 174 |
-
# Add a dynamic greeting resource
|
| 175 |
-
@mcp.resource("greeting://{name}")
|
| 176 |
-
def get_greeting(name: str) -> str:
|
| 177 |
-
"""Get a personalized greeting"""
|
| 178 |
-
return f"Hello, {name}!"
|
| 179 |
-
```
|
| 180 |
-
|
| 181 |
-
You can install this server in [Claude Desktop](https://claude.ai/download) and interact with it right away by running:
|
| 182 |
-
```bash
|
| 183 |
-
fastmcp install server.py
|
| 184 |
-
```
|
| 185 |
-
|
| 186 |
-

|
| 187 |
-
|
| 188 |
|
| 189 |
## Core Concepts
|
| 190 |
|
| 191 |
-
These are the building blocks for creating MCP servers
|
| 192 |
|
| 193 |
### The `FastMCP` Server
|
| 194 |
|
| 195 |
-
The central object representing your MCP application. It
|
| 196 |
|
| 197 |
```python
|
| 198 |
from fastmcp import FastMCP
|
| 199 |
|
| 200 |
-
# Create a
|
| 201 |
-
mcp = FastMCP("
|
| 202 |
-
|
| 203 |
-
# Specify dependencies needed when deployed via `fastmcp install`
|
| 204 |
-
mcp = FastMCP("My App", dependencies=["pandas", "numpy"])
|
| 205 |
```
|
| 206 |
|
| 207 |
-
|
| 208 |
|
| 209 |
-
|
| 210 |
|
| 211 |
-
|
| 212 |
|
| 213 |
```python
|
| 214 |
-
import httpx
|
| 215 |
-
from pydantic import BaseModel
|
| 216 |
-
|
| 217 |
-
class UserInfo(BaseModel):
|
| 218 |
-
user_id: int
|
| 219 |
-
notify: bool = False
|
| 220 |
-
|
| 221 |
@mcp.tool()
|
| 222 |
-
|
| 223 |
-
"""
|
| 224 |
-
|
| 225 |
-
# Simulate sending notification
|
| 226 |
-
print(f"Notifying user {user.user_id}: {message}")
|
| 227 |
-
return {"status": "sent", "user_id": user.user_id}
|
| 228 |
-
return {"status": "skipped", "user_id": user.user_id}
|
| 229 |
-
|
| 230 |
-
@mcp.tool()
|
| 231 |
-
def get_stock_price(ticker: str) -> float:
|
| 232 |
-
"""Gets the current price for a stock ticker."""
|
| 233 |
-
# Replace with actual API call
|
| 234 |
-
prices = {"AAPL": 180.50, "GOOG": 140.20}
|
| 235 |
-
return prices.get(ticker.upper(), 0.0)
|
| 236 |
```
|
| 237 |
|
| 238 |
-
|
| 239 |
|
| 240 |
-
Resources
|
| 241 |
|
| 242 |
-
|
| 243 |
|
| 244 |
```python
|
| 245 |
-
# Static resource
|
| 246 |
-
@mcp.resource("config://
|
| 247 |
-
def
|
| 248 |
-
|
| 249 |
-
|
| 250 |
-
|
| 251 |
-
|
| 252 |
-
|
| 253 |
-
|
| 254 |
-
"""
|
| 255 |
-
# Replace with actual database lookup
|
| 256 |
-
emails = {"123": "alice@example.com", "456": "bob@example.com"}
|
| 257 |
-
return emails.get(user_id, "not_found@example.com")
|
| 258 |
-
|
| 259 |
-
# Resource returning JSON data
|
| 260 |
-
@mcp.resource("data://product-categories")
|
| 261 |
-
def get_categories() -> list[str]:
|
| 262 |
-
"""Returns a list of available product categories."""
|
| 263 |
-
return ["Electronics", "Books", "Home Goods"]
|
| 264 |
```
|
| 265 |
|
| 266 |
-
|
| 267 |
|
| 268 |
-
|
| 269 |
|
| 270 |
-
Decorate functions with `@mcp.prompt()`.
|
| 271 |
|
| 272 |
```python
|
| 273 |
-
from fastmcp.prompts.base import UserMessage, AssistantMessage
|
| 274 |
-
|
| 275 |
@mcp.prompt()
|
| 276 |
-
def
|
| 277 |
-
"""
|
| 278 |
-
return f"Please
|
| 279 |
-
|
| 280 |
-
@mcp.prompt()
|
| 281 |
-
def debug_session_start(error_message: str) -> list[Message]:
|
| 282 |
-
"""Initiates a debugging help session."""
|
| 283 |
-
return [
|
| 284 |
-
UserMessage(f"I encountered an error:\n{error_message}"),
|
| 285 |
-
AssistantMessage("Okay, I can help with that. Can you provide the full traceback and tell me what you were trying to do?")
|
| 286 |
-
]
|
| 287 |
-
```
|
| 288 |
-
|
| 289 |
-
### Context
|
| 290 |
-
|
| 291 |
-
Gain access to MCP server capabilities *within* your tool or resource functions by adding a parameter type-hinted with `fastmcp.Context`.
|
| 292 |
-
|
| 293 |
-
```python
|
| 294 |
-
from fastmcp import Context, FastMCP
|
| 295 |
-
|
| 296 |
-
mcp = FastMCP("Context Demo")
|
| 297 |
-
|
| 298 |
-
@mcp.resource("system://status")
|
| 299 |
-
async def get_system_status(ctx: Context) -> dict:
|
| 300 |
-
"""Checks system status and logs information."""
|
| 301 |
-
await ctx.info("Checking system status...")
|
| 302 |
-
# Perform checks
|
| 303 |
-
await ctx.report_progress(1, 1) # Report completion
|
| 304 |
-
return {"status": "OK", "load": 0.5, "client": ctx.client_id}
|
| 305 |
-
|
| 306 |
-
@mcp.tool()
|
| 307 |
-
async def process_large_file(file_uri: str, ctx: Context) -> str:
|
| 308 |
-
"""Processes a large file, reporting progress and reading resources."""
|
| 309 |
-
await ctx.info(f"Starting processing for {file_uri}")
|
| 310 |
-
# Read the resource using the context
|
| 311 |
-
file_content_resource = await ctx.read_resource(file_uri)
|
| 312 |
-
file_content = file_content_resource[0].content # Assuming single text content
|
| 313 |
-
lines = file_content.splitlines()
|
| 314 |
-
total_lines = len(lines)
|
| 315 |
-
|
| 316 |
-
for i, line in enumerate(lines):
|
| 317 |
-
# Process line...
|
| 318 |
-
if (i + 1) % 100 == 0: # Report progress every 100 lines
|
| 319 |
-
await ctx.report_progress(i + 1, total_lines)
|
| 320 |
-
|
| 321 |
-
await ctx.info(f"Finished processing {file_uri}")
|
| 322 |
-
return f"Processed {total_lines} lines."
|
| 323 |
-
|
| 324 |
```
|
| 325 |
|
| 326 |
-
|
| 327 |
-
* Logging: `ctx.debug()`, `ctx.info()`, `ctx.warning()`, `ctx.error()`
|
| 328 |
-
* Progress Reporting: `ctx.report_progress(current, total)`
|
| 329 |
-
* Resource Access: `await ctx.read_resource(uri)`
|
| 330 |
-
* Request Info: `ctx.request_id`, `ctx.client_id`
|
| 331 |
-
* Sampling (Advanced): `await ctx.sample(...)` to ask the connected LLM client for completions.
|
| 332 |
|
| 333 |
-
###
|
| 334 |
|
| 335 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 336 |
|
| 337 |
-
|
| 338 |
-
The below code requires the `pillow` library to be installed.
|
| 339 |
-
</Tip>
|
| 340 |
|
| 341 |
```python
|
| 342 |
-
from
|
| 343 |
-
from io import BytesIO
|
| 344 |
-
try:
|
| 345 |
-
from PIL import Image as PILImage
|
| 346 |
-
except ImportError:
|
| 347 |
-
raise ImportError("Please install the `pillow` library to run this example.")
|
| 348 |
|
| 349 |
-
mcp = FastMCP("My
|
| 350 |
|
| 351 |
@mcp.tool()
|
| 352 |
-
def
|
| 353 |
-
|
| 354 |
-
|
| 355 |
-
img.thumbnail((100, 100))
|
| 356 |
-
buffer = BytesIO()
|
| 357 |
-
img.save(buffer, format="PNG")
|
| 358 |
-
return Image(data=buffer.getvalue(), format="png")
|
| 359 |
-
```
|
| 360 |
-
Return the `Image` helper class from your tool to send an image to the client. The `Image` helper class handles the conversion to/from the base64-encoded format required by the MCP protocol. It works with either a path to an image file, or a bytes object.
|
| 361 |
-
|
| 362 |
-
|
| 363 |
-
### MCP Clients
|
| 364 |
|
| 365 |
-
|
|
|
|
| 366 |
|
| 367 |
-
|
| 368 |
-
|
| 369 |
|
| 370 |
-
|
| 371 |
-
|
| 372 |
-
result = await client.call_tool("weather", {"location": "San Francisco"})
|
| 373 |
-
print(result)
|
| 374 |
-
|
| 375 |
-
# Read a resource
|
| 376 |
-
res = await client.read_resource("db://users/123/profile")
|
| 377 |
-
print(res)
|
| 378 |
```
|
| 379 |
|
| 380 |
-
|
| 381 |
-
|
| 382 |
-
#### Client Methods
|
| 383 |
-
|
| 384 |
-
The `Client` class exposes several methods for interacting with MCP servers.
|
| 385 |
-
|
| 386 |
-
```python
|
| 387 |
-
async with Client("path/to/server") as client:
|
| 388 |
-
# List available tools
|
| 389 |
-
tools = await client.list_tools()
|
| 390 |
-
|
| 391 |
-
# List available resources
|
| 392 |
-
resources = await client.list_resources()
|
| 393 |
-
|
| 394 |
-
# Call a tool with arguments
|
| 395 |
-
result = await client.call_tool("generate_report", {"user_id": 123})
|
| 396 |
-
|
| 397 |
-
# Read a resource
|
| 398 |
-
user_data = await client.read_resource("db://users/123/profile")
|
| 399 |
-
|
| 400 |
-
# Get a prompt
|
| 401 |
-
greeting = await client.get_prompt("welcome", {"name": "Alice"})
|
| 402 |
-
|
| 403 |
-
# Send progress updates
|
| 404 |
-
await client.progress("task-123", 50, 100) # 50% complete
|
| 405 |
-
|
| 406 |
-
# Basic connectivity testing
|
| 407 |
-
await client.ping()
|
| 408 |
-
```
|
| 409 |
|
| 410 |
-
|
| 411 |
|
| 412 |
-
|
| 413 |
|
| 414 |
-
|
| 415 |
|
| 416 |
```python
|
| 417 |
from fastmcp import Client
|
| 418 |
-
from fastmcp.client.transports import (
|
| 419 |
-
SSETransport,
|
| 420 |
-
PythonStdioTransport,
|
| 421 |
-
FastMCPTransport
|
| 422 |
-
)
|
| 423 |
-
|
| 424 |
-
# Connect to a server over SSE (common for web-based MCP servers)
|
| 425 |
-
async with Client(SSETransport("http://localhost:8000/mcp")) as client:
|
| 426 |
-
# Use client here...
|
| 427 |
-
|
| 428 |
-
# Connect to a Python script using stdio (useful for local tools)
|
| 429 |
-
async with Client(PythonStdioTransport("path/to/script.py")) as client:
|
| 430 |
-
# Use client here...
|
| 431 |
-
|
| 432 |
-
# Connect directly to a FastMCP server object in the same process
|
| 433 |
-
from your_app import mcp_server
|
| 434 |
-
async with Client(FastMCPTransport(mcp_server)) as client:
|
| 435 |
-
# Use client here...
|
| 436 |
-
```
|
| 437 |
-
|
| 438 |
-
Common transport options include:
|
| 439 |
-
- `SSETransport`: Connect to a server via Server-Sent Events (HTTP)
|
| 440 |
-
- `PythonStdioTransport`: Run a Python script and communicate via stdio
|
| 441 |
-
- `FastMCPTransport`: Connect directly to a FastMCP server object
|
| 442 |
-
- `WSTransport`: Connect via WebSockets
|
| 443 |
-
|
| 444 |
-
In addition, if you pass a connection string or `FastMCP` server object to the `Client` constructor, it will try to automatically detect the appropriate transport.
|
| 445 |
-
|
| 446 |
-
#### LLM Sampling
|
| 447 |
-
|
| 448 |
-
Sampling is an MCP feature that allows a server to request a completion from the client LLM, enabling sophisticated use cases while maintaining security and privacy on the server.
|
| 449 |
|
| 450 |
-
|
| 451 |
-
|
| 452 |
-
|
| 453 |
-
|
| 454 |
-
|
| 455 |
-
|
| 456 |
-
|
| 457 |
-
|
| 458 |
-
|
| 459 |
-
|
| 460 |
-
|
| 461 |
-
|
| 462 |
-
"""Generate a short poem about the given topic."""
|
| 463 |
-
# The server requests a completion from the client LLM
|
| 464 |
-
response = await context.sample(
|
| 465 |
-
f"Write a short poem about {topic}",
|
| 466 |
-
system_prompt="You are a talented poet who writes concise, evocative verses."
|
| 467 |
-
)
|
| 468 |
-
return response.text
|
| 469 |
-
|
| 470 |
-
@mcp.tool()
|
| 471 |
-
async def summarize_document(document_uri: str, context: Context) -> str:
|
| 472 |
-
"""Summarize a document using client-side LLM capabilities."""
|
| 473 |
-
# First read the document as a resource
|
| 474 |
-
doc_resource = await context.read_resource(document_uri)
|
| 475 |
-
doc_content = doc_resource[0].content # Assuming single text content
|
| 476 |
-
|
| 477 |
-
# Then ask the client LLM to summarize it
|
| 478 |
-
response = await context.sample(
|
| 479 |
-
f"Summarize the following document:\n\n{doc_content}",
|
| 480 |
-
system_prompt="You are an expert summarizer. Create a concise summary."
|
| 481 |
-
)
|
| 482 |
-
return response.text
|
| 483 |
-
|
| 484 |
-
# -- CLIENT SIDE --
|
| 485 |
-
# Create a client that handles the sampling requests
|
| 486 |
-
|
| 487 |
-
async def sampling_handler(
|
| 488 |
-
messages: list[SamplingMessage],
|
| 489 |
-
params: SamplingParams,
|
| 490 |
-
ctx: RequestContext,
|
| 491 |
-
) -> str:
|
| 492 |
-
"""Handle sampling requests from the server using your preferred LLM."""
|
| 493 |
-
# Extract the messages and system prompt
|
| 494 |
-
prompt = [m.content.text for m in messages if m.content.type == "text"]
|
| 495 |
-
system_instruction = params.systemPrompt or "You are a helpful assistant."
|
| 496 |
-
|
| 497 |
-
# Use your preferred LLM client to generate completions
|
| 498 |
-
return await marvin.say_async(
|
| 499 |
-
message=prompt,
|
| 500 |
-
instructions=system_instruction,
|
| 501 |
-
)
|
| 502 |
-
|
| 503 |
-
# Connect them together
|
| 504 |
-
async with Client(mcp, sampling_handler=sampling_handler) as client:
|
| 505 |
-
result = await client.call_tool("generate_poem", {"topic": "autumn leaves"})
|
| 506 |
-
print(result.content[0].text)
|
| 507 |
```
|
| 508 |
|
| 509 |
-
|
| 510 |
-
1. The server can delegate text generation to the client LLM
|
| 511 |
-
2. The server remains focused on business logic and data handling
|
| 512 |
-
3. The client maintains control over which LLM is used and how requests are handled
|
| 513 |
-
4. No sensitive data needs to be sent to external APIs
|
| 514 |
-
|
| 515 |
-
#### Roots Access
|
| 516 |
-
|
| 517 |
-
FastMCP exposes the MCP roots functionality, allowing clients to specify which file system roots they can access. This creates a secure boundary for tools that need to work with files. Note that the server must account for client roots explicitly.
|
| 518 |
|
| 519 |
```python
|
| 520 |
-
from fastmcp import
|
| 521 |
|
| 522 |
-
|
| 523 |
-
roots = ["file:///path/to/allowed/directory"]
|
| 524 |
|
| 525 |
-
async
|
| 526 |
-
#
|
| 527 |
-
|
|
|
|
| 528 |
```
|
| 529 |
|
| 530 |
-
|
| 531 |
|
| 532 |
-
|
| 533 |
|
|
|
|
| 534 |
|
| 535 |
### Proxy Servers
|
| 536 |
|
| 537 |
-
Create a FastMCP server that acts as an intermediary
|
| 538 |
-
|
| 539 |
-
**Use Cases:**
|
| 540 |
-
|
| 541 |
-
* **Transport Conversion:** Expose a server running on Stdio (like many local tools) over SSE or WebSockets, making it accessible to web clients or Claude Desktop.
|
| 542 |
-
* **Adding Functionality:** Wrap an existing server to add authentication, request logging, or modified tool behavior.
|
| 543 |
-
* **Aggregating Servers:** Combine multiple backend MCP servers behind a single proxy interface (though `mount` might be simpler for this).
|
| 544 |
-
|
| 545 |
-
```python
|
| 546 |
-
import asyncio
|
| 547 |
-
from fastmcp import FastMCP, Client
|
| 548 |
-
from fastmcp.client.transports import PythonStdioTransport
|
| 549 |
-
|
| 550 |
-
# Create a client that connects to the original server
|
| 551 |
-
proxy_client = Client(
|
| 552 |
-
transport=PythonStdioTransport('path/to/original_stdio_server.py'),
|
| 553 |
-
)
|
| 554 |
-
|
| 555 |
-
# Create a proxy server that connects to the client and exposes its capabilities
|
| 556 |
-
proxy = FastMCP.from_client(proxy_client, name="Stdio-to-SSE Proxy")
|
| 557 |
-
|
| 558 |
-
if __name__ == "__main__":
|
| 559 |
-
proxy.run(transport='sse')
|
| 560 |
-
```
|
| 561 |
-
|
| 562 |
-
`FastMCP.from_client` is a class method that connects to the target, discovers its capabilities, and dynamically builds the proxy server instance.
|
| 563 |
-
|
| 564 |
|
|
|
|
| 565 |
|
| 566 |
### Composing MCP Servers
|
| 567 |
|
| 568 |
-
|
| 569 |
-
|
| 570 |
-
```python
|
| 571 |
-
from fastmcp import FastMCP
|
| 572 |
-
|
| 573 |
-
# --- Weather MCP ---
|
| 574 |
-
weather_mcp = FastMCP("Weather Service")
|
| 575 |
-
|
| 576 |
-
@weather_mcp.tool()
|
| 577 |
-
def get_forecast(city: str):
|
| 578 |
-
return f"Sunny in {city}"
|
| 579 |
-
|
| 580 |
-
@weather_mcp.resource("data://temp/{city}")
|
| 581 |
-
def get_temp(city: str):
|
| 582 |
-
return 25.0
|
| 583 |
-
|
| 584 |
-
# --- News MCP ---
|
| 585 |
-
news_mcp = FastMCP("News Service")
|
| 586 |
-
|
| 587 |
-
@news_mcp.tool()
|
| 588 |
-
def fetch_headlines():
|
| 589 |
-
return ["Big news!", "Other news"]
|
| 590 |
-
|
| 591 |
-
@news_mcp.resource("data://latest_story")
|
| 592 |
-
def get_story():
|
| 593 |
-
return "A story happened."
|
| 594 |
-
|
| 595 |
-
# --- Composite MCP ---
|
| 596 |
-
|
| 597 |
-
mcp = FastMCP("Composite")
|
| 598 |
-
|
| 599 |
-
# Mount sub-apps with prefixes
|
| 600 |
-
mcp.mount("weather", weather_mcp) # Tools prefixed "weather/", resources prefixed "weather+"
|
| 601 |
-
mcp.mount("news", news_mcp) # Tools prefixed "news/", resources prefixed "news+"
|
| 602 |
-
|
| 603 |
-
@mcp.tool()
|
| 604 |
-
def ping():
|
| 605 |
-
return "Composite OK"
|
| 606 |
-
|
| 607 |
-
|
| 608 |
-
if __name__ == "__main__":
|
| 609 |
-
mcp.run()
|
| 610 |
-
```
|
| 611 |
|
| 612 |
-
|
| 613 |
|
| 614 |
### OpenAPI & FastAPI Generation
|
| 615 |
|
| 616 |
-
|
| 617 |
-
|
| 618 |
-
By default, the following rules are applied:
|
| 619 |
-
- `GET` requests -> MCP resources
|
| 620 |
-
- `GET` requests with path parameters -> MCP resource templates
|
| 621 |
-
- All other HTTP methods -> MCP tools
|
| 622 |
-
|
| 623 |
-
You can override these rules to customize or even ignore certain endpoints.
|
| 624 |
-
|
| 625 |
-
**From FastAPI:**
|
| 626 |
-
|
| 627 |
-
```python
|
| 628 |
-
from fastapi import FastAPI
|
| 629 |
-
from fastmcp import FastMCP
|
| 630 |
-
|
| 631 |
-
# Your existing FastAPI application
|
| 632 |
-
fastapi_app = FastAPI(title="My Existing API")
|
| 633 |
|
| 634 |
-
|
| 635 |
-
def get_status():
|
| 636 |
-
return {"status": "running"}
|
| 637 |
-
|
| 638 |
-
@fastapi_app.post("/items")
|
| 639 |
-
def create_item(name: str, price: float):
|
| 640 |
-
return {"id": 1, "name": name, "price": price}
|
| 641 |
-
|
| 642 |
-
# Generate an MCP server directly from the FastAPI app
|
| 643 |
-
mcp_server = FastMCP.from_fastapi(fastapi_app)
|
| 644 |
-
|
| 645 |
-
if __name__ == "__main__":
|
| 646 |
-
mcp_server.run()
|
| 647 |
-
```
|
| 648 |
-
|
| 649 |
-
**From an OpenAPI Specification:**
|
| 650 |
-
|
| 651 |
-
```python
|
| 652 |
-
import httpx
|
| 653 |
-
import json
|
| 654 |
-
from fastmcp import FastMCP
|
| 655 |
-
|
| 656 |
-
# Load the OpenAPI spec (dict)
|
| 657 |
-
# with open("my_api_spec.json", "r") as f:
|
| 658 |
-
# openapi_spec = json.load(f)
|
| 659 |
-
openapi_spec = { ... } # Your spec dict
|
| 660 |
-
|
| 661 |
-
# Create an HTTP client to make requests to the actual API endpoint
|
| 662 |
-
http_client = httpx.AsyncClient(base_url="https://api.yourservice.com")
|
| 663 |
-
|
| 664 |
-
# Generate the MCP server
|
| 665 |
-
mcp_server = FastMCP.from_openapi(openapi_spec, client=http_client)
|
| 666 |
-
|
| 667 |
-
if __name__ == "__main__":
|
| 668 |
-
mcp_server.run()
|
| 669 |
-
```
|
| 670 |
-
|
| 671 |
-
### Handling `stderr`
|
| 672 |
-
The MCP spec allows for the server to write anything it wants to `stderr`, and it
|
| 673 |
-
doesn't specify the format in any way. FastMCP will forward the server's `stderr`
|
| 674 |
-
to the client's `stderr`.
|
| 675 |
|
| 676 |
## Running Your Server
|
| 677 |
|
| 678 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 679 |
|
| 680 |
-
### Development Mode (Recommended for Building & Testing)
|
| 681 |
|
| 682 |
-
|
| 683 |
|
| 684 |
-
|
| 685 |
-
fastmcp dev your_server_file.py
|
| 686 |
-
# With temporary dependencies
|
| 687 |
-
fastmcp dev your_server_file.py --with pandas --with numpy
|
| 688 |
-
# With local package in editable mode
|
| 689 |
-
fastmcp dev your_server_file.py --with-editable .
|
| 690 |
-
```
|
| 691 |
|
| 692 |
-
###
|
| 693 |
|
| 694 |
-
|
|
|
|
| 695 |
|
| 696 |
-
|
| 697 |
-
fastmcp install your_server_file.py
|
| 698 |
-
# With a custom name in Claude
|
| 699 |
-
fastmcp install your_server_file.py --name "My Analysis Tool"
|
| 700 |
-
# With extra packages and environment variables
|
| 701 |
-
fastmcp install server.py --with requests -v API_KEY=123 -f .env
|
| 702 |
-
```
|
| 703 |
|
| 704 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 705 |
|
| 706 |
-
|
| 707 |
|
| 708 |
-
|
| 709 |
-
|
| 710 |
-
|
| 711 |
-
mcp.run() # Assuming 'mcp' is your FastMCP instance
|
| 712 |
-
```
|
| 713 |
-
Run with:
|
| 714 |
```bash
|
| 715 |
-
|
| 716 |
-
# or
|
| 717 |
-
uv run python your_server_file.py
|
| 718 |
```
|
| 719 |
|
| 720 |
-
###
|
| 721 |
|
| 722 |
-
|
| 723 |
|
|
|
|
| 724 |
```bash
|
| 725 |
-
|
| 726 |
-
fastmcp install api.py:api_app
|
| 727 |
```
|
| 728 |
-
|
| 729 |
-
## Examples
|
| 730 |
-
|
| 731 |
-
Explore the `examples/` directory for code samples demonstrating various features:
|
| 732 |
-
|
| 733 |
-
* `simple_echo.py`: Basic tool, resource, and prompt.
|
| 734 |
-
* `complex_inputs.py`: Using Pydantic models for tool inputs.
|
| 735 |
-
* `mount_example.py`: Mounting multiple FastMCP servers.
|
| 736 |
-
* `sampling.py`: Using LLM completions within your MCP server.
|
| 737 |
-
* `screenshot.py`: Tool returning an Image object.
|
| 738 |
-
* `text_me.py`: Tool interacting with an external API.
|
| 739 |
-
* `memory.py`: More complex example with database interaction.
|
| 740 |
-
|
| 741 |
-
## Contributing
|
| 742 |
-
|
| 743 |
-
Contributions make the open-source community vibrant! We welcome improvements and features.
|
| 744 |
-
|
| 745 |
-
<details>
|
| 746 |
-
|
| 747 |
-
<summary><h3>Open Developer Guide</h3></summary>
|
| 748 |
-
|
| 749 |
-
#### Prerequisites
|
| 750 |
-
|
| 751 |
-
* Python 3.10+
|
| 752 |
-
* [uv](https://docs.astral.sh/uv/)
|
| 753 |
-
|
| 754 |
-
#### Setup
|
| 755 |
-
|
| 756 |
-
1. Clone: `git clone https://github.com/jlowin/fastmcp.git && cd fastmcp`
|
| 757 |
-
2. Install Env & Dependencies: `uv venv && uv sync` (Activate the `.venv` after creation)
|
| 758 |
-
|
| 759 |
-
#### Testing
|
| 760 |
-
|
| 761 |
-
Run the test suite:
|
| 762 |
```bash
|
| 763 |
-
|
|
|
|
|
|
|
| 764 |
```
|
| 765 |
|
| 766 |
-
###
|
| 767 |
-
|
| 768 |
-
We use `ruff` via `pre-commit`.
|
| 769 |
-
1. Install hooks: `pre-commit install`
|
| 770 |
-
2. Run checks: `pre-commit run --all-files`
|
| 771 |
-
|
| 772 |
-
#### Pull Requests
|
| 773 |
-
|
| 774 |
-
1. Fork the repository.
|
| 775 |
-
2. Create a feature branch.
|
| 776 |
-
3. Make changes, commit, and push to your fork.
|
| 777 |
-
4. Open a pull request against the `main` branch of `jlowin/fastmcp`.
|
| 778 |
|
| 779 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 780 |
|
| 781 |
-
|
|
|
|
| 12 |
<a href="https://trendshift.io/repositories/13266" target="_blank"><img src="https://trendshift.io/api/badge/repositories/13266" alt="jlowin%2Ffastmcp | Trendshift" style="width: 250px; height: 55px;" width="250" height="55"/></a>
|
| 13 |
</div>
|
| 14 |
|
| 15 |
+
> [!NOTE]
|
| 16 |
+
> #### FastMCP 2.0 & The Official MCP SDK
|
| 17 |
+
>
|
| 18 |
+
> Recognize the `FastMCP` name? You might have used the version integrated into the [official MCP Python SDK](https://github.com/modelcontextprotocol/python-sdk), which was based on **FastMCP 1.0**.
|
| 19 |
+
>
|
| 20 |
+
> **Welcome to FastMCP 2.0!** This is the actively developed successor, and it significantly expands on 1.0 by introducing powerful client capabilities, server proxying & composition, OpenAPI/FastAPI integration, and more advanced features.
|
| 21 |
+
>
|
| 22 |
+
> FastMCP 2.0 is the recommended path for building modern, powerful MCP applications. Ready to upgrade or get started? Follow the [installation instructions](https://gofastmcp.com/getting-started/installation), which include specific steps for upgrading from the official MCP SDK.
|
| 23 |
+
|
| 24 |
+
---
|
| 25 |
+
|
| 26 |
The [Model Context Protocol (MCP)](https://modelcontextprotocol.io) is a new, standardized way to provide context and tools to your LLMs, and FastMCP makes building MCP servers and clients simple and intuitive. Create tools, expose resources, define prompts, and connect components with clean, Pythonic code.
|
| 27 |
|
| 28 |
```python
|
|
|
|
| 40 |
mcp.run()
|
| 41 |
```
|
| 42 |
|
|
|
|
| 43 |
Run the server locally:
|
| 44 |
```bash
|
| 45 |
fastmcp run server.py
|
| 46 |
```
|
| 47 |
|
| 48 |
+
### ๐ Documentation
|
| 49 |
+
|
| 50 |
+
This readme provides only a high-level overview. For detailed guides, API references, and advanced patterns, please refer to the complete FastMCP documentation at **[gofastmcp.com](https://gofastmcp.com)**.
|
| 51 |
|
| 52 |
+
---
|
| 53 |
|
| 54 |
<!-- omit in toc -->
|
| 55 |
## Table of Contents
|
| 56 |
|
| 57 |
- [What is MCP?](#what-is-mcp)
|
| 58 |
- [Why FastMCP?](#why-fastmcp)
|
| 59 |
+
- [Installation](#installation)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 60 |
- [Core Concepts](#core-concepts)
|
| 61 |
- [The `FastMCP` Server](#the-fastmcp-server)
|
| 62 |
- [Tools](#tools)
|
| 63 |
+
- [Resources \& Templates](#resources--templates)
|
| 64 |
- [Prompts](#prompts)
|
| 65 |
- [Context](#context)
|
|
|
|
| 66 |
- [MCP Clients](#mcp-clients)
|
|
|
|
|
|
|
|
|
|
|
|
|
| 67 |
- [Advanced Features](#advanced-features)
|
| 68 |
- [Proxy Servers](#proxy-servers)
|
| 69 |
- [Composing MCP Servers](#composing-mcp-servers)
|
| 70 |
- [OpenAPI \& FastAPI Generation](#openapi--fastapi-generation)
|
|
|
|
| 71 |
- [Running Your Server](#running-your-server)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 72 |
- [Contributing](#contributing)
|
| 73 |
+
- [Prerequisites](#prerequisites)
|
| 74 |
+
- [Setup](#setup)
|
| 75 |
+
- [Unit Tests](#unit-tests)
|
| 76 |
+
- [Static Checks](#static-checks)
|
| 77 |
+
- [Pull Requests](#pull-requests)
|
| 78 |
|
| 79 |
+
---
|
| 80 |
|
| 81 |
## What is MCP?
|
| 82 |
|
| 83 |
The [Model Context Protocol (MCP)](https://modelcontextprotocol.io) 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:
|
| 84 |
|
| 85 |
+
- Expose data through **Resources** (similar to `GET` requests; load info into context)
|
| 86 |
+
- Provide functionality through **Tools** (similar to `POST`/`PUT` requests; execute actions)
|
| 87 |
- Define interaction patterns through **Prompts** (reusable templates)
|
| 88 |
- And more!
|
| 89 |
|
|
|
|
| 93 |
|
| 94 |
The MCP protocol is powerful but implementing it involves a lot of boilerplate - server setup, protocol handlers, content types, error management. FastMCP handles all the complex protocol details and server management, so you can focus on building great tools. It's designed to be high-level and Pythonic; in most cases, decorating a function is all you need.
|
| 95 |
|
| 96 |
+
While the core server concepts of FastMCP 1.0 laid the groundwork and were contributed to the official MCP SDK, **FastMCP 2.0 (this project) is the actively developed successor**, adding significant enhancements and entirely new capabilities like a powerful **client library**, server **proxying**, **composition** patterns, **OpenAPI/FastAPI integration**, and much more.
|
| 97 |
|
| 98 |
+
FastMCP aims to be:
|
| 99 |
|
| 100 |
๐ **Fast:** High-level interface means less code and faster development
|
| 101 |
|
|
|
|
| 105 |
|
| 106 |
๐ **Complete:** FastMCP aims to provide a full implementation of the core MCP specification for both servers and clients
|
| 107 |
|
| 108 |
+
## Installation
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 109 |
|
| 110 |
+
We recommend installing FastMCP with [uv](https://docs.astral.sh/uv/):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 111 |
|
| 112 |
```bash
|
| 113 |
uv pip install fastmcp
|
| 114 |
```
|
| 115 |
|
| 116 |
+
For full installation instructions, including verification, upgrading from the official MCPSDK, and developer setup, see the [**Installation Guide**](https://gofastmcp.com/getting-started/installation).
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 117 |
|
| 118 |
## Core Concepts
|
| 119 |
|
| 120 |
+
These are the building blocks for creating MCP servers and clients with FastMCP.
|
| 121 |
|
| 122 |
### The `FastMCP` Server
|
| 123 |
|
| 124 |
+
The central object representing your MCP application. It holds your tools, resources, and prompts, manages connections, and can be configured with settings like [authentication providers](https://gofastmcp.com/servers/fastmcp#authentication).
|
| 125 |
|
| 126 |
```python
|
| 127 |
from fastmcp import FastMCP
|
| 128 |
|
| 129 |
+
# Create a server instance
|
| 130 |
+
mcp = FastMCP(name="MyAssistantServer")
|
|
|
|
|
|
|
|
|
|
| 131 |
```
|
| 132 |
|
| 133 |
+
Learn more in the [**FastMCP Server Documentation**](https://gofastmcp.com/servers/fastmcp).
|
| 134 |
|
| 135 |
+
### Tools
|
| 136 |
|
| 137 |
+
Tools allow LLMs to perform actions by executing your Python functions (sync or async). Ideal for computations, API calls, or side effects (like `POST`/`PUT`). FastMCP handles schema generation from type hints and docstrings. Tools can return various types, including text, JSON-serializable objects, and even images using the [`fastmcp.Image`](https://gofastmcp.com/servers/tools#return-values) helper.
|
| 138 |
|
| 139 |
```python
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 140 |
@mcp.tool()
|
| 141 |
+
def multiply(a: float, b: float) -> float:
|
| 142 |
+
"""Multiplies two numbers."""
|
| 143 |
+
return a * b
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 144 |
```
|
| 145 |
|
| 146 |
+
Learn more in the [**Tools Documentation**](https://gofastmcp.com/servers/tools).
|
| 147 |
|
| 148 |
+
### Resources & Templates
|
| 149 |
|
| 150 |
+
Resources expose read-only data sources (like `GET` requests). Use `@mcp.resource("your://uri")`. Use `{placeholders}` in the URI to create dynamic templates that accept parameters, allowing clients to request specific data subsets.
|
| 151 |
|
| 152 |
```python
|
| 153 |
+
# Static resource
|
| 154 |
+
@mcp.resource("config://version")
|
| 155 |
+
def get_version():
|
| 156 |
+
return "2.0.1"
|
| 157 |
+
|
| 158 |
+
# Dynamic resource template
|
| 159 |
+
@mcp.resource("users://{user_id}/profile")
|
| 160 |
+
def get_profile(user_id: int):
|
| 161 |
+
# Fetch profile for user_id...
|
| 162 |
+
return {"name": f"User {user_id}", "status": "active"}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 163 |
```
|
| 164 |
|
| 165 |
+
Learn more in the [**Resources & Templates Documentation**](https://gofastmcp.com/servers/resources).
|
| 166 |
|
| 167 |
+
### Prompts
|
| 168 |
|
| 169 |
+
Prompts define reusable message templates to guide LLM interactions. Decorate functions with `@mcp.prompt()`. Return strings or `Message` objects.
|
| 170 |
|
| 171 |
```python
|
|
|
|
|
|
|
| 172 |
@mcp.prompt()
|
| 173 |
+
def summarize_request(text: str) -> str:
|
| 174 |
+
"""Generate a prompt asking for a summary."""
|
| 175 |
+
return f"Please summarize the following text:\n\n{text}"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 176 |
```
|
| 177 |
|
| 178 |
+
Learn more in the [**Prompts Documentation**](https://gofastmcp.com/servers/prompts).
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 179 |
|
| 180 |
+
### Context
|
| 181 |
|
| 182 |
+
Access MCP session capabilities within your tools, resources, or prompts by adding a `ctx: Context` parameter. Context provides methods for:
|
| 183 |
+
* **Logging:** Log messages to MCP clients with `ctx.info()`, `ctx.error()`, etc.
|
| 184 |
+
* **LLM Sampling:** Use `ctx.sample()` to request completions from the client's LLM.
|
| 185 |
+
* **HTTP Request:** Use `ctx.http_request()` to make HTTP requests to other servers.
|
| 186 |
+
* **Resource Access:** Use `ctx.read_resource()` to access resources on the server
|
| 187 |
+
* **Progress Reporting:** Use `ctx.report_progress()` to report progress to the client.
|
| 188 |
+
* and more...
|
| 189 |
|
| 190 |
+
To access the context, add a parameter annotated as `Context` to any mcp-decorated function. FastMCP will automatically inject the correct context object when the function is called.
|
|
|
|
|
|
|
| 191 |
|
| 192 |
```python
|
| 193 |
+
from fastmcp import FastMCP, Context
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 194 |
|
| 195 |
+
mcp = FastMCP("My MCP Server")
|
| 196 |
|
| 197 |
@mcp.tool()
|
| 198 |
+
async def process_data(uri: str, ctx: Context):
|
| 199 |
+
# Log a message to the client
|
| 200 |
+
await ctx.info(f"Processing {uri}...")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 201 |
|
| 202 |
+
# Read a resource from the server
|
| 203 |
+
data = await ctx.read_resource(uri)
|
| 204 |
|
| 205 |
+
# Ask client LLM to summarize the data
|
| 206 |
+
summary = await ctx.sample(f"Summarize: {data.content[:500]}")
|
| 207 |
|
| 208 |
+
# Return the summary
|
| 209 |
+
return summary.text
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 210 |
```
|
| 211 |
|
| 212 |
+
Learn more in the [**Context Documentation**](https://gofastmcp.com/servers/context).
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 213 |
|
| 214 |
+
### MCP Clients
|
| 215 |
|
| 216 |
+
Interact with *any* MCP server programmatically using the `fastmcp.Client`. It supports various transports (Stdio, SSE, In-Memory) and often auto-detects the correct one. The client can also handle advanced patterns like server-initiated **LLM sampling requests** if you provide an appropriate handler.
|
| 217 |
|
| 218 |
+
Critically, the client allows for efficient **in-memory testing** of your servers by connecting directly to a `FastMCP` server instance via the `FastMCPTransport`, eliminating the need for process management or network calls during tests.
|
| 219 |
|
| 220 |
```python
|
| 221 |
from fastmcp import Client
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 222 |
|
| 223 |
+
async def main():
|
| 224 |
+
# Connect via stdio to a local script
|
| 225 |
+
async with Client("my_server.py") as client:
|
| 226 |
+
tools = await client.list_tools()
|
| 227 |
+
print(f"Available tools: {tools}")
|
| 228 |
+
result = await client.call_tool("add", {"a": 5, "b": 3})
|
| 229 |
+
print(f"Result: {result.text}")
|
| 230 |
+
|
| 231 |
+
# Connect via SSE
|
| 232 |
+
async with Client("http://localhost:8000/sse") as client:
|
| 233 |
+
# ... use the client
|
| 234 |
+
pass
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 235 |
```
|
| 236 |
|
| 237 |
+
To use clients to test servers, use the following pattern:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 238 |
|
| 239 |
```python
|
| 240 |
+
from fastmcp import FastMCP, Client
|
| 241 |
|
| 242 |
+
mcp = FastMCP("My MCP Server")
|
|
|
|
| 243 |
|
| 244 |
+
async def main():
|
| 245 |
+
# Connect via in-memory transport
|
| 246 |
+
async with Client(mcp) as client:
|
| 247 |
+
# ... use the client
|
| 248 |
```
|
| 249 |
|
| 250 |
+
Learn more in the [**Client Documentation**](https://gofastmcp.com/clients/client) and [**Transports Documentation**](https://gofastmcp.com/clients/transports).
|
| 251 |
|
| 252 |
+
## Advanced Features
|
| 253 |
|
| 254 |
+
FastMCP introduces powerful ways to structure and deploy your MCP applications.
|
| 255 |
|
| 256 |
### Proxy Servers
|
| 257 |
|
| 258 |
+
Create a FastMCP server that acts as an intermediary for another local or remote MCP server using `FastMCP.from_client()`. This is especially useful for bridging transports (e.g., remote SSE to local Stdio) or adding a layer of logic to a server you don't control.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 259 |
|
| 260 |
+
Learn more in the [**Proxying Documentation**](https://gofastmcp.com/patterns/proxy).
|
| 261 |
|
| 262 |
### Composing MCP Servers
|
| 263 |
|
| 264 |
+
Build modular applications by mounting multiple `FastMCP` instances onto a parent server using `mcp.mount()` (live link) or `mcp.import_server()` (static copy).
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 265 |
|
| 266 |
+
Learn more in the [**Composition Documentation**](https://gofastmcp.com/patterns/composition).
|
| 267 |
|
| 268 |
### OpenAPI & FastAPI Generation
|
| 269 |
|
| 270 |
+
Automatically generate FastMCP servers from existing OpenAPI specifications (`FastMCP.from_openapi()`) or FastAPI applications (`FastMCP.from_fastapi()`), instantly bringing your web APIs to the MCP ecosystem.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 271 |
|
| 272 |
+
Learn more: [**OpenAPI Integration**](https://gofastmcp.com/patterns/openapi) | [**FastAPI Integration**](https://gofastmcp.com/patterns/fastapi).
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 273 |
|
| 274 |
## Running Your Server
|
| 275 |
|
| 276 |
+
You can run your FastMCP server in several ways:
|
| 277 |
+
|
| 278 |
+
1. **Development (`fastmcp dev`)**: Recommended for building and testing. Provides an interactive testing environment with the MCP Inspector.
|
| 279 |
+
```bash
|
| 280 |
+
fastmcp dev server.py
|
| 281 |
+
# Optionally add temporary dependencies
|
| 282 |
+
fastmcp dev server.py --with pandas numpy
|
| 283 |
+
```
|
| 284 |
+
|
| 285 |
+
2. **FastMCP CLI**: Run your server with the FastMCP CLI. This can autodetect and load your server object and run it with any transport configuration you want.
|
| 286 |
+
```bash
|
| 287 |
+
fastmcp run path/to/server.py:server_object
|
| 288 |
+
|
| 289 |
+
# Run as SSE on port 4200
|
| 290 |
+
fastmcp run path/to/server.py:server_object --transport sse --port 4200
|
| 291 |
+
```
|
| 292 |
+
FastMCP will auto-detect the server object if it's named `mcp`, `app`, or `server`. In these cases, you can omit the `:server_object` part unless you need to select a specific object.
|
| 293 |
+
|
| 294 |
+
3. **Direct Execution**: For maximum compatibility with the MCP ecosystem, you can run your server directly as part of a Python script. You will typically do this within an `if __name__ == "__main__":` block in your script:
|
| 295 |
+
```python
|
| 296 |
+
# Add this to server.py
|
| 297 |
+
if __name__ == "__main__":
|
| 298 |
+
# Default: runs stdio transport
|
| 299 |
+
mcp.run()
|
| 300 |
+
|
| 301 |
+
# Example: Run with SSE transport on a specific port
|
| 302 |
+
mcp.run(transport="sse", host="127.0.0.1", port=9000)
|
| 303 |
+
```
|
| 304 |
+
Run your script:
|
| 305 |
+
```bash
|
| 306 |
+
python server.py
|
| 307 |
+
# or using uv to manage the environment
|
| 308 |
+
uv run python server.py
|
| 309 |
+
```
|
| 310 |
+
4. **Claude Desktop Integration (`fastmcp install`)**: The easiest way to make your server persistently available in the Claude Desktop app. It handles creating an isolated environment using `uv`.
|
| 311 |
+
```bash
|
| 312 |
+
fastmcp install server.py --name "My Analysis Tool"
|
| 313 |
+
# Optionally add dependencies and environment variables
|
| 314 |
+
fastmcp install server.py --with requests -v API_KEY=123 -f .env
|
| 315 |
+
```
|
| 316 |
+
|
| 317 |
+
|
| 318 |
+
See the [**Server Documentation**](https://gofastmcp.com/servers/fastmcp#running-the-server) for more details on transports and configuration.
|
| 319 |
|
|
|
|
| 320 |
|
| 321 |
+
## Contributing
|
| 322 |
|
| 323 |
+
Contributions are the core of open source! We welcome improvements and features.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 324 |
|
| 325 |
+
### Prerequisites
|
| 326 |
|
| 327 |
+
* Python 3.10+
|
| 328 |
+
* [uv](https://docs.astral.sh/uv/) (Recommended for environment management)
|
| 329 |
|
| 330 |
+
### Setup
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 331 |
|
| 332 |
+
1. Clone the repository:
|
| 333 |
+
```bash
|
| 334 |
+
git clone https://github.com/jlowin/fastmcp.git
|
| 335 |
+
cd fastmcp
|
| 336 |
+
```
|
| 337 |
+
2. Create and sync the environment:
|
| 338 |
+
```bash
|
| 339 |
+
uv sync
|
| 340 |
+
```
|
| 341 |
+
This installs all dependencies, including dev tools.
|
| 342 |
+
|
| 343 |
+
3. Activate the virtual environment (e.g., `source .venv/bin/activate` or via your IDE).
|
| 344 |
|
| 345 |
+
### Unit Tests
|
| 346 |
|
| 347 |
+
FastMCP has a comprehensive unit test suite. All PRs must introduce or update tests as appropriate and pass the full suite.
|
| 348 |
+
|
| 349 |
+
Run tests using pytest:
|
|
|
|
|
|
|
|
|
|
| 350 |
```bash
|
| 351 |
+
pytest
|
|
|
|
|
|
|
| 352 |
```
|
| 353 |
|
| 354 |
+
### Static Checks
|
| 355 |
|
| 356 |
+
FastMCP uses `pre-commit` for code formatting, linting, and type-checking. All PRs must pass these checks (they run automatically in CI).
|
| 357 |
|
| 358 |
+
Install the hooks locally:
|
| 359 |
```bash
|
| 360 |
+
uv run pre-commit install
|
|
|
|
| 361 |
```
|
| 362 |
+
The hooks will now run automatically on `git commit`. You can also run them manually at any time:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 363 |
```bash
|
| 364 |
+
pre-commit run --all-files
|
| 365 |
+
# or via uv
|
| 366 |
+
uv run pre-commit run --all-files
|
| 367 |
```
|
| 368 |
|
| 369 |
+
### Pull Requests
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 370 |
|
| 371 |
+
1. Fork the repository on GitHub.
|
| 372 |
+
2. Create a feature branch from `main`.
|
| 373 |
+
3. Make your changes, including tests and documentation updates.
|
| 374 |
+
4. Ensure tests and pre-commit hooks pass.
|
| 375 |
+
5. Commit your changes and push to your fork.
|
| 376 |
+
6. Open a pull request against the `main` branch of `jlowin/fastmcp`.
|
| 377 |
|
| 378 |
+
Please open an issue or discussion for questions or suggestions before starting significant work!
|
docs/getting-started/installation.mdx
CHANGED
|
@@ -23,7 +23,7 @@ Alternatively, you can install it directly with `pip` or `uv pip`:
|
|
| 23 |
```
|
| 24 |
</CodeGroup>
|
| 25 |
|
| 26 |
-
## Verify Installation
|
| 27 |
|
| 28 |
To verify that FastMCP is installed correctly, you can run the following command:
|
| 29 |
|
|
@@ -42,10 +42,26 @@ Python version: 3.12.2
|
|
| 42 |
Platform: macOS-15.3.1-arm64-arm-64bit
|
| 43 |
FastMCP root path: ~/Developer/fastmcp
|
| 44 |
```
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 45 |
|
| 46 |
## Installing for Development
|
| 47 |
|
| 48 |
-
If you plan to contribute to FastMCP, you should begin by cloning the repository and using uv to install all dependencies
|
| 49 |
|
| 50 |
```bash
|
| 51 |
git clone https://github.com/jlowin/fastmcp.git
|
|
@@ -53,10 +69,26 @@ cd fastmcp
|
|
| 53 |
uv sync
|
| 54 |
```
|
| 55 |
|
| 56 |
-
This will install all dependencies, including ones for development, and create a virtual environment.
|
| 57 |
|
| 58 |
-
|
|
|
|
|
|
|
| 59 |
|
| 60 |
```bash
|
| 61 |
pytest
|
| 62 |
-
```
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 23 |
```
|
| 24 |
</CodeGroup>
|
| 25 |
|
| 26 |
+
### Verify Installation
|
| 27 |
|
| 28 |
To verify that FastMCP is installed correctly, you can run the following command:
|
| 29 |
|
|
|
|
| 42 |
Platform: macOS-15.3.1-arm64-arm-64bit
|
| 43 |
FastMCP root path: ~/Developer/fastmcp
|
| 44 |
```
|
| 45 |
+
## Upgrading from the Official MCP SDK
|
| 46 |
+
|
| 47 |
+
Upgrading from the official MCP SDK's FastMCP 1.0 to FastMCP 2.0 is easy! The core server API is highly compatible, so after you install the `fastmcp` package, just change your import statement from `from mcp.server.fastmcp import FastMCP` to `from fastmcp import FastMCP`.
|
| 48 |
+
|
| 49 |
+
|
| 50 |
+
```python {1-5}
|
| 51 |
+
# Before
|
| 52 |
+
# from mcp.server.fastmcp import FastMCP
|
| 53 |
+
|
| 54 |
+
# After
|
| 55 |
+
from fastmcp import FastMCP
|
| 56 |
+
|
| 57 |
+
mcp = FastMCP("My MCP Server")
|
| 58 |
+
```
|
| 59 |
+
|
| 60 |
+
While the 1.0 server API is very stable for common use cases, FastMCP 2.0 introduces many new features (like the Client, proxying, composition) documented throughout this site. Review the documentation for details on new capabilities.
|
| 61 |
|
| 62 |
## Installing for Development
|
| 63 |
|
| 64 |
+
If you plan to contribute to FastMCP, you should begin by cloning the repository and using uv to install all dependencies (development dependencies are installed automatically):
|
| 65 |
|
| 66 |
```bash
|
| 67 |
git clone https://github.com/jlowin/fastmcp.git
|
|
|
|
| 69 |
uv sync
|
| 70 |
```
|
| 71 |
|
| 72 |
+
This will install all dependencies, including ones for development, and create a virtual environment, which you can activate and use as normal.
|
| 73 |
|
| 74 |
+
### Unit Tests
|
| 75 |
+
|
| 76 |
+
FastMCP has a comprehensive unit test suite, and all PR's must introduce and pass appropriate tests. To run the tests, use pytest:
|
| 77 |
|
| 78 |
```bash
|
| 79 |
pytest
|
| 80 |
+
```
|
| 81 |
+
|
| 82 |
+
### Pre-Commit Hooks
|
| 83 |
+
|
| 84 |
+
FastMCP uses pre-commit to manage code quality, including formatting, linting, and type-safety. All PR's must pass the pre-commit hooks, which are run as a part of the CI process. To install the pre-commit hooks, run:
|
| 85 |
+
|
| 86 |
+
```bash
|
| 87 |
+
uv run pre-commit install
|
| 88 |
+
```
|
| 89 |
+
|
| 90 |
+
Alternatively, to run pre-commit manually at any time, use:
|
| 91 |
+
|
| 92 |
+
```bash
|
| 93 |
+
pre-commit run --all-files
|
| 94 |
+
```
|
docs/getting-started/welcome.mdx
CHANGED
|
@@ -1,5 +1,5 @@
|
|
| 1 |
---
|
| 2 |
-
title: "Welcome to FastMCP!"
|
| 3 |
sidebarTitle: "Welcome!"
|
| 4 |
description: The fast, Pythonic way to build MCP servers and clients.
|
| 5 |
|
|
@@ -24,6 +24,19 @@ if __name__ == "__main__":
|
|
| 24 |
```
|
| 25 |
|
| 26 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 27 |
## What is MCP?
|
| 28 |
The Model Context Protocol lets you build servers that expose data and functionality to LLM applications in a secure, standardized way. It is often described as "the USB-C port for AI", providing a uniform way to connect LLMs to resources they can use. It may be easier to think of it as an API, but specifically designed for LLM interactions. MCP servers can:
|
| 29 |
|
|
@@ -34,17 +47,13 @@ The Model Context Protocol lets you build servers that expose data and functiona
|
|
| 34 |
|
| 35 |
There is a low-level Python SDK available for implementing the protocol directly, but FastMCP aims to make that easier by providing a high-level, Pythonic interface.
|
| 36 |
|
| 37 |
-
<Tip>
|
| 38 |
-
FastMCP 1.0 was so successful that it is now included as part of the official [MCP Python SDK](https://github.com/modelcontextprotocol/python-sdk)!
|
| 39 |
-
</Tip>
|
| 40 |
-
|
| 41 |
-
|
| 42 |
-
|
| 43 |
|
| 44 |
## Why FastMCP?
|
| 45 |
|
| 46 |
The MCP protocol is powerful but implementing it involves a lot of boilerplate - server setup, protocol handlers, content types, error management. FastMCP handles all the complex protocol details and server management, so you can focus on building great tools. It's designed to be high-level and Pythonic; in most cases, decorating a function is all you need.
|
| 47 |
|
|
|
|
|
|
|
| 48 |
FastMCP aims to be:
|
| 49 |
|
| 50 |
๐ **Fast**: High-level interface means less code and faster development
|
|
@@ -55,5 +64,4 @@ FastMCP aims to be:
|
|
| 55 |
|
| 56 |
๐ **Complete**: FastMCP aims to provide a full implementation of the core MCP specification
|
| 57 |
|
| 58 |
-
**FastMCP v1** focused on abstracting the most common boilerplate of exposing MCP server functionality, and is now included in the official MCP Python SDK. **FastMCP v2** expands on that foundation to introduce novel functionality mainly focused on simplifying server interactions, including flexible clients, proxying and composition, and deployment.
|
| 59 |
|
|
|
|
| 1 |
---
|
| 2 |
+
title: "Welcome to FastMCP 2.0!"
|
| 3 |
sidebarTitle: "Welcome!"
|
| 4 |
description: The fast, Pythonic way to build MCP servers and clients.
|
| 5 |
|
|
|
|
| 24 |
```
|
| 25 |
|
| 26 |
|
| 27 |
+
## FastMCP 2.0 and the Official MCP SDK
|
| 28 |
+
|
| 29 |
+
<Tip>
|
| 30 |
+
Recognize the `FastMCP` name? You might have used the version integrated into the [official MCP Python SDK](https://github.com/modelcontextprotocol/python-sdk), which was based on **FastMCP 1.0**.
|
| 31 |
+
|
| 32 |
+
|
| 33 |
+
**Welcome to FastMCP 2.0!** This is the [actively developed successor](https://github.com/jlowin/fastmcp), and it significantly expands on v1 by introducing powerful client capabilities, server proxying & composition, OpenAPI/FastAPI integration, and more advanced features.
|
| 34 |
+
|
| 35 |
+
FastMCP 2.0 is the recommended path for building modern, powerful MCP applications. Ready to upgrade or get started? Follow the [installation instructions](/getting-started/installation), which include specific steps for upgrading.
|
| 36 |
+
</Tip>
|
| 37 |
+
|
| 38 |
+
|
| 39 |
+
|
| 40 |
## What is MCP?
|
| 41 |
The Model Context Protocol lets you build servers that expose data and functionality to LLM applications in a secure, standardized way. It is often described as "the USB-C port for AI", providing a uniform way to connect LLMs to resources they can use. It may be easier to think of it as an API, but specifically designed for LLM interactions. MCP servers can:
|
| 42 |
|
|
|
|
| 47 |
|
| 48 |
There is a low-level Python SDK available for implementing the protocol directly, but FastMCP aims to make that easier by providing a high-level, Pythonic interface.
|
| 49 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 50 |
|
| 51 |
## Why FastMCP?
|
| 52 |
|
| 53 |
The MCP protocol is powerful but implementing it involves a lot of boilerplate - server setup, protocol handlers, content types, error management. FastMCP handles all the complex protocol details and server management, so you can focus on building great tools. It's designed to be high-level and Pythonic; in most cases, decorating a function is all you need.
|
| 54 |
|
| 55 |
+
While the core server concepts of FastMCP 1.0 laid the groundwork and were contributed to the official MCP SDK, FastMCP 2.0 (this project) is the actively developed successor, adding significant enhancements and entirely new capabilities like a powerful client library, server proxying, composition patterns, and much more.
|
| 56 |
+
|
| 57 |
FastMCP aims to be:
|
| 58 |
|
| 59 |
๐ **Fast**: High-level interface means less code and faster development
|
|
|
|
| 64 |
|
| 65 |
๐ **Complete**: FastMCP aims to provide a full implementation of the core MCP specification
|
| 66 |
|
|
|
|
| 67 |
|