Skip to content

[Bug] AuthMiddleware denies hashed FastMCPApp backend tool calls and synthesized Prefab resources #5840

Closed

Description

@BlueX888

Summary

With a server-wide AuthMiddleware, every FastMCPApp backend tool invoked by the hashed backend name that FastMCP serializes into the Prefab payload (<hash>_<local_name>) is rejected with Authorization failed for tool '<hash>_<local_name>': not found or not authorized, even when the caller's token satisfies the required scopes. The same tool invoked by its display name succeeds. docs/apps/architecture.mdx:98 says: "Transforms, enabled state, and authorization apply to a hashed name exactly as they do to a name call."

The same gap makes synthesized Prefab renderer resources listed but unreadable: ui://prefab/tool/<hash>/renderer.html is advertised by list_resources, then every read fails authorization under AuthMiddleware.

Reproduction (current main adf90b6, offline)

from fastmcp import FastMCP, Client
from fastmcp.server.middleware.authorization import AuthMiddleware, require_scopes
# FastMCPApp backend tool `save`, token granting the required scope
mcp.add_middleware(AuthMiddleware(require_scopes("test")))

Observed with a valid token:

hashed backend name: 10c0803009ff_save
[by display name] OK: 'saved alice'
[by hashed name] AuthorizationError: Authorization failed for tool '10c0803009ff_save': not found or not authorized
[listed prefab renderer] ui://prefab/tool/e7e8170316cc/renderer.html
[read prefab renderer] AuthorizationError: Authorization failed for resource 'ui://prefab/tool/e7e8170316cc/renderer.html': not found or not authorized

Expected: the hashed-name call executes the tool body and the synthesized renderer is readable when the token carries the scope.

Root cause

  • fastmcp_slim/fastmcp/server/middleware/authorization.py:229 (on_call_tool) resolves only self.fastmcp.get_tool(tool_name, version). Core routing (server.py:1453-1461) retries a failed display-name lookup through parse_hashed_backend_name + get_tool_by_hash. The middleware lacks that fallback, so every hashed-name call is denied before reaching core.
  • authorization.py:312-317 (on_read_resource) checks only get_resource and get_resource_template. Per-tool Prefab renderer resources are synthesized on demand in core (server.py:1592-1599), so the middleware cannot resolve them and denies a listed resource.

Suggested fix

In on_call_tool, when get_tool returns None, parse the hashed backend name with the same helper core uses and retry get_tool_by_hash; deny only if both lookups fail. get_tool_by_hash already applies transforms, visibility, enabled state, and component auth, so refusals must stay refusals. In on_read_resource, fall back to synthesize_prefab_resource_by_uri when the stored-resource and template lookups miss, and authorize against the synthesized component.

Tests

A fix with seven regression tests is ready: hashed-name call with sufficient scope executes, insufficient scope raises InsufficientScopeError, component-auth denial, transform-refused tool stays denied, display-name behavior unchanged, and synthesized renderer allowed/denied. I'll open the linked PR with red/green evidence.

Activity

  1. added
    authRelated to authentication (Bearer, JWT, OAuth, WorkOS) for client or server.
    bugSomething isn't working. Reports of errors, unexpected behavior, or broken functionality.
    mcp appsRelated to MCP Apps - user-facing applications with frontend bundles served by MCP servers.
    on Oct 19, 2026
  2. added a commit that references this issue on Nov 10, 2026
    ad5092a
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    authRelated to authentication (Bearer, JWT, OAuth, WorkOS) for client or server.bugSomething isn't working. Reports of errors, unexpected behavior, or broken functionality.mcp appsRelated to MCP Apps - user-facing applications with frontend bundles served by MCP servers.

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions