+21

![opencode-agent[bot] <219766164+opencode-agent[bot]@users.noreply.github.com>](/assets/img/avatar_default.png)



![opencode-agent[bot] <opencode-agent[bot]@users.noreply.github.com>](/assets/img/avatar_default.png)



James Long
Brendan Allan
Kit Langton
opencode-agent[bot] <opencode-agent[bot]@users.noreply.github.com>
Affan Ali
affanali2k3
Frank
opencode-agent[bot] <219766164+opencode-agent[bot]@users.noreply.github.com>
𝓛𝓲𝓽𝓽𝓵𝓮 𝓕𝓻𝓪𝓷𝓴
Aiden Cline
Jay V
Dax Raad
Aarav Sareen
OpeOginni
Luke Parker
Ben Guthrie
Dax
Filip
Max Anderson
Brendan Allan
Jack
Shoubhit Dash
Dustin Deus
starptech
Aiden Cline
usrnk1
Jay
runvip
opencode
Julian Coy
Vladimir Glafirov
8c94e9005f
Co-authored-by: Brendan Allan <14191578+Brendonovich@users.noreply.github.com> Co-authored-by: Kit Langton <kit.langton@gmail.com> Co-authored-by: opencode-agent[bot] <opencode-agent[bot]@users.noreply.github.com> Co-authored-by: Affan Ali <93028901+affanali2k3@users.noreply.github.com> Co-authored-by: affanali2k3 <affanalikhanxx@gmail.com> Co-authored-by: Frank <frank@anoma.ly> Co-authored-by: opencode-agent[bot] <219766164+opencode-agent[bot]@users.noreply.github.com> Co-authored-by: 𝓛𝓲𝓽𝓽𝓵𝓮 𝓕𝓻𝓪𝓷𝓴 <little-frank@opencord.local> Co-authored-by: Aiden Cline <63023139+rekram1-node@users.noreply.github.com> Co-authored-by: Jay V <air@live.ca> Co-authored-by: Dax Raad <d@ironbay.co> Co-authored-by: Aarav Sareen <96787824+arvsrn@users.noreply.github.com> Co-authored-by: OpeOginni <107570612+OpeOginni@users.noreply.github.com> Co-authored-by: Luke Parker <10430890+Hona@users.noreply.github.com> Co-authored-by: Ben Guthrie <benjee.012@gmail.com> Co-authored-by: Dax <mail@thdxr.com> Co-authored-by: Filip <34747899+neriousy@users.noreply.github.com> Co-authored-by: Max Anderson <max.a.anderson95@gmail.com> Co-authored-by: Brendan Allan <git@brendonovich.dev> Co-authored-by: Jack <jack@anoma.ly> Co-authored-by: Shoubhit Dash <shoubhit2005@gmail.com> Co-authored-by: Dustin Deus <deusdustin@gmail.com> Co-authored-by: starptech <starptech@starptechs-MBP.fritz.box> Co-authored-by: Aiden Cline <aidenpcline@gmail.com> Co-authored-by: usrnk1 <7547651+usrnk1@users.noreply.github.com> Co-authored-by: Jay <53023+jayair@users.noreply.github.com> Co-authored-by: runvip <164729189+runvip@users.noreply.github.com> Co-authored-by: opencode <opencode@sst.dev> Co-authored-by: Julian Coy <julian@ex-machina.co> Co-authored-by: Vladimir Glafirov <vglafirov@gitlab.com>
128 lines
3.9 KiB
TypeScript
128 lines
3.9 KiB
TypeScript
import { describe, expect, mock, beforeEach } from "bun:test"
|
|
import { LayerNode } from "@opencode-ai/core/effect/layer-node"
|
|
import { Effect } from "effect"
|
|
import { testEffect } from "../lib/effect"
|
|
|
|
// Track what options were passed to each transport constructor
|
|
const transportCalls: Array<{
|
|
type: "streamable" | "sse"
|
|
url: string
|
|
options: { authProvider?: unknown; requestInit?: RequestInit }
|
|
}> = []
|
|
|
|
// Mock the transport constructors to capture their arguments
|
|
void mock.module("@modelcontextprotocol/sdk/client/streamableHttp.js", () => ({
|
|
StreamableHTTPClientTransport: class MockStreamableHTTP {
|
|
constructor(url: URL, options?: { authProvider?: unknown; requestInit?: RequestInit }) {
|
|
transportCalls.push({
|
|
type: "streamable",
|
|
url: url.toString(),
|
|
options: options ?? {},
|
|
})
|
|
}
|
|
async start() {
|
|
throw new Error("Mock transport cannot connect")
|
|
}
|
|
},
|
|
}))
|
|
|
|
void mock.module("@modelcontextprotocol/sdk/client/sse.js", () => ({
|
|
SSEClientTransport: class MockSSE {
|
|
constructor(url: URL, options?: { authProvider?: unknown; requestInit?: RequestInit }) {
|
|
transportCalls.push({
|
|
type: "sse",
|
|
url: url.toString(),
|
|
options: options ?? {},
|
|
})
|
|
}
|
|
async start() {
|
|
throw new Error("Mock transport cannot connect")
|
|
}
|
|
},
|
|
}))
|
|
|
|
beforeEach(() => {
|
|
transportCalls.length = 0
|
|
})
|
|
|
|
// Import MCP after mocking
|
|
const { MCP } = await import("../../src/mcp/index")
|
|
const it = testEffect(LayerNode.compile(MCP.node))
|
|
|
|
describe("mcp.headers", () => {
|
|
it.instance("headers are passed to transports when oauth is enabled (default)", () =>
|
|
Effect.gen(function* () {
|
|
const mcp = yield* MCP.Service
|
|
yield* mcp
|
|
.add("test-server", {
|
|
type: "remote",
|
|
url: "https://example.com/mcp",
|
|
headers: {
|
|
Authorization: "Bearer test-token",
|
|
"X-Custom-Header": "custom-value",
|
|
},
|
|
})
|
|
.pipe(Effect.catch(() => Effect.void))
|
|
|
|
// Both transports should have been created with headers
|
|
expect(transportCalls.length).toBeGreaterThanOrEqual(1)
|
|
|
|
for (const call of transportCalls) {
|
|
expect(call.options.requestInit).toBeDefined()
|
|
expect(call.options.requestInit?.headers).toEqual({
|
|
Authorization: "Bearer test-token",
|
|
"X-Custom-Header": "custom-value",
|
|
})
|
|
// OAuth should be enabled by default, so authProvider should exist
|
|
expect(call.options.authProvider).toBeDefined()
|
|
}
|
|
}),
|
|
)
|
|
|
|
it.instance("headers are passed to transports when oauth is explicitly disabled", () =>
|
|
Effect.gen(function* () {
|
|
const mcp = yield* MCP.Service
|
|
yield* mcp
|
|
.add("test-server-no-oauth", {
|
|
type: "remote",
|
|
url: "https://example.com/mcp",
|
|
oauth: false,
|
|
headers: {
|
|
Authorization: "Bearer test-token",
|
|
},
|
|
})
|
|
.pipe(Effect.catch(() => Effect.void))
|
|
|
|
expect(transportCalls.length).toBeGreaterThanOrEqual(1)
|
|
|
|
for (const call of transportCalls) {
|
|
expect(call.options.requestInit).toBeDefined()
|
|
expect(call.options.requestInit?.headers).toEqual({
|
|
Authorization: "Bearer test-token",
|
|
})
|
|
// OAuth is disabled, so no authProvider
|
|
expect(call.options.authProvider).toBeUndefined()
|
|
}
|
|
}),
|
|
)
|
|
|
|
it.instance("no requestInit when headers are not provided", () =>
|
|
Effect.gen(function* () {
|
|
const mcp = yield* MCP.Service
|
|
yield* mcp
|
|
.add("test-server-no-headers", {
|
|
type: "remote",
|
|
url: "https://example.com/mcp",
|
|
})
|
|
.pipe(Effect.catch(() => Effect.void))
|
|
|
|
expect(transportCalls.length).toBeGreaterThanOrEqual(1)
|
|
|
|
for (const call of transportCalls) {
|
|
// No headers means requestInit should be undefined
|
|
expect(call.options.requestInit).toBeUndefined()
|
|
}
|
|
}),
|
|
)
|
|
})
|