# ezyang/codemcp architecture

> Architecture diagram of the GitHub repository ezyang/codemcp, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-08-31). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/ezyang/codemcp
- Repository: https://github.com/ezyang/codemcp

## Overview

#### Purpose and operating model
codemcp is a Python MCP server that lets a Claude client inspect and modify a local Git checkout. Its core safety model is scoped project initialization, configured command execution rather than unrestricted shell access, and Git commits/amendments for agent edits. The README marks the project obsolete, but the implementation remains a local coding-agent server.

#### Process entry points
The installed CLI enters through `codemcp/__main__.py` and command dispatch in `codemcp/main.py`. The principal runtime mode is `codemcp serve`, which exposes an MCP SSE endpoint for Claude Desktop or a browser MCP extension. `codemcp/mcp.py` defines the MCP server integration; `codemcp/agno.py` appears to provide an alternate agent-framework integration.

#### Project initialization and session boundary
Initialization establishes the target repository and loads its per-project policy. `codemcp/tools/init_project.py` is the client-facing initialization tool; `codemcp/config.py` parses `codemcp.toml`; `codemcp/access.py` centralizes project/path access constraints. This is the main trust boundary: tools should operate only within the initialized project, while command permissions derive from declared configuration.

#### MCP tool surface
The server exposes granular tools rather than one monolithic coding operation. Filesystem capabilities are implemented under `codemcp/tools/`: reads and discovery (`read_file.py`, `ls.py`, `glob.py`, `grep.py`), mutations (`write_file.py`, `edit_file.py`, `mv.py`, `rm.py`, `chmod.py`), and controlled execution (`run_command.py`). This makes the Claude client responsible for sequencing inspect → edit → validate actions, with the MCP server enforcing local policy.

#### Edit pipeline and formatting
Mutation tools perform content and filesystem changes, with shared low-level concerns in `codemcp/file_utils.py`, `codemcp/async_file_utils.py`, and `codemcp/line_endings.py`. `codemcp/tools/edit_file.py` handles targeted text changes, while `codemcp/tools/write_file.py` handles replacement/creation. Configured formatting is a post-edit stage: commands defined in `codemcp.toml` are invoked through `codemcp/tools/run_command.py`, so formatting can modify the working tree before versioning.

#### Git-backed change lifecycle
Git is both an integration boundary and the rollback/audit mechanism. Core wrappers live in `codemcp/git.py`, `codemcp/git_commit.py`, and `codemcp/git_message.py`; Git-facing MCP tools include `codemcp/tools/git_diff.py`, `codemcp/tools/git_log.py`, and `codemcp/tools/git_show.py`. Edits made during a chat are intended to create a commit and then amend it as work continues, allowing users to review or revert agent changes at chat granularity.

#### Command security and external dependencies
Shell execution is deliberately mediated: `codemcp/tools/run_command.py` and `codemcp/shell.py` run only commands declared in project configuration, rather than accepting arbitrary command strings. The material external dependencies are Git, the local OS/filesystem, user-provided formatter/test commands, and an MCP-compatible Claude client. The server normally binds locally via SSE; remote exposure is possible but materially expands the trust boundary.

#### Rules and generated-project support
Repository instructions can be collected from editor rule formats by `codemcp/rules.py`, including Cursor-oriented behavior represented by `.cursor/rules/`. Project bootstrapping is supported by `codemcp/tools/init_project.py` and templates under `codemcp/templates/`, enabling a Claude workflow to initialize configuration before normal tool use.

