@mindstone/mcp-server-google-workspace 0.1.4 → 0.2.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.
Files changed (47) hide show
  1. package/README.md +19 -6
  2. package/dist/modules/accounts/manager.js +20 -2
  3. package/dist/modules/accounts/token.d.ts +13 -0
  4. package/dist/modules/accounts/token.js +73 -58
  5. package/dist/modules/accounts/types.d.ts +1 -0
  6. package/dist/modules/calendar/service.js +9 -0
  7. package/dist/modules/comments/service.js +6 -5
  8. package/dist/modules/docs/index.js +2 -1
  9. package/dist/modules/docs/service.js +8 -7
  10. package/dist/modules/drive/service.d.ts +2 -1
  11. package/dist/modules/drive/service.js +29 -0
  12. package/dist/modules/drive/types.d.ts +8 -0
  13. package/dist/modules/forms/service.js +4 -3
  14. package/dist/modules/gmail/services/attachment.js +2 -1
  15. package/dist/modules/gmail/services/base.js +2 -1
  16. package/dist/modules/gmail/services/draft.js +13 -7
  17. package/dist/modules/gmail/services/email.js +4 -3
  18. package/dist/modules/gmail/services/label.js +10 -9
  19. package/dist/modules/gmail/services/settings.js +2 -1
  20. package/dist/modules/slides/service.js +7 -6
  21. package/dist/modules/tasks/service.js +7 -6
  22. package/dist/resources/compose-email-template.d.ts +1 -1
  23. package/dist/resources/compose-email-template.js +448 -22
  24. package/dist/services/base/BaseGoogleService.js +7 -0
  25. package/dist/tools/calendar-handlers.js +28 -23
  26. package/dist/tools/contacts-handlers.js +8 -23
  27. package/dist/tools/definitions/account.js +8 -1
  28. package/dist/tools/definitions/destructive-overrides.json +1 -0
  29. package/dist/tools/definitions/drive.js +84 -6
  30. package/dist/tools/definitions/open-world-overrides.json +1 -0
  31. package/dist/tools/drive-handlers.d.ts +10 -0
  32. package/dist/tools/drive-handlers.js +44 -1
  33. package/dist/tools/forms-handlers.js +5 -12
  34. package/dist/tools/gmail-handlers.d.ts +7 -1
  35. package/dist/tools/gmail-handlers.js +38 -24
  36. package/dist/tools/server.js +15 -3
  37. package/dist/tools/tasks-handlers.js +7 -18
  38. package/dist/tools/type-guards.d.ts +3 -1
  39. package/dist/tools/type-guards.js +22 -2
  40. package/dist/tools/types.d.ts +13 -0
  41. package/dist/utils/apiError.d.ts +49 -0
  42. package/dist/utils/apiError.js +93 -0
  43. package/package.json +5 -1
  44. package/dist/services/calendar/index.d.ts +0 -27
  45. package/dist/services/calendar/index.js +0 -146
  46. package/dist/services/gmail/index.d.ts +0 -39
  47. package/dist/services/gmail/index.js +0 -337
@@ -1,8 +1,8 @@
1
1
  import { CalendarService } from '../modules/calendar/service.js';
2
2
  import { DriveService } from '../modules/drive/service.js';
3
3
  import { McpError, ErrorCode } from '@modelcontextprotocol/sdk/types.js';
4
+ import { toMcpError } from '../utils/apiError.js';
4
5
  import { getAccountManager, validateEmail, resolveEmail } from '../modules/accounts/index.js';
5
- import { CalendarError } from '../modules/calendar/types.js';
6
6
  import { google } from 'googleapis';
7
7
  import { wrapUntrustedContent, wrapUntrustedJsonStrings } from '../utils/untrusted-content.js';
8
8
  // Singleton instances
@@ -214,6 +214,11 @@ export async function handleGetCurrentTime(params) {
214
214
  try {
215
215
  // Fast-fail auth gate: throw clear error instead of helper's silent UTC fallback
216
216
  const tokenStatus = await accountManager.validateToken(email);
217
+ if (!tokenStatus.valid && tokenStatus.canRetry) {
218
+ // Transient refresh blip, not a dead grant — surface a retryable error rather than
219
+ // "Authentication required", which would wrongly push the user to reconnect.
220
+ throw new McpError(ErrorCode.InternalError, 'Google Workspace sign-in refresh hit a temporary error. Please try again in a moment.');
221
+ }
217
222
  if (!tokenStatus.valid || !tokenStatus.token) {
218
223
  throw new McpError(ErrorCode.InvalidRequest, 'Authentication required');
219
224
  }
@@ -271,9 +276,7 @@ export async function handleGetCurrentTime(params) {
271
276
  };
272
277
  }
273
278
  catch (error) {
274
- if (error instanceof McpError)
275
- throw error;
276
- throw new McpError(ErrorCode.InternalError, `Failed to get current time: ${error instanceof Error ? error.message : 'Unknown error'}`);
279
+ throw toMcpError(error, 'Failed to get current time');
277
280
  }
278
281
  });
