Building AI Systems
November 12, 2026•11 min read

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
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.

1-Click Install via AIStoreHub CLI
$ aihub mcp install community/postgres-mcp --client cursor
Requires: pip install aistorehubCLI Docs

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.


Why FastMCP is the Fastest Way to Build Tools

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.
  • Clean STDIO Handling: FastMCP guarantees that logging uses stderr, completely preventing MCP stdout corruption.

Setting Up Your Python Environment with uv

We recommend using uv (the ultra-fast Python package manager) to isolate dependencies:

bash
# 1. Create a new directory and virtual environment
mkdir my-custom-mcp && cd my-custom-mcp
uv venv .venv

# 2. Activate virtual environment (Windows PowerShell)
.venv\Scripts\activate
# Or on macOS / Linux: source .venv/bin/activate

# 3. Install FastMCP
uv pip install fastmcp httpx pydantic

Building Your First Tool: System & API Inspector

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()

Testing STDIO Communication via MCP Inspector

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.


Connecting Your Server to Claude Desktop & Cursor

1. Claude Desktop Setup

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:

json
{
  "mcpServers": {
    "system-toolkit": {
      "command": "uv",
      "args": [
        "run",
        "--directory",
        "C:\\path\\to\\my-custom-mcp",
        "python",
        "server.py"
      ]
    }
  }
}

Restart Claude Desktop. A hammer/tools icon will appear indicating your custom tools are active.

2. Cursor IDE Setup

In your project directory or global config (~/.cursor/mcp.json), add:

json
{
  "mcpServers": {
    "system-toolkit": {
      "command": "uv",
      "args": ["run", "python", "C:/path/to/my-custom-mcp/server.py"]
    }
  }
}

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.


Publishing Your MCP Server to the AIStoreHub Registry

Once your tool is tested, you can share it with over 5,000 active AI developers:

  1. Push your repository to GitHub (include a descriptive README.md and requirements.txt).
  2. Visit AIStoreHub Submission Portal.
  3. 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.
  4. Users worldwide can now discover and install your tool with 1 command:
bash
aistorehub pull your-username/catalog/system-toolkit

Frequently Asked Questions

Interactive Registry Preview

Featured Systems in the AIStoreHub Registry

Verified packages installable directly via terminal into Cursor, Claude Desktop, and Python runtimes.

Browse all 143 systems
MCP Server
PostgreSQL & SQLite Inspector

Inspect schema, explain queries, and generate zero-downtime migrations in Cursor.

Autonomous Agent
Harvey 24/7 AI Sales Agent

Autonomous prospecting, cold emails, and meeting booking with zero API token bills.

Claude Skill
Day Trader Skills: 11 Claude Skills

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.
AIStoreHub
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.

Topics:#FastMCP#Python#Model Context Protocol#MCP Development#Developer Guide#Claude Desktop#Cursor

Related Engineering Guides

Continue learning how to build, monetize, and operate AI systems effectively.