Tutorials & Guides

Build Your First MCP Server in 20 Minutes

2026-09-04 👁 60 views 8
Build Your First MCP Server in 20 Minutes

The Model Context Protocol lets AI assistants call your own tools. With FastMCP, a working server is fifteen lines of Python — this tutorial walks from concept to a Claude Desktop integration you can use today.

If your AI assistant could search your notes, query your database or drive your internal tools, it would stop being a chatbot. The Model Context Protocol (MCP) is the open standard that makes that connection — and a first server takes minutes, not days.

What MCP Is, in One Paragraph

Introduced in 2024, MCP is an open protocol in which a server exposes capabilities to AI applications over JSON-RPC, through a local stdio connection or remote SSE/HTTP. Three primitives matter: tools (actions the model can call), resources (read-only data it can pull into context) and prompts (reusable interaction templates). The official Python SDK installs with pip install mcp (currently 1.8.x); the FastMCP framework (pip install fastmcp, 2.x) wraps it so that, most of the time, decorating a function is all the work there is. Type annotations are mandatory — they become the tool's schema.

Advertisement

A Server in Fifteen Lines

Save this as server.py — a tiny notebook your assistant can write to and search:

from fastmcp import FastMCP

mcp = FastMCP("Notes")

NOTES: list[str] = []

@mcp.tool()
def add_note(text: str) -> str:
    """Add a note to the shared notebook."""
    NOTES.append(text)
    return f"Added note #{len(NOTES)}"

@mcp.tool()
def search_notes(keyword: str) -> list[str]:
    """Return notes containing the keyword."""
    return [n for n in NOTES if keyword.lower() in n.lower()]

@mcp.resource("notes://recent")
def recent_notes() -> str:
    """The five most recent notes."""
    return "\n".join(NOTES[-5:])

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

That is a complete server: two tools, one resource, running over stdio by default.

Test It, Install It, Ship It

During development, run fastmcp dev server.py — it launches the MCP Inspector, a web interface where you can call your tools interactively and read the logs. To install into Claude Desktop, run fastmcp install server.py; the CLI creates an isolated environment (declare extra packages via FastMCP("Notes", dependencies=["httpx"])), registers the server in claude_desktop_config.json, and asks you to fully restart the app. Choose stdio for local personal tools; choose SSE/HTTP when the server must be shared or remote — the current MCP spec (2026-07-28) defines a stateless, streamable HTTP transport with strict result typing, which is what you would deploy behind TLS on any container platform.