-
-
Notifications
You must be signed in to change notification settings - Fork 10
feat: Implement enhanced error handling and retry mechanisms #6
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 '__'.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This commit introduces several improvements to the MCP proxy server's reliability:
Error Propagation: Ensured that errors from backend MCP services are consistently propagated to you in a standard JSON-RPC error format.
SSE Auto-Reconnect and Retry:
proxy.retrySseToolCallOnDisconnectsetting inmcp_server.json(defaults totrue).HTTP Request Retry:
mcp_server.json:proxy.retryHttpToolCall(boolean, default:true)proxy.httpToolCallMaxRetries(number, default:2)proxy.httpToolCallRetryDelayBaseMs(number, default:300ms)Configuration: Updated
src/config.tsto load and manage these new settings with appropriate defaults.Documentation: Updated
README.mdto 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.