Skip to content

Add Zed Agent support via MCP server#765

Draft
Krishnachaitanyakc wants to merge 1 commit intogit-ai-project:mainfrom
Krishnachaitanyakc:feat/zed-agent-675
Draft

Add Zed Agent support via MCP server#765
Krishnachaitanyakc wants to merge 1 commit intogit-ai-project:mainfrom
Krishnachaitanyakc:feat/zed-agent-675

Conversation

@Krishnachaitanyakc
Copy link
Contributor

Closes #675

Summary

Adds Zed Agent support for git-ai. Zed's extension API currently lacks tool-use hooks (no pre/post tool use callbacks, no document change events from extensions), so integration uses an MCP server approach.

Components

  • git-ai mcp-server — MCP server over stdio with Content-Length framing (MCP/LSP spec). Exposes a git_ai_checkpoint tool that Zed's agent can call before/after file edits
  • zed checkpoint preset — Parses hook input from MCP tool calls, creates Human (PreToolUse) and AiAgent (PostToolUse) checkpoints
  • Zed installer (src/mdm/agents/zed.rs) — Detects Zed installation (binary + ~/.config/zed/), configures context_servers entry. Respects XDG_CONFIG_HOME
  • .zed/rules template (agent-support/zed/rules) — Instructs the agent to call git_ai_checkpoint before/after every file edit

How it works

  1. git-ai install-hooks → detects Zed → adds MCP server config to ~/.config/zed/settings.json
  2. User copies .zed/rules to their project
  3. Zed's agent reads the rules → calls git_ai_checkpoint(event: "PreToolUse") before editing and git_ai_checkpoint(event: "PostToolUse") after
  4. MCP server shells out to git-ai checkpoint zed --hook-input stdin
  5. Standard git-ai attribution pipeline handles the rest

Design decisions

  • Stable session ID: Generated per MCP server instance (not per call), so pre/post checkpoint pairs are properly correlated
  • Pipe deadlock prevention: Process spawning starts stdout/stderr readers before writing stdin, per codebase conventions
  • Event validation: Preset validates PreToolUse/PostToolUse values

Limitations

  • Relies on agent compliance with rules (no enforced hooks — Zed doesn't offer them)
  • No transcript capture (Zed doesn't expose conversation data via MCP)
  • These are inherent to Zed's current API surface

Test plan

  • cargo fmt -- --check — passes
  • cargo check — zero warnings
  • cargo clippy --lib -- -D warnings — passes
  • cargo test zed — all 5 tests pass
  • Full test suite — no regressions
  • Manual: verify git-ai mcp-server responds to MCP protocol messages
  • Manual: verify git-ai install-hooks detects Zed and outputs config instructions

Zed's extension API lacks tool-use hooks, so integration uses an MCP
server that exposes a `git_ai_checkpoint` tool. The agent is instructed
via a .rules file to call checkpoints before/after file edits.

Components:
- `git-ai mcp-server` command: MCP server over stdio with Content-Length
  framing (MCP/LSP spec), exposes git_ai_checkpoint tool
- `zed` checkpoint preset: parses hook input from MCP tool calls
- Zed installer: detects Zed via binary/config, sets up context_servers
- `.zed/rules` template: instructs agent to call checkpoint tool

The MCP server generates a stable session ID per instance to correlate
pre/post checkpoint pairs. Process spawning follows pipe deadlock
prevention patterns (start readers before writing stdin).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add support to Zed Agent

1 participant