-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathinstall.sh
More file actions
164 lines (140 loc) · 6.1 KB
/
Copy pathinstall.sh
File metadata and controls
164 lines (140 loc) · 6.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
#!/bin/bash
# ============================================================
# Apple Intelligence MCP Server - 安裝腳本
# 需求:Apple Silicon Mac + macOS 26 (Tahoe)+
# ============================================================
set -e # 任何錯誤立即中止
REPO_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
PLIST_DIR="$HOME/Library/LaunchAgents"
PLIST_SWIFT="$PLIST_DIR/com.apple-intel-mcp.swift-core.plist"
PLIST_MCP="$PLIST_DIR/com.apple-intel-mcp.server.plist"
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
RED='\033[0;31m'
NC='\033[0m'
info() { echo -e "${GREEN}[✓]${NC} $1"; }
warn() { echo -e "${YELLOW}[!]${NC} $1"; }
error() { echo -e "${RED}[✗]${NC} $1"; exit 1; }
echo ""
echo "╔══════════════════════════════════════════╗"
echo "║ Apple Intelligence MCP Server 安裝 ║"
echo "╚══════════════════════════════════════════╝"
echo ""
# ── 1. 前提條件檢查 ─────────────────────────────────────────
# Apple Silicon 確認
ARCH=$(uname -m)
[ "$ARCH" = "arm64" ] || error "需要 Apple Silicon Mac(目前:$ARCH)"
info "Apple Silicon 確認($ARCH)"
# macOS 版本確認(需要 26+)
MACOS_VERSION=$(sw_vers -productVersion | cut -d. -f1)
[ "$MACOS_VERSION" -ge 26 ] 2>/dev/null || error "需要 macOS 26(Tahoe)或更新版本(目前:$(sw_vers -productVersion))"
info "macOS 版本確認($(sw_vers -productVersion))"
# Swift 確認
command -v swift >/dev/null 2>&1 || error "找不到 Swift,請安裝 Xcode Command Line Tools:xcode-select --install"
info "Swift 確認($(swift --version 2>&1 | head -1))"
# Homebrew Python 確認
PYTHON_BIN="/opt/homebrew/bin/python3"
if [ ! -f "$PYTHON_BIN" ]; then
warn "找不到 Homebrew Python,嘗試安裝..."
command -v brew >/dev/null 2>&1 || error "找不到 Homebrew,請先安裝:https://brew.sh"
brew install python3
fi
info "Python 確認($($PYTHON_BIN --version))"
# ── 2. 編譯 Swift Core Service ───────────────────────────────
info "編譯 Swift Core Service..."
cd "$REPO_DIR/swift-core"
swift build -c release
SWIFT_BIN="$REPO_DIR/swift-core/.build/release/AppleIntelCore"
[ -f "$SWIFT_BIN" ] || error "Swift 編譯失敗"
info "Swift 編譯完成:$SWIFT_BIN"
# ── 3. 建立 Python 虛擬環境並安裝依賴 ───────────────────────
info "設定 Python 虛擬環境..."
cd "$REPO_DIR/mcp-server"
if [ ! -d "venv" ]; then
"$PYTHON_BIN" -m venv venv
fi
source venv/bin/activate
pip install -q -r requirements.txt
deactivate
info "Python 依賴安裝完成"
# ── 4. 建立 launchd plist(自動啟動)────────────────────────
mkdir -p "$PLIST_DIR"
# Swift Core Service plist
cat > "$PLIST_SWIFT" << EOF
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN"
"http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>Label</key>
<string>com.apple-intel-mcp.swift-core</string>
<key>ProgramArguments</key>
<array>
<string>${SWIFT_BIN}</string>
</array>
<key>RunAtLoad</key>
<false/>
<key>KeepAlive</key>
<false/>
<key>StandardErrorPath</key>
<string>/tmp/apple-intel-swift-core.log</string>
</dict>
</plist>
EOF
# Python MCP Server plist
PYTHON_VENV="$REPO_DIR/mcp-server/venv/bin/python3"
cat > "$PLIST_MCP" << EOF
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN"
"http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>Label</key>
<string>com.apple-intel-mcp.server</string>
<key>ProgramArguments</key>
<array>
<string>${PYTHON_VENV}</string>
<string>${REPO_DIR}/mcp-server/server.py</string>
</array>
<key>RunAtLoad</key>
<true/>
<key>KeepAlive</key>
<true/>
<key>StandardOutPath</key>
<string>/tmp/apple-intel-mcp.log</string>
<key>StandardErrorPath</key>
<string>/tmp/apple-intel-mcp.log</string>
</dict>
</plist>
EOF
info "launchd 設定檔建立完成"
# ── 5. 載入並啟動服務 ────────────────────────────────────────
launchctl unload "$PLIST_MCP" 2>/dev/null || true
launchctl load "$PLIST_MCP"
info "MCP Server 已啟動(port 11435)"
# ── 6. 完成 ──────────────────────────────────────────────────
echo ""
echo "╔══════════════════════════════════════════╗"
echo "║ 安裝完成! ║"
echo "╚══════════════════════════════════════════╝"
echo ""
PYTHON_VENV_BIN="$REPO_DIR/mcp-server/venv/bin/python3"
SERVER_PY="$REPO_DIR/mcp-server/server.py"
echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
echo " Claude Desktop(stdio 模式)"
echo " 編輯 ~/Library/Application Support/Claude/claude_desktop_config.json"
echo ""
echo ' "mcpServers": {'
echo ' "apple-intelligence": {'
echo " \"command\": \"${PYTHON_VENV_BIN}\","
echo " \"args\": [\"${SERVER_PY}\", \"--stdio\"]"
echo ' }'
echo ' }'
echo ""
echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
echo " 其他 AI 客戶端(HTTP 模式,已在背景執行)"
echo " MCP Endpoint:http://127.0.0.1:11435/mcp"
echo ""
echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
echo "查看日誌:tail -f /tmp/apple-intel-mcp.log"
echo ""