fix(mcp): serialize empty retrieve_tools result as [] instead of null - #954
Merged
Conversation
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
Deploying mcpproxy-docs with
|
| 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 |
|
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
📦 Build ArtifactsWorkflow Run: View Run Available Artifacts
How to DownloadOption 1: GitHub Web UI (easiest)
Option 2: GitHub CLI gh run download 30982119172 --repo smart-mcp-proxy/mcpproxy-go
|
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
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.
Summary
retrieve_toolsreturned"tools": nullwhen a search matched nothing, because the tools slice was a nil slice (var mcpTools []map[string]interface{}) and Go marshals nil slices asnull. Strict MCP clients that iterate the array crash ('NoneType' object is not iterable).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
TestRetrieveTools_EmptyResultSerializesEmptyArray— verified RED ("tools":nullin 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