From c54c00b27cbd3001f45225f4685f8af2c9cd2980 Mon Sep 17 00:00:00 2001 From: varz1 <60377372+varz1@users.noreply.github.com> Date: Wed, 24 Sep 2025 11:49:04 +0800 Subject: [PATCH] =?UTF-8?q?docs:=20=E6=B7=BB=E5=8A=A0=20macOS=20launchd=20?= =?UTF-8?q?=E6=9C=8D=E5=8A=A1=E9=85=8D=E7=BD=AE=E5=92=8C=E5=AE=89=E8=A3=85?= =?UTF-8?q?=E6=8C=87=E5=8D=97=20(#142)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- deploy/macos/readme.md | 62 +++++++++++++++++++++++++++++++++++++++ deploy/macos/xhsmcp.fish | 43 +++++++++++++++++++++++++++ deploy/macos/xhsmcp.plist | 28 ++++++++++++++++++ 3 files changed, 133 insertions(+) create mode 100644 deploy/macos/readme.md create mode 100644 deploy/macos/xhsmcp.fish create mode 100644 deploy/macos/xhsmcp.plist diff --git a/deploy/macos/readme.md b/deploy/macos/readme.md new file mode 100644 index 0000000..eac34c6 --- /dev/null +++ b/deploy/macos/readme.md @@ -0,0 +1,62 @@ +## 后台运行小红书 MCP 的解决方案 - Mac 端 + +通过此方法你可以:通过系统进程管理小红书 MCP + +### 快速开始 + +#### 1. 安装配置 + +1. 打开当前目录下 xhsmcp.plist + 1. 必须:替换 {二进制路径} 为你的小红书 MCP 二进制路径 + 2. 必须:替换 {工作路径} 为你的小红书 MCP 工作路径,必须在有 cookies.json 文件的目录才能正常工作 + 3. 可选:修改默认日志路径 StandardOutPath + 4. 可选:修改默认错误日志路径 StandardErrorPath + 5. 可选:修改错误退出的行为是否重启 KeepAlive + 6. 可选:修改是否开机自动重启 RunAtLoad +2. 安装配置 + 1. ln -s {你编辑后的 plist} ~/Library/LaunchAgents/xhsmcp.plist + 2. launchctl load ~/Library/LaunchAgents/xhsmcp.plist + +至此就完成了配置安装 + +#### 2. 使用配置 + +启动小红书 MCP 服务 + +```bash +launchctl start xhsmcp +``` + +关闭小红书 MCP 服务 + +```bash +launchctl stop xhsmcp +``` + +查看服务状态,输出有进程 ID 则为运行中,也可以通过 curl 检查服务运行状态 + +```bash +launchctl list | grep xhsmcp +``` + +### Shell 脚本管理 (进阶用法) + +如果你使用 fish shell,可以安装该目录下的 xhsmcp.fish,实现类似这样的效果: + +``` bash +~/home +> launchctl list | grep + +- 0 xhsmcp + +~/home +> xhsmcp_status + +✗ xhsmcp 未运行 +是否启动服务? (yes/其他): yes +✓ 服务启动成功 (PID: 76061) + +~/home +> launchctl list | grep +76061 0 xhsmcp +``` diff --git a/deploy/macos/xhsmcp.fish b/deploy/macos/xhsmcp.fish new file mode 100644 index 0000000..288ce79 --- /dev/null +++ b/deploy/macos/xhsmcp.fish @@ -0,0 +1,43 @@ +function xhsmcp_stop + launchctl stop xhsmcp +end + +function xhsmcp_start + launchctl start xhsmcp +end + +function xhsmcp_status + gomcp + set service_name "xhsmcp" + + # 获取服务状态 + set pid_status (launchctl list | grep $service_name | awk '{print $1}') + + if test "$pid_status" != "-" + echo "✓ $service_name 正在运行 (PID: $pid_status)" + read -P "是否停止服务? (yes/其他): " answer + if test "$answer" = "yes" + xhsmcp_stop + echo "✓ 服务已停止" + else + echo "取消操作" + end + else + echo "✗ $service_name 未运行" + read -P "是否启动服务? (yes/其他): " answer + if test "$answer" = "yes" + xhsmcp_start + sleep 1 + set pid_status (launchctl list | grep $service_name | awk '{print $1}') + if test "$pid_status" != "-" + echo "✓ 服务启动成功 (PID: $pid_status)" + else + echo "✗ 服务启动失败,检查日志: /tmp/xhsmcp.err" + return 1 + end + else + echo "取消操作" + return 1 + end + end +end \ No newline at end of file diff --git a/deploy/macos/xhsmcp.plist b/deploy/macos/xhsmcp.plist new file mode 100644 index 0000000..99481a6 --- /dev/null +++ b/deploy/macos/xhsmcp.plist @@ -0,0 +1,28 @@ + + + + + Label + xhsmcp + + ProgramArguments + + {二进制路径} + + + WorkingDirectory + {工作路径} + + RunAtLoad + + + KeepAlive + + + StandardOutPath + /tmp/xhsmcp.log + + StandardErrorPath + /tmp/xhsmcp.err + + \ No newline at end of file