mirror of
https://github.com/openswarm-ai/openswarm.git
synced 2026-08-24 21:42:22 +02:00
[eric] reddit mcp electron npm build fix
This commit is contained in:
@@ -402,11 +402,25 @@ def derive_mcp_config(tool: ToolDefinition) -> Optional[dict]:
|
||||
|
||||
if config.get("type") == "stdio":
|
||||
if config.get("command"):
|
||||
resolved = _resolve_command(config["command"])
|
||||
if resolved:
|
||||
config["command"] = resolved
|
||||
else:
|
||||
logger.warning(f"Command '{config['command']}' not found on PATH or bundled directories")
|
||||
# Check for bundled npm MCP servers — use Electron's Node.js instead of npx
|
||||
if config["command"] in ("npx", "bunx"):
|
||||
pkg_name = next((a for a in (config.get("args") or []) if not a.startswith("-")), None)
|
||||
if pkg_name:
|
||||
_backend = os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
|
||||
bundle_path = os.path.join(_backend, "mcp-bundles", f"{pkg_name}.js")
|
||||
electron_path = os.environ.get("OPENSWARM_ELECTRON_PATH")
|
||||
if os.path.isfile(bundle_path) and electron_path:
|
||||
config["command"] = electron_path
|
||||
config["args"] = [bundle_path]
|
||||
config.setdefault("env", {})["ELECTRON_RUN_AS_NODE"] = "1"
|
||||
logger.info(f"Using bundled MCP server for {pkg_name}")
|
||||
|
||||
if not os.path.isabs(config.get("command", "")):
|
||||
resolved = _resolve_command(config["command"])
|
||||
if resolved:
|
||||
config["command"] = resolved
|
||||
else:
|
||||
logger.warning(f"Command '{config['command']}' not found on PATH or bundled directories")
|
||||
env = config.setdefault("env", {})
|
||||
env.setdefault("PATH", _augmented_path())
|
||||
env.setdefault("PYTHONPATH", "")
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -66,6 +66,22 @@ else
|
||||
fi
|
||||
echo ""
|
||||
|
||||
# Step 0b: Bundle npm MCP servers (uses Electron's Node at runtime)
|
||||
MCP_BUNDLE_DIR="$PROJECT_ROOT/backend/mcp-bundles"
|
||||
mkdir -p "$MCP_BUNDLE_DIR"
|
||||
if [[ ! -f "$MCP_BUNDLE_DIR/reddit-mcp-buddy.js" ]]; then
|
||||
echo "[0b] Bundling npm MCP servers..."
|
||||
TMPDIR_MCP=$(mktemp -d)
|
||||
cd "$TMPDIR_MCP"
|
||||
npm install reddit-mcp-buddy --silent 2>/dev/null
|
||||
npx esbuild node_modules/reddit-mcp-buddy/dist/index.js --bundle --platform=node --format=cjs --outfile="$MCP_BUNDLE_DIR/reddit-mcp-buddy.js" 2>/dev/null
|
||||
rm -rf "$TMPDIR_MCP"
|
||||
echo "npm MCP servers bundled."
|
||||
else
|
||||
echo "[0b] npm MCP bundles already present."
|
||||
fi
|
||||
echo ""
|
||||
|
||||
# Step 1: Build frontend
|
||||
echo "[1/4] Building frontend..."
|
||||
cd "$PROJECT_ROOT/frontend"
|
||||
|
||||
Reference in New Issue
Block a user