Repository navigation
Description
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 onlyself.fastmcp.get_tool(tool_name, version). Core routing (server.py:1453-1461) retries a failed display-name lookup throughparse_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 onlyget_resourceandget_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
fix(auth): authorize hashed app-tool names and synthesized Prefab res…