// Build production-ready MCP servers using FastMCP framework with proven patterns for tools, resources, prompts, OAuth authentication, and comprehensive testing. Use this when creating FastMCP-based MCP servers with features like Google OAuth, multiple resource types, testing with FastMCP Client, or complex tool implementations.
| name | fastmcp-builder |
| description | Build production-ready MCP servers using FastMCP framework with proven patterns for tools, resources, prompts, OAuth authentication, and comprehensive testing. Use this when creating FastMCP-based MCP servers with features like Google OAuth, multiple resource types, testing with FastMCP Client, or complex tool implementations. |
This skill provides comprehensive, production-ready patterns for building MCP (Model Context Protocol) servers using FastMCP, the official high-level Python framework. It includes complete reference implementations, working examples, and best practices proven in production.
FastMCP is the recommended approach for building MCP servers in Python - it's simpler, faster to develop, and more maintainable than the low-level MCP SDK.
This skill contains:
reference/) - 6 comprehensive guides covering all aspects of FastMCP developmentexamples/) - Runnable examples from minimal to complete serversreference-project/) - Full production implementation with:
๐ก Tip: When in doubt, look at the reference-project for real-world implementation examples.
Use this skill when you need to:
โ Build MCP servers with FastMCP - Python-based MCP server development โ Add OAuth authentication - Especially Google OAuth for remote access โ Implement production patterns - Tools, resources, prompts with best practices โ Set up comprehensive testing - Using FastMCP Client for fast, in-memory tests โ Structure larger projects - Proper organization and separation of concerns โ Deploy to production - With authentication, error handling, monitoring
Don't use this skill for:
IMPORTANT: When encountering questions or issues not covered in this skill's reference materials, you should:
The most reliable way to find FastMCP documentation is using WebSearch with site-specific queries:
WebSearch(
query="site:gofastmcp.com [your specific topic]"
)
This will search the official FastMCP documentation site and return relevant pages.
If you know the general documentation structure, you can fetch specific pages directly:
WebFetch(
url="https://gofastmcp.com/[section]/[topic]",
prompt="Your specific question about this topic"
)
Common documentation sections:
/getting-started/ - Installation, quickstart, welcome/servers/ - Tools, resources, prompts, context, logging/deployment/ - Running servers, HTTP deployment, configuration/integrations/ - Auth0, AWS Cognito, Azure, GitHub, Google, WorkOS, OpenAI, etc./testing/ - Testing guides and best practicesTip: Any page can be accessed as markdown by appending .md to the URL.
Consult official documentation when:
User asks about OpenAI integration:
WebSearch(query="site:gofastmcp.com openai integration")
โ Find https://gofastmcp.com/integrations/openai
โ Fetch that page for details
User asks about AWS Cognito authentication:
WebSearch(query="site:gofastmcp.com aws cognito oauth")
โ Find relevant auth documentation
โ Implement based on official guidance
User asks about testing patterns:
WebSearch(query="site:gofastmcp.com testing")
โ Find testing documentation
โ Apply patterns from official docs
Exploring what's available:
WebSearch(query="site:gofastmcp.com deployment options")
WebSearch(query="site:gofastmcp.com authentication providers")
โ Browse results to see available topics
Note: Always try the reference materials in this skill first, then consult official docs if needed.
Step 1.1: Review FastMCP Overview
Step 1.2: Understand Requirements
Step 1.3: Review Project Structure
Step 1.4: Set Up Project
Create project structure:
mkdir my-mcp-server
cd my-mcp-server
# Create directories
mkdir -p app/tools app/resources app/prompts tests
# Create initial files
touch app/__init__.py
touch app/main.py
touch app/main_noauth.py
touch app/common.py
touch app/config.py
touch tests/__init__.py
touch pyproject.toml
touch .env.example
touch README.md
Initialize with uv:
# Install FastMCP
uv add fastmcp==2.13.0.1
uv add python-dotenv==1.2.1
# Add test dependencies
uv add --optional test pytest==8.4.2 pytest-asyncio==1.2.0 pytest-mock==3.15.1 httpx==0.28.1
Step 2.1: Implement Configuration
Create app/config.py based on patterns in project_structure.md:
Step 2.2: Implement Tools
Load tool_patterns.md for comprehensive patterns:
Identify tool patterns needed:
Create tools in app/tools/:
Example tool structure:
# app/tools/my_tool.py
async def my_tool(param: str, ctx: Context | None = None) -> dict:
"""
Tool description
Args:
param: Parameter description
ctx: FastMCP context (auto-injected)
Returns:
dict: Result structure
"""
try:
if ctx:
await ctx.info("Processing...")
# Tool logic here
result = process(param)
if ctx:
await ctx.info("Completed!")
return {"status": "success", "data": result}
except Exception as e:
if ctx:
await ctx.error(f"Failed: {e}")
return {"status": "error", "error": str(e)}
Step 2.3: Implement Resources (if needed)
Load resource_patterns.md for all resource types:
Choose resource types:
Create resources in app/resources/:
Example resource:
# app/resources/welcome.py
def get_welcome_message() -> str:
"""Welcome message resource"""
return "Welcome to my MCP server!"
Step 2.4: Implement Prompts (if needed)
Create reusable prompt templates:
# app/prompts/explain.py
def explain_concept(
concept: str,
audience_level: str = "intermediate",
) -> str:
"""Generate explanation prompt"""
return f"Explain {concept} for {audience_level} audience..."
Step 2.5: Create Common Registration
In app/common.py, register all components:
from fastmcp import FastMCP
# Import tools
from app.tools.my_tool import my_tool
# Import resources
from app.resources.welcome import get_welcome_message
# Import prompts
from app.prompts.explain import explain_concept
def register_all(mcp: FastMCP) -> None:
"""Register all components - DRY principle"""
# Tools
mcp.tool()(my_tool)
# Resources
mcp.resource("greeting://welcome")(get_welcome_message)
# Prompts
mcp.prompt()(explain_concept)
Step 2.6: Create Server Entry Points
app/main_noauth.py (for local development):
from fastmcp import FastMCP
from app.config import Config
from app.common import register_all
mcp = FastMCP(Config.SERVER_NAME)
register_all(mcp)
if __name__ == "__main__":
mcp.run()
app/main.py (with OAuth - if needed): Load oauth_integration.md for complete OAuth setup.
Only if you need remote access with authentication.
Step 3.1: Set Up Google OAuth
Follow oauth_integration.md:
Step 3.2: Test OAuth Flow
Step 4.1: Set Up Test Structure
Load testing_guide.md for comprehensive testing patterns.
Create tests/conftest.py:
import pytest
from fastmcp import Client
from app.main_noauth import mcp
@pytest.fixture
async def client():
"""Provide FastMCP client for testing"""
async with Client(mcp) as c:
yield c
Step 4.2: Write Tool Tests
# tests/test_tools.py
@pytest.mark.asyncio
async def test_my_tool(client):
"""Should execute my_tool successfully"""
result = await client.call_tool("my_tool", {"param": "test"})
assert result.data["status"] == "success"
Step 4.3: Write Resource Tests
# tests/test_resources.py
@pytest.mark.asyncio
async def test_welcome_resource(client):
"""Should read welcome resource"""
content = await client.read_resource("greeting://welcome")
assert "Welcome" in content
Step 4.4: Write Integration Tests
# tests/test_integration.py
@pytest.mark.asyncio
async def test_complete_workflow(client):
"""Should execute complete workflow"""
# Test multiple components working together
pass
Step 4.5: Run Tests
# Run all tests
uv run pytest tests/ -v
# Run with coverage
uv run pytest tests/ --cov=app --cov-report=html
Step 5.1: Write README
Document:
Step 5.2: Prepare for Deployment
Environment Variables:
Testing:
Deployment:
Load these as needed during development:
Run or reference these complete examples:
from fastmcp import FastMCP
mcp = FastMCP("my-server")
@mcp.tool()
def greet(name: str) -> str:
"""Greet someone"""
return f"Hello, {name}!"
if __name__ == "__main__":
mcp.run()
from fastmcp import FastMCP, Context
mcp = FastMCP("my-server")
# Tool
@mcp.tool()
async def process(text: str, ctx: Context | None = None) -> dict:
if ctx:
await ctx.info("Processing...")
return {"result": text.upper()}
# Resource
@mcp.resource("greeting://hello")
def get_greeting() -> str:
return "Hello from resource!"
# Prompt
@mcp.prompt()
def explain(topic: str) -> str:
return f"Explain {topic} in detail"
if __name__ == "__main__":
mcp.run()
from fastmcp import FastMCP
from fastmcp.server.auth.providers.google import GoogleProvider
import os
auth = GoogleProvider(
client_id=os.getenv("GOOGLE_CLIENT_ID"),
client_secret=os.getenv("GOOGLE_CLIENT_SECRET"),
base_url="https://your-server.com",
)
mcp = FastMCP("my-server", auth=auth)
# ... add tools, resources, prompts ...
if __name__ == "__main__":
mcp.run(transport="http", host="0.0.0.0", port=8000)
app/tools/my_tool.pyapp/common.py registrationtests/test_tools.pyuv run pytest tests/test_tools.py -vapp/config.py with OAuth settingsapp/main.py to use GoogleProvidermain_noauth.py for faster local testingawait ctx.debug(...)common.pyHappy building! ๐