How to Build & Publish an MCP Server in Python with FastMCP (2026 Step-by-Step Guide)
Create a production-grade Model Context Protocol tool in under 10 minutes using FastMCP. Test locally via STDIO, validate tool schemas, and publish to AIStoreHub.
AIStoreHub
Open AI Registry & Developer Platform
Executive Blueprint & Summary (BLUF)
While official TypeScript MCP SDKs require complex build steps and node process management, Python developers can build and run production-grade Model Context Protocol servers in under 30 lines of code using FastMCP. This handbook walks through environment setup with uv, creating typed tools with Pydantic validation, connecting to local SQLite and REST APIs, debugging STDIO streams, and submitting your verified tool to the AIStoreHub open registry.
Building custom tools for AI coding assistants used to require writing monolithic agent loops, managing custom WebSocket protocols, or authoring intricate VS Code extensions.
With the Model Context Protocol (MCP), Anthropic introduced a standardized, client-agnostic protocol that allows any frontier model to discover, parameterize, and execute external code.
For Python developers, the FastMCP framework provides the simplest, most intuitive interface for authoring MCP tools. By leveraging standard Python type annotations and Pydantic validation, FastMCP automatically converts Python functions into JSON-RPC 2.0 tool definitions without manual schema drafting.
In this guide, you will learn how to build a working MCP server from scratch, test it locally, link it to Claude Desktop and Cursor, and publish it to the AIStoreHub open registry.
Looking for Pre-Built Servers? Before building from scratch, explore 250+ community-verified tools in the AIStoreHub MCP Registry with 1-click install.
Traditional MCP development in Python required low-level handling of asyncio streams, raw JSON-RPC packet parsing, and manual error code mapping.
FastMCP abstracts all transport boilerplate:
Automatic JSON Schema Generation: Type hints like city: str and days: int = 5 become structured JSON parameters with automatic required/optional validation.
Docstring Ingestion: Your function docstrings automatically populate the tool description that models like Claude 3.5 Sonnet and GPT-4o read to decide when to call your tool.
Create a file named server.py with the following implementation:
python
from fastmcp import FastMCP
import httpx
import platform
import os
# Initialize FastMCP server instance
mcp = FastMCP("System & API Toolkit")
@mcp.tool()
def get_system_diagnostics() -> dict:
"""Return local host OS, processor architecture, and Python runtime version.
Call this tool when diagnosing developer environment issues or system configuration.
"""
return {
"os": platform.system(),
"release": platform.release(),
"architecture": platform.machine(),
"python_version": platform.python_version(),
"cpu_count": os.cpu_count(),
}
@mcp.tool()
async def query_public_api(endpoint: str) -> dict:
"""Make a secure HTTP GET request to a public REST API and return JSON data.
Args:
endpoint: Full HTTPS URL of the public API endpoint to query.
"""
if not endpoint.startswith("https://"):
return {"error": "Only secure HTTPS endpoints are permitted."}
async with httpx.AsyncClient(timeout=10.0) as client:
try:
response = await client.get(endpoint)
return {
"status_code": response.status_code,
"data": response.json() if "application/json" in response.headers.get("content-type", "") else response.text[:1000]
}
except Exception as e:
return {"error": f"Request failed: {str(e)}"}
if __name__ == "__main__":
mcp.run()
Before configuring Cursor or Claude Desktop, verify that your server passes protocol health checks using the official Anthropic MCP Inspector:
bash
npx @modelcontextprotocol/inspector uv run python server.py
This spins up an interactive browser UI at http://localhost:5173. You can click List Tools, inspect the generated schemas for get_system_diagnostics and query_public_api, and execute test invocations.
Open your claude_desktop_config.json (located at %APPDATA%\Claude\claude_desktop_config.json on Windows or ~/Library/Application Support/Claude/claude_desktop_config.json on macOS) and add your server:
Open Cursor Chat (Ctrl+L / Cmd+L) and type: "What is my machine's CPU architecture?". Cursor will automatically invoke get_system_diagnostics and answer accurately.
Paste your GitHub repository URL. AIStoreHub will automatically parse your manifest, attest Ed25519 tamper-proof release signatures, and list your server in the official catalog.
Users worldwide can now discover and install your tool with 1 command:
Scan charts, calculate risk/reward brackets, and backtest setups via Claude Code.
Frequently Asked Questions
Essential clarifications for developers and engineering teams building and operating AI systems.
FastMCP is a high-level Python framework for building Model Context Protocol servers. It automatically converts standard typed Python functions and docstrings into compliant JSON-RPC 2.0 tool definitions.
Written by AIStoreHub
Open AI Registry & Developer Platform
AIStoreHub is the open registry and 1-click CLI for discovering, running, and installing production-grade AI systems, Model Context Protocol (MCP) servers, and autonomous agents.
Discover the best open-source MCP servers for Cursor IDE and Claude Desktop. Explore top tools for PostgreSQL inspection, autonomous web browsing, secure filesystem ops, and 1-click install commands.
Learn how to connect any Model Context Protocol server to Cursor IDE, fix common mcp.json syntax errors, and automate tool injection using the 1-click AIStoreHub CLI.
Learn how to find claude_desktop_config.json across Windows and macOS, solve spawn ENOENT path errors, pass API tokens securely, and automate tool installation with AIStoreHub CLI.
Diagnose and fix the top 5 MCP server failure modes: MCP Error -32000 Connection closed, Exit code 1, spawn ENOENT, and unhandled JSON-RPC parse exceptions.