Ejemplos de Código
Copia y pega estos ejemplos para empezar inmediatamente
cURLBuscar Productos
curl -X POST https://trusteed.xyz/demo-store/mcp \
-H "Content-Type: application/json" \
-H "X-Agent-Api-Key: YOUR_API_KEY" \
-d '{
"jsonrpc": "2.0",
"id": 1,
"method": "tools/call",
"params": {
"name": "search_products",
"arguments": {
"query": "laptop",
"limit": 10
}
}
}'PythonCrear Carrito
import requests
response = requests.post(
"https://trusteed.xyz/demo-store/mcp/checkout",
headers={
"X-Agent-Api-Key": "YOUR_SANDBOX_KEY",
"Content-Type": "application/json"
},
json={
"jsonrpc": "2.0",
"id": 1,
"method": "tools/call",
"params": {
"name": "create_cart",
"arguments": {
"items": [{"product_id": "prod-017", "quantity": 1}]
}
}
}
)
cart_id = response.json()["result"]["structuredContent"]["cart_id"]
print(f"Cart created: {cart_id}")TypeScriptObtener Tasas de Envío
const response = await fetch(
"https://trusteed.xyz/demo-store/mcp/checkout",
{
method: "POST",
headers: {
"X-Agent-Api-Key": "YOUR_SANDBOX_KEY",
"Content-Type": "application/json"
},
body: JSON.stringify({
jsonrpc: "2.0",
id: 1,
method: "tools/call",
params: {
name: "get_shipping_rates",
arguments: {
cart_id: cartId,
shipping_address: {
address1: "123 Main St",
city: "San Francisco",
province_code: "CA",
country_code: "US",
zip: "94105"
}
}
}
})
}
);
const { result } = await response.json();
process.stdout.write(JSON.stringify(result.structuredContent));cURLSeleccionar Opción de Envío
curl -X POST https://trusteed.xyz/demo-store/mcp/checkout \
-H "X-Agent-Api-Key: YOUR_SANDBOX_KEY" \
-H "Content-Type: application/json" \
-d '{
"jsonrpc": "2.0",
"id": 1,
"method": "tools/call",
"params": {
"name": "select_shipping_option",
"arguments": {
"cart_id": "<cart_id from create_cart>",
"shipping_handle": "standard"
}
}
}'PythonAplicar Descuento
def apply_discount(cart_id: str, code: str) -> dict:
"""Apply discount code to cart."""
response = requests.post(
"https://trusteed.xyz/demo-store/mcp/checkout",
headers={
"X-Agent-Api-Key": "YOUR_SANDBOX_KEY",
"Content-Type": "application/json"
},
json={
"jsonrpc": "2.0",
"id": 1,
"method": "tools/call",
"params": {
"name": "apply_discount",
"arguments": {
"cart_id": cart_id,
"discount_code": code
}
}
}
)
return response.json()["result"]
result = apply_discount(cart_id, "TEST123")
print(result)TypeScriptCompletar Checkout
async function completeCheckout(
checkoutSessionId: string, // from preview_checkout
idempotencyKey: string, // one per purchase attempt; reuse it on retry
buyer: { name: string; email: string; phone: string }
) {
const response = await fetch(
"https://trusteed.xyz/demo-store/mcp/checkout",
{
method: "POST",
headers: {
"X-Agent-Api-Key": "YOUR_SANDBOX_KEY",
"Content-Type": "application/json"
},
body: JSON.stringify({
jsonrpc: "2.0",
id: 1,
method: "tools/call",
params: {
name: "complete_checkout",
arguments: {
checkout_session_id: checkoutSessionId,
idempotency_key: idempotencyKey,
payment_method: "MOCK",
buyer
}
}
})
}
);
const { result, error } = await response.json();
// A missing key arrives as error.data.code === "no_credentials" (HTTP 200 on demo-store).
if (error) throw new Error(error.data?.code ?? error.message);
// COMPLETED → order_id. PENDING_EXTERNAL_CONFIRMATION → send the buyer to
// approval_url / payment_url, then call again with the same two ids.
return result.structuredContent;
}Referencia Rápida de Tools
| Herramienta | Descripción | Auth Requerida |
|---|---|---|
| search_products | Buscar productos con filtros | Yes |
| get_product_details | Obtener detalles completos del producto | Yes |
| create_cart | Crear carrito de compra | Yes |
| get_shipping_rates | Obtener tasas de envío | Yes |
| select_shipping_option | Seleccionar opción de envío | Yes |
| apply_discount | Aplicar código de descuento | Yes |
| preview_checkout | Previsualizacar checkout | Yes |
| complete_checkout | Completar pago | Yes |
Ejemplos con SDK
Conecta directamente desde tu framework de agentes
OpenAI Agents SDKpip install openai-agents
# pip install openai-agents
from agents import Agent, Runner
from agents.mcp import MCPServerStreamableHttp
async with MCPServerStreamableHttp(
name="trusteed",
params={"url": "https://trusteed.xyz/{storeSlug}/mcp",
"headers": {"X-Agent-Api-Key": "agnt_xxx"}}
) as mcp:
agent = Agent(instructions="Verify the merchant's trust level before checkout.")
result = await Runner.run_async(agent, "Find laptops under $1500")Claude Agent SDKnpm install @anthropic-ai/claude-agent-sdk
// npm install @anthropic-ai/claude-agent-sdk
import { query } from "@anthropic-ai/claude-agent-sdk";
for await (const msg of query({
prompt: "Search products, verify the merchant's trust level, create cart",
options: {
mcpServers: { trusteed: { type: "http",
url: "https://trusteed.xyz/{storeSlug}/mcp",
headers: { "X-Agent-Api-Key": process.env.TRUSTEED_KEY } } },
allowedTools: ["mcp__trusteed__search_products",
"mcp__trusteed__get_merchant_profile",
"mcp__trusteed__create_cart"],
},
})) { if (msg.type === "result") process.stdout.write(msg.result); }Vercel AI SDKnpm install ai @ai-sdk/openai
// npm install ai @ai-sdk/openai
import { experimental_createMCPClient as createMCPClient } from "ai";
import { generateText } from "ai";
import { openai } from "@ai-sdk/openai";
const mcp = await createMCPClient({ transport: { type: "http",
url: "https://trusteed.xyz/{storeSlug}/mcp",
headers: { "X-Agent-Api-Key": process.env.TRUSTEED_KEY } } });
const { text } = await generateText({ model: openai("gpt-4o"),
tools: await mcp.tools(), maxSteps: 5,
prompt: "Find laptops, verify the merchant's trust level, create cart" });
await mcp.close();Guía completa de inicio rápido /for-agents/sdk-quickstarts →
Endpoints MCP: 3 buckets
Cada tienda expone tres endpoints especializados (Discovery / Customer / Checkout). Elige el bucket según el scope de la operación.
Aviso de deprecación: endpoint legacy
El endpoint monolítico /{storeSlug}/mcp está deprecated y se está retirando (ver headers Sunset y Deprecation en cada respuesta). Migra a los endpoints por bucket antes de la fecha. Guía completa: /docs/integrations/three-bucket-migration.
Discovery:
POST /{storeSlug}/mcp/discoveryanonymous · cacheable · 20 tools# tools/list (no auth required)
curl -X POST https://trusteed.xyz/demo-store/mcp/discovery \
-H "Content-Type: application/json" \
-H "MCP-Protocol-Version: 2025-11-25" \
-d '{"jsonrpc":"2.0","id":1,"method":"tools/list"}'
# tools/call search_products
curl -X POST https://trusteed.xyz/demo-store/mcp/discovery \
-H "Content-Type: application/json" \
-H "MCP-Protocol-Version: 2025-11-25" \
-d '{
"jsonrpc":"2.0","id":2,"method":"tools/call",
"params":{
"name":"search_products",
"arguments":{"query":"laptop","limit":5}
}
}'Customer:
POST /{storeSlug}/mcp/customerOAuth 2.1 · resource=customer-mcp · 9 tools# tools/call onx_get_orders (Bearer OAuth + RFC 8707 resource indicator)
curl -X POST https://trusteed.xyz/demo-store/mcp/customer \
-H "Content-Type: application/json" \
-H "MCP-Protocol-Version: 2025-11-25" \
-H "Authorization: Bearer $CUSTOMER_OAUTH_TOKEN" \
-d '{
"jsonrpc":"2.0","id":3,"method":"tools/call",
"params":{
"name":"onx_get_orders",
"arguments":{"limit":10}
}
}'
# Note: token MUST be issued with resource indicator
# resource=https://trusteed.xyz/{storeSlug}/mcp/customer
# (RFC 8707). Tokens for other resources will 401.Checkout:
POST /{storeSlug}/mcp/checkoutAgenticTrust · Idempotency-Key · mandate · 26 tools# tools/call complete_checkout
# Needs a credential and a payment mandate (X-Payment-Mandate header, or the
# payment_mandate argument). On demo-store the credential is a sandbox key.
curl -X POST https://trusteed.xyz/demo-store/mcp/checkout \
-H "Content-Type: application/json" \
-H "MCP-Protocol-Version: 2025-11-25" \
-H "X-Agent-Api-Key: $SANDBOX_KEY" \
-H "X-Payment-Mandate: $PAYMENT_MANDATE" \
-d '{
"jsonrpc":"2.0","id":4,"method":"tools/call",
"params":{
"name":"complete_checkout",
"arguments":{
"checkout_session_id":"<checkout_session_id from preview_checkout>",
"idempotency_key":"550e8400-e29b-41d4-a716-446655440000",
"payment_method":"MOCK",
"buyer":{
"name":"Ada Lovelace",
"email":"ada@example.com",
"phone":"+34600000000"
}
}
}
}'
# The result's status tells you what happened: COMPLETED (order_id set;
# simulated on demo-store) or PENDING_EXTERNAL_CONFIRMATION (send the buyer to
# approval_url / payment_url, then call again with the same
# checkout_session_id and idempotency_key).¿Cuándo usar cada bucket? Ver matriz en el quickstart →