mcp-101 / main.py
Yoon-gu Hwang
tool을 gradio mcp에 추가
812e2f4
raw
history blame
943 Bytes
import asyncio
from mcp import ClientSession
from mcp.client.sse import sse_client
from langchain_mcp_adapters.tools import load_mcp_tools
from langgraph.prebuilt import create_react_agent
from pprint import pprint
async def main():
sse_url = "http://127.0.0.1:7860/gradio_api/mcp/sse" # 실제 SSE 서버 URL로 변경
async with sse_client(sse_url) as (read, write):
async with ClientSession(read, write) as session:
# Initialize the connection
await session.initialize()
# Get tools
tools = await load_mcp_tools(session)
pprint(f"Loaded tools: {[tool.name for tool in tools]}")
# Create and run the agent
agent = create_react_agent("openai:gpt-4.1", tools)
agent_response = await agent.ainvoke({"messages": "(3 + 5) x 12?이 뭐야?"})
pprint(agent_response)
if __name__ == "__main__":
asyncio.run(main())