Run This Ai
EN DE

Getting Started with FastMCP: A Step-by-Step Tutorial

Build your first MCP server with FastMCP in minutes. Step-by-step guide covering installation, tools, resources, prompts, and client connections.

πŸš€ Want to deploy FastMCP yourself?

Docker configs, system requirements, and installation guides β€” all on one page.

View FastMCP Tool Page β†’

This tutorial walks you through creating your first MCP server with FastMCP β€” from installation to a fully functional tool. By the end, you'll have a working MCP server you can connect to any MCP-compatible LLM client.

Installation

Installing FastMCP is straightforward:

pip install fastmcp

That's it. FastMCP requires Python 3.10+. It has minimal dependencies and works on Linux, macOS, and Windows.

Your First MCP Server

Create a file called server.py:

from fastmcp import FastMCP

mcp = FastMCP("My First Server")

@mcp.tool
def add(a: int, b: int) -> int:
    """Add two numbers together"""
    return a + b

@mcp.tool
def get_weather(city: str) -> str:
    """Get current weather for a city"""
    return f"The weather in {city} is sunny, 22Β°C"

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

Running Your Server

You can run the server in two modes:

SSE Mode (HTTP server):

python server.py

FastMCP runs an SSE (Server-Sent Events) server on http://localhost:8080 by default.

Stdio Mode (for local LLM clients):

python server.py --transport stdio

Adding Resources and Prompts

FastMCP also supports MCP resources and prompts:

@mcp.resource("config://app")
def get_config() -> str:
    """Return application configuration"""
    return "version: 1.0, debug: true"

@mcp.prompt
def greeting(name: str) -> str:
    """Create a friendly greeting prompt"""
    return f"Please greet {name} warmly and ask how you can help them."

Connecting a Client

Use FastMCP's built-in client to connect to any server:

from fastmcp import Client

async with Client("http://localhost:8080") as client:
    result = await client.call_tool("add", {"a": 5, "b": 3})
    print(result)  # 8

FastMCP handles connection negotiation, authentication, and protocol compliance automatically.

For production deployments, consider Docker β€” FastMCP images are available on Docker Hub and can be deployed with a simple docker-compose.yml configuration.

πŸš€ Ready to deploy FastMCP?

Get Docker configs, system requirements, and the full installation guide.

View FastMCP Tool Page β†’
#fastmcp #mcp #python #tutorial #getting-started