Skip to content

fix(mcp): only advertise list-resource meta-tools when resources exist#3963

Open
h3c-hexin wants to merge 1 commit into
Hmbown:mainfrom
h3c-hexin:fix/list-mcp-resources-empty-gate
Open

fix(mcp): only advertise list-resource meta-tools when resources exist#3963
h3c-hexin wants to merge 1 commit into
Hmbown:mainfrom
h3c-hexin:fix/list-mcp-resources-empty-gate

Conversation

@h3c-hexin

Copy link
Copy Markdown
Contributor

Problem

list_mcp_resources and list_mcp_resource_templates are 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/call and returns -32601 method not found for resources/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 existing mcp_read_resource guard 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

  • No behavior change for servers that expose resources or templates.
  • Existing tests unaffected: the defer_loading catalog tests construct list_mcp_resources directly via api_tool(...), and McpPool::is_mcp_tool(...) classification is independent of injection.
  • cargo check -p codewhale-tui passes.

`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.
@h3c-hexin h3c-hexin requested a review from Hmbown as a code owner July 3, 2026 07:32
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.

1 participant