summaryrefslogtreecommitdiff
path: root/packages/core/src
diff options
context:
space:
mode:
authorBlackoutta <[email protected]>2025-08-20 08:32:08 +0800
committerGitHub <[email protected]>2025-08-20 00:32:08 +0000
commitd587c6f1042824de7a1ae94eb1ea9c049cfc34c9 (patch)
treef1e42eba699ef032153875dbb0d7ef9bd982fb9b /packages/core/src
parent6732665a080a5635368f37da532106edf83b8907 (diff)
Fix IDE Companion Connection in Proxy Environments (#6308)
Co-authored-by: Jacob Richman <[email protected]>
Diffstat (limited to 'packages/core/src')
-rw-r--r--packages/core/src/ide/ide-client.ts27
1 files changed, 27 insertions, 0 deletions
diff --git a/packages/core/src/ide/ide-client.ts b/packages/core/src/ide/ide-client.ts
index efb9c8f0..e4d5f0ba 100644
--- a/packages/core/src/ide/ide-client.ts
+++ b/packages/core/src/ide/ide-client.ts
@@ -20,6 +20,7 @@ import { Client } from '@modelcontextprotocol/sdk/client/index.js';
import { StreamableHTTPClientTransport } from '@modelcontextprotocol/sdk/client/streamableHttp.js';
import * as os from 'node:os';
import * as path from 'node:path';
+import { EnvHttpProxyAgent } from 'undici';
const logger = {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
@@ -325,6 +326,29 @@ export class IdeClient {
}
}
+ private createProxyAwareFetch() {
+ // ignore proxy for 'localhost' by deafult to allow connecting to the ide mcp server
+ const existingNoProxy = process.env['NO_PROXY'] || '';
+ const agent = new EnvHttpProxyAgent({
+ noProxy: [existingNoProxy, 'localhost'].filter(Boolean).join(','),
+ });
+ const undiciPromise = import('undici');
+ return async (url: string | URL, init?: RequestInit): Promise<Response> => {
+ const { fetch: fetchFn } = await undiciPromise;
+ const fetchOptions: RequestInit & { dispatcher?: unknown } = {
+ ...init,
+ dispatcher: agent,
+ };
+ const options = fetchOptions as unknown as import('undici').RequestInit;
+ const response = await fetchFn(url, options);
+ return new Response(response.body as ReadableStream<unknown> | null, {
+ status: response.status,
+ statusText: response.statusText,
+ headers: response.headers,
+ });
+ };
+ }
+
private registerClientHandlers() {
if (!this.client) {
return;
@@ -389,6 +413,9 @@ export class IdeClient {
});
transport = new StreamableHTTPClientTransport(
new URL(`http://${getIdeServerHost()}:${port}/mcp`),
+ {
+ fetch: this.createProxyAwareFetch(),
+ },
);
await this.client.connect(transport);
this.registerClientHandlers();