|
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" |
|
|
|
async with sse_client(sse_url) as (read, write): |
|
async with ClientSession(read, write) as session: |
|
|
|
await session.initialize() |
|
|
|
|
|
tools = await load_mcp_tools(session) |
|
pprint(f"Loaded tools: {[tool.name for tool in tools]}") |
|
|
|
|
|
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()) |
|
|