File tree Expand file tree Collapse file tree 2 files changed +12
-5
lines changed
Expand file tree Collapse file tree 2 files changed +12
-5
lines changed Original file line number Diff line number Diff line change 1- from contextlib import asynccontextmanager
1+ from contextlib import AsyncExitStack , asynccontextmanager
22from typing import Annotated , AsyncGenerator
33
44from fastapi import Depends
@@ -41,12 +41,19 @@ async def setup_graph() -> AsyncGenerator[Resource]:
4141 async with checkpointer_context (
4242 settings .checkpoint_conn_str
4343 ) as checkpointer :
44- async with mcp_sse_client () as session :
45- tools = await load_mcp_tools (session )
44+ tools = []
45+ sessions = []
46+ async with AsyncExitStack () as stack :
47+ for hostname in settings .mcp_hostnames :
48+ session = await stack .enter_async_context (
49+ mcp_sse_client (hostname )
50+ )
51+ tools += await load_mcp_tools (session )
52+ sessions .append (session )
4653 yield Resource (
4754 checkpointer = checkpointer ,
4855 tools = tools ,
49- session = session ,
56+ sessions = sessions ,
5057 )
5158
5259
Original file line number Diff line number Diff line change 77class Resource (BaseModel ):
88 checkpointer : AsyncPostgresSaver
99 tools : list [StructuredTool ]
10- session : ClientSession
10+ sessions : list [ ClientSession ]
1111
1212 class Config :
1313 arbitrary_types_allowed = True
You can’t perform that action at this time.
0 commit comments