fix: improve MCP probe error reporting and SSE fallback

When SSE fallback gets 405 (confirming a Streamable HTTP server),
surface the original Streamable HTTP error instead of the misleading
SSE 405. Extract HTTP status codes from SDK error objects to produce
clearer log messages like 'HTTP 401: Streamable HTTP error: ...'.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
This commit is contained in:
David KayaandCopilot committed 2026-03-28 19:43:53 +01:00
1 parent e38a663834
commit 169a9617c8
1 file changed
+25 -5
+25 -5
View File
@@ -73,7 +73,7 @@ export async function probeServer(
status: 'success',
};
} catch (error) {
const message = error instanceof Error ? error.message : String(error);
const message = formatProbeError(error);
console.warn(`[aryx mcp-probe] ${server.name}: failed — ${message}`);
return {
serverId: server.id,
@@ -102,10 +102,17 @@ async function probeServerCore(
return await probeWithTransport(
new StreamableHTTPClientTransport(new URL(server.url), headerOpts),
);
} catch {
return probeWithTransport(
new SSEClientTransport(new URL(server.url), headerOpts),
);
} catch (streamableError) {
try {
return await probeWithTransport(
new SSEClientTransport(new URL(server.url), headerOpts),
);
} catch (sseError) {
// SSE 405 means the server IS Streamable HTTP — surface the original error.
const sseCode = (sseError as { code?: number }).code;
if (sseCode === 405) throw streamableError;
throw sseError;
}
}
}
@@ -177,6 +184,19 @@ function buildHeaders(
};
}
function formatProbeError(error: unknown): string {
if (!(error instanceof Error)) return String(error);
const httpCode = (error as { code?: number }).code;
const base = error.message;
if (typeof httpCode === 'number' && httpCode >= 100) {
return `HTTP ${httpCode}: ${base}`;
}
return base;
}
function withTimeout<T>(promise: Promise<T>, ms: number, message: string): Promise<T> {
return new Promise<T>((resolve, reject) => {
const timer = setTimeout(() => reject(new Error(message)), ms);