mirror of
https://github.com/affaan-m/ECC.git
synced 2026-09-03 06:34:16 +08:00
fix(hooks): keep MCP reachability probes bounded
Remove the redundant JSON-RPC initialize fallback from the consolidated MCP health-check batch. A routed 404 already proves the endpoint is reachable, and the real authenticated MCP call remains authoritative. Avoiding the fallback also prevents a stalled GET plus stalled POST from consuming twice the configured hook timeout.
This commit is contained in:
@@ -256,28 +256,19 @@ function detectFailureCode(text) {
|
||||
return null;
|
||||
}
|
||||
|
||||
function requestHttp(urlString, headers, timeoutMs, options = {}) {
|
||||
function requestHttp(urlString, headers, timeoutMs) {
|
||||
return new Promise(resolve => {
|
||||
let settled = false;
|
||||
let timedOut = false;
|
||||
|
||||
const url = new URL(urlString);
|
||||
const client = url.protocol === 'https:' ? https : http;
|
||||
const method = options.method || 'GET';
|
||||
const body = options.body || null;
|
||||
const requestHeaders = { ...headers };
|
||||
|
||||
if (body) {
|
||||
requestHeaders['content-type'] = 'application/json';
|
||||
requestHeaders['content-length'] = Buffer.byteLength(body);
|
||||
requestHeaders.accept = 'application/json, text/event-stream';
|
||||
}
|
||||
|
||||
const req = client.request(
|
||||
url,
|
||||
{
|
||||
method,
|
||||
headers: requestHeaders,
|
||||
method: 'GET',
|
||||
headers,
|
||||
},
|
||||
res => {
|
||||
if (settled) return;
|
||||
@@ -306,23 +297,7 @@ function requestHttp(urlString, headers, timeoutMs, options = {}) {
|
||||
});
|
||||
});
|
||||
|
||||
req.end(body || undefined);
|
||||
});
|
||||
}
|
||||
|
||||
// Some Streamable HTTP MCP servers (e.g. api.telnyx.com/v2/mcp) only route POST
|
||||
// and answer any GET with 404, so a bare GET proves nothing. Replay the probe as
|
||||
// a real JSON-RPC initialize before declaring the server unreachable.
|
||||
function mcpInitializeBody() {
|
||||
return JSON.stringify({
|
||||
jsonrpc: '2.0',
|
||||
id: 1,
|
||||
method: 'initialize',
|
||||
params: {
|
||||
protocolVersion: '2025-06-18',
|
||||
capabilities: {},
|
||||
clientInfo: { name: 'ecc-mcp-health-check', version: '1' }
|
||||
}
|
||||
req.end();
|
||||
});
|
||||
}
|
||||
|
||||
@@ -541,19 +516,7 @@ async function probeServer(serverName, resolvedConfig) {
|
||||
const config = resolvedConfig.config;
|
||||
|
||||
if (config.type === 'http' || config.url) {
|
||||
const timeoutMs = envNumber('ECC_MCP_HEALTH_TIMEOUT_MS', DEFAULT_TIMEOUT_MS);
|
||||
let result = await requestHttp(config.url, config.headers || {}, timeoutMs);
|
||||
|
||||
if (!result.ok) {
|
||||
const posted = await requestHttp(config.url, config.headers || {}, timeoutMs, {
|
||||
method: 'POST',
|
||||
body: mcpInitializeBody()
|
||||
});
|
||||
|
||||
if (posted.ok) {
|
||||
result = posted;
|
||||
}
|
||||
}
|
||||
const result = await requestHttp(config.url, config.headers || {}, envNumber('ECC_MCP_HEALTH_TIMEOUT_MS', DEFAULT_TIMEOUT_MS));
|
||||
|
||||
return {
|
||||
ok: result.ok,
|
||||
|
||||
Reference in New Issue
Block a user