# LangChain — CryptoDataAPI

> Add live crypto market data to LangChain / LangGraph agents: load the CryptoDataAPI MCP tools with MultiServerMCPClient (streamable HTTP + headers). Free tier.

Give your **LangChain / LangGraph** agent live crypto market data — prices, funding, open interest, liquidations, market regimes, Fear & Greed, dealer gamma and whale activity — as ready-to-bind tools.

The cleanest path is `langchain-mcp-adapters`: point `MultiServerMCPClient` at our **[MCP server](/ai-agents/mcp-server)** over streamable HTTP and it returns LangChain tool objects you can pass to any agent. Prefer plain HTTP? Wrap a `requests` call as a `@tool` — the `?format=markdown` option gives you LLM-ready text with no parsing.

- **Vendor:** LangChain
- **Agent docs:** https://docs.langchain.com/oss/python/langchain/mcp
- **Config:** `MultiServerMCPClient (langchain-mcp-adapters)`
- **MCP transports:** http (streamable)

## Step 1 — Install the adapter

Install `langchain-mcp-adapters` alongside your LangChain / LangGraph stack.

**Terminal:**
```bash
pip install langchain-mcp-adapters langgraph "langchain[anthropic]"
```

## Step 2 — Load the MCP tools

Configure `MultiServerMCPClient` with the streamable-HTTP transport, our URL, and your key on the `X-API-Key` header. `get_tools()` returns LangChain tools ready to bind to an agent.

Replace `cdk_live_YOUR_KEY` with your key — a free one comes from [cryptodataapi.com/login](https://cryptodataapi.com/login) or a `POST` to `/api/v1/auth/keys`.

**Python:**
```python
from langchain_mcp_adapters.client import MultiServerMCPClient
from langchain.agents import create_agent

client = MultiServerMCPClient({
    "cryptodataapi": {
        "transport": "streamable_http",
        "url": "https://cryptodataapi.com/mcp",
        "headers": {"X-API-Key": "cdk_live_YOUR_KEY"},
    }
})

tools = await client.get_tools()
agent = create_agent("anthropic:claude-sonnet-5", tools)
resp = await agent.ainvoke(
    {"messages": "What's the current crypto market regime?"}
)
```

## Step 3 — Or wrap the REST API as a tool

Don't need the full MCP toolset? Wrap a single endpoint as a LangChain `@tool`. Use `?format=markdown` so the model gets clean text instead of raw JSON.

**Python (plain HTTP tool):**
```python
import requests
from langchain_core.tools import tool

HEADERS = {"X-API-Key": "cdk_live_YOUR_KEY"}

@tool
def market_snapshot() -> str:
    """Live crypto market snapshot: health, regime, sentiment."""
    r = requests.get(
        "https://cryptodataapi.com/api/v1/daily",
        params={"format": "markdown"}, headers=HEADERS, timeout=30,
    )
    r.raise_for_status()
    return r.text
```

## Example prompts

- "What's the current market regime and which strategy baskets fit it?"
- "Compare BTC funding rates across exchanges and flag crowded positioning."
- "Which coins have the highest liquidation risk right now?"
- "Build me a market brief from the daily snapshot and the Fear & Greed index."
- "Is dealer gamma amplifying or dampening BTC moves today?"

## FAQ

### Does it cost anything?

No. The **Free** API tier (no card) covers the whole market-wide picture. Per-coin quant, gamma and whale signals need [Pro](/pricing).

### MCP adapter or a plain HTTP tool?

Use `MultiServerMCPClient` when you want the full curated toolset with one config block and automatic tool discovery. Wrap a `requests` call as a `@tool` when you only need one or two endpoints and want maximum control (and the `?format=markdown` convenience).

### Do I have to use async?

`get_tools()` and `ainvoke` are async, which fits most LangGraph agents. If you're in synchronous code, run them inside an event loop (`asyncio.run(...)`) or use your framework's sync entry points. The plain `requests` tool is fully synchronous if you'd rather avoid async entirely.

## Related

- [MCP Server](https://cryptodataapi.com/ai-agents/mcp-server)
- [REST API docs](https://cryptodataapi.com/api/docs)
- [n8n setup](https://cryptodataapi.com/ai-agents/n8n)
- [elizaOS setup](https://cryptodataapi.com/ai-agents/elizaos)
- [Prompt library](https://cryptodataapi.com/prompts)

---

Canonical: https://cryptodataapi.com/ai-agents/langchain
Machine-readable API map: https://cryptodataapi.com/llms.txt
Agent skill repo: https://github.com/Crypto-Data-API/cryptodataapi-skills (`npx skills add Crypto-Data-API/cryptodataapi-skills -g -y`)
Free API key (no signup): POST https://cryptodataapi.com/api/v1/auth/keys {"email":"you@example.com"}
