OpenAI Agents SDK trend tools through MCP

The OpenAI Agents SDK supports three MCP connection modes: hosted tools for public servers, Streamable HTTP for bearer-authenticated endpoints, and stdio for local subprocesses. Trends MCP exposes get_trends, get_growth, and get_top_trends over Streamable HTTP at api.trendsmcp.ai/mcp, so agents can rank keywords, compare growth windows, and read live leaderboards without custom scrapers.

Why OpenAI Agents need a dedicated trend tool surface

Agents that rely on web search for trend questions get stale snippets, relative Google indexes without cross-platform context, and no stable JSON contract for evaluation. The OpenAI Agents SDK treats MCP servers as first-class tool providers. Trends MCP returns normalized 0-100 scores, optional absolute volume, and growth metadata across Google Search, YouTube, TikTok, Reddit, Amazon, Wikipedia, news volume, npm, Steam, and 15 live trending feeds.

The SDK supports three MCP postures. Picking the wrong one is the most common integration failure: hosted tools delegate connectivity to OpenAI's Responses API, while Streamable HTTP keeps auth and logging in the application runtime.

Choosing a transport for Trends MCP

Deployment need SDK option Trends MCP fit
Public server, OpenAI manages tool round-trips hostedMcpTool Possible if auth model allows platform-side calls with your bearer token
Application owns connection, bearer token in headers MCPServerStreamableHttp Default choice for Trends MCP production use
Local subprocess, no direct HTTP from agent host MCPServerStdio via mcp-remote Works for desktop prototypes; adds a Node wrapper

Trends MCP endpoint: https://api.trendsmcp.ai/mcp with Streamable HTTP transport. Auth header: Authorization: Bearer YOUR_API_KEY. Free tier: 100 requests per month, no credit card. Full reference: trendsmcp.ai/docs.

The MCP project deprecated Server-Sent Events for new integrations. Prefer Streamable HTTP or stdio. The SDK still exposes MCPServerSSE for legacy servers only.

Streamable HTTP setup (recommended)

This pattern keeps the bearer token in the application process and works with any OpenAI model the Agents SDK supports.

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

const trendsServer = new MCPServerStreamableHttp({
  name: 'Trends MCP',
  url: 'https://api.trendsmcp.ai/mcp',
  headers: {
    Authorization: `Bearer ${process.env.TRENDSMCP_API_KEY}`,
  },
});

await trendsServer.connect();

const agent = new Agent({
  name: 'Trend analyst',
  instructions:
    'Use Trends MCP tools for all trend questions. ' +
    'Call get_growth with comma-separated sources when comparing platforms. ' +
    'Use exact source strings from the docs: google search, youtube, tiktok, reddit, amazon.',
  mcpServers: [trendsServer],
});

const result = await run(
  agent,
  'Using TrendsMCP, how has Google Search interest in running shoes grown over 12M and YTD?',
);

console.log(result.finalOutput);
await trendsServer.close();

Python follows the same shape with MCPServerStreamableHttp from agents.mcp. Pass url, name, and headers with the bearer token. Connect before run, close after.

For agents that query multiple MCP servers, the JavaScript SDK provides connectMcpServers to track active and failed connections. The Python SDK accepts a list on mcp_servers and supports mcpConfig options such as includeServerInToolNames: true to disambiguate tool names when several servers are attached.

Hosted MCP setup (Responses API path)

Hosted tools push the tool round-trip into OpenAI's infrastructure. The model lists remote tools and invokes them without a callback to the local Python or Node process. This fits public MCP servers where the auth model allows platform-side calls.

import { Agent, hostedMcpTool } from '@openai/agents';

export const hostedTrendAgent = new Agent({
  name: 'Hosted trend assistant',
  instructions: 'Always use Trends MCP tools for trend data. Never guess numbers.',
  tools: [
    hostedMcpTool({
      serverLabel: 'trends-mcp',
      serverUrl: 'https://api.trendsmcp.ai/mcp',
      headers: {
        Authorization: `Bearer ${process.env.TRENDSMCP_API_KEY}`,
      },
      allowedTools: ['get_trends', 'get_growth', 'get_top_trends'],
    }),
  ],
});

