Build and Test Python MCP Servers with FastMCP
Build, test, and deploy Python MCP servers.
Written by Neura Market from the official Hermes Agent documentation for Fastmcp. Commands, paths, and version numbers are reproduced from the source unchanged.
Read the official documentationFastMCP is a Python framework for building, testing, and deploying MCP servers. You reach for it when you need to wrap an API, database, CLI, or file-processing workflow as MCP tools, resources, or prompts. It also handles local validation, installation into MCP clients like Claude Code or Cursor, and preparation for HTTP deployment.
What it does
FastMCP gives you a Pythonic way to define MCP servers. You write functions decorated with @mcp.tool, @mcp.resource, or @mcp.prompt, and FastMCP handles the protocol. The CLI lets you inspect, list, call, and run your server locally before wiring it into any client. When the server is stable, you can install it into supported MCP clients or deploy it as an HTTP endpoint.
Before you start
Install FastMCP in your working Python environment:
pip install fastmcp
fastmcp version
If you plan to use the API wrapper template, also install httpx:
pip install httpx
The skill ships with templates, scripts, and references under the path optional-skills/mcp/fastmcp. It is optional and installed on demand. It runs on Linux, macOS, and Windows.
Included files
Templates
templates/api_wrapper.py- REST API wrapper with auth header supporttemplates/database_server.py- read-only SQLite query servertemplates/file_processor.py- text-file inspection and search server
Scripts
scripts/scaffold_fastmcp.py- copy a starter template and replace the server name placeholder
References
references/fastmcp-cli.md- FastMCP CLI workflow, installation targets, and deployment checks
Workflow
1. Pick the smallest viable server shape
Choose the narrowest useful surface area first:
- API wrapper: start with 1-3 high-value endpoints, not the whole API
- database server: expose read-only introspection and a constrained query path
- file processor: expose deterministic operations with explicit path arguments
- prompts/resources: add only when the client needs reusable prompt templates or discoverable documents
Prefer a thin server with good names, docstrings, and schemas over a large server with vague tools.
2. Scaffold from a template
Copy a template directly or use the scaffold helper:
python ~/.hermes/skills/mcp/fastmcp/scripts/scaffold_fastmcp.py \
--template api_wrapper \
--name "Acme API" \
--output ./acme_server.py
Available templates:
python ~/.hermes/skills/mcp/fastmcp/scripts/scaffold_fastmcp.py --list
If copying manually, replace __SERVER_NAME__ with a real server name.
3. Implement tools first
Start with @mcp.tool functions before adding resources or prompts.
Rules for tool design:
- Give every tool a concrete verb-based name
- Write docstrings as user-facing tool descriptions
- Keep parameters explicit and typed
- Return structured JSON-safe data where possible
- Validate unsafe inputs early
- Prefer read-only behavior by default for first versions
Good tool examples:
get_customersearch_ticketsdescribe_tablesummarize_text_file
Weak tool examples:
runprocessdo_thing
4. Add resources and prompts only when they help
Add @mcp.resource when the client benefits from fetching stable read-only content such as schemas, policy docs, or generated reports.
Add @mcp.prompt when the server should provide a reusable prompt template for a known workflow.
Do not turn every document into a prompt. Prefer:
- tools for actions
- resources for data/document retrieval
- prompts for reusable LLM instructions
5. Test the server before integrating it anywhere
Use the FastMCP CLI for local validation:
fastmcp inspect acme_server.py:mcp
fastmcp list acme_server.py --json
fastmcp call acme_server.py search_resources query=router limit=5 --json
For fast iterative debugging, run the server locally:
fastmcp run acme_server.py:mcp
To test HTTP transport locally:
fastmcp run acme_server.py:mcp --transport http --host 127.0.0.1 --port 8000
fastmcp list http://127.0.0.1:8000/mcp --json
fastmcp call http://127.0.0.1:8000/mcp search_resources query=router --json
Always run at least one real fastmcp call against each new tool before claiming the server works.
6. Install into a client when local validation passes
FastMCP can register the server with supported MCP clients:
fastmcp install claude-code acme_server.py
fastmcp install claude-desktop acme_server.py
fastmcp install cursor acme_server.py -e .
Use fastmcp discover to inspect named MCP servers already configured on the machine.
When the goal is Hermes integration, either:
- configure the server in
~/.hermes/config.yamlusing thenative-mcpskill, or - keep using FastMCP CLI commands during development until the interface stabilizes
7. Deploy after the local contract is stable
For managed hosting, Prefect Horizon is the path FastMCP documents most directly. Before deployment:
fastmcp inspect acme_server.py:mcp
Make sure the repo contains:
- a Python file with the FastMCP server object
requirements.txtorpyproject.toml- any environment-variable documentation needed for deployment
For generic HTTP hosting, validate the HTTP transport locally first, then deploy on any Python-compatible platform that can expose the server port.
Common patterns
API wrapper pattern
Use when exposing a REST or HTTP API as MCP tools.
Recommended first slice:
- one read path
- one list/search path
- optional health check
Implementation notes:
- keep auth in environment variables, not hardcoded
- centralize request logic in one helper
- surface API errors with concise context
- normalize inconsistent upstream payloads before returning them
Start from templates/api_wrapper.py.
Database pattern
Use when exposing safe query and inspection capabilities.
Recommended first slice:
list_tablesdescribe_table- one constrained read query tool
Implementation notes:
- default to read-only DB access
- reject non-
SELECTSQL in early versions - limit row counts
- return rows plus column names
Start from templates/database_server.py.
File processor pattern
Use when the server needs to inspect or transform files on demand.
Recommended first slice:
- summarize file contents
- search within files
- extract deterministic metadata
Implementation notes:
- accept explicit file paths
- check for missing files and encoding failures
- cap previews and result counts
- avoid shelling out unless a specific external tool is required
Start from templates/file_processor.py.
Quality bar
Before handing off a FastMCP server, verify all of the following:
- server imports cleanly
fastmcp inspectsucceedsfastmcp list --jsonsucceeds- every new tool has at least one real
fastmcp call - environment variables are documented
- the tool surface is small enough to understand without guesswork
Troubleshooting
FastMCP command missing
Install the package in the active environment:
pip install fastmcp
fastmcp version
fastmcp inspect fails
Check that:
- the file imports without side effects that crash
- the FastMCP instance is named correctly in ``
- optional dependencies from the template are installed
Tool works in Python but not through CLI
Run:
fastmcp list server.py --json
fastmcp call server.py your_tool_name --json
This usually exposes naming mismatches, missing required arguments, or non-serializable return values.
Hermes cannot see the deployed server
The server-building part may be correct while the Hermes config is not. Load the native-mcp skill and configure the server in ~/.hermes/config.yaml, then restart Hermes.
When not to use it
Use native-mcp when the server already exists and only needs to be connected to Hermes. Use mcporter when the goal is ad-hoc CLI access to an existing MCP server instead of building one.
Limits and gotchas
- The source does not list explicit limits beyond the troubleshooting items above.
- The quality bar section is your best checklist for avoiding common failures.
What pairs with this
native-mcpskill for connecting an existing server to Hermesmcporterfor ad-hoc CLI access to an MCP serverreferences/fastmcp-cli.mdfor CLI details, install targets, and deployment checks