apple-tools-mcp 3.3.4 → 3.3.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 +2 -2
- package/index.js +4 -5
- package/indexer.js +34 -13
- package/package.json +1 -1
- package/search.js +12 -0
package/README.md
CHANGED
|
@@ -295,8 +295,8 @@ Your client can also call `audit_index`.
|
|
|
295
295
|
| Tool | Description |
|
|
296
296
|
|------|-------------|
|
|
297
297
|
| `calendar_search` | Semantic search for events, with filters. |
|
|
298
|
-
| `calendar_date` | Events on a date, read live from Calendar rather than the search index. |
|
|
299
|
-
| `calendar_upcoming` | Next
|
|
298
|
+
| `calendar_date` | Events on a date, read live from Calendar rather than the search index. A failed read is an error, never an empty day. |
|
|
299
|
+
| `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
300
|
| `calendar_week` | Events for this week or a future week. |
|
|
301
301
|
| `calendar_free_time` | Open time on a date, read live from Calendar rather than the search index. |
|
|
302
302
|
| `calendar_recurring` | Recurring events. |
|
package/index.js
CHANGED
|
@@ -219,6 +219,7 @@ import {
|
|
|
219
219
|
formatSendersResults,
|
|
220
220
|
formatMessageContactsResults,
|
|
221
221
|
formatUpcomingEventsResults,
|
|
222
|
+
requireCalendarRead,
|
|
222
223
|
formatWeekEventsResults,
|
|
223
224
|
formatEmailThreadResults,
|
|
224
225
|
formatRecurringEventsResults
|
|
@@ -576,13 +577,11 @@ async function calendarSearch(query, options = {}) {
|
|
|
576
577
|
}
|
|
577
578
|
|
|
578
579
|
async function calendarDate(date) {
|
|
579
|
-
|
|
580
|
-
return formatCalendarResults(result);
|
|
580
|
+
return formatCalendarResults(requireCalendarRead(await getCalendarDateResults(date)));
|
|
581
581
|
}
|
|
582
582
|
|
|
583
583
|
async function calendarFreeTime(date, options = {}) {
|
|
584
|
-
|
|
585
|
-
return formatFreeTimeResults(result);
|
|
584
|
+
return formatFreeTimeResults(requireCalendarRead(await calculateFreeTime(date, options)));
|
|
586
585
|
}
|
|
587
586
|
|
|
588
587
|
// Mail directory for path validation
|
|
@@ -1618,7 +1617,7 @@ function createServer() {
|
|
|
1618
1617
|
|
|
1619
1618
|
// Calendar tools
|
|
1620
1619
|
case "calendar_upcoming":
|
|
1621
|
-
result = formatUpcomingEventsResults(getUpcomingEvents(validateLimit(args?.limit, 30, 100)));
|
|
1620
|
+
result = formatUpcomingEventsResults(requireCalendarRead(getUpcomingEvents(validateLimit(args?.limit, 30, 100))));
|
|
1622
1621
|
break;
|
|
1623
1622
|
|
|
1624
1623
|
// ============ NEW TOOLS - PHASE 2 ============
|
package/indexer.js
CHANGED
|
@@ -1990,19 +1990,15 @@ export function getMessageContacts(limit = 50) {
|
|
|
1990
1990
|
}
|
|
1991
1991
|
}
|
|
1992
1992
|
|
|
1993
|
-
// calendar_upcoming: Get next N upcoming events
|
|
1994
|
-
|
|
1995
|
-
|
|
1996
|
-
|
|
1997
|
-
|
|
1998
|
-
|
|
1999
|
-
const fetchLimit = safeLimit + 1; // Fetch one extra to detect if more exist
|
|
2000
|
-
|
|
2001
|
-
// Query OccurrenceCache to include recurring event occurrences
|
|
2002
|
-
const query = `
|
|
1993
|
+
// calendar_upcoming: Get next N upcoming events, starting with every event on the current local day.
|
|
1994
|
+
// OccurrenceCache.day is each occurrence's local midnight, so the lower bound is today's local midnight,
|
|
1995
|
+
// never now: comparing day to now dropped all of today (all-day and later-today events) after midnight.
|
|
1996
|
+
export function buildUpcomingEventsQuery(dayStartMac, fetchLimit) {
|
|
1997
|
+
const occStart = "COALESCE(oc.occurrence_end_date - (ci.end_date - ci.start_date), ci.start_date)";
|
|
1998
|
+
return `
|
|
2003
1999
|
SELECT
|
|
2004
2000
|
ci.summary as title,
|
|
2005
|
-
datetime(
|
|
2001
|
+
datetime(${occStart} + 978307200, 'unixepoch', 'localtime') as start,
|
|
2006
2002
|
datetime(COALESCE(oc.occurrence_end_date, ci.end_date) + 978307200, 'unixepoch', 'localtime') as end,
|
|
2007
2003
|
ci.all_day as isAllDay,
|
|
2008
2004
|
c.title as calendar,
|
|
@@ -2012,11 +2008,35 @@ export function getUpcomingEvents(limit = 10) {
|
|
|
2012
2008
|
INNER JOIN CalendarItem ci ON oc.event_id = ci.ROWID
|
|
2013
2009
|
LEFT JOIN Calendar c ON ci.calendar_id = c.ROWID
|
|
2014
2010
|
LEFT JOIN Location l ON ci.location_id = l.ROWID
|
|
2015
|
-
WHERE oc.day >= ${
|
|
2016
|
-
ORDER BY sort_day ASC
|
|
2011
|
+
WHERE oc.day >= ${dayStartMac} AND ci.summary IS NOT NULL AND ci.summary <> ''
|
|
2012
|
+
ORDER BY sort_day ASC, ci.all_day DESC, ${occStart} ASC, title ASC
|
|
2017
2013
|
LIMIT ${fetchLimit}
|
|
2018
2014
|
`;
|
|
2015
|
+
}
|
|
2016
|
+
|
|
2017
|
+
// Start of the current local day, in Apple/Core Data seconds.
|
|
2018
|
+
function localTodayStartMac() {
|
|
2019
|
+
const midnight = new Date();
|
|
2020
|
+
midnight.setHours(0, 0, 0, 0);
|
|
2021
|
+
return Math.floor(midnight.getTime() / 1000) - MAC_ABSOLUTE_EPOCH;
|
|
2022
|
+
}
|
|
2023
|
+
|
|
2024
|
+
// A copy with no OccurrenceCache rows at all is not a readable calendar: say so instead of an empty day.
|
|
2025
|
+
function assertOccurrenceCache(dbPath) {
|
|
2026
|
+
const rows = safeSqlite3Json(dbPath, "SELECT COUNT(*) AS n FROM (SELECT 1 FROM OccurrenceCache LIMIT 1)", { timeout: 10000 });
|
|
2027
|
+
if (!rows.length || !Number(rows[0].n)) {
|
|
2028
|
+
throw new Error("Calendar OccurrenceCache is empty, so the calendar could not be read");
|
|
2029
|
+
}
|
|
2030
|
+
}
|
|
2031
|
+
|
|
2032
|
+
export function getUpcomingEvents(limit = 10) {
|
|
2033
|
+
try {
|
|
2034
|
+
// Validate limit to prevent SQL issues
|
|
2035
|
+
const safeLimit = validateLimit(limit, 10, 100);
|
|
2036
|
+
const fetchLimit = safeLimit + 1; // Fetch one extra to detect if more exist
|
|
2037
|
+
const query = buildUpcomingEventsQuery(localTodayStartMac(), fetchLimit);
|
|
2019
2038
|
const events = withCalendarCopy((dbPath) => {
|
|
2039
|
+
assertOccurrenceCache(dbPath);
|
|
2020
2040
|
return safeSqlite3Json(dbPath, query, { timeout: 10000 });
|
|
2021
2041
|
});
|
|
2022
2042
|
const hasMore = events.length > safeLimit;
|
|
@@ -2149,6 +2169,7 @@ export function getEventsOnDate(startMs, endMs) {
|
|
|
2149
2169
|
const query = buildEventsOnDateQuery(startMac, endMac, { includeUid: attempt === 0 });
|
|
2150
2170
|
try {
|
|
2151
2171
|
const events = withCalendarCopy((dbPath) => {
|
|
2172
|
+
assertOccurrenceCache(dbPath);
|
|
2152
2173
|
return safeSqlite3Json(dbPath, query, { timeout: 15000 });
|
|
2153
2174
|
});
|
|
2154
2175
|
return { events, error: null };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "apple-tools-mcp",
|
|
3
|
-
"version": "3.3.
|
|
3
|
+
"version": "3.3.5",
|
|
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
|
@@ -1601,6 +1601,18 @@ export function formatMessageContactsResults(contacts) {
|
|
|
1601
1601
|
return output;
|
|
1602
1602
|
}
|
|
1603
1603
|
|
|
1604
|
+
// A calendar tool result that failed to read the calendar becomes a thrown error, so the MCP
|
|
1605
|
+
// dispatcher answers isError: true. A failed read must never look like an empty day.
|
|
1606
|
+
export function requireCalendarRead(result) {
|
|
1607
|
+
if (result?.success === false) {
|
|
1608
|
+
throw new Error(result.error || "The calendar could not be read");
|
|
1609
|
+
}
|
|
1610
|
+
if (result?.error) {
|
|
1611
|
+
throw new Error(`Error getting upcoming events: ${result.error}`);
|
|
1612
|
+
}
|
|
1613
|
+
return result;
|
|
1614
|
+
}
|
|
1615
|
+
|
|
1604
1616
|
// Format calendar_upcoming results
|
|
1605
1617
|
export function formatUpcomingEventsResults(result) {
|
|
1606
1618
|
if (result?.error) {
|