mastra-ai/mastra · error

MCP server with id ${id} not found

Error message

MCP server with id ${id} not found

What it means

Thrown by `update` in the in-memory MCP servers domain when no MCP server with the given id is stored. Updates mutate only existing records and will not create one implicitly.

Source

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

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

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

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

    const existingConfig = this.db.mcpServers.get(id);
    if (!existingConfig) {
      throw new Error(`MCP server 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: StorageMCPServerType = {
      ...existingConfig,
      ...(authorId !== undefined && { authorId }),
      ...(activeVersionId !== undefined && { activeVersionId }),
      ...(status !== undefined && { status: status as StorageMCPServerType['status'] }),
      ...(metadata !== undefined && {
        metadata: { ...existingConfig.metadata, ...metadata },
      }),
      updatedAt: new Date(),
    };

    // Save the updated record

View on GitHub (pinned to 75dd419e61)

Solutions

  1. Verify the server exists (get/list) before updating.
  2. Implement upsert: fall back to create when update reports not-found.
  3. Share one storage instance across the code path performing create and update.

Example fix

// before
await mcpServers.update({ id: serverId, status: 'active' });
// after
try {
  await mcpServers.update({ id: serverId, status: 'active' });
} catch (e) {
  if (!/not found/.test(String(e))) throw e;
  await mcpServers.create({ mcpServer: { id: serverId } });
}
Defensive patterns

Strategy: try-catch

Validate before calling

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

Try / catch

try {
  await mcpServers.update({ id, ...updates });
} catch (err) {
  if (err instanceof Error && /not found/.test(err.message)) {
    // surface 404 or create the record
    return;
  }
  throw err;
}

Prevention

When it happens

Trigger: Calling `storage.mcpServers.update({ id, ...updates })` with an id absent from the map — never created, created in a different storage instance, or already deleted.

Common situations: Stale references after storage re-instantiation between tests; ids from another environment; typos or changed id schemes.

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/f27cb672489a6f49. Report an issue: GitHub.