Skip to content
SDK Quickstarts

Connect your AI agent to Trusteed

Copy-ready examples for the 3 most popular AI SDKs. Each example includes trust score verification.

OpenAI Agents SDK

OpenAI Agents SDK — Python

Installpip install openai-agents
Tested version: openai-agents ≥ 0.14.0
PythonShopping agent with trust verification
import asyncio
from agents import Agent, Runner
from agents.mcp import MCPServerStreamableHttp

async def main():
    async with MCPServerStreamableHttp(
        name="trusteed",
        params={
            "url": "https://trusteed.xyz/demo-store/mcp",
            "headers": {"X-Agent-Api-Key": "agnt_your_key"},
            "timeout": 30,
        },
        cache_tools_list=True,
    ) as mcp:
        agent = Agent(
            name="shopping-agent",
            instructions="""
            You are a shopping assistant for Trusteed.
            IMPORTANT: Before any checkout, always call get_merchant_profile
            and verify trust_score >= 0.70. If lower, stop and inform the user.
            Methodology: GET /api/v1/trust/methodology
            """,
        )

        result = await Runner.run_async(
            agent,
            "Search for laptops under $1500, verify merchant trust, and create a cart."
        )
        print(result.final_output)

asyncio.run(main())

The agent receives trust_score in the get_merchant_profile response. With the system prompt instructions, the model automatically verifies the threshold before calling create_cart.

Claude Agent SDK

Claude Agent SDK — TypeScript

Installnpm install @anthropic-ai/claude-agent-sdk
Tested version: @anthropic-ai/claude-agent-sdk ≥ 0.2.0
Note: SDK is under active development — review the CHANGELOG before upgrading minor versions.
TypeScriptAgent with allowedTools and trust check
import { query } from "@anthropic-ai/claude-agent-sdk";

// Source: https://code.claude.com/docs/en/agent-sdk/mcp#httpsse-servers

async function main() {
  for await (const message of query({
    prompt: `
      1. Call search_products with query "laptop" limit 5
      2. Call get_merchant_profile to get trust_score
      3. If trust_score >= 0.70, call create_cart with the first result
      4. Report the cart_id and trust_score
    `,
    options: {
      mcpServers: {
        trusteed: {
          type: "http",
          url: "https://trusteed.xyz/demo-store/mcp",
          headers: {
            "X-Agent-Api-Key": process.env.TRUSTEED_API_KEY ?? "",
          },
        },
      },
      allowedTools: [
        "mcp__trusteed__search_products",
        "mcp__trusteed__get_merchant_profile",
        "mcp__trusteed__create_cart",
      ],
    },
  })) {
    if (message.type === "result" && message.subtype === "success") {
      process.stdout.write(JSON.stringify(message.result) + "\n");
    }
    if (message.type === "assistant") {
      for (const block of message.message.content) {
        if (block.type === "text") {
          process.stdout.write(block.text);
        }
      }
    }
  }
}

main().catch((err) => process.stderr.write(String(err)));

allowedTools restricts which MCP tools the agent can invoke — important for reducing blast radius in production.

Vercel AI SDK

Vercel AI SDK — TypeScript

Installnpm install ai @ai-sdk/openai
Tested version: ai ≥ 6.0.0
Note: experimental_createMCPClient is still in beta — API may change.
TypeScript (Node.js)generateText with MCP client
import { experimental_createMCPClient as createMCPClient } from "ai";
import { generateText } from "ai";
import { openai } from "@ai-sdk/openai";

async function main() {
  const mcpClient = await createMCPClient({
    transport: {
      type: "http",
      url: "https://trusteed.xyz/demo-store/mcp",
      headers: {
        "X-Agent-Api-Key": process.env.TRUSTEED_API_KEY ?? "",
      },
    },
  });

  const tools = await mcpClient.tools();

  const { text, toolCalls } = await generateText({
    model: openai("gpt-4o"),
    tools,
    maxSteps: 6,
    system: `You are a shopping assistant.
IMPORTANT: Always call get_merchant_profile first and verify trust_score >= 0.70.
If trust_score < 0.70, do NOT create a cart. Inform the user instead.`,
    prompt: "Find me a laptop under $1500 and start the checkout process.",
  });

  process.stdout.write("Response: " + text + "\n");
  process.stdout.write("Tool calls: " + toolCalls.length + "\n");

  await mcpClient.close();
}

main().catch((err) => process.stderr.write(String(err)));
TypeScript (Next.js App Router)Streaming in Next.js App Router
// app/api/shop/route.ts
import { experimental_createMCPClient as createMCPClient } from "ai";
import { streamText } from "ai";
import { openai } from "@ai-sdk/openai";

export async function POST(req: Request) {
  const { message } = await req.json();

  const mcpClient = await createMCPClient({
    transport: {
      type: "http",
      url: `https://trusteed.xyz/${process.env.STORE_SLUG}/mcp`,
      headers: { "X-Agent-Api-Key": process.env.TRUSTEED_API_KEY ?? "" },
    },
  });

  const tools = await mcpClient.tools();

  const result = streamText({
    model: openai("gpt-4o"),
    tools,
    maxSteps: 8,
    system: "Shopping assistant. Verify trust_score >= 0.70 before checkout.",
    messages: [{ role: "user", content: message }],
    onFinish: () => mcpClient.close(),
  });

  return result.toDataStreamResponse();
}

streamText with onFinish closes the MCP client automatically when the response completes, preventing connection leaks.

Trust Check Pattern — common to all 3 SDKs

trust_score thresholds your agent must enforce before initiating checkout

ScoreLevelAgent action
≥ 0.95ELITEProceed without friction
≥ 0.85VERIFIEDProceed with standard confirmation
≥ 0.70STANDARDMinimum eligible for checkout
< 0.70DO NOT PROCEEDDo NOT initiate checkout

Full methodology: GET /api/v1/trust/methodology

Ready to connect? Get your API key in seconds.

Get API Key
SDK Quickstarts — AI Agents | Trusteed