From 8453de06e9751a53653424fbd141c90b51b1129e Mon Sep 17 00:00:00 2001 From: Alex Akimov Date: Sun, 16 Nov 2025 06:54:03 +0100 Subject: [PATCH] Fix the module not found error --- mcp-client-python/client.py | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/mcp-client-python/client.py b/mcp-client-python/client.py index 38fa66c6..219f1ae1 100644 --- a/mcp-client-python/client.py +++ b/mcp-client-python/client.py @@ -7,6 +7,7 @@ from anthropic import Anthropic from dotenv import load_dotenv +from pathlib import Path load_dotenv() # load environment variables from .env @@ -30,14 +31,19 @@ async def connect_to_server(self, server_script_path: str): is_js = server_script_path.endswith('.js') if not (is_python or is_js): raise ValueError("Server script must be a .py or .js file") - - command = "python" if is_python else "node" - server_params = StdioServerParameters( - command=command, - args=[server_script_path], - env=None - ) - + + if is_python: + path = Path(server_script_path).resolve() + server_params = StdioServerParameters( + command="uv", + args=["--directory", str(path.parent), "run", path.name], + env=None, + ) + else: + server_params = StdioServerParameters( + command="node", args=[server_script_path], env=None + ) + stdio_transport = await self.exit_stack.enter_async_context(stdio_client(server_params)) self.stdio, self.write = stdio_transport self.session = await self.exit_stack.enter_async_context(ClientSession(self.stdio, self.write))