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.
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.
https://mcp.eterna.exchange/mcp1. 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`.
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();
}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.
Frequently asked questions
Should I call Eterna MCP directly from the browser?
Does `@ai-sdk/mcp` work with Eterna's `execute_code` sandbox?
References & verification links
- Eterna AI Building GuideStep-by-step architecture for production AI trading agents.
- Eterna MCP Server CardMachine-readable server metadata and transport info.
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.