vercel/ai · error · MCPClientError
Server sent invalid initialize result
Error message
Server sent invalid initialize result
What it means
Thrown during MCPClient.init when the 'initialize' request resolves with undefined — i.e. the server's response failed to validate against InitializeResultSchema or the request produced no result. This indicates a malformed or non-compliant server response to the MCP handshake.
Source
Thrown at packages/mcp/src/tool/mcp-client.ts:568
this.protocolEra = 'legacy';
this.protocolVersion = LATEST_LEGACY_PROTOCOL_VERSION;
this.setTransportProtocolVersion(this.protocolVersion);
const result = await this.request({
request: {
method: 'initialize',
params: {
protocolVersion: LATEST_LEGACY_PROTOCOL_VERSION,
capabilities: this.clientCapabilities,
clientInfo: this.clientInfo,
},
},
resultSchema: InitializeResultSchema,
options: { signal },
});
if (result === undefined) {
throw new MCPClientError({
message: 'Server sent invalid initialize result',
});
}
this.applyInitializeResult(result);
// Complete initialization handshake:
await this.notification(
{
method: 'notifications/initialized',
},
{ signal },
);
return this;
} catch (error) {
try {
await waitForAbort(this.transport.close({ signal }), signal);View on GitHub (pinned to 69428b1f8b)
Solutions
- Inspect the raw initialize response from the server (curl the endpoint) to see what is actually returned.
- Update the MCP server to a spec-compliant version that returns protocolVersion, capabilities, and serverInfo.
- Verify you are pointing at the correct MCP endpoint URL and transport, not an HTML page or wrong route.
- Update @ai-sdk/mcp in case the schema expectations changed.
Example fix
// before (server response missing fields)
{ jsonrpc: '2.0', id: 1, result: { serverInfo: { name: 'x' } } }
// after (spec-compliant)
{ jsonrpc: '2.0', id: 1, result: { protocolVersion: '2025-06-18', capabilities: {}, serverInfo: { name: 'x', version: '1.0' } } } Defensive patterns
Strategy: try-catch
Validate before calling
const res = await fetch(mcpUrl, { method: 'POST', headers: { 'content-type': 'application/json' }, body: JSON.stringify({ jsonrpc: '2.0', id: 1, method: 'initialize', params: { protocolVersion: '2025-06-18', capabilities: {}, clientInfo: { name: 'probe', version: '0' } } }) });
const body = await res.json();
if (!body?.result?.protocolVersion || !body?.result?.serverInfo) throw new Error('Endpoint is not a compliant MCP server'); Type guard
function isInitializeResult(r: unknown): r is { protocolVersion: string; capabilities: object; serverInfo: { name: string; version: string } } {
return !!r && typeof r === 'object' && 'protocolVersion' in r && 'capabilities' in r && 'serverInfo' in r;
} Try / catch
try {
const client = await createMCPClient({ transport });
} catch (e) {
if (MCPClientError.isInstance(e) && e.message === 'Server sent invalid initialize result') {
// inspect raw server response / verify endpoint URL
} else throw e;
} Prevention
- Probe the MCP endpoint with a raw initialize request before wiring the client
- Confirm the URL points at the MCP route, not an HTML page
- Keep server and client MCP SDK versions aligned
When it happens
Trigger: The server replies to the initialize request with a payload missing required fields (protocolVersion, capabilities, serverInfo) or with invalid shapes, causing schema validation to fail and result to be undefined.
Common situations: Connecting to a non-MCP or partially-implemented HTTP/SSE endpoint; a proxy returning HTML error pages; protocol version drift where the server speaks an incompatible response format; server bugs after upgrades.
Related errors
- ACP session initialization did not produce a session.
- Server does not support the requested protocol version: ${th
- Server's protocol version is not supported: ${result.protoco
- CODE_MODE_PROTOCOL_ERROR
- CODE_MODE_PROTOCOL_ERROR
AI-assisted analysis of vercel/ai@69428b1f8b (2026-08-30).
Data as JSON: /api/errors/e648a81fefc68c0b.
Report an issue: GitHub.