---
title: 'Tutorial: Use Hive Tools in LangChain and CrewAI Agents'
lastUpdated: '2026-05-31'
byline: founder
nextjs:
  metadata:
    title: LangChain & CrewAI Integration | Hive Intelligence
    description: Connect Hive Intelligence tools to LangChain and CrewAI agents for live crypto prices, DeFi analytics, wallets, and token security.
    alternates:
      canonical: https://www.hiveintelligence.xyz/tutorials/langchain
---

This tutorial shows how to add live Hive crypto data to LangChain and CrewAI agents. Use MCP when your framework can consume a remote tool server directly, and use REST custom tools when you want to expose only a small curated set of Hive calls.

{% ai-doc-actions path="/tutorials/langchain" title="LangChain and CrewAI Integration" /%}

---

## Two ways to integrate

### Option A: MCP Protocol (recommended)

LangChain and CrewAI both support MCP tool servers. This is the simplest path - your agent discovers and calls Hive tools at runtime through the MCP protocol.

**LangChain with MCP:**

```python
from langchain_mcp_adapters.client import MultiServerMCPClient
from langchain.agents import create_agent

client = MultiServerMCPClient(
    {
        "hive": {
            "transport": "http",
            "url": "https://mcp.hiveintelligence.xyz/mcp",
            "headers": {"Authorization": "Bearer YOUR_HIVE_API_KEY"},
        }
    }
)

tools = await client.get_tools()
agent = create_agent("your-provider:your-model", tools)
result = await agent.ainvoke(
    {
        "messages": [
            {
                "role": "user",
                "content": "What's the current price of Bitcoin and is it safe to trade this token?",
            }
        ]
    }
)
```

This uses the `langchain-mcp-adapters` package. Install it with the LangChain model integration your app already uses, then replace `your-provider:your-model` with that configured model id. LangChain calls Streamable HTTP transport `http`; `streamable_http` is accepted as an alias by the adapter.

**CrewAI with MCP:**

CrewAI supports MCP servers through the `mcps` field on agents. Use a structured HTTP MCP configuration so the Bearer token stays in headers:

```python
from crewai import Agent, Task, Crew
from crewai.mcp import MCPServerHTTP

researcher = Agent(
    role="Crypto Research Analyst",
    goal="Provide accurate, live crypto market analysis",
    backstory="A crypto market analyst who verifies live data before answering.",
    mcps=[
        MCPServerHTTP(
            url="https://mcp.hiveintelligence.xyz/mcp",
            headers={"Authorization": "Bearer YOUR_HIVE_API_KEY"},
            streamable=True,
            cache_tools_list=True,
        )
    ],
    llm="your-configured-model",
)

task = Task(
    description="Analyze the top 5 DeFi protocols by TVL and check if their governance tokens are safe",
    expected_output="A concise report with live TVL context, token risk notes, and freshness timestamps.",
    agent=researcher,
)

crew = Crew(agents=[researcher], tasks=[task])
result = crew.kickoff()
```

### Option B: REST API as custom tools

If your framework doesn't support MCP, wrap the Hive REST API as custom LangChain tools:

```python
from langchain_core.tools import tool
import requests

HIVE_API = "https://mcp.hiveintelligence.xyz/api/v1/execute"
HIVE_API_KEY = "YOUR_HIVE_API_KEY"

def hive_call(tool_name: str, args: dict) -> dict:
    response = requests.post(
        HIVE_API,
        headers={"Authorization": f"Bearer {HIVE_API_KEY}", "Content-Type": "application/json"},
        json={"tool": tool_name, "args": args},
        timeout=30,
    )
    response.raise_for_status()
    payload = response.json()
    if not payload.get("ok", False):
        raise RuntimeError(payload.get("error", {}).get("message", "Hive call failed"))
    return payload["data"]

@tool
def get_crypto_price(coin_ids: str, currencies: str = "usd") -> str:
    """Get current prices for cryptocurrencies. coin_ids: comma-separated (e.g. 'bitcoin,ethereum')"""
    result = hive_call("get_price", {"ids": coin_ids, "vs_currencies": currencies})
    return str(result)

@tool
def check_token_security(chain_id: str, contract_address: str) -> str:
    """Check if a token contract is safe. chain_id: '1' for Ethereum, '56' for BSC."""
    result = hive_call("get_token_security", {"chainId": chain_id, "contract_addresses": contract_address})
    return str(result)

@tool
def get_defi_tvl(protocol: str = "") -> str:
    """Get DeFi protocol TVL data. Leave protocol empty for top protocols."""
    result = hive_call("get_protocol_tvl", {"protocol": protocol} if protocol else {})
    return str(result)
```

Then use with any LangChain agent:

```python
from langchain.agents import create_agent

agent = create_agent("your-provider:your-model", [get_crypto_price, check_token_security, get_defi_tvl])
result = await agent.ainvoke(
    {"messages": [{"role": "user", "content": "What's Bitcoin's price and is USDT safe?"}]}
)
```

### Which approach to choose

| | MCP (Option A) | REST Custom Tools (Option B) |
|---|---|---|
| Setup | One connection, full catalog | Define each tool manually |
| Tool discovery | Automatic at runtime | Manual - you choose which tools to expose |
| Best for | Full access to Hive catalog | When you only need 3-5 specific tools |
| Framework support | LangChain, CrewAI, and header-capable MCP clients | Any framework with custom tool support |

### Category endpoints for focused agents

If your agent only needs market data, connect to the category endpoint instead of the root:

```python
"hive-market-data": {
    "url": "https://mcp.hiveintelligence.xyz/hive_market_data/mcp",
    "transport": "http",
    "headers": {"Authorization": "Bearer YOUR_HIVE_API_KEY"},
}
```

This gives your agent 87 market data tools instead of the full catalog - faster discovery, smaller context.

For broader research agents, keep the root endpoint and let the agent use Hive's compact discovery and routing flow. For production workflows with a fixed job, category endpoints usually make prompts easier to audit because the agent only sees the capability set it actually needs.

### Next steps

- [MCP Integration Tutorial](/tutorials/mcp-integration) - Connect Claude and Cursor
- [REST API Tutorial](/tutorials/rest-api) - Direct HTTP integration
- [Tools Reference](/tools) - Browse all 10 categories
- [Workflow Guides](/use-cases) - See complete workflow examples
