Skip to content

Commit 8d3e37f

Browse files
committed
feat: add command line option to enable HTTP proxy support
1 parent 76c1f26 commit 8d3e37f

File tree

2 files changed

+24
-4
lines changed

2 files changed

+24
-4
lines changed

README.md

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,22 @@ To bypass authentication, or to emit custom headers on all requests to your remo
135135
]
136136
```
137137

138+
* 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`).
139+
140+
Example:
141+
142+
```json
143+
"args": [
144+
"mcp-remote",
145+
"https://remote.mcp.server/sse",
146+
"--enable-proxy"
147+
],
148+
"env": {
149+
"HTTPS_PROXY": "http://127.0.0.1:3128",
150+
"NO_PROXY": "localhost,127.0.0.1"
151+
}
152+
```
153+
138154
* 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 `*`.
139155

140156
```json

src/lib/utils.ts

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import fs from 'fs'
1414
import { readFile, rm } from 'fs/promises'
1515
import path from 'path'
1616
import { version as MCP_REMOTE_VERSION } from '../../package.json'
17-
import { fetch, setGlobalDispatcher, RequestInit, EnvHttpProxyAgent } from 'undici';
17+
import { fetch, setGlobalDispatcher, RequestInit, EnvHttpProxyAgent } from 'undici'
1818

1919
// Global type declaration for typescript
2020
declare global {
@@ -33,9 +33,6 @@ const pid = process.pid
3333
// Global debug flag
3434
export let DEBUG = false
3535

36-
// Use env proxy
37-
setGlobalDispatcher(new EnvHttpProxyAgent());
38-
3936
// Helper function for timestamp formatting
4037
function getTimestamp(): string {
4138
const now = new Date()
@@ -646,6 +643,13 @@ export async function parseCommandLineArgs(args: string[], usage: string) {
646643
log('Debug mode enabled - detailed logs will be written to ~/.mcp-auth/')
647644
}
648645

646+
const enableProxy = args.includes('--enable-proxy')
647+
if (enableProxy) {
648+
// Use env proxy
649+
setGlobalDispatcher(new EnvHttpProxyAgent())
650+
log('HTTP proxy support enabled - using system HTTP_PROXY/HTTPS_PROXY environment variables')
651+
}
652+
649653
// Parse transport strategy
650654
let transportStrategy: TransportStrategy = 'http-first' // Default
651655
const transportIndex = args.indexOf('--transport')

0 commit comments

Comments
 (0)