NewAI Content Creation is now live in Early Access
Turning Point Academy
0%
Module 2 — Build your first serverLesson 1 of 4
Video lesson

A Python server with FastMCP (stdio)

BeginnerVideo lesson
6 min videoBeginner
Downloads & resources
Grab this lesson's prompts and skills, ready to use.

Skill packs and prompts are provided in English so they work best with the AI tools. Use them as-is.

Your first MCP server in Python with FastMCP

Example prompt

Level: from scratch — no prior experience needed. If you've been following the course, you already know what an MCP server is and what tools are. Now for the fun part: writing one yourself, step by step. Watch the video above and follow this guide at your own pace.

So far we've covered the theory. In this lesson you'll build a real MCP server in Python using FastMCP, a library that does almost all the heavy lifting for you. We're going to build a calculator: a server with one tool that multiplies two numbers. It's a deliberately minimal example — once you understand this one, you understand them all.

What you'll learn

  • What FastMCP is and why it saves us so much code.
  • How to install it inside your virtual environment (the .venv from Module 0).
  • How to define a tool with a decorator, type hints, and a docstring.
  • Why the docstring is what the agent reads to decide when to use your tool.
  • How to run the server over stdio and connect it to a client to test it.

Step 1 — Activate your environment and install FastMCP

First, activate the virtual environment you created in Module 0 (this keeps the packages isolated from your system). Then install the library with pip, Python's package installer.

bash
# Activate the virtual environment (macOS / Linux)
source .venv/bin/activate
# On Windows (PowerShell): .venv\Scripts\Activate.ps1

# Install FastMCP inside the environment
pip install fastmcp
Example prompt

FastMCP is a library that implements the MCP protocol for you. Without it, you'd have to write all the "plumbing" by hand (the handshake, the message format, the tool lists). With it, you focus only on what your server does.

Step 2 — Create the server

Create a file called server.py. These two lines import FastMCP and create your server, which we give a name ("calculator"). That name is how the client will identify it.

python
from fastmcp import FastMCP

mcp = FastMCP("calculator")

mcp is your server. You'll "hang" the tools on this object in the next step.

Step 3 — Define your first tool

Here's the heart of the lesson. A tool is an ordinary Python function that we put the decorator @mcp.tool on top of. That decorator is what turns it into a tool the agent can see and use.

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

Notice three details, because all three matter:

  • The decorator @mcp.tool — tells FastMCP: "this function is a tool, publish it."
  • The type hints (a: float, b: float) -> float — tell the model what type of data goes in and comes out. FastMCP uses them to build the tool's "schema" automatically.
  • The docstring ("""Multiply two numbers.""") — is the text between triple quotes. This is what the agent reads to understand when it's a good idea to use your tool. A good docstring is the difference between a tool the model uses well and one it ignores.
Example prompt

Decorator: an annotation that starts with @ and sits right above a function to "modify" or register it. You don't need to know how it works internally: think of it as a label that says "this is a tool."

Step 4 — Run the server over stdio

At the end of the file we add the startup. mcp.run() sets the server listening. By default it uses stdio (standard input/output), the transport we saw in Module 1: the client and server talk to each other through the same terminal, ideal for running on your machine.

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

The line if __name__ == "__main__": is a standard Python idiom that means "run this only if I run this file directly." Now launch it from the terminal:

bash
python server.py

If it shows no errors, your server is running and waiting for a client!

Step 5 — Connect it and test it

A server on its own does nothing visible: it needs a client to talk to it. The fastest way to test it is to register it in Claude Code, pointing to the command that starts it:

bash
claude mcp add calculator -- python server.py

Then open Claude Code and ask it something like "multiply 6 by 7." The agent will discover your multiply tool, decide to use it, pass it the numbers, and return 42. That back-and-forth is exactly the lifecycle we studied in Module 1, now with your own server.

Example prompt

Tip: there's also the official MCP inspector for testing servers without an LLM. But connecting it to a real client like Claude Code is the most satisfying test.

Key moments in the video

  • 4
    FastMCP setup: installation and the first lines to create the server. It's the equivalent of our Steps 1 and 2; follow along with this file open beside you.
  • 6
    @mcp.tool: how the decorator turns a normal function into a tool the agent can invoke. Pay attention to the docstring and the type hints (our Step 3).

Quick glossary

  • FastMCP: a Python library that implements MCP for you; you write tools, not plumbing.
  • pip: Python's package installer (pip install <package>).
  • Decorator (@mcp.tool): a label above a function that registers it as a tool.
  • Type hints: the type annotations (a: float) that describe inputs and outputs.
  • Docstring: the text between """..."""; what the agent reads to know when to use the tool.
  • stdio: standard input/output transport; the default for mcp.run() to run locally.
  • __main__: a Python pattern to run code only if you run the file directly.

To download

  • 📄 Commented code — Your first MCP server (PDF): the complete server.py, line by line, plus the commands to install, run, and connect it.
  • 🧩 Skill pack — mcp-python-starter: a Claude Code skill that scaffolds a FastMCP server over stdio for you, so you can start your next server in seconds.

Before you move on

If you take away one idea, let it be this: a tool is an ordinary Python function with the decorator @mcp.tool, and its docstring is what the agent reads to decide to use it. In the next lesson we do the same thing, but in Node.js / TypeScript, so you can see that MCP is just as simple in any language.