fix: include tool result payload in text content, not just a count #27

Merged
jknapp merged 1 commits from fix/tool-results-text-payload into main 2026-11-14 18:56:07 +00:00
Owner

Problem

From a claude.ai session, memory_search and memory_list returned only "8 result(s)" / "30 result(s)", with no ids, content, tags or scores, so the caller couldn't read or memory_get anything it found.

Root cause

ok() in apps/web/lib/mcp/tools.ts put only the summary string in content and the payload only in structuredContent. The tools declare no outputSchema, and claude.ai renders only the content text blocks. Claude Code reads structuredContent, which is why the bug never showed there.

Every tool uses ok(), so the problem was wider than reported:

  • memory.get showed only memory <id>
  • snippet.get dropped the body
  • snippet.list showed only a count
  • project.identify and memory.write looked fine only because their summaries include the id

Fix

The first text block is now <summary>\n<JSON payload>, which is what the MCP spec asks for when a tool returns structured results. structuredContent is unchanged. I used one block instead of two because some clients render only the first block.

Tests

Added 5 integration tests that check the first text block of memory.list, memory.search (including rrfScore), memory.get, snippet.list and snippet.get contains ids and content, not just a count. All 5 failed before the fix with the reported symptom, and the full suite (75 tests) passes after. Typecheck and lint are clean.

After deploy

From a claude.ai session:

  • memory_search {query: "OLS Digital", project: "ols-digital"} should return memory e9e10431-47f2-4f82-ab6c-d1d363d9de65
  • memory_list {project: "ols-digital"} should list the same memory

🤖 Generated with Claude Code

## Problem From a claude.ai session, `memory_search` and `memory_list` returned only `"8 result(s)"` / `"30 result(s)"`, with no ids, content, tags or scores, so the caller couldn't read or `memory_get` anything it found. ## Root cause `ok()` in `apps/web/lib/mcp/tools.ts` put only the summary string in `content` and the payload only in `structuredContent`. The tools declare no `outputSchema`, and claude.ai renders only the `content` text blocks. Claude Code reads `structuredContent`, which is why the bug never showed there. Every tool uses `ok()`, so the problem was wider than reported: - `memory.get` showed only `memory <id>` - `snippet.get` dropped the body - `snippet.list` showed only a count - `project.identify` and `memory.write` looked fine only because their summaries include the id ## Fix The first text block is now `<summary>\n<JSON payload>`, which is what the MCP spec asks for when a tool returns structured results. `structuredContent` is unchanged. I used one block instead of two because some clients render only the first block. ## Tests Added 5 integration tests that check the first text block of `memory.list`, `memory.search` (including `rrfScore`), `memory.get`, `snippet.list` and `snippet.get` contains ids and content, not just a count. All 5 failed before the fix with the reported symptom, and the full suite (75 tests) passes after. Typecheck and lint are clean. ## After deploy From a claude.ai session: - `memory_search {query: "OLS Digital", project: "ols-digital"}` should return memory `e9e10431-47f2-4f82-ab6c-d1d363d9de65` - `memory_list {project: "ols-digital"}` should list the same memory 🤖 Generated with [Claude Code](https://claude.com/claude-code)
jknapp added 1 commit 2026-11-14 18:54:30 +00:00
ok() put only a summary string ("8 result(s)") in `content` and the
actual payload only in `structuredContent`. Tools declare no
outputSchema, and claude.ai renders only the text blocks, so
memory.search / memory.list returned counts with no ids — the caller
could not read or memory.get anything it found. The same helper backs
every tool, so memory.get, snippet.get (body dropped) and snippet.list
were equally affected; project.identify and memory.write only looked
fine because their summaries embed the id.

The first text block is now `<summary>\n<JSON payload>`, per the MCP
spec's guidance that structured results also be returned as serialized
JSON text. structuredContent is unchanged for clients that consume it.
One block rather than two because some clients render only the first.

Adds integration tests asserting that the first text block of
memory.list, memory.search, memory.get, snippet.list and snippet.get
carries ids/content, not just the count.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
jknapp merged commit 3d43c40609 into main 2026-11-14 18:56:07 +00:00
jknapp deleted branch fix/tool-results-text-payload 2026-11-14 18:56:08 +00:00
Sign in to join this conversation.
No Reviewers
No labels
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: cybercove-labs/shared-memory#27