Table of Contents

Interface ITokenCache

Namespace
ModelContextProtocol.Authentication
Assembly
ModelContextProtocol.Core.dll

Allows the client to cache access tokens beyond the lifetime of the transport.

public interface ITokenCache

Remarks

Implementations must be safe for concurrent use. A single cache instance may be shared by multiple in-flight requests, and GetTokensAsync(CancellationToken) in particular can be invoked concurrently (it is called on the request hot path without holding the provider's token-acquisition lock).

Methods

GetTokensAsync(CancellationToken)

Get the cached token. This method is invoked for every request.

ValueTask<TokenContainer?> GetTokensAsync(CancellationToken cancellationToken)

Parameters

cancellationToken CancellationToken

Returns

ValueTask<TokenContainer>

StoreTokensAsync(TokenContainer, CancellationToken)

Cache the token. After a new access token is acquired, this method is invoked to store it.

ValueTask StoreTokensAsync(TokenContainer tokens, CancellationToken cancellationToken)

Parameters

tokens TokenContainer
cancellationToken CancellationToken

Returns

ValueTask