Skip to main content
Glama
mhattingpete

code-copy-mcp

by mhattingpete

Code Copy MCP Server

Python MCP

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
) -> str

paste_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
) -> str

copy_entire_file

Copy the complete content of a source file.

copy_entire_file(
    source_file: str,
    include_line_numbers: bool = False
) -> str

search_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
) -> str

get_file_info

Get detailed information about a file.

get_file_info(file_path: str) -> str

Installation

Prerequisites

  • Python 3.11 or higher

  • UV package manager

Setup

  1. Clone or create the project:

cd /Users/map/Documents/Repos/code-copy-mcp
  1. Install dependencies:

uv install
  1. Configure allowed directories (optional):

cp .env.example .env
# Edit .env to set your ALLOWED_DIRECTORIES

Usage

Running the Server

uv run python mcp_server.py

Development Mode

# Activate virtual environment first
source .venv/bin/activate  # On Windows: .venv\Scripts\activate

# Run server
python mcp_server.py

Configuration

Create a .env file in the project root:

# Comma-separated list of allowed directories
ALLOWED_DIRECTORIES=/Users/yourname,/Users/yourname/Documents,/Users/yourname/Projects

If 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

  1. Copy code lines from a source file:

    copy_code("/path/to/source.py", start_line=10, end_line=20)
  2. Paste the code into target file:

    paste_code("/path/to/target.py", line_number=5, code=" copied_code_content ")
  3. 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

  1. Clone the repository:

    git clone https://github.com/mhattingpete/code-copy-mcp.git
    cd code-copy-mcp
  2. Install dependencies:

    uv sync
    # Or without UV: pip install -e .
  3. 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)

  1. Open Cursor settings (Cmd/Ctrl + ,)

  2. Navigate to ExtensionsMCP Servers

  3. Add 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

  1. Install the Claude Code

  2. 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:

  1. "Module not found" errors:

    # Ensure dependencies are installed
    uv install
    # Or with pip:
    pip install -e .
  2. Permission denied errors:

    • Check that the allowed directories are correctly configured

    • Ensure the directories exist and are accessible

  3. 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 50

The assistant will:

  1. Use get_file_info to examine the files

  2. Use copy_code with appropriate line numbers

  3. Use paste_code at 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 backups

The assistant will:

  1. Use search_and_replace on each file

  2. Verify changes with get_file_info

  3. Report the modifications made

Example 3: Copy entire file

User: Make a copy of template.py as new_template.py

The assistant will:

  1. Use copy_entire_file to get the content

  2. Use paste_code to 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 file

Dependencies

  • 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 tools
copy_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

ParametersJSON Schema
NameRequiredDescriptionDefault
end_lineNo
start_lineYes
source_fileYes
include_line_numbersNo

Output Schema

ParametersJSON Schema
NameRequiredDescription
resultYes

TDQS

A3.9/5.0
Behavior3/5

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.

Conciseness5/5

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.

Completeness4/5

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.

Parameters5/5

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.

Purpose5/5

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.

Usage Guidelines2/5

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

ParametersJSON Schema
NameRequiredDescriptionDefault
source_fileYes
include_line_numbersNo

Output Schema

ParametersJSON Schema
NameRequiredDescription
resultYes

TDQS

A4/5.0
Behavior3/5

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.

Conciseness5/5

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.

Completeness4/5

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.

Parameters4/5

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.

Purpose5/5

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.

Usage Guidelines3/5

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

ParametersJSON Schema
NameRequiredDescriptionDefault
file_pathYes

Output Schema

ParametersJSON Schema
NameRequiredDescription
resultYes

TDQS

C2.7/5.0
Behavior2/5

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.

Conciseness4/5

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.

Completeness2/5

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.

Parameters2/5

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.

Purpose4/5

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.

Usage Guidelines2/5

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

ParametersJSON Schema
NameRequiredDescriptionDefault
codeYes
line_numberYes
target_fileYes
create_backupNo

Output Schema

ParametersJSON Schema
NameRequiredDescription
resultYes

TDQS

A3.7/5.0
Behavior3/5

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.

Conciseness5/5

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.

Completeness3/5

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.

Parameters4/5

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.

Purpose5/5

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.

Usage Guidelines2/5

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

ParametersJSON Schema
NameRequiredDescriptionDefault
replace_allNo
replacementYes
target_fileYes
create_backupNo
case_sensitiveNo
search_patternYes

Output Schema

ParametersJSON Schema
NameRequiredDescription
resultYes

TDQS

A3.6/5.0
Behavior2/5

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.

Conciseness4/5

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.

Completeness3/5

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.

Parameters4/5

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.

Purpose5/5

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.

Usage Guidelines3/5

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.

  1. 5 tool updatesv0.1.0
    • First observedcopy_code
    • First observedcopy_entire_file
    • First observedget_file_info
    • First observedpaste_code
    • First observedsearch_and_replace

TDQS

A3.7/5.0
Disambiguation5/5

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.

Naming Consistency5/5

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.

Tool Count5/5

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.

Completeness4/5

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

ActivityInactive
ResponsivenessNo issues

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

Latest Blog Posts

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