LangChain + BananaCrystal: complete integration guide
A step-by-step guide to connecting a LangChain agent to BananaCrystal's MCP server. This gives it the ability to check balances, transfer stablecoins, swap currencies, and handle fiat operations autonomously.
Prerequisites
- Python 3.9+ or Node.js 18+
- A BananaCrystal API key. You can get one free at agents.bananacrystal.com
-
LangChain installed (
pip install langchain langchain-openai) - An OpenAI API key (or any LangChain-compatible LLM)
What you are building
You are building a LangChain agent with real financial autonomy. The agent will be able to check wallet balance, transfer stablecoins, swap currencies, get live exchange rates, view transaction history, and check spending limits.
Setting up BananaCrystal MCP
Step 1: Install the SDK
# Python pip install bananacrystal langchain langchain-openai langchain-mcp # Node.js npm install @bananacrystal/sdk langchain @langchain/openai @langchain/mcp-adapters
Step 2: Set environment variables
BANANACRYSTAL_API_KEY=bc_live_xxxxxxxxxxxx BANANACRYSTAL_ENV=production OPENAI_API_KEY=sk-xxxxxxxxxxxx
Step 3: Initialize the client
import bananacrystal as bc import os client = bc.Client(api_key=os.getenv("BANANACRYSTAL_API_KEY")) wallet = client.wallets.get_or_create( agent_id="langchain-research-agent-v1", currency="USDC", spending_limit=50, max_tx_amount=10, allowed_currencies=["USDC", "USDb", "EURb"] )
Creating the LangChain payment tool
from langchain.tools import tool @tool def transfer_payment(amount: float, recipient: str, currency: str = "USDb") -> str: """Transfer stablecoins to a recipient. Use for paying vendors or services.""" result = client.transfers.send( from_wallet=wallet.id, to=recipient, amount=amount, currency=currency ) return f"Transfer complete. TX: {result.tx_hash} · Fee: ${result.fee}"
Configuring spending limits
Spending limits are enforced at the infrastructure level. The agent cannot exceed them regardless of what the LLM decides.
- spending_limit: maximum total spend per 24-hour rolling window
- max_tx_amount: maximum single transaction amount
- allowed_currencies: whitelist of currencies the agent can use
- allowed_recipients: optional allowlist of recipient addresses
Building a full payment-capable agent
from langchain.agents import AgentExecutor, create_openai_tools_agent from langchain_openai import ChatOpenAI llm = ChatOpenAI(model="gpt-4o", temperature=0) tools = [transfer_payment, check_balance, get_exchange_rate] agent = create_openai_tools_agent(llm, tools, prompt) executor = AgentExecutor(agent=agent, tools=tools, verbose=True) result = executor.invoke({ "input": "Pay vendor-api-7g2 $12.50 for API usage this month" })
Production checklist
-
Set
BANANACRYSTAL_ENV=production(not sandbox) - Configure spending limits appropriate for your use case
- Use separate API keys per agent for independent audit trails
- Enable webhook notifications for transaction confirmations
- Test with small amounts before increasing limits