|
| 1 | +# Installation |
| 2 | + |
| 3 | +Learn how to install and set up the MCP Python SDK for different use cases. |
| 4 | + |
| 5 | +## Prerequisites |
| 6 | + |
| 7 | +- **Python 3.10 or later** |
| 8 | +- **uv package manager** (recommended) or pip |
| 9 | + |
| 10 | +### Installing uv |
| 11 | + |
| 12 | +If you don't have uv installed: |
| 13 | + |
| 14 | +```bash |
| 15 | +# macOS and Linux |
| 16 | +curl -LsSf https://astral.sh/uv/install.sh | sh |
| 17 | + |
| 18 | +# Windows |
| 19 | +powershell -ExecutionPolicy ByPass -c "irm https://astral.sh/uv/install.ps1 | iex" |
| 20 | + |
| 21 | +# Or with pip |
| 22 | +pip install uv |
| 23 | +``` |
| 24 | + |
| 25 | +## Installation methods |
| 26 | + |
| 27 | +### For new projects (recommended) |
| 28 | + |
| 29 | +Create a new uv-managed project: |
| 30 | + |
| 31 | +```bash |
| 32 | +uv init my-mcp-server |
| 33 | +cd my-mcp-server |
| 34 | +uv add "mcp[cli]" |
| 35 | +``` |
| 36 | + |
| 37 | +This creates a complete project structure with: |
| 38 | +- `pyproject.toml` - Project configuration |
| 39 | +- `src/` directory for your code |
| 40 | +- Virtual environment management |
| 41 | + |
| 42 | +### Add to existing project |
| 43 | + |
| 44 | +If you have an existing project: |
| 45 | + |
| 46 | +```bash |
| 47 | +uv add "mcp[cli]" |
| 48 | +``` |
| 49 | + |
| 50 | +### Using pip |
| 51 | + |
| 52 | +For projects that use pip: |
| 53 | + |
| 54 | +```bash |
| 55 | +pip install "mcp[cli]" |
| 56 | +``` |
| 57 | + |
| 58 | +## Package variants |
| 59 | + |
| 60 | +The MCP SDK offers different installation options: |
| 61 | + |
| 62 | +### Core package |
| 63 | +```bash |
| 64 | +uv add mcp |
| 65 | +``` |
| 66 | + |
| 67 | +Includes: |
| 68 | +- Core MCP protocol implementation |
| 69 | +- FastMCP server framework |
| 70 | +- Client libraries |
| 71 | +- All transport types (stdio, SSE, Streamable HTTP) |
| 72 | + |
| 73 | +### CLI tools |
| 74 | +```bash |
| 75 | +uv add "mcp[cli]" |
| 76 | +``` |
| 77 | + |
| 78 | +Adds CLI utilities for: |
| 79 | +- `mcp dev` - Development server with web inspector |
| 80 | +- `mcp install` - Claude Desktop integration |
| 81 | +- `mcp run` - Direct server execution |
| 82 | + |
| 83 | +### Rich output |
| 84 | +```bash |
| 85 | +uv add "mcp[rich]" |
| 86 | +``` |
| 87 | + |
| 88 | +Adds enhanced terminal output with colors and formatting. |
| 89 | + |
| 90 | +### WebSocket support |
| 91 | +```bash |
| 92 | +uv add "mcp[ws]" |
| 93 | +``` |
| 94 | + |
| 95 | +Adds WebSocket transport capabilities. |
| 96 | + |
| 97 | +### All features |
| 98 | +```bash |
| 99 | +uv add "mcp[cli,rich,ws]" |
| 100 | +``` |
| 101 | + |
| 102 | +## Development setup |
| 103 | + |
| 104 | +For contributing to the MCP SDK or advanced development: |
| 105 | + |
| 106 | +```bash |
| 107 | +git clone https://github.com/modelcontextprotocol/python-sdk |
| 108 | +cd python-sdk |
| 109 | +uv sync --group docs --group dev |
| 110 | +``` |
| 111 | + |
| 112 | +This installs: |
| 113 | +- All dependencies |
| 114 | +- Development tools (ruff, pyright, pytest) |
| 115 | +- Documentation tools (mkdocs, mkdocs-material) |
| 116 | + |
| 117 | +## Verify installation |
| 118 | + |
| 119 | +Test your installation: |
| 120 | + |
| 121 | +```bash |
| 122 | +# Check MCP CLI is available |
| 123 | +uv run mcp --help |
| 124 | + |
| 125 | +# Create and test a simple server |
| 126 | +echo 'from mcp.server.fastmcp import FastMCP |
| 127 | +mcp = FastMCP("Test") |
| 128 | +@mcp.tool() |
| 129 | +def hello() -> str: |
| 130 | + return "Hello from MCP!" |
| 131 | +if __name__ == "__main__": |
| 132 | + mcp.run()' > test_server.py |
| 133 | + |
| 134 | +# Test the server |
| 135 | +uv run mcp dev test_server.py |
| 136 | +``` |
| 137 | + |
| 138 | +If successful, you'll see the MCP Inspector web interface open. |
| 139 | + |
| 140 | +## IDE integration |
| 141 | + |
| 142 | +### VS Code |
| 143 | + |
| 144 | +For the best development experience, install: |
| 145 | + |
| 146 | +- **Python extension** - Python language support |
| 147 | +- **Pylance** - Advanced Python features |
| 148 | +- **Ruff** - Code formatting and linting |
| 149 | + |
| 150 | +### Type checking |
| 151 | + |
| 152 | +The MCP SDK includes comprehensive type hints. Enable strict type checking: |
| 153 | + |
| 154 | +```bash |
| 155 | +# Check types |
| 156 | +uv run pyright |
| 157 | + |
| 158 | +# In VS Code, add to settings.json: |
| 159 | +{ |
| 160 | + "python.analysis.typeCheckingMode": "strict" |
| 161 | +} |
| 162 | +``` |
| 163 | + |
| 164 | +## Troubleshooting |
| 165 | + |
| 166 | +### Common issues |
| 167 | + |
| 168 | +**"mcp command not found"** |
| 169 | +- Ensure uv is in your PATH |
| 170 | +- Try `uv run mcp` instead of just `mcp` |
| 171 | + |
| 172 | +**Import errors** |
| 173 | +- Verify installation: `uv run python -c "import mcp; print(mcp.__version__)"` |
| 174 | +- Check you're in the right directory/virtual environment |
| 175 | + |
| 176 | +**Permission errors on Windows** |
| 177 | +- Run terminal as administrator for global installations |
| 178 | +- Use `--user` flag with pip if needed |
| 179 | + |
| 180 | +**Python version conflicts** |
| 181 | +- Check version: `python --version` |
| 182 | +- Use specific Python: `uv python install 3.11` then `uv python use 3.11` |
| 183 | + |
| 184 | +### Getting help |
| 185 | + |
| 186 | +- **GitHub Issues**: [Report bugs and feature requests](https://github.com/modelcontextprotocol/python-sdk/issues) |
| 187 | +- **Discussions**: [Community support](https://github.com/modelcontextprotocol/python-sdk/discussions) |
| 188 | +- **Documentation**: [Official MCP docs](https://modelcontextprotocol.io) |
| 189 | + |
| 190 | +## Next steps |
| 191 | + |
| 192 | +- **[Build your first server](quickstart.md)** - Follow the quickstart guide |
| 193 | +- **[Learn core concepts](servers.md)** - Understand MCP fundamentals |
| 194 | +- **[Explore examples](https://github.com/modelcontextprotocol/python-sdk/tree/main/examples)** - See real-world implementations |
0 commit comments