Skip to main content

MCP server providing Python code analysis using Rope and Pyright

Project description

Python LSP MCP Server

Python MCP server providing code analysis features using Rope and Pyright.

Features

Tool Description Backend
hover Get documentation at position Rope/Pyright
definition Go to symbol definition Rope/Pyright
references Find all references Rope/Pyright
completions Code completion suggestions Rope/Pyright
symbols Extract document symbols Rope/Pyright
rename Rename refactoring Rope
move Move function/class to another module Rope
change_signature Change function parameters Rope
function_signature Get function signature info Rope
diagnostics Type checking errors Pyright
signature_help Function signatures Pyright
update_document Incremental document updates Pyright
search Regex search in files ripgrep
set_backend Switch backend at runtime -
status Server status info -

Installation

From PyPI (Recommended)

# Using uvx (no install needed)
uvx python-lsp-mcp@latest

# Using pipx
pipx install python-lsp-mcp

# Using pip
pip install python-lsp-mcp

From Source

cd python
uv sync
uv run python-lsp-mcp

Usage

Run the server

# With uvx (recommended)
uvx python-lsp-mcp@latest

# With pip install
python-lsp-mcp

# From source
uv run python-lsp-mcp

Configure in Claude Code

Add to your .mcp.json or MCP settings:

{
  "mcpServers": {
    "python-lsp-mcp": {
      "command": "uvx",
      "args": ["python-lsp-mcp@latest"]
    }
  }
}

Or if installed from source:

{
  "mcpServers": {
    "python-lsp-mcp": {
      "command": "uv",
      "args": ["run", "--directory", "/path/to/PyLspMcp/python", "python-lsp-mcp"]
    }
  }
}

MCP Inspector

uvx mcp dev python-lsp-mcp

Configuration

Backend Selection

The server supports two backends for shared tools (hover, definition, references, completions, symbols):

Backend Strengths Use Case
rope (default) Fast, low latency, good refactoring Quick operations, CI/CD
pyright Accurate types, cross-file analysis Type-heavy projects

Runtime Switching

Use the set_backend tool to switch backends at runtime:

# Switch all shared tools to pyright
set_backend(backend="pyright")

# Switch only hover to rope
set_backend(backend="rope", tool="hover")

# Check current configuration
status()

Environment Variables

Configure backends at startup via environment variables (supports both prefixes):

Variable Description Default
PYTHON_LSP_MCP_BACKEND Default backend (rope or pyright) rope
PYTHON_LSP_MCP_HOVER_BACKEND Backend for hover inherited
PYTHON_LSP_MCP_DEFINITION_BACKEND Backend for definition inherited
PYTHON_LSP_MCP_REFERENCES_BACKEND Backend for references inherited
PYTHON_LSP_MCP_COMPLETIONS_BACKEND Backend for completions inherited
PYTHON_LSP_MCP_SYMBOLS_BACKEND Backend for symbols inherited
PYTHON_LSP_MCP_NO_CACHE Disable Rope caching (1 or true) false

Note: ROPE_MCP_* prefix is also supported for backward compatibility.

Rope Caching

By default, Rope creates a .ropeproject folder in each analyzed project to cache analysis results. This significantly improves performance for medium to large projects.

  • Cache location: .ropeproject/ in each project root (project-isolated)
  • Cache contents: Module info, object database, refactoring history
  • Disable caching: Set PYTHON_LSP_MCP_NO_CACHE=1

You may want to add .ropeproject/ to your .gitignore.

Example:

# Use pyright for all shared tools
PYTHON_LSP_MCP_BACKEND=pyright uvx python-lsp-mcp@latest

# Use pyright for hover only
PYTHON_LSP_MCP_HOVER_BACKEND=pyright uvx python-lsp-mcp@latest

Development

Run tests

uv run pytest tests/ -v

Run benchmarks

uv run pytest tests/test_benchmark.py -v -s

Architecture

┌─────────────────┐     stdio      ┌─────────────────────┐
│  Claude / AI    │ ◄────────────► │     python-lsp-mcp        │
│                 │      MCP       │                     │
└─────────────────┘                └─────────┬───────────┘
                                             │
                           ┌─────────────────┼─────────────────┐
                           │                 │                 │
                           ▼                 ▼                 ▼
                    ┌───────────┐     ┌───────────┐     ┌───────────┐
                    │   Rope    │     │  Pyright  │     │ Pyright   │
                    │  Library  │     │   CLI     │     │   LSP     │
                    └───────────┘     └───────────┘     └───────────┘

Project Structure

python/
├── pyproject.toml
├── src/rope_mcp/
│   ├── server.py           # MCP server entry point
│   ├── rope_client.py      # Rope library wrapper
│   ├── pyright_client.py   # Pyright CLI wrapper
│   ├── config.py           # Backend configuration
│   ├── lsp/                # LSP client for Pyright
│   │   ├── client.py
│   │   └── types.py
│   └── tools/              # Tool implementations
│       ├── hover.py
│       ├── definition.py
│       ├── references.py
│       ├── completions.py
│       ├── symbols.py
│       ├── rename.py
│       └── diagnostics.py
└── tests/
    ├── test_tools.py
    └── test_benchmark.py

Performance

Rope is significantly faster than Pyright LSP for basic operations:

Tool Rope (ms) Pyright (ms) Speedup
hover 0.16 0.79 4.9x
definition 0.12 0.40 3.3x
completions 0.36 1.52 4.2x
symbols 0.24 0.44 1.8x

See docs/BENCHMARKS.md for detailed benchmarks.

License

MIT

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

python_lsp_mcp-0.3.1.tar.gz (88.9 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

python_lsp_mcp-0.3.1-py3-none-any.whl (37.3 kB view details)

Uploaded Python 3

File details

Details for the file python_lsp_mcp-0.3.1.tar.gz.

File metadata

  • Download URL: python_lsp_mcp-0.3.1.tar.gz
  • Upload date:
  • Size: 88.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.8.2

File hashes

Hashes for python_lsp_mcp-0.3.1.tar.gz
Algorithm Hash digest
SHA256 65d83b8e7c471253da6953b35f443feffded255421501f94c8397d4b8c2c5a46
MD5 d769b3b143ee20cc88c5ba0ed283b562
BLAKE2b-256 8afeb3fa44c7eb78d5d4effb884a385a5b1bdee8060157e18198eb3a7c3b70a6

See more details on using hashes here.

File details

Details for the file python_lsp_mcp-0.3.1-py3-none-any.whl.

File metadata

File hashes

Hashes for python_lsp_mcp-0.3.1-py3-none-any.whl
Algorithm Hash digest
SHA256 adf4c80513980a8df4ea7df4fe31fb4bf529ac2d2c79e207eb6983262efa92fd
MD5 710c9bc6d13afc0da99369e3f74ebfb3
BLAKE2b-256 2c29abf50bf84296d18887353dcddf3f930e00e3c1b4eb97b2153d191a9aa3e1

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page