Loading...
Loading...
Build MCP servers in Python with FastMCP. Workflow: define tools and resources, build server, test locally, deploy to FastMCP Cloud or Docker. Use when creating MCP servers, exposing tools/resources/prompts to LLMs, building Claude integrations, or troubleshooting FastMCP module-level server, storage, lifespan, middleware, OAuth, or deployment errors.
npx skill4agent add jezweb/claude-skills mcp-builderpip install fastmcpassets/basic-server.pyfrom fastmcp import FastMCP
# MUST be at module level for FastMCP Cloud
mcp = FastMCP("My Server")
@mcp.tool()
async def search_customers(query: str) -> str:
"""Search customers by name or email."""
# Implementation here
return f"Found customers matching: {query}"
@mcp.resource("customers://{customer_id}")
async def get_customer(customer_id: str) -> str:
"""Get customer details by ID."""
return f"Customer {customer_id} details"
if __name__ == "__main__":
mcp.run()my-mcp-server/
├── src/index.ts # MCP server (for Claude.ai)
├── scripts/
│ ├── search.ts # CLI version of search tool
│ └── _shared.ts # Shared auth/config
├── SCRIPTS.md # Documents available scripts
└── package.jsonassets/SCRIPTS-TEMPLATE.mdassets/script-template.ts# Run server directly
python server.py
# With FastMCP dev mode (auto-reload)
fastmcp dev server.py
# HTTP mode for remote clients
python server.py --transport http --port 8000
# Test with MCP Inspector
fastmcp dev server.py --with-editable .fastmcp deploy server.py --name my-serverreferences/cloud-deployment.md# CORRECT
mcp = FastMCP("My Server")
@mcp.tool()
def my_tool(): ...
# WRONG — Cloud can't find the server
def create_server():
mcp = FastMCP("My Server")
return mcp@mcp.tool()
async def search(
query: str, # Required parameter
limit: int = 10, # Optional with default
tags: list[str] = [] # Complex types supported
) -> str:
"""Docstring becomes the tool description."""
...@mcp.tool()
async def get_data(id: str) -> str:
try:
result = await fetch_data(id)
return json.dumps(result)
except NotFoundError:
return f"Error: No data found for ID {id}"assets/basic-server.pyassets/self-contained-server.pyassets/tools-examples.pyassets/resources-examples.pyassets/prompts-examples.pyassets/client-example.pyassets/SCRIPTS-TEMPLATE.mdassets/script-template.tsreferences/common-errors.mdreferences/cli-commands.mdreferences/cloud-deployment.mdreferences/production-patterns.mdreferences/integration-patterns.mdreferences/context-features.md