mastra-ai/mastra · error · HTTPException
Failed to resolve created MCP client
Error message
Failed to resolve created MCP client
What it means
HTTP 500 thrown when, immediately after successfully creating the stored MCP client, the follow-up getByIdResolved(id, { status: 'draft' }) returns null. This indicates an internal consistency failure: the record was written but cannot be read back as a resolved (thin record + version config) entity. It is not caused by user input.
Source
Thrown at packages/server/src/server/handlers/stored-mcp-clients.ts:166
throw new HTTPException(409, { message: `MCP client with id ${id} already exists` });
}
await mcpClientStore.create({
mcpClient: {
id,
authorId,
metadata: scopeStoredResourceMetadata(metadata, await getStoredResourceScope(mastra, requestContext)),
name,
description,
servers,
},
});
// Return the resolved MCP client (thin record + version config)
// Use draft status since newly created entities start as drafts
const resolved = await mcpClientStore.getByIdResolved(id, { status: 'draft' });
if (!resolved) {
throw new HTTPException(500, { message: 'Failed to resolve created MCP client' });
}
return resolved;
} catch (error) {
return handleError(error, 'Error creating stored MCP client');
}
},
});
/**
* PATCH /stored/mcp-clients/:storedMCPClientId - Update a stored MCP client
*/
export const UPDATE_STORED_MCP_CLIENT_ROUTE = createRoute({
method: 'PATCH',
path: '/stored/mcp-clients/:storedMCPClientId',
responseType: 'json',
pathParamSchema: storedMCPClientIdPathParams,
bodySchema: updateStoredMCPClientBodySchema,View on GitHub (pinned to 75dd419e61)
Solutions
- Use an officially supported storage adapter with complete getByIdResolved support.
- Retry the GET after creation to rule out replication/consistency lag.
- Check storage adapter version compatibility with your @mastra/core version and upgrade.
- Report/pin down with the adapter vendor if a supported adapter reproduces this reliably.
Example fix
// before
const store = await storage.getStore('mcpClients');
await store.create({ mcpClient }); // replica lag may break next read
const resolved = await store.getByIdResolved(id, { status: 'draft' });
// after
await store.create({ mcpClient });
await new Promise(r => setTimeout(r, 100)); // allow read consistency
const resolved = await store.getByIdResolved(id, { status: 'draft' }); Defensive patterns
Strategy: retry
Try / catch
let lastErr;
for (let i = 0; i < 3; i++) {
const res = await fetch(`/api/mcp/clients/${id}?status=draft`);
if (res.ok) return res.json();
lastErr = res.status;
await new Promise(r => setTimeout(r, 200 * (i + 1)));
}
throw new Error(`Created client ${id} not resolvable after retries (last: ${lastErr})`); Prevention
- Use officially supported adapters with complete getByIdResolved implementations.
- Allow brief read-consistency delay after writes on replica/eventual-consistency stores.
- Keep storage and core versions in lockstep.
- Alert on this 500 — it signals an internal bug, not user error.
When it happens
Trigger: A race or storage-layer bug where create() commits but getByIdResolved with status 'draft' cannot find/resolve the row; a custom storage adapter whose getByIdResolved does not handle freshly written records or the draft status.
Common situations: Custom/experimental storage adapters with incomplete getByIdResolved implementations; read-replica lag where the read goes to a replica not yet updated; eventual-consistency stores (e.g. DynamoDB-backed adapters) queried instantly after write.
Related errors
- Storage is not configured
- MCP clients storage domain is not available
- Failed to retrieve created version
- Failed to resolve updated MCP client
- Failed to resolve created skill
AI-assisted analysis of mastra-ai/mastra@75dd419e61 (2026-08-30).
Data as JSON: /api/errors/bfb63e673a424196.
Report an issue: GitHub.