Repository navigation
fix: keep canAccess tools visible to sessions without auth after a runtime change - #389
Merged
Merged
Conversation
…ntime change Session creation only consults `canAccess` when the session has an auth object: with no `authenticate` configured, or none passed to `connect()`, every tool is visible, which is what the "canAccess works without authentication" test and the README examples rely on. `FastMCPSession.toolsListChanged()` did not apply that rule. It called `canAccess(undefined)` on every tool, so after any runtime `addTool()` or `removeTool()` a tool such as `canAccess: (auth) => auth?.role === "admin"` disappeared from `tools/list` for unauthenticated sessions, and a `canAccess` written without optional chaining threw a TypeError out of `addTool()`, skipping the refresh for every later session. Use the same rule as `#createSession`: filter with `canAccess` only when the session has auth.
Contributor
Author
|
The OpenAPI (network) failure here is the Stripe spec hash drift ( |
|
🎉 This PR is included in version 4.20.17 🎉 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.
Problem
Session creation only consults
canAccesswhen the session has an auth object. With noauthenticateconfigured (or none passed toconnect()), every tool is visible; the existing test "canAccess works without authentication" and the README examplecanAccess: (auth) => auth?.role === "admin"rely on that.FastMCPSession.toolsListChanged()did not apply the same rule. It calledcanAccess(undefined)on every tool, so:addTool()/removeTool(), a tool withcanAccess: (auth) => auth?.role === "admin"disappeared fromtools/listfor unauthenticated sessions, andtools/callon it answered "Unknown tool";canAccesswritten without optional chaining (auth => auth.role === "admin") threw aTypeErrorout ofserver.addTool(), after#toolshad already been updated, and skipped the refresh for every later session in the loop.Repro:
Fix
toolsListChanged()now uses the same rule as#createSession: filter withcanAccessonly when the session has auth.Tests
Two cases added to
src/FastMCP.can-access-empty.test.ts(in-memory transport, no auth): the admin-only tool stays listed and callable after a runtimeaddTool(), and anaddTool()with acanAccessthat dereferencesauthdoes not throw. Both fail onmainand pass with this change.prettier,eslintandtsc --noEmitare clean.