Skip to content

fix(mcp): surface real error in collection validation catch#383

Open
mvanhorn wants to merge 1 commit into
zilliztech:masterfrom
mvanhorn:osc/215-improve-collection-validation-error
Open

fix(mcp): surface real error in collection validation catch#383
mvanhorn wants to merge 1 commit into
zilliztech:masterfrom
mvanhorn:osc/215-improve-collection-validation-error

Conversation

@mvanhorn

Copy link
Copy Markdown
Contributor

Summary

Replace the err.message || err interpolation in the MCP catch blocks with a small formatValidationError helper so users see the actual error from Zilliz / Milvus instead of [object Object].

Why this matters

Issue #215 reports Error validating collection creation: [object Object] from index_codebase. Multiple users in the thread confirm the same opaque message (@DeadManPoe on Rust, @Wazabit on a NestJS TS codebase, @PeterSenyszyn, @mahmoudnaif, @KrustyHack). @PeterSenyszyn traced the root cause: Zilliz Cloud free tier caps collections at 5 per cluster, and the create call rejects past that.

The catch at packages/mcp/src/handlers.ts:463 interpolated ${validationError.message || validationError}. When validationError is a plain object without .message, the || fallback returns the object itself and template coercion produces [object Object]. The same antipattern repeats at four other catch sites in the file (cloud sync description, fallback query, snapshot delete, indexing dispatcher).

formatValidationError tries, in order:

  • err.message (when it's a non-empty string and not literally [object Object])
  • err.response.data.message
  • err.response.data.detail
  • err.response.statusText
  • JSON.stringify(err) (when the result is not {} or null)
  • String(err) (final fallback)

This turns the Zilliz collection-limit error and similar response-bearing errors into a readable message at every existing catch site without changing the surrounding flow. checkCollectionLimit itself is not modified; this is purely a presentation fix.

Testing

  • npx tsc --noEmit on packages/mcp passes.
  • No public API or schema changes; existing call sites unchanged.

Fixes #215

The catch block in handlers.ts interpolated `err.message || err`, which
falls through to default object stringification when the thrown value is
a plain object without a `.message` property. The user-facing MCP response
ended up reading "Error validating collection creation: [object Object]".

Replace the antipattern with a `formatValidationError` helper that tries
`err.message`, then nested `response.data.message` and `response.data.detail`,
then `response.statusText`, then JSON.stringify, and only falls back to
String(err) when nothing usable can be extracted. Apply the helper to the
same antipattern at the other catch sites in the file (sync, fallback
query, snapshot delete, indexing dispatcher).

`npx tsc --noEmit` on packages/mcp passes after this change.

Fixes zilliztech#215
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Indexing error : Error validating collection creation

1 participant