279
282
  }
@@ -295,6 +298,11 @@ export async function handleFindFreeSlots(params) {
295
298
  return accountManager.withTokenRenewal(email, async () => {
296
299
  try {
297
300
  const tokenStatus = await accountManager.validateToken(email);
301
+ if (!tokenStatus.valid && tokenStatus.canRetry) {
302
+ // Transient refresh blip, not a dead grant — surface a retryable error rather than
303
+ // "Authentication required", which would wrongly push the user to reconnect.
304
+ throw new McpError(ErrorCode.InternalError, 'Google Workspace sign-in refresh hit a temporary error. Please try again in a moment.');
305
+ }
298
306
  if (!tokenStatus.valid || !tokenStatus.token) {
299
307
  throw new McpError(ErrorCode.InvalidRequest, 'Authentication required');
300
308
  }
@@ -366,9 +374,7 @@ export async function handleFindFreeSlots(params) {
366
374
  }, 'google-workspace:calendar:freebusy');
367
375
  }
368
376
  catch (error) {
369
- if (error instanceof McpError)
370
- throw error;
371
- throw new McpError(ErrorCode.InternalError, `Failed to find free slots: ${error instanceof Error ? error.message : 'Unknown error'}`);
377
+ throw toMcpError(error, 'Failed to find free slots');
372
378
  }
373
379
  });
374
380
  }
@@ -385,9 +391,7 @@ export async function handleListWorkspaceCalendars(params) {
385
391
  return wrapUntrustedJsonStrings(calendars, 'google-workspace:calendar:list');
386
392
  }
387
393
  catch (error) {
388
- if (error instanceof McpError)
389
- throw error;
390
- throw new McpError(ErrorCode.InternalError, `Failed to list calendars: ${error instanceof Error ? error.message : 'Unknown error'}`);
394
+ throw toMcpError(error, 'Failed to list calendars');
391
395
  }
392
396
  });
393
397
  }
@@ -466,7 +470,7 @@ export async function handleListWorkspaceCalendarEvents(params) {
466
470
  return formatEventsAsText(events, tzInfo);
467
471
  }
468
472
  catch (error) {
469
- throw new McpError(ErrorCode.InternalError, `Failed to list calendar events: ${error instanceof Error ? error.message : 'Unknown error'}`);
473
+ throw toMcpError(error, 'Failed to list calendar events');
470
474
  }
471
475
  });
472
476
  }
@@ -484,7 +488,7 @@ export async function handleGetWorkspaceCalendarEvent(params) {
484
488
  return wrapUntrustedJsonStrings(await calendarService.getEvent(email, eventId, calendarId), `google-workspace:calendar:event/${eventId}`);
485
489
  }
486
490
  catch (error) {
487
- throw new McpError(ErrorCode.InternalError, `Failed to get calendar event: ${error instanceof Error ? error.message : 'Unknown error'}`);
491
+ throw toMcpError(error, 'Failed to get calendar event');
488
492
  }
489
493
  });
490
494
  }
@@ -581,11 +585,13 @@ export async function handleCreateWorkspaceCalendarEvent(params) {
581
585
  return wrapUntrustedJsonStrings(createdEvent, 'google-workspace:calendar:event/create');
582
586
  }
583
587
  catch (error) {
584
- // Check if this is a CalendarError with a specific code (e.g., PERMISSION_DENIED)
585
- if (error instanceof CalendarError) {
586
- throw new McpError(ErrorCode.InvalidParams, error.message, error.details);
587
- }
588
- throw new McpError(ErrorCode.InternalError, `Failed to create calendar event: ${error instanceof Error ? error.message : 'Unknown error'}`);
588
+ // CalendarError here is operational (auth/permission/API failure), not caller-arg
589
+ // validation — genuine bad args are rejected by the explicit pre-checks above.
590
+ // Route it through toMcpError so the real cause reaches the user: server.ts's
591
+ // formatErrorResponse folds the thrown error's message into `action_required`. (An
592
+ // auth CalendarError/AccountError is passed through unchanged so formatErrorResponse can
593
+ // emit its structured `auth_required` reconnect handoff.)
594
+ throw toMcpError(error, 'Failed to create calendar event');
589
595
  }
