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/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..4258e43 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 { @@ -642,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')