Skip to content

fix(mcp): reject empty anchor in MemoryFetch (#219) - #251

Merged
radimsem merged 1 commit into
devfrom
fix/fetch-validate-empty-anchor
Jun 6, 2026
Merged

fix(mcp): reject empty anchor in MemoryFetch (#219)#251
radimsem merged 1 commit into
devfrom
fix/fetch-validate-empty-anchor

Conversation

@radimsem

@radimsem radimsem commented Jun 6, 2026

Copy link
Copy Markdown
Owner

Closes #219.

What

HandleFetch passed input.Anchor straight to Engine.Fetch with no guard. An empty anchor produced a generic failed to fetch: ...node not found error that obscured the real problem (a missing required argument), hurting LLM tool-use recovery loops.

Change

  • pkg/mcp/tools/fetch.go — add an empty-anchor guard immediately after defer d.logCall(...) (so the rejected call still logs), returning anchor is required. Mirrors the existing precedent in related.go, fetch_batch.go, and history.go.
  • pkg/mcp/tools/tools_test.goTestHandleFetch_EmptyAnchor, mirroring TestHandleHistory_EmptyAnchor. Asserts the anchor is required message and the absence of the generic failed to fetch error, so the test proves the guard short-circuits before Engine.Fetch rather than passing on the engine's own empty-ID error (the [enhancement] HandleWrite swallows GetNode errors with blank identifier — non-ErrNoRows DB failures silently fall into the create path #218 false-positive trap).

Notes

  • Contract-neutral: anchor is already documented as the required node ID, so no skills/remind/ update is needed — consistent with the sibling guards.
  • Verified: `make build`, `make test`, `make lint` (0 issues) all green; stash-the-fix confirms the new test fails without the guard.

🤖 Generated with Claude Code

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Signed-off-by: radimsem <me@radimsemerak.cz>
@radimsem
radimsem merged commit ac04128 into dev Jun 6, 2026
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[enhancement] HandleFetch should validate empty anchor like MemoryRelated and MemoryFetchBatch

1 participant