fastmcp
This skill provides templates, examples, and agents to build FastMCP MCP servers in Python/TypeScript and to deploy them. It includes explicit shell commands (pip install fastmcp, npx wrangler deploy), environment-secret usage (API_KEY, GITHUB_CLIENT_SECRET, STORAGE_ENCRYPTION_KEY), and network endpoints (https://github.com/login/oauth/authorize, https://api.example.com).
fastmcp
Build MCP (Model Context Protocol) servers in Python with FastMCP
What This Skill Does
This skill provides production-tested patterns, templates, and error prevention for building production-ready MCP servers with FastMCP in Python. It covers:
- Server Creation: Tools, resources, resource templates, and prompts
- Storage Backends: Memory, Disk, Redis, DynamoDB with encrypted persistence
- Server Lifespans: Resource management for DB connections and API clients
- Middleware System: 8 built-in types (logging, rate limiting, caching, error handling, timing)
- Server Composition: Modular architecture with import/mount strategies
- Authentication: 4 patterns (Token Validation, Remote OAuth, OAuth Proxy, Full OAuth)
- OAuth Proxy: Bridge to GitHub, Google, Azure, AWS, Discord, Facebook
- Icons Support: Visual representations for better UX
- API Integration: OpenAPI/Swagger auto-generation, FastAPI conversion, manual integration
- Cloud Deployment: FastMCP Cloud requirements and common pitfalls
- Error Prevention: 28 documented errors with solutions
- Production Patterns: Self-contained architecture, connection pooling, caching, retry logic
- Context Features: Elicitation, progress tracking, sampling, state management
- Background Tasks (v2.14.0+): Long-running operations with progress tracking
- Sampling with Tools (v2.14.1+): Agentic workflows where LLM can call tools
- Testing: Unit and integration testing patterns
- Client Configuration: Claude Desktop, Claude Code CLI
When to Use This Skill
Use this skill when you need to:
- Build an MCP server to expose tools/resources/prompts to LLMs
- Configure persistent storage for OAuth tokens or response caching
- Set up server lifespans for database connections or API client pooling
- Add middleware for logging, rate limiting, caching, or error handling
- Compose modular servers with import/mount strategies
- Implement OAuth authentication (GitHub, Google, Azure, AWS, Discord, Facebook)
- Secure MCP servers with JWT verification or OAuth Proxy
- Add icons to servers, tools, resources, or prompts
- Integrate an external API with Claude (via MCP)
- Deploy an MCP server to FastMCP Cloud
- Convert an OpenAPI/Swagger spec to MCP
- Convert a FastAPI app to MCP
- Wrap a database, file system, or service for LLM access
- Debug MCP server errors (storage, lifespan, middleware, OAuth, circular imports)
- Test MCP servers with FastMCP Client
- Implement elicitation (user input during execution)
- Add progress tracking to long-running operations
- Use sampling (LLM completions from within tools)
- Manage server state with context
Don't use this skill if:
- You're building an MCP client (not server)
- You're using a different MCP framework (not FastMCP)
- You're working in a language other than Python
- You're building with Anthropic's TypeScript SDK for MCP
Auto-Trigger Keywords
This skill should automatically trigger when you mention:
Primary Keywords
fastmcp,fast mcp,FastMCPMCP server,mcp server,MCP server python,python mcp servermodel context protocol,model context protocol pythonmcp tools,mcp resources,mcp promptsmcp integration,mcp framework
Use Case Keywords
build mcp server,create mcp server,make mcp serverpython mcp,mcp python,mcp with pythonintegrate api with claude,expose api to llm,api for claudeopenapi to mcp,swagger to mcp,fastapi to mcpmcp cloud,fastmcp cloud,deploy mcpmcp testing,test mcp server
Storage & Persistence Keywords
mcp storage,fastmcp storage backends,persistent storage mcpredis storage mcp,disk storage mcp,encrypted storageoauth token storage,cache persistence mcppy-key-value-aio,fernet encryption mcp
Middleware Keywords
mcp middleware,fastmcp middleware,middleware systemrate limiting mcp,response caching mcp,logging middlewaretiming middleware,error handling middlewaremiddleware order,middleware hooks
Authentication Keywords
oauth mcp,oauth proxy mcp,jwt verification mcpgithub oauth mcp,google oauth mcp,azure oauth mcptoken validation mcp,auth patterns mcpconsent screen,pkce mcp,token introspection
Server Composition Keywords
import server mcp,mount server mcp,server compositionmodular mcp,subservers mcp,tag filtering mcp
Lifespan Keywords
server lifespan mcp,mcp lifespan,resource management mcpdatabase connection mcp,cleanup hooks mcpasgi integration mcp,fastapi lifespan
Icons Keywords
mcp icons,server icons mcp,visual mcpdata uri icons,icon sizes mcp
Error Keywords
mcp server not found,no server object foundstorage backend error,lifespan not running,middleware order erroroauth not persisting,consent screen missingcircular import fastmcp,import error mcpmodule-level server,fastmcp cloud deploymentmcp async await,mcp context injectionresource uri scheme,invalid resource uripydantic validation mcp,mcp json serializable
Feature Keywords
mcp elicitation,user input during tool executionmcp progress tracking,progress updates mcpmcp sampling,llm from mcp toolresource templates mcp,dynamic resourcestool transformation mcp,client handlersstate management mcp,context state
Integration Keywords
openapi integration,swagger integration,fastapi mcpapi wrapper mcp,database mcp,file system mcpconnection pooling mcp,caching mcp,retry logic mcp
Claude Integration Keywords
claude desktop mcp,claude code mcpclaude_desktop_config.json,mcp configurationexpose tools to claude,claude tools
Token Efficiency
- Without skill: ~50-70k tokens, 8-15 errors
- With skill: ~3-5k tokens, 0 errors
- Savings: 90-95% token reduction
This is the highest token savings in the skills collection!
Errors Prevented
This skill prevents 28 common errors:
Core Server Errors (1-5)
- Missing server object - Module-level export for FastMCP Cloud
- Async/await confusion - Proper async/sync patterns
- Context not injected - Type hints for context parameter
- Resource URI syntax - Missing scheme prefixes
- Resource template mismatch - Parameter name alignment
Validation & Serialization (6-12)
- Pydantic validation errors - Type hint consistency
- Transport/protocol mismatch - Client/server compatibility
- Import errors - Editable package installation
- Deprecation warnings - FastMCP v2 migration
- Port conflicts - Address already in use
- Schema generation failures - Unsupported type hints
- JSON serialization - Non-serializable objects
Architecture & Lifecycle (13-15)
- Circular imports - Factory function anti-patterns
- Python version compatibility - Deprecated methods
- Import-time execution - Async resource creation
Storage & Persistence (16)
- Storage backend not configured - Production persistence requirements
Lifespan & Integration (17)
- Lifespan not passed to ASGI app - FastAPI/Starlette integration
Middleware (18-19)
- Middleware execution order error - Incorrect middleware ordering
- Circular middleware dependencies - Middleware loop errors
Server Composition (20-21)
- Import vs mount confusion - Static vs dynamic composition
- Resource prefix format mismatch - Path vs protocol formats
OAuth & Security (22-23)
- OAuth proxy without consent screen - Security vulnerabilities
- Missing JWT signing key - Production auth requirements
Icons & Breaking Changes (24-25)
- Icon data URI format error - Invalid data URI format
- Lifespan behavior change (v2.13.0) - Per-server vs per-session
v2.14.0 Migration Errors (26-28)
- BearerAuthProvider removed - Use OAuth patterns instead
- Context.get_http_request() removed - Use alternative context methods
- fastmcp.Image import changed - New import path required
What's Included
Templates (19)
Basic Server Templates:
basic-server.py- Minimal working servertools-examples.py- Sync/async toolsresources-examples.py- Static/dynamic resourcesprompts-examples.py- Prompt templates
Production Features:
storage-backends-example.py- Memory, Disk, Redis storageserver-lifespan-example.py- Database connection lifecyclemiddleware-examples.py- All 8 built-in middleware typesserver-composition-example.py- Import vs mount patternsoauth-proxy-example.py- Full OAuth proxy configurationauthentication-patterns.py- 4 auth strategiesicons-example.py- Server and component icons
Integration & Testing:
openapi-integration.py- OpenAPI auto-generationapi-client-pattern.py- Manual API integrationclient-example.py- Testing with Clienterror-handling.py- Structured errors with retryself-contained-server.py- Production pattern
Configuration:
.env.example- Environment variablesrequirements.txt- Package dependencies (fastmcp>=2.14.0)pyproject.toml- Package configuration
Reference Docs (11)
Error & Deployment:
common-errors.md- 28 errors with solutionscloud-deployment.md- FastMCP Cloud guidecli-commands.md- FastMCP CLI reference
Production Features:
storage-backends.md- Complete storage options guideserver-lifespans.md- Lifecycle management patternsmiddleware-guide.md- Middleware system deep diveoauth-security.md- OAuth Proxy and security featuresperformance-optimization.md- Caching and middleware strategies
Integration & Patterns:
integration-patterns.md- OpenAPI, FastAPI patternsproduction-patterns.md- Self-contained architecturecontext-features.md- Elicitation, progress, sampling, state
Scripts (3)
check-versions.sh- Verify package versionstest-server.sh- Test with FastMCP Clientdeploy-cloud.sh- Deployment checklist
Quick Start
Install the Skill
cd /path/to/claude-skills
./scripts/install-skill.sh fastmcp
Use the Skill
Just mention "fastmcp" or "build an mcp server" in your conversation with Claude Code, and the skill will automatically load.
Example prompts:
- "Help me build a FastMCP server"
- "Create an MCP server that wraps this API"
- "Convert this OpenAPI spec to an MCP server"
- "My MCP server has a circular import error"
- "Deploy my MCP server to FastMCP Cloud"
Production Validation
Tested With:
- FastMCP 2.14.x (v2.14.0+ with Background Tasks and Sampling with Tools)
- Python 3.10, 3.11, 3.12
- Storage backends: Memory, Disk, Redis
- Middleware: All 8 built-in types
- OAuth Proxy: GitHub, Google authentication
- FastMCP Cloud deployments
- OpenAPI integrations
- FastAPI conversions
- Server composition (import/mount)
- Background Tasks with Docket scheduler
- Sampling with Tools (AnthropicSamplingHandler)
Based On:
- Official FastMCP v2.14.x documentation
- FastMCP updates: https://gofastmcp.com/updates.md
- Storage backends: https://gofastmcp.com/servers/storage-backends.md
- Icons: https://gofastmcp.com/servers/icons.md
- Progress: https://gofastmcp.com/servers/progress.md
- Background Tasks: https://gofastmcp.com/servers/tasks.md
- Sampling: https://gofastmcp.com/servers/sampling.md
- Real-world production patterns
- SimPro MCP server case study
- FastMCP Cloud deployment experience
Package Info
- Package:
fastmcp>=2.14.0 - Python:
>=3.10 - Repository: https://github.com/jlowin/fastmcp
- Cloud: https://fastmcp.cloud
- Context7:
/jlowin/fastmcp - Dependencies:
py-key-value-aio(storage backends)cryptography(encrypted storage)httpx(async HTTP)pydantic(validation)docket(background task scheduling, optional)
Included Agents
This skill includes 1 companion agent for common workflows:
| Agent | Purpose | Trigger Phrases |
|---|---|---|
| mcp-scaffold | Create MCP server projects | "create mcp server", "scaffold fastmcp project" |
Why use the agent? Context hygiene. Project scaffolding generates many files - the agent runs in isolated context and returns a clean summary of what was created.
Related Skills
openai-api- OpenAI API integrationclaude-api- Claude API integrationcloudflare-worker-base- Deploy as Cloudflare Workergoogle-gemini-api- Gemini API integrationclerk-auth- Alternative auth solutionbetter-auth- Better Auth for authentication
Skill Metadata
- Version: 2.1.0
- License: MIT
- Token Savings: 90-95%
- Errors Prevented: 28
- Production Tested: ✅
- Last Updated: 2026-01-03
- Breaking Changes: v2.14.0 removes BearerAuthProvider and Context.get_http_request()
Questions or issues? Check the templates and references in this skill, or consult the official FastMCP documentation at https://github.com/jlowin/fastmcp