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

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (96) hide show
  1. package/README.md +28 -9
  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/chat/index.d.ts +12 -0
  8. package/dist/modules/chat/index.js +18 -0
  9. package/dist/modules/chat/scopes.d.ts +14 -0
  10. package/dist/modules/chat/scopes.js +32 -0
  11. package/dist/modules/chat/types.d.ts +88 -0
  12. package/dist/modules/chat/types.js +14 -0
  13. package/dist/modules/comments/service.js +26 -5
  14. package/dist/modules/contacts/scopes.d.ts +1 -0
  15. package/dist/modules/contacts/scopes.js +2 -2
  16. package/dist/modules/contacts/types.d.ts +34 -0
  17. package/dist/modules/docs/index.js +2 -1
  18. package/dist/modules/docs/service.js +36 -7
  19. package/dist/modules/drive/activity-service.d.ts +45 -0
  20. package/dist/modules/drive/activity-service.js +114 -0
  21. package/dist/modules/drive/index.d.ts +4 -0
  22. package/dist/modules/drive/index.js +12 -0
  23. package/dist/modules/drive/scopes.d.ts +1 -0
  24. package/dist/modules/drive/scopes.js +3 -0
  25. package/dist/modules/drive/service.d.ts +2 -1
  26. package/dist/modules/drive/service.js +29 -0
  27. package/dist/modules/drive/types.d.ts +8 -0
  28. package/dist/modules/forms/service.js +16 -3
  29. package/dist/modules/gmail/services/attachment.js +2 -1
  30. package/dist/modules/gmail/services/base.d.ts +5 -1
  31. package/dist/modules/gmail/services/base.js +10 -1
  32. package/dist/modules/gmail/services/draft.js +13 -7
  33. package/dist/modules/gmail/services/email.js +4 -3
  34. package/dist/modules/gmail/services/label.js +10 -9
  35. package/dist/modules/gmail/services/settings.d.ts +14 -1
  36. package/dist/modules/gmail/services/settings.js +96 -1
  37. package/dist/modules/gmail/types.d.ts +36 -0
  38. package/dist/modules/meet/index.d.ts +12 -0
  39. package/dist/modules/meet/index.js +18 -0
  40. package/dist/modules/meet/scopes.d.ts +9 -0
  41. package/dist/modules/meet/scopes.js +25 -0
  42. package/dist/modules/meet/types.d.ts +97 -0
  43. package/dist/modules/meet/types.js +14 -0
  44. package/dist/modules/sheets/service.js +49 -0
  45. package/dist/modules/slides/service.js +31 -6
  46. package/dist/modules/tasks/service.js +31 -6
  47. package/dist/resources/compose-email-template.d.ts +1 -1
  48. package/dist/resources/compose-email-template.js +388 -19
  49. package/dist/services/base/BaseGoogleService.d.ts +9 -1
  50. package/dist/services/base/BaseGoogleService.js +33 -1
  51. package/dist/services/chat/index.d.ts +34 -0
  52. package/dist/services/chat/index.js +120 -0
  53. package/dist/services/contacts/index.d.ts +19 -1
  54. package/dist/services/contacts/index.js +124 -0
  55. package/dist/services/meet/index.d.ts +35 -0
  56. package/dist/services/meet/index.js +116 -0
  57. package/dist/tools/calendar-handlers.js +28 -23
  58. package/dist/tools/chat-handlers.d.ts +14 -0
  59. package/dist/tools/chat-handlers.js +126 -0
  60. package/dist/tools/contacts-handlers.d.ts +31 -0
  61. package/dist/tools/contacts-handlers.js +96 -23
  62. package/dist/tools/definitions/account.js +8 -1
  63. package/dist/tools/definitions/chat.d.ts +3 -0
  64. package/dist/tools/definitions/chat.js +137 -0
  65. package/dist/tools/definitions/contacts.js +82 -0
  66. package/dist/tools/definitions/destructive-overrides.json +12 -0
  67. package/dist/tools/definitions/drive.js +132 -6
  68. package/dist/tools/definitions/gmail.js +94 -0
  69. package/dist/tools/definitions/index.d.ts +2 -0
  70. package/dist/tools/definitions/index.js +6 -0
  71. package/dist/tools/definitions/meet.d.ts +3 -0
  72. package/dist/tools/definitions/meet.js +149 -0
  73. package/dist/tools/definitions/open-world-overrides.json +12 -0
  74. package/dist/tools/drive-handlers.d.ts +27 -0
  75. package/dist/tools/drive-handlers.js +93 -2
  76. package/dist/tools/forms-handlers.js +5 -12
  77. package/dist/tools/gmail-handlers.d.ts +31 -1
  78. package/dist/tools/gmail-handlers.js +167 -35
  79. package/dist/tools/meet-handlers.d.ts +42 -0
  80. package/dist/tools/meet-handlers.js +144 -0
  81. package/dist/tools/server.js +67 -5
  82. package/dist/tools/tasks-handlers.js +7 -18
  83. package/dist/tools/type-guards.d.ts +3 -1
  84. package/dist/tools/type-guards.js +22 -2
  85. package/dist/tools/types.d.ts +13 -0
  86. package/dist/utils/apiError.d.ts +49 -0
  87. package/dist/utils/apiError.js +96 -0
  88. package/dist/utils/scope-hierarchy.js +10 -0
  89. package/dist/utils/service-initializer.js +9 -0
  90. package/dist/utils/untrusted-content.d.ts +37 -1
  91. package/dist/utils/untrusted-content.js +61 -6
  92. package/package.json +5 -1
  93. package/dist/services/calendar/index.d.ts +0 -27
  94. package/dist/services/calendar/index.js +0 -146
  95. package/dist/services/gmail/index.d.ts +0 -39
  96. package/dist/services/gmail/index.js +0 -337
@@ -0,0 +1,34 @@
1
+ import { google } from "googleapis";
2
+ import { BaseGoogleService } from "../base/BaseGoogleService.js";
3
+ import { ListChatSpacesParams, ListChatSpacesResponse, ListChatMessagesParams, ListChatMessagesResponse, SendChatMessageParams, ChatMessage } from "../../modules/chat/types.js";
4
+ type ChatApiClient = ReturnType<typeof google.chat>;
5
+ /**
6
+ * Chat service implementation extending BaseGoogleService.
7
+ * Handles Google Chat API specific operations (user-authenticated).
8
+ */
9
+ export declare class ChatService extends BaseGoogleService<ChatApiClient> {
10
+ constructor();
11
+ /**
12
+ * Gets an authenticated Chat API client for the specified account.
13
+ */
14
+ private getChatClient;
15
+ /**
16
+ * Lists spaces (DMs, group chats, named spaces) for the specified user account.
17
+ */
18
+ listSpaces(params: ListChatSpacesParams): Promise<ListChatSpacesResponse>;
19
+ /**
20
+ * Lists messages in a space for the specified user account.
21
+ */
22
+ listMessages(params: ListChatMessagesParams): Promise<ListChatMessagesResponse>;
23
+ /**
24
+ * Posts a plain-text message to a space as the authenticated user.
25
+ */
26
+ sendMessage(params: SendChatMessageParams): Promise<ChatMessage>;
27
+ /**
28
+ * Maps errors from Chat API operations to ChatError, mirroring the contacts service:
29
+ * GoogleServiceError keeps its code/details, anything else becomes an unknown error.
30
+ */
31
+ private toChatError;
32
+ }
33
+ export {};
34
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1,120 @@
1
+ import { google } from "googleapis";
2
+ import { BaseGoogleService, GoogleServiceError } from "../base/BaseGoogleService.js";
3
+ import { ChatError } from "../../modules/chat/types.js";
4
+ import { CHAT_SCOPES } from "../../modules/chat/scopes.js";
5
+ /**
6
+ * Chat service implementation extending BaseGoogleService.
7
+ * Handles Google Chat API specific operations (user-authenticated).
8
+ */
9
+ export class ChatService extends BaseGoogleService {
10
+ constructor() {
11
+ super({
12
+ serviceName: "chat",
13
+ version: "v1"
14
+ });
15
+ // Initialize immediately or ensure initialized before first use
16
+ this.initialize();
17
+ }
18
+ /**
19
+ * Gets an authenticated Chat API client for the specified account.
20
+ */
21
+ async getChatClient(email) {
22
+ // The clientFactory function tells BaseGoogleService how to create the specific client
23
+ return this.getAuthenticatedClient(email, (auth) => google.chat({ version: "v1", auth }));
24
+ }
25
+ /**
26
+ * Lists spaces (DMs, group chats, named spaces) for the specified user account.
27
+ */
28
+ async listSpaces(params) {
29
+ const { email, pageSize, pageToken, filter } = params;
30
+ try {
31
+ // Ensure necessary scopes are granted
32
+ await this.validateScopes(email, [CHAT_SCOPES.SPACES_READONLY]);
33
+ const chatApi = await this.getChatClient(email);
34
+ const response = await chatApi.spaces.list({
35
+ pageSize: pageSize,
36
+ pageToken: pageToken,
37
+ filter: filter
38
+ });
39
+ // Assume the response structure matches ListChatSpacesResponse;
40
+ // googleapis types use 'null' where we defined optional fields ('undefined')
41
+ return response.data;
42
+ }
43
+ catch (error) {
44
+ throw this.toChatError(error, "Error listing chat spaces");
45
+ }
46
+ }
47
+ /**
48
+ * Lists messages in a space for the specified user account.
49
+ */
50
+ async listMessages(params) {
51
+ const { email, parent, pageSize, pageToken, filter, orderBy } = params;
52
+ if (!parent) {
53
+ throw new ChatError("Missing required parameter: parent", "INVALID_PARAMS", 'Specify the space resource name (e.g. "spaces/AAAA...")');
54
+ }
55
+ try {
56
+ await this.validateScopes(email, [CHAT_SCOPES.MESSAGES_READONLY]);
57
+ const chatApi = await this.getChatClient(email);
58
+ const response = await chatApi.spaces.messages.list({
59
+ parent: parent,
60
+ pageSize: pageSize,
61
+ pageToken: pageToken,
62
+ filter: filter,
63
+ orderBy: orderBy
64
+ });
65
+ return response.data;
66
+ }
67
+ catch (error) {
68
+ throw this.toChatError(error, "Error listing chat messages");
69
+ }
70
+ }
71
+ /**
72
+ * Posts a plain-text message to a space as the authenticated user.
73
+ */
74
+ async sendMessage(params) {
75
+ const { email, parent, text } = params;
76
+ if (!parent) {
77
+ throw new ChatError("Missing required parameter: parent", "INVALID_PARAMS", 'Specify the space resource name (e.g. "spaces/AAAA...")');
78
+ }
79
+ if (!text) {
80
+ throw new ChatError("Missing required parameter: text", "INVALID_PARAMS", "Specify the message text to send");
81
+ }
82
+ try {
83
+ await this.validateScopes(email, [CHAT_SCOPES.MESSAGES_CREATE]);
84
+ const chatApi = await this.getChatClient(email);
85
+ const response = await chatApi.spaces.messages.create({
86
+ parent: parent,
87
+ requestBody: { text: text }
88
+ });
89
+ return response.data;
90
+ }
91
+ catch (error) {
92
+ throw this.toChatError(error, "Error sending chat message");
93
+ }
94
+ }
95
+ /**
96
+ * Maps errors from Chat API operations to ChatError, mirroring the contacts service:
97
+ * GoogleServiceError keeps its code/details, anything else becomes an unknown error.
98
+ */
99
+ toChatError(error, fallbackMessage) {
100
+ // Handle known GoogleServiceError specifically
101
+ if (error instanceof GoogleServiceError) {
102
+ // Assuming GoogleServiceError inherits message and data from McpError
103
+ // Use type assertion as the linter seems unsure
104
+ const gError = error;
105
+ return new ChatError(gError.message || fallbackMessage, // Fallback message
106
+ gError.data?.code || "GOOGLE_SERVICE_ERROR", // Code from data
107
+ gError.data?.details // Details from data
108
+ );
109
+ }
110
+ // Handle other potential errors (e.g. network errors)
111
+ else if (error instanceof Error) {
112
+ return new ChatError(`${fallbackMessage}: ${error.message}`, "UNKNOWN_API_ERROR");
113
+ }
114
+ // Handle non-Error throws
115
+ else {
116
+ return new ChatError(`${fallbackMessage} due to an unknown issue`, "UNKNOWN_INTERNAL_ERROR");
117
+ }
118
+ }
119
+ }
120
+ //# sourceMappingURL=index.js.map
@@ -1,6 +1,6 @@
1
1
  import { google } from "googleapis";
2
2
  import { BaseGoogleService } from "../base/BaseGoogleService.js";
3
- import { GetContactsParams, GetContactsResponse } from "../../modules/contacts/types.js";
3
+ import { GetContactsParams, GetContactsResponse, CreateContactParams, UpdateContactParams, ContactWriteResult } from "../../modules/contacts/types.js";
4
4
  type PeopleApiClient = ReturnType<typeof google.people>;
5
5
  /**
6
6
  * Contacts service implementation extending BaseGoogleService.
@@ -35,6 +35,24 @@ export declare class ContactsService extends BaseGoogleService<PeopleApiClient>
35
35
  }>;
36
36
  totalResults: number;
37
37
  }>;
38
+ /**
39
+ * Maps the flat write fields onto a People API Person request body.
40
+ * Only provided fields are included; `updatePersonFields` mirrors that set
41
+ * so an update replaces exactly the fields the caller sent.
42
+ */
43
+ private buildPersonRequestBody;
44
+ private toWriteResult;
45
+ private wrapWriteError;
46
+ /**
47
+ * Create a new contact via the People API.
48
+ */
49
+ createContact(params: CreateContactParams): Promise<ContactWriteResult>;
50
+ /**
51
+ * Update an existing contact via the People API. The People API requires the
52
+ * contact's current etag, so it is fetched first; only the provided fields
53
+ * are replaced (updatePersonFields semantics).
54
+ */
55
+ updateContact(params: UpdateContactParams): Promise<ContactWriteResult>;
38
56
  }