590
596
  });
591
597
  }
@@ -616,7 +622,7 @@ export async function handleManageWorkspaceCalendarEvent(params) {
616
622
  return wrapUntrustedJsonStrings(managedEvent, `google-workspace:calendar:event/${eventId}`);
617
623
  }
618
624
  catch (error) {
619
- throw new McpError(ErrorCode.InternalError, `Failed to manage calendar event: ${error instanceof Error ? error.message : 'Unknown error'}`);
625
+ throw toMcpError(error, 'Failed to manage calendar event');
620
626
  }
621
627
  });
622
628
  }
@@ -647,11 +653,10 @@ export async function handleDeleteWorkspaceCalendarEvent(params) {
647
653
  };
648
654
  }
649
655
  catch (error) {
650
- // Check if this is a CalendarError with a specific code
651
- if (error instanceof CalendarError) {
652
- throw new McpError(ErrorCode.InvalidParams, error.message, error.details);
653
- }
654
- throw new McpError(ErrorCode.InternalError, `Failed to delete calendar event: ${error instanceof Error ? error.message : 'Unknown error'}`);
656
+ // CalendarError here is operational (auth/permission/API failure), not caller-arg
657
+ // validation — genuine bad args are rejected by the explicit pre-checks above.
658
+ // Route it through toMcpError so the real cause reaches the user (see create-event).
659
+ throw toMcpError(error, 'Failed to delete calendar event');
655
660
  }
656
661
  });
657
662
  }
@@ -1,6 +1,6 @@
1
- import { ContactsError } from "../modules/contacts/types.js";
2
1
  import { ContactsService } from "../services/contacts/index.js";
3
2
  import { McpError, ErrorCode } from "@modelcontextprotocol/sdk/types.js";
3
+ import { toMcpError } from "../utils/apiError.js";
4
4
  import { getAccountManager, resolveEmail } from "../modules/accounts/index.js";
5
5
  import { readAliasedBoolean, readAliasedNumber, readAliasedString } from './arg-aliases.js';
6
6
  import { wrapUntrustedContent, wrapUntrustedJsonStrings } from "../utils/untrusted-content.js";
@@ -48,19 +48,10 @@ export async function handleGetContacts(params) {
48
48
  return wrapUntrustedJsonStrings(result, 'google-workspace:contacts:list');
49
49
  }
50
50
  catch (error) {
51
- if (error instanceof ContactsError) {
52
- // Map ContactsError to McpError
53
- throw new McpError(ErrorCode.InternalError, // Or map specific error codes
54
- `Contacts API Error: ${error.message}`, { code: error.code, details: error.details });
55
- }
56
- else if (error instanceof McpError) {
57
- // Re-throw existing McpErrors (like auth errors from token renewal)
58
- throw error;
59
- }
60
- else {
61
- // Catch unexpected errors
62
- throw new McpError(ErrorCode.InternalError, `Failed to get contacts: ${error instanceof Error ? error.message : "Unknown error"}`);
63
- }
51
+ // toMcpError passes an McpError through, and folds a ContactsError's details into
52
+ // the message (InternalError) so the real cause reaches the user — the host drops
53
+ // an McpError's `data` arg, so details-as-data (the old shape) were invisible.
54
+ throw toMcpError(error, 'Failed to get contacts');
64
55
  }
65
56
  });
66
57
  }
@@ -113,15 +104,9 @@ export async function handleSearchContacts(params) {
113
104
  return formatContactsAsText(result.results, result.totalResults);
114
105
  }
115
106
  catch (error) {
116
- if (error instanceof ContactsError) {
117
- throw new McpError(ErrorCode.InternalError, `Contacts search error: ${error.message}`, { code: error.code, details: error.details });
118
- }
119
- else if (error instanceof McpError) {
120
- throw error;
121
- }
122
- else {
123
- throw new McpError(ErrorCode.InternalError, `Failed to search contacts: ${error instanceof Error ? error.message : "Unknown error"}`);
124
- }
107
+ // See handleGetContacts: toMcpError surfaces the real cause (details folded into
108
+ // the message) and passes an McpError through unchanged.
109
+ throw toMcpError(error, 'Failed to search contacts');
125
110
  }
126
111
  });
127
112
  }
