x402serps logox402serps

Web search in OpenAI Agents SDK with x402serps

The OpenAI Agents SDK connects to streamable HTTP MCP servers with headers, in Python and JavaScript. You can also let OpenAI call the server for you with the hosted MCP tool.

Python

from agents import Agent, Runner
from agents.mcp import MCPServerStreamableHttp

async with MCPServerStreamableHttp(
    name="x402serps",
    params={"url": "https://x402serps.com/api/mcp",
            "headers": {"Authorization": "Bearer xs_YOUR_KEY"}},  # or {"X-Trial": "1"}
    cache_tools_list=True,
) as server:
    agent = Agent(name="Researcher", mcp_servers=[server])
    result = await Runner.run(agent, "Search the news for x402 protocol")
    print(result.final_output)

JavaScript

import { Agent, run, MCPServerStreamableHttp } from "@openai/agents";

const server = new MCPServerStreamableHttp({
  name: "x402serps",
  url: "https://x402serps.com/api/mcp",
  requestInit: { headers: { Authorization: `Bearer ${process.env.X402SERPS_KEY}` } },
});
await server.connect();
try {
  const agent = new Agent({ name: "Researcher", mcpServers: [server] });
  console.log((await run(agent, "Search the web for x402")).finalOutput);
} finally { await server.close(); }

Hosted MCP tool (Python)

from agents import HostedMCPTool
HostedMCPTool(tool_config={"type": "mcp", "server_label": "x402serps",
    "server_url": "https://x402serps.com/api/mcp", "headers": {"Authorization": "Bearer xs_YOUR_KEY"},
    "require_approval": "never"})

Pay per call with x402 instead: tool calls without a trial header or key return the x402 payment requirements, which an x402-aware client can pay in USDC on Base or Solana. Search is $0.004 a call. Buy a credit key on the pricing page.

Pricing · Docs · MCP · Integrations · Help

Related