claude-for-commerce-examples

hiobuy/claude-for-commerce-examples Checked 2 days ago

China sourcing examples for Anthropic's commerce-agents, powered by HIOBuy Agent API and MCP.

HIOBuy implementation of Anthropic's commerce-agents blueprint for China sourcing. Add live China sourcing capabilities to Claude Commerce Agents using HIOBuy Agent API and MCP. Search live products from 1688 and Taobao, search by image, inspect variants, and compare China product sourcing options with Claude. Weidian is reserved for a future release: the reviewed Gateway's Weidian adapter is a placeholder, not a live product integration. This example intentionally does not expose it as live data. Try: “Find wireless earbuds under ¥30 on 1688 and compare three sourcing options.”

Summary extracted from the README.

Claude for Commerce × HIOBuy

China Sourcing for Commerce Agents

HIOBuy implementation of Anthropic's commerce-agents blueprint for China sourcing. Add live China sourcing capabilities to Claude Commerce Agents using HIOBuy Agent API and MCP.

Search live products from 1688 and Taobao, search by image, inspect variants, and compare China product sourcing options with Claude. Weidian is reserved for a future release: the reviewed Gateway's Weidian adapter is a placeholder, not a live product integration. This example intentionally does not expose it as live data.

Try: “Find wireless earbuds under ¥30 on 1688 and compare three sourcing options.”

What this is

A small, runnable China sourcing backend / integration for commerce agents. It installs the real Anthropic shopping-agent-core, shopping-agent-runtime, and commerce-common packages at a fixed Git commit and implements their StorefrontBackend contract. It does not recreate an agent platform or marketplace API.

Built as an implementation/example based on Anthropic's commerce-agents blueprint. This independent developer implementation is not maintained, sponsored, or endorsed by Anthropic or Shopify.

Why HIOBuy

HIOBuy provides the marketplace authentication, normalization, and upstream access behind agent-ready commerce APIs. This example adds the small translation layer between those APIs and Claude's commerce workflow. It is useful for sourcing discovery, price and variant research, and supplier/product comparison based on available facts.

HIOBuy component Role
REST API Traditional application integration
Agent API Tool discovery and calls for tool-calling agents
MCP The same capabilities for MCP-compatible agents
Agent Skills Guidance for coding agents using HIOBuy
HIOBuy Starter General application starting point
This repository Anthropic commerce-agents implementation for China sourcing

Architecture

Browser chat / image upload
          ↓ local Python server (credentials stay here)
Claude ↔ Anthropic ShoppingAgent / skills / provenance gates
          ↓ HioBuyStorefrontBackend
          ├─ Mode A: /ai/v1/tools → /ai/v1/tools/call
          └─ Mode B: /mcp → initialize / tools/list / tools/call
          ↓ existing HIOBuy Gateway
          ↓ 1688 / Taobao

The Python Messages API runtime does not accept an arbitrary remote MCP server as a constructor argument. In MCP mode, backend methods call HIOBuy's existing MCP endpoint server-side, as the blueprint recommends for platform APIs. Neither mode adds a new MCP server or accesses marketplaces directly.

Features and marketplaces

Capability 1688 Taobao Weidian
Keyword search / CNY price filter Yes Yes Unavailable
Product detail / seller data Yes Yes Placeholder upstream; disabled
Variants / SKUs / returned stock Yes Yes Disabled
Upload image → similarity search Yes Yes Not supported
Compare and recommend Yes Yes Disabled

A key must have access to the selected marketplace. Fields, stock freshness, SKU completeness and price conditions vary by product and upstream. Search results do not provide stock; unknown data stays unknown. MOQ, tiers and seller information are included only as reported by HIOBuy. No supplier quality or authenticity is inferred.

Quick Start

Requirements: Python 3.11+, Git, an Anthropic API key with model access, and a live HIOBuy API key with the scopes and channel authorization described below.

Clone the repository and set up the environment:

git clone https://github.com/hiobuy/claude-for-commerce-examples.git
cd claude-for-commerce-examples
python3 -m venv .venv
source .venv/bin/activate
pip install -r requirements.lock.txt
cp .env.example .env
# Fill ANTHROPIC_API_KEY and HIOBUY_API_KEY in .env.
python -m uvicorn examples.china_sourcing.app:app --host 127.0.0.1 --port 8000

Open localhost:8000. On Windows, activate with .venv\Scripts\activate. The source dependency manifest is requirements.txt; requirements.lock.txt records the verified dependency versions for reproducible installs. The official blueprint packages are installed from Git, without copying the upstream repo.

The page starts without keys and explains which settings are missing. It never silently falls back to generated products. Fill the two keys and restart to enable calls.

Agent API mode

Default: HIOBUY_MODE=agent-api. The server discovers permitted tools through GET /ai/v1/tools, validates arguments against each returned JSON Schema, and invokes POST /ai/v1/tools/call with { "tool_id": "product.search", "arguments": {...} }. Only four product tools are allowed. See Agent API integration.

MCP mode

Set HIOBUY_MODE=mcp in .env and restart. The same chat, comparison and image flows now use /mcp. The thin client initializes a session, accepts the server's negotiated protocol version, lists tools, and unwraps the HIOBuy JSON envelope from MCP text content. See MCP integration for protocol details and standalone connection guidance.

Try these prompts

  • “Find wireless earbuds under ¥30 on 1688. Inspect details and recommend a shortlist.”
  • “Find canvas tote bags on Taobao. Compare three products and recommend one.”
  • “Find a cheaper alternative to 1688:<actual returned ID>. Compare the SKU prices and MOQ.”
  • “Compare these three products: 1688:<id1>, 1688:<id2>, 1688:<id3>.”
  • “Show the available colors and sizes for taobao:<actual returned id>.”

