langchain_mcp_adapters - MultiServerMCPClient 获取工具
文章目录
- 获取 Server 和 tool 数据
- `vars(tool)`
- loaded_tools
获取 Server 和 tool 数据
import asyncio
from langchain_mcp_adapters.client import MultiServerMCPClientasync def get_tools():mcp_servers = { 'amap-amap-sse': {'transport': 'sse', 'url': 'https://mcp.amap.com/sse?key=1d01...20d600da'}}loaded_tools = []client = MultiServerMCPClient(mcp_servers) print('-- mcp client', client) tools = await client.get_tools() for tool in tools: print('\n-- tool name : ', tool.name) print(tool.description) loaded_tools.append(tool)print('-- loaded_tools : ', loaded_tools, len(loaded_tools) ) print(vars(tool)) if __name__ == '__main__':asyncio.run(get_tools())
vars(tool)
{'name': 'maps_weather','description': '根据城市名称或者标准adcode查询指定城市的天气','args_schema': {'type': 'object','properties': {'city': {'type': 'string','description': '城市名称或者adcode'}},'required': ['city']},'response_format': 'content_and_artifact','coroutine': < function convert_mcp_tool_to_langchain_tool. < locals > .call_tool at 0x10c82f1a0 >,'return_direct': False,'verbose': False,'callbacks': None,'callback_manager': None,'tags': None,'metadata': None,'handle_tool_error': False,'handle_validation_error': False,'func': None,
}
loaded_tools
[StructuredTool(name = 'maps_direction_bicycling',description = '骑行路径规划用于规划骑行通勤方案,规划时会考虑天桥、单行线、封路等情况。最大支持 500km 的骑行路线规划',args_schema = {'type': 'object','properties': {'origin': {'type': 'string','description': '出发点经纬度,坐标格式为:经度,纬度'},'destination': {'type': 'string','description': '目的地经纬度,坐标格式为:经度,纬度'}},'required': ['origin', 'destination']},response_format = 'content_and_artifact',coroutine = < function convert_mcp_tool_to_langchain_tool. < locals > .call_tool at 0x1076efb00 > ),StructuredTool(name = 'maps_direction_driving',description = '驾车路径规划 API 可以根据用户起终点经纬度坐标规划以小客车、轿车通勤出行的方案,并且返回通勤方案的数据。',args_schema = {'type': 'object','properties': {'origin': {'type': 'string','description': '出发点经纬度,坐标格式为:经度,纬度'},'destination': {'type': 'string','description': '目的地经纬度,坐标格式为:经度,纬度'}},'required': ['origin', 'destination']},response_format = 'content_and_artifact',coroutine = < function convert_mcp_tool_to_langchain_tool. < locals > .call_tool at 0x10c82e2a0 > ),...StructuredTool(name = 'maps_weather',description = '根据城市名称或者标准adcode查询指定城市的天气',args_schema = {'type': 'object','properties': {'city': {'type': 'string','description': '城市名称或者adcode'}},'required': ['city']},response_format = 'content_and_artifact',coroutine = < function convert_mcp_tool_to_langchain_tool. < locals > .call_tool at 0x10c82f1a0 > )
]
2025-06-14(六)