Fix versioned auth middleware checks - #4401
Conversation
There was a problem hiding this comment.
馃挕 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 840374e1ad
鈩癸笍 About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 馃憤.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| if version is None or version.eq is None: | ||
| return None |
There was a problem hiding this comment.
Preserve range version specs in auth metadata
When callers use the public server API with a non-exact VersionSpec such as VersionSpec(lt="2.0"), this branch drops the version metadata, so AuthMiddleware authorizes the default/highest component while execution still uses the original range. In a server with public calc@2.0 and admin-tagged calc@1.0, await mcp.call_tool("calc", {}, version=VersionSpec(lt="2.0")) runs the restricted v1 after checking v2. The synthetic middleware request needs to carry the full VersionSpec, or auth needs another way to use the same spec as execution.
Useful? React with 馃憤聽/ 馃憥.
There was a problem hiding this comment.
馃挕 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 840374e1ad
鈩癸笍 About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 馃憤.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| if version is None or version.eq is None: | ||
| return None |
There was a problem hiding this comment.
Preserve non-exact version specs for auth
When a direct server caller passes a range such as VersionSpec(lt="2.0"), this helper drops the version metadata entirely, so AuthMiddleware authorizes the default/highest component while the subsequent call_next still executes with the original range. In a server with public calc@2.0 and admin-tagged calc@1.0, await mcp.call_tool("calc", {}, version=VersionSpec(lt="2.0")) authorizes against 2.0 but runs 1.0, leaving the versioned auth bypass in place for range specs.
Useful? React with 馃憤聽/ 馃憥.
FastMCP carries requested component versions in
_meta.fastmcp.version, but direct server execution rebuilds the middleware request params before authorization runs. That meant middleware could resolve a same-named component without the version metadata that execution would later use. This preserves FastMCP version metadata on synthetictools/call,resources/read, andprompts/getparams, then hasAuthMiddlewareauthorize the same versioned component that will execute.The request metadata now remains visible through middleware, so the auth check and execution both resolve
calc@1.0instead of evaluating different versions of the same component.