Merge pull request #75 from a-akimov/fix-module-not-found

Fix the "module not found" error
This commit is contained in:
Jonathan Hefner 2025-11-17 07:57:20 -06:00 • committed by GitHub
commit 1604073254
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -7,6 +7,7 @@ from mcp.client.stdio import stdio_client
from anthropic import Anthropic from anthropic import Anthropic
from dotenv import load_dotenv from dotenv import load_dotenv
from pathlib import Path
load_dotenv() # load environment variables from .env load_dotenv() # load environment variables from .env
@ -30,14 +31,19 @@ class MCPClient:
is_js = server_script_path.endswith('.js') is_js = server_script_path.endswith('.js')
if not (is_python or is_js): if not (is_python or is_js):
raise ValueError("Server script must be a .py or .js file") raise ValueError("Server script must be a .py or .js file")
command = "python" if is_python else "node" if is_python:
server_params = StdioServerParameters( path = Path(server_script_path).resolve()
command=command, server_params = StdioServerParameters(
args=[server_script_path], command="uv",
env=None 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)) stdio_transport = await self.exit_stack.enter_async_context(stdio_client(server_params))
self.stdio, self.write = stdio_transport self.stdio, self.write = stdio_transport
self.session = await self.exit_stack.enter_async_context(ClientSession(self.stdio, self.write)) self.session = await self.exit_stack.enter_async_context(ClientSession(self.stdio, self.write))