Use the Search by image control for a JPEG or PNG (up to 2 MB). The server calls product.upload_image, then product.search_by_image with its returned image_id. Images are sent to HIOBuy, not placed into Claude's text prompt. Matching product data enters the same session; ask Claude to inspect and compare it. No local image is saved.

Use IDs exactly as returned. Taobao id is its opaque mi_id, not necessarily the numeric source product ID. The adapter qualifies IDs with the marketplace and URI encodes them to keep cross-marketplace and SKU identities distinct. The Inspect button builds the appropriate prompt, so no manual encoding is needed.

Environment variables

Name Required Default / purpose
ANTHROPIC_API_KEY For chat Server-side Anthropic authentication
HIOBUY_API_KEY For product calls Server-side HIOBuy authentication
HIOBUY_MODE No agent-api; alternatively mcp
HIOBUY_BASE_URL No https://api.hiobuy.com; HTTPS only, no credentials in URL
ANTHROPIC_MODEL No Pinned blueprint default: claude-sonnet-5

The current runtime uses adaptive thinking and eager tool streaming. A model override must support its request features; older models are not guaranteed compatible.

Authentication and safety

Create an approved application and live key through the HioBuy Developer Platform. Grant product:search (search and image tools) and product:detail. Authorize 1688 / Taobao for that application as required by your HIOBuy account. A syntactically valid key alone does not provide scopes, quota, or marketplace access. Test keys invoke Gateway sandbox behavior and cannot establish live sourcing readiness.

All key-bearing requests originate on the Python server. .env* is ignored, with only .env.example allowed in source control. The UI never requests or receives a key. Upstream error bodies and exception stacks are not displayed. Safe errors retain a valid request_id; provide that ID to support@hiobuy.com for diagnosis.

This is a local developer demo: it binds to loopback, rejects other Host headers and cross-origin POSTs, and uses an HttpOnly same-site session cookie. Conversations are in memory, expire after inactivity, and are scoped to the browser cookie. Run one worker. Restarting clears sessions. Public hosting requires a separate access-control and usage-budget design; that is outside V1.

Errors and data limits

Handled states include missing/invalid keys, missing scopes, unauthorized channels, rate/quota limits, upstream timeout, unavailable products, bad IDs, malformed tool arguments, empty keyword results, and no image matches. Errors include safe HIOBuy request IDs where the protocol provides them. Product cards also retain successful IDs.

  • Only 1688 and Taobao are enabled; Weidian needs a genuine Gateway implementation.
  • No purchases, carts, checkout, wallet payments, order creation, fulfillment, returns, inventory writes, merchant admin, accounts, database, or billing system.
  • The official backend has no image-search method. Image upload is a separate host flow that feeds the same agent session and provenance record.
  • Price/stock nullability is a small local Product extension. No fake zero price or default in-stock value is added by this adapter. The Gateway itself may normalize absent upstream values to defaults; this example cannot reconstruct their provenance.
  • Base, promotion, wholesale and tier prices are not interchangeable; returned conditions are retained in product facts. Search results are not supplier verification.
  • Search is one page per call. Category/rating/arbitrary attribute filters are explicitly unsupported; keyword, channel, CNY price filters and keyword price sorting are supported.
  • A large SKU family may exceed the runtime's 24,000-character model fence. The UI retains returned SKU records, but Claude must not claim that a truncated tool response is complete.
  • No persistent memory or cross-device conversation storage; this is a developer example.

Verification

Live Claude end-to-end: NOT VERIFIED. No Anthropic API key was available. Production uses the real Claude runtime; test doubles exist only in tests. See verification status for exact coverage and live HIOBuy limits.

pip install -r requirements-dev.txt
python -m pytest -q
python -m mypy
python -m ruff check hiobuy examples tests
python -m ruff format --check hiobuy examples tests
node --check examples/china_sourcing/static/app.js
python -m build
python -m pip check
# Install Gitleaks 8.30.1 separately, then scan tracked history:
gitleaks git --redact --no-banner --log-opts="--all"

All normal tests use clearly labeled unit fixtures and mocked HTTP transports; CI never depends on live Taobao/1688 or paid Claude calls. Tests execute the actual installed blueprint contract, serializer, executor, presentation provenance gates, and both transport protocols. The typecheck covers the Python implementation (including unannotated function bodies); the third-party blueprint does not publish type markers, so its imports are treated as untyped. The frontend is plain JavaScript with a syntax check, not a TypeScript project.

python -m build produces a wheel and source archive. The wheel includes the real sourcing skill and static UI. An installation outside the source checkout is tested for skill/assets and no-key startup; no build-time Anthropic call is needed.

For an opt-in, billable live smoke check after configuring a live key:

python -m examples.china_sourcing.smoke --mode agent-api --channel 1688
python -m examples.china_sourcing.smoke --mode mcp --channel taobao
# Include upload → image search with your own image:
python -m examples.china_sourcing.smoke --mode agent-api --channel 1688 --image ./product.jpg

These checks do not call Claude. Verify the five prompt flows manually in the UI with an Anthropic key before release. See verification status for what was actually tested and which live checks still require credentials.

Roadmap

Planned for later phases: procurement workflow, sourcing quotation, HIOBuy Fulfillment, warehouse packages, shipping quotes, international shipment tracking, and supplier inquiry / HioAsk. Weidian will be enabled only after its live Gateway adapter is verified.

References and license