codemcp

repository·main·Indexed 23 days ago

https://github.com/ezyang/codemcp

An MCP (Model Context Protocol) server version 0.7.0 that enables LLMs like Claude to act as active pair programming assistants. It provides tools for file operations (ReadFile, WriteFile, EditFile, LS, Grep), project initialization, and the execution of project-specific shell commands defined in a codemcp.toml file, including automatic Git snapshots during command execution.

Tokens
9.6K
Snippets
12
Records
75
Agent score
82%

What's inside codemcp

  1. How InitProject integrates system prompts

    main

    When the InitProject tool is called, codemcp performs the following integration steps:

    1. Reads the codemcp.toml file from the project root.
    2. Constructs a comprehensive system prompt consisting of:
      • Default system instructions.
      • The custom project_prompt defined in the config.
      • Instructions on when and how to use the available tools (e.g., instructing Claude to use the Format tool once a task is complete if a format command is configured).
  2. Configure codemcp in Claude Desktop (macOS/Linux)

    main

    To use codemcp with Claude Desktop on macOS or Linux, add the server configuration to your ~/.config/anthropic/claude/claude_desktop_config.json file. This method uses uvx to run the package directly from the GitHub repository.

    Note: Replace <USERNAME> with your actual system username. Ensure the path to uvx is correct for your installation.

    {
      "mcpServers": {
        "codemcp": {
          "command": "/Users/<USERNAME>/.local/bin/uvx",
          "args": [
            "--from",
            "git+https://github.com/ezyang/codemcp@prod",
            "codemcp"
          ]
        }
      }
    }
  3. Configure codemcp in Claude Desktop (Windows)

    main

    To use codemcp with Claude Desktop on Windows, add the server configuration to your %USERPROFILE%\.anthropic\claude\claude_desktop_config.json file. This method uses uvx.exe to run the package directly from the GitHub repository.

    Note: Replace <USERNAME> with your actual Windows username.

    {
      "mcpServers": {
        "codemcp": {
          "command": "C:\\Users\\<USERNAME>\\.local\\bin\\uvx.exe",
          "args": [
            "--from",
            "git+https://github.com/ezyang/codemcp@prod",
            "codemcp"
          ]
        }
      }
    }
  4. Install and run codemcp

    main

    To use codemcp as a pair programming assistant in Claude, follow these steps:

    1. Prerequisites: Ensure uv and git are installed on your system.
    2. Browser Extension: Install the claude-mcp extension to connect to SSE MCP servers directly from the Claude website.
    3. Start the Server: Run the following command to start the codemcp server using uvx:
      uvx --from git+https://github.com/ezyang/codemcp@prod codemcp serve
      • Use --port <PORT> to specify a non-standard port.
      • Use --host <IP> to run remotely (e.g., via Tailscale), but be aware this allows arbitrary code execution on your machine.
    4. Connect Claude: In the claude-mcp extension, configure the URL to http://127.0.0.1:8000/sse (adjust the port if you changed it in step 3).
    5. Verify: Check the browser console for [MCP codemcp] SSE connection opened or ask Claude what tools it has available.
    uvx --from git+https://github.com/ezyang/codemcp@prod codemcp serve
  5. Configure codemcp for a project

    main

    Before starting work, you must create a codemcp.toml file in your Git repository's root directory. This file allows you to define project-specific prompts and permitted commands.

    Defining Commands

    You must declare commands the agent is allowed to run in the [commands] section. This prevents unrestricted shell access.

    • The format command is special: it is automatically executed after every file edit.
    • Other commands (like test) are available for the LLM to decide when to use.

    Project Prompts

    You can define a project_prompt which is loaded when the project is initialized in a chat session.

    project_prompt = """
    Before beginning work on this feature, write a short haiku. Do this only once.
    """
    
    [commands]
    format = ["./run_format.sh"]
    test = ["./run_test.sh"]
  6. Initialize codemcp in Claude

    main

    To start using codemcp in a Claude chat session, you should provide initialization instructions. It is recommended to create a Claude Project and add the following to the Project Instructions:

    Initialize codemcp with $PROJECT_DIR

    Replace $PROJECT_DIR with the absolute path to the project directory you want the agent to work on.

  7. Install codemcp globally via pip

    main

    If you prefer not to use uv, you can install codemcp globally using pip. This requires Python 3.12 and assumes no dependency conflicts with your global Python environment.

    1. Install the package: pip install git+https://github.com/ezyang/codemcp@prod

    2. Configure Claude Desktop: Add the following to your claude_desktop_config.json:

      {
          "mcpServers": {
               "codemcp": {
                     "command": "python",
                     "args": ["-m", "codemcp"]
                }
           }
      }
    3. Update manually: To upgrade, run: pip install --upgrade git+https://github.com/ezyang/codemcp@prod

    pip install git+https://github.com/ezyang/codemcp@prod
  8. Configure codemcp in Claude Desktop using WSL (Recommended for Windows)

    main

    If you prefer a Linux environment on Windows, you can run codemcp via WSL. This allows Claude Desktop to access your Linux filesystem directly.

    1. Prerequisites: Ensure Python 3.12+ and uv are installed within your WSL distribution.
    2. Configuration: Add the following to your claude_desktop_config.json file, replacing NameOfWSLUser with your actual WSL username.
    3. Usage: You can initialize codemcp in Claude using Linux paths, e.g., Initialize codemcp with /home/NameOfWSLUser/project_in_wsl_to_work_on.

    WSL Setup Commands:

    # Install Python 3.12
    sudo apt update
    sudo apt install python3.12
    
    # Install uv
    curl -sSf https://astral.sh/uv/install.sh | sh
    {
      "mcpServers": {
        "codemcp": {
          "command": "wsl.exe",
          "args": [
            "bash",
            "-c",
            "/home/NameOfWSLUser/.local/bin/uvx --from git+https://github.com/ezyang/codemcp@prod codemcp"
          ]
        }
      }
    }
  9. Configure advanced command settings in codemcp.toml

    main

    For more control, you can provide specific documentation for individual tools within the [commands] section. This helps the LLM understand how to use the command correctly.

    Use the [commands.<tool_name>] syntax to provide a doc string alongside the command array.

    [commands.test]
    command = ["./run_test.sh"]
    doc = "Accepts a pytest-style test selector as an argument to run a specific test."
  10. Define a project prompt in codemcp.toml

    main

    Use the project_prompt key in codemcp.toml to provide Claude with project-specific instructions, context, or coding standards. This string is automatically injected into the system prompt during project initialization.

    project_prompt = """
    Project-specific instructions for Claude go here.
    """
  11. Configure codemcp using codemcp.toml

    main
    codemcp is configured via a codemcp.toml file located in the project root. This file allows you to define project-specific instructions for the AI and register shell commands that the AI can trigger via specialized tools.
  12. Register commands in codemcp.toml

    main

    The [commands] section allows you to define shell commands that Claude can execute through specific tools. Commands are defined as arrays of strings; these strings are joined with spaces and executed in a shell context.

    Currently, the format command is supported. It is used by the Format tool to apply project-specific code formatting standards.

    [commands]
    format = ["./run_format.sh"]