File tree 1 file changed +13
-7
lines changed
src/upsonicai/server/tools/server
1 file changed +13
-7
lines changed Original file line number Diff line number Diff line change @@ -26,25 +26,31 @@ class ListToolsRequest(BaseRequestMCP):
26
26
pass
27
27
28
28
29
+ # Global variable to store the session
30
+ session_store = None
31
+
29
32
async def get_session (command : str , args : list , env : dict ):
30
33
print ("env" , env )
31
34
print ("args" , args )
32
35
print ("command" , command )
33
36
34
- if env :
35
- env = get_default_environment ()
36
- env .update (env ) if env else None
37
-
38
37
server_params = StdioServerParameters (
39
38
command = command , # Executable
40
39
args = args , # Optional command line arguments
41
40
env = env , # Environment variables
42
41
)
43
42
async with stdio_client (server_params ) as (read , write ):
44
43
async with ClientSession (read , write ) as session :
45
- await session .initialize ()
46
- yield session
47
- await session .close ()
44
+ try :
45
+ print ("Initializing session..." )
46
+ await session .initialize ()
47
+ print ("Session initialized." )
48
+ yield session
49
+ except Exception as e :
50
+ print (f"Error in session: { e } " )
51
+ raise
52
+ finally :
53
+ print ("Session cleanup." )
48
54
49
55
50
56
@app .post (f"{ prefix } /tools" )
You can’t perform that action at this time.
0 commit comments