Skip to content

feat(template): native Storefront MCP catalog search agent tool#408

Merged
laugharn merged 5 commits into
mainfrom
native-mcp-search
Jul 8, 2026
Merged

feat(template): native Storefront MCP catalog search agent tool#408
laugharn merged 5 commits into
mainfrom
native-mcp-search

Conversation

@laugharn

@laugharn laugharn commented Jul 7, 2026

Copy link
Copy Markdown
Collaborator

Prototypes an agent search tool backed by Shopify's hosted Storefront MCP server (search_catalog) as an alternative to the GraphQL-backed search_products, so the two can be compared on relevance. Both tools ship side-by-side.

What's here

  • lib/shopify/storefront-mcp.ts — a universal JSON-RPC 2.0 client for the store's /api/mcp server (no server-only/next/cache, so the eve agent runtime can import it, same as storefront.ts). Exports callStorefrontMcp (reusable primitive) and searchCatalog. Handles both the structuredContent and text-block response forms, surfaces isError, and sends meta.ucp-agent.profile only when configured.
  • agent/tools/search_catalog.ts — an eve tool (auto-discovered by filename) mirroring search_products' output shape (available, image, price, title) for apples-to-apples comparison, plus productId/hasMore and a natural-language intent hint for native semantic relevance.
  • turbo.json + .env.example — registers the optional UCP_AGENT_PROFILE_URL (Turbo globalEnv + env docs).

Verified (live, against the jtwics-2 dev store)

  • search_catalog is enabled on /api/mcp and works without a profile.
  • Correct transform: "coat rack" → the Arco coat rack, available: true, image, price: "528.00 USD", GID.
  • Passing locale context localized currency (GBP→USD), confirming the localization path.
  • Natural-language + intent query returns results.
  • tsc clean, oxlint clean, no next/cache/server-only/next/headers in the eve import chain.

Caveats (by design, for a prototype)

  1. No handle in the MCP response — results carry a Shopify product GID, not a storefront handle, so navigate_user/get_product_details (handle-based) can't chain directly off these results yet. A GID→handle resolve step would make it drop-in.
  2. Relevance is the merchant's (Search & Discovery tuning) — which is exactly the thing to A/B against the current GraphQL search.

Not included (follow-ups if we adopt)

  • GID→handle resolution to chain with navigation tools.
  • Sibling native tools via the same client: search_shop_policies_and_faqs (policy Q&A), get_product_details.
  • Docs entry in apps/docs + a template-rollout-log entry once it graduates from prototype.

🤖 Generated with Claude Code

Prototype an agent search tool backed by Shopify's hosted Storefront MCP
server (search_catalog) as an alternative to the GraphQL-backed
search_products, so the two can be compared on relevance.

- lib/shopify/storefront-mcp.ts: universal JSON-RPC 2.0 client for the
  store's /api/mcp server (no server-only/next/cache, so the eve runtime
  can import it). Exports callStorefrontMcp and searchCatalog; handles the
  structuredContent and text-block response forms and sends the optional
  meta.ucp-agent.profile only when configured.
- agent/tools/search_catalog.ts: eve tool mirroring search_products' output
  shape, plus a natural-language `intent` hint for native semantic relevance.
  Results carry a Shopify product GID (no storefront handle).
- Registers optional UCP_AGENT_PROFILE_URL in turbo.json globalEnv and
  documents it in .env.example.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@vercel

vercel Bot commented Jul 7, 2026

Copy link
Copy Markdown
Contributor

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
shop-docs Ready Ready Preview, Comment Jul 8, 2026 12:10am
shop-template Ready Ready Preview, Comment, Open in v0 Jul 8, 2026 12:10am

…tools

Builds on the native Storefront MCP search tool:

- GID→handle bridge (b): fetchProductHandlesByIds in lib/shopify/fetch.ts
  resolves Shopify product GIDs to storefront handles via the Storefront
  `nodes` query. search_catalog now enriches each result with a handle, so
  MCP results feed navigate_user / get_product_details / add_to_cart directly
  instead of living in a GID-only silo.
- Native sibling tools (c):
  - agent/tools/get_catalog_product.ts — get_product_details by GID via MCP,
    returning price/availability/options/variantId plus the resolved handle.
  - agent/tools/search_shop_policies_and_faqs.ts — native policy/FAQ Q&A
    (net-new capability; no site equivalent).
- storefront-mcp.ts: adds getCatalogProduct + searchShopPoliciesAndFaqs and
  their types. Note get_product_details encodes money as major-unit strings
  with a sibling currency, unlike search_catalog's minor-unit objects.

Verified live against the dev store: search results carry handles, native
product details map correctly (price, variantId, options), and policy Q&A
returns answers.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Move the MCP client and catalog/product/policy functions out of the
non-standard storefront-mcp.ts into storefront.ts (reusing its store-domain
const and i18n imports), repoint tool imports, and trim comments to the
load-bearing ones.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Add the native MCP group (search_catalog, get_catalog_product,
search_shop_policies_and_faqs) to the agent anatomy doc — bumping the tool
count to 14 and noting the MCP helpers now live in storefront.ts — and add a
template-rollout-log entry for the change.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Add capability entries and a short "choosing a search tool" rule to
instructions.md: prefer search_catalog for descriptive/intent queries and
search_products for exact keyword/price-sorted lookups, fall back to
search_products on error, and route policy questions to
search_shop_policies_and_faqs. Include the MCP tools in the product-card
render rule.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@laugharn laugharn merged commit a7147da into main Jul 8, 2026
6 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