Files
karuo-ai/01_卡资(金)/金仓_存储备份/Cursor持久对话/check-mcp.sh
2026-07-19 00:21:46 +08:00

107 lines
4.2 KiB
Bash
Executable File
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#!/usr/bin/env bash
# 深度检查 persistent-chat 是否真正可用
set -u
INSTALL_DIR="${PCHAT_INSTALL_DIR:-$HOME/.persistent-chat-local}"
GLOBAL_MCP="$HOME/.cursor/mcp.json"
PORT="${PCHAT_HTTP_PORT:-13458}"
FAIL=0
ok() { echo "$1"; }
bad() { echo "$1"; FAIL=$((FAIL+1)); }
warn() { echo " ⚠️ $1"; }
echo "🔍 Persistent Chat 深度连接检查"
echo ""
# 1. 全局 MCP 唯一
if [[ -f "$GLOBAL_MCP" ]] && grep -q '"persistent-chat"' "$GLOBAL_MCP"; then
ok "全局 ~/.cursor/mcp.json 有 persistent-chat"
else
bad "全局 MCP 缺失 → bash install.sh"
fi
# 2. 项目级不应有 duplicate
DUP=$(for f in \
"$HOME/Documents/个人/.cursor/mcp.json" \
"$HOME/Documents/个人/卡若AI/.cursor/mcp.json" \
"$HOME/Documents/开发/3、自营项目/卡若ai网站/.cursor/mcp.json" \
"$HOME/Documents/开发/8、小工具/Docker项目/OpenClaw/.cursor/mcp.json" \
"$HOME/Documents/开发/8、小工具/Docker项目/OpenClaw/openclaw/.cursor/mcp.json" \
"$HOME/Documents/开发/7.项目调研/claude-code-sourcemap/.cursor/mcp.json" \
"$HOME/Documents/开发/7.项目调研/tryvoice-oss/.cursor/mcp.json"; do
[[ -f "$f" ]] && grep -q '"persistent-chat"' "$f" 2>/dev/null && echo "$f"
done)
if [[ -n "$DUP" ]]; then
bad "仍有项目级重复 MCP会导致 Settings 出现两个):"
echo "$DUP" | sed 's/^/ /'
echo " → bash 脚本/清理重复MCP.sh"
FAIL=$((FAIL+1))
else
ok "无项目级重复 MCP"
fi
# 3. Hub
HUB=$(curl -sf -m 3 "http://127.0.0.1:${PORT}/api/health" 2>/dev/null || echo "")
if [[ -n "$HUB" ]]; then
ok "Hub 在线 http://127.0.0.1:${PORT}/ (pid $(echo "$HUB" | python3 -c "import sys,json; print(json.load(sys.stdin).get('pid','?'))" 2>/dev/null))"
else
bad "Hub 离线 → node $INSTALL_DIR/hub.js &"
fi
# 4. MCP stdio 工具列表(模拟 Cursor 调用)
NODE="${PCHAT_NODE:-$(command -v node 2>/dev/null || echo /usr/local/opt/node@22/bin/node)}"
if [[ -x "$INSTALL_DIR/ensure-hub.sh" ]]; then
EXPECTED=$(python3 - <<'PY'
import json, os
p = os.path.expanduser('~/.cursor/mcp.json')
try:
d = json.load(open(p, encoding='utf-8'))
env = d.get('mcpServers', {}).get('persistent-chat', {}).get('env', {})
print(4 if env.get('PCHAT_TOOL_SET') == '4' else 9)
except Exception:
print(4)
PY
)
TOOLS=$(printf '{"jsonrpc":"2.0","id":1,"method":"initialize","params":{"protocolVersion":"2024-11-05","capabilities":{},"clientInfo":{"name":"check","version":"1"}}}\n{"jsonrpc":"2.0","method":"notifications/initialized"}\n{"jsonrpc":"2.0","id":2,"method":"tools/list"}\n' | PCHAT_TOOL_SET="$EXPECTED" PCHAT_VSIX_4TOOLS="$([[ "$EXPECTED" == "4" ]] && echo 1 || echo 0)" "$INSTALL_DIR/ensure-hub.sh" --workspace=/tmp 2>/dev/null | tail -1 || echo "")
COUNT=$(echo "$TOOLS" | python3 -c "import sys,json; d=json.load(sys.stdin); print(len(d.get('result',{}).get('tools',[])))" 2>/dev/null || echo "0")
if [[ "${COUNT:-0}" == "${EXPECTED:-4}" ]]; then
ok "MCP 工具可用 (${COUNT} tools与配置一致)"
else
bad "MCP 工具列表异常 (got ${COUNT:-0}, expected ${EXPECTED:-4})"
fi
else
warn "跳过 MCP stdio 测试ensure-hub.sh 不存在)"
fi
# 5. 面板
CODE=$(curl -s -o /dev/null -w "%{http_code}" -m 2 "http://127.0.0.1:${PORT}/" 2>/dev/null || echo 000)
[[ "$CODE" == "200" ]] && ok "面板 HTML 可访问" || bad "面板 HTTP $CODE"
# 6. MCP 进程数 & vscdb 可读(防 interrupted
SRV_CNT=$(ps aux 2>/dev/null | grep '[s]erver.js.*persistent-chat-local' | wc -l | tr -d ' ')
SRV_CNT=${SRV_CNT:-0}
if [[ "${SRV_CNT:-0}" -le 8 ]]; then
ok "MCP server.js 进程数 ${SRV_CNT}≤8 正常)"
else
warn "MCP server.js 进程过多 (${SRV_CNT}) → Cmd+Q 重启 Cursor"
fi
VSCDB="$HOME/Library/Application Support/Cursor/User/globalStorage/state.vscdb"
if [[ -f "$VSCDB" ]]; then
if sqlite3 -cmd '.timeout 3000' "$VSCDB" "SELECT 1;" >/dev/null 2>&1; then
ok "Cursor state.vscdb 可读busy_timeout 正常)"
else
bad "state.vscdb 锁定/不可读 → 重启 Cursor"
fi
else
warn "未找到 state.vscdbCursor 未装或路径变更)"
fi
echo ""
if [[ $FAIL -eq 0 ]]; then
echo "🟢 全部通过。Cursor Settings 应只显示 1 个 persistent-chat · 绿点 · 4 tools enabled"
exit 0
else
echo "🔴 $FAIL 项未通过。修复后 Cmd+Q 重启 Cursor。"
exit 1
fi