OptionalonCalled when the server responds with 401. If provided, the transport will
await this, then retry the request once. If the retry also gets 401, or if
this method is not provided, the transport throws UnauthorizedError.
Implementations should refresh tokens, re-authenticate, etc. — whatever is
needed so the next token() call returns a valid token.
Returns the current bearer token, or undefined if no token is available.
Called before every request.
Minimal interface for authenticating MCP client transports with bearer tokens.
Transports call
token()before every request to obtain the current token, andonUnauthorized()(if provided) when the server responds with 401, giving the provider a chance to refresh credentials before the transport retries once.For simple cases (API keys, gateway-managed tokens), implement only
token():For OAuth flows, pass an
OAuthClientProviderdirectly — transports accept either shape and adapt OAuth providers automatically viaadaptOAuthProvider.