Skip to content

fix(mcp): serialize empty retrieve_tools result as [] instead of null - #954

Merged
github-actions[bot] merged 2 commits into
mainfrom
fix/retrieve-tools-empty-null
Aug 5, 2026
Merged

fix(mcp): serialize empty retrieve_tools result as [] instead of null#954
github-actions[bot] merged 2 commits into
mainfrom
fix/retrieve-tools-empty-null

Conversation

@Dumbris

@Dumbris Dumbris commented Aug 5, 2026

Copy link
Copy Markdown
Member

Summary

  • Fixes retrieve_tools returns "tools": null instead of [] on empty search — breaks strict MCP clients #953: retrieve_tools returned "tools": null when a search matched nothing, because the tools slice was a nil slice (var mcpTools []map[string]interface{}) and Go marshals nil slices as null. Strict MCP clients that iterate the array crash ('NoneType' object is not iterable).
  • Initializes the slice with make(..., 0, len(results)) so zero-match responses always emit "tools": []. This also covers the case where the spec-035 annotation filter removes every match.

Test plan

  • New regression test TestRetrieveTools_EmptyResultSerializesEmptyArray — verified RED ("tools":null in the serialized response) before the fix, GREEN after.
  • go test -race ./internal/server/ passes; golangci-lint v2 (CI config) clean.

🤖 Generated with Claude Code

https://claude.ai/code/session_01W2f2uxUUtENehyZoiVLQKN

A nil tools slice marshals as JSON null, crashing strict MCP clients
that iterate the array ('NoneType' object is not iterable). Initialize
the slice so zero-match searches (including results fully removed by
the spec-035 annotation filter) always emit "tools": [].

Fixes #953

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01W2f2uxUUtENehyZoiVLQKN
@cloudflare-workers-and-pages

cloudflare-workers-and-pages Bot commented Aug 5, 2026

Copy link
Copy Markdown

Deploying mcpproxy-docs with  Cloudflare Pages  Cloudflare Pages

Latest commit: a991bf4
Status: ✅  Deploy successful!
Preview URL: https://86a20ba7.mcpproxy-docs.pages.dev
Branch Preview URL: https://fix-retrieve-tools-empty-nul.mcpproxy-docs.pages.dev

View logs

@codecov-commenter

codecov-commenter commented Aug 5, 2026

Copy link
Copy Markdown

⚠️ Please install the 'codecov app svg image' to ensure uploads and comments are reliably processed by Codecov.

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

@github-actions

github-actions Bot commented Aug 5, 2026

Copy link
Copy Markdown

📦 Build Artifacts

Workflow Run: View Run
Branch: fix/retrieve-tools-empty-null

Available Artifacts

  • archive-darwin-amd64 (28 MB)
  • archive-darwin-arm64 (26 MB)
  • archive-linux-amd64 (17 MB)
  • archive-linux-arm64 (15 MB)
  • archive-windows-amd64 (28 MB)
  • archive-windows-arm64 (25 MB)
  • frontend-dist-pr (0 MB)
  • installer-dmg-darwin-amd64 (22 MB)
  • installer-dmg-darwin-arm64 (20 MB)

How to Download

Option 1: GitHub Web UI (easiest)

  1. Go to the workflow run page linked above
  2. Scroll to the bottom "Artifacts" section
  3. Click on the artifact you want to download

Option 2: GitHub CLI

gh run download 30982119172 --repo smart-mcp-proxy/mcpproxy-go

Note: Artifacts expire in 14 days.

Cross-model review found sibling sites with the same nil-slice defect as
issue #953: read_cache.records, quarantine_security servers,
inspect_quarantined tools, search_servers servers, and
retrieve_tools usage_summary.top_tools. All now serialize as [] when
empty. The spec-085 golden fixture is updated for the intentional
top_tools change (null -> []); the retrieve_tools regression test now
asserts the wire type via json.RawMessage instead of substring matching.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01W2f2uxUUtENehyZoiVLQKN

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cross-model review (opencode/gpt-5.6-sol) round 2: CLEAN. Local API E2E 65/65 at head; race suite green on all touched packages.

@github-actions
github-actions Bot merged commit 0cb5f66 into main Aug 5, 2026
39 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.

retrieve_tools returns "tools": null instead of [] on empty search — breaks strict MCP clients

2 participants