fix(mcp): preserve headers during auth and debug (#31802)

This commit is contained in:
Aiden Cline
2026-06-10 23:12:02 -05:00
committed by GitHub
parent 51b10b128e
commit bf05e8a122
3 changed files with 15 additions and 5 deletions
@@ -38,7 +38,7 @@ class MockUnauthorizedError extends Error {
const transportCalls: Array<{
type: "streamable" | "sse"
url: string
options: { authProvider?: unknown }
options: { authProvider?: unknown; requestInit?: RequestInit }
}> = []
// Mock the transport constructors
@@ -46,7 +46,10 @@ void mock.module("@modelcontextprotocol/sdk/client/streamableHttp.js", () => ({
StreamableHTTPClientTransport: class MockStreamableHTTP {
url: string
authProvider: { redirectToAuthorization?: (url: URL) => Promise<void> } | undefined
constructor(url: URL, options?: { authProvider?: { redirectToAuthorization?: (url: URL) => Promise<void> } }) {
constructor(
url: URL,
options?: { authProvider?: { redirectToAuthorization?: (url: URL) => Promise<void> }; requestInit?: RequestInit },
) {
this.url = url.toString()
this.authProvider = options?.authProvider
transportCalls.push({
@@ -127,11 +130,12 @@ const mcpTest = testEffect(
)
const service = MCP.Service as unknown as Effect.Effect<MCPNS.Interface, never, never>
const config = (name: string) => ({
const config = (name: string, headers?: Record<string, string>) => ({
mcp: {
[name]: {
type: "remote" as const,
url: "https://example.com/mcp",
headers,
},
},
})
@@ -227,6 +231,7 @@ mcpTest.instance(
expect(failure).toEqual(Option.none())
expect(typeof url).toBe("string")
expect(url).toContain("https://")
expect(transportCalls.at(-1)?.options.requestInit?.headers).toEqual({ "X-Custom-Header": "custom-value" })
}),
{ config: config("test-oauth-server-3") },
{ config: config("test-oauth-server-3", { "X-Custom-Header": "custom-value" }) },
)