@mindstone/mcp-server-google-workspace 0.1.5 → 0.3.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.
- package/README.md +28 -9
- package/dist/modules/accounts/manager.js +20 -2
- package/dist/modules/accounts/token.d.ts +13 -0
- package/dist/modules/accounts/token.js +73 -58
- package/dist/modules/accounts/types.d.ts +1 -0
- package/dist/modules/calendar/service.js +9 -0
- package/dist/modules/chat/index.d.ts +12 -0
- package/dist/modules/chat/index.js +18 -0
- package/dist/modules/chat/scopes.d.ts +14 -0
- package/dist/modules/chat/scopes.js +32 -0
- package/dist/modules/chat/types.d.ts +88 -0
- package/dist/modules/chat/types.js +14 -0
- package/dist/modules/comments/service.js +26 -5
- package/dist/modules/contacts/scopes.d.ts +1 -0
- package/dist/modules/contacts/scopes.js +2 -2
- package/dist/modules/contacts/types.d.ts +34 -0
- package/dist/modules/docs/index.js +2 -1
- package/dist/modules/docs/service.js +36 -7
- package/dist/modules/drive/activity-service.d.ts +45 -0
- package/dist/modules/drive/activity-service.js +114 -0
- package/dist/modules/drive/index.d.ts +4 -0
- package/dist/modules/drive/index.js +12 -0
- package/dist/modules/drive/scopes.d.ts +1 -0
- package/dist/modules/drive/scopes.js +3 -0
- package/dist/modules/drive/service.d.ts +2 -1
- package/dist/modules/drive/service.js +29 -0
- package/dist/modules/drive/types.d.ts +8 -0
- package/dist/modules/forms/service.js +16 -3
- package/dist/modules/gmail/services/attachment.js +2 -1
- package/dist/modules/gmail/services/base.d.ts +5 -1
- package/dist/modules/gmail/services/base.js +10 -1
- package/dist/modules/gmail/services/draft.js +13 -7
- package/dist/modules/gmail/services/email.js +4 -3
- package/dist/modules/gmail/services/label.js +10 -9
- package/dist/modules/gmail/services/settings.d.ts +14 -1
- package/dist/modules/gmail/services/settings.js +96 -1
- package/dist/modules/gmail/types.d.ts +36 -0
- package/dist/modules/meet/index.d.ts +12 -0
- package/dist/modules/meet/index.js +18 -0
- package/dist/modules/meet/scopes.d.ts +9 -0
- package/dist/modules/meet/scopes.js +25 -0
- package/dist/modules/meet/types.d.ts +97 -0
- package/dist/modules/meet/types.js +14 -0
- package/dist/modules/sheets/service.js +49 -0
- package/dist/modules/slides/service.js +31 -6
- package/dist/modules/tasks/service.js +31 -6
- package/dist/resources/compose-email-template.d.ts +1 -1
- package/dist/resources/compose-email-template.js +388 -19
- package/dist/services/base/BaseGoogleService.d.ts +9 -1
- package/dist/services/base/BaseGoogleService.js +33 -1
- package/dist/services/chat/index.d.ts +34 -0
- package/dist/services/chat/index.js +120 -0
- package/dist/services/contacts/index.d.ts +19 -1
- package/dist/services/contacts/index.js +124 -0
- package/dist/services/meet/index.d.ts +35 -0
- package/dist/services/meet/index.js +116 -0
- package/dist/tools/calendar-handlers.js +28 -23
- package/dist/tools/chat-handlers.d.ts +14 -0
- package/dist/tools/chat-handlers.js +126 -0
- package/dist/tools/contacts-handlers.d.ts +31 -0
- package/dist/tools/contacts-handlers.js +96 -23
- package/dist/tools/definitions/account.js +8 -1
- package/dist/tools/definitions/chat.d.ts +3 -0
- package/dist/tools/definitions/chat.js +137 -0
- package/dist/tools/definitions/contacts.js +82 -0
- package/dist/tools/definitions/destructive-overrides.json +12 -0
- package/dist/tools/definitions/drive.js +132 -6
- package/dist/tools/definitions/gmail.js +94 -0
- package/dist/tools/definitions/index.d.ts +2 -0
- package/dist/tools/definitions/index.js +6 -0
- package/dist/tools/definitions/meet.d.ts +3 -0
- package/dist/tools/definitions/meet.js +149 -0
- package/dist/tools/definitions/open-world-overrides.json +12 -0
- package/dist/tools/drive-handlers.d.ts +27 -0
- package/dist/tools/drive-handlers.js +93 -2
- package/dist/tools/forms-handlers.js +5 -12
- package/dist/tools/gmail-handlers.d.ts +31 -1
- package/dist/tools/gmail-handlers.js +167 -35
- package/dist/tools/meet-handlers.d.ts +42 -0
- package/dist/tools/meet-handlers.js +144 -0
- package/dist/tools/server.js +67 -5
- package/dist/tools/tasks-handlers.js +7 -18
- package/dist/tools/type-guards.d.ts +3 -1
- package/dist/tools/type-guards.js +22 -2
- package/dist/tools/types.d.ts +13 -0
- package/dist/utils/apiError.d.ts +49 -0
- package/dist/utils/apiError.js +96 -0
- package/dist/utils/scope-hierarchy.js +10 -0
- package/dist/utils/service-initializer.js +9 -0
- package/dist/utils/untrusted-content.d.ts +37 -1
- package/dist/utils/untrusted-content.js +61 -6
- package/package.json +5 -1
- package/dist/services/calendar/index.d.ts +0 -27
- package/dist/services/calendar/index.js +0 -146
- package/dist/services/gmail/index.d.ts +0 -39
- package/dist/services/gmail/index.js +0 -337
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
import { McpError, ErrorCode } from '@modelcontextprotocol/sdk/types.js';
|
|
2
2
|
import { getAccountManager, resolveEmail } from '../modules/accounts/index.js';
|
|
3
|
-
import { getDriveService } from '../modules/drive/index.js';
|
|
4
|
-
import {
|
|
3
|
+
import { getDriveService, getDriveActivityService } from '../modules/drive/index.js';
|
|
4
|
+
import { normalizeDriveItemName } from '../modules/drive/activity-service.js';
|
|
5
|
+
import { toMcpError } from '../utils/apiError.js';
|
|
6
|
+
import { readAliasedBoolean, readAliasedNumber, readAliasedString } from './arg-aliases.js';
|
|
5
7
|
import { wrapUntrustedContent, wrapUntrustedJsonStrings } from '../utils/untrusted-content.js';
|
|
6
8
|
const HOST_TIMEZONE = Intl.DateTimeFormat().resolvedOptions().timeZone;
|
|
7
9
|
/**
|
|
@@ -60,6 +62,21 @@ function formatFilesAsText(files) {
|
|
|
60
62
|
}
|
|
61
63
|
return wrapUntrustedContent(lines.join('\n'), 'google-workspace:drive:file-list');
|
|
62
64
|
}
|
|
65
|
+
/**
|
|
66
|
+
* Format shared-drives list as human-readable text
|
|
67
|
+
*/
|
|
68
|
+
function formatSharedDrivesAsText(drives) {
|
|
69
|
+
if (!drives || drives.length === 0) {
|
|
70
|
+
return 'No shared drives found.';
|
|
71
|
+
}
|
|
72
|
+
const lines = [];
|
|
73
|
+
lines.push(`Shared drives: ${drives.length} result${drives.length !== 1 ? 's' : ''}\n`);
|
|
74
|
+
for (const drive of drives) {
|
|
75
|
+
lines.push(`${drive.name}`);
|
|
76
|
+
lines.push(` [id: ${drive.id}]`);
|
|
77
|
+
}
|
|
78
|
+
return wrapUntrustedContent(lines.join('\n'), 'google-workspace:drive:shared-drive-list');
|
|
79
|
+
}
|
|
63
80
|
/** @internal Exported for tests. */
|
|
64
81
|
export function formatDriveRecoveryError(operation, error) {
|
|
65
82
|
const status = error && typeof error === 'object'
|
|
@@ -181,6 +198,34 @@ export async function handleSearchDriveFiles(args) {
|
|
|
181
198
|
}
|
|
182
199
|
});
|
|
183
200
|
}
|
|
201
|
+
export async function handleListSharedDrives(args) {
|
|
202
|
+
const accountManager = getAccountManager();
|
|
203
|
+
const rawArgs = args;
|
|
204
|
+
const returnJson = readAliasedBoolean(rawArgs, 'return_json', 'returnJson') ?? false;
|
|
205
|
+
const pageSize = readAliasedNumber(rawArgs, 'page_size', 'pageSize');
|
|
206
|
+
const pageToken = readAliasedString(rawArgs, 'page_token', 'pageToken');
|
|
207
|
+
// Resolve email - uses instance account if not provided, validates if provided
|
|
208
|
+
const email = await resolveEmail(args);
|
|
209
|
+
return await accountManager.withTokenRenewal(email, async () => {
|
|
210
|
+
try {
|
|
211
|
+
const driveService = await getDriveService();
|
|
212
|
+
const result = await driveService.listSharedDrives(email, { pageSize, pageToken });
|
|
213
|
+
// Return JSON if requested, otherwise format as human-readable text
|
|
214
|
+
// Return string directly - server.ts handles MCP response wrapping
|
|
215
|
+
if (returnJson) {
|
|
216
|
+
return formatDriveJsonResult('list shared drives', result, 'google-workspace:drive:shared-drive-list');
|
|
217
|
+
}
|
|
218
|
+
if (!result.success) {
|
|
219
|
+
return formatDriveRecoveryError('list shared drives', new Error(result.error || 'Unknown error'));
|
|
220
|
+
}
|
|
221
|
+
const drives = result.data?.drives || [];
|
|
222
|
+
return formatSharedDrivesAsText(drives);
|
|
223
|
+
}
|
|
224
|
+
catch (error) {
|
|
225
|
+
return formatDriveRecoveryError('list shared drives', error);
|
|
226
|
+
}
|
|
227
|
+
});
|
|
228
|
+
}
|
|
184
229
|
export async function handleUploadDriveFile(args) {
|
|
185
230
|
if (!args.options?.name) {
|
|
186
231
|
throw new McpError(ErrorCode.InvalidParams, 'Missing required parameter: "options.name" (filename for upload). ' +
|
|
@@ -503,4 +548,50 @@ export async function handleDownloadFileRevision(args) {
|
|
|
503
548
|
}
|
|
504
549
|
});
|
|
505
550
|
}
|
|
551
|
+
const MAX_DRIVE_ACTIVITY_PAGE_SIZE = 100;
|
|
552
|
+
/**
|
|
553
|
+
* Query the Drive Activity API: what changed on a file, or inside a folder /
|
|
554
|
+
* shared drive, and who did it.
|
|
555
|
+
*/
|
|
556
|
+
export async function handleQueryDriveActivity(args) {
|
|
557
|
+
const rawArgs = args;
|
|
558
|
+
const itemId = readAliasedString(rawArgs, 'item_id', 'itemId');
|
|
559
|
+
const ancestorId = readAliasedString(rawArgs, 'ancestor_id', 'ancestorId');
|
|
560
|
+
const filter = readAliasedString(rawArgs, 'filter', 'filter');
|
|
561
|
+
const pageToken = readAliasedString(rawArgs, 'page_token', 'pageToken');
|
|
562
|
+
const rawPageSize = readAliasedNumber(rawArgs, 'page_size', 'pageSize');
|
|
563
|
+
if (!itemId && !ancestorId) {
|
|
564
|
+
throw new McpError(ErrorCode.InvalidParams, 'Provide item_id (a file/folder ID, from list_drive_files or search_drive_files) ' +
|
|
565
|
+
'or ancestor_id (a folder or shared-drive ID, to see everything that changed inside it).');
|
|
566
|
+
}
|
|
567
|
+
if (itemId && ancestorId) {
|
|
568
|
+
throw new McpError(ErrorCode.InvalidParams, 'Provide only one of item_id or ancestor_id — the Drive Activity API rejects queries with both.');
|
|
569
|
+
}
|
|
570
|
+
if (rawPageSize !== undefined && (rawPageSize < 1 || !Number.isInteger(rawPageSize))) {
|
|
571
|
+
throw new McpError(ErrorCode.InvalidParams, 'page_size must be a positive integer');
|
|
572
|
+
}
|
|
573
|
+
const pageSize = rawPageSize === undefined
|
|
574
|
+
? undefined
|
|
575
|
+
: Math.min(rawPageSize, MAX_DRIVE_ACTIVITY_PAGE_SIZE);
|
|
576
|
+
const accountManager = getAccountManager();
|
|
577
|
+
const email = await resolveEmail(args);
|
|
578
|
+
return await accountManager.withTokenRenewal(email, async () => {
|
|
579
|
+
try {
|
|
580
|
+
const activityService = await getDriveActivityService();
|
|
581
|
+
const result = await activityService.queryActivity(email, {
|
|
582
|
+
itemName: itemId ? normalizeDriveItemName(itemId) : undefined,
|
|
583
|
+
ancestorName: ancestorId ? normalizeDriveItemName(ancestorId) : undefined,
|
|
584
|
+
pageSize,
|
|
585
|
+
pageToken,
|
|
586
|
+
filter
|
|
587
|
+
});
|
|
588
|
+
// Titles are enveloped field-level in the service (see summarizeTarget);
|
|
589
|
+
// the rest of the summary is connector-derived and returned raw.
|
|
590
|
+
return result;
|
|
591
|
+
}
|
|
592
|
+
catch (error) {
|
|
593
|
+
throw toMcpError(error, 'Failed to query Drive activity');
|
|
594
|
+
}
|
|
595
|
+
});
|
|
596
|
+
}
|
|
506
597
|
//# sourceMappingURL=drive-handlers.js.map
|
|
@@ -2,6 +2,7 @@ import { getFormsService } from '../modules/forms/index.js';
|
|
|
2
2
|
import { getDriveService } from '../modules/drive/index.js';
|
|
3
3
|
import { getAccountManager, resolveEmail } from '../modules/accounts/index.js';
|
|
4
4
|
import { McpError, ErrorCode } from '@modelcontextprotocol/sdk/types.js';
|
|
5
|
+
import { toMcpError } from '../utils/apiError.js';
|
|
5
6
|
import { readAliasedNumber, readAliasedString } from './arg-aliases.js';
|
|
6
7
|
import { wrapUntrustedContent } from '../utils/untrusted-content.js';
|
|
7
8
|
const HOST_TIMEZONE = Intl.DateTimeFormat().resolvedOptions().timeZone;
|
|
@@ -233,9 +234,7 @@ export async function handleListForms(params) {
|
|
|
233
234
|
return wrapUntrustedContent(lines.join('\n'), 'google-workspace:forms:list');
|
|
234
235
|
}
|
|
235
236
|
catch (error) {
|
|
236
|
-
|
|
237
|
-
throw error;
|
|
238
|
-
throw new McpError(ErrorCode.InternalError, `Failed to list forms: ${error instanceof Error ? error.message : 'Unknown error'}`);
|
|
237
|
+
throw toMcpError(error, 'Failed to list forms');
|
|
239
238
|
}
|
|
240
239
|
});
|
|
241
240
|
}
|
|
@@ -299,9 +298,7 @@ export async function handleGetForm(params) {
|
|
|
299
298
|
return wrapUntrustedContent(lines.join('\n'), `google-workspace:forms:form/${formId}`);
|
|
300
299
|
}
|
|
301
300
|
catch (error) {
|
|
302
|
-
|
|
303
|
-
throw error;
|
|
304
|
-
throw new McpError(ErrorCode.InternalError, `Failed to get form: ${error instanceof Error ? error.message : 'Unknown error'}`);
|
|
301
|
+
throw toMcpError(error, 'Failed to get form');
|
|
305
302
|
}
|
|
306
303
|
});
|
|
307
304
|
}
|
|
@@ -365,9 +362,7 @@ export async function handleListFormResponses(params) {
|
|
|
365
362
|
return wrapUntrustedContent(lines.join('\n'), `google-workspace:forms:responses/${formId}`);
|
|
366
363
|
}
|
|
367
364
|
catch (error) {
|
|
368
|
-
|
|
369
|
-
throw error;
|
|
370
|
-
throw new McpError(ErrorCode.InternalError, `Failed to list form responses: ${error instanceof Error ? error.message : 'Unknown error'}`);
|
|
365
|
+
throw toMcpError(error, 'Failed to list form responses');
|
|
371
366
|
}
|
|
372
367
|
});
|
|
373
368
|
}
|
|
@@ -426,9 +421,7 @@ export async function handleGetFormResponse(params) {
|
|
|
426
421
|
return wrapUntrustedContent(lines.join('\n'), `google-workspace:forms:response/${responseId}`);
|
|
427
422
|
}
|
|
428
423
|
catch (error) {
|
|
429
|
-
|
|
430
|
-
throw error;
|
|
431
|
-
throw new McpError(ErrorCode.InternalError, `Failed to get form response: ${error instanceof Error ? error.message : 'Unknown error'}`);
|
|
424
|
+
throw toMcpError(error, 'Failed to get form response');
|
|
432
425
|
}
|
|
433
426
|
});
|
|
434
427
|
}
|
|
@@ -208,10 +208,40 @@ export declare function handleGetWorkspaceEmailThread(params: GetThreadParams):
|
|
|
208
208
|
}>;
|
|
209
209
|
}>;
|
|
210
210
|
}>;
|
|
211
|
-
export declare function handleSendWorkspaceEmail(params: SendEmailRequestParams & Record<string, unknown>): Promise<
|
|
211
|
+
export declare function handleSendWorkspaceEmail(params: SendEmailRequestParams & Record<string, unknown>): Promise<{
|
|
212
|
+
content: {
|
|
213
|
+
type: "text";
|
|
214
|
+
text: string;
|
|
215
|
+
}[];
|
|
216
|
+
structuredContent: import("../modules/gmail/types.js").SendEmailResponse;
|
|
217
|
+
}>;
|
|
212
218
|
export declare function handleGetWorkspaceGmailSettings(params: {
|
|
213
219
|
email?: string;
|
|
214
220
|
}): Promise<import("../modules/gmail/types.js").GetGmailSettingsResponse>;
|
|
221
|
+
export interface UpdateVacationResponderToolParams {
|
|
222
|
+
email?: string;
|
|
223
|
+
enabled?: boolean;
|
|
224
|
+
response_subject?: string;
|
|
225
|
+
responseSubject?: string;
|
|
226
|
+
response_body?: string;
|
|
227
|
+
responseBody?: string;
|
|
228
|
+
start_time?: number | string;
|
|
229
|
+
startTime?: number | string;
|
|
230
|
+
end_time?: number | string;
|
|
231
|
+
endTime?: number | string;
|
|
232
|
+
clear_end_time?: boolean;
|
|
233
|
+
clearEndTime?: boolean;
|
|
234
|
+
contacts_only?: boolean;
|
|
235
|
+
contactsOnly?: boolean;
|
|
236
|
+
domain_only?: boolean;
|
|
237
|
+
domainOnly?: boolean;
|
|
238
|
+
}
|
|
239
|
+
export declare function handleUpdateWorkspaceVacationResponder(params: UpdateVacationResponderToolParams): Promise<import("../modules/gmail/types.js").VacationResponderState>;
|
|
240
|
+
export declare function handleListWorkspaceSendAs(params: {
|
|
241
|
+
email?: string;
|
|
242
|
+
}): Promise<{
|
|
243
|
+
sendAs: import("../modules/gmail/types.js").SendAsAlias[];
|
|
244
|
+
}>;
|
|
215
245
|
export declare function handleManageWorkspaceDraft(params: ManageDraftParams): Promise<void | import("../modules/gmail/types.js").DraftResponse | import("../modules/gmail/types.js").GetDraftsResponse | import("../modules/gmail/types.js").SendEmailResponse>;
|
|
216
246
|
export declare function handleManageWorkspaceLabel(params: ManageLabelParams): Promise<void | import("../modules/gmail/types.js").Label | import("../modules/gmail/types.js").GetLabelsResponse>;
|
|
217
247
|
export declare function handleManageWorkspaceLabelAssignment(params: ManageLabelAssignmentParams): Promise<{
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import { getGmailService } from '../modules/gmail/index.js';
|
|
2
2
|
import { getAccountManager, validateEmail, resolveEmail } from '../modules/accounts/index.js';
|
|
3
3
|
import { McpError, ErrorCode } from '@modelcontextprotocol/sdk/types.js';
|
|
4
|
-
import {
|
|
4
|
+
import { toMcpError } from '../utils/apiError.js';
|
|
5
5
|
import { AttachmentService } from '../modules/attachments/service.js';
|
|
6
6
|
import { ATTACHMENT_FOLDERS } from '../modules/attachments/types.js';
|
|
7
|
-
import { lstatSync, readFileSync, realpathSync, statSync } from 'fs';
|
|
7
|
+
import { closeSync, constants, fstatSync, lstatSync, openSync, readFileSync, realpathSync, statSync } from 'fs';
|
|
8
8
|
import path from 'path';
|
|
9
9
|
import { wrapUntrustedContent, wrapUntrustedJsonStrings } from '../utils/untrusted-content.js';
|
|
10
10
|
// Singleton instances
|
|
@@ -104,15 +104,45 @@ export function resolveAttachmentFromPath(filePath) {
|
|
|
104
104
|
if (!isPathInsideDirectory(candidateRealpath, rootRealpath)) {
|
|
105
105
|
throw new McpError(ErrorCode.InvalidParams, `Attachment path must be within the workspace directory. Got: ${filePath}`);
|
|
106
106
|
}
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
107
|
+
// Pin the identity (device + inode) of the object that passed containment.
|
|
108
|
+
// O_NOFOLLOW only refuses a symlink in the FINAL path component — an
|
|
109
|
+
// attacker who swaps an intermediate directory for an out-of-workspace
|
|
110
|
+
// symlink between this check and the open would otherwise redirect the read.
|
|
111
|
+
// Re-verifying the opened descriptor's identity against the validated one
|
|
112
|
+
// fails closed on any such swap (ancestor-directory or final-component).
|
|
113
|
+
const validatedStats = statSync(candidateRealpath);
|
|
114
|
+
if (!validatedStats.isFile()) {
|
|
115
|
+
throw new McpError(ErrorCode.InvalidParams, 'Attachment path must point to a regular file.');
|
|
116
|
+
}
|
|
117
|
+
// Open once and read through the fd: checking the path and then re-opening it
|
|
118
|
+
// by name would leave a swap race between the containment check and the read.
|
|
119
|
+
// O_NOFOLLOW (where the platform supports it) refuses a symlink planted in
|
|
120
|
+
// that window.
|
|
121
|
+
const fd = openSync(candidateRealpath, constants.O_RDONLY | (constants.O_NOFOLLOW ?? 0));
|
|
122
|
+
try {
|
|
123
|
+
const stats = fstatSync(fd);
|
|
124
|
+
if (!stats.isFile()) {
|
|
125
|
+
throw new McpError(ErrorCode.InvalidParams, 'Attachment path must point to a regular file.');
|
|
126
|
+
}
|
|
127
|
+
if (stats.dev !== validatedStats.dev || stats.ino !== validatedStats.ino) {
|
|
128
|
+
throw new McpError(ErrorCode.InvalidParams, 'Attachment file changed while it was being verified; refusing to read it.');
|
|
129
|
+
}
|
|
130
|
+
// Irreducible residual: an attacker who can already write the validated
|
|
131
|
+
// in-workspace file can mutate its content in place (same inode) between
|
|
132
|
+
// this check and the read. That is not a containment escape — the bytes
|
|
133
|
+
// still come from the approved workspace file — so it is out of scope here.
|
|
134
|
+
const content = readFileSync(fd);
|
|
135
|
+
const ext = path.extname(candidateRealpath).toLowerCase();
|
|
136
|
+
return {
|
|
137
|
+
content: content.toString('base64'),
|
|
138
|
+
name: path.basename(candidateRealpath),
|
|
139
|
+
mimeType: MIME_TYPES[ext] || 'application/octet-stream',
|
|
140
|
+
size: stats.size,
|
|
141
|
+
};
|
|
142
|
+
}
|
|
143
|
+
finally {
|
|
144
|
+
closeSync(fd);
|
|
145
|
+
}
|
|
116
146
|
}
|
|
117
147
|
function processOutgoingAttachments(attachments) {
|
|
118
148
|
return attachments?.map(attachment => {
|
|
@@ -152,7 +182,15 @@ function readAliasedNumber(args, canonicalKey, legacyKey) {
|
|
|
152
182
|
}
|
|
153
183
|
function readAliasedBoolean(args, canonicalKey, legacyKey) {
|
|
154
184
|
const value = args[canonicalKey] ?? args[legacyKey];
|
|
155
|
-
|
|
185
|
+
if (value === undefined || value === null)
|
|
186
|
+
return undefined;
|
|
187
|
+
// Fail closed on wrong-typed input (e.g. the string "true") rather than
|
|
188
|
+
// silently treating it as absent — for write flags like clear_end_time a
|
|
189
|
+
// coerced default can mask what the caller asked for.
|
|
190
|
+
if (typeof value !== 'boolean') {
|
|
191
|
+
throw new McpError(ErrorCode.InvalidParams, `"${canonicalKey}" must be a boolean (true/false), got ${typeof value}`);
|
|
192
|
+
}
|
|
193
|
+
return value;
|
|
156
194
|
}
|
|
157
195
|
function readAliasedStringArray(args, canonicalKey, legacyKey) {
|
|
158
196
|
const value = args[canonicalKey] ?? args[legacyKey];
|
|
@@ -221,6 +259,14 @@ function normalizeDraftData(data) {
|
|
|
221
259
|
references: data.references,
|
|
222
260
|
};
|
|
223
261
|
}
|
|
262
|
+
// Fail loudly on a malformed recipient list — a non-array crashes buildMimeMessage
|
|
263
|
+
// deep in the service and used to surface as an opaque InternalError. Empty arrays are
|
|
264
|
+
// valid for drafts, so only the shape is checked here. Covers to/cc/bcc alike.
|
|
265
|
+
function assertRecipientsArray(value, field) {
|
|
266
|
+
if (value !== undefined && !Array.isArray(value)) {
|
|
267
|
+
throw new McpError(ErrorCode.InvalidParams, `Draft recipients (${field}) must be an array of email addresses`);
|
|
268
|
+
}
|
|
269
|
+
}
|
|
224
270
|
export async function handleComposeWorkspaceEmail(params) {
|
|
225
271
|
const to = Array.isArray(params.to)
|
|
226
272
|
? params.to.filter((addr) => typeof addr === 'string' && addr.trim().length > 0)
|
|
@@ -340,7 +386,7 @@ export async function handleSearchWorkspaceEmails(params) {
|
|
|
340
386
|
return formatEmailsAsText(result);
|
|
341
387
|
}
|
|
342
388
|
catch (error) {
|
|
343
|
-
throw
|
|
389
|
+
throw toMcpError(error, 'Failed to search emails');
|
|
344
390
|
}
|
|
345
391
|
});
|
|
346
392
|
}
|
|
@@ -435,7 +481,7 @@ export async function handleGetWorkspaceEmailThread(params) {
|
|
|
435
481
|
return formatThreadAsText(result, offset, includeFullBodies);
|
|
436
482
|
}
|
|
437
483
|
catch (error) {
|
|
438
|
-
throw
|
|
484
|
+
throw toMcpError(error, 'Failed to get thread');
|
|
439
485
|
}
|
|
440
486
|
});
|
|
441
487
|
}
|
|
@@ -507,15 +553,18 @@ export async function handleSendWorkspaceEmail(params) {
|
|
|
507
553
|
references: threading.references,
|
|
508
554
|
attachments: processOutgoingAttachments(attachments)
|
|
509
555
|
};
|
|
510
|
-
|
|
556
|
+
const sendResult = await gmailService.sendEmail(emailParams);
|
|
557
|
+
// Return an McpToolResponse-shaped result so the identifiers survive as
|
|
558
|
+
// structuredContent (hoisted by super-mcp) — the compose-email UI reads
|
|
559
|
+
// { messageId, threadId } from it to build an "Open in Gmail" deep link.
|
|
560
|
+
// The text block preserves the same JSON the model saw before this change.
|
|
561
|
+
return {
|
|
562
|
+
content: [{ type: 'text', text: JSON.stringify(sendResult) }],
|
|
563
|
+
structuredContent: sendResult,
|
|
564
|
+
};
|
|
511
565
|
}
|
|
512
566
|
catch (error) {
|
|
513
|
-
|
|
514
|
-
? `${error.message}: ${error.details}`
|
|
515
|
-
: error instanceof Error
|
|
516
|
-
? error.message
|
|
517
|
-
: 'Unknown error';
|
|
518
|
-
throw new McpError(ErrorCode.InternalError, `Failed to send email: ${details}`);
|
|
567
|
+
throw toMcpError(error, 'Failed to send email');
|
|
519
568
|
}
|
|
520
569
|
});
|
|
521
570
|
}
|
|
@@ -528,7 +577,87 @@ export async function handleGetWorkspaceGmailSettings(params) {
|
|
|
528
577
|
return await gmailService.getWorkspaceGmailSettings({ email });
|
|
529
578
|
}
|
|
530
579
|
catch (error) {
|
|
531
|
-
throw
|
|
580
|
+
throw toMcpError(error, 'Failed to get Gmail settings');
|
|
581
|
+
}
|
|
582
|
+
});
|
|
583
|
+
}
|
|
584
|
+
/**
|
|
585
|
+
* Parses a vacation start/end timestamp per the repo's epoch-ms rules: a number
|
|
586
|
+
* or digit-only string in the unambiguous epoch-ms window [1e12, 1e14), or a
|
|
587
|
+
* parseable date string. Anything else — notably Unix *seconds* like
|
|
588
|
+
* 1735689600, which would silently be 1000x off — is rejected.
|
|
589
|
+
*/
|
|
590
|
+
function parseEpochMsField(value, fieldName) {
|
|
591
|
+
if (value === undefined || value === null)
|
|
592
|
+
return undefined;
|
|
593
|
+
if (typeof value === 'number') {
|
|
594
|
+
if (!Number.isFinite(value) || value < 1e12 || value >= 1e14) {
|
|
595
|
+
throw new McpError(ErrorCode.InvalidParams, `${fieldName} numbers must be epoch milliseconds (e.g. 1735689600000), not seconds`);
|
|
596
|
+
}
|
|
597
|
+
return value;
|
|
598
|
+
}
|
|
599
|
+
if (typeof value === 'string') {
|
|
600
|
+
if (/^\d+$/.test(value)) {
|
|
601
|
+
const parsed = Number(value);
|
|
602
|
+
if (parsed >= 1e12 && parsed < 1e14)
|
|
603
|
+
return parsed;
|
|
604
|
+
throw new McpError(ErrorCode.InvalidParams, `${fieldName} digit-only strings must be epoch milliseconds (e.g. 1735689600000), not seconds`);
|
|
605
|
+
}
|
|
606
|
+
const parsed = Date.parse(value);
|
|
607
|
+
if (Number.isNaN(parsed)) {
|
|
608
|
+
throw new McpError(ErrorCode.InvalidParams, `${fieldName} must be epoch milliseconds or a parseable date string (e.g. "2026-08-07")`);
|
|
609
|
+
}
|
|
610
|
+
return parsed;
|
|
611
|
+
}
|
|
612
|
+
throw new McpError(ErrorCode.InvalidParams, `${fieldName} must be a number or a date string`);
|
|
613
|
+
}
|
|
614
|
+
export async function handleUpdateWorkspaceVacationResponder(params) {
|
|
615
|
+
await initializeServices();
|
|
616
|
+
const rawParams = params;
|
|
617
|
+
const email = await resolveEmail(params);
|
|
618
|
+
const enabled = readAliasedBoolean(rawParams, 'enabled', 'enabled');
|
|
619
|
+
if (enabled === undefined) {
|
|
620
|
+
throw new McpError(ErrorCode.InvalidParams, 'Missing required parameter: "enabled" (true to turn the out-of-office reply on, false to turn it off)');
|
|
621
|
+
}
|
|
622
|
+
const startTime = parseEpochMsField(rawParams.start_time ?? rawParams.startTime, 'start_time');
|
|
623
|
+
const endTime = parseEpochMsField(rawParams.end_time ?? rawParams.endTime, 'end_time');
|
|
624
|
+
const clearEndTime = readAliasedBoolean(rawParams, 'clear_end_time', 'clearEndTime') ?? false;
|
|
625
|
+
if (clearEndTime && endTime !== undefined) {
|
|
626
|
+
throw new McpError(ErrorCode.InvalidParams, 'Pass either end_time or clear_end_time, not both');
|
|
627
|
+
}
|
|
628
|
+
if (startTime !== undefined && endTime !== undefined && endTime <= startTime) {
|
|
629
|
+
throw new McpError(ErrorCode.InvalidParams, 'end_time must be after start_time');
|
|
630
|
+
}
|
|
631
|
+
return accountManager.withTokenRenewal(email, async () => {
|
|
632
|
+
try {
|
|
633
|
+
const result = await gmailService.updateVacationResponder({
|
|
634
|
+
email,
|
|
635
|
+
enabled,
|
|
636
|
+
responseSubject: readAliasedString(rawParams, 'response_subject', 'responseSubject'),
|
|
637
|
+
responseBody: readAliasedString(rawParams, 'response_body', 'responseBody'),
|
|
638
|
+
startTime,
|
|
639
|
+
endTime,
|
|
640
|
+
clearEndTime,
|
|
641
|
+
contactsOnly: readAliasedBoolean(rawParams, 'contacts_only', 'contactsOnly'),
|
|
642
|
+
domainOnly: readAliasedBoolean(rawParams, 'domain_only', 'domainOnly')
|
|
643
|
+
});
|
|
644
|
+
return wrapUntrustedJsonStrings(result, 'google-workspace:gmail:vacation-responder');
|
|
645
|
+
}
|
|
646
|
+
catch (error) {
|
|
647
|
+
throw toMcpError(error, 'Failed to update vacation responder');
|
|
648
|
+
}
|
|
649
|
+
});
|
|
650
|
+
}
|
|
651
|
+
export async function handleListWorkspaceSendAs(params) {
|
|
652
|
+
await initializeServices();
|
|
653
|
+
const email = await resolveEmail(params);
|
|
654
|
+
return accountManager.withTokenRenewal(email, async () => {
|
|
655
|
+
try {
|
|
656
|
+
const result = await gmailService.listSendAs({ email });
|
|
657
|
+
return wrapUntrustedJsonStrings(result, 'google-workspace:gmail:send-as');
|
|
658
|
+
}
|
|
659
|
+
catch (error) {
|
|
660
|
+
throw toMcpError(error, 'Failed to list send-as aliases');
|
|
532
661
|
}
|
|
533
662
|
});
|
|
534
663
|
}
|
|
@@ -554,6 +683,9 @@ export async function handleManageWorkspaceDraft(params) {
|
|
|
554
683
|
if (!data) {
|
|
555
684
|
throw new McpError(ErrorCode.InvalidParams, 'Draft data is required for create action');
|
|
556
685
|
}
|
|
686
|
+
assertRecipientsArray(data.to, 'to');
|
|
687
|
+
assertRecipientsArray(data.cc, 'cc');
|
|
688
|
+
assertRecipientsArray(data.bcc, 'bcc');
|
|
557
689
|
if (data.to)
|
|
558
690
|
data.to.forEach(validateEmail);
|
|
559
691
|
if (data.cc)
|
|
@@ -585,6 +717,9 @@ export async function handleManageWorkspaceDraft(params) {
|
|
|
585
717
|
if (!draftId || !data) {
|
|
586
718
|
throw new McpError(ErrorCode.InvalidParams, 'Draft ID and data are required for update action');
|
|
587
719
|
}
|
|
720
|
+
assertRecipientsArray(data.to, 'to');
|
|
721
|
+
assertRecipientsArray(data.cc, 'cc');
|
|
722
|
+
assertRecipientsArray(data.bcc, 'bcc');
|
|
588
723
|
if (data.to)
|
|
589
724
|
data.to.forEach(validateEmail);
|
|
590
725
|
if (data.cc)
|
|
@@ -629,7 +764,7 @@ export async function handleManageWorkspaceDraft(params) {
|
|
|
629
764
|
}
|
|
630
765
|
}
|
|
631
766
|
catch (error) {
|
|
632
|
-
throw
|
|
767
|
+
throw toMcpError(error, 'Failed to manage draft');
|
|
633
768
|
}
|
|
634
769
|
});
|
|
635
770
|
}
|
|
@@ -660,7 +795,7 @@ export async function handleManageWorkspaceLabel(params) {
|
|
|
660
795
|
});
|
|
661
796
|
}
|
|
662
797
|
catch (error) {
|
|
663
|
-
throw
|
|
798
|
+
throw toMcpError(error, 'Failed to manage label');
|
|
664
799
|
}
|
|
665
800
|
});
|
|
666
801
|
}
|
|
@@ -687,7 +822,7 @@ export async function handleManageWorkspaceLabelAssignment(params) {
|
|
|
687
822
|
};
|
|
688
823
|
}
|
|
689
824
|
catch (error) {
|
|
690
|
-
throw
|
|
825
|
+
throw toMcpError(error, 'Failed to manage label assignment');
|
|
691
826
|
}
|
|
692
827
|
});
|
|
693
828
|
}
|
|
@@ -783,10 +918,7 @@ export async function handleManageWorkspaceAttachment(params) {
|
|
|
783
918
|
}
|
|
784
919
|
}
|
|
785
920
|
catch (error) {
|
|
786
|
-
|
|
787
|
-
throw error;
|
|
788
|
-
}
|
|
789
|
-
throw new McpError(ErrorCode.InternalError, `Failed to manage attachment: ${error instanceof Error ? error.message : 'Unknown error'}`);
|
|
921
|
+
throw toMcpError(error, 'Failed to manage attachment');
|
|
790
922
|
}
|
|
791
923
|
});
|
|
792
924
|
}
|
|
@@ -811,7 +943,7 @@ export async function handleManageWorkspaceLabelFilter(params) {
|
|
|
811
943
|
});
|
|
812
944
|
}
|
|
813
945
|
catch (error) {
|
|
814
|
-
throw
|
|
946
|
+
throw toMcpError(error, 'Failed to manage label filter');
|
|
815
947
|
}
|
|
816
948
|
});
|
|
817
949
|
}
|
|
@@ -956,7 +1088,7 @@ export async function handleArchiveWorkspaceEmail(params) {
|
|
|
956
1088
|
: `${ids.length} messages archived successfully.`;
|
|
957
1089
|
}
|
|
958
1090
|
catch (error) {
|
|
959
|
-
throw
|
|
1091
|
+
throw toMcpError(error, 'Failed to archive email');
|
|
960
1092
|
}
|
|
961
1093
|
});
|
|
962
1094
|
}
|
|
@@ -974,7 +1106,7 @@ export async function handleTrashWorkspaceEmail(params) {
|
|
|
974
1106
|
: `${ids.length} messages moved to trash.`;
|
|
975
1107
|
}
|
|
976
1108
|
catch (error) {
|
|
977
|
-
throw
|
|
1109
|
+
throw toMcpError(error, 'Failed to trash email');
|
|
978
1110
|
}
|
|
979
1111
|
});
|
|
980
1112
|
}
|
|
@@ -992,7 +1124,7 @@ export async function handleUntrashWorkspaceEmail(params) {
|
|
|
992
1124
|
: `${ids.length} messages restored from trash.`;
|
|
993
1125
|
}
|
|
994
1126
|
catch (error) {
|
|
995
|
-
throw
|
|
1127
|
+
throw toMcpError(error, 'Failed to untrash email');
|
|
996
1128
|
}
|
|
997
1129
|
});
|
|
998
1130
|
}
|
|
@@ -1015,7 +1147,7 @@ export async function handleMarkWorkspaceEmailRead(params) {
|
|
|
1015
1147
|
: `${ids.length} messages marked as read.`;
|
|
1016
1148
|
}
|
|
1017
1149
|
catch (error) {
|
|
1018
|
-
throw
|
|
1150
|
+
throw toMcpError(error, 'Failed to mark email as read');
|
|
1019
1151
|
}
|
|
1020
1152
|
});
|
|
1021
1153
|
}
|
|
@@ -1038,7 +1170,7 @@ export async function handleMarkWorkspaceEmailUnread(params) {
|
|
|
1038
1170
|
: `${ids.length} messages marked as unread.`;
|
|
1039
1171
|
}
|
|
1040
1172
|
catch (error) {
|
|
1041
|
-
throw
|
|
1173
|
+
throw toMcpError(error, 'Failed to mark email as unread');
|
|
1042
1174
|
}
|
|
1043
1175
|
});
|
|
1044
1176
|
}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { ListConferenceRecordsResponse, ListTranscriptsResponse, ListTranscriptEntriesResponse } from "../modules/meet/types.js";
|
|
2
|
+
interface ListMeetConferenceRecordsHandlerParams {
|
|
3
|
+
email?: string;
|
|
4
|
+
page_size?: number;
|
|
5
|
+
pageSize?: number;
|
|
6
|
+
page_token?: string;
|
|
7
|
+
pageToken?: string;
|
|
8
|
+
filter?: string;
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* Handler function for listing Google Meet conference records.
|
|
12
|
+
*/
|
|
13
|
+
export declare function handleListMeetConferenceRecords(params: ListMeetConferenceRecordsHandlerParams & Record<string, unknown>): Promise<ListConferenceRecordsResponse>;
|
|
14
|
+
interface ListMeetTranscriptsHandlerParams {
|
|
15
|
+
email?: string;
|
|
16
|
+
conference_record?: string;
|
|
17
|
+
conferenceRecord?: string;
|
|
18
|
+
page_size?: number;
|
|
19
|
+
pageSize?: number;
|
|
20
|
+
page_token?: string;
|
|
21
|
+
pageToken?: string;
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Handler function for listing the transcripts of a Google Meet conference record.
|
|
25
|
+
*/
|
|
26
|
+
export declare function handleListMeetTranscripts(params: ListMeetTranscriptsHandlerParams & Record<string, unknown>): Promise<ListTranscriptsResponse>;
|
|
27
|
+
interface GetMeetTranscriptEntriesHandlerParams {
|
|
28
|
+
email?: string;
|
|
29
|
+
conference_record?: string;
|
|
30
|
+
conferenceRecord?: string;
|
|
31
|
+
transcript?: string;
|
|
32
|
+
page_size?: number;
|
|
33
|
+
pageSize?: number;
|
|
34
|
+
page_token?: string;
|
|
35
|
+
pageToken?: string;
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Handler function for listing the entries (speaker + text) of one Google Meet transcript.
|
|
39
|
+
*/
|
|
40
|
+
export declare function handleGetMeetTranscriptEntries(params: GetMeetTranscriptEntriesHandlerParams & Record<string, unknown>): Promise<ListTranscriptEntriesResponse>;
|
|
41
|
+
export {};
|
|
42
|
+
//# sourceMappingURL=meet-handlers.d.ts.map
|