Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -444,6 +444,30 @@ $(npm bin -g)/reddit-mcp-buddy
| `REDDIT_BUDDY_PORT` | HTTP server port (when HTTP=true) | `3000` |
| `REDDIT_BUDDY_NO_CACHE` | Disable caching (always fetch fresh) | `false` |

#### Proxy Configuration
| Variable | Description | Example |
|----------|-------------|---------|
| `HTTPS_PROXY` or `https_proxy` | HTTPS proxy server URL | `http://proxy.company.com:8080` |
| `HTTP_PROXY` or `http_proxy` | HTTP proxy server URL | `http://proxy.company.com:8080` |
| `NO_PROXY` or `no_proxy` | Comma-separated list of hosts to bypass proxy | `localhost,127.0.0.1` |

**Proxy Support**: Reddit MCP Buddy automatically detects and uses proxy settings from environment variables. This is useful for corporate networks, restricted regions, or when using VPN services.

**Example with authentication**:
```json
{
"mcpServers": {
"reddit": {
"command": "npx",
"args": ["-y", "reddit-mcp-buddy"],
"env": {
"HTTPS_PROXY": "http://username:password@proxy.company.com:8080"
}
}
}
}
```

## Technical Details

### Smart Caching System
Expand Down
14 changes: 12 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@
},
"dependencies": {
"@modelcontextprotocol/sdk": "^1.17.5",
"undici": "~6.13.0",
"zod": "^3.23.8",
"zod-to-json-schema": "^3.24.6"
},
Expand Down
1 change: 1 addition & 0 deletions scripts/rate-limit-tester.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,7 @@ console.log(`${colors.blue}Starting MCP server...${colors.reset}`);
const server = spawn('npm', ['start'], {
env: serverEnv,
stdio: ['ignore', 'pipe', 'pipe'],
shell: true, // Required for Windows compatibility
});

let serverReady = false;
Expand Down
75 changes: 75 additions & 0 deletions src/core/proxy.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
/**
* HTTP Proxy configuration for Reddit API requests
*
* Automatically detects and configures proxy from environment variables:
* - HTTPS_PROXY / https_proxy
* - HTTP_PROXY / http_proxy
* - NO_PROXY / no_proxy
*/

import { ProxyAgent, setGlobalDispatcher } from 'undici';

/**
* Setup HTTP proxy for all fetch requests
*
* This function reads proxy configuration from environment variables and
* sets up a global dispatcher. Once configured, ALL fetch() calls will
* automatically use the proxy without any code changes.
*
* Supported environment variables (checked in order):
* - HTTPS_PROXY, https_proxy: For HTTPS requests
* - HTTP_PROXY, http_proxy: For HTTP requests
* - NO_PROXY, no_proxy: Comma-separated list of hosts to exclude
*
* Proxy URL formats:
* - http://proxy.example.com:8080
* - http://username:password@proxy.example.com:8080
* - https://proxy.example.com:8443
*/
export function setupProxy(): void {
// Check environment variables (case-insensitive, uppercase first)
const httpsProxy = process.env.HTTPS_PROXY || process.env.https_proxy;
const httpProxy = process.env.HTTP_PROXY || process.env.http_proxy;

// Use HTTPS proxy first, fall back to HTTP proxy
const proxyUrl = httpsProxy || httpProxy;

if (!proxyUrl) {
return; // No proxy configured, direct connection
}

try {
// Validate proxy URL
const proxyUrlObj = new URL(proxyUrl);

// Create ProxyAgent
const proxyAgent = new ProxyAgent(proxyUrl);

// Set as global dispatcher - affects ALL fetch() calls
setGlobalDispatcher(proxyAgent);

// Log proxy configuration (hide password for security)
const safeProxyUrl = proxyUrlObj.password
? proxyUrl.replace(`:${proxyUrlObj.password}@`, ':***@')
: proxyUrl;

console.error(`🔧 Proxy configured: ${safeProxyUrl}`);

} catch (error: any) {
// Invalid proxy URL - log warning but don't crash
console.error(`⚠️ Invalid proxy URL: ${error.message}`);
console.error(` Continuing with direct connection`);
}
}

/**
* Get current proxy configuration (for debugging)
*/
export function getProxyConfig(): { https?: string; http?: string; no?: string } {
return {
https: process.env.HTTPS_PROXY || process.env.https_proxy,
http: process.env.HTTP_PROXY || process.env.http_proxy,
no: process.env.NO_PROXY || process.env.no_proxy,
};
}

3 changes: 3 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,11 @@
* Main entry point
*/

import { setupProxy } from './core/proxy.js';
import { startStdioServer, startHttpServer } from './mcp-server.js';

setupProxy();

// Determine transport mode from environment
const isHttpMode = process.env.REDDIT_BUDDY_HTTP === 'true';
const port = parseInt(process.env.REDDIT_BUDDY_PORT || '3000', 10);
Expand Down