npx skills add ...
npx skills add jezweb/claude-skills --skill mcp-builder
Build MCP servers in Python with FastMCP. Define tools / resources / prompts, build the server, test locally, deploy to FastMCP Cloud or Docker. Use whenever the user mentions building an MCP server, exposing tools to LLMs, FastMCP, building a Claude integration, or troubleshooting FastMCP module-level server, storage, lifespan, middleware, OAuth, or deployment errors.
npx skills add jezweb/claude-skills --skill mcp-builder
Build a working MCP server from a description of the tools you need. Produces a deployable Python server using FastMCP.
Ask what the server needs to provide:
A brief like "MCP server for querying our customer database" is enough.
Create the server file. The server instance MUST be at module level:
For Claude Code terminal use, add scripts alongside the MCP server:
CLI scripts provide file I/O, batch processing, and richer output that MCP can't.
See assets/SCRIPTS-TEMPLATE.md and assets/script-template.ts for TypeScript templates.
Quick test -- run directly:
Dev mode with inspector UI (recommended):
HTTP mode for remote clients:
Automated test script using FastMCP Client:
Run these checks before deploying. All required checks must pass.
Required (will cause deploy failure):
python3 -m py_compile server.pyrequirements.txt exists with PyPI packages only (no git+, -e, .whl, .tar.gz)api_key = "..." patterns excluding os.getenv/os.environ)Advisory (warnings):
fastmcp listed in requirements.txt.gitignore includes .envtimeout 5 fastmcp inspect server.pyFastMCP Cloud (simplest):
Cloud requirements:
mcp, server, or apprequirements.txtDocker (self-hosted):
Cloudflare Workers (edge): See the cloudflare-worker-builder skill for Workers-based MCP servers.
FastMCP Cloud requires the server instance at module level:
FastMCP uses type annotations to generate tool schemas:
Return errors as strings, don't raise exceptions:
These are the errors you will hit. Fix them before deploying.
| Error | Cause | Fix |
|---|---|---|
RuntimeError: No server object found at module level | Server inside a function | Export mcp = FastMCP(...) at module level |
RuntimeError: no running event loop | Missing async/await | Use async def for async operations |
TypeError: missing required argument 'context' | Context not type-hinted | Add context: Context with type hint |
ValueError: Invalid resource URI | Missing URI scheme | Use data://, file://, info://, api:// |
| Resource template parameter mismatch | Name mismatch | user://{user_id} needs def get_user(user_id: str) |
| Pydantic validation error | Wrong type hints | Ensure hints match actual data types |
| Transport mismatch | Client/server protocol differ | Match both to stdio or both to http |
| Import errors with editable package | Package not installed | pip install -e . or add to PYTHONPATH |
DeprecationWarning: mcp.settings | Old API | Use os.getenv() instead |
| Port already in use | Stale process | lsof -ti:8000 | xargs kill -9 |
| Schema generation failure | Non-JSON types | Use JSON-compatible types (no NumPy arrays) |
| JSON serialization error | datetime/bytes in response | Convert to .isoformat() or string |
| Circular import | Factory in __init__.py | Use direct imports, avoid factory pattern |
| Python 3.12+ datetime warning | datetime.utcnow() deprecated | Use datetime.now(timezone.utc) |
| Import-time execution | Async resource at module level | Use lazy init pattern |
Keep all utilities in one file to avoid circular imports:
Don't create async resources at module level. Initialise on first use:
Environment variables: FASTMCP_LOG_LEVEL (DEBUG/INFO/WARNING/ERROR), FASTMCP_ENV (development/staging/production).
For specific integration approaches, see references/integration-patterns.md:
httpx.AsyncClient with reusable clientFastMCP.from_openapi(spec, client, route_maps=[...])FastMCP.from_fastapi(app)assets/basic-server.py -- Minimal FastMCP server templateassets/self-contained-server.py -- Server with storage and middlewareassets/tools-examples.py -- Tool patterns and type annotationsassets/resources-examples.py -- Resource URI patternsassets/prompts-examples.py -- Prompt template patternsassets/client-example.py -- MCP client usageassets/SCRIPTS-TEMPLATE.md -- CLI companion docs templateassets/script-template.ts -- TypeScript CLI script template