You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
McpServer: middleware and visibility can't use per-request services from HttpRouter middleware under layerHttp #9854
On v4/next-minor (pkg.pr.new 7ce7d03), tools can depend on per-request services provided by HttpRouter middleware: layerHttp converts the remaining McpRequest.From<"Requires", R> into HttpRouter.Request.From<"Requires", R>. MCP middleware and visibility checks can't. MiddlewareLayer turns any requirement outside TransportServices into MissingRequestDependencies, so it can only be satisfied by .combine or the transport.
classCurrentUserextendsContext.Service<CurrentUser,{readonlyid: number}>()("CurrentUser"){}// HTTP auth stays at the HTTP layer: OAuth discovery and refresh need a 401 with WWW-Authenticate,// and MCP middleware never runs for initialize/pingconstAuth=HttpRouter.middleware<{provides: CurrentUser}>()(/* bearer token -> user */)constPolicy=McpServer.visibility(Effect.succeed(({ target })=>Effect.gen(function*(){constuser=yield*CurrentUserreturncanUse(user,target)})))Policy.layer// ^? MissingRequestDependencies<CurrentUser>, although Auth provides CurrentUser to every request under layerHttp
The workaround is an MCP middleware that re-provides what is already on the fiber:
Doing the authentication itself in a combined MCP middleware would mean resolving the token and user a second time on every request.
Proposal
Drop the conditional and always put the per-request requirements in the layer input, as registrations already do. layerHttp then forwards them to HttpRouter, while layer / layerStdio still surface them as unmet requirements:
The runtime already handles this. With only the .d.ts patched and the bridge removed, through layerHttp + HttpRouter.toWebHandler:
tools/list hides the tool the policy rejects
the visible tool receives CurrentUser
calling the hidden tool returns -32602 Tool '…' not found
Trade-off: an unmet requirement then shows up as a missing layer requirement at the server instead of the named MissingRequestDependencies at .layer. Happy to open a PR if this direction is fine.
Activity