How token caching works in the MCP server
mainWhen using the client credentials flow, the MCP server automatically manages token lifecycle through caching to minimize redundant authentication requests.
Caching Logic:
- Tokens are cached for their lifetime as defined by the
expires_inparameter in the OAuth token response. - A 60-second safety margin is subtracted from the lifetime to prevent using an expired token.
Request Workflow:
- The server checks for a valid, non-expired cached token.
- If a valid token exists, it is used for the API request.
- If no valid cached token is found, the server requests a new token before proceeding with the API call.