Set Up the MCP Python SDK v2

Start new projects on the current v2 SDK unless you have a specific legacy constraint.

Create a project

uv init my-mcp-server
cd my-mcp-server
uv add "mcp[cli]"

With pip, create and activate a virtual environment first, then install mcp[cli].

Recommended layout

my-mcp-server/
  pyproject.toml
  .env.example
  src/
    app.py
    tools/
    resources/
    services/
  tests/

Useful commands

Pin important dependencies

Production projects should lock dependencies and review MCP SDK migration notes before major upgrades. SDK package versions and protocol versions are separate concepts.

Do not commit secrets. Commit a .env.example with variable names, not real credentials.