LlamaIndex
เชื่อมต่อ agent ของ LlamaIndex กับ Edison Watch โดยใช้ BasicMCPClient และ McpToolSpec
LlamaIndex เชื่อมต่อกับ Edison ด้วย BasicMCPClient ซึ่งเลือก streamable HTTP โดยอัตโนมัติสำหรับ URL แบบ https:// อย่างของ Edison McpToolSpec เปลี่ยน tools ของ server ให้เป็น LlamaIndex tools connection URL ของคุณมี API key อยู่แล้ว ดังนั้นไม่ต้องใช้ auth header
pip install llama-index-tools-mcp llama-index-llms-openai llama-indeximport asyncio
import os
from llama_index.tools.mcp import BasicMCPClient, McpToolSpec
from llama_index.llms.openai import OpenAI
from llama_index.core.agent.workflow import FunctionAgent
async def main() -> None:
client = BasicMCPClient(os.environ["EDISON_MCP_URL"])
tools = await McpToolSpec(client=client).to_tool_list_async()
agent = FunctionAgent(tools=tools, llm=OpenAI(model="gpt-5.4-mini"))
response = await agent.run("List my available tools.")
print(response)
asyncio.run(main())ตั้งค่า EDISON_MCP_URL เป็น connection URL ของคุณ เช่น https://mcp.edison.watch/mcp/<your-api-key>/?client=llamaindex
llama-index-llms-openai จะ resolve แต่ละ model กับ ตาราง context-window
ที่ hardcode ไว้ และ raise ValueError: Unknown model สำหรับ id ที่ไม่อยู่ในตาราง -
ดังนั้น model id ใหม่มากอาจล้มเหลวจนกว่าคุณจะอัปเกรด integration เลือก model ที่
เวอร์ชันที่ติดตั้งรู้จัก (อัปเกรดด้วย pip install -U llama-index-llms-openai)
หรือใช้ OpenAILike จาก llama-index-llms-openai-like เพื่อข้ามตารางทั้งหมด
ทางเลือก: header สำหรับ encrypted secrets
สำหรับ server ที่มี ความลับที่เข้ารหัสแบบ zero-knowledge BasicMCPClient รับ headers dict:
client = BasicMCPClient(
os.environ["EDISON_MCP_URL"],
headers={"x-edison-secret-key": os.environ["EDISON_SECRET_KEY"]},
)helper ที่ใช้งานง่าย get_tools_from_mcp_url / aget_tools_from_mcp_url ไม่รับ argument headers เพื่อส่ง custom header ด้วยมัน ให้ส่ง client ที่สร้างไว้ล่วงหน้า: aget_tools_from_mcp_url(url, client=BasicMCPClient(url, headers=...))

