Design and deploy Model Context Protocol servers with deep knowledge of the JSON-RPC 2.0 spec, transport mechanisms, and protocol lifecycle. Covers FastMCP framework patterns, production hardening, and diagnostic techniques for connectivity failures. Engage when architecting MCP integrations, building custom servers, or debugging protocol-level issues.
Architects Model Context Protocol servers with JSON-RPC 2.0 compliance and FastMCP framework expertise.
npx claudepluginhub aeyeops/aeo-skill-marketplaceThis skill inherits all available tools. When active, it can use any tool Claude has access to.
references/deployment-patterns.mdreferences/dual-client-authentication.mdreferences/fastmcp-framework.mdreferences/mcp-protocol-spec.mdreferences/transport-patterns.mdreferences/troubleshooting-guide.mdscripts/init_mcp_server.pyscripts/test_mcp_connection.pyThis skill provides expert guidance for Model Context Protocol (MCP) architecture, design, implementation, and troubleshooting. Combines deep knowledge of the MCP specification (JSON-RPC 2.0, protocol lifecycle, transport mechanisms) with practical expertise in building production-ready MCP servers using the FastMCP framework. Includes comprehensive troubleshooting capabilities for diagnosing and fixing MCP servers that won't start, can't connect, or fail during operation.
This skill applies to tasks involving:
Create New Server:
python scripts/init_mcp_server.py my-server
cd my-server
pip install -r requirements.txt
python server.py
Test Connection:
python scripts/test_mcp_connection.py http://localhost:8000/mcp
Basic Server Pattern:
from mcp.server.fastmcp import FastMCP
mcp = FastMCP("ServerName")
@mcp.tool()
def my_tool(param: str) -> str:
return f"Result: {param}"
mcp.run(transport="streamable-http")
Tool with Error Handling:
@mcp.tool()
def safe_operation(input: str) -> str:
try:
return process(input)
except ValueError as e:
return json.dumps({"error": str(e), "isError": True})
Deep Dive References:
Reference references/mcp-protocol-spec.md for complete protocol details.
Key Protocol Concepts:
id), Responses (matching id), Notifications (no id)Critical Requirements:
// Request MUST have unique id
{"jsonrpc": "2.0", "id": 1, "method": "tools/list"}
// Response MUST match request id
{"jsonrpc": "2.0", "id": 1, "result": {...}}
// Notification MUST NOT have id
{"jsonrpc": "2.0", "method": "notifications/progress", "params": {...}}
Reference references/transport-patterns.md for transport-specific details.
Transport Selection Guide:
| Use Case | Transport | Reason |
|---|---|---|
| Web application | Streamable HTTP | Browser-compatible, SSE support |
| Local CLI tool | stdio | Simple process model |
| Cloud service | Streamable HTTP | Standard HTTP infrastructure |
| IDE plugin | stdio | Process isolation |
Streamable HTTP Critical Points:
/mcp) for both POST (client→server) and GET (SSE server→client)Mcp-Session-Id header for session managementMcp-Session-Id in CORS expose_headersOrigin header for securitystdio Critical Points:
Reference references/fastmcp-framework.md for comprehensive implementation examples.
Basic Server Pattern:
from mcp.server.fastmcp import FastMCP
mcp = FastMCP("ServerName")
@mcp.tool()
def my_tool(param: str) -> str:
"""Tool description shown to LLM."""
return f"Result: {param}"
if __name__ == "__main__":
mcp.run(transport="streamable-http")
Key Framework Features:
Context.report_progress() for long-running toolsReference references/troubleshooting-guide.md for systematic diagnostic procedures.
Quick Triage Checklist:
ps or Task Manager)curl)tools/list)tools/call)Common Issue Patterns:
@mcp.tool() decorator, server capabilities not advertisedAccept: text/event-stream header, CORS misconfigurationMcp-Session-Id not in CORS expose_headersFor systematic testing, run the diagnostic script:
python scripts/test_mcp_connection.py http://localhost:8000/mcp
Option 1: Quick Start with Template
# Create basic server project
python scripts/init_mcp_server.py my-server
# Create OAuth-protected server
python scripts/init_mcp_server.py my-server --template oauth
# Custom output directory
python scripts/init_mcp_server.py my-server --output /path/to/projects
Generates complete project structure:
server.py - FastMCP server with example toolsrequirements.txt - Python dependenciesDockerfile and docker-compose.yml - Container deploymentREADME.md - Documentationtests/ - Unit test examplesOption 2: Manual Setup
pip install mcp httpx pydanticserver.py with FastMCP initialization@mcp.tool() decorator@mcp.resource() decoratormcp.run(transport="streamable-http")For detailed tool and resource design patterns, see references/fastmcp-framework.md which covers:
IMPORTANT: For production servers supporting multiple clients (OpenAI, Claude), refer to references/dual-client-authentication.md for comprehensive guidance on authentication patterns, OWASP compliance, and recommended architectures.
1. OAuth 2.1 Authentication:
from pydantic import AnyHttpUrl
from mcp.server.auth.provider import TokenVerifier, AccessToken
from mcp.server.auth.settings import AuthSettings
class ProductionTokenVerifier(TokenVerifier):
async def verify_token(self, token: str) -> AccessToken | None:
# Verify JWT signature with public key
# Check expiration timestamp
# Validate required scopes
# Validate audience claim (prevents confused deputy attacks)
if valid:
return AccessToken(token=token, scopes=["user"], expires_at=None)
return None
mcp = FastMCP(
"SecureServer",
token_verifier=ProductionTokenVerifier(),
auth=AuthSettings(
issuer_url=AnyHttpUrl("https://auth.example.com"),
resource_server_url=AnyHttpUrl("http://localhost:8000"),
required_scopes=["user"]
)
)
2. Input Validation: Use Pydantic models with validators to prevent injection attacks and path traversal.
3. CORS Configuration: Configure with specific allowed origins, expose Mcp-Session-Id header for session management.
For production deployment patterns, see references/deployment-patterns.md which covers:
When building systems with both traditional REST API and MCP interface:
from mcp.server.fastmcp import FastMCP
from fastapi import FastAPI
# REST API
rest_api = FastAPI()
@rest_api.get("/api/data/{id}")
def get_data_rest(id: str):
return get_data_from_db(id) # Shared business logic
# MCP Interface
mcp = FastMCP("DualInterface")
@mcp.tool()
def get_data(id: str) -> str:
"""Get data by ID (MCP tool)."""
data = get_data_from_db(id) # Same business logic
return json.dumps(data)
# Mount both
from starlette.applications import Starlette
from starlette.routing import Mount
app = Starlette(routes=[
Mount("/api", rest_api),
Mount("/mcp", mcp.streamable_http_app())
])
For complex systems with multiple specialized servers:
# weather_server.py
weather = FastMCP("WeatherService")
@weather.tool()
def get_weather(city: str) -> dict:
return {"city": city, "temp": 22}
# analytics_server.py
analytics = FastMCP("AnalyticsService")
@analytics.tool()
def get_metrics() -> dict:
return {"users": 1000}
# Combined app
app = Starlette(routes=[
Mount("/weather", weather.streamable_http_app()),
Mount("/analytics", analytics.streamable_http_app())
])
For servers supporting both OpenAI and Claude clients, use separate endpoints with shared backend logic due to:
See references/dual-client-authentication.md for:
test_mcp_connection.py - Diagnostic tool for testing MCP server connectivity and protocol compliance.
Usage:
# Test HTTP MCP server
python scripts/test_mcp_connection.py http://localhost:8000/mcp
# Test with verbose output
python scripts/test_mcp_connection.py http://localhost:8000/mcp --verbose
Systematic checks:
tools/list)Mcp-Session-Id header)init_mcp_server.py - Project generator for new MCP servers.
Usage:
# Create basic FastMCP server
python scripts/init_mcp_server.py my-server
# Create OAuth-protected server
python scripts/init_mcp_server.py my-server --template oauth
# Custom output directory
python scripts/init_mcp_server.py my-server --output /path/to/projects
Generates complete project structure:
server.py with FastMCP initialization and example toolsrequirements.txt with Python dependenciesDockerfile and docker-compose.yml for containerizationREADME.md with documentation and usage instructionstests/ directory with unit test examples.gitignore for Python projectsmcp-protocol-spec.md - Complete MCP protocol specification.
Contents:
transport-patterns.md - Comprehensive transport mechanism guide.
Contents:
fastmcp-framework.md - In-depth FastMCP Python framework guide.
Contents:
troubleshooting-guide.md - Systematic troubleshooting procedures.
Contents:
dual-client-authentication.md - Multi-client authentication patterns.
Contents:
deployment-patterns.md - Production deployment patterns.
Contents:
Create New Server:
python scripts/init_mcp_server.py my-server
cd my-server
pip install -r requirements.txt
python server.py
Test Connection:
python scripts/test_mcp_connection.py http://localhost:8000/mcp
Basic Server Pattern:
from mcp.server.fastmcp import FastMCP
mcp = FastMCP("ServerName")
@mcp.tool()
def my_tool(param: str) -> str:
return f"Result: {param}"
mcp.run(transport="streamable-http")
Tool with Error Handling:
@mcp.tool()
def safe_operation(input: str) -> str:
try:
return process(input)
except ValueError as e:
return json.dumps({"error": str(e), "isError": True})
Reference Documentation:
references/mcp-protocol-spec.mdreferences/transport-patterns.mdreferences/fastmcp-framework.mdreferences/troubleshooting-guide.mdreferences/dual-client-authentication.mdreferences/deployment-patterns.md