saywatch-mcp 0.0.0-stage → 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (4) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +58 -2
  3. package/package.json +23 -4
  4. package/server.mjs +334 -0
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 SayWatch
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -1,3 +1,59 @@
1
- # Temporary Holding Version
1
+ # saywatch-mcp
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ Let Claude Code, Cursor, Claude desktop and other MCP clients search and read what you recorded on your Apple Watch with the SayWatch app.
4
+
5
+ Read-only, local files only, no network access, zero dependencies (Node.js 18+).
6
+
7
+ ## Before you start
8
+
9
+ In the SayWatch iPhone app: **Settings → Let AI on Your Computer Read Recordings → Choose Sync Folder**. We recommend a `SayWatch` folder in iCloud Drive.
10
+ The app writes transcripts (never audio) to `<folder>/recordings/*.json`.
11
+
12
+ ## Install
13
+
14
+ Claude Code:
15
+
16
+ ```bash
17
+ claude mcp add saywatch -- npx -y saywatch-mcp
18
+ ```
19
+
20
+ Cursor (`~/.cursor/mcp.json`) or Claude desktop (Settings → Developer → Edit Config):
21
+
22
+ ```json
23
+ {
24
+ "mcpServers": {
25
+ "saywatch": { "command": "npx", "args": ["-y", "saywatch-mcp"] }
26
+ }
27
+ }
28
+ ```
29
+
30
+ If your folder isn't `iCloud Drive/SayWatch`, pass `--dir "/path/to/folder"` or set `SAYWATCH_DIR`.
31
+
32
+ ## Tools
33
+
34
+ | Tool | What it does |
35
+ |---|---|
36
+ | `list_recordings` | List recordings by time, optionally within a date range |
37
+ | `search_recordings` | Full-text search; all keywords must match; returns sentences with context |
38
+ | `get_recording` | Read one recording in full, including marks ⚑ |
39
+ | `get_day` | Read every recording from one day (defaults to today) |
40
+ | `get_marked_moments` | Read what was said around the moments you marked on your watch |
41
+
42
+ Then just ask your AI: "What did we decide in this morning's meeting?" or "Where did I mention the budget last week?"
43
+
44
+ ## Development
45
+
46
+ ```bash
47
+ node server.mjs --dir "/path/to/folder"
48
+ ```
49
+
50
+ The server speaks MCP over stdin/stdout (one JSON-RPC message per line) and logs only to stderr.
51
+ The export format is `ExportedRecording` (version 1) in the iOS app's `Phone/FolderExport.swift`; keep both sides in sync.
52
+
53
+ ## 中文说明
54
+
55
+ 让 Claude Code、Cursor、Claude 桌面版等 AI 工具直接搜索你在 Apple Watch 上用「抬手录」录下的话。先在 iPhone 的「设置 → 让电脑上的 AI 读取录音 → 选择同步文件夹」开启同步,再按上面的命令安装即可。只读本地文件,不联网。
56
+
57
+ ## License
58
+
59
+ MIT
package/package.json CHANGED
@@ -1,6 +1,25 @@
1
1
  {
2
2
  "name": "saywatch-mcp",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
3
+ "version": "0.1.0",
4
+ "description": "MCP server that lets Claude Code, Cursor and other AI tools search your SayWatch Apple Watch voice recordings (read-only, local files).",
5
+ "type": "module",
6
+ "bin": {
7
+ "saywatch-mcp": "server.mjs"
8
+ },
9
+ "files": [
10
+ "server.mjs",
11
+ "README.md",
12
+ "LICENSE"
13
+ ],
14
+ "engines": {
15
+ "node": ">=18"
16
+ },
17
+ "keywords": [
18
+ "mcp",
19
+ "apple-watch",
20
+ "voice-recorder",
21
+ "transcription",
22
+ "claude"
23
+ ],
24
+ "license": "MIT"
25
+ }
package/server.mjs ADDED
@@ -0,0 +1,334 @@
1
+ #!/usr/bin/env node
2
+ // saywatch-mcp:让 Claude Code、Cursor、Claude 桌面版等 AI 工具读取 SayWatch(抬手录)同步到电脑的文字。
3
+ // 零依赖,只读本地文件夹,不联网。协议:MCP(JSON-RPC 2.0,stdio,每行一条消息)。
4
+ //
5
+ // 用法:
6
+ // npx -y saywatch-mcp # 默认读 iCloud 云盘/SayWatch
7
+ // npx -y saywatch-mcp --dir "/path/to/folder"
8
+ // 或环境变量 SAYWATCH_DIR=/path/to/folder
9
+
10
+ import { execFile } from "node:child_process";
11
+ import { existsSync } from "node:fs";
12
+ import { readdir, readFile } from "node:fs/promises";
13
+ import { homedir } from "node:os";
14
+ import { join } from "node:path";
15
+ import { createInterface } from "node:readline";
16
+
17
+ const VERSION = "0.1.0";
18
+ const SUPPORTED_PROTOCOLS = ["2025-11-25", "2025-06-18", "2025-03-26", "2024-11-05"];
19
+ const DEFAULT_DIR = join(homedir(), "Library/Mobile Documents/com~apple~CloudDocs/SayWatch");
20
+
21
+ function resolveRoot(argv) {
22
+ const i = argv.indexOf("--dir");
23
+ if (i !== -1 && argv[i + 1]) return argv[i + 1].replace(/^~(?=\/|$)/, homedir());
24
+ if (process.env.SAYWATCH_DIR) return process.env.SAYWATCH_DIR.replace(/^~(?=\/|$)/, homedir());
25
+ return DEFAULT_DIR;
26
+ }
27
+
28
+ const ROOT = resolveRoot(process.argv.slice(2));
29
+ const REC_DIR = join(ROOT, "recordings");
30
+
31
+ // ---------- 读取数据 ----------
32
+
33
+ async function loadAll() {
34
+ if (!existsSync(REC_DIR)) return { recordings: [], missing: true, notDownloaded: 0 };
35
+ const names = await readdir(REC_DIR);
36
+
37
+ // iCloud “优化存储”会把文件变成 .xxx.json.icloud 占位符:触发下载,并告诉 AI 有多少还没下来。
38
+ const placeholders = names.filter((n) => n.startsWith(".") && n.endsWith(".json.icloud"));
39
+ for (const p of placeholders) {
40
+ execFile("brctl", ["download", join(REC_DIR, p)], () => {});
41
+ }
42
+
43
+ const recordings = [];
44
+ for (const name of names) {
45
+ if (!name.endsWith(".json") || name.startsWith(".")) continue;
46
+ try {
47
+ const raw = JSON.parse(await readFile(join(REC_DIR, name), "utf8"));
48
+ if (raw.version !== 1) continue;
49
+ recordings.push({
50
+ id: raw.id,
51
+ start: new Date(raw.start),
52
+ end: new Date(raw.end),
53
+ duration: raw.duration,
54
+ language: raw.language,
55
+ summary: raw.summary ?? null,
56
+ marks: (raw.marks ?? []).map((d) => new Date(d)),
57
+ lines: (raw.lines ?? []).map((l) => ({ time: new Date(l.time), text: l.text })),
58
+ });
59
+ } catch {
60
+ // 正在同步写入的文件可能读到一半,跳过即可。
61
+ }
62
+ }
63
+ recordings.sort((a, b) => a.start - b.start);
64
+ return { recordings, missing: false, notDownloaded: placeholders.length };
65
+ }
66
+
67
+ // ---------- 格式化 ----------
68
+
69
+ const dayKey = (d) => d.toLocaleDateString("sv-SE"); // 本地时区的 YYYY-MM-DD
70
+ const clock = (d) => d.toLocaleTimeString("sv-SE"); // 本地时区的 HH:MM:SS
71
+ const hm = (d) => clock(d).slice(0, 5);
72
+
73
+ function duration(sec) {
74
+ const s = Math.floor(sec);
75
+ const h = Math.floor(s / 3600);
76
+ const m = Math.floor((s % 3600) / 60);
77
+ const r = s % 60;
78
+ const pad = (n) => String(n).padStart(2, "0");
79
+ return h > 0 ? `${h}:${pad(m)}:${pad(r)}` : `${pad(m)}:${pad(r)}`;
80
+ }
81
+
82
+ function header(r) {
83
+ const marks = r.marks.length ? `, ${r.marks.length} mark(s)` : "";
84
+ return `${dayKey(r.start)} ${hm(r.start)}–${hm(r.end)} (${duration(r.duration)}${marks}) id=${r.id}`;
85
+ }
86
+
87
+ /** 全文:句子按时间排,标记以 ⚑ 插在对应位置。 */
88
+ function fullText(r) {
89
+ const items = [
90
+ ...r.lines.map((l) => ({ t: l.time, s: `[${clock(l.time)}] ${l.text}` })),
91
+ ...r.marks.map((m) => ({ t: m, s: `[${clock(m)}] ⚑ MARK (the user flagged the moment from here as important)` })),
92
+ ].sort((a, b) => a.t - b.t);
93
+ let out = `## ${header(r)}\n`;
94
+ if (r.summary) out += `Summary:\n${r.summary}\n\n`;
95
+ out += items.length ? items.map((i) => i.s).join("\n") : "(no speech detected)";
96
+ return out;
97
+ }
98
+
99
+ function parseDay(input) {
100
+ const v = String(input ?? "today").trim().toLowerCase();
101
+ const now = new Date();
102
+ if (v === "today" || v === "今天" || v === "") return dayKey(now);
103
+ if (v === "yesterday" || v === "昨天") return dayKey(new Date(now.getTime() - 86_400_000));
104
+ if (/^\d{4}-\d{2}-\d{2}$/.test(v)) return v;
105
+ throw rpcError(-32602, `Invalid date "${input}". Use YYYY-MM-DD, "today" or "yesterday".`);
106
+ }
107
+
108
+ function truncate(text, max) {
109
+ if (text.length <= max) return text;
110
+ return text.slice(0, max) + `\n\n[Truncated: ${text.length - max} more characters. Use search_recordings or get_recording for a narrower view.]`;
111
+ }
112
+
113
+ function notice(data) {
114
+ const notes = [];
115
+ if (data.notDownloaded > 0) {
116
+ notes.push(`Note: ${data.notDownloaded} recording file(s) are still in iCloud and not downloaded to this Mac yet; a download was requested, try again shortly.`);
117
+ }
118
+ return notes.length ? "\n\n" + notes.join("\n") : "";
119
+ }
120
+
121
+ function missingFolderText() {
122
+ return `The SayWatch folder was not found at:\n${ROOT}\n\n` +
123
+ `Ask the user to: (1) in the iPhone app, open Settings > "让电脑上的 AI 读取录音" (Let AI on your computer read recordings) and choose a sync folder ` +
124
+ `(recommended: iCloud Drive/SayWatch); (2) make sure it has synced to this Mac. ` +
125
+ `If the folder is elsewhere, start this server with --dir "<path>".`;
126
+ }
127
+
128
+ // ---------- 工具 ----------
129
+
130
+ const tools = [
131
+ {
132
+ name: "list_recordings",
133
+ description:
134
+ "List the user's Apple Watch voice recordings (most recent first) with time range, length, number of marks and a preview. " +
135
+ "Use this to see what was recorded on which days. Transcripts are usually Chinese or English.",
136
+ inputSchema: {
137
+ type: "object",
138
+ properties: {
139
+ from: { type: "string", description: "Earliest day, YYYY-MM-DD (inclusive). Optional." },
140
+ to: { type: "string", description: "Latest day, YYYY-MM-DD (inclusive). Optional." },
141
+ limit: { type: "integer", minimum: 1, maximum: 200, default: 30 },
142
+ },
143
+ },
144
+ run: async ({ from, to, limit = 30 }, data) => {
145
+ const f = from ? parseDay(from) : null;
146
+ const t = to ? parseDay(to) : null;
147
+ const list = data.recordings
148
+ .filter((r) => (!f || dayKey(r.start) >= f) && (!t || dayKey(r.start) <= t))
149
+ .reverse()
150
+ .slice(0, limit);
151
+ if (!list.length) return "No recordings in that range.";
152
+ return list
153
+ .map((r) => {
154
+ const preview = (r.summary ?? r.lines.slice(0, 3).map((l) => l.text).join(" ")).slice(0, 120);
155
+ return `- ${header(r)}\n ${preview || "(no speech detected)"}`;
156
+ })
157
+ .join("\n");
158
+ },
159
+ },
160
+ {
161
+ name: "search_recordings",
162
+ description:
163
+ "Full-text search over everything the user said in their recordings. All whitespace-separated terms must appear in a sentence " +
164
+ "(case-insensitive). Returns matching sentences with timestamps, recording id and surrounding context. " +
165
+ "Search in the language the user spoke (often Chinese); try synonyms if nothing is found.",
166
+ inputSchema: {
167
+ type: "object",
168
+ properties: {
169
+ query: { type: "string", description: "Keywords, e.g. \"预算 周五\"" },
170
+ limit: { type: "integer", minimum: 1, maximum: 100, default: 20 },
171
+ context: { type: "integer", minimum: 0, maximum: 5, default: 1, description: "Sentences of context before/after each hit." },
172
+ },
173
+ required: ["query"],
174
+ },
175
+ run: async ({ query, limit = 20, context = 1 }, data) => {
176
+ const terms = String(query ?? "").toLowerCase().split(/\s+/).filter(Boolean);
177
+ if (!terms.length) throw rpcError(-32602, "query must not be empty");
178
+ const blocks = [];
179
+ let hits = 0;
180
+ for (const r of [...data.recordings].reverse()) {
181
+ r.lines.forEach((line, i) => {
182
+ if (hits >= limit) return;
183
+ const text = line.text.toLowerCase();
184
+ if (!terms.every((t) => text.includes(t))) return;
185
+ hits++;
186
+ const ctx = r.lines
187
+ .slice(Math.max(0, i - context), i + context + 1)
188
+ .map((l) => `${l === line ? ">" : " "} [${clock(l.time)}] ${l.text}`)
189
+ .join("\n");
190
+ blocks.push(`### ${dayKey(line.time)} ${hm(line.time)} (id=${r.id})\n${ctx}`);
191
+ });
192
+ if (hits >= limit) break;
193
+ }
194
+ if (!hits) return `No sentences contain all of: ${terms.join(", ")}.`;
195
+ return `${hits} match(es)${hits >= limit ? " (limit reached)" : ""}:\n\n` + blocks.join("\n\n");
196
+ },
197
+ },
198
+ {
199
+ name: "get_recording",
200
+ description: "Get the full transcript of one recording by id (from list_recordings or search_recordings), with timestamps and the user's marks (⚑).",
201
+ inputSchema: {
202
+ type: "object",
203
+ properties: {
204
+ id: { type: "string" },
205
+ max_chars: { type: "integer", minimum: 1000, default: 60000 },
206
+ },
207
+ required: ["id"],
208
+ },
209
+ run: async ({ id, max_chars = 60000 }, data) => {
210
+ const r = data.recordings.find((x) => x.id === id);
211
+ if (!r) return `No recording with id "${id}". Use list_recordings to see available ids.`;
212
+ return truncate(fullText(r), max_chars);
213
+ },
214
+ },
215
+ {
216
+ name: "get_day",
217
+ description:
218
+ "Get all transcripts from one day in time order — use for questions like \"what did I discuss today\" or \"summarize yesterday\". " +
219
+ "Long days are truncated; then use search_recordings or get_recording.",
220
+ inputSchema: {
221
+ type: "object",
222
+ properties: {
223
+ date: { type: "string", description: "YYYY-MM-DD, \"today\" or \"yesterday\". Default today (local time).", default: "today" },
224
+ max_chars: { type: "integer", minimum: 1000, default: 60000 },
225
+ },
226
+ },
227
+ run: async ({ date, max_chars = 60000 }, data) => {
228
+ const key = parseDay(date);
229
+ const list = data.recordings.filter((r) => dayKey(r.start) === key);
230
+ if (!list.length) return `No recordings on ${key}.`;
231
+ return truncate(`${list.length} recording(s) on ${key}:\n\n` + list.map(fullText).join("\n\n"), max_chars);
232
+ },
233
+ },
234
+ {
235
+ name: "get_marked_moments",
236
+ description:
237
+ "Get what was said around each moment the user flagged on their watch (the user taps \"mark\" when something important is said; " +
238
+ "the mark is already placed ~30s before the tap). Usually the most important parts of a day.",
239
+ inputSchema: {
240
+ type: "object",
241
+ properties: {
242
+ date: { type: "string", description: "YYYY-MM-DD, \"today\" or \"yesterday\". Ignored if id is given. Default today." },
243
+ id: { type: "string", description: "Limit to one recording." },
244
+ seconds_after: { type: "integer", minimum: 10, maximum: 600, default: 90 },
245
+ },
246
+ },
247
+ run: async ({ date, id, seconds_after = 90 }, data) => {
248
+ const list = id
249
+ ? data.recordings.filter((r) => r.id === id)
250
+ : data.recordings.filter((r) => dayKey(r.start) === parseDay(date));
251
+ const blocks = [];
252
+ for (const r of list) {
253
+ for (const m of r.marks) {
254
+ const from = m.getTime() - 10_000;
255
+ const to = m.getTime() + seconds_after * 1000;
256
+ const lines = r.lines.filter((l) => l.time.getTime() >= from && l.time.getTime() <= to);
257
+ blocks.push(
258
+ `### ⚑ ${dayKey(m)} ${clock(m)} (id=${r.id})\n` +
259
+ (lines.length ? lines.map((l) => `[${clock(l.time)}] ${l.text}`).join("\n") : "(no speech around this mark)"),
260
+ );
261
+ }
262
+ }
263
+ if (!blocks.length) return "No marked moments found.";
264
+ return `${blocks.length} marked moment(s):\n\n` + blocks.join("\n\n");
265
+ },
266
+ },
267
+ ];
268
+
269
+ // ---------- JSON-RPC / MCP ----------
270
+
271
+ function rpcError(code, message) {
272
+ const e = new Error(message);
273
+ e.code = code;
274
+ return e;
275
+ }
276
+
277
+ async function handle(method, params) {
278
+ switch (method) {
279
+ case "initialize": {
280
+ const requested = params?.protocolVersion;
281
+ return {
282
+ protocolVersion: SUPPORTED_PROTOCOLS.includes(requested) ? requested : SUPPORTED_PROTOCOLS[0],
283
+ capabilities: { tools: {} },
284
+ serverInfo: { name: "saywatch", version: VERSION },
285
+ instructions:
286
+ "Read-only access to the user's Apple Watch voice recordings, transcribed on their iPhone. " +
287
+ "Timestamps are in the user's local time. Transcripts may contain recognition errors. " +
288
+ "Quote timestamps when citing what was said.",
289
+ };
290
+ }
291
+ case "ping":
292
+ return {};
293
+ case "tools/list":
294
+ return { tools: tools.map(({ name, description, inputSchema }) => ({ name, description, inputSchema })) };
295
+ case "tools/call": {
296
+ const tool = tools.find((t) => t.name === params?.name);
297
+ if (!tool) throw rpcError(-32602, `Unknown tool: ${params?.name}`);
298
+ const data = await loadAll();
299
+ if (data.missing) return { content: [{ type: "text", text: missingFolderText() }], isError: true };
300
+ try {
301
+ const text = await tool.run(params.arguments ?? {}, data);
302
+ return { content: [{ type: "text", text: text + notice(data) }] };
303
+ } catch (e) {
304
+ return { content: [{ type: "text", text: e.message }], isError: true };
305
+ }
306
+ }
307
+ default:
308
+ throw rpcError(-32601, `Method not found: ${method}`);
309
+ }
310
+ }
311
+
312
+ function send(msg) {
313
+ process.stdout.write(JSON.stringify(msg) + "\n");
314
+ }
315
+
316
+ const rl = createInterface({ input: process.stdin });
317
+ rl.on("line", async (line) => {
318
+ if (!line.trim()) return;
319
+ let msg;
320
+ try {
321
+ msg = JSON.parse(line);
322
+ } catch {
323
+ send({ jsonrpc: "2.0", id: null, error: { code: -32700, message: "Parse error" } });
324
+ return;
325
+ }
326
+ if (msg.id === undefined || msg.id === null) return; // 通知,无需回复
327
+ try {
328
+ send({ jsonrpc: "2.0", id: msg.id, result: await handle(msg.method, msg.params ?? {}) });
329
+ } catch (e) {
330
+ send({ jsonrpc: "2.0", id: msg.id, error: { code: e.code ?? -32603, message: e.message } });
331
+ }
332
+ });
333
+
334
+ process.stderr.write(`saywatch-mcp ${VERSION} reading ${ROOT}\n`);