GeezerVison is showing github.com — fix(mcp): preserve headers during auth and debug (#31802) · ildella/opencode@bf05e8a
File treeExpand file treeCollapse file tree Open diff view settings Expand file treeCollapse file tree Open diff view settings Collapse file Copy file name to clipboardExpand all lines: packages/opencode/src/cli/cmd/mcp.ts +2Lines changed: 2 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -744,6 +744,7 @@ export const McpDebugCommand = effectCmd({ | 744 | 744 | const response = await fetch(serverConfig.url, { | 745 | 745 | method: "POST", | 746 | 746 | headers: { | | 747 | + ...serverConfig.headers, | 747 | 748 | "Content-Type": "application/json", | 748 | 749 | Accept: "application/json, text/event-stream", | 749 | 750 | }, | @@ -792,6 +793,7 @@ export const McpDebugCommand = effectCmd({ | 792 | 793 | // Try creating transport with auth provider to trigger discovery | 793 | 794 | const transport = new StreamableHTTPClientTransport(new URL(serverConfig.url), { | 794 | 795 | authProvider, | | 796 | + requestInit: serverConfig.headers ? { headers: serverConfig.headers } : undefined, | 795 | 797 | }) | 796 | 798 |
| 797 | 799 | try { | |
Collapse file Copy file name to clipboardExpand all lines: packages/opencode/src/mcp/index.ts +4-1Lines changed: 4 additions & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
@@ -741,7 +741,10 @@ export const layer = Layer.effect( | 741 | 741 | auth, | 742 | 742 | ) | 743 | 743 |
| 744 | | - const transport = new StreamableHTTPClientTransport(url, { authProvider }) | | 744 | + const transport = new StreamableHTTPClientTransport(url, { | | 745 | + authProvider, | | 746 | + requestInit: mcpConfig.headers ? { headers: mcpConfig.headers } : undefined, | | 747 | + }) | 745 | 748 |
| 746 | 749 | return yield* Effect.tryPromise({ | 747 | 750 | try: () => { | |
Collapse file Copy file name to clipboardExpand all lines: packages/opencode/test/mcp/oauth-browser.test.ts +9-4Lines changed: 9 additions & 4 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -38,15 +38,18 @@ class MockUnauthorizedError extends Error { | 38 | 38 | const transportCalls: Array<{ | 39 | 39 | type: "streamable" | "sse" | 40 | 40 | url: string | 41 | | - options: { authProvider?: unknown } | | 41 | + options: { authProvider?: unknown; requestInit?: RequestInit } | 42 | 42 | }> = [] | 43 | 43 |
| 44 | 44 | // Mock the transport constructors | 45 | 45 | void mock.module("@modelcontextprotocol/sdk/client/streamableHttp.js", () => ({ | 46 | 46 | StreamableHTTPClientTransport: class MockStreamableHTTP { | 47 | 47 | url: string | 48 | 48 | authProvider: { redirectToAuthorization?: (url: URL) => Promise<void> } | undefined | 49 | | - constructor(url: URL, options?: { authProvider?: { redirectToAuthorization?: (url: URL) => Promise<void> } }) { | | 49 | + constructor( | | 50 | + url: URL, | | 51 | + options?: { authProvider?: { redirectToAuthorization?: (url: URL) => Promise<void> }; requestInit?: RequestInit }, | | 52 | + ) { | 50 | 53 | this.url = url.toString() | 51 | 54 | this.authProvider = options?.authProvider | 52 | 55 | transportCalls.push({ | @@ -127,11 +130,12 @@ const mcpTest = testEffect( | 127 | 130 | ) | 128 | 131 | const service = MCP.Service as unknown as Effect.Effect<MCPNS.Interface, never, never> | 129 | 132 |
| 130 | | -const config = (name: string) => ({ | | 133 | +const config = (name: string, headers?: Record<string, string>) => ({ | 131 | 134 | mcp: { | 132 | 135 | [name]: { | 133 | 136 | type: "remote" as const, | 134 | 137 | url: "https://example.com/mcp", | | 138 | + headers, | 135 | 139 | }, | 136 | 140 | }, | 137 | 141 | }) | @@ -227,6 +231,7 @@ mcpTest.instance( | 227 | 231 | expect(failure).toEqual(Option.none()) | 228 | 232 | expect(typeof url).toBe("string") | 229 | 233 | expect(url).toContain("https://") | | 234 | + expect(transportCalls.at(-1)?.options.requestInit?.headers).toEqual({ "X-Custom-Header": "custom-value" }) | 230 | 235 | }), | 231 | | - { config: config("test-oauth-server-3") }, | | 236 | + { config: config("test-oauth-server-3", { "X-Custom-Header": "custom-value" }) }, | 232 | 237 | ) |
|