feat(mcp-server): add report_session_done and get_worktree_diff tools, document MCP server#142
Open
liam-russell wants to merge 3 commits into
Open
feat(mcp-server): add report_session_done and get_worktree_diff tools, document MCP server#142liam-russell wants to merge 3 commits into
liam-russell wants to merge 3 commits into
Conversation
…, document MCP server Closes #99 Expands the MCP tool set so external agents can review their own working-tree diff and report back that a session of work is done (surfaced as a toast in the workspace UI), plus adds a full reference doc for every tool the server exposes.
Contributor
There was a problem hiding this comment.
Pull request overview
Adds two new MCP server tools (get_worktree_diff, report_session_done) and wires report_session_done through main → preload → renderer so SproutGit can notify the user (toast) when an external agent reports it finished work in a worktree. Also introduces a comprehensive MCP server reference doc covering all tools and expected shapes.
Changes:
- Implemented and registered
get_worktree_diffandreport_session_donetool handlers (with shared “known worktree” validation). - Added a new main→renderer push event (
EVENT_MCP_SESSION_DONE) plus renderer listener/toast and preload API surface. - Added/updated unit + integration tests and wrote
docs/mcp-server.mdas a full tool reference.
Reviewed changes
Copilot reviewed 13 out of 13 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| packages/types/src/mcp.ts | Adds McpSessionDoneEvent payload type for the renderer push event. |
| packages/types/src/ipc.ts | Adds IPC.EVENT_MCP_SESSION_DONE constant for main→renderer notifications. |
| packages/mcp-server/src/tools.ts | Adds handlers + tool registrations for get_worktree_diff and report_session_done; refactors worktree validation into assertKnownWorktree. |
| packages/mcp-server/src/context.ts | Extends McpServerContext with reportSessionDone callback for host-app notification. |
| packages/mcp-server/src/tests/tools.test.ts | Adds handler-level tests for the two new MCP tools (diff + session done forwarding/validation). |
| packages/mcp-server/src/tests/http-server.test.ts | Updates HTTP server context stub + tools/list assertions to include new tool names. |
| docs/mcp-server.md | New end-to-end documentation for MCP server enablement, security model, tool reference, and example session. |
| docs/agent-instructions.md | Documents packages/mcp-server/ in the repo layout list and links to the MCP server doc. |
| app/src/renderer/settings/McpSection.tsx | Updates Settings copy to mention diffs and session-done reporting. |
| app/src/renderer/routes/workspace.tsx | Adds renderer-side listener that toasts on EVENT_MCP_SESSION_DONE. |
| app/src/preload/index.ts | Adds api.onMcpSessionDone bridge wiring IPC event to renderer callbacks. |
| app/src/main/mcp-bridge.ts | Implements reportSessionDone in the MCP server context by pushing EVENT_MCP_SESSION_DONE to the workspace window (if present). |
| app/src/main/tests/mcp-bridge.test.ts | Adds an end-to-end test calling report_session_done over real HTTP and asserting webContents.send. |
# Conflicts: # app/src/renderer/routes/workspace.tsx
…handling - Split worktreePath on both / and \ when deriving the toast's short name, so Windows paths show a worktree name instead of the full path. - Fix docs/comment wording that claimed report_session_done "doesn't touch git or the filesystem" — its known-worktree check does read via listWorktrees, same as every other read-only tool. The real guarantee is that it never mutates anything, which is what actually matters for the mutating-tools gate. - Also picks up two doc edits from the previous merge commit that were made to the working tree but never staged (agent-instructions.md's pointer to the Starlight guide, and the guide's new-tools table).
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Type
Summary
report_session_doneMCP tool so an external agent can tell SproutGit it finished a session of work in a worktree — surfaced to the user as a toast in the workspace.get_worktree_diffMCP tool so an agent can review its own working-tree diff (optionally scoped to one file) before reporting done.docs/mcp-server.md, a full reference for every MCP tool (parameters, return shapes, which are gated behind the mutating-tools permission, and an example session).Why
Issue #99:
packages/mcp-serverexisted but was undocumented, and was missing thereport_session_donecapability called out in the original proposal (docs/improvement-ideas.md).list_worktreesandcreate_worktreealready covered the other two examples from that proposal.Screenshots / recordings
Backend/tool-layer change; the only renderer touches are a one-line Settings description update and a new toast triggered by an MCP tool call (no static layout change to screenshot). Did not spin up the full Electron app to trigger the toast live — verified the event dispatch end-to-end instead via a real HTTP call into a running MCP server in
app/src/main/__tests__/mcp-bridge.test.ts(assertswebContents.sendreceives the rightEVENT_MCP_SESSION_DONEpayload).Breaking changes
None.
McpServerContextgained a new requiredreportSessionDonefield, but it's an internal type owned by this repo (packages/mcp-server+ its one consumer,app/src/main/mcp-bridge.ts), both updated together.Test plan
pnpm lint && pnpm typecheck && pnpm test— all green across the workspace.get_worktree_diff/report_session_donehandlers inpackages/mcp-server/src/__tests__/tools.test.ts(including the known-worktree validation and mock-forwarding behavior).app/src/main/__tests__/mcp-bridge.test.tsthat callsreport_session_doneover a real HTTP MCP request and asserts the renderer push event, plus a no-open-window no-op case.packages/mcp-server/src/__tests__/http-server.test.ts'stools/listassertion to include the two new tool names.