@@ -24,10 +24,17 @@ export const accountTools = [
24
24
  default_package_id // mirrors the package_id of the is_default account; empty string if no accounts
25
25
  }
26
26
 
27
+ auth_status.valid means "reconnect is NOT required". A transient refresh blip (status
28
+ "REFRESH_FAILED" with a temporary-error reason) keeps it true; anything else that isn't a live
29
+ grant sets it false — a revoked/invalid grant ("AUTH_REQUIRED"), a missing token ("NO_TOKEN"),
30
+ an unusable token ("INVALID"), or a hard error ("ERROR"). Read status/reason for detail.
31
+
27
32
  Common Response Patterns:
28
- - Valid account exists → Proceed with requested operation (use its package_id)
33
+ - Valid account exists (auth_status.valid true) → Proceed with requested operation (use its package_id)
29
34
  - Multiple accounts exist → Ask user which to use; fall back to default_package_id if user has no preference
30
35
  - Token expired → Proceed normally (auto-refresh occurs)
36
+ - Transient refresh failure (auth_status.valid true, status "REFRESH_FAILED", reason mentions a temporary error) → Proceed / retry the operation; do NOT tell the user to reconnect — the grant is still valid, the refresh just hit a temporary network blip
37
+ - Reconnect required (auth_status.valid false, e.g. status "AUTH_REQUIRED", "NO_TOKEN", "INVALID", or "ERROR") → Start authentication flow
31
38
  - No accounts exist → Start authentication flow
32
39
 
33
40
  Example Usage:
@@ -56,6 +56,7 @@
56
56
  "list_file_revisions": false,
57
57
  "list_form_responses": false,
58
58
  "list_forms": false,
59
+ "list_shared_drives": false,
59
60
  "list_task_lists": false,
60
61
  "list_tasks": false,
61
62
  "list_workspace_accounts": false,
@@ -18,14 +18,19 @@ export const driveTools = [
18
18
  3. Filter by query:
19
19
  { "email": "user@example.com", "options": { "query": "mimeType='application/pdf'", "pageSize": 20 } }
20
20
 
21
- 4. Get JSON output:
21
+ 4. List files in one shared drive (get the ID from list_shared_drives):
22
+ { "email": "user@example.com", "options": { "driveId": "0ABCdef123" } }
23
+
24
+ 5. Get JSON output:
22
25
  { "email": "user@example.com", "return_json": true }
23
-
26
+
24
27
  Parameters (all inside "options"):
25
28
  - folderId: List contents of specific folder
26
29
  - query: Drive API query string
27
30
  - pageSize: Number of files to return
28
- - orderBy: Sort order fields`,
31
+ - orderBy: Sort order fields
32
+ - driveId: Limit results to one shared drive (corpora is forced to 'drive')
33
+ - corpora: 'user' (default), 'drive', or 'allDrives' (My Drive + every shared drive)`,
29
34
  aliases: ['list_files', 'get_files', 'show_files'],
30
35
  annotations: { readOnlyHint: true },
31
36
  inputSchema: {
@@ -59,6 +64,15 @@ export const driveTools = [
59
64
  type: 'array',
60
65
  items: { type: 'string' },
61
66
  description: 'Fields to include in response'
67
+ },
68
+ driveId: {
69
+ type: 'string',
70
+ description: 'Shared drive ID to list from (see list_shared_drives); corpora is forced to "drive"'
71
+ },
72
+ corpora: {
73
+ type: 'string',
74
+ enum: ['user', 'drive', 'allDrives'],
75
+ description: 'Scope of the listing: "user" (default), "drive" (one shared drive), or "allDrives"'
62
76
  }
63
77
  }
64
78
  },
@@ -91,14 +105,22 @@ export const driveTools = [
91
105
  4. Combined search:
92
106
  { "email": "user@example.com", "options": { "fullText": "meeting notes", "mimeType": "application/vnd.google-apps.document" } }
93
107
 
94
- 5. Get JSON output:
108
+ 5. Search everywhere, including every shared drive:
109
+ { "email": "user@example.com", "options": { "fullText": "budget", "corpora": "allDrives" } }
110
+
111
+ 6. Search one shared drive (get the ID from list_shared_drives):
112
+ { "email": "user@example.com", "options": { "fullText": "budget", "driveId": "0ABCdef123" } }
113
+
114
+ 7. Get JSON output:
95
115
  { "email": "user@example.com", "options": { "fullText": "report" }, "return_json": true }
96
-
116
+
97
117
  Parameters (all inside "options"):
98
118
  - fullText: Text to search in file content
99
119
  - mimeType: Filter by file type
100
120
  - folderId: Search within folder
101
- - trashed: Include trashed files (default: false)`,
121
+ - trashed: Include trashed files (default: false)
122
+ - driveId: Limit results to one shared drive (corpora is forced to 'drive')
123
+ - corpora: 'user' (default), 'drive', or 'allDrives' (My Drive + every shared drive)`,
102
124
  aliases: ['search_files', 'find_files', 'query_files'],
103
125
  annotations: { readOnlyHint: true },
104
126
  inputSchema: {
@@ -134,6 +156,15 @@ export const driveTools = [
134
156
  pageSize: {
135
157
  type: 'number',
136
158
  description: 'Maximum number of files to return'
159
+ },
160
+ driveId: {
161
+ type: 'string',
162
+ description: 'Shared drive ID to search in (see list_shared_drives); corpora is forced to "drive"'
163
+ },
164
+ corpora: {
165
+ type: 'string',
166
+ enum: ['user', 'drive', 'allDrives'],
167
+ description: 'Scope of the search: "user" (default), "drive" (one shared drive), or "allDrives"'
137
168
  }
138
169
  }
139
170
  },
@@ -145,6 +176,53 @@ export const driveTools = [
145
176
  required: ['options']
146
177
  }
147
178
  },
179
+ {
180
+ name: 'list_shared_drives',
181
+ category: 'Drive/Files',
182
+ description: `List the shared drives (Team Drives) the account can access.
183
+
184
+ Returns human-readable text by default. Use return_json: true for structured output.
185
+
186
+ Usage examples:
187
+
188
+ 1. List shared drives:
189
+ { "email": "user@example.com" }
190
+
191
+ 2. Page through results:
192
+ { "email": "user@example.com", "page_size": 50, "page_token": "..." }
193
+
194
+ WORKFLOW: Use a returned drive ID as "options.driveId" in list_drive_files or
195
+ search_drive_files to target that shared drive, or set "options.corpora" to
196
+ "allDrives" there to search My Drive and every shared drive at once.
197
+
198
+ NOTE: Files that live in a shared drive have no per-file owner (the drive owns
199
+ them; use lastModifyingUser/createdTime as proxies), and the revision tools do
200
+ not return revisions for shared-drive files. These are Google API limitations.`,
201
+ aliases: ['list_team_drives', 'get_shared_drives', 'show_shared_drives'],
202
+ annotations: { readOnlyHint: true },
203
+ inputSchema: {
204
+ type: 'object',
205
+ properties: {
206
+ email: {
207
+ type: 'string',
208
+ description: 'Email address of the Drive account'
209
+ },
210
+ page_size: {
211
+ type: 'number',
212
+ description: 'Maximum number of shared drives to return (Google caps at 100)'
213
+ },
214
+ page_token: {
215
+ type: 'string',
216
+ description: 'Page token from a previous list_shared_drives response'
217
+ },
218
+ return_json: {
219
+ type: 'boolean',
220
+ description: 'Return structured JSON instead of formatted text (default: false)'
221
+ }
222
+ },
223
+ required: []
224
+ }
225
+ },
148
226
  {
149
227
  name: 'upload_drive_file',
150
228
  category: 'Drive/Files',
@@ -56,6 +56,7 @@
56
56
  "list_file_revisions": true,
57
57
  "list_form_responses": true,
58
58
  "list_forms": true,
59
+ "list_shared_drives": true,
59
60
  "list_task_lists": true,
60
61
  "list_tasks": true,
61
62
  "list_workspace_accounts": false,
@@ -46,6 +46,16 @@ interface DriveDeleteArgs {
46
46
  }
47
47
  export declare function handleListDriveFiles(args: DriveFileListArgs & Record<string, unknown>): Promise<McpToolResponse | string | object>;
48
48
  export declare function handleSearchDriveFiles(args: DriveSearchArgs & Record<string, unknown>): Promise<McpToolResponse | string | object>;
49
+ interface ListSharedDrivesArgs {
50
+ email?: string;
51
+ page_size?: number;
52
+ pageSize?: number;
53
+ page_token?: string;
54
+ pageToken?: string;
55
+ return_json?: boolean;
56
+ returnJson?: boolean;
57
+ }
58
+ export declare function handleListSharedDrives(args: ListSharedDrivesArgs & Record<string, unknown>): Promise<McpToolResponse | string | object>;
49
59
  export declare function handleUploadDriveFile(args: DriveUploadArgs): Promise<McpToolResponse>;
50
60
  export declare function handleDownloadDriveFile(args: DriveDownloadArgs): Promise<string>;
51
61
  export declare function handleCreateDriveFolder(args: DriveFolderArgs): Promise<McpToolResponse>;
@@ -1,7 +1,7 @@
1
1
  import { McpError, ErrorCode } from '@modelcontextprotocol/sdk/types.js';
2
2
  import { getAccountManager, resolveEmail } from '../modules/accounts/index.js';
3
3
  import { getDriveService } from '../modules/drive/index.js';
4
- import { readAliasedBoolean, readAliasedString } from './arg-aliases.js';
4
+ import { readAliasedBoolean, readAliasedNumber, readAliasedString } from './arg-aliases.js';
5
5
  import { wrapUntrustedContent, wrapUntrustedJsonStrings } from '../utils/untrusted-content.js';
6
6
  const HOST_TIMEZONE = Intl.DateTimeFormat().resolvedOptions().timeZone;
7
7
  /**
@@ -60,6 +60,21 @@ function formatFilesAsText(files) {
60
60
  }
61
61
  return wrapUntrustedContent(lines.join('\n'), 'google-workspace:drive:file-list');
62
62
  }
63
+ /**
64
+ * Format shared-drives list as human-readable text
65
+ */
66
+ function formatSharedDrivesAsText(drives) {
67
+ if (!drives || drives.length === 0) {
68
+ return 'No shared drives found.';
69
+ }
70
+ const lines = [];
71
+ lines.push(`Shared drives: ${drives.length} result${drives.length !== 1 ? 's' : ''}\n`);
72
+ for (const drive of drives) {
73
+ lines.push(`${drive.name}`);
74
+ lines.push(` [id: ${drive.id}]`);
75
+ }
76
+ return wrapUntrustedContent(lines.join('\n'), 'google-workspace:drive:shared-drive-list');
77
+ }
63
78
  /** @internal Exported for tests. */
64
79
  export function formatDriveRecoveryError(operation, error) {
65
80
  const status = error && typeof error === 'object'
@@ -181,6 +196,34 @@ export async function handleSearchDriveFiles(args) {
181
196
  }
182
197
  });
