1
1
import asyncio
2
- from mcp import ClientSession , StdioServerParameters , stdio_client
2
+ from mcp import StdioServerParameters , stdio_client
3
3
4
4
from mcp_bridge .config import config
5
+ from mcp_bridge .mcp_clients .session import McpClientSession
5
6
from .AbstractClient import GenericMcpClient
6
7
from loguru import logger
7
8
import shutil
@@ -17,24 +18,28 @@ class StdioClient(GenericMcpClient):
17
18
def __init__ (self , name : str , config : StdioServerParameters ) -> None :
18
19
super ().__init__ (name = name )
19
20
21
+ # logger.debug(f"initializing settings for {name}: {config.command} {" ".join(config.args)}")
22
+
23
+ own_config = config .model_copy (deep = True )
24
+
20
25
env = dict (os .environ .copy ())
21
26
22
27
env = {
23
28
key : value for key , value in env .items ()
24
29
if not any (key .startswith (keyword ) for keyword in venv_keywords )
25
30
}
26
31
27
- # logger.debug(f"env: {env}")
28
-
29
32
if config .env is not None :
30
33
env .update (config .env )
31
34
35
+ own_config .env = env
36
+
32
37
command = shutil .which (config .command )
33
38
if command is None :
34
39
logger .error (f"could not find command { config .command } " )
35
40
exit (1 )
36
41
37
- own_config = config . model_copy ( deep = True )
42
+ own_config . command = command
38
43
39
44
# this changes the default to ignore
40
45
if "encoding_error_handler" not in config .model_fields_set :
@@ -48,7 +53,7 @@ async def _maintain_session(self):
48
53
logger .debug (f"entered stdio_client context manager for { self .name } " )
49
54
assert client [0 ] is not None , f"missing read stream for { self .name } "
50
55
assert client [1 ] is not None , f"missing write stream for { self .name } "
51
- async with ClientSession (* client ) as session :
56
+ async with McpClientSession (* client ) as session :
52
57
logger .debug (f"entered client session context manager for { self .name } " )
53
58
await session .initialize ()
54
59
logger .debug (f"finished initialise session for { self .name } " )
0 commit comments