Python MCP SDK

Welcome! I'm Param, and in this course we are going to build an MCP server that reviews GitHub pull requests from inside Claude Desktop or Cursor. You will fetch diffs, run structured LLM review, and post inline comments back. By the end, your IDE can review any PR with a single tool call.

The server exposes three tools: fetch_pr_diff, review_pr, and post_review_comments. Any MCP client can call them. A FastAPI inspector sits on the same business logic so you can debug without an MCP client in the loop.

terminal
bash
# Clone the workshop repository
git clone https://github.com/learnwithparam/mcp-pr-review-server.git
cd mcp-pr-review-server

# One command to set up everything
make dev

This clones the repo, creates a virtual environment with uv, installs the MCP SDK and PyGithub, and starts the FastAPI inspector so you can verify the setup.

mcp_server.py
python
from mcp.server import Server
from mcp.server.stdio import stdio_server
from mcp.types import TextContent, Tool

server: Server = Server("mcp-pr-review-server")


@server.list_tools()
async def list_tools() -> list[Tool]:
    return [
        Tool(
            name="fetch_pr_diff",
            description="Fetch a GitHub pull request's unified diff and changed files.",
            inputSchema={
                "type": "object",
                "properties": {
                    "owner": {"type": "string"},
                    "repo": {"type": "string"},
                    "pr_number": {"type": "integer"},
                },
                "required": ["owner", "repo", "pr_number"],
            },
        ),
    ]

The MCP SDK exposes a Server object that you decorate with tool definitions. Each Tool carries a name, a description, and a JSON Schema describing its input. The client uses the schema to build type-safe calls.

MCP server anatomy

How an MCP client discovers and calls tools on your server.

The SDK handles the JSON-RPC framing, initialization handshake, capability negotiation, and error format for you. If you write your own, you end up reimplementing the same state machine that every MCP client expects. The SDK lets you focus on tools and resources instead of wire format.

Quiz: Quiz

Loading practice…