code-copy-mcp
Click on "Install Server".
Wait a few minutes for the server to deploy. Once ready, it will show a "Started" state.
In the chat, type
@followed by the MCP server name and your instructions, e.g., "@code-copy-mcpcopy lines 10-20 from source.py to target.py at line 5"
That's it! The server will respond to your query, and you can continue using it as needed.
Here is a step-by-step guide with screenshots.
Code Copy MCP Server
A Model Context Protocol (MCP) server that enables code copy-paste operations between files with security controls and validation.
Table of Contents
Related MCP server: Snippet Saver
Features
Line-by-line code copying: Extract specific line ranges from source files
Precise pasting: Insert code at exact line positions in target files
Entire file operations: Copy complete file contents
Search and replace: Find and replace text patterns with backup support
File information: Get metadata and statistics about files
Security controls: Restrict operations to allowed directories
Backup creation: Automatic backups before file modifications
Tools
copy_code
Copy code lines from a source file with optional line numbers.
copy_code(
source_file: str,
start_line: int,
end_line: Optional[int] = None,
include_line_numbers: bool = False
) -> strpaste_code
Paste code at a specific line number in a target file.
paste_code(
target_file: str,
line_number: int,
code: str,
create_backup: bool = True
) -> strcopy_entire_file
Copy the complete content of a source file.
copy_entire_file(
source_file: str,
include_line_numbers: bool = False
) -> strsearch_and_replace
Search and replace text patterns in files.
search_and_replace(
target_file: str,
search_pattern: str,
replacement: str,
case_sensitive: bool = True,
replace_all: bool = True,
create_backup: bool = True
) -> strget_file_info
Get detailed information about a file.
get_file_info(file_path: str) -> strInstallation
Prerequisites
Python 3.11 or higher
UV package manager
Setup
Clone or create the project:
cd /Users/map/Documents/Repos/code-copy-mcpInstall dependencies:
uv installConfigure allowed directories (optional):
cp .env.example .env
# Edit .env to set your ALLOWED_DIRECTORIESUsage
Running the Server
uv run python mcp_server.pyDevelopment Mode
# Activate virtual environment first
source .venv/bin/activate # On Windows: .venv\Scripts\activate
# Run server
python mcp_server.pyConfiguration
Create a .env file in the project root:
# Comma-separated list of allowed directories
ALLOWED_DIRECTORIES=/Users/yourname,/Users/yourname/Documents,/Users/yourname/ProjectsIf not specified, defaults to:
User's home directory
Documents folder
Desktop folder
Projects folder (if exists)
Security Features
Path validation prevents directory traversal attacks
File permission checks ensure read/write access
Automatic backup creation before modifications
Restricted operation to configured directories only
Example Workflow
Copy code lines from a source file:
copy_code("/path/to/source.py", start_line=10, end_line=20)Paste the code into target file:
paste_code("/path/to/target.py", line_number=5, code=" copied_code_content ")Get file information:
get_file_info("/path/to/target.py")
Installation & Configuration
Prerequisites
Python 3.11 or higher
UV package manager (recommended) or pip
One of the supported MCP clients
Quick Setup
Clone the repository:
git clone https://github.com/mhattingpete/code-copy-mcp.git cd code-copy-mcpInstall dependencies:
uv sync # Or without UV: pip install -e .Configure allowed directories (optional):
cp .env.example .env # Edit .env to set your ALLOWED_DIRECTORIES
MCP Client Integration
1. Claude Desktop
Add to your Claude Desktop configuration file:
macOS: ~/Library/Application Support/Claude/claude_desktop_config.json
Windows: %APPDATA%\Claude\claude_desktop_config.json
{
"mcpServers": {
"code-copy": {
"command": "/full/path/to/uv",
"args": ["--directory", "/full/path/to/code-copy-mcp", "run", "python", "mcp_server.py"],
"env": {
"ALLOWED_DIRECTORIES": "/Users/yourname,/Users/yourname/Documents,/Users/yourname/Projects"
}
}
}
}2. Cursor (AI Code Editor)
Open Cursor settings (
Cmd/Ctrl + ,)Navigate to
Extensions→MCP ServersAdd new server:
Name: Code Copy MCP Command: full/path/to/uv Arguments: --directory /full/path/to/code-copy-mcp run python mcp_server.py Environment Variables: ALLOWED_DIRECTORIES=/Users/yourname,/Users/yourname/Documents,/Users/yourname/Projects
3. Claude Code
Install the Claude Code
Add server configuration:
claude mcp add-json code-copy '{"type":"stdio","command":"full/path/to/uv","args":["--directory", "/full/path/to/code-copy-mcp", "run", "python", "mcp_server.py"],"env": {"ALLOWED_DIRECTORIES": "/Users/yourname,/Users/yourname/Documents,/Users/yourname/Projects"}}'
Configuration
Environment Variables
Create a .env file in the project root:
# Comma-separated list of directories where file operations are allowed
# Examples for different operating systems:
# macOS/Linux:
ALLOWED_DIRECTORIES=/Users/yourname,/Users/yourname/Documents,/Users/yourname/Projects
# Windows:
ALLOWED_DIRECTORIES=C:\Users\YourName,C:\Users\YourName\Documents,C:\Users\YourName\Projects
# If not specified, defaults to:
# - User's home directory
# - Documents folder
# - Desktop folder
# - Projects folder (if exists)Security Configuration
The server only allows operations within the specified directories for security reasons. Make sure to include all directories where you want to perform code copy-paste operations.
Troubleshooting
Common Issues:
"Module not found" errors:
# Ensure dependencies are installed uv install # Or with pip: pip install -e .Permission denied errors:
Check that the allowed directories are correctly configured
Ensure the directories exist and are accessible
MCP Server not appearing:
Verify the command path is correct
Check the client's logs for error messages
Restart the MCP client after configuration changes
Usage Examples
Once configured, you can use the tools within your MCP client:
Example 1: Copy function from one file to another
User: Copy the function calculate_total from utils.py and paste it into main.py at line 50The assistant will:
Use
get_file_infoto examine the filesUse
copy_codewith appropriate line numbersUse
paste_codeat the specified location
Example 2: Replace code with backup
User: Replace all occurrences of "old_method" with "new_method" in all Python files and create backupsThe assistant will:
Use
search_and_replaceon each fileVerify changes with
get_file_infoReport the modifications made
Example 3: Copy entire file
User: Make a copy of template.py as new_template.pyThe assistant will:
Use
copy_entire_fileto get the contentUse
paste_codeto create the new file
Project Structure
code-copy-mcp/
├── mcp_server.py # Main MCP server
├── tools/
│ ├── __init__.py # Package init
│ ├── validation.py # Security validation
│ └── copy_tools.py # Copy-paste tools
├── .env.example # Configuration template
├── pyproject.toml # UV project configuration
└── README.md # This fileDependencies
fastmcp: MCP server framework
pydantic: Data validation
loguru: Structured logging
python-dotenv: Environment file support
Logging
Logs are written to ~/.code-copy-mcp/mcp_server.log with:
Rotation at 1MB
7-day retention
DEBUG level logging for troubleshooting
Available Tools
5 toolscopy_codeA
Copy code lines from source file.
Args: source_file: Path to source file start_line: Starting line number (1-based) end_line: Ending line number (1-based), defaults to start_line include_line_numbers: Whether to include line numbers in output
Returns: Copied code content as string
| Name | Required | Description | Default |
|---|---|---|---|
| end_line | No | ||
| start_line | Yes | ||
| source_file | Yes | ||
| include_line_numbers | No |
Output Schema
| Name | Required | Description |
|---|---|---|
| result | Yes |
TDQS
Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?
With no annotations, the description must disclose behavior. It mentions the 1-based line numbering, default for end_line, and include_line_numbers option, and implies a read-only copy via the verb 'copy.' However, it does not explicitly state side effects (e.g., no modification to source), behavior on out-of-bounds lines, or error handling.
Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.
Is the description appropriately sized, front-loaded, and free of redundancy?
The description is concise and well-structured with a purpose sentence followed by Args and Returns sections. Every sentence provides useful information, with no unnecessary filler.
Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.
Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?
The description covers the operation, parameters, and return type, and an output schema exists. It is adequate for a simple read-only tool, though it misses edge-case details and doesn't relate to sibling tools. Overall, it is sufficiently complete for most use cases.
Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.
Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?
The schema has no property descriptions (0% coverage), but the tool description compensates fully by explaining each parameter: source_file path, start_line 1-based, end_line defaults to start_line, and include_line_numbers as a flag. This adds meaningful semantics beyond the schema.
Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.
Does the description clearly state what the tool does and how it differs from similar tools?
The description explicitly states 'Copy code lines from source file,' which clearly identifies the action (copy) and resource (source file). The Args section with start_line and end_line clarifies that it copies a specific line range, distinguishing it from sibling copy_entire_file.
Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.
Does the description explain when to use this tool, when not to, or what alternatives exist?
The description provides no when-to-use guidance, no prerequisites, and no references to alternative tools like copy_entire_file. It only describes the function, leaving the agent to infer when this tool is appropriate.
Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.
copy_entire_fileA
Copy entire content of source file.
Args: source_file: Path to source file include_line_numbers: Whether to include line numbers
Returns: Full file content as string
| Name | Required | Description | Default |
|---|---|---|---|
| source_file | Yes | ||
| include_line_numbers | No |
Output Schema
| Name | Required | Description |
|---|---|---|
| result | Yes |
TDQS
Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?
With no annotations, the description carries the full burden. It discloses that it returns the full file content as a string, which implies a read-only operation, but does not mention potential issues like memory usage, error handling, or line number formatting. Basic transparency, but lacks deeper context.
Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.
Is the description appropriately sized, front-loaded, and free of redundancy?
The description is minimal and well-organized with a one-line summary, an Args section, and a Returns section. Every sentence adds value and there is no fluff or repetition.
Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.
Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?
For a simple tool with only two parameters and an output schema, the description is largely complete. It covers purpose, parameters, and return value, and is likely sufficient for an agent to invoke it correctly. However, it lacks explicit usage guidance, which is a minor gap.
Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.
Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?
Schema description coverage is 0%, so the description must compensate. It does so by clearly explaining both parameters: 'Path to source file' and 'Whether to include line numbers.' This adds meaning beyond the bare schema, though it could include more details like path format or line number style.
Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.
Does the description clearly state what the tool does and how it differs from similar tools?
The description clearly states the tool copies the entire content of a source file, using a specific verb and resource. It distinguishes itself from siblings like copy_code (which likely copies to clipboard) and get_file_info (metadata) by focusing on full content retrieval.
Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.
Does the description explain when to use this tool, when not to, or what alternatives exist?
The description implies usage by saying 'copy entire content,' but does not explicitly state when to use this tool over alternatives like copy_code or search_and_replace. No exclusions or when-not-to-use guidance is provided.
Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.
get_file_infoC
Get basic information about a file.
Args: file_path: Path to file
Returns: File information as string
| Name | Required | Description | Default |
|---|---|---|---|
| file_path | Yes |
Output Schema
| Name | Required | Description |
|---|---|---|
| result | Yes |
TDQS
Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?
No annotations are provided, so the description must disclose behavior. It only states that it returns a string, but it does not mention error handling, whether the file must exist, permissions, or any side effects. This is insufficient for a no-annotation tool.
Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.
Is the description appropriately sized, front-loaded, and free of redundancy?
The description is concise and well-structured with Args/Returns sections. It avoids unnecessary words, though it sacrifices useful detail for brevity.
Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.
Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?
Despite having an output schema, the description lacks essential context about path conventions, error behaviors, and what 'basic information' entails. It is minimal for a tool with no annotations and a single parameter.
Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.
Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?
Schema coverage is 0%, and the description's 'Path to file' adds little beyond the parameter name. It does not specify absolute/relative path, accepted formats, or any constraints.
Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.
Does the description clearly state what the tool does and how it differs from similar tools?
The description clearly states the tool retrieves basic file information, using a specific verb ('Get') and resource ('file'). It is distinct from sibling tools like copy_entire_file or search_and_replace, which perform different operations. However, it does not specify what 'basic information' includes, which limits precision.
Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.
Does the description explain when to use this tool, when not to, or what alternatives exist?
The description offers no guidance on when to use this tool versus alternatives, nor any prerequisites or caveats. It simply states what it does without context on when it is appropriate.
Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.
paste_codeA
Paste code at specific line in target file.
Args: target_file: Path to target file line_number: Line number to paste at (1-based, inserts before this line) code: Code content to paste create_backup: Whether to create backup file before modification
Returns: Success message with details
| Name | Required | Description | Default |
|---|---|---|---|
| code | Yes | ||
| line_number | Yes | ||
| target_file | Yes | ||
| create_backup | No |
Output Schema
| Name | Required | Description |
|---|---|---|
| result | Yes |
TDQS
Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?
With no annotations, the description carries the burden of behavioral disclosure. It does add useful behavior context, such as 'inserts before this line' and the backup option. However, it does not disclose edge-case behavior (e.g., line number out of range, file not existing), error handling, or reversibility, leaving notable gaps.
Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.
Is the description appropriately sized, front-loaded, and free of redundancy?
The description is front-loaded with the main purpose, followed by a structured Args list and a Returns note. Every sentence serves a purpose, with no fluff. It is concise yet sufficiently detailed for a tool of this size.
Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.
Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?
Given the tool's moderate complexity (4 params, no annotations, output schema presence mentioned but not detailed), the description is somewhat complete but has gaps. It explains parameters and return type, but lacks usage guidelines, edge cases, and side-effect details beyond backup. It suffices for a basic insertion tool but could be more thorough.
Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.
Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?
Schema description coverage is 0%, so the description must compensate. It defines each parameter with meaningful explanations (e.g., line_number is '1-based, inserts before this line'), which adds value beyond the bare schema types. It does not fully specify edge cases, but it covers the essentials.
Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.
Does the description clearly state what the tool does and how it differs from similar tools?
The description states a specific verb ('Paste') and resource ('code at specific line in target file'), which clearly distinguishes it from sibling tools like copy_entire_file, search_and_replace, and copy_code. The operation is unambiguous.
Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.
Does the description explain when to use this tool, when not to, or what alternatives exist?
The description does not provide any explicit guidance on when to use this tool versus alternatives (e.g., search_and_replace for replacing existing text, copy_entire_file for duplicating whole files). The usage is implied by the name and args, but there are no stated exclusions or preferred scenarios.
Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.
search_and_replaceA
Search and replace text in target file.
Args: target_file: Path to target file search_pattern: Text to search for replacement: Replacement text case_sensitive: Whether search is case sensitive replace_all: Whether to replace all occurrences or just first create_backup: Whether to create backup file
Returns: Success message with replacement count
| Name | Required | Description | Default |
|---|---|---|---|
| replace_all | No | ||
| replacement | Yes | ||
| target_file | Yes | ||
| create_backup | No | ||
| case_sensitive | No | ||
| search_pattern | Yes |
Output Schema
| Name | Required | Description |
|---|---|---|
| result | Yes |
TDQS
Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?
No annotations are provided, so the description must cover behavioral traits. It mentions the 'create_backup' parameter, hinting at a safety feature, but it does not disclose that the operation modifies the file, whether it is reversible, what happens if the pattern is not found, or any permission requirements. For a mutating tool, this is a significant gap.
Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.
Is the description appropriately sized, front-loaded, and free of redundancy?
The description is front-loaded with the main purpose, followed by a structured list of arguments and return value. It is succinct and each line serves a purpose, though the list format is slightly verbose for its content.
Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.
Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?
The tool has 6 parameters, no annotations, and no output schema provided (though indicated as present). The description covers the main purpose, all parameters, and the return message, but lacks usage guidelines, edge-case handling, and deeper behavioral context. It is adequate but not fully comprehensive given the tool's complexity.
Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.
Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?
Schema coverage is 0%, but the description compensates by explaining all six parameters in the Args section, e.g., 'search_pattern: Text to search for' and 'case_sensitive: Whether search is case sensitive'. This adds clear meaning beyond the bare schema, though some descriptions are minimal.
Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.
Does the description clearly state what the tool does and how it differs from similar tools?
The description clearly states the function: 'Search and replace text in target file.' This specifies a verb and resource, distinguishing it from sibling tools like copy_entire_file or paste_code, which involve different operations.
Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.
Does the description explain when to use this tool, when not to, or what alternatives exist?
The purpose implies when to use (when text replacement is needed), but the description provides no explicit guidance on when to use this over alternatives, nor any exclusions or prerequisites. It relies on the user to infer usage from the tool's purpose.
Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.
Tool Schema Changelog
Recent tool additions, removals, and schema changes observed during successful MCP inspections. Dates show when Glama detected each change.
5 tool updates
v0.1.0- First observed
copy_code - First observed
copy_entire_file - First observed
get_file_info - First observed
paste_code - First observed
search_and_replace
TDQS
Each tool targets a distinct operation: full file read, partial read, metadata read, text replacement, and line insertion. There is no ambiguity because the descriptions clearly differentiate between copying content and modifying files.
All tool names follow a consistent verb_noun snake_case pattern, such as copy_entire_file, get_file_info, and paste_code. Even search_and_replace uses a verb-first structure, maintaining predictability.
With 5 tools, the server is well-scoped for its purpose of copying and manipulating code. The count is neither too sparse nor excessive, and each tool serves a clear role in the workflow.
The tools cover the core operations for code copying: reading an entire file, reading a range, replacing text, and inserting code. A minor gap is the lack of a create_file operation, but agents can work around this by using existing files.
Maintenance
Resources
Unclaimed servers have limited discoverability.
Looking for Admin?
If you are the server author, to access and configure the admin panel.
Related MCP Connectors
Related MCP Servers
- AlicenseNot gradedqualityDmaintenanceMCP server for SSH remote execution, file transfer, and file editing with automatic backup/trash and ~/.ssh/config integration.1171MIT
- FlicenseAqualityDmaintenanceAn MCP server that enables AI coding tools to save, list, and read code snippets as files in the local filesystem.3-
- FlicenseNot gradedqualityDmaintenanceAn MCP server that provides secure access to local file system operations.-
- AlicenseNot gradedqualityCmaintenanceAn MCP server that provides on-demand safety for AI coding workflows, enabling inspection, review, checkpointing, and rollback of risky actions.211MIT
Latest Blog Posts
- Who's Calling? MCP Hosts Are an Identity Blind Spot (And the Spec Knows It)By Om-Shree-0709 on .mcpAgent IdentityOAuth 2.1
- Your AI Chatbot Just Exposed Your CEO's Salary to an InternBy Om-Shree-0709 on .Agent IdentityMCP SecurityOAuth Delegation
- Why MCP Servers Need Execution Sandboxing (And Why Your Current Stack Isn't Enough)By Om-Shree-0709 on .Agentic AiPrompt InjectionWebAssembly
MCP directory API
We provide all the information about MCP servers via our MCP API.
curl -X GET 'https://glama.ai/api/mcp/v1/servers/mhattingpete/code-copy-mcp'
If you have feedback or need assistance with the MCP directory API, please join our Discord server