FastMCP 3.0 Server Development
Complete reference for building production-ready MCP (Model Context Protocol) servers with FastMCP 3.0 - the fast, Pythonic framework for connecting LLMs to tools and data.
When to use this skill
Use FastMCP Server when:
- Creating a new MCP server in Python
- Adding tools, resources, or prompts to an MCP server
- Implementing authentication (OAuth, OIDC, token verification)
- Setting up middleware for logging, rate limiting, or authorization
- Configuring providers (local, filesystem, skills, custom)
- Building production MCP servers with telemetry and storage
- Upgrading from FastMCP 2.x to 3.0
Key areas covered:
- Tools & Resources (CORE): Decorators, validation, return types, templates
- Context & DI (CORE): MCP context, dependency injection, background tasks
- Authentication (SECURITY): OAuth, OIDC, token verification, proxy patterns
- Authorization (SECURITY): Scope-based and role-based access control
- Middleware (ADVANCED): Request/response pipeline, built-in middleware
- Providers (ADVANCED): Local, filesystem, skills, and custom providers
- Features (ADVANCED): Pagination, sampling, storage, OpenTelemetry, versioning
Quick reference
Core patterns
Create a server with tools:
from fastmcp import FastMCP
mcp = FastMCP("MyServer")
@mcp.tool
def add(a: int, b: int) -> int:
"""Add two numbers"""
return a + b
Create a resource:
@mcp.resource("data://config")
def get_config() -> dict:
"""Return server configuration"""
return {"version": "1.0", "debug": False}
Create a resource template:
@mcp.resource("users://{user_id}/profile")
def get_user_profile(user_id: str) -> dict:
"""Get a user's profile by ID"""
return fetch_user(user_id)
Create a prompt:
@mcp.prompt
def review_code(code: str, language: str = "python") -> str:
"""Review code for best practices"""
return f"Review this {language} code:\n\n{code}"
Run the server:
if __name__ == "__main__":
mcp.run()
# Or with transport options:
# mcp.run(transport="sse", host="0.0.0.0", port=8000)
Using context in tools
from fastmcp import FastMCP, Context
mcp = FastMCP("MyServer")
@mcp.tool
def process_data(uri: str, ctx: Context) -> str:
"""Process data with logging and progress"""
ctx.info(f"Processing {uri}")
ctx.report_progress(0, 100)
data = ctx.read_resource(uri)
ctx.report_progress(100, 100)
return f"Processed: {data}"
Authentication setup
from fastmcp import FastMCP
from fastmcp.server.auth import BearerAuthProvider
auth = BearerAuthProvider(
jwks_uri="https://your-provider/.well-known/jwks.json",
audience="your-api",
issuer="https://your-provider/"
)
mcp = FastMCP("SecureServer", auth=auth)
Key concepts
Tools
Functions exposed as executable capabilities for LLMs. Decorated with @mcp.tool. Support Pydantic validation, async, custom return types, and annotations (readOnlyHint, destructiveHint).
Resources & Templates
Static or dynamic data sources identified by URIs. Resources use fixed URIs (data://config), templates use parameterized URIs (users://{id}/profile). Support MIME types, annotations, and wildcard parameters.
Context
The Context object provides access to MCP features within tools/resources: logging, progress reporting, resource access, LLM sampling, user elicitation, and session state.
Dependency Injection
Inject values into tool/resource functions using Depends(). Supports HTTP requests, access tokens, custom dependencies, and generator-based cleanup patterns.
Providers
Control where components come from. LocalProvider (default, decorator-based), FileSystemProvider (load from Python files on disk), SkillsProvider (packaged bundles), or custom providers.
Authentication & Authorization
Multiple auth patterns: token verification (JWT, JWKS), OAuth proxy, OIDC proxy, remote OAuth, and full OAuth server. Authorization via scopes on components and middleware.
Middleware
Intercept and modify requests/responses. Built-in middleware for rate limiting, error handling, logging, and response size limits. Custom middleware via @mcp.middleware.
Using the references
Detailed documentation is organized in the references/ folder:
Getting Started
- getting-started/installation.md - Install FastMCP, optional dependencies, verify setup
- getting-started/upgrade-guide.md - Migrate from FastMCP 2.x to 3.0
- getting-started/quickstart.md - First server, tools, resources, prompts, running
Server
- server/server-class.md - FastMCP server configuration, transport options, tag filtering
- server/tools.md - Tool decorator, parameters, validation, return types, annotations
- server/resources-and-templates.md - Resources, templates, URIs, wildcards, MIME types
Context
- context/mcp-context.md - Context object, logging, progress, resource access, sampling
- context/background-tasks.md - Long-running operations with task support
- context/dependency-injection.md - Depends(), custom deps, HTTP request, access tokens
- context/user-elicitation.md - Request structured input from users during execution
Features
- features/icons.md - Custom icons for tools, resources, prompts, and servers
- features/lifespans.md - Server lifecycle management and startup/shutdown hooks
- features/client-logging.md - Send log messages to MCP clients
- features/middleware.md - Request/response pipeline, built-in and custom middleware
- features/pagination.md - Paginate large component lists
- features/progress-reporting.md - Report progress for long-running operations
- features/sampling.md - Request LLM completions from the client
- features/storage-backends.md - Memory, file, and Redis storage for caching and tokens
- features/opentelemetry.md - Distributed tracing and observability
- features/versioning.md - Version components and filter by version ranges
Authentication
- authentication/token-verification.md - JWT, JWKS, introspection, static keys, custom
- authentication/remote-oauth.md - Delegate auth to upstream OAuth provider
- authentication/oauth-proxy.md - Full OAuth proxy with PKCE, client management
- authentication/oidc-proxy.md - OpenID Connect proxy with auto-discovery
- authentication/full-oauth-server.md - Complete built-in OAuth server
Authorization
- authorization.md - Scope-based access control, middleware authorization, patterns
Providers
- providers/local.md - Default provider, decorator-based component registration
- providers/filesystem.md - Load components from Python files on disk
- providers/skills.md - Package and distribute component bundles
- providers/custom.md - Build custom providers for any component source
Version history
v1.0.0 (February 2026)
- Initial release covering FastMCP 3.0 (release candidate)
- 30 reference files across 7 categories
- Complete coverage of tools, resources, context, auth, providers, and features
Converted and distributed by TomeVault | Claim this content
1---2name: fastmcp-server3description: Complete guide for building MCP servers with FastMCP 3.0 - tools, resources, authentication, providers, middleware, and deployment. Use when creating Python MCP servers or integrating AI models with external tools and data.4license: MIT5---67# FastMCP 3.0 Server Development89Complete reference for building production-ready MCP (Model Context Protocol) servers with FastMCP 3.0 - the fast, Pythonic framework for connecting LLMs to tools and data.1011## When to use this skill1213**Use FastMCP Server when:**14- Creating a new MCP server in Python15- Adding tools, resources, or prompts to an MCP server16- Implementing authentication (OAuth, OIDC, token verification)17- Setting up middleware for logging, rate limiting, or authorization18- Configuring providers (local, filesystem, skills, custom)19- Building production MCP servers with telemetry and storage20- Upgrading from FastMCP 2.x to 3.02122**Key areas covered:**23- **Tools & Resources** (CORE): Decorators, validation, return types, templates24- **Context & DI** (CORE): MCP context, dependency injection, background tasks25- **Authentication** (SECURITY): OAuth, OIDC, token verification, proxy patterns26- **Authorization** (SECURITY): Scope-based and role-based access control27- **Middleware** (ADVANCED): Request/response pipeline, built-in middleware28- **Providers** (ADVANCED): Local, filesystem, skills, and custom providers29- **Features** (ADVANCED): Pagination, sampling, storage, OpenTelemetry, versioning3031## Quick reference3233### Core patterns3435**Create a server with tools:**36```python37from fastmcp import FastMCP3839mcp = FastMCP("MyServer")4041@mcp.tool42def add(a: int, b: int) -> int:43 """Add two numbers"""44 return a + b45```4647**Create a resource:**48```python49@mcp.resource("data://config")50def get_config() -> dict:51 """Return server configuration"""52 return {"version": "1.0", "debug": False}53```5455**Create a resource template:**56```python57@mcp.resource("users://{user_id}/profile")58def get_user_profile(user_id: str) -> dict:59 """Get a user's profile by ID"""60 return fetch_user(user_id)61```6263**Create a prompt:**64```python65@mcp.prompt66def review_code(code: str, language: str = "python") -> str:67 """Review code for best practices"""68 return f"Review this {language} code:\n\n{code}"69```7071**Run the server:**72```python73if __name__ == "__main__":74 mcp.run()7576# Or with transport options:77# mcp.run(transport="sse", host="0.0.0.0", port=8000)78```7980### Using context in tools8182```python83from fastmcp import FastMCP, Context8485mcp = FastMCP("MyServer")8687@mcp.tool88def process_data(uri: str, ctx: Context) -> str:89 """Process data with logging and progress"""90 ctx.info(f"Processing {uri}")91 ctx.report_progress(0, 100)92 data = ctx.read_resource(uri)93 ctx.report_progress(100, 100)94 return f"Processed: {data}"95```9697### Authentication setup9899```python100from fastmcp import FastMCP101from fastmcp.server.auth import BearerAuthProvider102103auth = BearerAuthProvider(104 jwks_uri="https://your-provider/.well-known/jwks.json",105 audience="your-api",106 issuer="https://your-provider/"107)108109mcp = FastMCP("SecureServer", auth=auth)110```111112## Key concepts113114### Tools115Functions exposed as executable capabilities for LLMs. Decorated with `@mcp.tool`. Support Pydantic validation, async, custom return types, and annotations (readOnlyHint, destructiveHint).116117### Resources & Templates118Static or dynamic data sources identified by URIs. Resources use fixed URIs (`data://config`), templates use parameterized URIs (`users://{id}/profile`). Support MIME types, annotations, and wildcard parameters.119120### Context121The `Context` object provides access to MCP features within tools/resources: logging, progress reporting, resource access, LLM sampling, user elicitation, and session state.122123### Dependency Injection124Inject values into tool/resource functions using `Depends()`. Supports HTTP requests, access tokens, custom dependencies, and generator-based cleanup patterns.125126### Providers127Control where components come from. `LocalProvider` (default, decorator-based), `FileSystemProvider` (load from Python files on disk), `SkillsProvider` (packaged bundles), or custom providers.128129### Authentication & Authorization130Multiple auth patterns: token verification (JWT, JWKS), OAuth proxy, OIDC proxy, remote OAuth, and full OAuth server. Authorization via scopes on components and middleware.131132### Middleware133Intercept and modify requests/responses. Built-in middleware for rate limiting, error handling, logging, and response size limits. Custom middleware via `@mcp.middleware`.134135## Using the references136137Detailed documentation is organized in the `references/` folder:138139### Getting Started140- **getting-started/installation.md** - Install FastMCP, optional dependencies, verify setup141- **getting-started/upgrade-guide.md** - Migrate from FastMCP 2.x to 3.0142- **getting-started/quickstart.md** - First server, tools, resources, prompts, running143144### Server145- **server/server-class.md** - FastMCP server configuration, transport options, tag filtering146- **server/tools.md** - Tool decorator, parameters, validation, return types, annotations147- **server/resources-and-templates.md** - Resources, templates, URIs, wildcards, MIME types148149### Context150- **context/mcp-context.md** - Context object, logging, progress, resource access, sampling151- **context/background-tasks.md** - Long-running operations with task support152- **context/dependency-injection.md** - Depends(), custom deps, HTTP request, access tokens153- **context/user-elicitation.md** - Request structured input from users during execution154155### Features156- **features/icons.md** - Custom icons for tools, resources, prompts, and servers157- **features/lifespans.md** - Server lifecycle management and startup/shutdown hooks158- **features/client-logging.md** - Send log messages to MCP clients159- **features/middleware.md** - Request/response pipeline, built-in and custom middleware160- **features/pagination.md** - Paginate large component lists161- **features/progress-reporting.md** - Report progress for long-running operations162- **features/sampling.md** - Request LLM completions from the client163- **features/storage-backends.md** - Memory, file, and Redis storage for caching and tokens164- **features/opentelemetry.md** - Distributed tracing and observability165- **features/versioning.md** - Version components and filter by version ranges166167### Authentication168- **authentication/token-verification.md** - JWT, JWKS, introspection, static keys, custom169- **authentication/remote-oauth.md** - Delegate auth to upstream OAuth provider170- **authentication/oauth-proxy.md** - Full OAuth proxy with PKCE, client management171- **authentication/oidc-proxy.md** - OpenID Connect proxy with auto-discovery172- **authentication/full-oauth-server.md** - Complete built-in OAuth server173174### Authorization175- **authorization.md** - Scope-based access control, middleware authorization, patterns176177### Providers178- **providers/local.md** - Default provider, decorator-based component registration179- **providers/filesystem.md** - Load components from Python files on disk180- **providers/skills.md** - Package and distribute component bundles181- **providers/custom.md** - Build custom providers for any component source182183## Version history184185**v1.0.0** (February 2026)186- Initial release covering FastMCP 3.0 (release candidate)187- 30 reference files across 7 categories188- Complete coverage of tools, resources, context, auth, providers, and features189190---191> Converted and distributed by [TomeVault](https://tomevault.io) | [Claim this content](https://tomevault.io/claim/davila7/claude-code-templates)