Restrict allowedTools to the three Trends MCP operations so the model does not surface unrelated tools if the server catalog expands. Set requireApproval: 'always' or per-tool overrides when agents run in production with side-effect risk, though read-only trend pulls are typically safe with requireApproval: 'never'.

Hosted MCP requires models that support the Responses API hosted MCP integration. For custom transport control, logging, or non-Responses models, use Streamable HTTP instead.

Stdio setup for local development

When the agent host cannot call HTTPS directly, wrap Trends MCP with mcp-remote:

{
  "trends-mcp": {
    "command": "npx",
    "args": [
      "-y", "mcp-remote",
      "https://api.trendsmcp.ai/mcp",
      "--header", "Authorization:${AUTH_HEADER}"
    ],
    "env": {
      "AUTH_HEADER": "Bearer YOUR_API_KEY"
    }
  }
}

Wire the resulting subprocess through MCPServerStdio with the fullCommand string. This adds a Node dependency and process overhead. Streamable HTTP is simpler for server deployments.

Tool calls agents should learn first

Three operations cover most agent workflows:

get_growth answers prioritization questions. One call with source: "google search, tiktok, amazon" and percent_growth: ["12M", "YTD"] returns growth percentages across platforms for a single keyword. Use this when the user asks whether interest is rising or which channel moved first.

get_trends loads the full weekly series (~5 years) for summarization, charting, or anomaly detection. One source per call. Run parallel calls when multiple sources are needed.

get_top_trends requires a feed type string and no keyword. Examples: Google Trends, TikTok Trending Hashtags, Reddit Hot Posts. Use when the user asks what is trending now without naming a topic.

The MCP server for OpenAI page covers ChatGPT connector setup separately from the Agents SDK. The OpenAI Responses API trends MCP page documents hosted-tool patterns for API-only deployments.

Guardrails that survive production review

Log the date, source, and keyword returned in each tool response so reviewers can trace agent summaries to API output. Cap limit on get_top_trends (default 25, max 200) to control token load. Cache repeated pulls within short windows; trend data is weekly for historical series and minutes-old for live feeds.

When growth looks extreme, follow up with get_trends on the same source and keyword so the agent cites a series rather than a single percentage. For multi-agent stacks that also use LangChain, see LangChain agents with live trend tools for parallel wiring patterns.

Next step

Create a key at trendsmcp.ai/account, connect https://api.trendsmcp.ai/mcp with Streamable HTTP and a bearer header, and copy source strings from the API reference. The Model Context Protocol overview explains why stable tool schemas matter for agent evaluation loops.

Common questions

Use MCPServerStreamableHttp when the agent runtime should own the connection and pass a Bearer token in headers. Use hostedMcpTool only if the deployment model allows OpenAI's Responses API to call the remote server on the model's behalf with acceptable auth boundaries. Use MCPServerStdio with mcp-remote when a local subprocess wrapper is required.
get_trends returns weekly historical series for one source and keyword. get_growth calculates percent change across preset windows like 12M, 3M, or YTD, and accepts comma-separated sources in one call. get_top_trends returns ranked items from live feeds such as Google Trends, TikTok Trending Hashtags, or Reddit Hot Posts when no keyword is supplied.
No, but many teams use both. Agents call MCP during interactive runs while scheduled evaluators POST to https://api.trendsmcp.ai/api with the same bearer token. The request shapes match, which keeps agent traces aligned with offline notebooks.
TikTok expects hashtag-style topics. Reddit expects a subreddit name without the r/ prefix. npm expects an exact package name such as react or @babel/core. Steam expects a game display name such as Elden Ring. Document these constraints in agent instructions so the model does not pass generic phrases to the wrong source.