2025-07-11 问题已反馈给官方,期望尽快解决

环境

  • Linux Mint 22.1

  • RustRover 2025.1.4 或者 Pycharm 2025.1.2

  • 插件:lingma 2.5.13

  • fnm 1.38.1 | node v22.17.0 | npm 10.9.2 | npx 10.9.2

问题描述

已知当前系统已通过fnm安装了nodejs

ryan@mt:~$ node -v && npm -v && npx -v
v22.17.0
10.9.2
10.9.2

但是在RustRover中的通义灵码插件中安装mcp服务的时候,仍然会报错:

failed to create MCP client for playwright: failed to start stdio transport: failed to start command: exec: "npx": executable file not found in $PATH

排查

1.查看问题所在

Lingma的MCP服务可以进行自定义命令,通过自定义命令执行某个写好的shell脚本得知,其执行过程中$TERMdumb$-hB ,在这种情况下,不会加载.bashrc,当然了,即使加载了,fnm env也会报错导致找不到npx:

error: process ID out of range

Usage:

ps [options]

Try 'ps --help <simple|list|output|threads|misc|all>'

or 'ps --help <s|l|o|t|m|a>'

for additional help text.

For more details see ps(1).

error: Can't infer shell!

fnm can't infer your shell based on the process tree.

Maybe it is unsupported? we support the following shells:

* bash

* zsh

* fish

* powershell

2.后台的lingma程序

使用命令ps aux | grep lingma 能看到,其实通义灵码是在后台运行了一个lingma的进程(多ide共享),然后通过webscoket交互的,如果我尝试杀掉这个进程,然后手动在我的终端启动:/home/ryan/.lingma/bin/2.5.15/x86_64_linux/Lingma start ,这个时候再试一下安装mcp服务,会惊喜的发现,跑通了,能安装了,因为是我直接在终端执行的命令,这个时候的环境是有npx命令的,所以不会再报错了。

临时解决

创建一个用户Systemd服务去管理lingma进程

综上,如果说我不使用RustRover的通义灵码插件启动的服务,而是直接手动启起来,那就不会存在找不到npx的问题。开始实践!

1.创建运行脚本

新建文件~/.lingma/bin/run_lingma.sh ,内容如下

#!/bin/bash

FNM_PATH="$HOME/.local/share/fnm"
if [ -d "$FNM_PATH" ]; then
  export PATH="$FNM_PATH:$PATH"
  eval "`fnm env --shell=bash`"
fi


# 配置文件路径
CONFIG_FILE="$HOME/.lingma/bin/config.json"

# 检查配置文件是否存在
if [ ! -f "$CONFIG_FILE" ]; then
    echo "错误:找不到配置文件 $CONFIG_FILE" >&2
    exit 1
fi

# 使用 sed 提取版本号
VERSION=$(sed -n 's/.*"cosy.core.version": *"\([^"]*\)".*/\1/p' "$CONFIG_FILE")

if [ -z "$VERSION" ]; then
    echo "错误:无法从配置文件中提取版本号" >&2
    exit 1
fi

# 构建可执行文件路径
LINGMA_BIN="$HOME/.lingma/bin/$VERSION/x86_64_linux/Lingma"

# 检查可执行文件是否存在
if [ ! -f "$LINGMA_BIN" ]; then
    echo "错误:找不到可执行文件 $LINGMA_BIN" >&2
    exit 1
fi

# 执行命令
exec "$LINGMA_BIN" "$@"
  • 其实在.bashrc中的fnm部分eval的是fnm env,这个脚本里改为了fnm env --shell=bash,因为systemd服务启动的时候,很不巧,也是dumb + hB

  • 同时通过文件$HOME/.lingma/bin/config.json去获取可执行文件的绝对路径,防止插件升级后脚本失效

2.创建systemd服务文件

新建文件~/.config/systemd/user/lingma.service ,内容如下

[Unit]
Description=Lingma AI Assistant Service
After=network.target

[Service]
Type=simple
ExecStart=%h/.lingma/bin/run_lingma.sh start
# ExecStop=%h/.lingma/bin/run_lingma.sh stop

# 重启策略
Restart=on-failure
RestartSec=5s

# 工作目录
WorkingDirectory=%h/.lingma

# 日志设置
StandardOutput=journal
StandardError=journal
SyslogIdentifier=lingma-service

[Install]
WantedBy=default.target

3.启动

systemctl --user daemon-reload
systemctl --user enable lingma.service
systemctl --user start lingma.service

这种方案还是有点风险的,比如当某种情况下这个systemd服务挂掉了,那么ide的插件在使用过程中发现socket断了,会尝试使用插件重启,那么npx找不到的问题就又会出现了。可以手动杀掉插件起的服务,然后systemctl --user restart lingma.service即可。

注意每次在插件更新的时候需要重启一下服务: systemctl --user restart lingma.service

总结

这个方案只能算是在当前问题下的临时解决方案,具体后面还要看是否是我的系统的问题,或者是通义灵码插件的问题(等日后插件更新看能不能解决吧)