Skip to main content
Glama
LANGGRAPH_MCP_GUIDE.md3.09 kB
# 🔧 LangGraph Agent MCP集成要点 如何将Binance MCP工具集成到您现有的LangGraph Agent中。 ## 🚀 核心集成步骤 ### 1. 安装MCP适配器 ```bash pip install git+https://github.com/shanrichard/binance-mcp.git pip install mcp-langchain # 或 langchain-community ``` ### 2. 启动MCP服务 ```bash binance-mcp config # 配置API密钥 binance-mcp start -d # 后台运行 ``` ### 3. 在您的Agent中添加MCP工具 ```python from mcp_langchain import MCPToolkit # 关键 # 连接到MCP服务器,获取工具 mcp_toolkit = MCPToolkit( server_command="python", server_args=["-m", "binance_mcp.simple_server"], server_env={} ) # 获取转换后的LangChain工具 binance_tools = mcp_toolkit.get_tools() # 添加到您现有的工具列表 your_existing_tools.extend(binance_tools) # 绑定到LLM llm_with_tools = llm.bind_tools(your_existing_tools) ``` ## 🛠️ 完整交易工具集(29个工具) ### 🏪 现货交易 - `create_spot_order` - 创建现货订单 ### 📋 订单管理 - `cancel_order` - 取消订单 - `get_open_orders` - 查看待成交订单 - `get_order_status` - 查询单个订单状态 - `get_my_trades` - 获取成交记录 - `cancel_all_orders` - 批量取消订单 ### 🛡️ 风险控制 - `create_stop_loss_order` - 创建止损订单 - `create_take_profit_order` - 创建止盈订单 - `create_stop_limit_order` - 创建止损限价订单 - `create_trailing_stop_order` - 创建追踪止损订单 - `create_oco_order` - 创建OCO订单 ### 📊 市场数据 - `get_ticker` - 获取价格行情 - `get_order_book` - 获取订单簿深度 - `get_klines` - 获取K线数据 - `get_funding_rate` - 获取资金费率 ### 🎯 期权交易 - `create_option_order` - 创建期权订单 - `get_option_chain` - 获取期权链 - `get_option_positions` - 获取期权持仓 - `get_option_info` - 获取期权合约信息 ### 📈 合约交易 - `create_contract_order` - 创建合约订单 - `close_position` - 一键平仓 - `get_futures_positions` - 获取期货持仓详情 ### 💰 账户管理 - `get_balance` - 查询余额 - `get_positions` - 查看持仓 - `set_leverage` - 设置杠杆倍数 - `set_margin_mode` - 设置保证金模式 - `transfer_funds` - 账户间转账 ### ℹ️ 系统工具 - `get_server_info` - 服务状态 ## ⚡ 快速测试 ```python # 测试工具是否正常加载 tools = mcp_toolkit.get_tools() print(f"加载了 {len(tools)} 个交易工具") # 测试调用 server_info_tool = next(t for t in tools if t.name == "get_server_info") result = server_info_tool.invoke({}) print(f"服务器状态: {result}") ``` ## 🎉 功能完整度 现在您的LangGraph Agent可以: - **现货交易** - 买卖各种数字货币 - **期货合约** - 杠杆交易、一键平仓 - **期权策略** - Call/Put期权买卖 - **风险管控** - 止损止盈、追踪止损、OCO订单 - **深度分析** - K线数据、订单簿、资金费率 - **账户管理** - 杠杆设置、保证金模式、资金划转 **完整的数字货币交易生态,29个专业工具!**🚀

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/shanrichard/binance-mcp'

If you have feedback or need assistance with the MCP directory API, please join our Discord server