@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
package/README.md CHANGED
@@ -8,9 +8,9 @@ Google Workspace MCP server — Gmail, Calendar, Drive, Docs, Sheets, Slides, Co
8
8
 
9
9
  ## Status
10
10
 
11
- - **Version:** [0.1.2](./CHANGELOG.md) · npm: not yet published
11
+ - **Version:** [0.2.0](./CHANGELOG.md) · npm: not yet published
12
12
  - **Auth:** OAuth (host-orchestrated) ([`GOOGLE_CLIENT_SECRET`](./server.json))
13
- - **Tools:** [94](./src/tools/definitions/) (Gmail, Calendar, Drive, Docs, Sheets, Slides, Contacts, Comments, Account; +10 gated Tasks/Forms behind `ENABLE_GOOGLE_TASKS_FORMS=true`)
13
+ - **Tools:** [95](./src/tools/definitions/) (Gmail, Calendar, Drive, Docs, Sheets, Slides, Contacts, Comments, Account; +10 gated Tasks/Forms behind `ENABLE_GOOGLE_TASKS_FORMS=true`)
14
14
  - **Surface:** cloud-api
15
15
  - **Machine-readable:** [`STATUS.json`](./STATUS.json)
16
16
 
@@ -18,7 +18,7 @@ This connector is based on [aaronsb/google-workspace-mcp](https://github.com/aar
18
18
 
19
19
  ## Why this exists
20
20
 
21
- When we ported this in early 2026, Google had not published a first-party MCP server for the Workspace surface. The community options at the time each got parts of the job right — Aaron Brown's [aaronsb/google-workspace-mcp](https://github.com/aaronsb/google-workspace-mcp), which we used as the starting point, covered the breadth of Workspace APIs but ran its own browser-callback server during OAuth, which our host application already does. We forked it so that the MCP host can own the entire OAuth flow (the connector returns a structured `auth_required` response instead of running a callback server or computing OAuth URLs), per-account token files are written atomically with restrictive permissions and symlink rejection, and the connector goes through our own security review before each release. Google's [Workspace MCP](https://github.com/googleworkspace/mcp) has since shipped; we continue to maintain this one because it integrates with our host's credential-file layout, host-orchestrated OAuth handoff, and recovery-guidance contract.
21
+ When we ported this in early 2026, Google had not published a first-party MCP server for the Workspace surface. The community options at the time each got parts of the job right — Aaron Brown's [aaronsb/google-workspace-mcp](https://github.com/aaronsb/google-workspace-mcp), which we used as the starting point, covered the breadth of Workspace APIs but ran its own browser-callback server during OAuth, which our host application already does. We forked it so that the MCP host can own the entire OAuth flow (the connector returns a structured `auth_required` response instead of running a callback server or computing OAuth URLs), per-account token files are written atomically with restrictive permissions and symlink rejection, and the connector goes through our own security review before each release. Google's [Workspace MCP](https://github.com/googleworkspace/mcp) has since shipped; we continue to maintain this one because it integrates with our host's credential-file layout, host-orchestrated OAuth handoff, and recovery-guidance contract. This is now a hard fork maintained independently in this repository — we do not sync changes from the upstream project.
22
22
 
23
23
  ## Example interaction
24
24
 
@@ -153,7 +153,7 @@ Until the host has written `${ACCOUNTS_PATH}` and the matching per-account token
153
153
  }
154
154
  ```
155
155
 
156
- ## Tools (94)
156
+ ## Tools (95)
157
157
 
158
158
  The full list lives under [`src/tools/definitions/`](./src/tools/definitions/) and is also surfaced in [`tools-inventory.json`](./tools-inventory.json). Grouped by domain:
159
159
 
@@ -161,7 +161,7 @@ The full list lives under [`src/tools/definitions/`](./src/tools/definitions/) a
161
161
  | --- | --- | --- |
162
162
  | Gmail | 21 | Email search/thread/send/compose, drafts, labels, label filters, attachments, archive/trash/read-state helpers. |
163
163
  | Calendar | 9 | Current time, free-slot lookup, calendar/event listing, event creation, updates, responses, and deletion. |
164
- | Drive | 13 | List/search/upload/download/copy/move/trash/untrash files, folders, permissions, and revisions. |
164
+ | Drive | 14 | List/search/upload/download/copy/move/trash/untrash files, folders, permissions, revisions, and shared-drive discovery. |
165
165
  | Docs | 8 | Read, create, append, replace, find/replace, tab listing, and batch updates. |
166
166
  | Sheets | 14 | Read/write ranges, create spreadsheets, sheet management, batch operations, find/replace, and formatting. |
167
167
  | Slides | 7 | Read, create, list/get slides, batch update, thumbnails, and ID extraction. |
@@ -172,7 +172,20 @@ The full list lives under [`src/tools/definitions/`](./src/tools/definitions/) a
172
172
  | Tasks (gated) | 6 | Registered only when `ENABLE_GOOGLE_TASKS_FORMS=true`. |
173
173
  | Forms (gated) | 4 | Registered only when `ENABLE_GOOGLE_TASKS_FORMS=true`. |
174
174
 
175
- The `## Status` block counts the 94 default-enabled tools; the additional 10 Tasks + Forms tools register when the feature flag is set.
175
+ The `## Status` block counts the 95 default-enabled tools; the additional 10 Tasks + Forms tools register when the feature flag is set.
176
+
177
+ ### Shared drives
178
+
179
+ All Drive file, permission, and comment tools work on shared-drive files (the `files.*` and `permissions.*` calls pass `supportsAllDrives`; the Comments API addresses files by ID and defines no such flag). Listing and search default to the user's own corpus plus files shared with them, so shared-drive content the user has access to but has never opened may not surface by default. To work with shared drives explicitly:
180
+
181
+ - **Discover drives:** `list_shared_drives` returns the shared drives the account can access (id, name, creation time).
182
+ - **Target one drive:** pass `options.driveId` to `list_drive_files` / `search_drive_files`. The connector forces `corpora: 'drive'` whenever `driveId` is set (the Drive API rejects any other pairing), overriding a caller-supplied `corpora`.
183
+ - **Search everything:** pass `options.corpora: 'allDrives'` (no `driveId`) to search across My Drive and all shared drives in one query. Google recommends this only for targeted searches; prefer a specific `driveId` for browsing.
184
+
185
+ Known Drive API limitations for shared-drive files (not fixable in this connector):
186
+
187
+ - Files native to a shared drive have no `owners[]` — ownership belongs to the drive itself. Use `lastModifyingUser` and `createdTime` as proxies when attributing files.
188
+ - The Revisions API does not support shared-drive files, so `list_file_revisions` / `download_file_revision` only work for My Drive files.
176
189
 
177
190
  ## Security notes
178
191
 
@@ -41,8 +41,20 @@ export class AccountManager {
41
41
  status: renewalResult.status
42
42
  };
43
43
  }
44
+ else if (renewalResult.canRetry) {
45
+ // Transient refresh failure (temporary network error, not a revoked grant):
46
+ // the grant is still good and no reconnect is required. Report valid:true so an
47
+ // agent keying off the boolean doesn't wrongly send the user to reconnect over a
48
+ // blip — this mirrors withTokenRenewal, which proceeds when canRetry is set. The
49
+ // status + reason still carry the transient detail for consumers that look deeper.
50
+ account.auth_status = {
51
+ valid: true,
52
+ status: renewalResult.status,
53
+ reason: renewalResult.reason
54
+ };
55
+ }
44
56
  else {
45
- // If auto-renewal failed, try to get an auth URL for re-authentication
57
+ // Refresh token invalid/revoked (or otherwise non-retryable) — reconnect required.
46
58
  account.auth_status = {
47
59
  valid: false,
48
60
  status: renewalResult.status,
@@ -274,8 +286,14 @@ export class AccountManager {
274
286
  status: tokenStatus.status
275
287
  };
276
288
  break;
277
- case 'INVALID':
278
289
  case 'REFRESH_FAILED':
290
+ // Transient refresh blip (canRetry) keeps the grant valid — no reconnect required,
291
+ // mirroring listAccounts. A non-retryable REFRESH_FAILED still reports as invalid.
292
+ account.auth_status = tokenStatus.canRetry
293
+ ? { valid: true, status: tokenStatus.status, reason: tokenStatus.reason }
294
+ : { valid: false, status: tokenStatus.status, reason: tokenStatus.reason, authUrl: undefined };
295
+ break;
296
+ case 'INVALID':
279
297
  case 'EXPIRED':
280
298
  account.auth_status = {
281
299
  valid: false,
@@ -18,6 +18,19 @@ export declare class TokenManager {
18
18
  private isRefreshDisabled;
19
19
  private authRequiredResult;
20
20
  deleteToken(email: string): Promise<void>;
21
+ /**
22
+ * Refreshes the access token, retrying once on a non-invalid_grant failure.
23
+ *
24
+ * Shared by autoRenewToken and validateToken so the retry + failure-classification
25
+ * logic can't drift between the two paths. On success the refreshed token is persisted
26
+ * (scope + refresh_token preserved, since Google omits them on refresh). The outcome
27
+ * distinguishes a dead grant (invalidGrant: true → reconnect) from a transient blip
28
+ * (invalidGrant: false → retryable), including the case where a transient first attempt
29
+ * is followed by an invalid_grant on retry.
30
+ *
31
+ * Callers must have already established that token.refresh_token and this.oauthClient exist.
32
+ */
33
+ private refreshWithRetry;
21
34
  /**
22
35
  * Basic token validation - just checks if token exists and isn't expired.
23
36
  * No scope validation - auth issues handled via 401 responses.
@@ -83,6 +83,52 @@ export class TokenManager {
83
83
  }
84
84
  }
85
85
  }
86
+ /**
87
+ * Refreshes the access token, retrying once on a non-invalid_grant failure.
88
+ *
89
+ * Shared by autoRenewToken and validateToken so the retry + failure-classification
90
+ * logic can't drift between the two paths. On success the refreshed token is persisted
91
+ * (scope + refresh_token preserved, since Google omits them on refresh). The outcome
92
+ * distinguishes a dead grant (invalidGrant: true → reconnect) from a transient blip
93
+ * (invalidGrant: false → retryable), including the case where a transient first attempt
94
+ * is followed by an invalid_grant on retry.
95
+ *
96
+ * Callers must have already established that token.refresh_token and this.oauthClient exist.
97
+ */
98
+ async refreshWithRetry(email, token) {
99
+ const attemptRefresh = async () => {
100
+ const newToken = await this.oauthClient.refreshToken(token.refresh_token);
101
+ // Preserve original scope and refresh_token - Google doesn't return these on refresh
102
+ newToken.scope = newToken.scope || token.scope;
103
+ newToken.refresh_token = newToken.refresh_token || token.refresh_token;
104
+ await this.saveToken(email, newToken);
105
+ return newToken;
106
+ };
107
+ try {
108
+ return { ok: true, token: await attemptRefresh() };
109
+ }
110
+ catch (error) {
111
+ if (isRefreshTokenInvalidError(error)) {
112
+ logger.error('Refresh token is invalid or revoked');
113
+ return { ok: false, invalidGrant: true };
114
+ }
115
+ // Not a refresh-token problem — a transient blip. Try once more.
116
+ try {
117
+ logger.warn('First refresh attempt failed, trying once more');
118
+ return { ok: true, token: await attemptRefresh() };
119
+ }
120
+ catch (secondError) {
121
+ // Re-classify the retry failure: a transient blip followed by an invalid_grant is
122
+ // still a dead grant, so it must not be mislabelled as retryable.
123
+ if (isRefreshTokenInvalidError(secondError)) {
124
+ logger.error('Refresh token is invalid or revoked (surfaced on retry)');
125
+ return { ok: false, invalidGrant: true };
126
+ }
127
+ logger.error('Both refresh attempts failed, but refresh token may still be valid');
128
+ return { ok: false, invalidGrant: false };
129
+ }
130
+ }
131
+ }
86
132
  /**
87
133
  * Basic token validation - just checks if token exists and isn't expired.
88
134
  * No scope validation - auth issues handled via 401 responses.
@@ -123,52 +169,17 @@ export class TokenManager {
123
169
  reason: 'No refresh token or OAuth client available'
124
170
  };
125
171
  }
126
- try {
127
- // Attempt to refresh the token
128
- const newToken = await this.oauthClient.refreshToken(token.refresh_token);
129
- // Preserve original scope - Google doesn't return scope on refresh
130
- newToken.scope = newToken.scope || token.scope;
131
- // Preserve refresh_token if not returned (Google sometimes omits it)
132
- newToken.refresh_token = newToken.refresh_token || token.refresh_token;
133
- await this.saveToken(email, newToken);
172
+ const outcome = await this.refreshWithRetry(email, token);
173
+ if (outcome.ok) {
134
174
  logger.info('Token refreshed successfully');
135
175
  return {
136
176
  success: true,
137
177
  status: 'REFRESHED',
138
- token: newToken
178
+ token: outcome.token
139
179
  };
140
180
  }
141
- catch (error) {
142
- // Check if the error indicates an invalid/revoked refresh token
143
- const isRefreshTokenInvalid = isRefreshTokenInvalidError(error);
144
- if (!isRefreshTokenInvalid) {
145
- // If it's not a refresh token issue, try one more time
146
- try {
147
- logger.warn('First refresh attempt failed, trying once more');
148
- const newToken = await this.oauthClient.refreshToken(token.refresh_token);
149
- // Preserve original scope and refresh_token
150
- newToken.scope = newToken.scope || token.scope;
151
- newToken.refresh_token = newToken.refresh_token || token.refresh_token;
152
- await this.saveToken(email, newToken);
153
- logger.info('Token refreshed successfully on second attempt');
154
- return {
155
- success: true,
156
- status: 'REFRESHED',
157
- token: newToken
158
- };
159
- }
160
- catch (secondError) {
161
- logger.error('Both refresh attempts failed, but refresh token may still be valid');
162
- return {
163
- success: false,
164
- status: 'REFRESH_FAILED',
165
- reason: 'Token refresh failed, temporary error',
166
- canRetry: true
167
- };
168
- }
169
- }
181
+ if (outcome.invalidGrant) {
170
182
  // Refresh token is invalid, need full reauth
171
- logger.error('Refresh token is invalid or revoked');
172
183
  return {
173
184
  success: false,
174
185
  status: 'AUTH_REQUIRED',
@@ -176,6 +187,12 @@ export class TokenManager {
176
187
  canRetry: false
177
188
  };
178
189
  }
190
+ return {
191
+ success: false,
192
+ status: 'REFRESH_FAILED',
193
+ reason: 'Token refresh failed, temporary error',
194
+ canRetry: true
195
+ };
179
196
  }
180
197
  // Token is still valid
181
198
  return {
@@ -233,35 +250,33 @@ export class TokenManager {
233
250
  };
234
251
  }
235
252
  if (token.refresh_token && this.oauthClient) {
236
- try {
237
- const newToken = await this.oauthClient.refreshToken(token.refresh_token);
238
- // Preserve original scope and refresh_token - Google doesn't return these on refresh
239
- newToken.scope = newToken.scope || token.scope;
240
- newToken.refresh_token = newToken.refresh_token || token.refresh_token;
241
- await this.saveToken(email, newToken);
253
+ // Retry-once + failure classification lives in refreshWithRetry (shared with
254
+ // autoRenewToken). A single transient network blip shouldn't be reported as a
255
+ // dead grant; the canRetry flag lets callers (e.g. BaseGoogleService) surface a
256
+ // retryable error instead of demanding a reconnect.
257
+ const outcome = await this.refreshWithRetry(email, token);
258
+ if (outcome.ok) {
242
259
  logger.info('Token refreshed successfully');
243
260
  return {
244
261
  valid: true,
245
262
  status: 'REFRESHED',
246
- token: newToken,
247
- requiredScopes: newToken.scope ? newToken.scope.split(' ') : undefined
263
+ token: outcome.token,
264
+ requiredScopes: outcome.token.scope ? outcome.token.scope.split(' ') : undefined
248
265
  };
249
266
  }
250
- catch (error) {
251
- logger.error('Token refresh failed', error);
252
- if (isRefreshTokenInvalidError(error)) {
253
- return {
254
- valid: false,
255
- status: 'AUTH_REQUIRED',
256
- reason: 'Refresh token is invalid or revoked'
257
- };
258
- }
267
+ if (outcome.invalidGrant) {
259
268
  return {
260
269
  valid: false,
261
- status: 'REFRESH_FAILED',
262
- reason: 'Token refresh failed'
270
+ status: 'AUTH_REQUIRED',
271
+ reason: 'Refresh token is invalid or revoked'
263
272
  };
264
273
  }
274
+ return {
275
+ valid: false,
276
+ status: 'REFRESH_FAILED',
277
+ reason: 'Token refresh failed, temporary error',
278
+ canRetry: true
279
+ };
265
280
  }
266
281
  logger.debug('No refresh token available');
267
282
  return {
@@ -30,6 +30,7 @@ export interface TokenStatus {
30
30
  reason?: string;
31
31
  authUrl?: string;
32
32
  requiredScopes?: string[];
33
+ canRetry?: boolean;
33
34
  }
34
35
  export interface AuthenticationError extends AccountError {
35
36
  authUrl: string;
@@ -116,6 +116,10 @@ export class CalendarService {
116
116
  const accountManager = getAccountManager();
117
117
  try {
118
118
  const tokenStatus = await accountManager.validateToken(email);
119
+ if (!tokenStatus.valid && tokenStatus.canRetry) {
120
+ // Transient refresh blip, not a dead grant — retryable, not a reconnect demand.
121
+ throw new CalendarError('Calendar sign-in refresh hit a temporary error', 'TEMPORARY_AUTH_ERROR', 'Please try again in a moment');
122
+ }
119
123
  if (!tokenStatus.valid || !tokenStatus.token) {
120
124
  throw new CalendarError('Calendar authentication required', 'AUTH_REQUIRED', 'Please authenticate to access calendar');
121
125
  }
@@ -147,6 +151,11 @@ export class CalendarService {
147
151
  this.oauth2Client.setCredentials(tokenStatus.token);
148
152
  return await operation();
149
153
  }
154
+ if (!tokenStatus.valid && tokenStatus.canRetry) {
155
+ // Transient refresh blip during 401 recovery — retryable, not a reconnect demand.
156
+ // Mirrors withTokenRenewal so the raw 401 doesn't fall through to the reconnect CTA.
157
+ throw new AccountError('Calendar sign-in refresh hit a temporary error', 'TEMPORARY_AUTH_ERROR', 'Please try again in a moment');
158
+ }
150
159
  }
151
160
  const status = error && typeof error === 'object'
152
161
  ? error.code
@@ -1,5 +1,6 @@
1
1
  import { google } from 'googleapis';
2
2
  import { BaseGoogleService } from '../../services/base/BaseGoogleService.js';
3
+ import { describeApiError } from '../../utils/apiError.js';
3
4
  import { DRIVE_SCOPES } from '../drive/scopes.js';
4
5
  const DEFAULT_PAGE_SIZE = 20;
5
6
  // Fields parameter for comments.list — Google API requires explicit field selection
@@ -98,7 +99,7 @@ export class CommentsService extends BaseGoogleService {
98
99
  catch (error) {
99
100
  return {
100
101
  success: false,
101
- error: error instanceof Error ? error.message : 'Unknown error occurred',
102
+ error: describeApiError(error),
102
103
  };
103
104
  }
104
105
  }
@@ -136,7 +137,7 @@ export class CommentsService extends BaseGoogleService {
136
137
  catch (error) {
137
138
  return {
138
139
  success: false,
139
- error: error instanceof Error ? error.message : 'Unknown error occurred',
140
+ error: describeApiError(error),
140
141
  };
141
142
  }
142
143
  }
@@ -166,7 +167,7 @@ export class CommentsService extends BaseGoogleService {
166
167
  catch (error) {
167
168
  return {
168
169
  success: false,
169
- error: error instanceof Error ? error.message : 'Unknown error occurred',
170
+ error: describeApiError(error),
170
171
  };
171
172
  }
172
173
  }
@@ -195,7 +196,7 @@ export class CommentsService extends BaseGoogleService {
195
196
  catch (error) {
196
197
  return {
197
198
  success: false,
198
- error: error instanceof Error ? error.message : 'Unknown error occurred',
199
+ error: describeApiError(error),
199
200
  };
200
201
  }
201
202
  }
@@ -219,7 +220,7 @@ export class CommentsService extends BaseGoogleService {
219
220
  catch (error) {
220
221
  return {
221
222
  success: false,
222
- error: error instanceof Error ? error.message : 'Unknown error occurred',
223
+ error: describeApiError(error),
223
224
  };
224
225
  }
225
226
  }
@@ -1,5 +1,6 @@
1
1
  import { docsService } from '../../services/docs/index.js';
2
2
  import { DocsService } from './service.js';
3
+ import { describeApiError } from '../../utils/apiError.js';
3
4
  // Export types and service
4
5
  export * from './types.js';
5
6
  export * from './scopes.js';
@@ -17,7 +18,7 @@ export async function initializeDocsModule() {
17
18
  export function handleDocsError(error) {
18
19
  return {
19
20
  success: false,
20
- error: error instanceof Error ? error.message : 'Unknown error occurred',
21
+ error: describeApiError(error),
21
22
  };
22
23
  }
23
24
  //# sourceMappingURL=index.js.map
@@ -1,6 +1,7 @@
1
1
  import { google } from 'googleapis';
2
2
  import { BaseGoogleService } from '../../services/base/BaseGoogleService.js';
3
3
  import { DOCS_SCOPES } from './scopes.js';
4
+ import { describeApiError } from '../../utils/apiError.js';
4
5
  const DEFAULT_MAX_CHARS = 50000;
5
6
  const TRUNCATION_MARKER = '\n\n[TRUNCATED - document exceeds character limit]';
6
7
  export class DocsService extends BaseGoogleService {
@@ -127,7 +128,7 @@ export class DocsService extends BaseGoogleService {
127
128
  catch (error) {
128
129
  return {
129
130
  success: false,
130
- error: error instanceof Error ? error.message : 'Unknown error occurred',
131
+ error: describeApiError(error),
131
132
  };
132
133
  }
133
134
  }
@@ -182,7 +183,7 @@ export class DocsService extends BaseGoogleService {
182
183
  catch (error) {
183
184
  return {
184
185
  success: false,
185
- error: error instanceof Error ? error.message : 'Unknown error occurred',
186
+ error: describeApiError(error),
186
187
  };
187
188
  }
188
189
  }
@@ -227,7 +228,7 @@ export class DocsService extends BaseGoogleService {
227
228
  catch (error) {
228
229
  return {
229
230
  success: false,
230
- error: error instanceof Error ? error.message : 'Unknown error occurred',
231
+ error: describeApiError(error),
231
232
  };
232
233
  }
233
234
  }
@@ -283,7 +284,7 @@ export class DocsService extends BaseGoogleService {
283
284
  catch (error) {
284
285
  return {
285
286
  success: false,
286
- error: error instanceof Error ? error.message : 'Unknown error occurred',
287
+ error: describeApiError(error),
287
288
  };
288
289
  }
289
290
  }
@@ -336,7 +337,7 @@ export class DocsService extends BaseGoogleService {
336
337
  catch (error) {
337
338
  return {
338
339
  success: false,
339
- error: error instanceof Error ? error.message : 'Unknown error occurred',
340
+ error: describeApiError(error),
340
341
  };
341
342
  }
342
343
  }
@@ -370,7 +371,7 @@ export class DocsService extends BaseGoogleService {
370
371
  catch (error) {
371
372
  return {
372
373
  success: false,
373
- error: error instanceof Error ? error.message : 'Unknown error occurred',
374
+ error: describeApiError(error),
374
375
  };
375
376
  }
376
377
  }
@@ -413,7 +414,7 @@ export class DocsService extends BaseGoogleService {
413
414
  catch (error) {
414
415
  return {
415
416
  success: false,
416
- error: error instanceof Error ? error.message : 'Unknown error occurred',
417
+ error: describeApiError(error),
417
418
  };
418
419
  }
419
420
  }
@@ -1,6 +1,6 @@
1
1
  import { google } from 'googleapis';
2
2
  import { BaseGoogleService } from '../../services/base/BaseGoogleService.js';
3
- import { DriveOperationResult, FileDownloadOptions, FileListOptions, FileSearchOptions, FileUploadOptions, PermissionOptions } from './types.js';
3
+ import { DriveOperationResult, FileDownloadOptions, FileListOptions, FileSearchOptions, FileUploadOptions, PermissionOptions, SharedDriveListOptions } from './types.js';
4
4
  export declare class DriveService extends BaseGoogleService<ReturnType<typeof google.drive>> {
5
5
  private initialized;
6
6
  constructor();
@@ -17,6 +17,7 @@ export declare class DriveService extends BaseGoogleService<ReturnType<typeof go
17
17
  */
18
18
  private checkInitialized;
19
19
  listFiles(email: string, options?: FileListOptions): Promise<DriveOperationResult>;
20
+ listSharedDrives(email: string, options?: SharedDriveListOptions): Promise<DriveOperationResult>;
20
21
  uploadFile(email: string, options: FileUploadOptions): Promise<DriveOperationResult>;
21
22
  downloadFile(email: string, options: FileDownloadOptions): Promise<DriveOperationResult>;
22
23
  createFolder(email: string, name: string, parentId?: string): Promise<DriveOperationResult>;
@@ -93,6 +93,9 @@ export class DriveService extends BaseGoogleService {
93
93
  pageToken: options.pageToken,
94
94
  orderBy: options.orderBy?.join(','),
95
95
  fields: options.fields?.join(',') || 'files(id, name, mimeType, modifiedTime, size)',
96
+ // Google rejects driveId unless corpora is 'drive', so force the pairing.
97
+ driveId: options.driveId || undefined,
98
+ corpora: options.driveId ? 'drive' : options.corpora,
96
99
  supportsAllDrives: true,
97
100
  includeItemsFromAllDrives: true,
98
101
  });
@@ -105,6 +108,26 @@ export class DriveService extends BaseGoogleService {
105
108
  throw this.handleError(error, 'Failed to list Drive files');
106
109
  }
107
110
  }
111
+ async listSharedDrives(email, options = {}) {
112
+ try {
113
+ await this.ensureInitialized();
114
+ this.checkInitialized();
115
+ await this.validateScopes(email, [DRIVE_SCOPES.READONLY]);
116
+ const client = await this.getAuthenticatedClient(email, (auth) => google.drive({ version: 'v3', auth }));
117
+ const response = await client.drives.list({
118
+ pageSize: options.pageSize,
119
+ pageToken: options.pageToken,
120
+ fields: 'drives(id, name, createdTime), nextPageToken',
121
+ });
122
+ return {
123
+ success: true,
124
+ data: response.data,
125
+ };
126
+ }
127
+ catch (error) {
128
+ throw this.handleError(error, 'Failed to list shared drives');
129
+ }
130
+ }
108
131
  async uploadFile(email, options) {
109
132
  try {
110
133
  await this.ensureInitialized();
@@ -265,6 +288,9 @@ export class DriveService extends BaseGoogleService {
265
288
  pageToken: options.pageToken,
266
289
  orderBy: options.orderBy?.join(','),
267
290
  fields: options.fields?.join(',') || 'files(id, name, mimeType, modifiedTime, size)',
291
+ // Google rejects driveId unless corpora is 'drive', so force the pairing.
292
+ driveId: options.driveId || undefined,
293
+ corpora: options.driveId ? 'drive' : options.corpora,
268
294
  supportsAllDrives: true,
269
295
  includeItemsFromAllDrives: true,
270
296
  });
@@ -417,6 +443,9 @@ export class DriveService extends BaseGoogleService {
417
443
  throw this.handleError(error, 'Failed to untrash Drive file');
418
444
  }
419
445
  }
446
+ // The Drive Revisions API does not accept supportsAllDrives and does not
447
+ // surface revisions for shared-drive files, so revisions.* calls here and in
448
+ // downloadRevision intentionally omit the flag (see CHANGELOG 0.1.3).
420
449
  async listRevisions(email, fileId) {
421
450
  try {
422
451
  await this.ensureInitialized();
@@ -4,6 +4,8 @@ export type DriveFileList = drive_v3.Schema$FileList;
4
4
  export type DrivePermission = drive_v3.Schema$Permission;
5
5
  export type DriveRevision = drive_v3.Schema$Revision;
6
6
  export type DriveRevisionList = drive_v3.Schema$RevisionList;
7
+ export type SharedDrive = drive_v3.Schema$Drive;
8
+ export type SharedDriveList = drive_v3.Schema$DriveList;
7
9
  export interface FileUploadOptions {
8
10
  name: string;
9
11
  mimeType?: string;
@@ -21,6 +23,12 @@ export interface FileListOptions {
21
23
  pageToken?: string;
22
24
  orderBy?: string[];
23
25
  fields?: string[];
26
+ driveId?: string;
27
+ corpora?: 'user' | 'drive' | 'allDrives';
28
+ }
29
+ export interface SharedDriveListOptions {
30
+ pageSize?: number;
31
+ pageToken?: string;
24
32
  }
25
33
  export interface FileSearchOptions extends FileListOptions {
26
34
  fullText?: string;
@@ -1,5 +1,6 @@
1
1
  import { google } from 'googleapis';
2
2
  import { BaseGoogleService } from '../../services/base/BaseGoogleService.js';
3
+ import { describeApiError } from '../../utils/apiError.js';
3
4
  import { FORMS_SCOPES } from './scopes.js';
4
5
  /**
5
6
  * Service for interacting with Google Forms API.
@@ -149,7 +150,7 @@ export class FormsService extends BaseGoogleService {
149
150
  catch (error) {
150
151
  return {
151
152
  success: false,
152
- error: error instanceof Error ? error.message : 'Unknown error occurred'
153
+ error: describeApiError(error)
153
154
  };
154
155
  }
155
156
  }
@@ -215,7 +216,7 @@ export class FormsService extends BaseGoogleService {
215
216
  catch (error) {
216
217
  return {
217
218
  success: false,
218
- error: error instanceof Error ? error.message : 'Unknown error occurred'
219
+ error: describeApiError(error)
219
220
  };
220
221
  }
221
222
  }
@@ -276,7 +277,7 @@ export class FormsService extends BaseGoogleService {
276
277
  catch (error) {
277
278
  return {
278
279
  success: false,
279
- error: error instanceof Error ? error.message : 'Unknown error occurred'
280
+ error: describeApiError(error)
280
281
  };
281
282
  }
282
283
  }
@@ -1,3 +1,4 @@
1
+ import { describeApiError } from '../../../utils/apiError.js';
1
2
  import { GmailError } from '../types.js';
2
3
  import { AttachmentIndexService } from '../../attachments/index-service.js';
3
4
  /**
@@ -112,7 +113,7 @@ export class GmailAttachmentService {
112
113
  catch (error) {
113
114
  if (error instanceof GmailError)
114
115
  throw error;
115
- throw new GmailError('Failed to get attachment', 'ATTACHMENT_ERROR', `Error: ${error instanceof Error ? error.message : 'Unknown error'}`);
116
+ throw new GmailError('Failed to get attachment', 'ATTACHMENT_ERROR', `Error: ${describeApiError(error)}`);
116
117
  }
117
118
  }
118
119
  /**
@@ -1,5 +1,6 @@
1
1
  import { google } from 'googleapis';
2
2
  import { BaseGoogleService } from '../../../services/base/BaseGoogleService.js';
3
+ import { describeApiError } from '../../../utils/apiError.js';
3
4
  import { GmailError } from '../types.js';
4
5
  import { EmailService } from './email.js';
5
6
  import { SearchService } from './search.js';
@@ -42,7 +43,7 @@ export class GmailService extends BaseGoogleService {
42
43
  this.initialized = true;
43
44
  }
44
45
  catch (error) {
45
- throw new GmailError('Failed to initialize Gmail service', 'INIT_ERROR', error instanceof Error ? error.message : 'Unknown error');
46
+ throw new GmailError('Failed to initialize Gmail service', 'INIT_ERROR', describeApiError(error));
46
47
  }
47
48
  }
48
49
  /**