File size: 668 Bytes
a604df6 5adb8b6 a604df6 5adb8b6 a604df6 5adb8b6 a604df6 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 |
from llama_index.tools.mcp import BasicMCPClient
from dotenv import load_dotenv
import os
load_dotenv()
HF_TOKEN = os.getenv("HF_TOKEN")
async def connect_and_get_tools():
# Connect to an MCP server using different transports
http_client = BasicMCPClient("https://huggingface.co/mcp", headers={"Authorization": f"Bearer {HF_TOKEN}"})
# List available tools
tools = await http_client.list_tools()
return tools
async def call_tool(tool_name, tool_args):
http_client = BasicMCPClient("https://huggingface.co/mcp", headers={"Authorization": f"Bearer {HF_TOKEN}"})
result = await http_client.call_tool(tool_name, tool_args)
return result
|