@imenam/refactoring-mcp
v3.4.1
Published
MCP server to copy or move code blocks between files, with optional directory confinement.
Maintainers
Readme
@imenam/refactoring-mcp
An MCP (Model Context Protocol) server that lets AI agents copy or move blocks of code between files, with optional directory confinement for safety.
Tools
move_or_copy_code
Copies or moves a range of lines from a source file to a destination file.
| Parameter | Type | Required | Description |
|---|---|---|---|
| sourceFile | string | ✅ | Absolute path to the source file |
| startLine | number | ✅ | Start line of the block (1-indexed) |
| endLine | number | ✅ | End line of the block, inclusive (1-indexed) |
| operationType | "copy" \| "cut" | ✅ | copy keeps the source intact, cut removes the lines |
| destinationFile | string | ✅ | Absolute path to the destination file (created automatically if it doesn't exist) |
| destinationLine | number | ❌ | Line at which to insert in the destination (appended at end by default) |
get_file_outline
Returns the list of top-level symbols in a file (functions, classes, interfaces, types, constants, methods) with their start and end line numbers. Useful for identifying the exact coordinates of a code block before moving it.
| Parameter | Type | Required | Description |
|---|---|---|---|
| filePath | string | ✅ | Absolute path to the file to analyse |
compare_code_sections
Compares two code sections from two files (delimited by line numbers) and returns a unified diff in git format. Useful for verifying that a block of code was correctly copied from one file to another. Leading and trailing blank lines in each section are ignored to avoid false positives from positioning differences.
| Parameter | Type | Required | Description |
|---|---|---|---|
| fileA | string | ✅ | Absolute path to the first file |
| startLineA | number | ✅ | Start line of the section in file A (1-indexed) |
| endLineA | number | ✅ | End line of the section in file A, inclusive (1-indexed) |
| fileB | string | ✅ | Absolute path to the second file |
| startLineB | number | ✅ | Start line of the section in file B (1-indexed) |
| endLineB | number | ✅ | End line of the section in file B, inclusive (1-indexed) |
Returns "Les sections sont identiques." when no differences are found, or a unified diff with real file line numbers otherwise.
Configuration
All file paths must be absolute. Relative paths are rejected.
To restrict operations to a specific directory, set the REFACTORING_ALLOWED_DIR environment variable. Any attempt to access a file outside that directory will be blocked.
# .env
REFACTORING_ALLOWED_DIR=C:/Users/you/my-projectInstallation
npm install -g @imenam/refactoring-mcpOr use it directly with npx:
{
"refactoring-mcp": {
"command": "npx",
"args": ["-y", "@imenam/refactoring-mcp"]
}
}Or point to a local build:
{
"refactoring-mcp": {
"command": "node",
"args": ["/absolute/path/to/refactoring-mcp/dist/index.js"],
"env": {
"REFACTORING_ALLOWED_DIR": "/absolute/path/to/your/project"
}
}
}License
MIT
