"""
同时获取多个MCP工具
使用获取资源的函数
使用自己的MCP stdio 与 sse
"""

import asyncio
from langchain_mcp_adapters.client import MultiServerMCPClient

#1. 配置MCP客户端
mcp_config = {
    "amap": {
        "url": "https://mcp.api-inference.modelscope.net/6ae8935632f641/sse",
        "transport": "sse",
    },
    "mcp_tools": {
        "url": "http://localhost:8000/sse",   # 指向上面启动的 FastMCP 服务
        "transport": "sse",
    },
}

client = MultiServerMCPClient(mcp_config)

async def get_mcp_tools():
        # 获取MCP工具
        tools = await client.get_tools()
        print(f"当前可用工具：{[t.name for t in tools]}")
        # 从指定 MCP Server 的 Resource 中读取数据
        # 每个 Resource 通过 URI 定位，就像访问一个 RESTful 端点
        async with client.session("mcp_tools") as session:
            # 拉取三条公司制度作为增强上下文
            leave_policy = await session.read_resource("knowledge://请假流程")
            expense_policy = await session.read_resource("knowledge://报销标准")
            print(f"[知识库] 请假流程: {leave_policy.contents[0].text}")
            print(f"[知识库] 报销标准: {expense_policy.contents[0].text}")
    
if __name__ == "__main__":
   asyncio.run(get_mcp_tools())