Spaces:
Running
Running
kongqi commited on
Commit ·
7d2a8d4
1
Parent(s): c562ea5
Add npx validation
Browse files
src/fastmcp/client/transports.py
CHANGED
|
@@ -7,7 +7,7 @@ from pathlib import Path
|
|
| 7 |
from typing import (
|
| 8 |
TypedDict,
|
| 9 |
)
|
| 10 |
-
|
| 11 |
from mcp import ClientSession, StdioServerParameters
|
| 12 |
from mcp.client.session import (
|
| 13 |
ListRootsFnT,
|
|
@@ -341,6 +341,10 @@ class NpxStdioTransport(StdioTransport):
|
|
| 341 |
env_vars: Additional environment variables
|
| 342 |
use_package_lock: Whether to use package-lock.json (--prefer-offline)
|
| 343 |
"""
|
|
|
|
|
|
|
|
|
|
|
|
|
| 344 |
# Basic validation
|
| 345 |
if project_directory and not Path(project_directory).exists():
|
| 346 |
raise NotADirectoryError(
|
|
|
|
| 7 |
from typing import (
|
| 8 |
TypedDict,
|
| 9 |
)
|
| 10 |
+
import shutil
|
| 11 |
from mcp import ClientSession, StdioServerParameters
|
| 12 |
from mcp.client.session import (
|
| 13 |
ListRootsFnT,
|
|
|
|
| 341 |
env_vars: Additional environment variables
|
| 342 |
use_package_lock: Whether to use package-lock.json (--prefer-offline)
|
| 343 |
"""
|
| 344 |
+
# verify npx is installed
|
| 345 |
+
if shutil.which("npx") is None:
|
| 346 |
+
raise ValueError("Command 'npx' not found")
|
| 347 |
+
|
| 348 |
# Basic validation
|
| 349 |
if project_directory and not Path(project_directory).exists():
|
| 350 |
raise NotADirectoryError(
|