Merge pull request #75 from a-akimov/fix-module-not-found
Fix the "module not found" error
This commit is contained in:
commit
1604073254
1 changed files with 14 additions and 8 deletions
|
|
@ -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))
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue