@anyshift/mcp-proxy 0.6.3 → 0.6.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.js +36 -16
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -19,6 +19,7 @@ import { StdioServerTransport } from '@modelcontextprotocol/sdk/server/stdio.js'
|
|
|
19
19
|
import { Client } from '@modelcontextprotocol/sdk/client/index.js';
|
|
20
20
|
import { StdioClientTransport } from '@modelcontextprotocol/sdk/client/stdio.js';
|
|
21
21
|
import { SSEClientTransport } from '@modelcontextprotocol/sdk/client/sse.js';
|
|
22
|
+
import { StreamableHTTPClientTransport } from '@modelcontextprotocol/sdk/client/streamableHttp.js';
|
|
22
23
|
import { ListToolsRequestSchema, CallToolRequestSchema } from '@modelcontextprotocol/sdk/types.js';
|
|
23
24
|
import { createJqTool } from './jq/index.js';
|
|
24
25
|
import { createTimeseriesTool } from './timeseries/index.js';
|
|
@@ -119,11 +120,16 @@ const CHILD_ARGS = process.env.MCP_PROXY_CHILD_ARGS
|
|
|
119
120
|
: [];
|
|
120
121
|
/**
|
|
121
122
|
* MCP_PROXY_REMOTE_URL (OPTIONAL)
|
|
122
|
-
*
|
|
123
|
-
* When set, the proxy connects as an SSE client to the remote server
|
|
123
|
+
* URL of a remote MCP server to connect to instead of spawning a child process
|
|
124
124
|
* Example: "http://internal-server:3100/sse"
|
|
125
125
|
*/
|
|
126
126
|
const REMOTE_URL = process.env.MCP_PROXY_REMOTE_URL;
|
|
127
|
+
/**
|
|
128
|
+
* MCP_PROXY_REMOTE_TRANSPORT (OPTIONAL, default: "sse")
|
|
129
|
+
* Transport protocol for connecting to a remote MCP server.
|
|
130
|
+
* Values: "sse" (legacy GET-based SSE), "streamable-http" (POST-based, newer MCP spec)
|
|
131
|
+
*/
|
|
132
|
+
const REMOTE_TRANSPORT = process.env.MCP_PROXY_REMOTE_TRANSPORT || 'sse';
|
|
127
133
|
/**
|
|
128
134
|
* MCP_PROXY_REMOTE_HEADERS (OPTIONAL)
|
|
129
135
|
* JSON string of custom headers to send with SSE/POST requests to the remote server
|
|
@@ -175,6 +181,12 @@ const MIN_CHARS_FOR_WRITE = parseInt(process.env.MCP_PROXY_MIN_CHARS_FOR_WRITE |
|
|
|
175
181
|
* The JQ tool is added to the list of available tools from the child MCP
|
|
176
182
|
*/
|
|
177
183
|
const ENABLE_JQ = process.env.MCP_PROXY_ENABLE_JQ !== 'false'; // default true
|
|
184
|
+
/**
|
|
185
|
+
* MCP_PROXY_REQUEST_TIMEOUT_MS (OPTIONAL, default: 60000)
|
|
186
|
+
* Timeout in milliseconds for requests forwarded to the child/remote MCP server.
|
|
187
|
+
* Increase for long-running tools (e.g. agent-gateway's analyze_code).
|
|
188
|
+
*/
|
|
189
|
+
const REQUEST_TIMEOUT_MS = parseInt(process.env.MCP_PROXY_REQUEST_TIMEOUT_MS || '60000');
|
|
178
190
|
/**
|
|
179
191
|
* MCP_PROXY_JQ_TIMEOUT_MS (OPTIONAL, default: 30000)
|
|
180
192
|
* Timeout in milliseconds for JQ query execution
|
|
@@ -295,7 +307,7 @@ for (const [key, value] of Object.entries(process.env)) {
|
|
|
295
307
|
// ============================================================================
|
|
296
308
|
if (ENABLE_LOGGING) {
|
|
297
309
|
console.debug('[mcp-proxy] Configuration:');
|
|
298
|
-
console.debug(` Mode: ${REMOTE_URL ?
|
|
310
|
+
console.debug(` Mode: ${REMOTE_URL ? `remote (${REMOTE_TRANSPORT})` : CHILD_COMMAND ? 'wrapper' : 'standalone (JQ only)'}`);
|
|
299
311
|
if (REMOTE_URL) {
|
|
300
312
|
console.debug(` Remote URL: ${REMOTE_URL}`);
|
|
301
313
|
console.debug(` Remote headers: ${REMOTE_HEADERS ? 'configured' : 'none'}`);
|
|
@@ -360,20 +372,26 @@ async function main() {
|
|
|
360
372
|
}
|
|
361
373
|
headers['X-Client-Credentials'] = REMOTE_CREDENTIALS;
|
|
362
374
|
}
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
375
|
+
let childTransport;
|
|
376
|
+
if (REMOTE_TRANSPORT === 'streamable-http') {
|
|
377
|
+
childTransport = new StreamableHTTPClientTransport(new URL(REMOTE_URL), {
|
|
378
|
+
requestInit: { headers },
|
|
379
|
+
});
|
|
380
|
+
}
|
|
381
|
+
else {
|
|
382
|
+
childTransport = new SSEClientTransport(new URL(REMOTE_URL), {
|
|
383
|
+
eventSourceInit: {
|
|
384
|
+
fetch: (url, init) => {
|
|
385
|
+
const merged = new Headers(init?.headers);
|
|
386
|
+
for (const [key, value] of Object.entries(headers)) {
|
|
387
|
+
merged.set(key, value);
|
|
388
|
+
}
|
|
389
|
+
return fetch(url, { ...init, headers: merged });
|
|
390
|
+
},
|
|
373
391
|
},
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
}
|
|
392
|
+
requestInit: { headers },
|
|
393
|
+
});
|
|
394
|
+
}
|
|
377
395
|
childClient = new Client({
|
|
378
396
|
name: 'mcp-proxy-client',
|
|
379
397
|
version: '1.0.0'
|
|
@@ -691,6 +709,8 @@ async function main() {
|
|
|
691
709
|
result = await childClient.callTool({
|
|
692
710
|
name: toolName,
|
|
693
711
|
arguments: sanitizedArgs
|
|
712
|
+
}, undefined, {
|
|
713
|
+
timeout: REQUEST_TIMEOUT_MS
|
|
694
714
|
});
|
|
695
715
|
// Check if child MCP returned an error
|
|
696
716
|
const childReturnedError = !!result.isError;
|