Skip to content

Add Zed Agent support via MCP server#765

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

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

@Krishnachaitanyakc Krishnachaitanyakc commented Mar 20, 2026

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

Open with Devin

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).
@Krishnachaitanyakc Krishnachaitanyakc marked this pull request as ready for review March 21, 2026 16:12
@Krishnachaitanyakc
Copy link
Contributor Author

@svarlamov can you review this?

Copy link
Contributor

@devin-ai-integration devin-ai-integration bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Devin Review found 1 potential issue.

View 6 additional findings in Devin Review.

Open in Devin Review

Comment on lines +389 to +391
if !status.success() {
return Err(format!("Checkpoint failed: {}", stderr_output.trim()));
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔴 MCP server always reports checkpoint success because subprocess always exits with code 0

The run_checkpoint function in mcp_server.rs relies on status.success() (line 389) to detect child process failures. However, git-ai checkpoint always exits with code 0 regardless of outcome—every error path in handle_checkpoint calls std::process::exit(0) (e.g., git_ai_handlers.rs:339, git_ai_handlers.rs:345, git_ai_handlers.rs:566, git_ai_handlers.rs:999), and the success path naturally exits with 0 via main.rs:46. Because the exit code check never triggers, the captured stderr (which contains the actual error messages) is silently discarded at line 384, and the function always returns Ok("Created ... checkpoint for N file(s)"). Zed's agent will always receive a success response even when the checkpoint completely failed (e.g., no git repo found, invalid JSON input, preset errors), causing AI authorship tracking to silently not work.

Prompt for agents
In src/commands/mcp_server.rs, the run_checkpoint function at lines 389-391 checks status.success() to detect failures, but the child process (git-ai checkpoint) always exits with code 0 even on error. The fix should check the captured stderr output for error indicators regardless of exit code. One approach: after joining stderr_handle (line 384), check if stderr_output contains known error prefixes like 'Zed preset error:', 'No hook input provided', 'Checkpoint failed', 'Failed to find repository', etc. If stderr_output is non-empty and doesn't contain 'Checkpoint completed', treat it as a failure and return Err with the stderr content. Alternatively, you could refactor to call the checkpoint logic directly in-process (similar to how other presets work) instead of shelling out, which would avoid the exit code problem entirely.
Open in Devin Review

Was this helpful? React with 👍 or 👎 to provide feedback.

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