Skip to content

Commit 1604073

Browse files
Merge pull request #75 from a-akimov/fix-module-not-found
Fix the "module not found" error
2 parents 6785f80 + 8453de0 commit 1604073

File tree

1 file changed

+14
-8
lines changed

1 file changed

+14
-8
lines changed

mcp-client-python/client.py

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
from anthropic import Anthropic
99
from dotenv import load_dotenv
10+
from pathlib import Path
1011

1112
load_dotenv() # load environment variables from .env
1213

@@ -30,14 +31,19 @@ async def connect_to_server(self, server_script_path: str):
3031
is_js = server_script_path.endswith('.js')
3132
if not (is_python or is_js):
3233
raise ValueError("Server script must be a .py or .js file")
33-
34-
command = "python" if is_python else "node"
35-
server_params = StdioServerParameters(
36-
command=command,
37-
args=[server_script_path],
38-
env=None
39-
)
40-
34+
35+
if is_python:
36+
path = Path(server_script_path).resolve()
37+
server_params = StdioServerParameters(
38+
command="uv",
39+
args=["--directory", str(path.parent), "run", path.name],
40+
env=None,
41+
)
42+
else:
43+
server_params = StdioServerParameters(
44+
command="node", args=[server_script_path], env=None
45+
)
46+
4147
stdio_transport = await self.exit_stack.enter_async_context(stdio_client(server_params))
4248
self.stdio, self.write = stdio_transport
4349
self.session = await self.exit_stack.enter_async_context(ClientSession(self.stdio, self.write))

0 commit comments

Comments
 (0)