Skip to content

feat(vtex): expose param descriptions to the agent (sync client + Zod metadata) - #525

Merged
guitavano merged 3 commits into
mainfrom
guitavano/vtex-enable-descriptions
Jul 27, 2026
Merged

feat(vtex): expose param descriptions to the agent (sync client + Zod metadata)#525
guitavano merged 3 commits into
mainfrom
guitavano/vtex-enable-descriptions

Conversation

@guitavano

@guitavano guitavano commented Jul 27, 2026

Copy link
Copy Markdown
Contributor

Single PR covering the whole fix. Supersedes #523, #524 (now closed).

Problem

An agent on the VTEX MCP couldn't tell it needed f_RnB to count sales for a coupon/promotion (e.g. FICA10 / "Pop retenção DECO"). Root cause: the agent received no description for any parameter of any tool. The generated Zod schemas were built with metadata: false (comment: "descriptions are not read at runtime" — inaccurate for an MCP: the input schema becomes the JSON Schema sent to the LLM). Every f_ filter reached the agent as a bare string.

The global fix

One line — metadata: falsetrue in openapi-ts.config.ts — then regenerate. This turns on descriptions for every field of every tool at once. The *.gen.ts changes are generator output (bun run openapi), not hand edits.

What's in this PR (3 commits)

  1. chore: regenerate client from current upstream — the committed client had drifted; regenerating surfaced 8 renamed/removed operations. Reconciles registry.ts (6 renames; removes VTEX_GET_ROLES_BY_USER2 and VTEX_ORDER_CHANGES_POST_CHANGE, whose endpoints no longer exist upstream). Doing the sync first keeps the metadata step a clean, description-only diff. (Only hand edit: registry.ts.)
  2. feat: enable Zod metadata — flips the flag + regenerates. sdk.gen.ts/types.gen.ts are byte-identical to commit 1; only zod.gen.ts files change (fields reflow to add .register(z.globalRegistry, { description })). (Only hand edit: 1 line in the config.)
  3. fix: curated param descriptions — layers richer-than-OpenAPI text on the params where VTEX's own wording is jargon (adapter-level, param-descriptions.ts). Notably f_RnB now explains it takes the promotion id, not the coupon code, and that FICA10 / a promotion name must be resolved via the promotions tools first.

Why the diff is huge but the review surface is tiny

  • 226 files in commit 1: new upstream modules + drift, all machine-generated. Real hand edit = registry.ts.
  • ~39k lines in commit 2: adding .register() reflows every described field across 13.7k fields. No operation/schema change — proven by sdk/types being byte-identical.

Cost (measured)

Server bundle 4.70 → 6.05 MB raw, 629 → 944 KB gzipped (+301 KB / +47%). Inherent — description strings must ship to reach the LLM. Truncating to 120 chars saved only ~34 KB gzip while cutting the value-format examples, so descriptions are kept full.

Verification

  • Build warning-free; 107 tests pass; no project typecheck errors.
  • End-to-end via z.toJSONSchema: f_RnB/f_status descriptions land in the agent-facing schema; the curated f_RnB text wins over the raw generated one.
  • Guard test so metadata: false can't silently return.

🤖 Generated with Claude Code

guitavano and others added 3 commits July 27, 2026 11:23
Regenerates the hey-api client from the latest VTEX OpenAPI schemas.
Upstream renamed several operations and removed two; this reconciles the
tool registry so no tool references a now-undefined SDK export.

Renamed operations (registry references updated):
- punchout: {get,post}ApiAuthenticatorPunchout* -> *V1Punchout*
- vtex-id: postApiAuthenticatorStorefrontUsers -> *V1StorefrontUsers
- delivery-promise-notification: {put,patch}DeliveryPromisesExternalSellers*
  -> {put,patch}ApiDeliveryPromisesExternalSellers*

Removed tools (endpoints no longer in upstream schemas):
- VTEX_GET_ROLES_BY_USER2 (getRolesbyUser2) — alternate endpoint dropped;
  VTEX_GET_ROLES_BY_USER (getRolesbyUser) remains.
- VTEX_ORDER_CHANGES_POST_CHANGE (postOrderChanges) — removed from the
  pick-and-pack-order-changes schema.

Prereq for enabling zod metadata (param descriptions): doing that regen on
top of a current client yields a description-only diff. Build is warning-free;
all 104 tests pass. metadata stays false here (no bundle change).

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Flips `metadata: false` -> `true` in openapi-ts.config.ts and regenerates.
The generated Zod request schemas now carry field descriptions, which flow
through the tool adapter into each tool's inputSchema — i.e. the JSON Schema
sent to the LLM. Previously every param (e.g. orders `f_RnB`) reached the
agent as a bare `string` with no meaning or value-format hint.

Stacked on the client-sync PR, so this diff is metadata-only: sdk.gen.ts and
types.gen.ts are byte-identical to the base; only zod.gen.ts files change
(field lines reflow to add `.register(z.globalRegistry, { description })`).

Cost (measured): server bundle 4.70 -> 6.05 MB raw, 629 -> 944 KB gzipped
(+301 KB / +47%) — inherent, the description strings must ship to reach the
LLM. Truncating to 120 chars saved only ~34 KB gzip while cutting the
value-format examples, so descriptions are kept full.

Adds a guard test so `metadata: false` can't silently return. All tests pass.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Generated Zod schemas are produced with `metadata: false`, so no field
description reaches the tool inputSchema (the JSON Schema the LLM sees).
Agents got bare `f_RnB: string` with no hint of meaning or value format —
which is why an agent couldn't map a coupon/promotion query to `f_RnB`.

Rather than re-enabling metadata globally (measured: +1.57 MB / +35% server
bundle, plus unrelated upstream schema drift and a broken export on regen),
layer curated descriptions onto the flattened input schema in the tool
adapter. Covers the params where the omission hurts on VTEX_LIST_ORDERS
(f_RnB, date ranges, status, full-text q), written richer than the raw
OpenAPI text — e.g. f_RnB now explains the coupon -> promotion-id lookup.

Bundle unchanged (4.70 MB). Adds regression tests asserting descriptions
reach the agent-facing JSON Schema and that overrides keep fields optional.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@guitavano guitavano changed the title feat(vtex): enable Zod metadata so param descriptions reach the agent feat(vtex): expose param descriptions to the agent (sync client + Zod metadata) Jul 27, 2026
@guitavano
guitavano changed the base branch from guitavano/vtex-sync-client to main July 27, 2026 14:33
@guitavano
guitavano merged commit 4dd867a into main Jul 27, 2026
2 checks passed
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.

1 participant