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 dotenv import load_dotenv
from pathlib import Path
load_dotenv() # load environment variables from .env
@ -30,14 +31,19 @@ class MCPClient:
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))