@mindstone/mcp-server-google-workspace 0.5.2 → 0.5.4
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 +27 -1
- package/dist/file-read-context.d.ts +57 -0
- package/dist/file-read-context.js +36 -0
- package/dist/modules/calendar/service.js +97 -90
- package/dist/modules/comments/service.js +6 -6
- package/dist/modules/docs/service.js +15 -11
- package/dist/modules/docs/types.d.ts +4 -0
- package/dist/modules/drive/service.js +1 -17
- package/dist/modules/forms/service.js +4 -4
- package/dist/modules/gmail/services/attachment.js +3 -1
- package/dist/modules/gmail/services/base.js +3 -1
- package/dist/modules/gmail/services/draft.js +13 -1
- package/dist/modules/gmail/services/email.js +13 -4
- package/dist/modules/gmail/services/label.js +19 -1
- package/dist/modules/gmail/services/settings.js +7 -1
- package/dist/modules/sheets/service.js +18 -18
- package/dist/modules/slides/service.js +7 -7
- package/dist/modules/tasks/service.js +7 -7
- package/dist/resources/compose-email-template.d.ts +1 -1
- package/dist/resources/compose-email-template.js +107 -53
- package/dist/services/base/BaseGoogleService.js +2 -2
- package/dist/services/chat/index.js +3 -0
- package/dist/services/contacts/index.js +8 -5
- package/dist/services/meet/index.js +3 -0
- package/dist/tools/calendar-handlers.js +7 -7
- package/dist/tools/chat-handlers.js +4 -4
- package/dist/tools/contacts-handlers.js +5 -5
- package/dist/tools/definitions/gmail.js +4 -0
- package/dist/tools/docs-handlers.js +14 -6
- package/dist/tools/drive-handlers.d.ts +2 -1
- package/dist/tools/drive-handlers.js +21 -16
- package/dist/tools/gmail-handlers.d.ts +6 -5
- package/dist/tools/gmail-handlers.js +39 -27
- package/dist/tools/meet-handlers.js +4 -4
- package/dist/tools/server.js +24 -10
- package/dist/tools/sheets-handlers.js +4 -4
- package/dist/tools/slides-handlers.js +4 -4
- package/dist/utils/apiError.d.ts +7 -3
- package/dist/utils/apiError.js +37 -16
- package/dist/utils/google-retry.d.ts +15 -0
- package/dist/utils/google-retry.js +108 -0
- package/dist/utils/request-timeout.js +2 -0
- package/dist/utils/untrusted-content.d.ts +9 -0
- package/dist/utils/untrusted-content.js +37 -0
- package/package.json +3 -2
|
@@ -5,7 +5,8 @@ import { getDriveService } from '../modules/drive/index.js';
|
|
|
5
5
|
import { idFromUri } from '../modules/docs/tabCopy.js';
|
|
6
6
|
import { extractDocumentIdFromUrl } from '../modules/docs/formatters.js';
|
|
7
7
|
import { readAliasedBoolean, readAliasedNumber, readAliasedString, readAliasedValue } from './arg-aliases.js';
|
|
8
|
-
import { wrapUntrustedContent,
|
|
8
|
+
import { wrapUntrustedContent, wrapUntrustedJsonControls } from '../utils/untrusted-content.js';
|
|
9
|
+
import { preserveGoogleRetryDecision } from '../utils/google-retry.js';
|
|
9
10
|
/**
|
|
10
11
|
* Format DocumentResponse as human-readable text
|
|
11
12
|
*/
|
|
@@ -103,7 +104,10 @@ export async function handleReadDocument(args) {
|
|
|
103
104
|
throw new McpError(ErrorCode.InternalError, result.error || 'Failed to read document');
|
|
104
105
|
}
|
|
105
106
|
if (returnJson) {
|
|
106
|
-
return
|
|
107
|
+
return wrapUntrustedJsonControls(result.data, `google-workspace:docs:document/${documentId}`, [
|
|
108
|
+
'documentId', 'revisionId', 'tabs.*.tabId', 'tabs.*.parentTabId', 'shownTab.tabId', 'requestedTab.tabId',
|
|
109
|
+
'tab.tabProperties.tabId', 'tab.tabProperties.parentTabId', 'childTabs.*.tabId',
|
|
110
|
+
]);
|
|
107
111
|
}
|
|
108
112
|
// Format as human-readable text
|
|
109
113
|
const docResponse = result.data;
|
|
@@ -255,12 +259,12 @@ export async function handleListDocumentTabs(args) {
|
|
|
255
259
|
}
|
|
256
260
|
const tabList = result.data;
|
|
257
261
|
if (returnJson) {
|
|
258
|
-
return
|
|
262
|
+
return wrapUntrustedJsonControls({
|
|
259
263
|
documentId: tabList.documentId,
|
|
260
264
|
title: tabList.title,
|
|
261
265
|
tabCount: tabList.tabs.length,
|
|
262
266
|
tabs: tabList.tabs,
|
|
263
|
-
}, `google-workspace:docs:tabs/${tabList.documentId}
|
|
267
|
+
}, `google-workspace:docs:tabs/${tabList.documentId}`, ['documentId', 'tabs.*.tabId', 'tabs.*.parentTabId']);
|
|
264
268
|
}
|
|
265
269
|
return formatTabsAsText(tabList);
|
|
266
270
|
});
|
|
@@ -293,7 +297,7 @@ export async function handleBatchUpdateDocument(args) {
|
|
|
293
297
|
throw new McpError(ErrorCode.InternalError, result.error || 'Failed to update document');
|
|
294
298
|
}
|
|
295
299
|
if (returnJson) {
|
|
296
|
-
return
|
|
300
|
+
return wrapUntrustedJsonControls(result.data, `google-workspace:docs:batch-update/${documentId}`, ['documentId']);
|
|
297
301
|
}
|
|
298
302
|
// Format as human-readable text
|
|
299
303
|
const response = result.data;
|
|
@@ -617,7 +621,11 @@ export async function handleCopyDocumentTab(args) {
|
|
|
617
621
|
...(newTabPosition !== undefined ? { newTabPosition } : {}),
|
|
618
622
|
}, checkChip);
|
|
619
623
|
if (!result.success || !result.data) {
|
|
620
|
-
|
|
624
|
+
const failure = new McpError(ErrorCode.InternalError, result.error || 'Failed to copy document tab');
|
|
625
|
+
Object.assign(failure, { cause: result.cause });
|
|
626
|
+
if (result.status !== undefined)
|
|
627
|
+
Object.assign(failure, { status: result.status });
|
|
628
|
+
throw preserveGoogleRetryDecision(failure, result);
|
|
621
629
|
}
|
|
622
630
|
const data = result.data;
|
|
623
631
|
const text = formatTabCopyAsText(data);
|
|
@@ -2,9 +2,10 @@ import { FileListOptions, FileSearchOptions, FileUploadOptions, PermissionOption
|
|
|
2
2
|
import { McpToolResponse } from './types.js';
|
|
3
3
|
/** @internal Exported for tests. */
|
|
4
4
|
export declare function formatDriveRecoveryError(operation: string, error: unknown): {
|
|
5
|
-
ok: boolean;
|
|
6
5
|
action_required: string;
|
|
7
6
|
next_step: string;
|
|
7
|
+
recoveryExhausted?: boolean | undefined;
|
|
8
|
+
ok: boolean;
|
|
8
9
|
};
|
|
9
10
|
interface DriveFileListArgs {
|
|
10
11
|
email?: string;
|
|
@@ -2,9 +2,10 @@ import { McpError, ErrorCode } from '@modelcontextprotocol/sdk/types.js';
|
|
|
2
2
|
import { getAccountManager, resolveEmail } from '../modules/accounts/index.js';
|
|
3
3
|
import { getDriveService, getDriveActivityService } from '../modules/drive/index.js';
|
|
4
4
|
import { normalizeDriveItemName } from '../modules/drive/activity-service.js';
|
|
5
|
-
import {
|
|
5
|
+
import { GOOGLE_RATE_LIMIT_NEXT_STEP, isGoogleRecoveryExhausted, isShortWindowRateLimit } from '../utils/google-retry.js';
|
|
6
|
+
import { extractHttpStatus, toMcpError } from '../utils/apiError.js';
|
|
6
7
|
import { readAliasedBoolean, readAliasedNumber, readAliasedString } from './arg-aliases.js';
|
|
7
|
-
import { wrapUntrustedContent, wrapUntrustedJsonStrings } from '../utils/untrusted-content.js';
|
|
8
|
+
import { wrapUntrustedContent, wrapUntrustedJsonStrings, wrapUntrustedJsonControls } from '../utils/untrusted-content.js';
|
|
8
9
|
const HOST_TIMEZONE = Intl.DateTimeFormat().resolvedOptions().timeZone;
|
|
9
10
|
/**
|
|
10
11
|
* Get human-readable label for MIME type
|
|
@@ -79,20 +80,22 @@ function formatSharedDrivesAsText(drives) {
|
|
|
79
80
|
}
|
|
80
81
|
/** @internal Exported for tests. */
|
|
81
82
|
export function formatDriveRecoveryError(operation, error) {
|
|
82
|
-
const status = error
|
|
83
|
-
|
|
84
|
-
?? error.code
|
|
85
|
-
: undefined;
|
|
86
|
-
const statusText = status ? ` (${status})` : '';
|
|
83
|
+
const status = extractHttpStatus(error);
|
|
84
|
+
const statusText = status === undefined ? '' : ` (${status})`;
|
|
87
85
|
const message = error instanceof Error
|
|
88
86
|
? error.message
|
|
89
87
|
: error && typeof error === 'object' && typeof error.message === 'string'
|
|
90
88
|
? error.message
|
|
91
89
|
: 'Unknown error';
|
|
90
|
+
const recoveryExhausted = isGoogleRecoveryExhausted(error);
|
|
91
|
+
const rateLimited = status === 429 || isShortWindowRateLimit(error);
|
|
92
92
|
return {
|
|
93
93
|
ok: false,
|
|
94
|
+
...(recoveryExhausted ? { recoveryExhausted: true } : {}),
|
|
94
95
|
action_required: `Drive ${operation} failed${statusText}`,
|
|
95
|
-
next_step:
|
|
96
|
+
next_step: recoveryExhausted || rateLimited
|
|
97
|
+
? GOOGLE_RATE_LIMIT_NEXT_STEP
|
|
98
|
+
: `${message}. Check Google Workspace authentication and Drive permissions, then retry.`,
|
|
96
99
|
};
|
|
97
100
|
}
|
|
98
101
|
function formatDriveToolResponse(operation, error) {
|
|
@@ -107,7 +110,9 @@ function formatDriveJsonResult(operation, result, source) {
|
|
|
107
110
|
if (result.success === false) {
|
|
108
111
|
return formatDriveRecoveryError(operation, new Error(result.error || 'Unknown error'));
|
|
109
112
|
}
|
|
110
|
-
return
|
|
113
|
+
return wrapUntrustedJsonControls(result, source, [
|
|
114
|
+
'data.nextPageToken', 'data.files.*.id', 'data.drives.*.id',
|
|
115
|
+
]);
|
|
111
116
|
}
|
|
112
117
|
export async function handleListDriveFiles(args) {
|
|
113
118
|
const accountManager = getAccountManager();
|
|
@@ -247,7 +252,7 @@ export async function handleUploadDriveFile(args) {
|
|
|
247
252
|
return {
|
|
248
253
|
content: [{
|
|
249
254
|
type: 'text',
|
|
250
|
-
text: JSON.stringify(
|
|
255
|
+
text: JSON.stringify(wrapUntrustedJsonControls(result, 'google-workspace:drive:file-upload', ['data.id', 'data.parents.*']), null, 2)
|
|
251
256
|
}]
|
|
252
257
|
};
|
|
253
258
|
}
|
|
@@ -301,7 +306,7 @@ export async function handleCreateDriveFolder(args) {
|
|
|
301
306
|
return {
|
|
302
307
|
content: [{
|
|
303
308
|
type: 'text',
|
|
304
|
-
text: JSON.stringify(
|
|
309
|
+
text: JSON.stringify(wrapUntrustedJsonControls(result, 'google-workspace:drive:folder/create', ['data.id', 'data.parents.*']), null, 2)
|
|
305
310
|
}]
|
|
306
311
|
};
|
|
307
312
|
}
|
|
@@ -394,7 +399,7 @@ export async function handleCopyDriveFile(args) {
|
|
|
394
399
|
return {
|
|
395
400
|
content: [{
|
|
396
401
|
type: 'text',
|
|
397
|
-
text: JSON.stringify(
|
|
402
|
+
text: JSON.stringify(wrapUntrustedJsonControls(result, `google-workspace:drive:file/${fileId}/copy`, ['data.id', 'data.parents.*']), null, 2)
|
|
398
403
|
}]
|
|
399
404
|
};
|
|
400
405
|
}
|
|
@@ -430,7 +435,7 @@ export async function handleMoveDriveFile(args) {
|
|
|
430
435
|
return {
|
|
431
436
|
content: [{
|
|
432
437
|
type: 'text',
|
|
433
|
-
text: JSON.stringify(
|
|
438
|
+
text: JSON.stringify(wrapUntrustedJsonControls(result, `google-workspace:drive:file/${fileId}/move`, ['data.id', 'data.parents.*']), null, 2)
|
|
434
439
|
}]
|
|
435
440
|
};
|
|
436
441
|
}
|
|
@@ -457,7 +462,7 @@ export async function handleTrashDriveFile(args) {
|
|
|
457
462
|
return {
|
|
458
463
|
content: [{
|
|
459
464
|
type: 'text',
|
|
460
|
-
text: JSON.stringify(
|
|
465
|
+
text: JSON.stringify(wrapUntrustedJsonControls(result, `google-workspace:drive:file/${fileId}/trash`, ['data.id', 'data.parents.*']), null, 2)
|
|
461
466
|
}]
|
|
462
467
|
};
|
|
463
468
|
}
|
|
@@ -484,7 +489,7 @@ export async function handleUntrashDriveFile(args) {
|
|
|
484
489
|
return {
|
|
485
490
|
content: [{
|
|
486
491
|
type: 'text',
|
|
487
|
-
text: JSON.stringify(
|
|
492
|
+
text: JSON.stringify(wrapUntrustedJsonControls(result, `google-workspace:drive:file/${fileId}/untrash`, ['data.id', 'data.parents.*']), null, 2)
|
|
488
493
|
}]
|
|
489
494
|
};
|
|
490
495
|
}
|
|
@@ -511,7 +516,7 @@ export async function handleListFileRevisions(args) {
|
|
|
511
516
|
return {
|
|
512
517
|
content: [{
|
|
513
518
|
type: 'text',
|
|
514
|
-
text: JSON.stringify(
|
|
519
|
+
text: JSON.stringify(wrapUntrustedJsonControls(result, `google-workspace:drive:file/${fileId}/revisions`, ['data.nextPageToken', 'data.revisions.*.id']), null, 2)
|
|
515
520
|
}]
|
|
516
521
|
};
|
|
517
522
|
}
|
|
@@ -1,9 +1,10 @@
|
|
|
1
|
+
import { type FileReadContext } from '../file-read-context.js';
|
|
1
2
|
import { ManageLabelParams, ManageLabelAssignmentParams, ManageLabelFilterParams } from '../modules/gmail/services/label.js';
|
|
2
3
|
import { McpToolResponse } from './types.js';
|
|
3
4
|
import { OutgoingGmailAttachment } from '../modules/gmail/types.js';
|
|
4
5
|
import { ManageAttachmentParams } from './types.js';
|
|
5
6
|
/** @internal Exported for tests. */
|
|
6
|
-
export declare function resolveAttachmentFromPath(filePath: string): {
|
|
7
|
+
export declare function resolveAttachmentFromPath(filePath: string, context?: FileReadContext, location?: (string | number)[]): {
|
|
7
8
|
content: string;
|
|
8
9
|
name: string;
|
|
9
10
|
mimeType: string;
|
|
@@ -211,7 +212,7 @@ export declare function handleGetWorkspaceEmailThread(params: GetThreadParams):
|
|
|
211
212
|
}>;
|
|
212
213
|
}>;
|
|
213
214
|
}>;
|
|
214
|
-
export declare function handleSendWorkspaceEmail(params: SendEmailRequestParams & Record<string, unknown
|
|
215
|
+
export declare function handleSendWorkspaceEmail(params: SendEmailRequestParams & Record<string, unknown>, context?: FileReadContext): Promise<{
|
|
215
216
|
content: {
|
|
216
217
|
type: "text";
|
|
217
218
|
text: string;
|
|
@@ -245,7 +246,7 @@ export declare function handleListWorkspaceSendAs(params: {
|
|
|
245
246
|
}): Promise<{
|
|
246
247
|
sendAs: import("../modules/gmail/types.js").SendAsAlias[];
|
|
247
248
|
}>;
|
|
248
|
-
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>;
|
|
249
|
+
export declare function handleManageWorkspaceDraft(params: ManageDraftParams, context?: FileReadContext, attachmentLocation?: (string | number)[]): Promise<void | import("../modules/gmail/types.js").DraftResponse | import("../modules/gmail/types.js").GetDraftsResponse | import("../modules/gmail/types.js").SendEmailResponse>;
|
|
249
250
|
export declare function handleManageWorkspaceLabel(params: ManageLabelParams): Promise<void | import("../modules/gmail/types.js").Label | import("../modules/gmail/types.js").GetLabelsResponse>;
|
|
250
251
|
export declare function handleManageWorkspaceLabelAssignment(params: ManageLabelAssignmentParams): Promise<{
|
|
251
252
|
content: {
|
|
@@ -265,8 +266,8 @@ export declare function handleGetWorkspaceDraft(params: {
|
|
|
265
266
|
email?: string;
|
|
266
267
|
draftId: string;
|
|
267
268
|
}): Promise<void | import("../modules/gmail/types.js").DraftResponse | import("../modules/gmail/types.js").GetDraftsResponse | import("../modules/gmail/types.js").SendEmailResponse>;
|
|
268
|
-
export declare function handleCreateWorkspaceDraft(params: Record<string, unknown
|
|
269
|
-
export declare function handleUpdateWorkspaceDraft(params: Record<string, unknown
|
|
269
|
+
export declare function handleCreateWorkspaceDraft(params: Record<string, unknown>, context?: FileReadContext): Promise<void | import("../modules/gmail/types.js").DraftResponse | import("../modules/gmail/types.js").GetDraftsResponse | import("../modules/gmail/types.js").SendEmailResponse>;
|
|
270
|
+
export declare function handleUpdateWorkspaceDraft(params: Record<string, unknown>, context?: FileReadContext): Promise<void | import("../modules/gmail/types.js").DraftResponse | import("../modules/gmail/types.js").GetDraftsResponse | import("../modules/gmail/types.js").SendEmailResponse>;
|
|
270
271
|
export declare function handleDeleteWorkspaceDraft(params: {
|
|
271
272
|
email?: string;
|
|
272
273
|
draft_id?: string;
|
|
@@ -1,12 +1,13 @@
|
|
|
1
|
+
import { centralReadPath } from '../file-read-context.js';
|
|
1
2
|
import { getGmailService } from '../modules/gmail/index.js';
|
|
2
3
|
import { getAccountManager, validateEmail, resolveEmail } from '../modules/accounts/index.js';
|
|
3
4
|
import { McpError, ErrorCode } from '@modelcontextprotocol/sdk/types.js';
|
|
4
|
-
import { toMcpError } from '../utils/apiError.js';
|
|
5
|
+
import { isPassthroughGoogleError, toMcpError } from '../utils/apiError.js';
|
|
5
6
|
import { AttachmentService } from '../modules/attachments/service.js';
|
|
6
7
|
import { ATTACHMENT_FOLDERS } from '../modules/attachments/types.js';
|
|
7
8
|
import { closeSync, constants, fstatSync, lstatSync, openSync, readFileSync, realpathSync, statSync } from 'fs';
|
|
8
9
|
import path from 'path';
|
|
9
|
-
import { wrapUntrustedContent, wrapUntrustedJsonStrings } from '../utils/untrusted-content.js';
|
|
10
|
+
import { wrapUntrustedContent, wrapUntrustedJsonStrings, wrapUntrustedJsonControls } from '../utils/untrusted-content.js';
|
|
10
11
|
import logger from '../utils/logger.js';
|
|
11
12
|
// Singleton instances
|
|
12
13
|
let gmailService;
|
|
@@ -77,6 +78,8 @@ async function resolveReplyThreading(email, replyToMessageId) {
|
|
|
77
78
|
return { headers: result };
|
|
78
79
|
}
|
|
79
80
|
catch (error) {
|
|
81
|
+
if (isPassthroughGoogleError(error))
|
|
82
|
+
throw error;
|
|
80
83
|
logger.warn(`[gmail-handlers] Reply threading degraded: failed to fetch original message ${replyToMessageId} for account ${email}:`, error instanceof Error ? error.message : error);
|
|
81
84
|
return { headers: {}, degradedReason: unthreadedReplyReason(replyToMessageId) };
|
|
82
85
|
}
|
|
@@ -116,16 +119,22 @@ function getAttachmentWorkspaceRoot() {
|
|
|
116
119
|
return realpathSync.native(rootPath);
|
|
117
120
|
}
|
|
118
121
|
/** @internal Exported for tests. */
|
|
119
|
-
export function resolveAttachmentFromPath(filePath) {
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
122
|
+
export function resolveAttachmentFromPath(filePath, context, location = []) {
|
|
123
|
+
let candidateRealpath = centralReadPath(context, filePath, location);
|
|
124
|
+
if (candidateRealpath === undefined) {
|
|
125
|
+
const rootRealpath = getAttachmentWorkspaceRoot();
|
|
126
|
+
const candidatePath = path.resolve(filePath);
|
|
127
|
+
const candidateStats = lstatSync(candidatePath);
|
|
128
|
+
if (candidateStats.isSymbolicLink()) {
|
|
129
|
+
throw new McpError(ErrorCode.InvalidParams, 'Attachment path must not be a symbolic link.');
|
|
130
|
+
}
|
|
131
|
+
candidateRealpath = realpathSync.native(candidatePath);
|
|
132
|
+
if (!isPathInsideDirectory(candidateRealpath, rootRealpath)) {
|
|
133
|
+
throw new McpError(ErrorCode.InvalidParams, `Attachment path must be within the workspace directory. Got: ${filePath}`);
|
|
134
|
+
}
|
|
125
135
|
}
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
throw new McpError(ErrorCode.InvalidParams, `Attachment path must be within the workspace directory. Got: ${filePath}`);
|
|
136
|
+
if (context?.mode === 'central' && realpathSync(candidateRealpath) !== candidateRealpath) {
|
|
137
|
+
throw new McpError(ErrorCode.InvalidParams, 'Attachment file changed while it was being verified; refusing to read it.');
|
|
129
138
|
}
|
|
130
139
|
// Pin the identity (device + inode) of the object that passed containment.
|
|
131
140
|
// O_NOFOLLOW only refuses a symlink in the FINAL path component — an
|
|
@@ -167,10 +176,10 @@ export function resolveAttachmentFromPath(filePath) {
|
|
|
167
176
|
closeSync(fd);
|
|
168
177
|
}
|
|
169
178
|
}
|
|
170
|
-
function processOutgoingAttachments(attachments) {
|
|
171
|
-
return attachments?.map(attachment => {
|
|
179
|
+
function processOutgoingAttachments(attachments, context, prefix = ['attachments']) {
|
|
180
|
+
return attachments?.map((attachment, index) => {
|
|
172
181
|
if (attachment.path && !attachment.content) {
|
|
173
|
-
const resolved = resolveAttachmentFromPath(attachment.path);
|
|
182
|
+
const resolved = resolveAttachmentFromPath(attachment.path, context, [...prefix, index, 'path']);
|
|
174
183
|
return {
|
|
175
184
|
id: attachment.id || resolved.name,
|
|
176
185
|
name: attachment.name || resolved.name,
|
|
@@ -407,7 +416,10 @@ export async function handleSearchWorkspaceEmails(params) {
|
|
|
407
416
|
const result = await gmailService.getEmails({ email, search: normalizedSearch, options, messageIds });
|
|
408
417
|
// Return formatted text by default, JSON only when explicitly requested
|
|
409
418
|
if (returnJson) {
|
|
410
|
-
return
|
|
419
|
+
return wrapUntrustedJsonControls(result, 'google-workspace:gmail:search', [
|
|
420
|
+
'nextPageToken', 'emails.*.id', 'emails.*.threadId', 'emails.*.attachments.*.id',
|
|
421
|
+
'threads.{}.messages.*',
|
|
422
|
+
]);
|
|
411
423
|
}
|
|
412
424
|
return formatEmailsAsText(result);
|
|
413
425
|
}
|
|
@@ -507,13 +519,13 @@ export async function handleGetWorkspaceEmailThread(params) {
|
|
|
507
519
|
// Snippet field is preserved so callers can still see what was elided.
|
|
508
520
|
if (includeBody && !includeFullBodies && result.messages.length > DEFAULT_FULL_BODY_TAIL) {
|
|
509
521
|
const tailStart = result.messages.length - DEFAULT_FULL_BODY_TAIL;
|
|
510
|
-
return
|
|
522
|
+
return wrapUntrustedJsonControls({
|
|
511
523
|
...result,
|
|
512
524
|
bodies_abbreviated: tailStart,
|
|
513
525
|
messages: result.messages.map((m, i) => i < tailStart ? { ...m, body: undefined } : m),
|
|
514
|
-
}, `google-workspace:gmail:thread/${threadId}
|
|
526
|
+
}, `google-workspace:gmail:thread/${threadId}`, ['threadId', 'messages.*.id', 'messages.*.attachments.*.id']);
|
|
515
527
|
}
|
|
516
|
-
return
|
|
528
|
+
return wrapUntrustedJsonControls(result, `google-workspace:gmail:thread/${threadId}`, ['threadId', 'messages.*.id', 'messages.*.attachments.*.id']);
|
|
517
529
|
}
|
|
518
530
|
return formatThreadAsText(result, offset, includeFullBodies);
|
|
519
531
|
}
|
|
@@ -522,7 +534,7 @@ export async function handleGetWorkspaceEmailThread(params) {
|
|
|
522
534
|
}
|
|
523
535
|
});
|
|
524
536
|
}
|
|
525
|
-
export async function handleSendWorkspaceEmail(params) {
|
|
537
|
+
export async function handleSendWorkspaceEmail(params, context) {
|
|
526
538
|
await initializeServices();
|
|
527
539
|
const { to, subject, body, cc, bcc, attachments } = params;
|
|
528
540
|
const rawParams = params;
|
|
@@ -588,7 +600,7 @@ export async function handleSendWorkspaceEmail(params) {
|
|
|
588
600
|
threadId: threadingResolution.headers.threadId,
|
|
589
601
|
inReplyTo: threadingResolution.headers.inReplyTo,
|
|
590
602
|
references: threadingResolution.headers.references,
|
|
591
|
-
attachments: processOutgoingAttachments(attachments)
|
|
603
|
+
attachments: processOutgoingAttachments(attachments, context)
|
|
592
604
|
};
|
|
593
605
|
const sendResult = await gmailService.sendEmail(emailParams);
|
|
594
606
|
// Degraded reply threading is observable in the result (additive
|
|
@@ -701,7 +713,7 @@ export async function handleListWorkspaceSendAs(params) {
|
|
|
701
713
|
}
|
|
702
714
|
});
|
|
703
715
|
}
|
|
704
|
-
export async function handleManageWorkspaceDraft(params) {
|
|
716
|
+
export async function handleManageWorkspaceDraft(params, context, attachmentLocation = ['data', 'attachments']) {
|
|
705
717
|
await initializeServices();
|
|
706
718
|
const rawParams = params;
|
|
707
719
|
const action = params.action;
|
|
@@ -745,7 +757,7 @@ export async function handleManageWorkspaceDraft(params) {
|
|
|
745
757
|
threadId: data.threadId ?? threading.threadId,
|
|
746
758
|
inReplyTo: data.inReplyTo ?? threading.inReplyTo,
|
|
747
759
|
references: data.references ?? threading.references,
|
|
748
|
-
attachments: processOutgoingAttachments(data.attachments)
|
|
760
|
+
attachments: processOutgoingAttachments(data.attachments, context, attachmentLocation)
|
|
749
761
|
}
|
|
750
762
|
});
|
|
751
763
|
}
|
|
@@ -779,7 +791,7 @@ export async function handleManageWorkspaceDraft(params) {
|
|
|
779
791
|
threadId: data.threadId ?? threading.threadId,
|
|
780
792
|
inReplyTo: data.inReplyTo ?? threading.inReplyTo,
|
|
781
793
|
references: data.references ?? threading.references,
|
|
782
|
-
attachments: processOutgoingAttachments(data.attachments)
|
|
794
|
+
attachments: processOutgoingAttachments(data.attachments, context, attachmentLocation)
|
|
783
795
|
}
|
|
784
796
|
});
|
|
785
797
|
}
|
|
@@ -1001,15 +1013,15 @@ export async function handleListWorkspaceDrafts(params) {
|
|
|
1001
1013
|
export async function handleGetWorkspaceDraft(params) {
|
|
1002
1014
|
return handleManageWorkspaceDraft({ ...params, action: 'read' });
|
|
1003
1015
|
}
|
|
1004
|
-
export async function handleCreateWorkspaceDraft(params) {
|
|
1016
|
+
export async function handleCreateWorkspaceDraft(params, context) {
|
|
1005
1017
|
const { email, ...data } = params;
|
|
1006
|
-
return handleManageWorkspaceDraft({ email: email, action: 'create', data: data });
|
|
1018
|
+
return handleManageWorkspaceDraft({ email: email, action: 'create', data: data }, context, ['attachments']);
|
|
1007
1019
|
}
|
|
1008
|
-
export async function handleUpdateWorkspaceDraft(params) {
|
|
1020
|
+
export async function handleUpdateWorkspaceDraft(params, context) {
|
|
1009
1021
|
const email = params.email;
|
|
1010
1022
|
const draftId = readAliasedString(params, 'draft_id', 'draftId');
|
|
1011
1023
|
const { draft_id: _draftIdSnake, draftId: _draftIdCamel, ...data } = params;
|
|
1012
|
-
return handleManageWorkspaceDraft({ email, action: 'update', draftId, data: data });
|
|
1024
|
+
return handleManageWorkspaceDraft({ email, action: 'update', draftId, data: data }, context, ['attachments']);
|
|
1013
1025
|
}
|
|
1014
1026
|
export async function handleDeleteWorkspaceDraft(params) {
|
|
1015
1027
|
const draftId = readAliasedString(params, 'draft_id', 'draftId');
|
|
@@ -3,7 +3,7 @@ import { McpError, ErrorCode } from "@modelcontextprotocol/sdk/types.js";
|
|
|
3
3
|
import { toMcpError } from "../utils/apiError.js";
|
|
4
4
|
import { getAccountManager, resolveEmail } from "../modules/accounts/index.js";
|
|
5
5
|
import { readAliasedNumber, readAliasedString } from './arg-aliases.js';
|
|
6
|
-
import {
|
|
6
|
+
import { wrapUntrustedJsonControls } from "../utils/untrusted-content.js";
|
|
7
7
|
// Singleton instances - Initialize or inject as per project pattern
|
|
8
8
|
let meetService;
|
|
9
9
|
let accountManager;
|
|
@@ -68,7 +68,7 @@ export async function handleListMeetConferenceRecords(params) {
|
|
|
68
68
|
pageToken,
|
|
69
69
|
filter
|
|
70
70
|
});
|
|
71
|
-
return
|
|
71
|
+
return wrapUntrustedJsonControls(result, 'google-workspace:meet:conference-records', ['nextPageToken', 'conferenceRecords.*.name']);
|
|
72
72
|
}
|
|
73
73
|
catch (error) {
|
|
74
74
|
// toMcpError passes an McpError (and auth-handoff errors) through, and folds a
|
|
@@ -100,7 +100,7 @@ export async function handleListMeetTranscripts(params) {
|
|
|
100
100
|
pageSize: pageSize !== undefined ? Math.min(pageSize, MEET_MAX_PAGE_SIZE) : undefined,
|
|
101
101
|
pageToken
|
|
102
102
|
});
|
|
103
|
-
return
|
|
103
|
+
return wrapUntrustedJsonControls(result, 'google-workspace:meet:transcripts', ['nextPageToken', 'transcripts.*.name', 'transcripts.*.docsDestination.document']);
|
|
104
104
|
}
|
|
105
105
|
catch (error) {
|
|
106
106
|
// See handleListMeetConferenceRecords: toMcpError surfaces the real cause.
|
|
@@ -133,7 +133,7 @@ export async function handleGetMeetTranscriptEntries(params) {
|
|
|
133
133
|
pageSize: pageSize !== undefined ? Math.min(pageSize, MEET_MAX_PAGE_SIZE) : undefined,
|
|
134
134
|
pageToken
|
|
135
135
|
});
|
|
136
|
-
return
|
|
136
|
+
return wrapUntrustedJsonControls(result, 'google-workspace:meet:transcript-entries', ['nextPageToken']);
|
|
137
137
|
}
|
|
138
138
|
catch (error) {
|
|
139
139
|
// See handleListMeetConferenceRecords: toMcpError surfaces the real cause.
|
package/dist/tools/server.js
CHANGED
|
@@ -1,7 +1,10 @@
|
|
|
1
|
+
import { FILE_READ_CAPABILITIES, fileReadContext } from '../file-read-context.js';
|
|
1
2
|
import { createRequire } from 'node:module';
|
|
2
3
|
import { Server } from "@modelcontextprotocol/sdk/server/index.js";
|
|
3
4
|
import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";
|
|
4
5
|
import logger from '../utils/logger.js';
|
|
6
|
+
import { GOOGLE_RATE_LIMIT_NEXT_STEP, isGoogleRecoveryExhausted, isShortWindowRateLimit } from '../utils/google-retry.js';
|
|
7
|
+
import { describeApiErrorUntrusted } from '../utils/apiError.js';
|
|
5
8
|
import { CallToolRequestSchema, ListToolsRequestSchema, ReadResourceRequestSchema, ErrorCode, McpError } from "@modelcontextprotocol/sdk/types.js";
|
|
6
9
|
const require = createRequire(import.meta.url);
|
|
7
10
|
const pkg = require('../../package.json');
|
|
@@ -93,6 +96,7 @@ export class GSuiteServer {
|
|
|
93
96
|
version: SERVER_VERSION
|
|
94
97
|
}, {
|
|
95
98
|
capabilities: {
|
|
99
|
+
...FILE_READ_CAPABILITIES,
|
|
96
100
|
tools: {
|
|
97
101
|
list: true,
|
|
98
102
|
call: true
|
|
@@ -118,6 +122,7 @@ export class GSuiteServer {
|
|
|
118
122
|
name: tool.name,
|
|
119
123
|
description: tool.description,
|
|
120
124
|
inputSchema: tool.inputSchema,
|
|
125
|
+
_meta: tool._meta,
|
|
121
126
|
annotations: tool.annotations
|
|
122
127
|
}));
|
|
123
128
|
}
|
|
@@ -126,6 +131,7 @@ export class GSuiteServer {
|
|
|
126
131
|
name: tool.name,
|
|
127
132
|
description: tool.description,
|
|
128
133
|
inputSchema: tool.inputSchema,
|
|
134
|
+
_meta: tool._meta,
|
|
129
135
|
annotations: tool.annotations
|
|
130
136
|
})),
|
|
131
137
|
_meta: {
|
|
@@ -149,6 +155,7 @@ export class GSuiteServer {
|
|
|
149
155
|
// Handle tool calls
|
|
150
156
|
this.server.setRequestHandler(CallToolRequestSchema, async (request, extra) => {
|
|
151
157
|
try {
|
|
158
|
+
const reads = fileReadContext(this.server.getClientCapabilities(), { _meta: request.params._meta });
|
|
152
159
|
const rawArgs = request.params.arguments;
|
|
153
160
|
const args = rawArgs && typeof rawArgs === 'object' && !Array.isArray(rawArgs)
|
|
154
161
|
? normalizeArgs(rawArgs)
|
|
@@ -190,7 +197,7 @@ export class GSuiteServer {
|
|
|
190
197
|
break;
|
|
191
198
|
case 'send_workspace_email':
|
|
192
199
|
assertSendEmailArgs(args);
|
|
193
|
-
result = await handleSendWorkspaceEmail(args);
|
|
200
|
+
result = await handleSendWorkspaceEmail(args, reads);
|
|
194
201
|
break;
|
|
195
202
|
case 'get_workspace_gmail_settings':
|
|
196
203
|
assertBaseToolArguments(args);
|
|
@@ -236,11 +243,11 @@ export class GSuiteServer {
|
|
|
236
243
|
break;
|
|
237
244
|
case 'create_workspace_draft':
|
|
238
245
|
assertBaseToolArguments(args);
|
|
239
|
-
result = await handleCreateWorkspaceDraft(args);
|
|
246
|
+
result = await handleCreateWorkspaceDraft(args, reads);
|
|
240
247
|
break;
|
|
241
248
|
case 'update_workspace_draft':
|
|
242
249
|
assertBaseToolArguments(args);
|
|
243
|
-
result = await handleUpdateWorkspaceDraft(args);
|
|
250
|
+
result = await handleUpdateWorkspaceDraft(args, reads);
|
|
244
251
|
break;
|
|
245
252
|
case 'delete_workspace_draft':
|
|
246
253
|
assertBaseToolArguments(args);
|
|
@@ -253,7 +260,7 @@ export class GSuiteServer {
|
|
|
253
260
|
// Draft Management (deprecated)
|
|
254
261
|
case 'manage_workspace_draft':
|
|
255
262
|
assertManageDraftParams(args);
|
|
256
|
-
result = await handleManageWorkspaceDraft(args);
|
|
263
|
+
result = await handleManageWorkspaceDraft(args, reads);
|
|
257
264
|
break;
|
|
258
265
|
// Individual Attachment Operations
|
|
259
266
|
case 'download_workspace_attachment':
|
|
@@ -723,7 +730,10 @@ export class GSuiteServer {
|
|
|
723
730
|
};
|
|
724
731
|
}
|
|
725
732
|
catch (error) {
|
|
726
|
-
const response =
|
|
733
|
+
const response = {
|
|
734
|
+
...this.formatErrorResponse(error),
|
|
735
|
+
...(isGoogleRecoveryExhausted(error) ? { recoveryExhausted: true } : {}),
|
|
736
|
+
};
|
|
727
737
|
return {
|
|
728
738
|
content: [{ type: 'text', text: JSON.stringify(response, null, 2) }],
|
|
729
739
|
isError: true,
|
|
@@ -733,7 +743,7 @@ export class GSuiteServer {
|
|
|
733
743
|
});
|
|
734
744
|
}
|
|
735
745
|
formatErrorResponse(error) {
|
|
736
|
-
const
|
|
746
|
+
const recoveryExhausted = isGoogleRecoveryExhausted(error);
|
|
737
747
|
// Read the string domain-error `code` from ANY domain error, not just AccountError:
|
|
738
748
|
// CalendarError/GmailError/ContactsError all expose a string `code`, and a
|
|
739
749
|
// `getCalendarClient` auth failure surfaces as `CalendarError('AUTH_REQUIRED')`, not an
|
|
@@ -773,18 +783,22 @@ export class GSuiteServer {
|
|
|
773
783
|
setupToolName: 'authenticate_workspace_account'
|
|
774
784
|
};
|
|
775
785
|
}
|
|
776
|
-
|
|
786
|
+
const rateLimited = numericStatus === 429 || recoveryExhausted || isShortWindowRateLimit(error);
|
|
787
|
+
const message = rateLimited
|
|
788
|
+
? describeApiErrorUntrusted(error, 'google-workspace:api-error')
|
|
789
|
+
: error instanceof Error ? error.message : 'Unknown error occurred';
|
|
790
|
+
if (rateLimited) {
|
|
777
791
|
return {
|
|
778
792
|
ok: false,
|
|
779
793
|
action_required: message,
|
|
780
|
-
next_step:
|
|
794
|
+
next_step: GOOGLE_RATE_LIMIT_NEXT_STEP
|
|
781
795
|
};
|
|
782
796
|
}
|
|
783
|
-
if (numericStatus ===
|
|
797
|
+
if (numericStatus === 403) {
|
|
784
798
|
return {
|
|
785
799
|
ok: false,
|
|
786
800
|
action_required: message,
|
|
787
|
-
next_step: 'Google Workspace
|
|
801
|
+
next_step: 'Google Workspace rejected the request due to insufficient permissions or scopes. Reconnect the account with the required scope or ask the file/calendar owner for access, then retry.'
|
|
788
802
|
};
|
|
789
803
|
}
|
|
790
804
|
if (numericStatus !== undefined && numericStatus >= 500 && numericStatus <= 599) {
|
|
@@ -5,7 +5,7 @@ import { ActionableA1Error, normaliseA1Range } from '../modules/sheets/a1Utils.j
|
|
|
5
5
|
import { rewriteSheetsApiError } from '../modules/sheets/errorRewriter.js';
|
|
6
6
|
import { VALUES_TRUNCATION_NOTICE, extractSpreadsheetIdFromUrl, firstSheetRowNumber, formatAnchorReadResponse, formatSpreadsheetAsText, formatOperationResult, formatShapedReadResponse, formatValuesAsTable, formatSheetListResultAsText, formatSheetAddedAsText, formatSheetDuplicatedAsText, formatSheetUpdatedAsText, formatDimensionInsertedAsText, } from '../modules/sheets/formatters.js';
|
|
7
7
|
import { readAliasedBoolean, readAliasedNumber, readAliasedString, readAliasedValue } from './arg-aliases.js';
|
|
8
|
-
import {
|
|
8
|
+
import { wrapUntrustedJsonControls } from '../utils/untrusted-content.js';
|
|
9
9
|
function normaliseRangeOrThrow(range) {
|
|
10
10
|
try {
|
|
11
11
|
return normaliseA1Range(range);
|
|
@@ -88,7 +88,7 @@ export async function handleReadSpreadsheet(args) {
|
|
|
88
88
|
throw new McpError(ErrorCode.InternalError, rewriteSheetsHandlerError(result.error, 'Failed to read spreadsheet', 'read_workspace_spreadsheet', rawArgs));
|
|
89
89
|
}
|
|
90
90
|
if (returnJson) {
|
|
91
|
-
return
|
|
91
|
+
return wrapUntrustedJsonControls(result.data, `google-workspace:sheets:spreadsheet/${spreadsheetId}`, ['spreadsheetId', 'continuationToken', 'data.continuationToken']);
|
|
92
92
|
}
|
|
93
93
|
// Format as human-readable text
|
|
94
94
|
const response = result.data;
|
|
@@ -148,7 +148,7 @@ export async function handleReadSpreadsheetValues(args) {
|
|
|
148
148
|
throw new McpError(ErrorCode.InternalError, rewriteSheetsHandlerError(result.error, 'Failed to read spreadsheet values', 'read_workspace_spreadsheet_values', rawArgs));
|
|
149
149
|
}
|
|
150
150
|
if (returnJson) {
|
|
151
|
-
return
|
|
151
|
+
return wrapUntrustedJsonControls(result.data, `google-workspace:sheets:values/${spreadsheetId}`, ['spreadsheetId', 'continuationToken', 'data.continuationToken']);
|
|
152
152
|
}
|
|
153
153
|
if (isAnchorReadResponse(result.data)) {
|
|
154
154
|
return formatAnchorReadResponse(result.data);
|
|
@@ -503,7 +503,7 @@ export async function handleBatchGetValues(args) {
|
|
|
503
503
|
throw new McpError(ErrorCode.InternalError, rewriteSheetsHandlerError(result.error, 'Failed to batch read values', 'batch_read_workspace_spreadsheet_values', rawArgs));
|
|
504
504
|
}
|
|
505
505
|
if (returnJson) {
|
|
506
|
-
return
|
|
506
|
+
return wrapUntrustedJsonControls(result.data, `google-workspace:sheets:batch/${spreadsheetId}`, ['*.data.continuationToken']);
|
|
507
507
|
}
|
|
508
508
|
if (valueView === 'shaped') {
|
|
509
509
|
const shapedRanges = result.data;
|
|
@@ -3,7 +3,7 @@ import { getAccountManager, resolveEmail } from '../modules/accounts/index.js';
|
|
|
3
3
|
import { getSlidesService } from '../modules/slides/index.js';
|
|
4
4
|
import { extractPresentationIdFromUrl } from '../modules/slides/formatters.js';
|
|
5
5
|
import { readAliasedBoolean, readAliasedNumber, readAliasedString, readAliasedValue } from './arg-aliases.js';
|
|
6
|
-
import { wrapUntrustedContent,
|
|
6
|
+
import { wrapUntrustedContent, wrapUntrustedJsonControls } from '../utils/untrusted-content.js';
|
|
7
7
|
/**
|
|
8
8
|
* Format PresentationResponse as human-readable text
|
|
9
9
|
*/
|
|
@@ -100,7 +100,7 @@ export async function handleReadPresentation(args) {
|
|
|
100
100
|
throw new McpError(ErrorCode.InternalError, result.error || 'Failed to read presentation');
|
|
101
101
|
}
|
|
102
102
|
if (returnJson) {
|
|
103
|
-
return
|
|
103
|
+
return wrapUntrustedJsonControls(result.data, `google-workspace:slides:presentation/${presentationId}`, ['presentationId']);
|
|
104
104
|
}
|
|
105
105
|
// Format as human-readable text
|
|
106
106
|
const presResponse = result.data;
|
|
@@ -172,7 +172,7 @@ export async function handleGetSlide(args) {
|
|
|
172
172
|
throw new McpError(ErrorCode.InternalError, result.error || 'Failed to get slide');
|
|
173
173
|
}
|
|
174
174
|
if (returnJson) {
|
|
175
|
-
return
|
|
175
|
+
return wrapUntrustedJsonControls(result.data, `google-workspace:slides:slide/${presentationId}`, ['presentationId']);
|
|
176
176
|
}
|
|
177
177
|
// Format as human-readable text
|
|
178
178
|
const slides = result.data;
|
|
@@ -220,7 +220,7 @@ export async function handleBatchUpdatePresentation(args) {
|
|
|
220
220
|
throw new McpError(ErrorCode.InternalError, result.error || 'Failed to update presentation');
|
|
221
221
|
}
|
|
222
222
|
if (returnJson) {
|
|
223
|
-
return
|
|
223
|
+
return wrapUntrustedJsonControls(result.data, `google-workspace:slides:batch/${presentationId}`, ['presentationId']);
|
|
224
224
|
}
|
|
225
225
|
// Format as human-readable text
|
|
226
226
|
const response = result.data;
|