fix(vtex): repair broken GET_HOME_TOP_VIEWED_PRODUCTS and LIST_COLLECTIONS - #544
Merged
Conversation
…lections
- GET_HOME_TOP_VIEWED_PRODUCTS returned a bare array, violating the MCP
structuredContent record contract (-32602). Wrap it in `{ items }` and
declare an outputSchema, matching the tool adapter's array normalization.
- LIST_COLLECTIONS used the generated `/collection/inactive` operation, which
only returns inactive collections. Replace it with a custom tool that pages
the catalog search endpoint (blank term) to list all collections.
- Document known API behaviors in tool descriptions: ORDERS_TIMELINE totalValue
is 0 on the analytics path (no per-bucket revenue), and GET_COLLECTION_PRODUCTS
returns empty for automatic (rule-based) collections.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes 4 issues reported against the VTEX MCP tools. Two were real bugs (fixed); two were API behaviors surfaced through misleading tool descriptions (now documented accurately).
Changes
🔴 GET_HOME_TOP_VIEWED_PRODUCTS — broken (fixed)
The handler returned the raw JSON array from the analytics endpoint. MCP
structuredContentmust be a record, so every call failed with-32602: expected record, received array. It was also the only home-analytics tool without anoutputSchema.Fix: wrap the payload as
{ items: [...] }and declare a matchingoutputSchema— the same normalization the tool adapter andorders-sales-card.tsalready apply to array payloads.🟡 LIST_COLLECTIONS — returned empty (fixed properly)
The tool used the generated
getAllInactiveCollectionsoperation (/api/catalog/pvt/collection/inactive), which by design returns only inactive collections — so stores with active collections got{ items: [] }.Fix: replaced it with a custom tool backed by
/api/catalog_system/pvt/collection/search(the same endpointSEARCH_COLLECTIONSuses), which returns all collections when paged with a blank term. Pagination is extracted into a purecollectAllCollections(fetchPage, pageSize)helper (stops on a short page, on reachingpaging.total, or at a 100-page cap) with unit tests.🟡 ORDERS_TIMELINE —
totalValuealways 0 (documented)The primary
home-orders-trendanalytics endpoint reports only per-bucket order counts, not revenue, sototalValueis 0 on that path (the OMS fallback populates it). Not fixable without adding 24 OMS requests, defeating the single-request design. Description now points toORDERS_SALES_CARDfor hourly revenue.🟡 GET_COLLECTION_PRODUCTS — automatic collections empty (documented)
Genuine VTEX behavior: automatic (rule-based) collections resolve their products at query time and return
TotalRows: 0from this endpoint. Description updated to explain it.Testing
collectAllCollections(multi-page, single-page early stop, empty, missingpaging.total).items+paging.total) is based on VTEX's documented contract and the existingSEARCH_COLLECTIONStool. Worth a sanity check against a real store before merge.🤖 Generated with Claude Code
Summary by cubic
Fixes VTEX tools by repairing GET_HOME_TOP_VIEWED_PRODUCTS and updating LIST_COLLECTIONS to return all collections; also clarifies two API behaviors so callers get correct results and expectations.
Written for commit 4322fc9. Summary will update on new commits.