apple-tools-mcp 3.4.0 → 3.4.1
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 +5 -1
- package/index.js +17 -6
- package/indexer.js +14 -12
- package/lib/indexerRuntime.js +10 -3
- package/lib/urlQuery.js +14 -0
- package/package.json +1 -1
- package/search.js +8 -6
package/README.md
CHANGED
|
@@ -210,6 +210,8 @@ apple-tools-mcp http-token
|
|
|
210
210
|
|
|
211
211
|
Under a secrets manager's runtime injection (for example `infisical run -- apple-tools-http`), set `APPLE_TOOLS_HTTP_TOKEN` and the server uses it instead of Keychain, which it then neither reads nor writes. To rotate without cutting off clients, start the server with the new token in `APPLE_TOOLS_HTTP_TOKEN` and the old one in `APPLE_TOOLS_HTTP_TOKEN_PREVIOUS`; once every client has the new token, restart without `APPLE_TOOLS_HTTP_TOKEN_PREVIOUS` and the old token stops working.
|
|
212
212
|
|
|
213
|
+
The HTTP server never indexes and never takes `indexer.lock`: it serves the index the indexer daemon keeps fresh, so run the indexer too. It also refuses `rebuild_index`; rebuild from a stdio client or as described under the index rebuild below. Restarting either one in any order is safe.
|
|
214
|
+
|
|
213
215
|
An example LaunchAgent is `examples/com.apple-tools-http.plist`. How to point Claude and other clients at it, including `apple-tools-http-proxy`, is in `examples/mcp-client.md`.
|
|
214
216
|
|
|
215
217
|
## Index commands
|
|
@@ -299,7 +301,9 @@ Your client can also call `audit_index`.
|
|
|
299
301
|
| `calendar_upcoming` | Next events, starting with everything on today's date (all-day and earlier-today events included). A failed read is an error. |
|
|
300
302
|
| `calendar_week` | Events for this week or a future week. |
|
|
301
303
|
| `calendar_free_time` | Open time on a date, read live from Calendar rather than the search index. |
|
|
302
|
-
| `calendar_recurring` | Recurring events. |
|
|
304
|
+
| `calendar_recurring` | Recurring events with their next occurrence, counting today's. |
|
|
305
|
+
|
|
306
|
+
Calendar tools print links in event titles and locations without their query string or fragment (`https://zoom.us/j/123?pwd=...` prints as `https://zoom.us/j/123`), so a meeting passcode never reaches a chat that reads the calendar.
|
|
303
307
|
|
|
304
308
|
### Contacts
|
|
305
309
|
|
package/index.js
CHANGED
|
@@ -42,6 +42,7 @@ import { closeEventKitSession, ensureEventKitSession } from "./lib/eventKitSessi
|
|
|
42
42
|
import { EVENTKIT_JXA_HELPERS } from "./lib/calendarWrite.js";
|
|
43
43
|
import { mailFind, MAILBOX_KINDS, MAIL_FIND_MAX_LIMIT } from "./lib/mailFind.js";
|
|
44
44
|
import { mailLinks } from "./lib/mailLinks.js";
|
|
45
|
+
import { stripUrlQueries } from "./lib/urlQuery.js";
|
|
45
46
|
|
|
46
47
|
const PACKAGE_VERSION = JSON.parse(
|
|
47
48
|
fs.readFileSync(new URL("./package.json", import.meta.url), "utf8")
|
|
@@ -449,9 +450,12 @@ async function initializeIndexing() {
|
|
|
449
450
|
// MCP stdio: if the indexer daemon (or another instance) holds the lock,
|
|
450
451
|
// skip background refresh and use the shared index. If nothing holds the
|
|
451
452
|
// lock, index locally as before so the stdio happy path still works.
|
|
452
|
-
|
|
453
|
+
// The HTTP server never takes the lock (see mcpIndexingStartup).
|
|
454
|
+
const startup = mcpIndexingStartup(() => acquireLock(), { httpMode: HTTP_MODE });
|
|
453
455
|
if (!startup.startBackground) {
|
|
454
|
-
console.error(
|
|
456
|
+
console.error(startup.reason === "http-server"
|
|
457
|
+
? "HTTP server never takes indexer.lock; it serves the index the indexer daemon keeps fresh."
|
|
458
|
+
: "Another apple-tools-mcp instance is indexing. Server will run without background indexing.");
|
|
455
459
|
// Lost lock is not "still indexing": this process will never complete a
|
|
456
460
|
// local cycle. Searches proceed whenever isIndexReady() is true (initDB
|
|
457
461
|
// re-lists shared on-disk tables; it must not cache an empty first connect).
|
|
@@ -675,7 +679,7 @@ function formatSmartSearchResults(results, synthesizedGroups = null) {
|
|
|
675
679
|
for (const group of synthesizedGroups.slice(0, 5)) {
|
|
676
680
|
sections.push(`📅 ${group.timeWindow} (${group.totalItems} items)`);
|
|
677
681
|
if (group.calendar.length > 0) {
|
|
678
|
-
sections.push(` Calendar: ${group.calendar.map(c => c.title).join(', ')}`);
|
|
682
|
+
sections.push(` Calendar: ${group.calendar.map(c => stripUrlQueries(c.title)).join(', ')}`);
|
|
679
683
|
}
|
|
680
684
|
if (group.mail.length > 0) {
|
|
681
685
|
sections.push(` Emails: ${group.mail.map(m => m.subject).join(', ')}`);
|
|
@@ -715,10 +719,10 @@ function formatSmartSearchResults(results, synthesizedGroups = null) {
|
|
|
715
719
|
sections.push("📅 CALENDAR:");
|
|
716
720
|
for (const r of results.calendar.results) {
|
|
717
721
|
sections.push(` [${r.rank}] Score: ${r.score}`);
|
|
718
|
-
sections.push(` Event: ${r.title}${r.isAllDay ? ' (All Day)' : ''}`);
|
|
722
|
+
sections.push(` Event: ${stripUrlQueries(r.title)}${r.isAllDay ? ' (All Day)' : ''}`);
|
|
719
723
|
sections.push(` Start: ${r.start}`);
|
|
720
724
|
sections.push(` Calendar: ${r.calendar}`);
|
|
721
|
-
if (r.location) sections.push(` Location: ${r.location}`);
|
|
725
|
+
if (r.location) sections.push(` Location: ${stripUrlQueries(r.location)}`);
|
|
722
726
|
}
|
|
723
727
|
sections.push("");
|
|
724
728
|
}
|
|
@@ -1057,7 +1061,7 @@ function formatPersonSearchResults(results) {
|
|
|
1057
1061
|
if (results.calendar && results.calendar.results && results.calendar.results.length > 0) {
|
|
1058
1062
|
sections.push(`📅 CALENDAR (${results.calendar.results.length}):`);
|
|
1059
1063
|
for (const r of results.calendar.results.slice(0, 10)) {
|
|
1060
|
-
sections.push(` • ${r.title}`);
|
|
1064
|
+
sections.push(` • ${stripUrlQueries(r.title)}`);
|
|
1061
1065
|
sections.push(` ${r.start} | ${r.calendar}`);
|
|
1062
1066
|
}
|
|
1063
1067
|
sections.push("");
|
|
@@ -1571,6 +1575,13 @@ function createServer() {
|
|
|
1571
1575
|
break;
|
|
1572
1576
|
}
|
|
1573
1577
|
|
|
1578
|
+
// The HTTP server never takes indexer.lock (it could hold it while the
|
|
1579
|
+
// indexer daemon restarts); rebuilds run from stdio or the indexer.
|
|
1580
|
+
if (HTTP_MODE) {
|
|
1581
|
+
result = "rebuild_index does not run over the HTTP server, which never takes indexer.lock. Run it from a stdio session (apple-tools-mcp) or with npm run build-index while the indexer daemon is stopped.";
|
|
1582
|
+
break;
|
|
1583
|
+
}
|
|
1584
|
+
|
|
1574
1585
|
// Acquire lock to prevent parallel rebuilds across multiple MCP instances
|
|
1575
1586
|
if (!acquireLock()) {
|
|
1576
1587
|
result = "Indexing is already in progress in a different session. Please wait for it to complete before starting a rebuild.";
|
package/indexer.js
CHANGED
|
@@ -2340,17 +2340,11 @@ export async function getEmailThread(filePath, limit = 20) {
|
|
|
2340
2340
|
}
|
|
2341
2341
|
}
|
|
2342
2342
|
|
|
2343
|
-
// calendar_recurring:
|
|
2344
|
-
|
|
2345
|
-
|
|
2346
|
-
|
|
2347
|
-
|
|
2348
|
-
const nowMac = Math.floor(Date.now() / 1000) - 978307200;
|
|
2349
|
-
const fetchLimit = safeLimit + 1; // Fetch one extra to detect if more exist
|
|
2350
|
-
|
|
2351
|
-
// Query events that have recurrence rules defined in the Recurrence table
|
|
2352
|
-
// Show the next upcoming occurrence of each recurring event
|
|
2353
|
-
const query = `
|
|
2343
|
+
// calendar_recurring: recurring events (a Recurrence row) with their next occurrence, from today on.
|
|
2344
|
+
// Bounded by today's local midnight, never now: OccurrenceCache.day is each occurrence's local midnight,
|
|
2345
|
+
// so comparing day to now dropped today's occurrence after midnight (the calendar_upcoming bug fixed in 3.3.5).
|
|
2346
|
+
export function buildRecurringEventsQuery(dayStartMac, fetchLimit) {
|
|
2347
|
+
return `
|
|
2354
2348
|
SELECT DISTINCT
|
|
2355
2349
|
ci.summary as title,
|
|
2356
2350
|
datetime(COALESCE(MIN(oc.occurrence_end_date) - (ci.end_date - ci.start_date), MIN(oc.day)) + 978307200, 'unixepoch', 'localtime') as start,
|
|
@@ -2361,12 +2355,20 @@ export function getRecurringEvents(limit = 20) {
|
|
|
2361
2355
|
INNER JOIN CalendarItem ci ON r.owner_id = ci.ROWID
|
|
2362
2356
|
INNER JOIN OccurrenceCache oc ON oc.event_id = ci.ROWID
|
|
2363
2357
|
LEFT JOIN Calendar c ON ci.calendar_id = c.ROWID
|
|
2364
|
-
WHERE oc.day >= ${
|
|
2358
|
+
WHERE oc.day >= ${dayStartMac}
|
|
2365
2359
|
AND ci.summary IS NOT NULL AND ci.summary <> ''
|
|
2366
2360
|
GROUP BY ci.ROWID, ci.summary, c.title, ci.all_day
|
|
2367
2361
|
ORDER BY occurrenceCount DESC, MIN(oc.day) ASC
|
|
2368
2362
|
LIMIT ${fetchLimit}
|
|
2369
2363
|
`;
|
|
2364
|
+
}
|
|
2365
|
+
|
|
2366
|
+
export function getRecurringEvents(limit = 20) {
|
|
2367
|
+
try {
|
|
2368
|
+
// Validate limit to prevent SQL issues
|
|
2369
|
+
const safeLimit = validateLimit(limit, 20, 100);
|
|
2370
|
+
const fetchLimit = safeLimit + 1; // Fetch one extra to detect if more exist
|
|
2371
|
+
const query = buildRecurringEventsQuery(localTodayStartMac(), fetchLimit);
|
|
2370
2372
|
const events = withCalendarCopy((dbPath) => {
|
|
2371
2373
|
return safeSqlite3Json(dbPath, query, { timeout: 30000 });
|
|
2372
2374
|
});
|
package/lib/indexerRuntime.js
CHANGED
|
@@ -178,12 +178,19 @@ export function applyIndexerCycleEnd({ success, indexerMode, cycleEndFlags, rele
|
|
|
178
178
|
}
|
|
179
179
|
|
|
180
180
|
/**
|
|
181
|
-
* MCP
|
|
181
|
+
* MCP startup: stdio indexes locally only when the lock is free. The HTTP
|
|
182
|
+
* server never takes indexer.lock: it serves the shared index the indexer
|
|
183
|
+
* daemon keeps fresh. As a local fallback it could win the lock while the
|
|
184
|
+
* daemon restarted after an install, leaving the daemon waiting for it.
|
|
182
185
|
*
|
|
183
186
|
* @param {() => boolean} acquireLock
|
|
184
|
-
* @
|
|
187
|
+
* @param {{ httpMode?: boolean }} [options]
|
|
188
|
+
* @returns {{ startBackground: boolean, ownsIndexLock: boolean, startHeartbeat: boolean, reason: "local-fallback" | "lock-held" | "http-server" }}
|
|
185
189
|
*/
|
|
186
|
-
export function mcpIndexingStartup(acquireLock) {
|
|
190
|
+
export function mcpIndexingStartup(acquireLock, { httpMode = false } = {}) {
|
|
191
|
+
if (httpMode) {
|
|
192
|
+
return { startBackground: false, ownsIndexLock: false, startHeartbeat: false, reason: "http-server" };
|
|
193
|
+
}
|
|
187
194
|
if (!acquireLock()) {
|
|
188
195
|
return { startBackground: false, ownsIndexLock: false, startHeartbeat: false, reason: "lock-held" };
|
|
189
196
|
}
|
package/lib/urlQuery.js
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
// Meeting links in calendar titles and locations often carry the join passcode
|
|
2
|
+
// in their query string (zoom.us/j/123?pwd=...). Calendar tools print each URL
|
|
3
|
+
// with its scheme, host and path only: the ?query and #fragment are dropped, so
|
|
4
|
+
// a passcode never reaches a chat that reads the calendar.
|
|
5
|
+
//
|
|
6
|
+
// A URL here is a scheme with "//" (https://, zoommtg://), a "www." host, or a
|
|
7
|
+
// bare host.tld/ path. The query runs to the next space, angle bracket or quote;
|
|
8
|
+
// closing ) or ] at its end are kept, since they close the text around the URL.
|
|
9
|
+
const URL_WITH_QUERY = /((?:\b[a-z][a-z0-9+.-]*:\/\/|\bwww\.|\b[a-z0-9-]+(?:\.[a-z0-9-]+)*\.[a-z]{2,}\/)[^\s?#<>"']*)([?#][^\s<>"']*)/gi;
|
|
10
|
+
|
|
11
|
+
export function stripUrlQueries(text) {
|
|
12
|
+
if (typeof text !== "string" || !text) return text;
|
|
13
|
+
return text.replace(URL_WITH_QUERY, (_, url, query) => url + (query.match(/[)\]]+$/) || [""])[0]);
|
|
14
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "apple-tools-mcp",
|
|
3
|
-
"version": "3.4.
|
|
3
|
+
"version": "3.4.1",
|
|
4
4
|
"description": "MCP server for semantic search and write actions across Apple Mail, Messages, Calendar, and Contacts. Speaks stdio (local) or bearer-token-authenticated Streamable HTTP (LAN / Tailscale).",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "index.js",
|
package/search.js
CHANGED
|
@@ -4,6 +4,7 @@ import { safeMatch, validateSearchQuery, toUnixMillis } from "./lib/validators.j
|
|
|
4
4
|
import { embed, getOpenTable, getRecentEmails, getEmailsByDateRange, getRecentMessages, getConversation, getEventsOnDate, resolveEmail, resolvePhone, resolveByExactName, normalizePhone, formatContact } from "./indexer.js";
|
|
5
5
|
import { createMessageContactMatcher, describeMessagePeer } from "./lib/messageContact.js";
|
|
6
6
|
import { indexUnavailableMessage } from "./lib/indexGate.js";
|
|
7
|
+
import { stripUrlQueries } from "./lib/urlQuery.js";
|
|
7
8
|
|
|
8
9
|
// ============ CACHING ============
|
|
9
10
|
|
|
@@ -1524,11 +1525,12 @@ export function formatCalendarResults(searchResult) {
|
|
|
1524
1525
|
const results = searchResult.results.map(r => {
|
|
1525
1526
|
let result = `[${r.rank || r.index}]`;
|
|
1526
1527
|
if (r.score) result += ` Score: ${r.score}`;
|
|
1527
|
-
|
|
1528
|
+
// Meeting-link passcodes ride in URL query strings: titles and locations print URLs without them.
|
|
1529
|
+
result += `\nEvent: ${stripUrlQueries(r.title)}`;
|
|
1528
1530
|
if (r.isAllDay) result += " (All Day)";
|
|
1529
1531
|
result += `\nCalendar: ${r.calendar}\nStart: ${r.start}\nEnd: ${r.end}`;
|
|
1530
1532
|
if (r.eventId) result += `\nEvent ID: ${r.eventId}`;
|
|
1531
|
-
if (r.location) result += `\nLocation: ${r.location}`;
|
|
1533
|
+
if (r.location) result += `\nLocation: ${stripUrlQueries(r.location)}`;
|
|
1532
1534
|
if (r.attendees && r.attendees.length > 0) {
|
|
1533
1535
|
const attendeeList = r.attendees.map(a => `${a.name} (${a.status})`).join(", ");
|
|
1534
1536
|
result += `\nAttendees: ${attendeeList}`;
|
|
@@ -1626,10 +1628,10 @@ export function formatUpcomingEventsResults(result) {
|
|
|
1626
1628
|
let output = "";
|
|
1627
1629
|
for (let i = 0; i < events.length; i++) {
|
|
1628
1630
|
const e = events[i];
|
|
1629
|
-
output += `${i + 1}. ${e.title || "No title"}${e.isAllDay ? " (All Day)" : ""}\n`;
|
|
1631
|
+
output += `${i + 1}. ${stripUrlQueries(e.title) || "No title"}${e.isAllDay ? " (All Day)" : ""}\n`;
|
|
1630
1632
|
output += ` ${e.start}${e.isAllDay ? "" : ` - ${e.end}`}\n`;
|
|
1631
1633
|
output += ` Calendar: ${e.calendar || "Unknown"}`;
|
|
1632
|
-
if (e.location) output += ` | Location: ${e.location}`;
|
|
1634
|
+
if (e.location) output += ` | Location: ${stripUrlQueries(e.location)}`;
|
|
1633
1635
|
output += "\n\n";
|
|
1634
1636
|
}
|
|
1635
1637
|
|
|
@@ -1672,7 +1674,7 @@ export function formatWeekEventsResults(result) {
|
|
|
1672
1674
|
output += `${day}:\n`;
|
|
1673
1675
|
for (const e of dayEvents) {
|
|
1674
1676
|
const time = e.isAllDay ? "All Day" : e.start.split(" ")[1];
|
|
1675
|
-
output += ` • ${time} - ${e.title || "No title"}`;
|
|
1677
|
+
output += ` • ${time} - ${stripUrlQueries(e.title) || "No title"}`;
|
|
1676
1678
|
if (e.calendar) output += ` [${e.calendar}]`;
|
|
1677
1679
|
output += "\n";
|
|
1678
1680
|
}
|
|
@@ -1723,7 +1725,7 @@ export function formatRecurringEventsResults(result) {
|
|
|
1723
1725
|
|
|
1724
1726
|
let output = "";
|
|
1725
1727
|
for (const e of events) {
|
|
1726
|
-
output += ` • ${e.title || "No title"}${e.isAllDay ? " (All Day)" : ""}\n`;
|
|
1728
|
+
output += ` • ${stripUrlQueries(e.title) || "No title"}${e.isAllDay ? " (All Day)" : ""}\n`;
|
|
1727
1729
|
output += ` Next: ${e.start} | Calendar: ${e.calendar || "Unknown"}\n`;
|
|
1728
1730
|
output += ` Occurrences: ${e.occurrenceCount}\n\n`;
|
|
1729
1731
|
}
|