Authentication

Token Expiration

Fixed lifetime policies, MongoDB TTL cleanup indexes, and token refresh handling across OAuth grants, scoped PATs, and setup previews.

Credential & State Lifetime Table

Every credential, authorization artifact, and pending setup plan stored in taicket_mcp has a bounded, non-infinite expiration timestamp enforced both in application checks and via MongoDB TTL indexes.

ArtifactCollectionLifetime (TTL)Notes
OAuth Access Tokenmcp_access_tokens1 hour (3,600s)Short-lived bearer credential bound to https://mcp.taicket.xyz/mcp
OAuth Refresh Tokenmcp_refresh_tokens30 daysSingle-use rotating token; replay revokes entire familyId
Authorization Codemcp_oauth_codes60 secondsSingle-use code bound to PKCE challenge and redirect_uri
OAuth Transactionmcp_oauth_transactions10 minutesPending browser handshake between /oauth/authorize and /oauth/consent
Setup Preview Planmcp_setup_previews15 minutesDry-run planId and human browser approval window at /oauth/approve-action
Scoped PAT (tmcp_...)mcp_access_tokens7, 30, or 90 daysUser selects expiry on creation; infinite PATs are prohibited

Client Refresh Strategy

OAuth 2.1 MCP clients should refresh access tokens proactively 60 to 120 seconds prior to expires_in or immediately upon receiving HTTP 401 with error="invalid_token". Serialize concurrent refresh calls per grant so two parallel requests never submit the same rotating refresh token.

Single-flight refresh guard for MCP clientstypescript
let inflightRefresh: Promise<TokenBundle> | null = null;

export async function refreshAccessTokenOnce(
  tokenEndpoint: string,
  clientId: string,
  refreshToken: string
): Promise<TokenBundle> {
  if (inflightRefresh) {
    return inflightRefresh;
  }

  inflightRefresh = fetch(tokenEndpoint, {
    method: 'POST',
    headers: { 'Content-Type': 'application/x-www-form-urlencoded' },
    body: new URLSearchParams({
      grant_type: 'refresh_token',
      refresh_token: refreshToken,
      client_id: clientId,
      resource: 'https://mcp.taicket.xyz/mcp',
    }),
  })
    .then(async (res) => {
      if (!res.ok) {
        throw new Error(`Token refresh failed with HTTP ${res.status}`);
      }
      return (await res.json()) as TokenBundle;
    })
    .finally(() => {
      inflightRefresh = null;
    });

  return inflightRefresh;
}

Avoid concurrent refresh races

Because refresh tokens rotate atomically, firing two parallel refresh requests with the same refresh_token triggers replay detection and revokes the entire grant family. Always coalesce refreshes behind a single-flight lock.

Scoped PAT Rotation & Renewal

Scoped Personal Access Tokens created in https://mcp.taicket.xyz/account do not issue refresh tokens and cannot be extended past their chosen 7, 30, or 90 day lifetime. To rotate a PAT with zero downtime, generate a replacement token in /account, update your MCP client configuration, and immediately revoke the previous token.

Related documentation