FastMCP: Create MCP Servers in Minutes, Not Hours

FastMCP: Create MCP Servers in Minutes, Not Hours

4 min de leitura

Have you ever tried to create an MCP server and found yourself drowning in dozens of config files, complex boilerplate, and hours of debugging before getting your first tool working? Developing and testing MCP servers needs to be fast — agile iteration is critical when experimenting with AI agents. That’s exactly where FastMCP comes in.

The Problem: MCP Complexity Kills Velocity

Even with AI-generated code (vibe coding), implementing MCP from scratch means understanding dozens of concepts before testing your first tool:

  • 🔌 Transport protocols (STDIO vs HTTP vs SSE)
  • 📡 Handshake and capability negotiation
  • 🔄 Correct JSON-RPC serialization
  • 🛠️ Registering and exposing tools/resources/prompts
  • ⚠️ Protocol error handling
  • 🐛 Inter-process communication debugging

The result: You waste time learning infrastructure instead of building features.

What we need: Abstract the protocol and focus on business logic.

FastMCP: Extreme Simplicity

FastMCP is a Python library that reduces a complete MCP server to literally 3 lines of code:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
from fastmcp import FastMCP

mcp = FastMCP("My Server")

@mcp.tool
def multiply(a: float, b: float) -> float:
    """Multiplies two numbers."""
    return a * b

if __name__ == "__main__":
    mcp.run()

Done. You have a fully functional MCP server with a tool that can be called by Claude, GPT, GitHub Copilot, or any MCP client.

Building Your First Server in 2 Minutes

Let’s create a data analysis server from scratch:

1. Installation

1
pip install fastmcp

2. Full Code

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
from fastmcp import FastMCP

mcp = FastMCP(
    "Data Analysis",
    instructions="Server for numerical dataset analysis. Use get_summary() for an overview."
)

@mcp.tool
def calculate_mean(numbers: list[float]) -> float:
    """Calculates the mean of a list of numbers."""
    if not numbers:
        return 0.0
    return sum(numbers) / len(numbers)

@mcp.tool
def find_outliers(numbers: list[float], std_devs: float = 2.0) -> list[float]:
    """
    Identifies outliers in a list using the standard deviation rule.

    Args:
        numbers: List of numbers to analyze
        std_devs: Number of standard deviations to consider outlier (default: 2.0)
    """
    if len(numbers) < 2:
        return []

    mean = sum(numbers) / len(numbers)
    variance = sum((x - mean) ** 2 for x in numbers) / len(numbers)
    std_dev = variance ** 0.5

    upper = mean + (std_devs * std_dev)
    lower = mean - (std_devs * std_dev)

    return [x for x in numbers if x > upper or x < lower]

@mcp.resource("data://config")
def get_config() -> dict:
    """Returns server configuration."""
    return {
        "version": "1.0",
        "mode": "production",
        "max_elements": 10000
    }

@mcp.prompt
def analyze_dataset(data_points: list[float]) -> str:
    """Generates a prompt for dataset analysis."""
    formatted = ", ".join(str(p) for p in data_points[:10])
    if len(data_points) > 10:
        formatted += f"... ({len(data_points)} points total)"

    return f"""Analyze this dataset:
Data: {formatted}

Provide:
1. General trend
2. Outliers
3. Key insights"""

if __name__ == "__main__":
    mcp.run()

Save as data_server.py and run:

1
python data_server.py

Done! Server running on STDIO, ready to connect with any MCP client.

The 3 Component Types

FastMCP exposes three types of components to clients:

🔧 Tools

Functions the agent can invoke to perform actions:

1
2
3
4
5
@mcp.tool
def get_stock_price(symbol: str) -> dict:
    """Fetches the current price of a stock."""
    # Your logic here
    return {"symbol": symbol, "price": 150.25, "currency": "USD"}

📊 Resources

Passive data that clients can read:

1
2
3
4
5
6
7
8
@mcp.resource("data://metrics")
def get_metrics() -> dict:
    """Exposes system metrics."""
    return {
        "requests_today": 1247,
        "avg_response_time_ms": 45,
        "error_rate_pct": 0.3
    }

💬 Prompts (Templates)

Reusable templates to guide LLMs:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
@mcp.prompt
def review_code(code: str, language: str) -> str:
    """Template for code review."""
    return f"""Review this {language} code:

Language: {language}
Code:\n{code}\n

Analyze:
- Potential bugs
- Performance issues
- Violated best practices
- Improvement suggestions"""

Transports: STDIO, HTTP, or SSE

FastMCP supports multiple transports without changing your code:

STDIO (Default — for local integration)

1
mcp.run()  # Uses STDIO automatically

HTTP (For web services)

1
mcp.run(transport="http", host="0.0.0.0", port=8000)

You now have an HTTP endpoint with the MCP Streamable protocol — perfect for production deployment.

Conclusion

FastMCP removes the friction from MCP server development. Instead of spending hours on protocol boilerplate, you write your business logic in minutes and connect it to any AI agent. Give it a try on your next project.