mcp-icloud 2.1.4 → 2.1.5

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.
package/README.md CHANGED
@@ -103,7 +103,7 @@ Tools marked local only return an error in cloud mode, because the iCloud protoc
103
103
 
104
104
  Reading requires the [`imsg`](https://github.com/steipete/imsg) CLI and Full Disk Access.
105
105
 
106
- - **list-chats**: `limit` (number, optional)
106
+ - **list-chats**: `limit` (number, optional, max 1000), `since` (ISO 8601, optional — only chats active since that date, e.g. a weekly review)
107
107
  - **read-messages**: `chatId` (number); `limit` (number, optional); `start`, `end` (ISO 8601, optional); `attachments` (boolean, optional)
108
108
  - **send-message**: `to` (string), `body` (string), `file` (string, optional)
109
109
  - **react-message**: `chatId` (number), `type` (`love`, `like`, `dislike`, `laugh`, `emphasis`, `question`)
package/messages/index.js CHANGED
@@ -9,7 +9,7 @@ const localClient = require('./local-client');
9
9
  const { formatError, formatSuccess, withErrorHandler } = require('../utils/error-handler');
10
10
  const { listOutput, listResult } = require('../utils/schemas');
11
11
  const { isLocalMode } = require('../mode');
12
- const { execFileSync } = require('child_process');
12
+ const { execFile } = require('child_process');
13
13
  const fs = require('fs');
14
14
 
15
15
  // Homebrew's prefix differs between Apple Silicon and Intel, and an MCP server
@@ -29,6 +29,9 @@ function resolveImsg() {
29
29
  return 'imsg';
30
30
  }
31
31
 
32
+ // Chats scanned when `since` is set; listing 5,000 takes well under a second.
33
+ const SINCE_FETCH_LIMIT = 5000;
34
+
32
35
  function requireLocalMode(toolName) {
33
36
  if (!isLocalMode()) {
34
37
  return formatError(new Error(`${toolName} is only available in LOCAL mode. Use set-mode to switch.`));
@@ -36,14 +39,29 @@ function requireLocalMode(toolName) {
36
39
  return null;
37
40
  }
38
41
 
39
- function runImsg(args) {
40
- let output;
41
- try {
42
- output = execFileSync(resolveImsg(), args, {
43
- timeout: 15000,
42
+ // Async on purpose: a synchronous call blocks the whole server, so parallel
43
+ // reads from a client queue behind each other until they time out (#17).
44
+ function execImsg(args) {
45
+ return new Promise((resolve, reject) => {
46
+ execFile(resolveImsg(), args, {
47
+ timeout: 30000,
44
48
  encoding: 'utf-8',
45
- stdio: ['pipe', 'pipe', 'pipe']
49
+ maxBuffer: 64 * 1024 * 1024
50
+ }, (error, stdout, stderr) => {
51
+ if (error) {
52
+ error.stderr = stderr;
53
+ reject(error);
54
+ } else {
55
+ resolve(stdout);
56
+ }
46
57
  });
58
+ });
59
+ }
60
+
61
+ async function runImsg(args) {
62
+ let output;
63
+ try {
64
+ output = await execImsg(args);
47
65
  } catch (error) {
48
66
  const detail = (error.stderr || error.message || '').toString();
49
67
  if (detail.includes('permissionDenied')) {
@@ -52,6 +70,9 @@ function runImsg(args) {
52
70
  if (error.code === 'ENOENT') {
53
71
  throw new Error('The imsg CLI was not found. Install it (brew install imsg) or set ICLOUD_MCP_IMSG_PATH.');
54
72
  }
73
+ if (error.killed) {
74
+ throw new Error('imsg timed out after 30s');
75
+ }
55
76
  throw new Error(detail.trim() || 'imsg failed');
56
77
  }
57
78
 
@@ -70,17 +91,26 @@ const messagesTools = [
70
91
  name: 'list-chats',
71
92
  outputSchema: listOutput('Recent conversations'),
72
93
  title: 'List Chats',
73
- description: 'List recent iMessage/SMS conversations with contact names and last message preview',
94
+ description: 'List recent iMessage/SMS conversations, most recent first. Use `since` to get only the conversations active after a date (e.g. the last 7 days).',
74
95
  inputSchema: {
75
- limit: z.number().int().min(1).max(200).optional().describe('Number of conversations to show (default 20)')
96
+ limit: z.number().int().min(1).max(1000).optional().describe('Maximum number of conversations to return (default 20)'),
97
+ since: z.string().refine(v => !Number.isNaN(Date.parse(v)), 'since must be an ISO 8601 date')
98
+ .optional().describe('Only conversations with a message at or after this date (ISO 8601, optional)')
76
99
  },
77
100
  annotations: {"readOnlyHint":true,"idempotentHint":true,"openWorldHint":false},
78
- handler: withErrorHandler(async ({ limit = 20 }) => {
101
+ handler: withErrorHandler(async ({ limit = 20, since }) => {
79
102
  const modeError = requireLocalMode('list-chats');
80
103
  if (modeError) return modeError;
81
- const result = runImsg(['chats', '--limit', String(limit), '--json']);
104
+ // imsg has no date filter, but returns chats newest first, so fetch a
105
+ // wide window and cut it at `since` here.
106
+ const fetchLimit = since ? Math.max(limit, SINCE_FETCH_LIMIT) : limit;
107
+ const result = await runImsg(['chats', '--limit', String(fetchLimit), '--json']);
82
108
  // imsg emits JSONL, and runImsg unwraps a single line to a bare object.
83
- const chats = Array.isArray(result) ? result : (result ? [result] : []);
109
+ let chats = Array.isArray(result) ? result : (result ? [result] : []);
110
+ if (since) {
111
+ const cutoff = Date.parse(since);
112
+ chats = chats.filter(c => Date.parse(c.last_message_at) >= cutoff).slice(0, limit);
113
+ }
84
114
  return formatSuccess(JSON.stringify(chats, null, 2), listResult(chats));
85
115
  }, 'list-chats')
86
116
  },
@@ -103,7 +133,7 @@ const messagesTools = [
103
133
  if (start) args.push('--start', start);
104
134
  if (end) args.push('--end', end);
105
135
  if (attachments) args.push('--attachments');
106
- const result = runImsg(args);
136
+ const result = await runImsg(args);
107
137
  return formatSuccess(JSON.stringify(result, null, 2));
108
138
  }, 'read-messages')
109
139
  },
@@ -128,7 +158,7 @@ const messagesTools = [
128
158
  try {
129
159
  const args = ['send', '--to', to, '--text', body];
130
160
  if (file) args.push('--file', file);
131
- const result = runImsg(args);
161
+ const result = await runImsg(args);
132
162
  return formatSuccess(JSON.stringify(result, null, 2));
133
163
  } catch (e) {
134
164
  throw new Error(`${error.message} (imsg fallback also failed: ${e.message})`);
@@ -148,7 +178,7 @@ const messagesTools = [
148
178
  handler: withErrorHandler(async ({ chatId, type }) => {
149
179
  const modeError = requireLocalMode('react-message');
150
180
  if (modeError) return modeError;
151
- const result = runImsg(['react', '--chat-id', String(chatId), '--type', type]);
181
+ const result = await runImsg(['react', '--chat-id', String(chatId), '--type', type]);
152
182
  return formatSuccess(JSON.stringify(result, null, 2));
153
183
  }, 'react-message')
154
184
  }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "mcp-icloud",
3
3
  "mcpName": "io.github.MrGo2/icloud-mcp",
4
- "version": "2.1.4",
4
+ "version": "2.1.5",
5
5
  "description": "MCP server for Apple services - Email, Calendar, Contacts, Reminders, Notes, Messages and Safari - with dual local (AppleScript) and cloud (IMAP/CalDAV/CardDAV) modes",
6
6
  "main": "index.js",
7
7
  "bin": {
@@ -27,7 +27,7 @@
27
27
  ],
28
28
  "scripts": {
29
29
  "start": "node index.js",
30
- "test": "node test/security.test.js && node test/local-output.test.js && node test/email-read.test.js",
30
+ "test": "node test/security.test.js && node test/local-output.test.js && node test/email-read.test.js && node test/messages.test.js",
31
31
  "test-mode": "USE_TEST_MODE=true node index.js",
32
32
  "inspect": "npx @modelcontextprotocol/inspector node index.js",
33
33
  "test:local": "node test/local-output.test.js"