← Back to Payloads
Tutorial2026-06-26

Build an MCP Server in 50 Lines of Python and Ship a Tool to Claude in 15 Minutes

You wrote a Python function. You want Claude, Cursor, or Continue to call it. Wrap it in 50 lines with the official MCP SDK and any MCP-aware client can discover and call it. No glue code, no SDK rewrites.
Quick Access
Install command
$ mrt install tutorial
Browse related skills
Build an MCP Server in 50 Lines of Python and Ship a Tool to Claude in 15 Minutes

Build an MCP Server in 50 Lines of Python and Ship a Tool to Claude in 15 Minutes

You wrote a function. It does something useful — searches a Postgres table, hits an internal API, reads your ~/.aws/credentials. Now you want Claude, Cursor, or Continue to call it. The old way was to copy-paste the function into every chat. The 2026 way is to expose it as an MCP server and let any MCP-aware client discover it, describe it, and call it for you.

Hey guys, Mr. Technology here.

The Model Context Protocol is the JSON-RPC standard Anthropic shipped in late 2024 that every serious AI client now speaks. A server is a process that exposes a list of tools with JSON-Schema-typed arguments. The client reads the list, picks the right tool for the user's prompt, and sends back arguments. You write the tool body. The protocol handles discovery, transport, and error framing.

The Setup

bash pip install mcp mkdir my-mcp && cd my-mcp

mcp is the official Python SDK. The only runtime deps are pydantic and anyio. Two files: server.py for the tool, and a config snippet in your AI client.

The Server

```python

server.py

from mcp.server.fastmcp import FastMCP

mcp = FastMCP("demo")

@mcp.tool() def search_docs(query: str, limit: int = 5) -> list[dict]: """Search internal docs by free-text query. Returns matching snippets."""

replace this with your real call

return [ {"title": f"Doc {i}", "snippet": f"Match for '{query}' #{i}"} for i in range(limit) ]

@mcp.tool() def get_weather(city: str) -> dict: """Return current weather for a city. Stub: always returns the same shape.""" return {"city": city, "temp_c": 18, "condition": "cloudy"}

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

Fifty-ish lines including the stub. FastMCP reads the type hints and docstrings, builds the JSON Schema for the arguments, and registers each function as a callable tool. You write Python; the protocol is generated for you.

Wire It Into Claude Desktop

~/Library/Application Support/Claude/claude_desktop_config.json (macOS) or %APPDATA%/Claude/claude_desktop_config.json (Windows):

json { "mcpServers": { "demo": { "command": "python", "args": ["/absolute/path/to/my-mcp/server.py"] } } }

Restart Claude Desktop. The chat composer now shows a small hammer icon. Click it. search_docs and get_weather are listed with their schemas and docstrings. Ask "what is the weather in Berlin?" and Claude calls get_weather directly. Ask "search docs for prompt caching" and it calls search_docs. No system prompt hack, no copy-paste, no function-calling boilerplate.

The same config works in Cursor (~/.cursor/mcp.json) and Continue (~/.continue/config.json under mcpServers). One server, three clients.

Why This Wins

Discovery is free. The client reads your tool list at startup. You add a third tool, restart the client, it appears. No SDK updates, no schema files to keep in sync.

Typed contracts, real errors. Argument validation happens at the JSON-RPC layer before your function runs. Pass limit="five" and the client gets a schema error back instead of a stack trace.

Local-first by default. stdio transport means the server runs as a child process of the client. Your data does not leave the machine. The same code runs in production behind an mcp.run(transport="sse") swap.

When To Skip This

If your tool is one-shot and you only ever call it from one script, a plain Python function is faster. MCP earns its keep the moment two clients need the same tool, or a non-engineer needs to call your function through Claude without learning your repo.

The Take

MCP is the boring plumbing move that turns "I wrote a function" into "Claude, Cursor, and Continue can all call my function with zero glue code." One pip install, one config file, fifty lines of Python, and your tools are first-class citizens in every AI client that speaks the protocol. Spend the fifteen minutes. Stop copy-pasting function bodies into chat.

Mr. Technology


*Python SDK: pip install mcp (>=1.0, Apache 2.0). Transports: stdio for local clients, sse for hosted. Clients that speak MCP today: Claude Desktop, Cursor, Continue.dev, Zed, Cline. Debug with mcp inspector (Python or TypeScript). Tool discovery uses JSON Schema generated from your type hints and docstrings.*

Related Dispatches