C.W.K.
Stream
Lesson 01 of 05 · published

Minimal MCP Server (Python SDK)

~22 min · python-sdk, fastmcp, minimal, scaffolding

Level 0Curious Reader
0 XP0/48 lessons0/14 achievements
0/100 XP to next level100 XP to go0% complete

The official Python SDK at modelcontextprotocol/python-sdk ships two layers: a low-level mcp.server.lowlevel for full control, and FastMCP for the 80% case. Most people start (and stay) on FastMCP — its decorator-based API converts type annotations into JSON Schema and docstrings into descriptions, which means a working server is about 20 lines of Python.

Install with pip install mcp (or uv add mcp). Define an app, attach tools/resources/prompts via decorators, run it. The SDK handles JSON-RPC framing, capability negotiation, error envelopes, and transport selection. By the time you are done with this lesson you will have a server you can connect to from Claude Desktop and watch the model call.

Code

A complete, runnable MCP server·python
# server.py
from mcp.server.fastmcp import FastMCP

app = FastMCP("hello-server")

@app.tool()
async def get_stock_price(symbol: str) -> str:
    """Get the current stock price for a ticker symbol (toy implementation)."""
    prices = {"AAPL": 198.50, "GOOGL": 178.25, "MSFT": 425.00}
    p = prices.get(symbol.upper())
    if p is None:
        return f"Unknown symbol: {symbol}"
    return f"{symbol.upper()}: ${p:.2f}"

@app.resource("greeting://hello")
def hello() -> str:
    return "Hello from a tiny MCP server."

if __name__ == "__main__":
    app.run()  # speaks stdio by default
Run it standalone for a sanity check·bash
$ python server.py
# Server is now listening on stdio. To exercise it from a client:
$ uvx mcp-cli connect "python server.py" tools/list

External links

Exercise

Build the minimal server above. Run it. Connect to it from any MCP client (Claude Desktop, the SDK's example client, mcp-cli). Call the stock-price tool. Read the greeting resource. The whole loop is short on purpose; doing it once removes most of the mystery.

Progress

Progress is local-only — sign in to sync across devices.
Spotted a bug or have feedback on this page?Report an Issue

Comments 0

🔔 Reply notifications (sign in)
Sign inPlease sign in to comment.

No comments yet — be the first.