mastra-ai/mastra · error

MCP client with id ${id} not found

Error message

MCP client with id ${id} not found

What it means

Thrown by `update` in the in-memory MCP clients domain when no client with the given id exists in the map. Update only mutates existing records; it never creates them. This is a look-before-mutate guard.

Source

Thrown at packages/core/src/storage/domains/mcp-clients/inmemory.ts:88

    await this.createVersion({
      id: versionId,
      mcpClientId: mcpClient.id,
      versionNumber: 1,
      ...snapshotConfig,
      changedFields: Object.keys(snapshotConfig),
      changeMessage: 'Initial version',
    });

    // Return the thin record
    return this.deepCopyConfig(newConfig);
  }

  async update(input: StorageUpdateMCPClientInput): Promise<StorageMCPClientType> {
    const { id, ...updates } = input;

    const existingConfig = this.db.mcpClients.get(id);
    if (!existingConfig) {
      throw new Error(`MCP client with id ${id} not found`);
    }

    // Separate metadata fields from config fields
    const { authorId, activeVersionId, metadata, status } = updates;

    // Update metadata fields on the record
    const updatedConfig: StorageMCPClientType = {
      ...existingConfig,
      ...(authorId !== undefined && { authorId }),
      ...(activeVersionId !== undefined && { activeVersionId }),
      ...(status !== undefined && { status: status as StorageMCPClientType['status'] }),
      ...(metadata !== undefined && {
        metadata: { ...existingConfig.metadata, ...metadata },
      }),
      updatedAt: new Date(),
    };

    // Save the updated record

View on GitHub (pinned to 75dd419e61)

Solutions

  1. Verify the client exists (list/get) before calling update.
  2. Create the client first if the id is expected to be new (upsert pattern: try update, fall back to create).
  3. Ensure the same storage instance is used across the operations in tests or runtime.

Example fix

// before
await mcpClients.update({ id: clientId, status: 'active' });
// after
const existing = await mcpClients.get(clientId);
if (!existing) await mcpClients.create({ mcpClient: { id: clientId } });
else await mcpClients.update({ id: clientId, status: 'active' });
Defensive patterns

Strategy: try-catch

Validate before calling

const existing = await mcpClients.get(id);
if (!existing) throw new Error(`Cannot update: MCP client ${id} does not exist`);

Try / catch

try {
  await mcpClients.update({ id, ...updates });
} catch (err) {
  if (err instanceof Error && /not found/.test(err.message)) {
    // handle missing record: create it or surface a 404
    return;
  }
  throw err;
}

Prevention

When it happens

Trigger: Calling `storage.mcpClients.update({ id, ...updates })` with an id that was never created, was created in a different storage instance, or belongs to a record that was removed.

Common situations: Hardcoded ids referencing another environment's data; operating on a stale reference after storage was re-instantiated (common in tests between test cases); typos in id strings.

Understand the failure class

Background: 'Could not be found', 'does not exist', 'not found in database': the resource-not-found family when an ID, slug, key, or URI lookup comes back empty — this error's family across 20 libraries.

Related errors


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