# LangChain & LangGraph MCP Crypto Trading Agent

> Connect LangChain or LangGraph to Eterna AI using `langchain-mcp-adapters` (`MultiServerMCPClient`) with `transport: 'streamable_http'` pointed at `https://mcp.eterna.exchange/mcp`. LangGraph's state graph lets you separate market research nodes, deterministic risk-check nodes, and human-in-the-loop interrupts before `execute_code` places any order.

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

LangGraph shines when a trading system needs deterministic state transitions, checkpointing, and mandatory human approval interrupts before live capital is committed. Eterna MCP supplies the execution and technical analysis layer without custom CCXT boilerplate.

## Key Facts

| Metric | Value | Notes |
|--------|-------|-------|
| Adapter Package | langchain-mcp-adapters | Python and TypeScript support |
| Architecture Fit | Research -> Risk -> Execute | Deterministic graph guardrails |
| Human Approval | interrupt() | Pause graph before live placeOrder() |
| Markets | 800+ perps / 380+ spot | Single MCP endpoint |

## 1. Wire Eterna MCP into LangGraph (Python)

Load the 3 Eterna MCP tools dynamically via `MultiServerMCPClient` and bind them to a LangGraph ReAct or custom state graph.

### langgraph_eterna_agent.py

```python
import asyncio
import os
from langchain_mcp_adapters.client import MultiServerMCPClient
from langgraph.prebuilt import create_react_agent

async def main():
    client = MultiServerMCPClient(
        {
            "eterna": {
                "transport": "streamable_http",
                "url": "https://mcp.eterna.exchange/mcp",
                "headers": {
                    "Authorization": f"Bearer {os.environ['ETERNA_ACCESS_TOKEN']}"
                },
            }
        }
    )
    tools = await client.get_tools()
    agent = create_react_agent("anthropic:claude-sonnet-4-5", tools)

    res = await agent.ainvoke(
        {
            "messages": [
                (
                    "user",
                    "Use execute_code to fetch SOLUSDT 15m RSI, Bollinger Bands, and current open positions. Propose a limit entry with stopLoss and takeProfit, but do not submit the order.",
                )
            ]
        }
    )
    print(res["messages"][-1].content)

asyncio.run(main())
```

*Works identically with OpenAI, Anthropic, or Gemini chat models via LangChain model strings.*

## 2. Recommended 3-Node Production Topology

Do not let a single unconstrained LLM loop hold unchecked order authority. Split execution across explicit graph nodes.

| Graph Node | Responsibility | Eterna SDK Calls Allowed |
| --- | --- | --- |
| 1. Scanner Node | Pull tickers, orderbooks, RSI/MACD/EMA/VWAP across watchlist | getTickers, getOrderbook, getRsi, getMacd, getEma, getVwap |
| 2. Risk Gate Node (deterministic) | Verify equity, drawdown limit, max open positions, and max leverage | getBalance, getPositions, getOrders |
| 3. Execution Node (optional interrupt) | Set leverage and place bracket order with mandatory SL/TP | setLeverage, placeOrder, setTradingStop, closePosition |

## Frequently Asked Questions

### Can LangGraph run with Python even though Eterna's sandbox runs TypeScript?

Yes. Your LangGraph orchestration runs in Python, while the LLM writes small TypeScript snippets passed to `execute_code` on Eterna's remote Deno sandbox. You never need Node.js installed on your Python server.

### How do I prevent runaway loops in LangGraph?

Set `recursion_limit`, enforce a deterministic pre-trade Risk Gate node in Python, and cap funds inside the isolated Eterna agent sub-account.

## References & Primary Sources

- [Eterna SDK Reference](https://ai.eterna.exchange/sdk): All 30+ typed SDK methods available inside execute_code.
- [Risk Guardrails Guide](https://ai.eterna.exchange/guides/ai-trading-risk-management-guardrails): Deterministic position sizing and kill-switch patterns.

## Related Guides

- [Vercel AI SDK + Eterna MCP Crypto Trading Integration](https://ai.eterna.exchange/integrations/vercel-ai-sdk)
- [OpenAI Agents SDK & Codex MCP Crypto Trading](https://ai.eterna.exchange/integrations/openai-agents-sdk)
- [AI Crypto Trading Risk Management: Position Sizing, TP/SL & Kill Switches](https://ai.eterna.exchange/guides/ai-trading-risk-management-guardrails)
- [MCP execute_code vs Tool Calling: Why Code-Execution MCP Uses ~90% Fewer Tokens](https://ai.eterna.exchange/guides/execute-code-vs-tool-calling)
