Skip to content

armgit / eve

Public Imported from GitHub
0

The Open Framework for Building Agents

fix(eve): wait for slow MCP server/discover over HTTP instead of falling back to legacy initialize (#4334)

e0-gh-vercel-connect[bot]58a68ddac780
diff --git a/.changeset/mcp-http-slow-discovery.md b/.changeset/mcp-http-slow-discovery.md
new file mode 100644
index 000000000..577738fc6
--- /dev/null
+++ b/.changeset/mcp-http-slow-discovery.md
@@ -0,0 +1,5 @@
+---
+"eve": patch
+---
+
+Keep MCP connections over HTTP on the `2026-07-28` protocol when the server is slow to answer `server/discover`. Previously eve gave up after 1 s and fell back to the legacy handshake, which servers that only speak the new protocol reject with `Unsupported protocol version: 2025-11-25`.
diff --git a/packages/eve/scripts/vendor-compiled/@ai-sdk/mcp.mjs b/packages/eve/scripts/vendor-compiled/@ai-sdk/mcp.mjs
index ab1acc9ea..18451931c 100644
--- a/packages/eve/scripts/vendor-compiled/@ai-sdk/mcp.mjs
+++ b/packages/eve/scripts/vendor-compiled/@ai-sdk/mcp.mjs
@@ -1,9 +1,45 @@
import { createDeclarationCopier } from "../_shared.mjs";
+const DISCOVERY_TIMEOUT_SOURCE = "timeout: DEFAULT_PROTOCOL_DISCOVERY_TIMEOUT";
+const HTTP_DISCOVERY_TIMEOUT_SOURCE =
+ "timeout: this.transport instanceof HttpMCPTransport ? void 0 : DEFAULT_PROTOCOL_DISCOVERY_TIMEOUT";
+
+// Streamable HTTP always answers, so a slow `server/discover` is not a legacy
+// signal: the MCP spec falls back there only on a 4xx. Upstream caps the probe
+// at 1 s on every transport and then downgrades modern-only servers to
+// `initialize`. Remove once @ai-sdk/mcp ships vercel/ai#22042; the contract
+// check below fails the build when that line changes.
+function waitForHttpProtocolDiscoveryPlugin() {
+ let patched = false;
+
+ return {
+ name: "eve-ai-sdk-mcp-wait-for-http-discovery",
+ transform(code, id) {
+ if (!id.replaceAll("\\", "/").endsWith("/@ai-sdk/mcp/dist/index.js")) {
+ return null;
+ }
+ if (!code.includes(DISCOVERY_TIMEOUT_SOURCE)) {
+ throw new Error("@ai-sdk/mcp's server/discover timeout contract changed.");
+ }
+ patched = true;
+ return {
+ code: code.replace(DISCOVERY_TIMEOUT_SOURCE, HTTP_DISCOVERY_TIMEOUT_SOURCE),
+ map: null,
+ };
+ },
+ buildEnd() {
+ if (!patched) {
+ throw new Error("@ai-sdk/mcp's server/discover timeout was not patched.");
+ }
+ },
+ };
+}
+
export default {
packageName: "@ai-sdk/mcp",
compiledPath: "@ai-sdk/mcp",
chunkGroup: "workflow",
+ plugins: [waitForHttpProtocolDiscoveryPlugin()],
copyDeclarations: createDeclarationCopier({
rewrites: {
"@ai-sdk/provider": { kind: "vendored", compiledPath: "@ai-sdk/provider" },
diff --git a/packages/eve/src/runtime/connections/mcp-client.integration.test.ts b/packages/eve/src/runtime/connections/mcp-client.integration.test.ts
index 66b764884..fe955a27e 100644
--- a/packages/eve/src/runtime/connections/mcp-client.integration.test.ts
+++ b/packages/eve/src/runtime/connections/mcp-client.integration.test.ts
@@ -18,6 +18,7 @@ describe.each(["static", "dynamic"] as const)(
const requests: { method: string; protocolVersion: string | null }[] = [];
let client: McpConnectionClient;
let discoveryError: { code: number; message: string; data?: unknown } | undefined;
+ let discoveryDelayMs: number;
let initializeError: { code: number; message: string } | undefined;
let callResult: Record<string, unknown>;
@@ -67,6 +68,7 @@ describe.each(["static", "dynamic"] as const)(
},
message: "Unsupported protocol version",
};
+ discoveryDelayMs = 0;
initializeError = undefined;
callResult = { content: [{ type: "text", text: "fixture-user" }] };
@@ -88,6 +90,7 @@ describe.each(["static", "dynamic"] as const)(
let result: Record<string, unknown>;
switch (message.method) {
case "server/discover":
+ await new Promise((resolve) => setTimeout(resolve, discoveryDelayMs));
if (discoveryError !== undefined) {
return Response.json({ jsonrpc: "2.0", id: message.id, error: discoveryError });
}
@@ -129,6 +132,7 @@ describe.each(["static", "dynamic"] as const)(
afterEach(async () => {
await client?.close();
+ vi.useRealTimers();
vi.unstubAllGlobals();
});
@@ -167,6 +171,25 @@ describe.each(["static", "dynamic"] as const)(
expect(requests).toEqual([{ method: "server/discover", protocolVersion: "2026-07-28" }]);
});
+ it("stays on the modern protocol when a modern-only server answers discovery slowly", async () => {
+ vi.useFakeTimers({ toFake: ["setTimeout", "clearTimeout"] });
+ await createClient();
+ discoveryError = undefined;
+ discoveryDelayMs = 2_000;
+ initializeError = { code: -32022, message: "Unsupported protocol version: 2025-11-25" };
+
+ await Promise.all([
+ expect(client.getToolMetadata()).resolves.toEqual([
+ expect.objectContaining({ name: "getMyUser" }),
+ ]),
+ vi.advanceTimersByTimeAsync(discoveryDelayMs),
+ ]);
+ expect(requests).toEqual([
+ { method: "server/discover", protocolVersion: "2026-07-28" },
+ { method: "tools/list", protocolVersion: "2026-07-28" },
+ ]);
+ });
+
it("propagates a failed handshake without retrying it or switching transports", async () => {
await createClient(false);
initializeError = { code: -32603, message: "Initialization failed" };