loading…
Search for a command to run...
loading…
Provides Python refactoring capabilities via the Rope library, enabling AI agents to perform safe, project-wide code transformations such as renaming symbols, m
Provides Python refactoring capabilities via the Rope library, enabling AI agents to perform safe, project-wide code transformations such as renaming symbols, moving modules, and extracting methods.
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.
foo_extra.py → foo/extra.py)foo.py into foo/__init__.py (no import changes!)foo.py into foo/foo.py with import updatesAll operations are project-aware and automatically update imports and references throughout your codebase.
# 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
pip install rope-mcp-server
claude mcp add rope-refactor uvx rope-mcp-server -s user
claude mcp list # verify
That's it.
list_symbolsList all top-level symbols (classes, functions, variables) in a Python file.
project_path: /path/to/your/project
file_path: src/models.py
move_symbolMove 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_moduleMove 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_moduleMove 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_packageConvert 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_symbolRename 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_methodExtract 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_variableInline 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_projectClose a Rope project to free memory. Call when done with refactoring.
project_path: /path/to/your/project
# Install dependencies
uv sync
# Run tests
uv run pytest tests/ -v
# Run server locally
uv run python -m rope_mcp_server.server
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:
move_and_rename_moduleMIT
Contributions welcome! Please open an issue first to discuss what you would like to change.
Выполни в терминале:
claude mcp add rope-mcp-server -- npx Не уверен что выбрать?
Найди свой стек за 60 секунд
Автор?
Embed-бейдж для README
Похожее
Все в категории development