Skip to content

fix: read catalog stock bands (availability) instead of exact counts - #10

Merged
virtualsms-io merged 1 commit into
mainfrom
fix/catalog-stock-bands
Sep 23, 2026
Merged

virtualsms-io merged 1 commit into
mainfrom
fix/catalog-stock-bands

Conversation

@virtualsms-io

Copy link
Copy Markdown
Owner

Summary

The catalog API now returns a stock band (in_stock / low_stock / out_of_stock) alongside the legacy exact per-country count, and will stop sending the count entirely soon. This PR moves every in-stock check in the server onto the band:

  • Added src/stock.ts: catalogStockBand(row) reads availability when present, falls back to count thresholds for older payloads, and returns unknown (never in stock) when neither field is present. isCatalogInStock(row) wraps that into a boolean.
  • CatalogCountry.count is now optional; availability is the new authoritative field.
  • find_cheapest and the price-check stock guard both use the shared helper. Tool output now carries an availability band string per country instead of an exact stock integer or a bare stock: true flag.
  • Docs (src/resources.ts, README.md) updated to tell agents to read availability, not count.
  • Version bumped to 1.3.3 across package.json, server.json (root + packages[0]), .plugin/plugin.json, and the lockfile. This also fixes a pre-existing drift between package.json (1.3.1) and server.json (1.3.2) that the repo's own version-consistency.test.ts was already failing on.

Out of scope: rental tools (/api/v1/rentals/*, RentalCatalogService.physical_count) — those are a separate stock model and untouched.

Deviation from the original brief, flagged for review: the brief's "Tests" section assumed no test runner existed and asked for a new test/stock.test.mjs on Node's built-in runner, replacing the test npm script. That assumption doesn't hold — this repo already has a working Vitest suite (src/__tests__/**, 107 tests) wired to npm test. Replacing the test script would have silently stopped that whole suite from running in CI. Instead, the new coverage was added as src/stock.test.ts in the existing Vitest convention, and the test script/config were left untouched.

Test plan

  • npm ci
  • npm run build
  • npm test (Vitest) — 11 files, 113 tests passed, including the newly-added src/stock.test.ts (6 tests) and the previously-failing version-consistency.test.ts (now fixed by the aligned version bump)
  • grep -rnE "\.count\b|count >|count <=|'count'|\"count\"" src | grep -v -i "rental\|endpoint\|params.count\|args.count" — every remaining hit is transaction pagination (TransactionsPage.count), proxy-location result count, or the intentional legacy fallback inside src/stock.ts/client.ts's catalog mapping — none leak an exact catalog stock integer into tool output
 Test Files  11 passed (11)
      Tests  113 passed (113)
src/client.ts:685:      count: c.count === undefined || c.count === null ? undefined : Number(c.count),
src/client.ts:730:      count: Number(raw.count ?? items.length),
src/client.ts:978:      count: Number(it.count ?? 0),
src/stock.ts:23:  if (typeof row.count === 'number' && Number.isFinite(row.count)) {
src/stock.ts:24:    if (row.count <= 0) return 'out_of_stock';
src/stock.ts:25:    if (row.count <= 5) return 'low_stock';
src/tools.ts:2094:      count: page.count,
src/tools.ts:2106:          : page.count === page.limit

🤖 Generated with Claude Code

The catalog API is adding a stock band (in_stock/low_stock/out_of_stock)
alongside the legacy exact count and will stop sending the count. Every
in-stock check (find_cheapest, price checks) now reads the band via a
shared helper, falling back to count thresholds only for older payloads,
and tool output carries the band string instead of any exact integer.
Also aligns package.json/server.json/.plugin/plugin.json on 1.3.3 (server.json
had drifted from package.json, which the existing version-consistency
test now catches).

Commit-Author: sub-agent
Task-Source: user-prompt
Reason: the backend is removing the exact per-country stock count from its
API response; without this change every installed copy of the MCP would
read every country as out of stock once that happens.
@virtualsms-io
virtualsms-io merged commit 913df71 into main Sep 23, 2026
9 of 10 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