feat: add runtime proxy configuration support to browser_configure

Enables on-the-fly proxy switching without restarting MCP server, allowing
users to dynamically set or clear proxy settings during browser sessions.

Changes:
- Add proxyServer and proxyBypass parameters to updateBrowserConfig method
- Implement proxy set/clear logic with proper validation for empty strings
- Expose proxy configuration through browser_configure tool interface
- Update auto-generated documentation with proxy parameter descriptions

Tested with SOCKS5 proxy, verified IP changes when proxy is enabled/disabled.
This commit is contained in:
Ryan Malloy 2025-11-14 21:34:40 -07:00
parent 1c55b771a8
commit 3e92fc031f
3 changed files with 72 additions and 0 deletions

View file

@ -501,6 +501,10 @@ export class Context {
permissions?: string[];
offline?: boolean;
// Proxy Configuration
proxyServer?: string;
proxyBypass?: string;
// Browser UI Customization
chromiumSandbox?: boolean;
slowMo?: number;
@ -564,6 +568,21 @@ export class Context {
if (changes.offline !== undefined)
(currentConfig.browser as any).offline = changes.offline;
// Apply proxy configuration
if (changes.proxyServer !== undefined) {
if (changes.proxyServer === '' || changes.proxyServer === null) {
// Clear proxy when empty string or null
delete currentConfig.browser.launchOptions.proxy;
} else {
// Set proxy server
currentConfig.browser.launchOptions.proxy = {
server: changes.proxyServer
};
if (changes.proxyBypass)
currentConfig.browser.launchOptions.proxy.bypass = changes.proxyBypass;
}
}
// Apply browser launch options for UI customization
if (changes.chromiumSandbox !== undefined)
currentConfig.browser.launchOptions.chromiumSandbox = changes.chromiumSandbox;

View file

@ -40,6 +40,10 @@ const configureSchema = z.object({
permissions: z.array(z.string()).optional().describe('Permissions to grant (e.g., ["geolocation", "notifications", "camera", "microphone"])'),
offline: z.boolean().optional().describe('Whether to emulate offline network conditions (equivalent to DevTools offline mode)'),
// Proxy Configuration
proxyServer: z.string().optional().describe('Proxy server to use for network requests. Examples: "http://myproxy:3128", "socks5://127.0.0.1:1080". Set to null (empty) to clear proxy.'),
proxyBypass: z.string().optional().describe('Comma-separated domains to bypass proxy (e.g., ".com,chromium.org,.domain.com")'),
// Browser UI Customization Options
chromiumSandbox: z.boolean().optional().describe('Enable/disable Chromium sandbox (affects browser appearance)'),
slowMo: z.number().min(0).optional().describe('Slow down operations by specified milliseconds (helps with visual tracking)'),
@ -316,6 +320,19 @@ export default [
}
// Track proxy changes
if (params.proxyServer !== undefined) {
const currentProxy = currentConfig.browser.launchOptions.proxy?.server;
if (params.proxyServer !== currentProxy) {
const fromProxy = currentProxy || 'none';
const toProxy = params.proxyServer || 'none';
changes.push(`proxy: ${fromProxy}${toProxy}`);
if (params.proxyBypass)
changes.push(`proxy bypass: ${params.proxyBypass}`);
}
}
if (changes.length === 0) {
response.addResult('No configuration changes detected. Current settings remain the same.');
@ -334,6 +351,8 @@ export default [
colorScheme: params.colorScheme,
permissions: params.permissions,
offline: params.offline,
proxyServer: params.proxyServer,
proxyBypass: params.proxyBypass,
});
response.addResult(`Browser configuration updated successfully:\n${changes.map(c => `${c}`).join('\n')}\n\nThe browser has been restarted with the new settings.`);