Skip to content

Bug: listVectorStores handler returns undefined id instead of fallback to vector name #15238

@kuishou68

Description

@kuishou68

Bug Report

Description

The legacy listVectorStores function in packages/server/src/server/handlers/vector.ts (lines 190-207) maps vector entries using id: vector.id without any fallback, which can produce undefined values when a MastraVector instance does not have an id property set.

This directly violates the listVectorsResponseSchema which declares id as a required z.string() field (non-optional):

// packages/server/src/server/schemas/vectors.ts
export const listVectorsResponseSchema = z.object({
  vectors: z.array(z.object({
    id: z.string(),   // <-- required, not optional
    name: z.string(),
    type: z.string(),
    ...
  }))
});

Root Cause

The newer LIST_VECTORS_ROUTE (lines 383-410) correctly uses:

id: vector.id || name,  // fallback to the registration key if id is not set

But the older standalone listVectorStores function uses:

id: vector.id,  // no fallback — can be undefined!

Impact

  • When a vector store is registered without an explicit id property, listVectorStores returns { id: undefined, name, type }
  • This fails Zod schema validation (schema expects a string, gets undefined)
  • Any client calling the legacy route gets malformed data or a runtime error

Fix

Apply the same id: vector.id || name fallback pattern used in LIST_VECTORS_ROUTE to the legacy listVectorStores function:

const vectorList = Object.entries(vectors).map(([name, vector]) => ({
  name,
  id: vector.id || name,  // fallback to registration key
  type: vector.constructor.name,
}));

File

packages/server/src/server/handlers/vector.tslistVectorStores function (~line 198)

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions