@mindstone/mcp-server-google-workspace 0.2.0 → 0.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (69) hide show
  1. package/README.md +14 -8
  2. package/dist/modules/chat/index.d.ts +12 -0
  3. package/dist/modules/chat/index.js +18 -0
  4. package/dist/modules/chat/scopes.d.ts +14 -0
  5. package/dist/modules/chat/scopes.js +32 -0
  6. package/dist/modules/chat/types.d.ts +88 -0
  7. package/dist/modules/chat/types.js +14 -0
  8. package/dist/modules/comments/service.js +21 -1
  9. package/dist/modules/contacts/scopes.d.ts +1 -0
  10. package/dist/modules/contacts/scopes.js +2 -2
  11. package/dist/modules/contacts/types.d.ts +34 -0
  12. package/dist/modules/docs/service.js +29 -1
  13. package/dist/modules/drive/activity-service.d.ts +45 -0
  14. package/dist/modules/drive/activity-service.js +114 -0
  15. package/dist/modules/drive/index.d.ts +4 -0
  16. package/dist/modules/drive/index.js +12 -0
  17. package/dist/modules/drive/scopes.d.ts +1 -0
  18. package/dist/modules/drive/scopes.js +3 -0
  19. package/dist/modules/forms/service.js +13 -1
  20. package/dist/modules/gmail/services/base.d.ts +5 -1
  21. package/dist/modules/gmail/services/base.js +8 -0
  22. package/dist/modules/gmail/services/settings.d.ts +14 -1
  23. package/dist/modules/gmail/services/settings.js +94 -0
  24. package/dist/modules/gmail/types.d.ts +36 -0
  25. package/dist/modules/meet/index.d.ts +12 -0
  26. package/dist/modules/meet/index.js +18 -0
  27. package/dist/modules/meet/scopes.d.ts +9 -0
  28. package/dist/modules/meet/scopes.js +25 -0
  29. package/dist/modules/meet/types.d.ts +97 -0
  30. package/dist/modules/meet/types.js +14 -0
  31. package/dist/modules/sheets/service.js +49 -0
  32. package/dist/modules/slides/service.js +25 -1
  33. package/dist/modules/tasks/service.js +25 -1
  34. package/dist/services/base/BaseGoogleService.d.ts +9 -1
  35. package/dist/services/base/BaseGoogleService.js +26 -1
  36. package/dist/services/chat/index.d.ts +34 -0
  37. package/dist/services/chat/index.js +120 -0
  38. package/dist/services/contacts/index.d.ts +19 -1
  39. package/dist/services/contacts/index.js +124 -0
  40. package/dist/services/meet/index.d.ts +35 -0
  41. package/dist/services/meet/index.js +116 -0
  42. package/dist/tools/chat-handlers.d.ts +14 -0
  43. package/dist/tools/chat-handlers.js +126 -0
  44. package/dist/tools/contacts-handlers.d.ts +31 -0
  45. package/dist/tools/contacts-handlers.js +88 -0
  46. package/dist/tools/definitions/chat.d.ts +3 -0
  47. package/dist/tools/definitions/chat.js +137 -0
  48. package/dist/tools/definitions/contacts.js +82 -0
  49. package/dist/tools/definitions/destructive-overrides.json +11 -0
  50. package/dist/tools/definitions/drive.js +48 -0
  51. package/dist/tools/definitions/gmail.js +94 -0
  52. package/dist/tools/definitions/index.d.ts +2 -0
  53. package/dist/tools/definitions/index.js +6 -0
  54. package/dist/tools/definitions/meet.d.ts +3 -0
  55. package/dist/tools/definitions/meet.js +149 -0
  56. package/dist/tools/definitions/open-world-overrides.json +11 -0
  57. package/dist/tools/drive-handlers.d.ts +17 -0
  58. package/dist/tools/drive-handlers.js +49 -1
  59. package/dist/tools/gmail-handlers.d.ts +24 -0
  60. package/dist/tools/gmail-handlers.js +129 -11
  61. package/dist/tools/meet-handlers.d.ts +42 -0
  62. package/dist/tools/meet-handlers.js +144 -0
  63. package/dist/tools/server.js +53 -3
  64. package/dist/utils/apiError.js +5 -2
  65. package/dist/utils/scope-hierarchy.js +10 -0
  66. package/dist/utils/service-initializer.js +9 -0
  67. package/dist/utils/untrusted-content.d.ts +37 -1
  68. package/dist/utils/untrusted-content.js +61 -6
  69. package/package.json +1 -1
package/README.md CHANGED
@@ -2,15 +2,15 @@
2
2
 
3
3
  [![License: FSL-1.1-MIT](https://img.shields.io/badge/License-FSL--1.1--MIT-blue.svg)](./LICENSE)
4
4
 
5
- Google Workspace MCP server — Gmail, Calendar, Drive, Docs, Sheets, Slides, Contacts, Comments, and account diagnostics, with optional Tasks and Forms behind a feature flag.
5
+ Google Workspace MCP server — Gmail, Calendar, Drive, Docs, Sheets, Slides, Contacts, Chat, Meet, Comments, and account diagnostics, with optional Tasks and Forms behind a feature flag.
6
6
 
7
7
  *Multi-account Google Workspace MCP. Host-orchestrated OAuth (the connector neither runs a callback server nor mints OAuth URLs), atomic per-account credential writes, and a structured `auth_required` handoff so the host drives the sign-in flow rather than the server.*
8
8
 
9
9
  ## Status
10
10
 
11
- - **Version:** [0.2.0](./CHANGELOG.md) · npm: not yet published
11
+ - **Version:** [0.3.0](./CHANGELOG.md) · npm: not yet published
12
12
  - **Auth:** OAuth (host-orchestrated) ([`GOOGLE_CLIENT_SECRET`](./server.json))
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`)
13
+ - **Tools:** [106](./src/tools/definitions/) (Gmail, Calendar, Drive, Docs, Sheets, Slides, Contacts, Chat, Meet, 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
 
@@ -153,26 +153,28 @@ Until the host has written `${ACCOUNTS_PATH}` and the matching per-account token
153
153
  }
154
154
  ```
155
155
 
156
- ## Tools (95)
156
+ ## Tools (106)
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
 
160
160
  | Domain | Tools | Notes |
161
161
  | --- | --- | --- |
162
- | Gmail | 21 | Email search/thread/send/compose, drafts, labels, label filters, attachments, archive/trash/read-state helpers. |
162
+ | Gmail | 23 | Email search/thread/send/compose, drafts, labels, label filters, attachments, archive/trash/read-state helpers, settings, vacation responder, and send-as aliases/signatures. |
163
163
  | Calendar | 9 | Current time, free-slot lookup, calendar/event listing, event creation, updates, responses, and deletion. |
164
- | Drive | 14 | List/search/upload/download/copy/move/trash/untrash files, folders, permissions, revisions, and shared-drive discovery. |
164
+ | Drive | 15 | List/search/upload/download/copy/move/trash/untrash files, folders, permissions, revisions, shared-drive discovery, and activity queries (what changed, when, by whom). |
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. |
168
168
  | Labels | 12 | Gmail label CRUD and filter rules. |
169
- | Contacts | 2 | List and search contacts. |
169
+ | Contacts | 4 | List, search, create, and update contacts. |
170
+ | Chat | 3 | List spaces, list messages in a space, and send text messages. |
171
+ | Meet | 3 | List conference records, list transcripts, and read transcript entries (speaker + text). |
170
172
  | Comments | 5 | List/create/reply/resolve/delete Drive comments. |
171
173
  | Account | 3 | List, authenticate, and remove workspace accounts. |
172
174
  | Tasks (gated) | 6 | Registered only when `ENABLE_GOOGLE_TASKS_FORMS=true`. |
173
175
  | Forms (gated) | 4 | Registered only when `ENABLE_GOOGLE_TASKS_FORMS=true`. |
174
176
 
175
- The `## Status` block counts the 95 default-enabled tools; the additional 10 Tasks + Forms tools register when the feature flag is set.
177
+ The `## Status` block counts the 106 default-enabled tools; the additional 10 Tasks + Forms tools register when the feature flag is set.
176
178
 
177
179
  ### Shared drives
178
180
 
@@ -187,6 +189,10 @@ Known Drive API limitations for shared-drive files (not fixable in this connecto
187
189
  - 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
190
  - The Revisions API does not support shared-drive files, so `list_file_revisions` / `download_file_revision` only work for My Drive files.
189
191
 
192
+ ### Vacation responder
193
+
194
+ `update_workspace_vacation_responder` merges with the existing settings (the Gmail API otherwise replaces the whole resource): omitted subject/body are kept, an existing HTML body stays HTML, and a pending scheduled end is preserved when `end_time` is omitted. To remove a scheduled end and make the auto-reply open-ended, pass `clear_end_time: true` (mutually exclusive with `end_time`). An already-past end is never carried into a re-enable.
195
+
190
196
  ## Security notes
191
197
 
192
198
  - Token and account writes use temp-file plus rename, restrictive permissions, fsync, and symlink rejection.
@@ -0,0 +1,12 @@
1
+ /**
2
+ * Chat module entry point.
3
+ * Exports types, services, and initialization functions for the Google Chat module.
4
+ */
5
+ export * from './types.js';
6
+ export { CHAT_SCOPES, registerChatScopes } from './scopes.js';
7
+ /**
8
+ * Initialize the chat module.
9
+ * This function is called during server startup to set up any required resources.
10
+ */
11
+ export declare function initializeChatModule(): Promise<void>;
12
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1,18 @@
1
+ /**
2
+ * Chat module entry point.
3
+ * Exports types, services, and initialization functions for the Google Chat module.
4
+ */
5
+ // Export types
6
+ export * from './types.js';
7
+ // Export scopes
8
+ export { CHAT_SCOPES, registerChatScopes } from './scopes.js';
9
+ /**
10
+ * Initialize the chat module.
11
+ * This function is called during server startup to set up any required resources.
12
+ */
13
+ export async function initializeChatModule() {
14
+ // Currently no async initialization needed
15
+ // This function is a placeholder for future initialization logic
16
+ return Promise.resolve();
17
+ }
18
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1,14 @@
1
+ export declare const CHAT_SCOPES: {
2
+ SPACES_READONLY: string;
3
+ MESSAGES_READONLY: string;
4
+ MESSAGES_CREATE: string;
5
+ };
6
+ /**
7
+ * Register Google Chat OAuth scopes at startup.
8
+ * Auth issues will be handled via 401 responses rather than pre-validation.
9
+ *
10
+ * Read scopes are registered first, followed by the write scope (order matters
11
+ * for auth URL generation).
12
+ */
13
+ export declare function registerChatScopes(): void;
14
+ //# sourceMappingURL=scopes.d.ts.map
@@ -0,0 +1,32 @@
1
+ import { scopeRegistry } from "../tools/scope-registry.js";
2
+ // Define Google Chat scopes as constants for reuse and testing
3
+ // Reference: https://developers.google.com/workspace/chat/api/reference/rest/v1/spaces/list
4
+ // (and the spaces.messages.list / spaces.messages.create method docs)
5
+ export const CHAT_SCOPES = {
6
+ // List spaces the authenticated user belongs to (spaces.list)
7
+ SPACES_READONLY: "https://www.googleapis.com/auth/chat.spaces.readonly",
8
+ // Read messages in a space (spaces.messages.list)
9
+ MESSAGES_READONLY: "https://www.googleapis.com/auth/chat.messages.readonly",
10
+ // Post a message to a space as the authenticated user (spaces.messages.create)
11
+ MESSAGES_CREATE: "https://www.googleapis.com/auth/chat.messages.create"
12
+ };
13
+ /**
14
+ * Register Google Chat OAuth scopes at startup.
15
+ * Auth issues will be handled via 401 responses rather than pre-validation.
16
+ *
17
+ * Read scopes are registered first, followed by the write scope (order matters
18
+ * for auth URL generation).
19
+ */
20
+ export function registerChatScopes() {
21
+ scopeRegistry.registerScope("chat", CHAT_SCOPES.SPACES_READONLY);
22
+ scopeRegistry.registerScope("chat", CHAT_SCOPES.MESSAGES_READONLY);
23
+ scopeRegistry.registerScope("chat", CHAT_SCOPES.MESSAGES_CREATE);
24
+ // Verify all scopes are registered
25
+ const registeredScopes = scopeRegistry.getAllScopes();
26
+ const requiredScopes = Object.values(CHAT_SCOPES);
27
+ const missingScopes = requiredScopes.filter(scope => !registeredScopes.includes(scope));
28
+ if (missingScopes.length > 0) {
29
+ throw new Error(`Failed to register Chat scopes: ${missingScopes.join(', ')}`);
30
+ }
31
+ }
32
+ //# sourceMappingURL=scopes.js.map
@@ -0,0 +1,88 @@
1
+ /**
2
+ * Parameters for listing Google Chat spaces.
3
+ */
4
+ export interface ListChatSpacesParams {
5
+ email: string;
6
+ pageSize?: number;
7
+ pageToken?: string;
8
+ filter?: string;
9
+ }
10
+ /**
11
+ * Response structure for listing spaces.
12
+ */
13
+ export interface ListChatSpacesResponse {
14
+ spaces: ChatSpace[];
15
+ nextPageToken?: string;
16
+ }
17
+ /**
18
+ * Parameters for listing messages in a space.
19
+ */
20
+ export interface ListChatMessagesParams {
21
+ email: string;
22
+ parent: string;
23
+ pageSize?: number;
24
+ pageToken?: string;
25
+ filter?: string;
26
+ orderBy?: string;
27
+ }
28
+ /**
29
+ * Response structure for listing messages.
30
+ */
31
+ export interface ListChatMessagesResponse {
32
+ messages: ChatMessage[];
33
+ nextPageToken?: string;
34
+ }
35
+ /**
36
+ * Parameters for sending a text message to a space.
37
+ */
38
+ export interface SendChatMessageParams {
39
+ email: string;
40
+ parent: string;
41
+ text: string;
42
+ }
43
+ /**
44
+ * Represents a Google Chat space (DM, group chat, or named space).
45
+ * Based on the Chat API Space resource.
46
+ * Reference: https://developers.google.com/workspace/chat/api/reference/rest/v1/spaces#Space
47
+ */
48
+ export interface ChatSpace {
49
+ name: string;
50
+ displayName?: string;
51
+ spaceType?: string;
52
+ singleUserBotDm?: boolean;
53
+ threaded?: boolean;
54
+ externalUserAllowed?: boolean;
55
+ spaceUri?: string;
56
+ createTime?: string;
57
+ }
58
+ /**
59
+ * Represents a user (sender) on a Chat message.
60
+ */
61
+ export interface ChatUser {
62
+ name?: string;
63
+ displayName?: string;
64
+ type?: string;
65
+ }
66
+ /**
67
+ * Represents a Google Chat message.
68
+ * Based on the Chat API Message resource.
69
+ * Reference: https://developers.google.com/workspace/chat/api/reference/rest/v1/spaces.messages#Message
70
+ */
71
+ export interface ChatMessage {
72
+ name: string;
73
+ text?: string;
74
+ createTime?: string;
75
+ sender?: ChatUser;
76
+ thread?: {
77
+ name?: string;
78
+ };
79
+ }
80
+ /**
81
+ * Base error class for Chat service.
82
+ */
83
+ export declare class ChatError extends Error {
84
+ code: string;
85
+ details?: string;
86
+ constructor(message: string, code: string, details?: string);
87
+ }
88
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1,14 @@
1
+ /**
2
+ * Base error class for Chat service.
3
+ */
4
+ export class ChatError extends Error {
5
+ code;
6
+ details;
7
+ constructor(message, code, details) {
8
+ super(message);
9
+ this.name = "ChatError";
10
+ this.code = code;
11
+ this.details = details;
12
+ }
13
+ }
14
+ //# sourceMappingURL=types.js.map
@@ -1,6 +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
+ import { describeApiError, isAuthHandoffError } from '../../utils/apiError.js';
4
4
  import { DRIVE_SCOPES } from '../drive/scopes.js';
5
5
  const DEFAULT_PAGE_SIZE = 20;
6
6
  // Fields parameter for comments.list — Google API requires explicit field selection
@@ -97,6 +97,10 @@ export class CommentsService extends BaseGoogleService {
97
97
  };
98
98
  }
99
99
  catch (error) {
100
+ // An expired/revoked grant must keep its reconnect signal — folding it
101
+ // into a plain error string would skip the host's auth_required handoff.
102
+ if (isAuthHandoffError(error))
103
+ throw error;
100
104
  return {
101
105
  success: false,
102
106
  error: describeApiError(error),
@@ -135,6 +139,10 @@ export class CommentsService extends BaseGoogleService {
135
139
  };
136
140
  }
137
141
  catch (error) {
142
+ // An expired/revoked grant must keep its reconnect signal — folding it
143
+ // into a plain error string would skip the host's auth_required handoff.
144
+ if (isAuthHandoffError(error))
145
+ throw error;
138
146
  return {
139
147
  success: false,
140
148
  error: describeApiError(error),
@@ -165,6 +173,10 @@ export class CommentsService extends BaseGoogleService {
165
173
  };
166
174
  }
167
175
  catch (error) {
176
+ // An expired/revoked grant must keep its reconnect signal — folding it
177
+ // into a plain error string would skip the host's auth_required handoff.
178
+ if (isAuthHandoffError(error))
179
+ throw error;
168
180
  return {
169
181
  success: false,
170
182
  error: describeApiError(error),
@@ -194,6 +206,10 @@ export class CommentsService extends BaseGoogleService {
194
206
  };
195
207
  }
196
208
  catch (error) {
209
+ // An expired/revoked grant must keep its reconnect signal — folding it
210
+ // into a plain error string would skip the host's auth_required handoff.
211
+ if (isAuthHandoffError(error))
212
+ throw error;
197
213
  return {
198
214
  success: false,
199
215
  error: describeApiError(error),
@@ -218,6 +234,10 @@ export class CommentsService extends BaseGoogleService {
218
234
  };
219
235
  }
220
236
  catch (error) {
237
+ // An expired/revoked grant must keep its reconnect signal — folding it
238
+ // into a plain error string would skip the host's auth_required handoff.
239
+ if (isAuthHandoffError(error))
240
+ throw error;
221
241
  return {
222
242
  success: false,
223
243
  error: describeApiError(error),
@@ -1,4 +1,5 @@
1
1
  export declare const CONTACTS_SCOPES: {
2
2
  READONLY: string;
3
+ CONTACTS: string;
3
4
  };
4
5
  //# sourceMappingURL=scopes.d.ts.map
@@ -3,8 +3,8 @@ import { scopeRegistry } from "../../modules/tools/scope-registry.js";
3
3
  // Reference: https://developers.google.com/people/api/rest/v1/people.connections/list (and other People API docs)
4
4
  export const CONTACTS_SCOPES = {
5
5
  READONLY: "https://www.googleapis.com/auth/contacts.readonly",
6
- // Add other scopes like write/modify later if needed
7
- // CONTACTS: 'https://www.googleapis.com/auth/contacts'
6
+ // Full contacts access (read + write); required for people.createContact / people.updateContact
7
+ CONTACTS: "https://www.googleapis.com/auth/contacts"
8
8
  };
9
9
  // Register the contacts scopes with the scope registry
10
10
  scopeRegistry.registerScope("contacts", CONTACTS_SCOPES.READONLY);
@@ -52,4 +52,38 @@ export declare class ContactsError extends Error {
52
52
  details?: string;
53
53
  constructor(message: string, code: string, details?: string);
54
54
  }
55
+ /**
56
+ * Fields accepted when creating or updating a contact.
57
+ * All fields are optional at the type level; handlers enforce that at least
58
+ * one is provided (and that create has a name or email).
59
+ */
60
+ export interface ContactWriteFields {
61
+ givenName?: string;
62
+ familyName?: string;
63
+ emailAddress?: string;
64
+ emailType?: string;
65
+ phoneNumber?: string;
66
+ phoneType?: string;
67
+ organization?: string;
68
+ jobTitle?: string;
69
+ notes?: string;
70
+ }
71
+ export interface CreateContactParams extends ContactWriteFields {
72
+ email: string;
73
+ }
74
+ export interface UpdateContactParams extends ContactWriteFields {
75
+ email: string;
76
+ resourceName: string;
77
+ }
78
+ /**
79
+ * Compact summary of a written contact, returned to the caller.
80
+ */
81
+ export interface ContactWriteResult {
82
+ resourceName: string;
83
+ etag?: string;
84
+ displayName?: string;
85
+ email?: string;
86
+ phone?: string;
87
+ organization?: string;
88
+ }
55
89
  //# sourceMappingURL=types.d.ts.map
@@ -1,7 +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
+ import { describeApiError, isAuthHandoffError } from '../../utils/apiError.js';
5
5
  const DEFAULT_MAX_CHARS = 50000;
6
6
  const TRUNCATION_MARKER = '\n\n[TRUNCATED - document exceeds character limit]';
7
7
  export class DocsService extends BaseGoogleService {
@@ -126,6 +126,10 @@ export class DocsService extends BaseGoogleService {
126
126
  };
127
127
  }
128
128
  catch (error) {
129
+ // An expired/revoked grant must keep its reconnect signal — folding it
130
+ // into a plain error string would skip the host's auth_required handoff.
131
+ if (isAuthHandoffError(error))
132
+ throw error;
129
133
  return {
130
134
  success: false,
131
135
  error: describeApiError(error),
@@ -181,6 +185,10 @@ export class DocsService extends BaseGoogleService {
181
185
  };
182
186
  }
183
187
  catch (error) {
188
+ // An expired/revoked grant must keep its reconnect signal — folding it
189
+ // into a plain error string would skip the host's auth_required handoff.
190
+ if (isAuthHandoffError(error))
191
+ throw error;
184
192
  return {
185
193
  success: false,
186
194
  error: describeApiError(error),
@@ -226,6 +234,10 @@ export class DocsService extends BaseGoogleService {
226
234
  };
227
235
  }
228
236
  catch (error) {
237
+ // An expired/revoked grant must keep its reconnect signal — folding it
238
+ // into a plain error string would skip the host's auth_required handoff.
239
+ if (isAuthHandoffError(error))
240
+ throw error;
229
241
  return {
230
242
  success: false,
231
243
  error: describeApiError(error),
@@ -282,6 +294,10 @@ export class DocsService extends BaseGoogleService {
282
294
  };
283
295
  }
284
296
  catch (error) {
297
+ // An expired/revoked grant must keep its reconnect signal — folding it
298
+ // into a plain error string would skip the host's auth_required handoff.
299
+ if (isAuthHandoffError(error))
300
+ throw error;
285
301
  return {
286
302
  success: false,
287
303
  error: describeApiError(error),
@@ -335,6 +351,10 @@ export class DocsService extends BaseGoogleService {
335
351
  };
336
352
  }
337
353
  catch (error) {
354
+ // An expired/revoked grant must keep its reconnect signal — folding it
355
+ // into a plain error string would skip the host's auth_required handoff.
356
+ if (isAuthHandoffError(error))
357
+ throw error;
338
358
  return {
339
359
  success: false,
340
360
  error: describeApiError(error),
@@ -369,6 +389,10 @@ export class DocsService extends BaseGoogleService {
369
389
  };
370
390
  }
371
391
  catch (error) {
392
+ // An expired/revoked grant must keep its reconnect signal — folding it
393
+ // into a plain error string would skip the host's auth_required handoff.
394
+ if (isAuthHandoffError(error))
395
+ throw error;
372
396
  return {
373
397
  success: false,
374
398
  error: describeApiError(error),
@@ -412,6 +436,10 @@ export class DocsService extends BaseGoogleService {
412
436
  };
413
437
  }
414
438
  catch (error) {
439
+ // An expired/revoked grant must keep its reconnect signal — folding it
440
+ // into a plain error string would skip the host's auth_required handoff.
441
+ if (isAuthHandoffError(error))
442
+ throw error;
415
443
  return {
416
444
  success: false,
417
445
  error: describeApiError(error),
@@ -0,0 +1,45 @@
1
+ import { driveactivity_v2 } from 'googleapis';
2
+ import { BaseGoogleService } from '../../services/base/BaseGoogleService.js';
3
+ export interface QueryDriveActivityOptions {
4
+ /** Drive item to inspect ("items/<id>" or a bare file/folder ID). */
5
+ itemName?: string;
6
+ /** Folder or shared drive whose subtree to inspect ("items/<id>" or bare ID). */
7
+ ancestorName?: string;
8
+ pageSize?: number;
9
+ pageToken?: string;
10
+ /** Drive Activity API filter string, passed through verbatim. */
11
+ filter?: string;
12
+ }
13
+ export interface DriveActivitySummary {
14
+ action: string;
15
+ timestamp?: string;
16
+ actors: string[];
17
+ targets: Array<{
18
+ title?: string;
19
+ name?: string;
20
+ mimeType?: string;
21
+ }>;
22
+ }
23
+ export interface QueryDriveActivityResult {
24
+ activities: DriveActivitySummary[];
25
+ nextPageToken?: string;
26
+ }
27
+ /**
28
+ * Normalizes a user-supplied item/ancestor reference to the API's resource
29
+ * form ("items/<id>"); accepts the resource form or a bare Drive ID.
30
+ */
31
+ export declare function normalizeDriveItemName(value: string): string;
32
+ /**
33
+ * Service for the Drive Activity API v2 — answers "what changed in this
34
+ * file/folder/shared drive". Kept separate from DriveService because
35
+ * BaseGoogleService caches one client per email and the activity API is a
36
+ * different client (google.driveactivity v2).
37
+ */
38
+ export declare class DriveActivityService extends BaseGoogleService<driveactivity_v2.Driveactivity> {
39
+ private initialized;
40
+ constructor();
41
+ initialize(): Promise<void>;
42
+ ensureInitialized(): Promise<void>;
43
+ queryActivity(email: string, options: QueryDriveActivityOptions): Promise<QueryDriveActivityResult>;
44
+ }
45
+ //# sourceMappingURL=activity-service.d.ts.map
@@ -0,0 +1,114 @@
1
+ import { google } from 'googleapis';
2
+ import { BaseGoogleService } from '../../services/base/BaseGoogleService.js';
3
+ import { DRIVE_SCOPES } from './scopes.js';
4
+ import { wrapUntrustedContent } from '../../utils/untrusted-content.js';
5
+ const KNOWN_ACTIONS = [
6
+ 'create', 'edit', 'move', 'rename', 'delete', 'restore',
7
+ 'permissionChange', 'comment', 'dlpChange', 'reference', 'settingsChange',
8
+ ];
9
+ /**
10
+ * Normalizes a user-supplied item/ancestor reference to the API's resource
11
+ * form ("items/<id>"); accepts the resource form or a bare Drive ID.
12
+ */
13
+ export function normalizeDriveItemName(value) {
14
+ return value.startsWith('items/') ? value : `items/${value}`;
15
+ }
16
+ function summarizeAction(detail) {
17
+ if (!detail)
18
+ return 'unknown';
19
+ for (const action of KNOWN_ACTIONS) {
20
+ if (detail[action] !== undefined && detail[action] !== null)
21
+ return action;
22
+ }
23
+ return 'unknown';
24
+ }
25
+ function summarizeActor(actor) {
26
+ if (actor.user?.knownUser) {
27
+ return actor.user.knownUser.isCurrentUser
28
+ ? 'you'
29
+ : actor.user.knownUser.personName || 'a known user';
30
+ }
31
+ if (actor.user?.deletedUser)
32
+ return 'a deleted user';
33
+ if (actor.anonymous)
34
+ return 'an anonymous user';
35
+ if (actor.system)
36
+ return 'Google Workspace (system)';
37
+ if (actor.administrator)
38
+ return 'an administrator';
39
+ return 'unknown actor';
40
+ }
41
+ function summarizeTarget(target) {
42
+ // Titles are authored in Drive (attacker-controlled) and get the envelope;
43
+ // resource names / MIME types are structural identifiers and stay raw so the
44
+ // caller can use them directly.
45
+ const wrapTitle = (title) => title ? wrapUntrustedContent(title, 'google-workspace:drive:activity') : undefined;
46
+ if (target.driveItem) {
47
+ return {
48
+ title: wrapTitle(target.driveItem.title),
49
+ name: target.driveItem.name || undefined,
50
+ mimeType: target.driveItem.mimeType || undefined,
51
+ };
52
+ }
53
+ if (target.drive) {
54
+ return { title: wrapTitle(target.drive.title), name: target.drive.name || undefined };
55
+ }
56
+ if (target.fileComment) {
57
+ return { title: wrapTitle(target.fileComment.parent?.title), name: target.fileComment.parent?.name || undefined };
58
+ }
59
+ if (target.teamDrive) {
60
+ return { title: wrapTitle(target.teamDrive.title), name: target.teamDrive.name || undefined };
61
+ }
62
+ return {};
63
+ }
64
+ /**
65
+ * Service for the Drive Activity API v2 — answers "what changed in this
66
+ * file/folder/shared drive". Kept separate from DriveService because
67
+ * BaseGoogleService caches one client per email and the activity API is a
68
+ * different client (google.driveactivity v2).
69
+ */
70
+ export class DriveActivityService extends BaseGoogleService {
71
+ initialized = false;
72
+ constructor() {
73
+ super({ serviceName: 'Google Drive Activity', version: 'v2' });
74
+ }
75
+ async initialize() {
76
+ try {
77
+ await super.initialize();
78
+ this.initialized = true;
79
+ }
80
+ catch (error) {
81
+ throw this.handleError(error, 'Failed to initialize Drive Activity service');
82
+ }
83
+ }
84
+ async ensureInitialized() {
85
+ if (!this.initialized) {
86
+ await this.initialize();
87
+ }
88
+ }
89
+ async queryActivity(email, options) {
90
+ await this.ensureInitialized();
91
+ await this.validateScopes(email, [DRIVE_SCOPES.ACTIVITY_READONLY]);
92
+ const client = await this.getAuthenticatedClient(email, (auth) => google.driveactivity({ version: 'v2', auth }));
93
+ const response = await client.activity.query({
94
+ requestBody: {
95
+ ...(options.itemName && { itemName: options.itemName }),
96
+ ...(options.ancestorName && { ancestorName: options.ancestorName }),
97
+ ...(options.pageSize && { pageSize: options.pageSize }),
98
+ ...(options.pageToken && { pageToken: options.pageToken }),
99
+ ...(options.filter && { filter: options.filter }),
100
+ }
101
+ });
102
+ const activities = (response.data.activities || []).map(activity => ({
103
+ action: summarizeAction(activity.primaryActionDetail),
104
+ timestamp: activity.timestamp ?? activity.timeRange?.endTime ?? undefined,
105
+ actors: (activity.actors || []).map(summarizeActor),
106
+ targets: (activity.targets || []).map(summarizeTarget),
107
+ }));
108
+ return {
109
+ activities,
110
+ nextPageToken: response.data.nextPageToken || undefined,
111
+ };
112
+ }
113
+ }
114
+ //# sourceMappingURL=activity-service.js.map
@@ -1,9 +1,13 @@
1
1
  import { DriveService } from './service.js';
2
+ import { DriveActivityService } from './activity-service.js';
2
3
  import { DriveOperationResult } from './types.js';
3
4
  export * from './types.js';
4
5
  export * from './scopes.js';
5
6
  export { DriveService };
7
+ export { DriveActivityService } from './activity-service.js';
8
+ export type { QueryDriveActivityOptions, QueryDriveActivityResult, DriveActivitySummary } from './activity-service.js';
6
9
  export declare function getDriveService(): Promise<DriveService>;
10
+ export declare function getDriveActivityService(): Promise<DriveActivityService>;
7
11
  export declare function initializeDriveModule(): Promise<void>;
8
12
  export declare function handleDriveError(error: unknown): DriveOperationResult;
9
13
  //# sourceMappingURL=index.d.ts.map
@@ -1,9 +1,11 @@
1
1
  import { driveService } from '../../services/drive/index.js';
2
2
  import { DriveService } from './service.js';
3
+ import { DriveActivityService } from './activity-service.js';
3
4
  // Export types and service
4
5
  export * from './types.js';
5
6
  export * from './scopes.js';
6
7
  export { DriveService };
8
+ export { DriveActivityService } from './activity-service.js';
7
9
  // Get singleton instance
8
10
  let serviceInstance;
9
11
  export async function getDriveService() {
@@ -13,6 +15,16 @@ export async function getDriveService() {
13
15
  }
14
16
  return serviceInstance;
15
17
  }
18
+ // Drive Activity API client (separate service: BaseGoogleService caches one
19
+ // client per email, and the activity API is a different googleapis client).
20
+ let activityServiceInstance;
21
+ export async function getDriveActivityService() {
22
+ if (!activityServiceInstance) {
23
+ activityServiceInstance = new DriveActivityService();
24
+ await activityServiceInstance.ensureInitialized();
25
+ }
26
+ return activityServiceInstance;
27
+ }
16
28
  // Initialize module
17
29
  export async function initializeDriveModule() {
18
30
  const service = await getDriveService();
@@ -3,6 +3,7 @@ export declare const DRIVE_SCOPES: {
3
3
  readonly READONLY: "https://www.googleapis.com/auth/drive.readonly";
4
4
  readonly FILE: "https://www.googleapis.com/auth/drive.file";
5
5
  readonly APPDATA: "https://www.googleapis.com/auth/drive.appdata";
6
+ readonly ACTIVITY_READONLY: "https://www.googleapis.com/auth/drive.activity.readonly";
6
7
  };
7
8
  export type DriveScope = typeof DRIVE_SCOPES[keyof typeof DRIVE_SCOPES];
8
9
  /**