# OpenAI Agents SDK & Codex MCP Crypto Trading

> The OpenAI Agents SDK (TypeScript and Python) and OpenAI Responses API both support remote streamable-HTTP MCP servers natively. Point `MCPServerStreamableHttp` or the `mcp` tool config at `https://mcp.eterna.exchange/mcp` with an OAuth bearer token to give GPT models all 30+ `eterna.*` trading and technical analysis methods.

- Canonical URL: https://ai.eterna.exchange/integrations/openai-agents-sdk
- Last updated: November 23, 2026
- Author: Eterna Engineering (MCP & Agent Infrastructure Team)
- MCP endpoint: https://mcp.eterna.exchange/mcp

Teams building programmatic GPT trading workflows can skip hand-writing dozens of OpenAI function-calling schemas. Eterna exposes 3 compact MCP tools (`search_sdk`, `search_examples`, `execute_code`) that keep token overhead low even on long reasoning chains.

## Key Facts

| Metric | Value | Notes |
|--------|-------|-------|
| OpenAI Surfaces | Agents SDK + Codex | Works with Responses API and ChatGPT too |
| MCP Transport | Streamable HTTP | https://mcp.eterna.exchange/mcp |
| Tool Overhead | 3 MCP tools | Avoids 50-tool JSON schema bloat |
| Execution Fees | 0.014% / 0.035% | Regular-tier USDT perp maker / taker |

## 1. Connect OpenAI Agents SDK (TypeScript)

Attach Eterna as a streamable HTTP MCP server so the agent discovers SDK docs on demand and runs atomic TypeScript strategies inside `execute_code`.

### openai-eterna-agent.ts

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

const eternaMcp = new MCPServerStreamableHttp({
  url: "https://mcp.eterna.exchange/mcp",
  name: "eterna",
  requestInit: {
    headers: {
      Authorization: `Bearer ${process.env.ETERNA_ACCESS_TOKEN}`,
    },
  },
});

await eternaMcp.connect();

const trader = new Agent({
  name: "EternaPerpAnalyst",
  model: "gpt-5",
  instructions:
    "Use Eterna MCP search_sdk and execute_code to inspect live market data and manage risk. Never exceed 3x leverage. Always set stopLoss and takeProfit.",
  mcpServers: [eternaMcp],
});

const result = await run(
  trader,
  "Check BTCUSDT and ETHUSDT 1h RSI, 50 EMA, and my open positions. Return a concise trade plan without placing an order yet.",
);
console.log(result.finalOutput);
await eternaMcp.close();
```

*Obtain an OAuth bearer token via Eterna OAuth 2.1 device flow (`npx @eterna-hybrid-exchange/cli auth login`).*

## 2. Connect OpenAI Codex CLI

Add Eterna to `~/.codex/config.toml` so Codex coding sessions can query live crypto prices, test indicator scripts, and review open risk alongside your codebase.

### ~/.codex/config.toml

```toml
[mcp_servers.eterna]
url = "https://mcp.eterna.exchange/mcp"
```

## Frequently Asked Questions

### Why use Eterna MCP instead of custom OpenAI function tools?

Custom function tools require you to maintain exchange auth, REST retries, HMAC signatures, indicator math, and 30+ JSON schemas. Eterna MCP exposes 3 tools and runs complete TypeScript logic inside a managed Deno sandbox.

### How do I authenticate a headless OpenAI agent on a server?

Use Eterna's OAuth 2.1 device flow via `npx @eterna-hybrid-exchange/cli` to mint scoped bearer tokens without hardcoding exchange API secrets.

## References & Primary Sources

- [ChatGPT Connector Guide](https://ai.eterna.exchange/integrations/chatgpt): Interactive ChatGPT web connector setup.
- [Eterna OAuth 2.1 Guide](https://ai.eterna.exchange/guides/mcp-oauth-authentication-for-agents): OAuth 2.1 and headless device flow documentation.

## Related Guides

- [ChatGPT Crypto Trading Connector: Trade Perps & Spot via MCP](https://ai.eterna.exchange/integrations/chatgpt)
- [OAuth 2.1 & Device Flow for Automated Crypto Trading Agents](https://ai.eterna.exchange/guides/mcp-oauth-authentication-for-agents)
- [MCP execute_code vs Tool Calling: Why Code-Execution MCP Uses ~90% Fewer Tokens](https://ai.eterna.exchange/guides/execute-code-vs-tool-calling)
- [Eterna MCP SDK Reference: All 30+ eterna.* Methods](https://ai.eterna.exchange/sdk)
