fix(opencode): respect MCP server capabilities (#31271)

This commit is contained in:
Aiden Cline
2026-06-07 21:24:41 -05:00
committed by GitHub
parent 4d09a71ef4
commit b5cb9aae7f
4 changed files with 151 additions and 5 deletions
@@ -21,6 +21,8 @@ const transportCalls: Array<{
// auth flow (which calls provider.state()) or a simple UnauthorizedError.
let simulateAuthFlow = true
let connectSucceedsImmediately = false
let serverCapabilities: { tools?: object; resources?: object } = { tools: {} }
let listToolsCalls = 0
// Mock the transport constructors to simulate OAuth auto-auth on 401
void mock.module("@modelcontextprotocol/sdk/client/streamableHttp.js", () => ({
@@ -91,10 +93,19 @@ void mock.module("@modelcontextprotocol/sdk/client/index.js", () => ({
setNotificationHandler() {}
getServerCapabilities() {
return serverCapabilities
}
async listTools() {
listToolsCalls++
return { tools: [{ name: "test_tool", inputSchema: { type: "object", properties: {} } }] }
}
async listResources() {
return { resources: [{ name: "docs", uri: "docs://readme" }] }
}
async close() {}
},
}))
@@ -108,6 +119,8 @@ beforeEach(() => {
transportCalls.length = 0
simulateAuthFlow = true
connectSucceedsImmediately = false
serverCapabilities = { tools: {} }
listToolsCalls = 0
})
// Import modules after mocking
@@ -234,3 +247,28 @@ mcpTest.instance(
),
{ config: config("test-oauth-connect") },
)
mcpTest.instance(
"authenticate() connects a resource-only server without listing tools",
() =>
MCP.Service.use((mcp) =>
Effect.gen(function* () {
const added = yield* mcp.add("test-oauth-resources", {
type: "remote",
url: "https://example.com/mcp",
})
const before = added.status as Record<string, { status: string }>
expect(before["test-oauth-resources"]?.status).toBe("needs_auth")
simulateAuthFlow = false
connectSucceedsImmediately = true
serverCapabilities = { resources: {} }
const result = yield* mcp.authenticate("test-oauth-resources")
expect(result.status).toBe("connected")
expect(listToolsCalls).toBe(0)
expect(Object.keys(yield* mcp.resources())).toEqual(["test-oauth-resources:docs"])
}),
),
{ config: config("test-oauth-resources") },
)