midudev/autoskills/fastmcp
Claude Code and agent skill by midudev/autoskills
- community
Checking that the SKILL.md file is still in the repository.
Production patterns for FastMCP Python MCP servers. Use when writing, improving, or debugging FastMCP Python code — tool schema design, multi-operation tools, pre-formatted output, Context usage, middleware, lifespan and startup/shutdown hooks, partial failure handling, running and deploying, async patterns, in-process testing with fastmcp.Client, and common mistakes. Do NOT activate for general questions about what MCP is, MCP concepts, or building an MCP server from scratch (use mcp-builder for that).
Install
npx vskill@latest install midudev/autoskills/fastmcpSKILL.md
The same SKILL.md was published earlier as midudev/autoskills/fastmcp.
FastMCP — Production Patterns
FastMCP (v3.x) is the standard Python framework for building MCP servers. This skill covers production patterns verified against the real FastMCP API — applicable to any domain: databases, REST APIs, file systems, Git, Slack, email, or any external service.
When to use
- Writing new tools or prompts in an existing FastMCP server
- Improving tool schemas, output formatting, or error messages
- Adding middleware, lifespan hooks, or lifecycle management
- Running and deploying FastMCP servers (transport choices)
- Testing FastMCP tools with the built-in
Client - Debugging failing tool calls or silent errors
- Handling partial failures across multiple external calls
Do NOT use for: general MCP questions, MCP protocol explanation, or scaffolding a new server from scratch (use mcp-builder skill instead).
Running the Server
FastMCP 3.x provides built-in run methods. Steps to deploy:
- Define your tools, middleware, and lifespan (see sections below)
- Create the
FastMCPinstance - Call
mcp.run()with the right transport for your use case - Wrap in
if __name__ == "__main__":
Transport choices:
| Transport | When to use | How | |
|---|---|---|---|
stdio (default) | Local agents: Claude Desktop, Cursor, CLI tools | mcp.run() | |
streamable-http | Remote/cloud agents, multi-user servers | mcp.run(transport="streamable-http", host="0.0.0.0", port=8000) | |
sse | Older clients that don't support streamable-http | mcp.run(transport="sse", port=8000) |
Server Setup
Define tools and middleware before creating the server. Register tools in an explicit method — keeps __init__ readable:
Lifespan — Startup and Shutdown
Real API: yield a dict, access via `ctx.lifespan_context` in tools.
Two equivalent patterns — both verified working in FastMCP 3.x. Both require Optional[Context] type hint on tool params (without it ctx is always None — see Common Mistakes):
Access in any tool via ctx.lifespan_context:
Tools that depend on lifespan state cannot use `ctx=None` in unit tests. Use Client(mcp) for those — it runs the full lifespan.
Tool Registration
The docstring IS the schema
The docstring becomes what the LLM sees when deciding whether to call the tool. Write it for the LLM:
Rules: first line = what + when to call; Args: = valid values and dependencies; Limits: = for irreversible tools; never state what the LLM already knows.
Context
ctx position (first or last) does not affect FastMCP's schema — put it last by convention. FastMCP automatically strips ctx from the tool's inputSchema so the LLM never sees it.
Multi-Operation Tool Pattern
Combine related operations into one tool with an operation parameter. Applies to any backend:
When to use multi-operation vs separate tools: same backend + related ops → multi-operation; one op must precede another → multi-operation; more than 5 ops with very different params → split.
Output Formatting
Return a pre-formatted output field alongside structured data. This applies to any domain:
In your skill or prompt: "Display the `output` field content verbatim. Do not reformat the `data` field."
Consistent return shapes — always the same top-level keys:
Note: "partial" is a project convention, not a FastMCP framework concept.
Always return a `dict`. FastMCP accepts any return type (string, int, None), but result.data in tests will be that raw value — result.data["status"] will raise TypeError for non-dict returns. Consistent dict returns make testing predictable.
Error messages that guide the agent:
Partial Failure Handling
When a tool makes multiple external calls and one fails, aggregate results rather than failing entirely:
This is the start of the file. Read the full SKILL.md on GitHub.
Security
- Security scanPassed, 95 of 100Pattern checks on the skill's files.
- Model reviewPassed
Quality evaluation
- Task evaluationNot runNo evaluation yet. Run one in Skill Studio.
Source
- SKILL.md in the repositoryCheckingpackages/autoskills/skills-registry/fastmcp/SKILL.md
Popularity
- Repository stars
- 6,099
- Repository forks
- 561
- 7-day trend score
- 44
Stars and forks are for the whole GitHub repository, not this skill alone. Not refreshed yet.
Works with
Any agent vskill installs to: 56 targets in all. These 39 have a page on this site.
- Claude Code
- Cursor
- GitHub Copilot
- Windsurf
- Codex
- Gemini CLI
- Cline
- Amp
- Roo Code
- Goose
- Continue
- Kilo Code
- Junie
- Trae
- OpenHands
- Qwen Code
- AI Agent
- Tabnine Chat
- Sourcegraph Cody
- Amazon Q
- Firebase Genkit
- Sweep
- Devin
- Phind
- Mentat
- Claude Desktop
- Aider
- GPT Pilot
- Plandex
- bolt.new
- v0
- Replit Agent
- Anse
- TypingMind
- BetterChatGPT
- LibreChat
- Warp AI
- Pieces
- Fig AI
Embed badge
[](https://verified-skill.com/skills/midudev/autoskills/fastmcp)