From 76c1f260c3f24ff604f12f82196893a59f887ccf Mon Sep 17 00:00:00 2001 From: nyyu Date: Sun, 27 Jul 2025 19:04:36 +0200 Subject: [PATCH 1/2] feat: proxy support --- package.json | 3 ++- pnpm-lock.yaml | 9 +++++++++ src/lib/utils.ts | 4 ++++ 3 files changed, 15 insertions(+), 1 deletion(-) diff --git a/package.json b/package.json index d83103c..078e998 100644 --- a/package.json +++ b/package.json @@ -33,7 +33,8 @@ "dependencies": { "express": "^4.21.2", "open": "^10.1.0", - "strict-url-sanitise": "^0.0.1" + "strict-url-sanitise": "^0.0.1", + "undici": "^7.12.0" }, "devDependencies": { "@modelcontextprotocol/sdk": "^1.17.3", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 878e695..8b81888 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -17,6 +17,9 @@ importers: strict-url-sanitise: specifier: ^0.0.1 version: 0.0.1 + undici: + specifier: ^7.12.0 + version: 7.12.0 devDependencies: '@modelcontextprotocol/sdk': specifier: ^1.17.3 @@ -1220,6 +1223,10 @@ packages: undici-types@6.20.0: resolution: {integrity: sha512-Ny6QZ2Nju20vw1SRHe3d9jVu6gJ+4e3+MMpqu7pqE5HT6WsTSlce++GQmK5UXS8mzV8DSYHrQH+Xrf2jVcuKNg==} + undici@7.12.0: + resolution: {integrity: sha512-GrKEsc3ughskmGA9jevVlIOPMiiAHJ4OFUtaAH+NhfTUSiZ1wMPIQqQvAJUrJspFXJt3EBWgpAeoHEDVT1IBug==} + engines: {node: '>=20.18.1'} + unpipe@1.0.0: resolution: {integrity: sha512-pjy2bYhSsufwWlKwPc+l3cN7+wuJlK6uz0YdJEOlQDbl6jo/YlPi4mb8agUkVC8BF7V8NuzeyPNqRksA3hztKQ==} engines: {node: '>= 0.8'} @@ -2502,6 +2509,8 @@ snapshots: undici-types@6.20.0: {} + undici@7.12.0: {} + unpipe@1.0.0: {} uri-js@4.4.1: diff --git a/src/lib/utils.ts b/src/lib/utils.ts index e60d0de..a5c02ab 100644 --- a/src/lib/utils.ts +++ b/src/lib/utils.ts @@ -14,6 +14,7 @@ import fs from 'fs' import { readFile, rm } from 'fs/promises' import path from 'path' import { version as MCP_REMOTE_VERSION } from '../../package.json' +import { fetch, setGlobalDispatcher, RequestInit, EnvHttpProxyAgent } from 'undici'; // Global type declaration for typescript declare global { @@ -32,6 +33,9 @@ const pid = process.pid // Global debug flag export let DEBUG = false +// Use env proxy +setGlobalDispatcher(new EnvHttpProxyAgent()); + // Helper function for timestamp formatting function getTimestamp(): string { const now = new Date() From 782ed649864fd654f1ba1277d7581e2999040bd4 Mon Sep 17 00:00:00 2001 From: nyyu Date: Wed, 27 Aug 2025 09:17:48 +0200 Subject: [PATCH 2/2] feat: add command line option to enable HTTP proxy support --- README.md | 14 ++++++++++++++ src/lib/utils.ts | 12 ++++++++---- 2 files changed, 22 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 43604b4..ca9d961 100644 --- a/README.md +++ b/README.md @@ -135,6 +135,20 @@ To bypass authentication, or to emit custom headers on all requests to your remo ] ``` +* To enable an outbound HTTP(S) proxy for mcp-remote, add the `--enable-proxy` flag. When enabled, mcp-remote will use the proxy settings from common environment variables (for example `HTTP_PROXY`, `HTTPS_PROXY`, and `NO_PROXY`). + +```json + "args": [ + "mcp-remote", + "https://remote.mcp.server/sse", + "--enable-proxy" + ], + "env": { + "HTTPS_PROXY": "http://127.0.0.1:3128", + "NO_PROXY": "localhost,127.0.0.1" + } +``` + * To ignore specific tools from the remote server, add the `--ignore-tool` flag. This will filter out tools matching the specified patterns from both `tools/list` responses and block `tools/call` requests. Supports wildcard patterns with `*`. ```json diff --git a/src/lib/utils.ts b/src/lib/utils.ts index a5c02ab..4258e43 100644 --- a/src/lib/utils.ts +++ b/src/lib/utils.ts @@ -14,7 +14,7 @@ import fs from 'fs' import { readFile, rm } from 'fs/promises' import path from 'path' import { version as MCP_REMOTE_VERSION } from '../../package.json' -import { fetch, setGlobalDispatcher, RequestInit, EnvHttpProxyAgent } from 'undici'; +import { fetch, setGlobalDispatcher, RequestInit, EnvHttpProxyAgent } from 'undici' // Global type declaration for typescript declare global { @@ -33,9 +33,6 @@ const pid = process.pid // Global debug flag export let DEBUG = false -// Use env proxy -setGlobalDispatcher(new EnvHttpProxyAgent()); - // Helper function for timestamp formatting function getTimestamp(): string { const now = new Date() @@ -646,6 +643,13 @@ export async function parseCommandLineArgs(args: string[], usage: string) { log('Debug mode enabled - detailed logs will be written to ~/.mcp-auth/') } + const enableProxy = args.includes('--enable-proxy') + if (enableProxy) { + // Use env proxy + setGlobalDispatcher(new EnvHttpProxyAgent()) + log('HTTP proxy support enabled - using system HTTP_PROXY/HTTPS_PROXY environment variables') + } + // Parse transport strategy let transportStrategy: TransportStrategy = 'http-first' // Default const transportIndex = args.indexOf('--transport')