-
Notifications
You must be signed in to change notification settings - Fork 58
Closed
Description
I have installed the dev-main because of middlware function, because we need auth in order to change the tools response.
Using StreamableHttpServerTransport with PSR-7 middleware that sets:
class AuthMiddleware
{
public function __invoke(ServerRequestInterface $request, callable $next)
{
// here how can i access this user_id inside a tool?
$request = $request->withAttribute('user_id', $mySuperDuperUserId);
$result = $next($request);
return match (true) {
$result instanceof PromiseInterface => $result->then(fn($response) => $this->handle($response)),
$result instanceof ResponseInterface => $this->handle($result),
default => $result
};
}What’s the supported approach to read this user_id inside a Tool handler?
Constraints
- (a) Constructor/DI injection won’t work because the PSR-7 request is per-request and can’t be bound at configuration time.
- (b) Adding a
ServerRequestInterfaceparameter to the handler also won’t work because it becomes part of the Tool’s schema (clients would have to pass it).
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels