fix: keep the tools capability when canAccess hides every tool - #371
Merged
punkpeye merged 1 commit intoSep 11, 2026
Merged
Conversation
A session declared the tools capability and registered the tools/list and tools/call handlers only when its own, already canAccess-filtered tool list was non-empty. A server that has tools but shows none of them to one session therefore did not declare the capability for it: tools/list answered -32601 instead of an empty list, and addTool() threw "Server does not support tools" while such a session was connected. The capability describes the server, not the session. Pass whether the server has any tools alongside the filtered list, and gate the capability and the handlers on that. The handlers work on the filtered list as before, so a session that may not see a tool still cannot list or call it. Fixes punkpeye#370
|
🎉 This PR is included in version 4.20.10 🎉 The release is available on: Your semantic-release bot 📦🚀 |
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
Fixes #370.
FastMCPSessiondeclared thetoolscapability and registered thetools/list/tools/callhandlers only when its own tool list was non-empty. That list is alreadycanAccess-filtered by#createSession, so a server that has tools but shows none of them to one session did not declare the capability for that session. The spec requires it ("Servers that support tools MUST declare the tools capability"), and two things broke:tools/listanswered-32601 Method not foundinstead of an empty list, so a client could not tell a tool-less server from one whose tools it may not see;addTool()threwServer does not support tools (required for tools/list)while such a session was connected, becausetoolsListChanged→setupToolHandlersregisters a handler for a capability that session never declared.Same class as #208/#209 (completions) and #327 (resource templates): a handler gated on the filtered/derived list instead of on what the server supports.
Change
src/FastMCP.tsFastMCPSessiontakes an optionalhasTools("the server has tools, including ones this session'scanAccessfiltering removed"), defaulting totools.length > 0so every other caller is unchanged.setupToolHandlersstill receives the filtered list, so a session that may not see a tool cannot list or call it (an empty list, andUnknown toolon call).#createSessionpasseshasTools: this.#tools.length > 0. The stdio path passes the unfiltered list already.A server without any tools still does not advertise the capability.
Tests
src/FastMCP.can-access-empty.test.ts: arole: usersession on a server with one admin-only tool gets thetoolscapability and an emptytools/list;addTool()no longer throws while that session is connected and the new public tool shows up on the next list; an admin session still sees the tool; a tool-less server still advertises nothing. The first two fail onmain.