@@ -30,7 +30,7 @@ class SLIMClient(SLIMBase):
3030
3131 def __init__ (
3232 self ,
33- config : dict [str , Any ],
33+ slim_client_configs : list [ dict [str , Any ] ],
3434 local_organization : str ,
3535 local_namespace : str ,
3636 local_agent : str ,
@@ -59,7 +59,7 @@ def __init__(
5959 """
6060
6161 super ().__init__ (
62- config ,
62+ slim_client_configs ,
6363 local_organization ,
6464 local_namespace ,
6565 local_agent ,
@@ -70,60 +70,30 @@ def __init__(
7070 message_retries = message_retries ,
7171 )
7272
73- async def _send_message (
74- self ,
75- session : slim_bindings .PySessionInfo ,
76- message : bytes ,
77- ) -> None :
78- """Send a message to the remote slim instance.
79-
80- Args:
81- session: Session information for the message
82- message: Message to send in bytes format
83-
84- Raises:
85- RuntimeError: If SLIM is not connected or if sending fails
86- """
87- if not self .is_connected ():
88- raise RuntimeError ("SLIM is not connected. Please use the with statement." )
89-
90- try :
91- logger .debug (
92- "Sending message to remote slim instance" ,
93- extra = {
94- "remote_svc" : str (self .remote_svc_name ),
95- },
96- )
97- # Send message to SLIM instance
98- await self .slim .publish (
99- session ,
100- message ,
101- self .remote_svc_name ,
102- )
103- logger .debug ("Message sent successfully" )
104- except Exception as e :
105- logger .error ("Failed to send message" , exc_info = True )
106- raise RuntimeError (f"Failed to send message: { str (e )} " ) from e
107-
10873 @asynccontextmanager
10974 async def to_mcp_session (self , * args , ** kwargs ):
11075 """Create a new MCP session.
11176
11277 Returns:
113- slim_bindings.PySessionInfo : The new MCP session
78+ slim_bindings.Session : The new MCP session
11479 """
11580 # create session
116- session = await self .slim .create_session (
117- slim_bindings . PySessionConfiguration . FireAndForget (
118- timeout = self . message_timeout ,
81+ session , ack = await self .slim .create_session (
82+ destination = self . remote_svc_name ,
83+ session_config = slim_bindings . SessionConfiguration . PointToPoint (
11984 max_retries = self .message_retries ,
120- sticky = True ,
121- )
85+ timeout = self . message_timeout ,
86+ ),
12287 )
88+ await ack
12389
12490 # create streams
125- async with self .new_streams (session ) as (read_stream , write_stream ):
126- async with ClientSession (
127- read_stream , write_stream , * args , ** kwargs
128- ) as mcp_session :
129- yield mcp_session
91+ try :
92+ async with self .new_streams (session ) as (read_stream , write_stream ):
93+ async with ClientSession (
94+ read_stream , write_stream , * args , ** kwargs
95+ ) as mcp_session :
96+ yield mcp_session
97+ finally :
98+ ack = await self .slim .delete_session (session )
99+ await ack
0 commit comments