mastra-ai/mastra · error · HTTPException

Failed to retrieve created version

Error message

Failed to retrieve created version

What it means

This 500 is thrown when a version was just created via the store's create-version operation but the subsequent getVersion(versionId) call cannot retrieve it. It indicates an internal inconsistency between the store's write and read paths rather than a user error.

Source

Thrown at packages/server/src/server/handlers/mcp-client-versions.ts:150

            latestVersion as unknown as Record<string, unknown>,
            MCP_CLIENT_SNAPSHOT_CONFIG_FIELDS,
          )
        : null;

      const changedFields = calculateChangedFields(previousConfig, currentConfig);

      const { versionId } = await createVersionWithRetry(
        mcpClientStore as unknown as VersionedStoreInterface,
        mcpClientId,
        'mcpClientId',
        currentConfig,
        changedFields,
        { changeMessage },
      );

      const version = await mcpClientStore.getVersion(versionId);
      if (!version) {
        throw new HTTPException(500, { message: 'Failed to retrieve created version' });
      }

      await enforceRetentionLimit(
        mcpClientStore as unknown as VersionedStoreInterface,
        mcpClientId,
        'mcpClientId',
        mcpClient.activeVersionId,
      );

      return version;
    } catch (error) {
      return handleError(error, 'Error creating MCP client version');
    }
  },
});

/**
 * GET /stored/mcp-clients/:mcpClientId/versions/:versionId - Get a specific version

View on GitHub (pinned to 75dd419e61)

Solutions

  1. Retry the request; if transient replication lag caused it, the version will be readable
  2. Verify the storage adapter's createVersion/getVersion implementation commits before returning
  3. Check the storage backend logs for failed writes
  4. Upgrade @mastra/core storage packages to the latest patch version

Example fix

null
Defensive patterns

Strategy: retry

Validate before calling

null

Type guard

null

Try / catch

try {
  const res = await fetch(`/api/mcp-clients/${id}/versions`, { method: 'POST', ... });
  if (res.status === 500) {
    // retry once after short delay; likely read-after-write lag
    await new Promise(r => setTimeout(r, 500));
    return retryOnce();
  }
  return await res.json();
} catch (err) {
  // log and fall back to listing versions to confirm creation
}

Prevention

When it happens

Trigger: Creating a new MCP client version via the endpoint; the create call returns a versionId, but mcpClientStore.getVersion(versionId) immediately afterwards returns null (store write not yet visible to reads, or a faulty storage adapter).

Common situations: Using a custom/storage adapter whose create-version does not commit synchronously; eventual-consistency lag in the backing database; a bug in a third-party storage driver.

Related errors


AI-assisted analysis of mastra-ai/mastra@75dd419e61 (2026-08-30). Data as JSON: /api/errors/d4469206322f8614. Report an issue: GitHub.