# Mastra.ai TypeScript Trading Agent + Eterna MCP

> Configure Mastra's `MCPClient` with `url: new URL('https://mcp.eterna.exchange/mcp')` and Bearer OAuth headers to expose Eterna's `search_sdk`, `search_examples`, and `execute_code` tools inside Mastra Agents and durable Workflows.

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

Mastra.ai brings typed workflows, memory, evals, and observability to TypeScript agent teams - matching Eterna's TypeScript `execute_code` SDK seamlessly end-to-end.

## Key Facts

| Metric | Value | Notes |
|--------|-------|-------|
| Stack Alignment | 100% TypeScript | Mastra + Eterna Deno SDK |
| MCP Client | @mastra/mcp | Native Streamable HTTP |
| Observability | Tracing & Evals | Log every execute_code payload |
| Cost | $0 Eterna MCP fee | 0.014%/0.035% perp fees |

## 1. Connect `@mastra/mcp` to Eterna MCP

### mastra-eterna-agent.ts

```typescript
import { Agent } from "@mastra/core/agent";
import { MCPClient } from "@mastra/mcp";
import { anthropic } from "@ai-sdk/anthropic";

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

export const eternaTrader = new Agent({
  name: "Eterna Systematic Trader",
  instructions:
    "Always inspect balance, positions, and orderbook spread before proposing any trade. Cap leverage at 3x and require stopLoss and takeProfit.",
  model: anthropic("claude-sonnet-4-5"),
  tools: await mcp.getTools(),
});
```

## Frequently Asked Questions

### Why use Mastra Workflows alongside Eterna MCP?

Mastra Workflows let you wrap deterministic pre-trade risk checks, retry logic, and human suspend/resume approval gates around the LLM agent before live orders execute.

## References & Primary Sources

- [Vercel AI SDK Integration](https://ai.eterna.exchange/integrations/vercel-ai-sdk): Related TypeScript streaming integration.

## Related Guides

- [Vercel AI SDK + Eterna MCP Crypto Trading Integration](https://ai.eterna.exchange/integrations/vercel-ai-sdk)
- [CrewAI Multi-Agent Crypto Trading Crew via Eterna MCP](https://ai.eterna.exchange/integrations/crewai)
- [How to Build an AI Crypto Trading Agent with MCP (Step-by-Step)](https://ai.eterna.exchange/ai-trading-agent)
- [Eterna MCP SDK Reference: All 30+ eterna.* Methods](https://ai.eterna.exchange/sdk)
