You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
While some general proxy behaviors might be configured here in the future, the primary retry and error handling settings are now managed via **Environment Variables** for easier deployment-specific overrides. Values in `config/mcp_server.json` for these specific settings will be overridden by environment variables if set.
177
+
- **`RETRY_SSE_TOOL_CALL_ON_DISCONNECT`**: (Optional) Controls whether to automatically reconnect and retry on SSE tool call failures. Set to `"true"` to enable, `"false"` to disable. Default: `true`. See the "Enhanced Reliability Features" section for details.
178
+
```bash
179
+
export RETRY_SSE_TOOL_CALL_ON_DISCONNECT="true"
180
+
```
181
+
- **`RETRY_HTTP_TOOL_CALL`**: (Optional) Controls whether to retry on HTTP tool call connection errors. Set to `"true"` to enable, `"false"` to disable. Default: `true`. See the "Enhanced Reliability Features" section for details.
182
+
```bash
183
+
export RETRY_HTTP_TOOL_CALL="true"
184
+
```
185
+
- **`HTTP_TOOL_CALL_MAX_RETRIES`**: (Optional) Maximum number of retry attempts for HTTP tool calls (after the initial failure). Default: `2`. See the "Enhanced Reliability Features" section for details.
186
+
```bash
187
+
export HTTP_TOOL_CALL_MAX_RETRIES="3"
188
+
```
189
+
- **`HTTP_TOOL_CALL_RETRY_DELAY_BASE_MS`**: (Optional) Base delay in milliseconds for HTTP tool call retries, used in exponential backoff. Default: `300`. See the "Enhanced Reliability Features" section for details.
190
+
```bash
191
+
export HTTP_TOOL_CALL_RETRY_DELAY_BASE_MS="500"
192
+
```
193
+
- **`RETRY_STDIO_TOOL_CALL`**: (Optional) Controls whether to retry on Stdio tool call connection errors (attempts to restart the process). Set to `"true"` to enable, `"false"` to disable. Default: `true`. See the "Enhanced Reliability Features" section for details.
194
+
```bash
195
+
export RETRY_STDIO_TOOL_CALL="true"
196
+
```
197
+
- **`STDIO_TOOL_CALL_MAX_RETRIES`**: (Optional) Maximum number of retry attempts for Stdio tool calls (after the initial failure). Default: `2`. See the "Enhanced Reliability Features" section for details.
198
+
```bash
199
+
export STDIO_TOOL_CALL_MAX_RETRIES="5"
200
+
```
201
+
- **`STDIO_TOOL_CALL_RETRY_DELAY_BASE_MS`**: (Optional) Base delay in milliseconds for Stdio tool call retries, used in exponential backoff. Default: `300`. See the "Enhanced Reliability Features" section for details.
202
+
```bash
203
+
export STDIO_TOOL_CALL_RETRY_DELAY_BASE_MS="1000"
204
+
```
179
205
180
-
Example `config/mcp_server.json` showing other potential proxy settings:
// Specific retry settings like retrySseToolCallOnDisconnect, retryHttpToolCall,
189
-
// httpToolCallMaxRetries, and httpToolCallRetryDelayBaseMs are now
190
-
// preferably set via environment variables (see below).
191
-
}
192
-
}
206
+
## Enhanced Reliability Features
207
+
208
+
The MCP Proxy Server includes features to improve its resilience and the reliability of interactions with backend MCP services, ensuring smoother operations and more consistent tool execution.
209
+
210
+
### 1. Error Propagation
211
+
The proxy server ensures that errors originating from backend MCP services are consistently propagated to the requesting client. These errors are formatted as standard JSON-RPC error responses, making it easier for clients to handle them uniformly.
212
+
213
+
### 2. SSE Connection Retry for Tool Calls
214
+
When a `tools/call` operation is made to an SSE-based backend server, and the underlying connection is lost or experiences an error, the proxy server will automatically attempt to:
215
+
1. Re-establish the connection to the SSE backend.
216
+
2. If reconnection is successful, it will retry the original `tools/call` request **once**.
217
+
218
+
This behavior helps mitigate transient network issues that might temporarily disrupt SSE connections.
219
+
220
+
**Configuration:**
221
+
This feature is primarily controlled by the **`RETRY_SSE_TOOL_CALL_ON_DISCONNECT`** environment variable.
- Set to `"true"` to enable the automatic reconnect and retry.
224
+
- Set to `"false"` to disable this feature.
225
+
- **Default Behavior:** `true` (if the environment variable is not set, is empty, or is an invalid value).
226
+
227
+
**Example (Environment Variable):**
228
+
```bash
229
+
export RETRY_SSE_TOOL_CALL_ON_DISCONNECT="true"
193
230
```
194
-
See the "Enhanced Reliability Features" and "Environment Variables" sections for details on these options.
195
231
232
+
### 3. HTTP Request Retry for Tool Calls
233
+
For `tools/call` operations directed to HTTP-based backend servers, the proxy implements a retry mechanism for connection errors (e.g., "failed to fetch", network timeouts).
234
+
235
+
**Retry Mechanism:**
236
+
If an initial HTTP request fails due to a connection error, the proxy will retry the request using an exponential backoff strategy. This means the delay before each subsequent retry attempt increases exponentially, with a small amount of jitter (randomness) added to prevent thundering herd scenarios.
196
237
197
-
## Enhanced Reliability Features
238
+
**Configuration:**
239
+
These settings are primarily controlled by environment variables.
- Specifies the maximum number of retry attempts *after* the initial failed attempt. For example, if set to `"2"`,there will be one initial attempt and up to two retry attempts, totaling a maximum of three attempts.
248
+
- **Default Behavior:** `2` (if the environment variable is not set, is empty, or is not a valid integer).
- The base delay in milliseconds used in the exponential backoff calculation. The delay before the *n*-th retry (0-indexed) is roughly `HTTP_TOOL_CALL_RETRY_DELAY_BASE_MS * (2^n) + jitter`.
252
+
- **Default Behavior:** `300` (milliseconds) (if the environment variable is not set, is empty, or is not a valid integer).
253
+
254
+
### 4. Stdio Connection Retry for Tool Calls
255
+
For `tools/call` operations directed to Stdio-based backend servers, the proxy implements a retry mechanism for connection errors (e.g., process crash or unresponsiveness).
256
+
257
+
**Retry Mechanism:**
258
+
If an initial Stdio connection or tool call fails, the proxy will attempt to restart the Stdio process and retry the request. This mechanism follows an exponential backoff strategy similar to HTTP retries.
259
+
260
+
**Configuration:**
261
+
These settings are primarily controlled by environment variables.
- Specifies the maximum number of retry attempts *after* the initial failed attempt. For example, if set to `"2"`,there will be one initial attempt and up to two retry attempts, totaling a maximum of three attempts.
270
+
- **Default Behavior:** `2` (if the environment variable is not set, is empty, or is not a valid integer).
- The base delay in milliseconds used in the exponential backoff calculation. The delay before the *n*-th retry (0-indexed) is roughly `STDIO_TOOL_CALL_RETRY_DELAY_BASE_MS * (2^n) + jitter`.
274
+
- **Default Behavior:** `300` (milliseconds) (if the environment variable is not set, is empty, or is not a valid integer).
275
+
276
+
**General Notes on Environment Variable Parsing:**
277
+
- Boolean environment variables (`RETRY_SSE_TOOL_CALL_ON_DISCONNECT`, `RETRY_HTTP_TOOL_CALL`, `RETRY_STDIO_TOOL_CALL`) are considered `true` if their lowercase value is exactly `"true"`. Any other value (including empty or not set) results in the default being applied or `false` if the default is `false` (though for these specific variables, the default is `true`).
278
+
- Numeric environment variables (`HTTP_TOOL_CALL_MAX_RETRIES`, `HTTP_TOOL_CALL_RETRY_DELAY_BASE_MS`, `STDIO_TOOL_CALL_MAX_RETRIES`, `STDIO_TOOL_CALL_RETRY_DELAY_BASE_MS`) are parsed as base-10 integers. If parsing fails (e.g., the value is not a number, or the variable is empty/not set), the default value is used.
279
+
280
+
## Development
198
281
199
282
The MCP Proxy Server includes features to improve its resilience and the reliability of interactions with backend MCP services, ensuring smoother operations and more consistent tool execution.
0 commit comments