Skip to content

Commit e089ed1

Browse files
fix(mcp): port upstream auth status scoping to configured server URL (anomalyco/opencode#33924)
1 parent 11bfb29 commit e089ed1

2 files changed

Lines changed: 31 additions & 1 deletion

File tree

‎packages/opencode/src/mcp/index.ts‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1648,7 +1648,11 @@ export const layer = Layer.effect(
16481648
})
16491649

16501650
const getAuthStatus = Effect.fn("MCP.getAuthStatus")(function* (mcpName: string) {
1651-
const entry = yield* auth.get(mcpName)
1651+
// altimate_change start — upstream_fix: only credentials stored for the configured server URL count (anomalyco/opencode#33924)
1652+
const mcpConfig = yield* getMcpConfig(mcpName)
1653+
if (!mcpConfig || mcpConfig.type !== "remote") return "not_authenticated"
1654+
const entry = yield* auth.getForUrl(mcpName, mcpConfig.url)
1655+
// altimate_change end
16521656
if (!entry?.tokens) return "not_authenticated"
16531657
const expired = yield* auth.isTokenExpired(mcpName)
16541658
return expired ? "expired" : "authenticated"

‎packages/opencode/test/mcp/oauth-auto-connect.test.ts‎

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -222,6 +222,32 @@ mcpTest.instance(
222222
{ config: config("test-oauth") },
223223
)
224224

225+
// altimate_change start — upstream_fix: auth status scoped to the configured server URL (anomalyco/opencode#33924)
226+
mcpTest.instance(
227+
"auth status only reports credentials stored for the configured server URL",
228+
() =>
229+
Effect.gen(function* () {
230+
const mcp = yield* MCP.Service
231+
const auth = yield* McpAuth.Service
232+
233+
yield* auth.updateTokens("test-status-url", { accessToken: "legacy-token" })
234+
expect(yield* mcp.getAuthStatus("test-status-url")).toBe("not_authenticated")
235+
236+
yield* auth.updateTokens("test-status-url", { accessToken: "old-token" }, "https://old.example.com/mcp")
237+
expect(yield* mcp.getAuthStatus("test-status-url")).toBe("not_authenticated")
238+
239+
yield* auth.updateTokens("test-status-url", { accessToken: "current-token" }, "https://example.com/mcp")
240+
expect(yield* mcp.getAuthStatus("test-status-url")).toBe("authenticated")
241+
242+
yield* auth.updateTokens("test-status-url", { accessToken: "expired-token", expiresAt: 1 }, "https://example.com/mcp")
243+
expect(yield* mcp.getAuthStatus("test-status-url")).toBe("expired")
244+
245+
expect(yield* mcp.getAuthStatus("not-configured")).toBe("not_authenticated")
246+
}),
247+
{ config: config("test-status-url") },
248+
)
249+
// altimate_change end
250+
225251
mcpTest.instance("state() generates a new state when none is saved", () =>
226252
Effect.gen(function* () {
227253
const auth = yield* McpAuth.Service

0 commit comments

Comments
 (0)