The Struggle of Building MCP Servers the “Classic” Way
Last month, I received an urgent task at 2 AM. The team needed to connect Claude Desktop to the log system to automatically diagnose issues when the server crashed. I rushed to use the standard Model Context Protocol (MCP) SDK. The result? I spent over an hour just writing boilerplate code: defining JSON schemas, managing connections, and handling minor errors.
It felt like wanting to drive a nail but having to forge the hammer first. The original SDK is powerful but too low-level for rapid deployment. That’s why I switched to FastMCP. This framework makes creating an MCP Server as effortless as FastAPI did for Web APIs.
Comparison: Standard SDK vs. FastMCP
Before diving into the code, let’s look at the differences. You’ll understand why FastMCP is the top choice for real-world projects today.
1. MCP Python SDK (The Old Way)
In this approach, you have to define everything manually. To add a tool, you must write the function, register it in a list, and describe the input/output using extremely verbose JSON Schema. A single missing comma in the schema, and the AI will be “clueless” about what the tool does.
2. FastMCP (The New Way)
FastMCP uses Python Decorators similar to FastAPI. You just write a pure Python function and add a decorator. The framework automatically handles JSON Schema generation, data validation, and registration with the MCP client. This reduces redundant code by up to 80%.
| Criteria | Standard SDK | FastMCP |
|---|---|---|
| Deployment Time | A few hours | A few minutes |
| Tool Definition | Manual JSON Schema | Automatic via Decorators |
| Complexity | High, error-prone | Low, easy to maintain |
| Validation | Manual logic required | Based on Python Type Hints |
Why is FastMCP worth using?
The biggest advantage I’ve found is the Developer Experience (DX). When focusing on business logic, you don’t want to wrestle with protocol structures. FastMCP helps me answer the question: “What data does this function get for the AI?” instead of “How do I explain this function to the AI?”.
However, it does have a minor drawback: it hides too many underlying details. If you need deep control over the transport layer, FastMCP might feel a bit restrictive. But for 95% of common needs, it’s the optimal choice.
Step-by-Step Implementation of a Real-World MCP Server
We will build a server that allows AI to read log files and check system resources in real-time.
Step 1: Environment Setup
Create a virtual environment to avoid library conflicts. I recommend using uv for installation, which is 10 times faster than standard pip.
pip install fastmcp psutil
Step 2: Writing the Source Code for the MCP Server
Create a server.py file. You’ll see how surprisingly clean it is:
from fastmcp import FastMCP
import psutil
import os
# Initialize the server with an identifier
mcp = FastMCP("SystemMonitor")
# Tool for AI to check disk usage
@mcp.tool()
def get_disk_usage(path: str = "/") -> str:
"""Check disk usage at a specific path."""
usage = psutil.disk_usage(path)
free_gb = usage.free // (2**30)
return f"Free space: {free_gb}GB out of {usage.total // (2**30)}GB total"
# Resource for AI to read system information (read-only)
@mcp.resource("config://system_info")
def get_system_info() -> str:
"""Provides CPU and OS information."""
return f"OS: {os.name}, CPU: {os.cpu_count()} cores"
if __name__ == "__main__":
mcp.run()
Code Breakdown:
- @mcp.tool(): Turns a Python function into an AI-callable tool. FastMCP inspects type hints (like
path: str) to generate the schema. - Docstring: This is the “manual” for the AI. It relies on this to know when to use the tool.
- @mcp.resource(): Provides static data or system state for the AI to reference.
Step 3: Connecting to Claude Desktop
To test, add the configuration to your claude_desktop_config.json file:
{
"mcpServers": {
"monitor-server": {
"command": "python",
"args": ["/path/to/your/server.py"]
}
}
}
Restart Claude, and you’ll see a lightning bolt icon appear. Now you can ask: “How much free space is left on my hard drive?” and the AI will automatically call the Python function you just wrote.
Hard-Won Lessons from Implementation
After many nights of debugging, I’ve gathered three important tips for a stable server:
- Invest in Docstrings: Don’t just write them for the sake of it. Be detailed: “Use this tool when comparing disk space between partitions.” The AI will be significantly smarter.
- Wrap in Try-Except carefully: Don’t let the server crash. Return errors as strings. For example: “Error: Path /data not found.” The AI can read this and suggest a solution instead of freezing.
- Control Permissions: FastMCP runs with the current user’s permissions. Never write a tool that allows file deletion (
os.remove) without rigorous input validation.
FastMCP is the shortest path to turning scattered Python scripts into a powerful AI Agent system. It helps you remove technical barriers to focus on what matters most: Data and Business Logic.
