fix(mcp): only advertise list-resource meta-tools when resources exist#3963
Open
h3c-hexin wants to merge 1 commit into
Open
fix(mcp): only advertise list-resource meta-tools when resources exist#3963h3c-hexin wants to merge 1 commit into
h3c-hexin wants to merge 1 commit into
Conversation
`list_mcp_resources` and `list_mcp_resource_templates` were injected whenever any MCP server was configured, regardless of whether any server actually exposes resources or templates. For tools-only servers this leaves the model with meta-tools that can only ever return empty results, wasting a tool slot and prompt tokens on every request. Gate each meta-tool on its own non-empty collection, mirroring the existing `mcp_read_resource` guard.
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.
Problem
list_mcp_resourcesandlist_mcp_resource_templatesare injected into the model-visible tool catalog whenever any MCP server is configured (!self.config.servers.is_empty()), regardless of whether the configured servers actually expose any resources or resource templates.For tools-only MCP servers — common in practice, e.g. a server that only implements
tools/list+tools/calland returns-32601 method not foundforresources/list— this means the model is permanently offered two meta-tools that can only ever return empty results. That wastes a tool slot and prompt tokens on every request, and can nudge smaller models into calling a no-op tool.Fix
Gate each meta-tool on its own non-empty collection (
all_resources()/all_resource_templates()), mirroring the existingmcp_read_resourceguard immediately below (!resources.is_empty()). Servers that do expose resources / templates are unaffected; tools-only servers simply no longer get the empty meta-tools.Notes
defer_loadingcatalog tests constructlist_mcp_resourcesdirectly viaapi_tool(...), andMcpPool::is_mcp_tool(...)classification is independent of injection.cargo check -p codewhale-tuipasses.