Skip to content
This repository was archived by the owner on May 15, 2026. It is now read-only.

Commit 1f8209a

Browse files
committed
refactor(McpOAuthClientProvider): add TOKEN_EXPIRY_BUFFER
1 parent 5aeed4f commit 1f8209a

3 files changed

Lines changed: 4 additions & 5 deletions

File tree

src/services/mcp/McpHub.ts

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ import { GlobalFileNames } from "../../shared/globalFileNames"
3636
import { UnauthorizedError } from "@modelcontextprotocol/sdk/client/auth.js"
3737

3838
import { fileExistsAtPath } from "../../utils/fs"
39+
import { TOKEN_EXPIRY_BUFFER_MS } from "./constants"
3940
import { SecretStorageService } from "./SecretStorageService"
4041
import { McpOAuthClientProvider } from "./McpOAuthClientProvider"
4142
import { arePathsEqual, getWorkspacePath } from "../../utils/path"
@@ -1053,8 +1054,6 @@ export class McpHub {
10531054
return
10541055
}
10551056

1056-
const TOKEN_EXPIRY_BUFFER_MS = 5 * 60 * 1000
1057-
10581057
// Check if another window already saved valid tokens
10591058
const existing = await this.secretStorage.getOAuthData(serverUrl)
10601059
if (existing && Date.now() < existing.expires_at - TOKEN_EXPIRY_BUFFER_MS) {
@@ -1163,8 +1162,6 @@ export class McpHub {
11631162
this._oauthWatchers.delete(watcherKey)
11641163
}
11651164

1166-
const TOKEN_EXPIRY_BUFFER_MS = 5 * 60 * 1000
1167-
11681165
// Called when SecretStorage fires onDidChange for this server's key.
11691166
// Runs in all VS Code windows the instant tokens are saved — no polling delay.
11701167
const onTokensChanged = async () => {

src/services/mcp/McpOAuthClientProvider.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import type {
99
OAuthTokens,
1010
} from "@modelcontextprotocol/sdk/shared/auth.js"
1111

12+
import { TOKEN_EXPIRY_BUFFER_MS } from "./constants"
1213
import { SecretStorageService } from "./SecretStorageService"
1314
import { startCallbackServer, stopCallbackServer } from "./utils/callbackServer"
1415
import { fetchOAuthAuthServerMetadata } from "./utils/oauth"
@@ -265,7 +266,7 @@ export class McpOAuthClientProvider implements OAuthClientProvider {
265266
if (!data) return undefined
266267

267268
// If the access token is still valid (with 5m buffer), return it.
268-
if (Date.now() < data.expires_at - 5 * 60 * 1000) {
269+
if (Date.now() < data.expires_at - TOKEN_EXPIRY_BUFFER_MS) {
269270
return data.tokens
270271
}
271272

src/services/mcp/constants.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export const TOKEN_EXPIRY_BUFFER_MS = 5 * 60 * 1000 // 5 minutes

0 commit comments

Comments
 (0)