|
from llama_index.tools.mcp import BasicMCPClient |
|
from dotenv import load_dotenv |
|
import os |
|
import asyncio |
|
load_dotenv() |
|
HF_TOKEN = os.getenv("HF_TOKEN") |
|
async def connect_and_get_tools(): |
|
|
|
http_client = BasicMCPClient("https://huggingface.co/mcp", headers={"Authorization": f"Bearer {HF_TOKEN}"}) |
|
|
|
|
|
tools = await asyncio.wait_for(http_client.list_tools(), timeout=10.0) |
|
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 asyncio.wait_for( |
|
http_client.call_tool(tool_name, tool_args), |
|
timeout=30.0 |
|
) |
|
return result |
|
|