Main entry points: [`codemcp/mcp.py`](https://github.com/ezyang/codemcp/blob/main/codemcp/mcp.py) (MCP SSE server), [`codemcp/tools/init_project.py`](https://github.com/ezyang/codemcp/blob/main/codemcp/tools/init_project.py) (Project initialization), [`codemcp/main.py`](https://github.com/ezyang/codemcp/blob/main/codemcp/main.py) (Command dispatch), [`codemcp/access.py`](https://github.com/ezyang/codemcp/blob/main/codemcp/access.py) (Project access boundary)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_runtime["Server Runtime"]
  node_cli["CLI entry<br/>Python CLI<br/>[__main__.py]"]
  node_main["Command dispatch<br/>runtime<br/>[main.py]"]
  node_mcp{{"MCP SSE server<br/>MCP integration<br/>[mcp.py]"}}
  node_agno["Alternate agent adapter<br/>agent integration<br/>[agno.py]"]
end

subgraph group_policy["Project Policy"]
  node_init["Project initialization<br/>MCP tool<br/>[init_project.py]"]
  node_config["Project configuration<br/>policy parser<br/>[config.py]"]
  node_access{{"Project access boundary<br/>authorization<br/>[access.py]"}}
  node_rules["Repository rules<br/>instruction collector<br/>[rules.py]"]
end

subgraph group_tools["MCP Tool Surface"]
  node_inspect["Inspect tools<br/>MCP tools"]
  node_edit["Mutation tools<br/>MCP tools"]
  node_fileutils["File mutation internals<br/>file I/O<br/>[file_utils.py]"]
  node_run["Controlled command runner<br/>MCP tool<br/>[run_command.py]"]
  node_shell{{"Command mediation<br/>shell security<br/>[shell.py]"}}
end

subgraph group_changes["Change Lifecycle"]
  node_gittools["Git review tools<br/>MCP tools<br/>[git_diff.py]"]
  node_git[("Git change lifecycle<br/>versioning<br/>[git.py]")]
end

node_client(("Claude MCP client<br/>external client"))
node_checkout[("Local Git checkout<br/>external filesystem")]
node_commands(("Formatter and validation commands<br/>external commands"))

node_cli -->|"starts"| node_main
node_main -->|"serve mode"| node_mcp
node_main -.->|"alternate integration"| node_agno
node_client -->|"MCP over SSE"| node_mcp
node_mcp -->|"exposes"| node_init
node_mcp -->|"exposes"| node_inspect
node_mcp -->|"exposes"| node_edit
node_mcp -->|"exposes"| node_run
node_mcp -->|"exposes"| node_gittools
node_init -->|"loads"| node_config
node_init -->|"establishes scope"| node_access
node_init -.->|"collects"| node_rules
node_access -->|"constrains paths"| node_inspect
node_access -->|"constrains paths"| node_edit
node_inspect -->|"reads"| node_checkout
node_edit -->|"uses"| node_fileutils
node_fileutils -->|"updates files"| node_checkout
node_config -->|"permits declared commands"| node_run
node_run -->|"mediates execution"| node_shell
node_shell -->|"runs"| node_commands
node_commands -.->|"formats or validates"| node_checkout
node_gittools -->|"queries"| node_git
node_git -->|"commits and amends"| node_checkout

click node_cli "https://github.com/ezyang/codemcp/blob/main/codemcp/__main__.py"
click node_main "https://github.com/ezyang/codemcp/blob/main/codemcp/main.py"
click node_mcp "https://github.com/ezyang/codemcp/blob/main/codemcp/mcp.py"
click node_agno "https://github.com/ezyang/codemcp/blob/main/codemcp/agno.py"
click node_init "https://github.com/ezyang/codemcp/blob/main/codemcp/tools/init_project.py"
click node_config "https://github.com/ezyang/codemcp/blob/main/codemcp/config.py"
click node_access "https://github.com/ezyang/codemcp/blob/main/codemcp/access.py"
click node_rules "https://github.com/ezyang/codemcp/blob/main/codemcp/rules.py"
click node_fileutils "https://github.com/ezyang/codemcp/blob/main/codemcp/file_utils.py"
click node_run "https://github.com/ezyang/codemcp/blob/main/codemcp/tools/run_command.py"
click node_shell "https://github.com/ezyang/codemcp/blob/main/codemcp/shell.py"
click node_gittools "https://github.com/ezyang/codemcp/blob/main/codemcp/tools/git_diff.py"
click node_git "https://github.com/ezyang/codemcp/blob/main/codemcp/git.py"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_cli,node_main,node_mcp,node_agno toneBlue
class node_init,node_config,node_access,node_rules toneAmber
class node_inspect,node_edit,node_fileutils,node_run,node_shell toneMint
class node_gittools,node_git toneRose
class node_client,node_checkout,node_commands toneNeutral
```

## Components

### Server Runtime

- [CLI entry](https://github.com/ezyang/codemcp/blob/main/codemcp/__main__.py): Python CLI · `codemcp/__main__.py`
- [Command dispatch](https://github.com/ezyang/codemcp/blob/main/codemcp/main.py): runtime · `codemcp/main.py`
- [MCP SSE server](https://github.com/ezyang/codemcp/blob/main/codemcp/mcp.py): MCP integration · Serves Claude clients over a local SSE endpoint. · `codemcp/mcp.py`
- [Alternate agent adapter](https://github.com/ezyang/codemcp/blob/main/codemcp/agno.py): agent integration · `codemcp/agno.py`

### Project Policy

- [Project initialization](https://github.com/ezyang/codemcp/blob/main/codemcp/tools/init_project.py): MCP tool · Establishes the scoped target checkout and bootstrap policy. · `codemcp/tools/init_project.py`
- [Project configuration](https://github.com/ezyang/codemcp/blob/main/codemcp/config.py): policy parser · Loads codemcp.toml command and formatting declarations. · `codemcp/config.py`
- [Project access boundary](https://github.com/ezyang/codemcp/blob/main/codemcp/access.py): authorization · Constrains tool paths to the initialized project. · `codemcp/access.py`
- [Repository rules](https://github.com/ezyang/codemcp/blob/main/codemcp/rules.py): instruction collector · Collects editor rules including Cursor rules. · `codemcp/rules.py`

### MCP Tool Surface

- **Inspect tools**: MCP tools · Read, list, glob, and grep project content.
- **Mutation tools**: MCP tools · Write, targeted edit, move, remove, and chmod project files.
- [File mutation internals](https://github.com/ezyang/codemcp/blob/main/codemcp/file_utils.py): file I/O · Shared synchronous, asynchronous, and line-ending handling. · `codemcp/file_utils.py`
- [Controlled command runner](https://github.com/ezyang/codemcp/blob/main/codemcp/tools/run_command.py): MCP tool · Executes only commands declared by project configuration. · `codemcp/tools/run_command.py`
- [Command mediation](https://github.com/ezyang/codemcp/blob/main/codemcp/shell.py): shell security · `codemcp/shell.py`

### Change Lifecycle

- [Git review tools](https://github.com/ezyang/codemcp/blob/main/codemcp/tools/git_diff.py): MCP tools · Provides diff, log, and show operations. · `codemcp/tools/git_diff.py`
- [Git change lifecycle](https://github.com/ezyang/codemcp/blob/main/codemcp/git.py): versioning · Creates and amends chat-scoped commits for review and rollback. · `codemcp/git.py`

### Other components

- **Claude MCP client**: external client
- **Local Git checkout**: external filesystem
- **Formatter and validation commands**: external commands

## Connections

- CLI entry → Command dispatch: starts
- Command dispatch → MCP SSE server: serve mode
- Command dispatch → Alternate agent adapter: alternate integration
- Claude MCP client → MCP SSE server: MCP over SSE
- MCP SSE server → Project initialization: exposes
- MCP SSE server → Inspect tools: exposes
- MCP SSE server → Mutation tools: exposes
- MCP SSE server → Controlled command runner: exposes
- MCP SSE server → Git review tools: exposes
- Project initialization → Project configuration: loads
- Project initialization → Project access boundary: establishes scope
- Project initialization → Repository rules: collects
- Project access boundary → Inspect tools: constrains paths
- Project access boundary → Mutation tools: constrains paths
- Inspect tools → Local Git checkout: reads
- Mutation tools → File mutation internals: uses
- File mutation internals → Local Git checkout: updates files
- Project configuration → Controlled command runner: permits declared commands
- Controlled command runner → Command mediation: mediates execution
- Command mediation → Formatter and validation commands: runs
- Formatter and validation commands → Local Git checkout: formats or validates
- Git review tools → Git change lifecycle: queries
- Git change lifecycle → Local Git checkout: commits and amends
