Installation

This chapter installs the official Python SDK and MCP Inspector, then checks that the commands run. Treat the python-sdk README and py.sdk.modelcontextprotocol.io as the source of truth for package names and imports.


Requirements

ComponentMinimumUsed for
Python3.10+ (3.11 / 3.12 recommended)Servers and the official SDK
pip or uvCurrent stableInstalling mcp
Node.js18+ for JS reference servers; Inspector docs currently say Node 22.19.0+npx @modelcontextprotocol/inspector, most npx servers
Optional hostCursor / Claude Code / Codex / …Attaching the server to a real chat

Check versions:

python --version
node --version
npm --version

Unix:

python3 --version
node --version
npm --version

Create a virtual environment

PowerShell:

python -m venv .venv
.\.venv\Scripts\Activate.ps1
python -m pip install -U pip

If script execution is blocked, allow it once for your user:

Set-ExecutionPolicy -Scope CurrentUser RemoteSigned

Unix / macOS:

python3 -m venv .venv
source .venv/bin/activate
python -m pip install -U pip

Install the official Python SDK

pip install mcp now installs SDK v2 (the 2026-07-28 line). The cli extra adds mcp dev and mcp run:

pip install "mcp[cli]"

Or with uv:

uv add "mcp[cli]"

Same commands on Unix. SDK only, no CLI: pip install mcp.

Verify the import (v2’s class is MCPServer, not v1’s FastMCP):

python -c "from mcp.server import MCPServer; print('ok', MCPServer)"
python -c 'from mcp.server import MCPServer; print("ok", MCPServer)'

Older snippets that from mcp.server.fastmcp import FastMCP raise ModuleNotFoundError on v2. The decorator style (@mcp.tool() and friends) is unchanged; only the class was renamed. Pin mcp>=1.28,<2 only if you must stay on v1. New projects should use v2. The separate community FastMCP project is not the official package this course uses.


Install / launch Inspector

The Inspector package is @modelcontextprotocol/inspector. You usually do not install it globally:

npx @modelcontextprotocol/inspector
npx @modelcontextprotocol/inspector

The command prints a URL with a one-time session token; open it in a browser. Three entry points:

ModeCommandUse
Web (default)npx @modelcontextprotocol/inspectorFull GUI
CLInpx @modelcontextprotocol/inspector --cli ...Scripts / CI
TUInpx @modelcontextprotocol/inspector --tui ...No browser

With mcp[cli] installed you can also run:

mcp dev .\server.py
mcp dev ./server.py

mcp dev starts Inspector and connects to your file over stdio. npx must be on PATH.


Suggested layout

mcp-demo/
├── .venv/
├── server.py
├── notes/          # used in the practical examples
├── requirements.txt
└── README.md

requirements.txt can be a single line: mcp[cli].


Troubleshooting

python is not a command (Windows)?
Use py -3.12 -m venv .venv, then python after activation.

Inspector will not open / Node is too old?
Upgrade Node using the Inspector docs. You can still write TypeScript servers on Node 18 LTS; the debugger may require a newer runtime.

mcp is not a command?
Confirm pip install "mcp[cli]" and an active venv, or run python -m mcp.

Several Python tutorials on one machine?
Give each course its own venv so LangChain and MCP do not fight over packages.


Next

评论