@mindstone/mcp-server-google-workspace 0.5.10 → 0.5.11
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 +1 -1
- package/dist/modules/calendar/service.js +153 -1
- package/dist/modules/calendar/types.d.ts +11 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -8,7 +8,7 @@ Google Workspace MCP server — Gmail, Calendar, Drive, Docs, Sheets, Slides, Co
|
|
|
8
8
|
|
|
9
9
|
## Status
|
|
10
10
|
|
|
11
|
-
- **Version:** [0.5.
|
|
11
|
+
- **Version:** [0.5.11](./CHANGELOG.md) · npm: not yet published
|
|
12
12
|
- **Auth:** OAuth (host-orchestrated) ([`GOOGLE_CLIENT_SECRET`](./server.json))
|
|
13
13
|
- **Tools:** [123](./src/tools/definitions/) (Gmail, Calendar, Drive, Docs, Sheets, Slides, Contacts, Chat, Meet, Tasks, Forms, Comments, Account)
|
|
14
14
|
- **Surface:** cloud-api
|
|
@@ -124,6 +124,148 @@ function planThisAndFollowing(series, occurrence) {
|
|
|
124
124
|
});
|
|
125
125
|
return { kind: 'cut', recurrence };
|
|
126
126
|
}
|
|
127
|
+
const hasOffset = (dateTime) => /(Z|[+-]\d\d:?\d\d)$/i.test(dateTime);
|
|
128
|
+
/** The date an entry falls on in the series' own time zone, whatever zone Google wrote its time in. */
|
|
129
|
+
const dayOf = (slot, timeZone) => {
|
|
130
|
+
if (slot?.date)
|
|
131
|
+
return slot.date;
|
|
132
|
+
if (!slot?.dateTime)
|
|
133
|
+
return undefined;
|
|
134
|
+
if (!hasOffset(slot.dateTime) || !timeZone)
|
|
135
|
+
return slot.dateTime.slice(0, 10);
|
|
136
|
+
return new Intl.DateTimeFormat('en-CA', { timeZone, year: 'numeric', month: '2-digit', day: '2-digit' }).format(new Date(slot.dateTime));
|
|
137
|
+
};
|
|
138
|
+
/** True only when both are surely the same moment: a time without an offset is compared as written, zone included. */
|
|
139
|
+
const sameInstant = (a, b) => {
|
|
140
|
+
if (a?.date || b?.date)
|
|
141
|
+
return a?.date === b?.date;
|
|
142
|
+
if (!a?.dateTime || !b?.dateTime)
|
|
143
|
+
return false;
|
|
144
|
+
if (hasOffset(a.dateTime) && hasOffset(b.dateTime))
|
|
145
|
+
return Date.parse(a.dateTime) === Date.parse(b.dateTime);
|
|
146
|
+
return a.dateTime === b.dateTime && (a.timeZone ?? '') === (b.timeZone ?? '');
|
|
147
|
+
};
|
|
148
|
+
/** Fields Google sets on each entry itself, or that can't be edited on one entry: never compared or written back. */
|
|
149
|
+
const PER_ENTRY = new Set(['kind', 'etag', 'id', 'status', 'htmlLink', 'created', 'updated', 'iCalUID', 'sequence', 'recurringEventId',
|
|
150
|
+
'originalStartTime', 'start', 'end', 'recurrence', 'creator', 'organizer', 'eventType', 'hangoutLink', 'privateCopy', 'locked', 'attendeesOmitted']);
|
|
151
|
+
/** Plain text details, written back on a single entry; Google leaves a cleared one out, so a clear is written as an empty value. */
|
|
152
|
+
const TEXT_FIELDS = new Set(['summary', 'description', 'location']);
|
|
153
|
+
const stable = (value) => Array.isArray(value) ? `[${value.map(stable).join(',')}]`
|
|
154
|
+
: value && typeof value === 'object' ? `{${Object.keys(value).sort().map(key => `${key}:${stable(value[key])}`).join(',')}}`
|
|
155
|
+
: JSON.stringify(value ?? null);
|
|
156
|
+
/** A field's value as an edit would change it: guests by who is invited, since each guest's reply to one entry is theirs. */
|
|
157
|
+
const comparable = (field, value) => {
|
|
158
|
+
if (field === 'attendees')
|
|
159
|
+
return stable((value ?? []).map(a => `${a.email}|${!!a.optional}`).sort());
|
|
160
|
+
return TEXT_FIELDS.has(field) ? stable(value ?? '') : stable(value);
|
|
161
|
+
};
|
|
162
|
+
/** The fields of one entry that differ from another: what the person edited on it. */
|
|
163
|
+
const differingFields = (entry, from) => {
|
|
164
|
+
const a = entry;
|
|
165
|
+
const b = from;
|
|
166
|
+
return [...new Set([...Object.keys(a), ...Object.keys(b)])].filter(field => !PER_ENTRY.has(field) && comparable(field, a[field]) !== comparable(field, b[field]));
|
|
167
|
+
};
|
|
168
|
+
const lengthOf = (event) => Date.parse(event.end?.dateTime ?? event.end?.date ?? '') - Date.parse(event.start?.dateTime ?? event.start?.date ?? '');
|
|
169
|
+
const describeChange = (c) => c.deleted ? 'deleted' : [c.moved && 'moved', c.edited.length > 0 && 'edited'].filter(Boolean).join(' and ');
|
|
170
|
+
async function listEntries(calendar, calendarId, seriesId, showDeleted) {
|
|
171
|
+
const entries = [];
|
|
172
|
+
let pageToken;
|
|
173
|
+
do {
|
|
174
|
+
const { data } = await calendar.events.instances({ calendarId, eventId: seriesId, showDeleted, maxResults: 2500, pageToken });
|
|
175
|
+
entries.push(...(data.items ?? []));
|
|
176
|
+
pageToken = data.nextPageToken ?? undefined;
|
|
177
|
+
} while (pageToken);
|
|
178
|
+
return entries;
|
|
179
|
+
}
|
|
180
|
+
/**
|
|
181
|
+
* Google keys a change to one entry of a series to that entry's original start, so a new series time
|
|
182
|
+
* leaves every such change behind: a moved entry snaps back and a deleted one returns. This reads them
|
|
183
|
+
* before the series changes, so they can be put back on the entry for the same date afterwards.
|
|
184
|
+
*/
|
|
185
|
+
async function readSingleChanges(calendar, calendarId, series) {
|
|
186
|
+
const zone = series.start?.timeZone ?? undefined;
|
|
187
|
+
const changes = [];
|
|
188
|
+
const entries = await listEntries(calendar, calendarId, series.id, true);
|
|
189
|
+
const perDate = new Map();
|
|
190
|
+
for (const entry of entries)
|
|
191
|
+
perDate.set(dayOf(entry.originalStartTime, zone), (perDate.get(dayOf(entry.originalStartTime, zone)) ?? 0) + 1);
|
|
192
|
+
for (const entry of entries) {
|
|
193
|
+
const deleted = entry.status === 'cancelled';
|
|
194
|
+
const moved = !deleted && (!sameInstant(entry.start, entry.originalStartTime) || lengthOf(entry) !== lengthOf(series));
|
|
195
|
+
const edited = deleted ? [] : differingFields(entry, series);
|
|
196
|
+
const date = dayOf(entry.originalStartTime, zone);
|
|
197
|
+
if (date && (deleted || moved || edited.length > 0))
|
|
198
|
+
changes.push({ date, entry, deleted, moved, edited, alone: perDate.get(date) === 1 });
|
|
199
|
+
}
|
|
200
|
+
return changes;
|
|
201
|
+
}
|
|
202
|
+
/**
|
|
203
|
+
* Puts each change back on the series' entry for the same date (dates in the series' zone after the change,
|
|
204
|
+
* which may differ from before it), writing only what differs, so a change
|
|
205
|
+
* still in place is kept as it is. One that has no entry on that date any more (the series moved to
|
|
206
|
+
* another day), that cannot be read back, or that Google refuses is returned as not kept, never dropped.
|
|
207
|
+
*/
|
|
208
|
+
async function restoreSingleChanges(calendar, calendarId, seriesId, zone, changes) {
|
|
209
|
+
const kept = [];
|
|
210
|
+
const notKept = [];
|
|
211
|
+
if (changes.length === 0)
|
|
212
|
+
return { kept, notKept };
|
|
213
|
+
let entries;
|
|
214
|
+
try {
|
|
215
|
+
entries = await listEntries(calendar, calendarId, seriesId, true);
|
|
216
|
+
}
|
|
217
|
+
catch (error) {
|
|
218
|
+
// The series has already changed: a thrown error here would be retried from the top and lose these.
|
|
219
|
+
const reason = `the series' entries could not be read back: ${error instanceof Error ? error.message : String(error)}`;
|
|
220
|
+
return { kept, notKept: changes.map(change => ({ date: change.date, change: describeChange(change), reason })) };
|
|
221
|
+
}
|
|
222
|
+
for (const change of changes) {
|
|
223
|
+
const outcome = { date: change.date, change: describeChange(change) };
|
|
224
|
+
// A date is matched only when it holds one entry of the series before and after, deleted ones counted:
|
|
225
|
+
// with two on one day, the one left could be one the person never touched.
|
|
226
|
+
const onDate = entries.filter(entry => dayOf(entry.originalStartTime, zone) === change.date);
|
|
227
|
+
try {
|
|
228
|
+
if (!change.alone || onDate.length > 1) {
|
|
229
|
+
notKept.push({ ...outcome, reason: 'the series has more than one entry on that date' });
|
|
230
|
+
continue;
|
|
231
|
+
}
|
|
232
|
+
const target = onDate[0];
|
|
233
|
+
if (change.deleted && target?.status === 'cancelled') {
|
|
234
|
+
kept.push(outcome);
|
|
235
|
+
continue;
|
|
236
|
+
}
|
|
237
|
+
if (!target || target.status === 'cancelled') {
|
|
238
|
+
notKept.push({ ...outcome, reason: 'the series no longer has one entry on that date' });
|
|
239
|
+
continue;
|
|
240
|
+
}
|
|
241
|
+
// Only times, deletions and plain text are written back: guests, reminders and other details are
|
|
242
|
+
// nested or carry other people's replies, so they are reported for the person to redo instead.
|
|
243
|
+
const left = change.edited.filter(field => !TEXT_FIELDS.has(field));
|
|
244
|
+
if (change.deleted) {
|
|
245
|
+
await calendar.events.delete({ calendarId, eventId: target.id, sendUpdates: 'none' });
|
|
246
|
+
}
|
|
247
|
+
else {
|
|
248
|
+
const requestBody = {
|
|
249
|
+
...(change.moved && !(sameInstant(target.start, change.entry.start) && sameInstant(target.end, change.entry.end))
|
|
250
|
+
? { start: change.entry.start, end: change.entry.end } : {}),
|
|
251
|
+
...Object.fromEntries(differingFields(change.entry, target).filter(field => TEXT_FIELDS.has(field) && change.edited.includes(field))
|
|
252
|
+
.map(field => [field, change.entry[field] ?? ''])),
|
|
253
|
+
};
|
|
254
|
+
if (Object.keys(requestBody).length > 0) {
|
|
255
|
+
await calendar.events.patch({ calendarId, eventId: target.id, sendUpdates: 'none', requestBody });
|
|
256
|
+
}
|
|
257
|
+
}
|
|
258
|
+
if (change.deleted || change.moved || left.length < change.edited.length)
|
|
259
|
+
kept.push(outcome);
|
|
260
|
+
if (left.length > 0)
|
|
261
|
+
notKept.push({ ...outcome, reason: `these details changed on that entry are not carried over: ${left.join(', ')}` });
|
|
262
|
+
}
|
|
263
|
+
catch (error) {
|
|
264
|
+
notKept.push({ ...outcome, reason: error instanceof Error ? error.message : String(error) });
|
|
265
|
+
}
|
|
266
|
+
}
|
|
267
|
+
return { kept, notKept };
|
|
268
|
+
}
|
|
127
269
|
export class CalendarService {
|
|
128
270
|
oauth2Client;
|
|
129
271
|
driveService;
|
|
@@ -643,6 +785,13 @@ export class CalendarService {
|
|
|
643
785
|
if (!hasNewTime && summary === undefined) {
|
|
644
786
|
throw new CalendarError('No new time provided', 'INVALID_REQUEST', 'Please provide the new time for the event');
|
|
645
787
|
}
|
|
788
|
+
// A new time for a whole series drops the person's changes to single entries of it; keep them.
|
|
789
|
+
const series = event.data;
|
|
790
|
+
// The zone counts too: the series repeats by its zone's clock, so a new zone re-keys its entries.
|
|
791
|
+
const newZone = hasNewTime ? newTimes[0].start?.timeZone ?? series.start?.timeZone : series.start?.timeZone;
|
|
792
|
+
const seriesTimeChanges = hasNewTime && !!series.recurrence?.length &&
|
|
793
|
+
(!sameInstant(newTimes[0].start, series.start) || !sameInstant(newTimes[0].end, series.end) || newZone !== series.start?.timeZone);
|
|
794
|
+
const singleChanges = seriesTimeChanges ? await readSingleChanges(calendar, targetCalendarId, series) : [];
|
|
646
795
|
const { data: updatedEvent } = await calendar.events.patch({
|
|
647
796
|
calendarId: targetCalendarId,
|
|
648
797
|
eventId,
|
|
@@ -653,12 +802,15 @@ export class CalendarService {
|
|
|
653
802
|
},
|
|
654
803
|
sendUpdates: 'all'
|
|
655
804
|
});
|
|
805
|
+
const { kept, notKept } = await restoreSingleChanges(calendar, targetCalendarId, eventId, updatedEvent.start?.timeZone ?? newZone ?? undefined, singleChanges);
|
|
656
806
|
return {
|
|
657
807
|
success: true,
|
|
658
808
|
eventId,
|
|
659
809
|
action,
|
|
660
810
|
status: 'updated',
|
|
661
|
-
htmlLink: updatedEvent.htmlLink || undefined
|
|
811
|
+
htmlLink: updatedEvent.htmlLink || undefined,
|
|
812
|
+
...(kept.length ? { singleEntryChangesKept: kept } : {}),
|
|
813
|
+
...(notKept.length ? { singleEntryChangesNotKept: notKept } : {})
|
|
662
814
|
};
|
|
663
815
|
}
|
|
664
816
|
default:
|
|
@@ -127,6 +127,17 @@ export interface ManageEventResponse {
|
|
|
127
127
|
start: EventTime;
|
|
128
128
|
end: EventTime;
|
|
129
129
|
}[];
|
|
130
|
+
/** After a series' time changed: the person's changes to single entries that were put back, by date. */
|
|
131
|
+
singleEntryChangesKept?: {
|
|
132
|
+
date: string;
|
|
133
|
+
change: string;
|
|
134
|
+
}[];
|
|
135
|
+
/** And those that could not be, with why: the reply must tell the person. */
|
|
136
|
+
singleEntryChangesNotKept?: {
|
|
137
|
+
date: string;
|
|
138
|
+
change: string;
|
|
139
|
+
reason?: string;
|
|
140
|
+
}[];
|
|
130
141
|
}
|
|
131
142
|
export interface DeleteEventParams {
|
|
132
143
|
email: string;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mindstone/mcp-server-google-workspace",
|
|
3
|
-
"version": "0.5.
|
|
3
|
+
"version": "0.5.11",
|
|
4
4
|
"mcpName": "io.github.mindstone/mcp-server-google-workspace",
|
|
5
5
|
"description": "Google Workspace MCP server for Gmail, Calendar, Drive, Docs, Sheets, Slides, Contacts, Tasks, and Forms",
|
|
6
6
|
"license": "FSL-1.1-MIT",
|