feat: MCP server — agents can search and reuse session history across tools#6
Conversation
New internal/mcpserver package built on the official MCP Go SDK (github.com/modelcontextprotocol/go-sdk). It serves five typed tools over stdio so any MCP-capable agent can search and reuse the local session history of every supported agent: - list_sessions: newest-first summaries with provider, workspace-substring, and free-text filters (workspace + first/last user message), limit default 25 / max 100 with a total count for pagination awareness - get_transcript: user/assistant turns, truncated to the most recent max_turns (default 50) so old sessions cannot flood a caller's context - branch_session: fork a local copy via session.Branch - convert_session: rewrite into another agent's native format via session.Convert - resume_command: the exact shell command + cwd to resume, never executed Deliberately no delete tool: destructive actions stay behind the TUI's two-press confirmation. Branch/convert only write new files through the existing atomic paths; originals are never touched. Tests connect an in-memory MCP client to the real server so filtering, end-truncation, branch, and convert are exercised through full tool dispatch, hermetically via the provider home env overrides. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
`showagent mcp` runs the MCP server on stdin/stdout until the client disconnects or the process is interrupted; extra arguments are a usage error. Help text documents the new subcommand and its non-destructive, never-executes contract. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Adds the "Use it from inside your agent (MCP)" section: the shared-memory pitch, claude/codex wiring examples, the tool table, and the explicit no-delete/no-exec note. Tops the README with the mcp-name registry annotation (io.github.aytzey/showagent). Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
📝 WalkthroughWalkthroughAdds an ChangesMCP session server
Estimated code review effort: 3 (Moderate) | ~25 minutes Sequence Diagram(s)sequenceDiagram
participant Agent as Claude/Codex Agent
participant CLI as showagent CLI
participant MCPServer as mcpserver.Server
participant Store as Session Storage
Agent->>CLI: showagent mcp
CLI->>MCPServer: mcpserver.Run(ctx, version)
MCPServer->>MCPServer: register tools (list_sessions, get_transcript, branch_session, convert_session, resume_command)
Agent->>MCPServer: call list_sessions(filters)
MCPServer->>Store: discover sessions
Store-->>MCPServer: session rows
MCPServer-->>Agent: filtered/sorted summaries + total
Agent->>MCPServer: call get_transcript(id or "latest")
MCPServer->>Store: resolveRow(id)
Store-->>MCPServer: session row
MCPServer-->>Agent: transcript turns (truncated)
Agent->>MCPServer: call branch_session(id)
MCPServer->>Store: resolveRow(id) + write new session file
Store-->>MCPServer: new session id/path
MCPServer-->>Agent: new session id + resume command
Possibly related PRs
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
🧹 Nitpick comments (1)
cmd/showagent/main.go (1)
326-341: 🩺 Stability & Availability | 🔵 Trivial | 💤 Low valueConsider handling SIGTERM as well as SIGINT
signal.NotifyContextonly listens foros.Interrupt, so the MCP server won’t exit gracefully when a supervisor sends SIGTERM. Addingsyscall.SIGTERMhere is a small robustness win for containerized deployments.🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@cmd/showagent/main.go` around lines 326 - 341, runMCP currently only listens for os.Interrupt via signal.NotifyContext, so it won’t shut down gracefully on SIGTERM. Update the signal setup in runMCP to include syscall.SIGTERM alongside os.Interrupt, keeping the rest of the mcpserver.Run flow unchanged so the MCP server exits cleanly under container/supervisor shutdown.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Nitpick comments:
In `@cmd/showagent/main.go`:
- Around line 326-341: runMCP currently only listens for os.Interrupt via
signal.NotifyContext, so it won’t shut down gracefully on SIGTERM. Update the
signal setup in runMCP to include syscall.SIGTERM alongside os.Interrupt,
keeping the rest of the mcpserver.Run flow unchanged so the MCP server exits
cleanly under container/supervisor shutdown.
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: 94d3b0a2-009e-47d9-9d00-553a9b6efed5
⛔ Files ignored due to path filters (1)
go.sumis excluded by!**/*.sum
📒 Files selected for processing (6)
README.mdcmd/showagent/main.gocmd/showagent/main_test.gogo.modinternal/mcpserver/server.gointernal/mcpserver/server_test.go
What
showagent mcp— a stdio MCP server so any MCP-capable agent (Claude Code, Codex, ...) can search every past coding session on the machine, across all supported agents, and pull one in as context or convert it to continue there.Built on the official MCP Go SDK (
github.com/modelcontextprotocol/go-sdkv1.6.1) — the one new dependency.Tools
list_sessionstotalget_transcriptmax_turnskeeps the most recent N (default 50) withtotal_turns/truncatedmarkersbranch_sessionsession.Branch; returns new id + file + resume commandconvert_sessionsession.Convert; returns new id + file + resume commandresume_commandNo delete tool by design — destructive actions stay behind the TUI's two-press confirm. Branch/convert only ever write new files through the existing atomic paths.
Testing
demo/fixtures/gen.shfixtures: initialize → tools/list →list_sessions {"query":"rate limit"}→resume_command latest, all sane.go test ./... -racegreen, CGO-free cross-compile for linux/darwin/windows amd64.🤖 Generated with Claude Code
Summary by CodeRabbit
New Features
showagent, including a new command to expose session history through agent-friendly tools.Documentation
Bug Fixes