MCP server for Python refactoring via Rope library
Project description
rope-mcp-server
A Model Context Protocol (MCP) server that provides Python refactoring capabilities powered by the Rope library. Enables AI agents like Claude to perform safe, project-wide refactoring operations.
Features
- Move Symbol - Move classes and functions between files with automatic import updates
- Move Module - Move entire modules or packages to different folders
- Move and Rename Module - Move module to folder and rename (e.g.,
foo_extra.py→foo/extra.py) - Convert Module to Init - Transform
foo.pyintofoo/__init__.py(no import changes!) - Convert Module to Package - Transform
foo.pyintofoo/foo.pywith import updates - Rename Symbol - Rename variables, functions, classes across entire projects
- Extract Method - Extract code blocks into new methods
- Inline Variable - Inline variables at all usage sites
- List Symbols - Discover top-level symbols in Python files
All operations are project-aware and automatically update imports and references throughout your codebase.
Installation
Quick Start with Claude Code (recommended)
# Global installation (all projects)
claude mcp add rope-refactor uvx rope-mcp-server -s user
# Or for current project only
claude mcp add rope-refactor uvx rope-mcp-server -s local
From PyPI
pip install rope-mcp-server
Usage with Claude Code
claude mcp add rope-refactor uvx rope-mcp-server -s user
claude mcp list # verify
That's it.
Available Tools
list_symbols
List all top-level symbols (classes, functions, variables) in a Python file.
project_path: /path/to/your/project
file_path: src/models.py
move_symbol
Move a class or function to another file. Automatically updates all imports.
project_path: /path/to/your/project
source_file: src/models.py
symbol_name: UserModel
dest_file: src/users/models.py
move_module
Move a module or package to another folder. Automatically updates all imports.
project_path: /path/to/your/project
module_path: src/utils.py
dest_folder: src/lib
convert_module_to_init (recommended)
Convert a module file into a package by moving it to __init__.py. No import changes needed!
This is the recommended way to convert a module to a package. After conversion, you can use move_module to move related files (like foo_mixins.py) into the new package.
project_path: /path/to/your/project
module_path: app/views/customer_order.py
Before:
app/views/customer_order.py
app/views/customer_order_mixins.py
After running convert_module_to_init:
app/views/customer_order/__init__.py (was customer_order.py)
app/views/customer_order_mixins.py (move this next with move_module)
Import from app.views.customer_order import X stays unchanged!
move_and_rename_module
Move a module to a folder and optionally rename it. Perfect for moving related files (like _mixins.py, _extra.py) into a package created with convert_module_to_init.
Auto-detection: If the module name starts with the destination folder name + underscore, it strips that prefix automatically.
Rope bug workaround: This tool includes a workaround for a Rope bug that crashes when a file has imports from BOTH the destination package AND the module being moved. Such files are temporarily hidden during the move, then their imports are fixed manually.
project_path: /path/to/your/project
module_path: app/views/customer_order_mixins.py
dest_folder: app/views/customer_order
new_name: mixins # Optional - auto-detected from prefix
Before:
app/views/customer_order/__init__.py
app/views/customer_order_mixins.py
Import: from app.views.customer_order_mixins import MyMixin
After:
app/views/customer_order/__init__.py
app/views/customer_order/mixins.py
Import: from app.views.customer_order.mixins import MyMixin
convert_module_to_package
Convert a module file into a package with the same name. Transforms foo.py into foo/foo.py while updating all imports project-wide.
Use this when you want the original module content in a submodule, not in __init__.py.
project_path: /path/to/your/project
module_path: app/views/service_contractor.py
Before:
app/views/service_contractor.py
Import: from app.views.service_contractor import MyClass
After:
app/views/service_contractor/
├── __init__.py
└── service_contractor.py
Import: from app.views.service_contractor.service_contractor import MyClass
rename_symbol
Rename a symbol across the entire project.
project_path: /path/to/your/project
file_path: src/utils.py
symbol_name: old_function_name
new_name: new_function_name
extract_method
Extract a code region into a new method.
project_path: /path/to/your/project
file_path: src/service.py
start_line: 15
start_col: 4
end_line: 20
end_col: 30
new_name: extracted_helper
inline_variable
Inline a variable at all usage sites.
project_path: /path/to/your/project
file_path: src/handler.py
variable_name: temp_result
line: 42
close_rope_project
Close a Rope project to free memory. Call when done with refactoring.
project_path: /path/to/your/project
Development
# Install dependencies
uv sync
# Run tests
uv run pytest tests/ -v
# Run server locally
uv run python -m rope_mcp_server.server
How it works
This server wraps the Rope refactoring library and exposes its capabilities via the Model Context Protocol. When Claude (or any MCP-compatible agent) needs to refactor Python code, it can use these tools to perform safe, AST-aware transformations that preserve code correctness.
Key implementation details:
- Project caching - Rope projects are cached to avoid re-parsing on every operation
- AST-based offset calculation - Symbol locations are computed via Python's AST module for accuracy
- Automatic import handling - Rope handles all import updates when moving/renaming symbols
Limitations
- Only supports Python code (Rope limitation)
- Moving methods between classes requires the target class to exist
- Large projects may have slower initial indexing
- Rope bug workaround: Files with imports from both the destination package and the module being moved are handled specially (hidden during move, then imports fixed manually) - see
move_and_rename_module
License
MIT
Contributing
Contributions welcome! Please open an issue first to discuss what you would like to change.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file rope_mcp_server-0.1.2.tar.gz.
File metadata
- Download URL: rope_mcp_server-0.1.2.tar.gz
- Upload date:
- Size: 76.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
c841820bf2bdad7fe11470006478164f7999f9b0308dd6a93929904f308435a0
|
|
| MD5 |
60ce988b5cdb164020f3d289f1366e71
|
|
| BLAKE2b-256 |
da3fdc44cd894c09adc03b435a02b4034d3632c5d50c0fa99d5f1ee320e62d19
|
Provenance
The following attestation bundles were made for rope_mcp_server-0.1.2.tar.gz:
Publisher:
publish.yml on krystofbe/rope-mcp-server
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
rope_mcp_server-0.1.2.tar.gz -
Subject digest:
c841820bf2bdad7fe11470006478164f7999f9b0308dd6a93929904f308435a0 - Sigstore transparency entry: 836270342
- Sigstore integration time:
-
Permalink:
krystofbe/rope-mcp-server@f38be134e27caca322f7898cf0b9f01684a189b1 -
Branch / Tag:
refs/tags/v0.1.2 - Owner: https://github.com/krystofbe
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@f38be134e27caca322f7898cf0b9f01684a189b1 -
Trigger Event:
push
-
Statement type:
File details
Details for the file rope_mcp_server-0.1.2-py3-none-any.whl.
File metadata
- Download URL: rope_mcp_server-0.1.2-py3-none-any.whl
- Upload date:
- Size: 12.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
694b6919c609f501d5626231688be6146a07ce3525cb34164643aabc0e151d0e
|
|
| MD5 |
c78577bb9391471c1d641012f5127c89
|
|
| BLAKE2b-256 |
f1191a8f15740abcb2f138747e25c8e98bde6422b4a090336281eef713f0a2fa
|
Provenance
The following attestation bundles were made for rope_mcp_server-0.1.2-py3-none-any.whl:
Publisher:
publish.yml on krystofbe/rope-mcp-server
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
rope_mcp_server-0.1.2-py3-none-any.whl -
Subject digest:
694b6919c609f501d5626231688be6146a07ce3525cb34164643aabc0e151d0e - Sigstore transparency entry: 836270357
- Sigstore integration time:
-
Permalink:
krystofbe/rope-mcp-server@f38be134e27caca322f7898cf0b9f01684a189b1 -
Branch / Tag:
refs/tags/v0.1.2 - Owner: https://github.com/krystofbe
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@f38be134e27caca322f7898cf0b9f01684a189b1 -
Trigger Event:
push
-
Statement type: