Handling OAuth2 Authentication
When an LLM uses an OAuth2-secured service (like Google Workspace, Slack, GitHub or a remote MCP server), HasMCP manages the whole OAuth2 lifecycle so that neither the LLM nor the MCP client ever handles a token.Connecting an Account
There are two ways to connect:- Ahead of time. Click Connect Account on a remote MCP provider’s page, or on a server’s Configuration tab under Remote MCP Credentials to connect for that server only.
- When a tool needs it. If a required token is missing or can’t be renewed when the LLM calls a tool, HasMCP returns a URL elicitation. The MCP client shows the user a sign-in link.
- Authorization. The user signs in on the provider and approves the scopes the server’s tools need. For remote MCP servers, HasMCP discovers the authorization server and registers its own OAuth2 client automatically, and uses PKCE.
- Token capture. HasMCP receives the redirect and exchanges the code for an access token and a refresh token.
- Storage. The tokens are encrypted and saved as
SECRETvariables (<SECRET_PREFIX>_ACCESS_TOKENand<SECRET_PREFIX>_REFRESH_TOKEN). Tokens connected for a server are saved for that server only. See Per-Server Variables & Credentials. - Resume. The client retries the tool call, which now finds the token.
Automated Refresh
Access tokens typically expire after an hour. HasMCP renews them automatically:- about 5 minutes before they expire, with the refresh token;
- once more, with a retry, if the API rejects a token with
401; - saving rotated refresh tokens, and dropping refresh tokens the authorization server rejects.