Skip to content

Code Examples

Copy and paste these examples to get started immediately

cURLSearch Products
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
      }
    }
  }'
PythonCreate Cart
import requests

response = requests.post(
  "https://trusteed.xyz/demo-store/mcp",
  headers={
    "X-Agent-Api-Key": "YOUR_API_KEY",
    "Content-Type": "application/json"
  },
  json={
    "jsonrpc": "2.0",
    "id": 1,
    "method": "tools/call",
    "params": {
      "name": "create_cart",
      "arguments": {
        "merchantId": "demo-store"
      }
    }
  }
)

cart_id = response.json()["result"]["cart_id"]
print(f"Cart created: {cart_id}")
TypeScriptGet Shipping Rates
const response = await fetch(
  "https://trusteed.xyz/demo-store/mcp",
  {
    method: "POST",
    headers: {
      "X-Agent-Api-Key": "YOUR_API_KEY",
      "Content-Type": "application/json"
    },
    body: JSON.stringify({
      jsonrpc: "2.0",
      id: 1,
      method: "tools/call",
      params: {
        name: "get_shipping_rates",
        arguments: {
          cartId: "cart-123",
          address: {
            street: "123 Main St",
            city: "San Francisco",
            country: "US",
            postalCode: "94105"
          }
        }
      }
    })
  }
);

const { result } = await response.json();
process.stdout.write(JSON.stringify(result.rates));
cURLSelect Shipping Option
curl -X POST https://trusteed.xyz/demo-store/mcp \
  -H "X-Agent-Api-Key: YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "jsonrpc": "2.0",
    "id": 1,
    "method": "tools/call",
    "params": {
      "name": "select_shipping_option",
      "arguments": {
        "cartId": "cart-123",
        "shippingId": "shipping-456",
        "address": {
          "street": "123 Main St",
          "city": "San Francisco",
          "country": "US",
          "postalCode": "94105"
        }
      }
    }
  }'
PythonApply Discount
def apply_discount(cart_id: str, code: str) -> dict:
    """Apply discount code to cart."""
    response = requests.post(
        "https://trusteed.xyz/demo-store/mcp",
        headers={
            "X-Agent-Api-Key": "YOUR_API_KEY",
            "Content-Type": "application/json"
        },
        json={
            "jsonrpc": "2.0",
            "id": 1,
            "method": "tools/call",
            "params": {
                "name": "apply_discount",
                "arguments": {
                    "cartId": cart_id,
                    "code": code
                }
            }
        }
    )
    return response.json()["result"]

# Ejemplo: 10% off con TEST123
result = apply_discount("cart-123", "TEST123")
print(f"Discount applied: {result['discountAmount']} off")
TypeScriptComplete Checkout
async function completeCheckout(
  cartId: string,
  buyerInfo: { name: string; email: string; phone: string }
) {
  const response = await fetch(
    "https://trusteed.xyz/demo-store/mcp",
    {
      method: "POST",
      headers: {
        "X-Agent-Api-Key": "YOUR_API_KEY",
        "Content-Type": "application/json"
      },
      body: JSON.stringify({
        jsonrpc: "2.0",
        id: 1,
        method: "tools/call",
        params: {
          name: "complete_checkout",
          arguments: {
            cartId,
            buyerInfo
          }
        }
      })
    }
  );

  const { result } = await response.json();
  return result.transactionId;
}

Tools Quick Reference

ToolDescriptionAuth Required
search_productsSearch products with filtersYes
get_product_detailsGet full product detailsYes
create_cartCreate shopping cartYes
get_shipping_ratesGet shipping ratesYes
select_shipping_optionSelect shipping optionYes
apply_discountApply discount codeYes
preview_checkoutPreview checkoutYes
complete_checkoutComplete paymentYes

SDK Examples

Connect directly from your agent framework

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 trust_score >= 0.70 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 trust >= 0.70, 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 trust >= 0.70, create cart" });
await mcp.close();

Full quickstart /for-agents/sdk-quickstarts →

MCP 3-Bucket Endpoints

Each store exposes three specialized endpoints (Discovery / Customer / Checkout). Pick the bucket that matches your operation scope.

Discovery — POST /{storeSlug}/mcp/discoveryanonymous · cacheable · 14 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":{"customerId":"cus_123","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 · 19 tools
# tools/call complete_checkout
# Mandatory headers: AgenticTrust JWT, Idempotency-Key (UUIDv4), mandate
curl -X POST https://trusteed.xyz/demo-store/mcp/checkout \
  -H "Content-Type: application/json" \
  -H "MCP-Protocol-Version: 2025-11-25" \
  -H "Authorization: Bearer $AGENTIC_TRUST_JWT" \
  -H "Idempotency-Key: 550e8400-e29b-41d4-a716-446655440000" \
  -H "X-Mandate-Id: mnd_signed_by_principal" \
  -d '{
    "jsonrpc":"2.0","id":4,"method":"tools/call",
    "params":{
      "name":"complete_checkout",
      "arguments":{
        "cartId":"cart-123",
        "buyerInfo":{
          "name":"Ada Lovelace",
          "email":"ada@example.com",
          "phone":"+34600000000"
        }
      }
    }
  }'

# Re-trying the same Idempotency-Key returns the cached response
# (RFC 8785 JCS canonicalization of the body).

When to use each bucket? See the matrix in the quickstart →

Code Examples - AI Agents | Trusteed