Skip to content

Commit 782ed64

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

File tree

2 files changed

+22
-4
lines changed

2 files changed

+22
-4
lines changed

README.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,20 @@ 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+
```json
141+
"args": [
142+
"mcp-remote",
143+
"https://remote.mcp.server/sse",
144+
"--enable-proxy"
145+
],
146+
"env": {
147+
"HTTPS_PROXY": "http://127.0.0.1:3128",
148+
"NO_PROXY": "localhost,127.0.0.1"
149+
}
150+
```
151+
138152
* 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 `*`.
139153

140154
```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)