Repository navigation
MCP: add an ask tool that returns a grounded, cited answer - #32
Merged
Merged
Conversation
Adds an `ask` tool to the MCP server that runs retrieve→synthesize and returns a JSON envelope with `answer` (the grounded text) and `citations` (`path:line_start-line_end` refs). Honors `synth_provider` and `local_only`; returns a clear error when synthesis is unavailable. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Contributor
Author
|
Retro: no durable lesson (merged clean / one-off). |
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.
🤖 Agent-Generated PR
Closes #12
Agent Used: Claude Code
Complexity: medium
Summary
Adds an
askMCP tool that runs retrieve→synthesize and returns a structured JSON response withanswer(grounded text) andcitations(path:line_start-line_endreferences), giving MCP clients (Claude Desktop, Cursor) a direct "what did I decide about X" answer instead of raw search chunks.Implementation Notes
mcpAskis a standalone helper that accepts asynth.Clientparameter for testability — the closure inrunMCPbuilds the live client viaanswerClient(cfg)and checksavailablebefore calling through, surfacing a clear error when synthesis is unavailable (local_only without Ollama, missing API key, etc.).{"answer": "...", "citations": ["path:line-line", ...]}. When no chunks are found the synth client is not called — returns{"answer": "No relevant notes found.", "citations": []}instead, avoiding an ungrounded hallucinated answer.since,tag,project, andkfilters match the existingsearchtool so callers can scope the retrieval window.searchChunks,answerQuery, andanswerClientfromsearch.go.Changes
cmd/mcp.go: addedaskInputandaskResponsestructs, registeredasktool inrunMCP, implementedmcpAskhelpercmd/mcp_test.go: four table-driven tests covering happy path, empty query error, synth error propagation, and no-results short-circuitTesting
Automated:
make test— all 11 packages green)Manual testing performed:
searchChunks→answerQuery(fake client) → JSON marshal → citations populatedanswerClientreturnsavailable=false, error returned beforemcpAskis calledReview Checklist
Correctness
Code Quality
Security
Performance
Tests
Reviewer Notes
The
synth.Clientinjection pattern (passing the fake directly intomcpAsk) keeps the function pure and avoids any config/env inspection in tests, consistent with the approach used throughoutcmd/answer_test.go.