39
57
  export {};
40
58
  //# sourceMappingURL=index.d.ts.map
@@ -1,5 +1,6 @@
1
1
  import { google } from "googleapis";
2
2
  import { BaseGoogleService, GoogleServiceError } from "../base/BaseGoogleService.js";
3
+ import { describeApiError, isAuthHandoffError } from "../../utils/apiError.js";
3
4
  import { ContactsError } from "../../modules/contacts/types.js";
4
5
  import { CONTACTS_SCOPES } from "../../modules/contacts/scopes.js";
5
6
  /**
@@ -48,6 +49,8 @@ export class ContactsService extends BaseGoogleService {
48
49
  return response.data;
49
50
  }
50
51
  catch (error) {
52
+ if (isAuthHandoffError(error))
53
+ throw error;
51
54
  // Handle known GoogleServiceError specifically
52
55
  if (error instanceof GoogleServiceError) {
53
56
  // Assuming GoogleServiceError inherits message and data from McpError
@@ -113,6 +116,8 @@ export class ContactsService extends BaseGoogleService {
113
116
  };
114
117
  }
115
118
  catch (error) {
119
+ if (isAuthHandoffError(error))
120
+ throw error;
116
121
  if (error instanceof GoogleServiceError) {
117
122
  const gError = error;
118
123
  throw new ContactsError(gError.message || 'Error searching contacts', gError.data?.code || 'GOOGLE_SERVICE_ERROR', gError.data?.details);
@@ -125,6 +130,125 @@ export class ContactsService extends BaseGoogleService {
125
130
  }
126
131
  }
127
132
  }
133
+ /**
134
+ * Maps the flat write fields onto a People API Person request body.
135
+ * Only provided fields are included; `updatePersonFields` mirrors that set
136
+ * so an update replaces exactly the fields the caller sent.
137
+ */
138
+ buildPersonRequestBody(fields) {
139
+ const body = {};
140
+ const personFields = [];
141
+ if (fields.givenName !== undefined || fields.familyName !== undefined) {
142
+ body.names = [{
143
+ givenName: fields.givenName ?? '',
144
+ familyName: fields.familyName ?? ''
145
+ }];
146
+ personFields.push('names');
147
+ }
148
+ if (fields.emailAddress !== undefined) {
149
+ body.emailAddresses = [{
150
+ value: fields.emailAddress,
151
+ ...(fields.emailType && { type: fields.emailType })
152
+ }];
153
+ personFields.push('emailAddresses');
154
+ }
155
+ if (fields.phoneNumber !== undefined) {
156
+ body.phoneNumbers = [{
157
+ value: fields.phoneNumber,
158
+ ...(fields.phoneType && { type: fields.phoneType })
159
+ }];
160
+ personFields.push('phoneNumbers');
161
+ }
162
+ if (fields.organization !== undefined || fields.jobTitle !== undefined) {
163
+ body.organizations = [{
164
+ name: fields.organization ?? '',
165
+ title: fields.jobTitle ?? ''
166
+ }];
167
+ personFields.push('organizations');
168
+ }
169
+ if (fields.notes !== undefined) {
170
+ body.biographies = [{ value: fields.notes, contentType: 'TEXT_PLAIN' }];
171
+ personFields.push('biographies');
172
+ }
173
+ return { body, personFields };
174
+ }
175
+ toWriteResult(person) {
176
+ return {
177
+ resourceName: person.resourceName || '',
178
+ etag: person.etag || undefined,
179
+ displayName: person.names?.[0]?.displayName || undefined,
180
+ email: person.emailAddresses?.[0]?.value || undefined,
181
+ phone: person.phoneNumbers?.[0]?.value || undefined,
182
+ organization: person.organizations?.[0]?.name || undefined
183
+ };
184
+ }
185
+ wrapWriteError(error, action) {
186
+ if (isAuthHandoffError(error) && error instanceof Error)
187
+ return error;
188
+ if (error instanceof GoogleServiceError) {
189
+ const gError = error;
190
+ return new ContactsError(gError.message || `Error ${action} contact`, gError.data?.code || 'GOOGLE_SERVICE_ERROR', gError.data?.details);
191
+ }
192
+ if (error instanceof Error) {
193
+ return new ContactsError(`Failed to ${action} contact: ${describeApiError(error)}`, 'WRITE_ERROR');
194
+ }
195
+ return new ContactsError(`Failed to ${action} contact due to an unknown issue`, 'UNKNOWN_ERROR');
196
+ }
197
+ /**
198
+ * Create a new contact via the People API.
199
+ */
200
+ async createContact(params) {
201
+ const { email, ...fields } = params;
202
+ try {
203
+ await this.validateScopes(email, [CONTACTS_SCOPES.CONTACTS]);
204
+ const peopleApi = await this.getPeopleClient(email);
205
+ const { body, personFields } = this.buildPersonRequestBody(fields);
206
+ const response = await peopleApi.people.createContact({
207
+ requestBody: body,
208
+ personFields: personFields.join(',')
209
+ });
210
+ return this.toWriteResult(response.data);
211
+ }
212
+ catch (error) {
213
+ throw this.wrapWriteError(error, 'create');
214
+ }
215
+ }
216
+ /**
217
+ * Update an existing contact via the People API. The People API requires the
218
+ * contact's current etag, so it is fetched first; only the provided fields
219
+ * are replaced (updatePersonFields semantics).
220
+ */
221
+ async updateContact(params) {
222
+ const { email, resourceName, ...fields } = params;
223
+ try {
224
+ await this.validateScopes(email, [CONTACTS_SCOPES.CONTACTS]);
225
+ const peopleApi = await this.getPeopleClient(email);
226
+ const { body, personFields } = this.buildPersonRequestBody(fields);
227
+ if (personFields.length === 0) {
228
+ throw new ContactsError('No fields to update', 'INVALID_PARAMS', 'Provide at least one field to change (e.g. phoneNumber or organization)');
229
+ }
230
+ const current = await peopleApi.people.get({
231
+ resourceName,
232
+ personFields: 'names,emailAddresses,phoneNumbers,organizations,biographies'
233
+ });
234
+ const response = await peopleApi.people.updateContact({
235
+ resourceName,
236
+ updatePersonFields: personFields.join(','),
237
+ personFields: personFields.join(','),
238
+ requestBody: {
239
+ ...body,
240
+ etag: current.data.etag || undefined
241
+ }
242
+ });
243
+ return this.toWriteResult(response.data);
244
+ }
245
+ catch (error) {
246
+ if (error instanceof ContactsError) {
247
+ throw error;
248
+ }
249
+ throw this.wrapWriteError(error, 'update');
250
+ }
251
+ }
128
252
  }
129
253
  // Optional: Export a singleton instance if needed by the module structure
130
254
  // let contactsServiceInstance: ContactsService | null = null;
@@ -0,0 +1,35 @@
1
+ import { google } from "googleapis";
2
+ import { BaseGoogleService } from "../base/BaseGoogleService.js";
3
+ import { ListConferenceRecordsParams, ListConferenceRecordsResponse, ListTranscriptsParams, ListTranscriptsResponse, ListTranscriptEntriesParams, ListTranscriptEntriesResponse } from "../../modules/meet/types.js";
4
+ type MeetApiClient = ReturnType<typeof google.meet>;
5
+ /**
6
+ * Meet service implementation extending BaseGoogleService.
7
+ * Handles Google Meet API v2 read-only operations (conference records,
8
+ * transcripts, and transcript entries).
9
+ */
10
+ export declare class MeetService extends BaseGoogleService<MeetApiClient> {
11
+ constructor();
12
+ /**
13
+ * Gets an authenticated Meet API client for the specified account.
14
+ */
15
+ private getMeetClient;
16
+ /**
17
+ * Maps a thrown error into a MeetError, mirroring the Contacts service.
18
+ */
19
+ private toMeetError;
20
+ /**
21
+ * Lists past conference records for the specified user account.
22
+ * Supports pagination and an optional EBNF filter passed through to the API.
23
+ */
24
+ listConferenceRecords(params: ListConferenceRecordsParams): Promise<ListConferenceRecordsResponse>;
25
+ /**
26
+ * Lists the transcripts of a conference record.
27
+ */
28
+ listTranscripts(params: ListTranscriptsParams): Promise<ListTranscriptsResponse>;
29
+ /**
30
+ * Lists the entries (speaker + text) of one transcript, paginated.
31
+ */
32
+ listTranscriptEntries(params: ListTranscriptEntriesParams): Promise<ListTranscriptEntriesResponse>;
33
+ }
34
+ export {};
35
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1,116 @@
1
+ import { google } from "googleapis";
2
+ import { BaseGoogleService, GoogleServiceError } from "../base/BaseGoogleService.js";
3
+ import { MeetError } from "../../modules/meet/types.js";
4
+ import { MEET_SCOPES } from "../../modules/meet/scopes.js";
5
+ /**
6
+ * Meet service implementation extending BaseGoogleService.
7
+ * Handles Google Meet API v2 read-only operations (conference records,
8
+ * transcripts, and transcript entries).
9
+ */
10
+ export class MeetService extends BaseGoogleService {
11
+ constructor() {
12
+ super({
13
+ serviceName: "meet", // Use 'meet' for the Google Meet API
14
+ version: "v2"
15
+ });
16
+ // Initialize immediately or ensure initialized before first use
17
+ this.initialize();
18
+ }
19
+ /**
20
+ * Gets an authenticated Meet API client for the specified account.
21
+ */
22
+ async getMeetClient(email) {
23
+ // The clientFactory function tells BaseGoogleService how to create the specific client
24
+ return this.getAuthenticatedClient(email, (auth) => google.meet({ version: "v2", auth }));
25
+ }
26
+ /**
27
+ * Maps a thrown error into a MeetError, mirroring the Contacts service.
28
+ */
29
+ toMeetError(error, action) {
30
+ if (error instanceof GoogleServiceError) {
31
+ // Assuming GoogleServiceError inherits message and data from McpError
32
+ // Use type assertion as the linter seems unsure
33
+ const gError = error;
34
+ return new MeetError(gError.message || `Error ${action}`, // Fallback message
35
+ gError.data?.code || "GOOGLE_SERVICE_ERROR", // Code from data
36
+ gError.data?.details // Details from data
37
+ );
38
+ }
39
+ // Handle other potential errors (e.g. network errors)
40
+ else if (error instanceof Error) {
41
+ return new MeetError(`Failed to ${action}: ${error.message}`, "UNKNOWN_API_ERROR" // More specific code
42
+ );
43
+ }
44
+ // Handle non-Error throws
45
+ return new MeetError(`Failed to ${action} due to an unknown issue`, "UNKNOWN_INTERNAL_ERROR" // More specific code
46
+ );
47
+ }
48
+ /**
49
+ * Lists past conference records for the specified user account.
50
+ * Supports pagination and an optional EBNF filter passed through to the API.
51
+ */
52
+ async listConferenceRecords(params) {
53
+ const { email, pageSize, pageToken, filter } = params;
54
+ try {
55
+ // Ensure necessary scopes are granted
56
+ await this.validateScopes(email, [MEET_SCOPES.MEETINGS_SPACE_READONLY]);
57
+ const meetApi = await this.getMeetClient(email);
58
+ const response = await meetApi.conferenceRecords.list({
59
+ pageSize: pageSize,
60
+ pageToken: pageToken,
61
+ filter: filter
62
+ });
63
+ // googleapis types use 'null' where we defined optional fields ('undefined');
64
+ // the shapes otherwise match the Meet API v2 resources.
65
+ return response.data;
66
+ }
67
+ catch (error) {
68
+ throw this.toMeetError(error, "list conference records");
69
+ }
70
+ }
71
+ /**
72
+ * Lists the transcripts of a conference record.
73
+ */
74
+ async listTranscripts(params) {
75
+ const { email, parent, pageSize, pageToken } = params;
76
+ if (!parent) {
77
+ throw new MeetError("Missing required parameter: parent", "INVALID_PARAMS", 'Specify the conference record resource name (e.g. "conferenceRecords/abc-123")');
78
+ }
79
+ try {
80
+ await this.validateScopes(email, [MEET_SCOPES.MEETINGS_SPACE_READONLY]);
81
+ const meetApi = await this.getMeetClient(email);
82
+ const response = await meetApi.conferenceRecords.transcripts.list({
83
+ parent: parent,
84
+ pageSize: pageSize,
85
+ pageToken: pageToken
86
+ });
87
+ return response.data;
88
+ }
89
+ catch (error) {
90
+ throw this.toMeetError(error, "list transcripts");
91
+ }
92
+ }
93
+ /**
94
+ * Lists the entries (speaker + text) of one transcript, paginated.
95
+ */
96
+ async listTranscriptEntries(params) {
97
+ const { email, parent, pageSize, pageToken } = params;
98
+ if (!parent) {
99
+ throw new MeetError("Missing required parameter: parent", "INVALID_PARAMS", 'Specify the transcript resource name (e.g. "conferenceRecords/abc-123/transcripts/def-456")');
100
+ }
101
+ try {
102
+ await this.validateScopes(email, [MEET_SCOPES.MEETINGS_SPACE_READONLY]);
103
+ const meetApi = await this.getMeetClient(email);
104
+ const response = await meetApi.conferenceRecords.transcripts.entries.list({
105
+ parent: parent,
106
+ pageSize: pageSize,
107
+ pageToken: pageToken
108
+ });
109
+ return response.data;
110
+ }
111
+ catch (error) {
112
+ throw this.toMeetError(error, "list transcript entries");
113
+ }
114
+ }
115
+ }
116
+ //# sourceMappingURL=index.js.map
@@ -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
  }
@@ -0,0 +1,14 @@
1
+ import { ListChatSpacesResponse, ListChatMessagesResponse, ChatMessage } from "../modules/chat/types.js";
2
+ /**
3
+ * Handler function for listing Google Chat spaces.
4
+ */
5
+ export declare function handleListChatSpaces(params: Record<string, unknown>): Promise<ListChatSpacesResponse>;
6
+ /**
7
+ * Handler function for listing messages in a Google Chat space.
8
+ */
9
+ export declare function handleListChatMessages(params: Record<string, unknown>): Promise<ListChatMessagesResponse>;
10
+ /**
11
+ * Handler function for posting a text message to a Google Chat space.
12
+ */
13
+ export declare function handleSendChatMessage(params: Record<string, unknown>): Promise<ChatMessage>;
14
+ //# sourceMappingURL=chat-handlers.d.ts.map