How ezyang/codemcp works
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: mcp.py MCP SSE server · init_project.py Project initialization · main.py Command dispatch · access.py Project access boundary
Components 18
Server Runtime
- CLI entry
codemcp/__main__.py - Command dispatch
codemcp/main.py - MCP SSE server · Serves Claude clients over a local SSE endpoint.
codemcp/mcp.py - Alternate agent adapter
codemcp/agno.py
Project Policy
- Project initialization · Establishes the scoped target checkout and bootstrap policy.
codemcp/tools/init_project.py - Project configuration · Loads codemcp.toml command and formatting declarations.
codemcp/config.py - Project access boundary · Constrains tool paths to the initialized project.
codemcp/access.py - Repository rules · Collects editor rules including Cursor rules.
codemcp/rules.py
MCP Tool Surface
- Inspect tools · Read, list, glob, and grep project content.
- Mutation tools · Write, targeted edit, move, remove, and chmod project files.
- File mutation internals · Shared synchronous, asynchronous, and line-ending handling.
codemcp/file_utils.py - Controlled command runner · Executes only commands declared by project configuration.
codemcp/tools/run_command.py - Command mediation
codemcp/shell.py
Change Lifecycle
- Git review tools · Provides diff, log, and show operations.
codemcp/tools/git_diff.py - Git change lifecycle · Creates and amends chat-scoped commits for review and rollback.
codemcp/git.py
Other components
- Claude MCP client
- Local Git checkout
- Formatter and validation commands
Connections 23
- 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