Framework Integration

Vercel AI SDK + Eterna MCP Crypto Trading Integration

Building a web-based crypto copilot, Telegram Mini App, or internal desk dashboard in TypeScript? The Vercel AI SDK pairs cleanly with Eterna's remote MCP endpoint so you can stream reasoning, tool outputs, and approval cards straight to React.

Updated: By Eterna Engineering (MCP & Agent Infrastructure Team)Read as Markdown
Quick Answer

Use `createMCPClient` from `@ai-sdk/mcp` with `type: 'http'` pointed at `https://mcp.eterna.exchange/mcp` inside a Next.js Route Handler or Server Action. Pass `await mcpClient.tools()` directly to `streamText` or `generateText` to build custom AI trading copilots across Claude, GPT, and Gemini models.

SDK Packageai + @ai-sdk/mcpNative HTTP MCP transport
Model FlexibilityModel agnosticSwap Claude, OpenAI, Gemini in 1 line
Server-Only AuthOAuth 2.1 BearerTokens stay server-side, never in browser
Latency<200ms executionSingle sandbox round-trip per turn
https://mcp.eterna.exchange/mcp

1. Connect `@ai-sdk/mcp` in a Next.js Server Route

Initialize the MCP client per authenticated user session on the server, pass the Eterna tools to `streamText`, and close the client in `onFinish`.

app/api/trade-chat/route.ts
import { streamText, stepCountIs } from "ai";
import { createMCPClient } from "@ai-sdk/mcp";
import { anthropic } from "@ai-sdk/anthropic";

export async function POST(req: Request) {
  const { messages } = await req.json();
  const accessToken = process.env.ETERNA_ACCESS_TOKEN;

  const mcpClient = await createMCPClient({
    transport: {
      type: "http",
      url: "https://mcp.eterna.exchange/mcp",
      headers: { Authorization: `Bearer ${accessToken}` },
    },
  });

  const tools = await mcpClient.tools();

  const result = streamText({
    model: anthropic("claude-sonnet-4-5"),
    system:
      "You are a risk-disciplined trading assistant connected to Eterna MCP. Always inspect balance and positions before proposing trades.",
    messages,
    tools,
    stopWhen: stepCountIs(5),
    onFinish: async () => {
      await mcpClient.close();
    },
  });

  return result.toUIMessageStreamResponse();
}
Note: Always bind per-user OAuth tokens server-side and enforce human confirmation UI before invoking order mutations.

2. Production Patterns for Web Trading Copilots

Keep custody isolation and auditability intact when exposing an AI trading agent to end users.

  • Use per-user OAuth 2.1 tokens via `ai-auth.eterna.exchange` so each user trades inside their own isolated sub-account.
  • Cap `stopWhen: stepCountIs(5)` to avoid infinite retry loops during exchange volatility.
  • Render structured trade-ticket confirmation cards in React before permitting the model to call `eterna.placeOrder`.
  • Log every `execute_code` snippet and returned JSON object for post-trade auditability.
FAQ

Frequently asked questions

Should I call Eterna MCP directly from the browser?
No. Keep MCP client sessions and OAuth access tokens inside Next.js Route Handlers, Server Actions, or a backend service.
Does `@ai-sdk/mcp` work with Eterna's `execute_code` sandbox?
Yes. `mcpClient.tools()` exposes `search_sdk`, `search_examples`, and `execute_code` automatically with full Zod/JSON schemas.
Primary Sources

References & verification links

Start Trading via MCP

Connect your AI agent in 30 seconds

One remote MCP URL. 800+ USDT perpetuals, 380+ spot pairs, 0.014% maker / 0.035% taker, no KYC.

View on GitHub