开始使用
快速入门
通过 HTTP 向 Shop MCP 发送首次搜索请求,查看返回结果。无需账户或 API 密钥。
本页将向 Shop MCP 发送一次 search_catalog 调用,并逐项解读返回结果。使用 curl 即可;JavaScript 版本则需 Node.js 18 或更高版本。
发送搜索请求
工具调用是通过 POST 方式发送到 https://mcp.shop.com/ 的 JSON-RPC tools/call 请求。以下请求为加拿大的购物者搜索价格不超过 80 加元的防雨夹克:
curl -s https://mcp.shop.com/ \
-H 'Content-Type: application/json' \
-H 'Accept: application/json, text/event-stream' \
-H 'MCP-Protocol-Version: 2026-07-28' \
-H 'Mcp-Method: tools/call' \
-H 'Mcp-Name: search_catalog' \
-d '{
"jsonrpc": "2.0",
"id": 1,
"method": "tools/call",
"params": {
"name": "search_catalog",
"arguments": {
"catalog": {
"query": "rain jacket",
"context": { "address_country": "CA", "currency": "CAD" },
"filters": { "price": { "max": 8000 } },
"pagination": { "limit": 5 }
}
},
"_meta": {
"io.modelcontextprotocol/protocolVersion": "2026-07-28",
"io.modelcontextprotocol/clientInfo": { "name": "my-app", "version": "1.0.0" },
"io.modelcontextprotocol/clientCapabilities": {}
}
}
}'
以下是同一请求的 JavaScript 版本,会输出每条结果的主推价格和卖家。将其保存为 search.mjs,然后运行 node search.mjs:
const response = await fetch('https://mcp.shop.com/', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
Accept: 'application/json, text/event-stream',
'MCP-Protocol-Version': '2026-07-28',
'Mcp-Method': 'tools/call',
'Mcp-Name': 'search_catalog',
},
body: JSON.stringify({
jsonrpc: '2.0',
id: 1,
method: 'tools/call',
params: {
name: 'search_catalog',
arguments: {
catalog: {
query: 'rain jacket',
context: { address_country: 'CA', currency: 'CAD' },
filters: { price: { max: 8000 } },
pagination: { limit: 5 },
},
},
_meta: {
'io.modelcontextprotocol/protocolVersion': '2026-07-28',
'io.modelcontextprotocol/clientInfo': { name: 'my-app', version: '1.0.0' },
'io.modelcontextprotocol/clientCapabilities': {},
},
},
}),
});
if (!response.ok) throw new Error(`HTTP ${response.status}`);
const { result, error } = await response.json();
if (error) throw new Error(error.message);
if (result?.isError) {
const text = result.content?.filter((part) => part.type === 'text').map((part) => part.text).join('\n');
throw new Error(text || 'Search failed');
}
const document = result?.structuredContent;
if (!Array.isArray(document?.products)) throw new Error('Search returned no products document');
for (const message of document.messages ?? []) {
if (message.type === 'warning') console.warn(message.content);
}
// Prices are integers in the currency's minor units: 6400 in CAD is 64.00.
const money = ({ amount, currency }) => {
const format = new Intl.NumberFormat('en', { style: 'currency', currency });
return format.format(amount / 10 ** format.resolvedOptions().maximumFractionDigits);
};
for (const product of document.products) {
const [variant] = product.variants;
console.log(`${product.title}: ${money(variant.price)} from ${variant.seller.name}`);
}
Craven Mens Waterproof Packaway Jacket - Black: CA$64.00 from TOG24
Men's Waterproof Rain Jacket V2 | Full Zip: CA$74.00 from Combat Iron Apparel Co.
Craven Mens Waterproof Packaway Jacket - Dark Orange: CA$64.00 from TOG24
Burradon Womens Waterproof Jacket - Magenta Pink: CA$75.00 from TOG24
Watertight II Rain Jacket - Men’s: CA$71.99 from SAIL plein air
商家的库存和价格会发生变化,因此实际搜索结果会有所不同。
各部分的作用
服务器不保留会话,因此无需在本次调用前调用 initialize。每个请求都通过 params._meta 指定协议版本和客户端信息。将 clientInfo 设置为您应用自身的名称和版本。
Mcp-Method 和 Mcp-Name 请求头分别对应请求正文中的方法和工具名称。每次调用都要发送这两个请求头,并确保其值与正文一致。
按照 MCP 对客户端的要求,Accept 同时列出 JSON 和事件流。Shop 则以纯 JSON 格式响应。
解读结果
以下是精简后的响应,仅保留第三个产品,并省略了其中的大部分字段:
{
"jsonrpc": "2.0",
"id": 1,
"result": {
"resultType": "complete",
"isError": false,
"content": [{ "type": "text", "text": "{\"ucp\":{\"version\":\"2026-08-25\"},\"products\":[…]}" }],
"structuredContent": {
"ucp": { "version": "2026-08-25" },
"products": [
{
"id": "gid://shopify/p/21LZl7P8DjyKRD7lJqv40C",
"title": "Craven Mens Waterproof Packaway Jacket - Dark Orange",
"rating": { "value": 4.8, "scale_min": 1, "scale_max": 5, "count": 850 },
"options": [
{ "name": "Size", "values": [{ "label": "S" }, { "label": "M" }, { "label": "L" }, { "label": "XL" }] }
],
"price_range": {
"min": { "amount": 6400, "currency": "CAD" },
"max": { "amount": 6400, "currency": "CAD" }
},
"variants": [
{
"id": "gid://shopify/ProductVariant/40439010361434",
"options": [{ "name": "Size", "label": "S" }],
"price": { "amount": 6400, "currency": "CAD" },
"availability": { "available": true },
"url": "https://www.tog24.com/products/craven-mens-milatex-5-5-jacket-dark-orange?variant=40439010361434&_gsid=mzWAwFn2Twg1&utm_source=shopify&utm_medium=catalog",
"seller": {
"id": "gid://shopify/Shop/4439113818",
"name": "TOG24",
"url": "https://www.tog24.com",
"domain": "tog24.myshopify.com"
}
}
]
}
],
"messages": [
{
"type": "info",
"code": "price_filter_applied",
"path": "$.filters.price",
"content": "Price filtering was applied on a USD basis; returned prices are contextualized to the buyer's market and may differ."
}
],
"pagination": {
"has_next_page": true,
"total_count": 371,
"cursor": "eyJvZmZzZXQiOjUsInRvdGFsX2NvdW50IjozNzEsInJldHVybmVkIjo1fQ"
},
"next": [
"Show every warning; it may change price, availability, terms or required disclosures. …"
]
}
}
}
structuredContent 是 JSON 格式的结果。content[0].text 以字符串形式提供同一份内容,供只读取文本的客户端使用。
每个产品都会列出所有选项,但 variants 只包含一个推荐多属性,即 Shop 为本次搜索选定的一种尺寸与颜色组合。将其 id、price、availability 和 seller 展示给购物者,并在后续结账时传入这些信息。多属性的 url 必须按返回的原样保留,包括查询字符串。若要展示其他尺寸,参照查找产品中的说明调用 get_product。
价格以相应货币最小单位的整数表示,因此 6400 加元表示 64.00 加元。
messages 说明 Shop 如何处理该请求。此处提示,80 加元的价格上限先换算为美元,再用于筛选,因此返回结果中的加元价格可能与该上限略有出入。向购物者展示所有类型为 warning 的消息。
要获取下一页,使用相同的查询、上下文和筛选条件再次发送请求,并将 pagination.cursor 设置为返回的游标。
next 包含 Shop 为处理此结果的智能体提供的一组建议,例如如何展示警告,以及何时值得调用 get_product。将这些建议与结果一起传给模型。不使用模型的应用可以忽略这些建议。
请求失败时
服务器无法接受请求时,会返回 HTTP 错误和 JSON-RPC error。请求 51 条结果时,由于超出上限 1 条,会返回 HTTP 400:
{"jsonrpc":"2.0","id":1,"error":{"code":-32602,"message":"$.catalog.pagination.limit: maximum constraint failed"}}
工具在执行过程中失败时,仍会返回 result,其中 isError 设为 true,result._meta 中则包含错误代码。错误与重试列出了这两类错误,并说明哪些情况可以安全重试。
通过 CLI 发送相同搜索
shop CLI 根据命令行标志构建此请求:
shop search 'rain jacket' --country CA --currency CAD --price-max 8000 --limit 5
添加 --dry-run --as curl,即可将请求输出为 curl 命令,而不实际发送。安装方法参阅 CLI 参考。
从原型到正式应用
CLI 内置公共客户端,可用于试用“使用 Shop 登录”和个性化结果。在发布自己的应用前,应使用为该应用注册的专属应用客户端,方便购物者识别您的应用,同时便于单独管理其生产环境访问权限。应用客户端说明了两者的区别;连接 Shop 账户则介绍 OAuth 集成方法。
本示例中的 clientInfo 用于标识您的软件;修改它并不会注册 OAuth 客户端,也不会提高频率限制。上述匿名搜索无需购物者令牌。
