fix(mcp): scope auth status to server URL (#33924)
This commit is contained in:
@@ -50,7 +50,6 @@ export interface Interface {
|
||||
readonly updateOAuthState: (mcpName: string, oauthState: string) => Effect.Effect<void>
|
||||
readonly getOAuthState: (mcpName: string) => Effect.Effect<string | undefined>
|
||||
readonly clearOAuthState: (mcpName: string) => Effect.Effect<void>
|
||||
readonly isTokenExpired: (mcpName: string) => Effect.Effect<boolean | null>
|
||||
}
|
||||
|
||||
export class Service extends Context.Service<Service, Interface>()("@opencode/McpAuth") {}
|
||||
@@ -142,13 +141,6 @@ export const layer = Layer.effect(
|
||||
return entry?.oauthState
|
||||
})
|
||||
|
||||
const isTokenExpired = Effect.fn("McpAuth.isTokenExpired")(function* (mcpName: string) {
|
||||
const entry = yield* get(mcpName)
|
||||
if (!entry?.tokens) return null
|
||||
if (!entry.tokens.expiresAt) return false
|
||||
return entry.tokens.expiresAt < Date.now() / 1000
|
||||
})
|
||||
|
||||
return Service.of({
|
||||
all,
|
||||
get,
|
||||
@@ -162,7 +154,6 @@ export const layer = Layer.effect(
|
||||
updateOAuthState,
|
||||
getOAuthState,
|
||||
clearOAuthState,
|
||||
isTokenExpired,
|
||||
})
|
||||
}),
|
||||
)
|
||||
|
||||
@@ -963,10 +963,15 @@ export const layer = Layer.effect(
|
||||
})
|
||||
|
||||
const getAuthStatus = Effect.fn("MCP.getAuthStatus")(function* (mcpName: string) {
|
||||
const entry = yield* auth.get(mcpName)
|
||||
const runtimeConfig = (yield* InstanceState.has(state))
|
||||
? (yield* InstanceState.get(state)).config[mcpName]
|
||||
: undefined
|
||||
const mcpConfig = runtimeConfig ?? (yield* cfgSvc.get()).mcp?.[mcpName]
|
||||
if (!mcpConfig || !isMcpConfigured(mcpConfig) || mcpConfig.type !== "remote") return "not_authenticated"
|
||||
const entry = yield* auth.getForUrl(mcpName, mcpConfig.url)
|
||||
if (!entry?.tokens) return "not_authenticated"
|
||||
const expired = yield* auth.isTokenExpired(mcpName)
|
||||
return expired ? "expired" : "authenticated"
|
||||
if (entry.tokens.expiresAt && entry.tokens.expiresAt < Date.now() / 1000) return "expired"
|
||||
return "authenticated"
|
||||
})
|
||||
|
||||
return Service.of({
|
||||
|
||||
Reference in New Issue
Block a user