Skip to content

Conversation

@ptbsare
Copy link
Owner

@ptbsare ptbsare commented May 29, 2025

This commit introduces several improvements to the MCP proxy server's reliability:

  1. Error Propagation: Ensured that errors from backend MCP services are consistently propagated to you in a standard JSON-RPC error format.

  2. SSE Auto-Reconnect and Retry:

    • For operations to SSE-based backends, if a connection-related error occurs, the proxy will automatically attempt to re-establish the connection and retry the call once.
    • This feature is configurable via the proxy.retrySseToolCallOnDisconnect setting in mcp_server.json (defaults to true).
  3. HTTP Request Retry:

    • For operations to HTTP-based backends, if a connection error occurs, the proxy will automatically retry the request using an exponential backoff strategy.
    • This is configurable via settings in mcp_server.json:
      • proxy.retryHttpToolCall (boolean, default: true)
      • proxy.httpToolCallMaxRetries (number, default: 2)
      • proxy.httpToolCallRetryDelayBaseMs (number, default: 300ms)
  4. Configuration: Updated src/config.ts to load and manage these new settings with appropriate defaults.

  5. Documentation: Updated README.md to reflect these new features and their configuration.

These changes aim to make the MCP proxy server more resilient to transient network issues and backend unavailability.

google-labs-jules bot and others added 19 commits May 29, 2025 10:28
This commit introduces several improvements to the MCP proxy server's reliability:

1.  **Error Propagation:** Ensured that errors from backend MCP services are consistently propagated to you in a standard JSON-RPC error format.

2.  **SSE Auto-Reconnect and Retry:**
    *   For operations to SSE-based backends, if a connection-related error occurs, the proxy will automatically attempt to re-establish the connection and retry the call once.
    *   This feature is configurable via the `proxy.retrySseToolCallOnDisconnect` setting in `mcp_server.json` (defaults to `true`).

3.  **HTTP Request Retry:**
    *   For operations to HTTP-based backends, if a connection error occurs, the proxy will automatically retry the request using an exponential backoff strategy.
    *   This is configurable via settings in `mcp_server.json`:
        *   `proxy.retryHttpToolCall` (boolean, default: `true`)
        *   `proxy.httpToolCallMaxRetries` (number, default: `2`)
        *   `proxy.httpToolCallRetryDelayBaseMs` (number, default: `300`ms)

4.  **Configuration:** Updated `src/config.ts` to load and manage these new settings with appropriate defaults.

5.  **Documentation:** Updated `README.md` to reflect these new features and their configuration.

These changes aim to make the MCP proxy server more resilient to transient network issues and backend unavailability.
Removes a duplicated and incomplete `createServer` function definition and a duplicated `isConnectionError` helper function that were causing a TypeScript build error (TS1005: '}' expected).

This correction ensures `src/mcp-proxy.ts` is syntactically valid and should allow the project to build successfully.
Ensures `currentProxyConfig` in `src/mcp-proxy.ts` is always initialized with a complete set of default values and its type guarantees it is non-nullable (`Required<NonNullable<Config['proxy']>>`).

This addresses TypeScript errors TS18048 ("'currentProxyConfig' is possibly 'undefined'") that occurred during property access. Updates to `currentProxyConfig` in `createServer` and `updateBackendConnections` now also ensure all default settings are preserved.
Removes a duplicated code block within the `createServer` function in `src/mcp-proxy.ts` that was causing a TS2451 error ("Cannot redeclare block-scoped variable 'initialActiveServers'").

This ensures `initialActiveServers` is declared and initialized only once, allowing the project to build successfully.
I've modified the MCP Proxy Server so you can configure specific proxy retry/reliability settings using environment variables. These environment variable settings will now take priority over any values you've set in `mcp_server.json` for the same fields.

The following settings are affected:
- `retrySseToolCallOnDisconnect` (env: `RETRY_SSE_TOOL_CALL_ON_DISCONNECT`)
- `retryHttpToolCall` (env: `RETRY_HTTP_TOOL_CALL`)
- `httpToolCallMaxRetries` (env: `HTTP_TOOL_CALL_MAX_RETRIES`)
- `httpToolCallRetryDelayBaseMs` (env: `HTTP_TOOL_CALL_RETRY_DELAY_BASE_MS`)

If you don't set the environment variables or if they are invalid, the system will use predefined default values for these settings.

The changes I made include:
- Updating `src/config.ts` to read and parse these environment variables.
- Updating `README.md` to reflect the new configuration method and environment variable names.

Please note that `README_ZH.md` will need to be updated manually with the translated documentation for these changes.
Moves the definition of the `defaultEnvProxySettings` constant to the beginning of the `loadConfig` function. This ensures it is correctly scoped and accessible to both the `try` and `catch` blocks within the function.

This resolves the TS2304 error ("Cannot find name 'defaultEnvProxySettings'") that occurred when trying to access this constant from the catch block.
The default separator for combining server names and tool names has been changed from '--' to '__'. This is a breaking change for users who relied on the hardcoded separator in tool_config.json or other integrations.

The separator can now be configured using the SERVER_TOOLNAME_SEPERATOR environment variable. It must be at least 2 characters long and contain only letters, numbers, '-', and '_'. Invalid values will fall back to the default '__'.
@ptbsare ptbsare merged commit 83c06e6 into main Jun 29, 2025
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants