Skip to content

MCP: add an ask tool that returns a grounded, cited answer - #32

Merged
ericmann merged 1 commit into
mainfrom
agent/issue-12
Jun 18, 2026
Merged

ericmann merged 1 commit into
mainfrom
agent/issue-12

Conversation

@claude

@claude claude Bot commented Jun 18, 2026

Copy link
Copy Markdown
Contributor

🤖 Agent-Generated PR

Closes #12
Agent Used: Claude Code
Complexity: medium


Summary

Adds an ask MCP tool that runs retrieve→synthesize and returns a structured JSON response with answer (grounded text) and citations (path:line_start-line_end references), giving MCP clients (Claude Desktop, Cursor) a direct "what did I decide about X" answer instead of raw search chunks.

Implementation Notes

  • mcpAsk is a standalone helper that accepts a synth.Client parameter for testability — the closure in runMCP builds the live client via answerClient(cfg) and checks available before calling through, surfacing a clear error when synthesis is unavailable (local_only without Ollama, missing API key, etc.).
  • Returns {"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, and k filters match the existing search tool so callers can scope the retrieval window.
  • No new dependencies. Fully reuses searchChunks, answerQuery, and answerClient from search.go.

Changes

  • cmd/mcp.go: added askInput and askResponse structs, registered ask tool in runMCP, implemented mcpAsk helper
  • cmd/mcp_test.go: four table-driven tests covering happy path, empty query error, synth error propagation, and no-results short-circuit

Testing

Automated:

  • Unit tests added/updated
  • Integration tests added/updated
  • All existing tests pass (make test — all 11 packages green)

Manual testing performed:

  • Traced the happy path: searchChunks → answerQuery (fake client) → JSON marshal → citations populated
  • Traced no-results path: synth client not called, empty citations returned
  • Traced unavailable-synth path: answerClient returns available=false, error returned before mcpAsk is called

Review Checklist

Correctness

  • Code actually solves the issue
  • Acceptance criteria are met
  • Edge cases handled

Code Quality

  • Follows existing codebase patterns
  • Follows project coding standards
  • Naming conventions consistent
  • No unnecessary complexity
  • Comments where needed (but code is self-documenting)

Security

  • Input validation present
  • No exposed secrets or credentials
  • Data properly sanitized/escaped
  • Authentication/authorization checks where needed

Performance

  • No obvious N+1 queries
  • Reasonable algorithmic complexity
  • Caching used where appropriate
  • No blocking operations in request lifecycle

Tests

  • Tests actually test behavior (not just coverage)
  • Edge cases covered
  • Failure modes tested

Reviewer Notes

The synth.Client injection pattern (passing the fake directly into mcpAsk) keeps the function pure and avoids any config/env inspection in tests, consistent with the approach used throughout cmd/answer_test.go.

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>
@claude claude Bot added the agent-generated PR was created by an AI agent label Jun 18, 2026
@ericmann
ericmann merged commit e3ac3e0 into main Jun 18, 2026
2 checks passed
@ericmann
ericmann deleted the agent/issue-12 branch June 18, 2026 21:16
@claude

claude Bot commented Jun 18, 2026

Copy link
Copy Markdown
Contributor Author

Retro: no durable lesson (merged clean / one-off).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agent-generated PR was created by an AI agent

Projects

None yet

Development

Successfully merging this pull request may close these issues.

MCP: add an ask tool that returns a grounded, cited answer

1 participant