183
198
  }
199
+ export async function handleListSharedDrives(args) {
200
+ const accountManager = getAccountManager();
201
+ const rawArgs = args;
202
+ const returnJson = readAliasedBoolean(rawArgs, 'return_json', 'returnJson') ?? false;
203
+ const pageSize = readAliasedNumber(rawArgs, 'page_size', 'pageSize');
204
+ const pageToken = readAliasedString(rawArgs, 'page_token', 'pageToken');
205
+ // Resolve email - uses instance account if not provided, validates if provided
206
+ const email = await resolveEmail(args);
207
+ return await accountManager.withTokenRenewal(email, async () => {
208
+ try {
209
+ const driveService = await getDriveService();
210
+ const result = await driveService.listSharedDrives(email, { pageSize, pageToken });
211
+ // Return JSON if requested, otherwise format as human-readable text
212
+ // Return string directly - server.ts handles MCP response wrapping
213
+ if (returnJson) {
214
+ return formatDriveJsonResult('list shared drives', result, 'google-workspace:drive:shared-drive-list');
215
+ }
216
+ if (!result.success) {
217
+ return formatDriveRecoveryError('list shared drives', new Error(result.error || 'Unknown error'));
218
+ }
219
+ const drives = result.data?.drives || [];
220
+ return formatSharedDrivesAsText(drives);
221
+ }
222
+ catch (error) {
223
+ return formatDriveRecoveryError('list shared drives', error);
224
+ }
225
+ });
226
+ }
184
227
  export async function handleUploadDriveFile(args) {
185
228
  if (!args.options?.name) {
186
229
  throw new McpError(ErrorCode.InvalidParams, 'Missing required parameter: "options.name" (filename for upload). ' +
@@ -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
- if (error instanceof McpError)
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
- if (error instanceof McpError)
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
- if (error instanceof McpError)
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
- if (error instanceof McpError)
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,7 +208,13 @@ export declare function handleGetWorkspaceEmailThread(params: GetThreadParams):
208
208
  }>;
209
209
  }>;
210
210
  }>;
211
- export declare function handleSendWorkspaceEmail(params: SendEmailRequestParams & Record<string, unknown>): Promise<import("../modules/gmail/types.js").SendEmailResponse>;
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>;