@mindstone/mcp-server-google-workspace 0.2.0 → 0.4.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.
- package/README.md +15 -12
- package/dist/modules/chat/index.d.ts +12 -0
- package/dist/modules/chat/index.js +18 -0
- package/dist/modules/chat/scopes.d.ts +14 -0
- package/dist/modules/chat/scopes.js +32 -0
- package/dist/modules/chat/types.d.ts +88 -0
- package/dist/modules/chat/types.js +14 -0
- package/dist/modules/comments/service.js +21 -1
- package/dist/modules/contacts/scopes.d.ts +1 -0
- package/dist/modules/contacts/scopes.js +2 -2
- package/dist/modules/contacts/types.d.ts +34 -0
- package/dist/modules/docs/service.js +29 -1
- package/dist/modules/drive/activity-service.d.ts +45 -0
- package/dist/modules/drive/activity-service.js +114 -0
- package/dist/modules/drive/index.d.ts +4 -0
- package/dist/modules/drive/index.js +12 -0
- package/dist/modules/drive/scopes.d.ts +1 -0
- package/dist/modules/drive/scopes.js +3 -0
- package/dist/modules/forms/service.js +13 -1
- package/dist/modules/gmail/services/base.d.ts +5 -1
- package/dist/modules/gmail/services/base.js +8 -0
- package/dist/modules/gmail/services/settings.d.ts +14 -1
- package/dist/modules/gmail/services/settings.js +94 -0
- package/dist/modules/gmail/types.d.ts +36 -0
- package/dist/modules/meet/index.d.ts +12 -0
- package/dist/modules/meet/index.js +18 -0
- package/dist/modules/meet/scopes.d.ts +9 -0
- package/dist/modules/meet/scopes.js +25 -0
- package/dist/modules/meet/types.d.ts +97 -0
- package/dist/modules/meet/types.js +14 -0
- package/dist/modules/sheets/service.js +49 -0
- package/dist/modules/slides/service.js +25 -1
- package/dist/modules/tasks/service.js +25 -1
- package/dist/services/base/BaseGoogleService.d.ts +9 -1
- package/dist/services/base/BaseGoogleService.js +26 -1
- package/dist/services/chat/index.d.ts +34 -0
- package/dist/services/chat/index.js +120 -0
- package/dist/services/contacts/index.d.ts +19 -1
- package/dist/services/contacts/index.js +124 -0
- package/dist/services/meet/index.d.ts +35 -0
- package/dist/services/meet/index.js +116 -0
- package/dist/tools/chat-handlers.d.ts +14 -0
- package/dist/tools/chat-handlers.js +126 -0
- package/dist/tools/contacts-handlers.d.ts +31 -0
- package/dist/tools/contacts-handlers.js +88 -0
- package/dist/tools/definitions/chat.d.ts +3 -0
- package/dist/tools/definitions/chat.js +137 -0
- package/dist/tools/definitions/contacts.js +82 -0
- package/dist/tools/definitions/destructive-overrides.json +11 -0
- package/dist/tools/definitions/drive.js +48 -0
- package/dist/tools/definitions/gmail.js +94 -0
- package/dist/tools/definitions/index.d.ts +4 -2
- package/dist/tools/definitions/index.js +10 -6
- package/dist/tools/definitions/meet.d.ts +3 -0
- package/dist/tools/definitions/meet.js +149 -0
- package/dist/tools/definitions/open-world-overrides.json +11 -0
- package/dist/tools/drive-handlers.d.ts +17 -0
- package/dist/tools/drive-handlers.js +49 -1
- package/dist/tools/gmail-handlers.d.ts +24 -0
- package/dist/tools/gmail-handlers.js +129 -11
- package/dist/tools/meet-handlers.d.ts +42 -0
- package/dist/tools/meet-handlers.js +144 -0
- package/dist/tools/server.js +53 -3
- package/dist/utils/apiError.js +5 -2
- package/dist/utils/scope-hierarchy.js +10 -0
- package/dist/utils/service-initializer.d.ts +0 -10
- package/dist/utils/service-initializer.js +14 -23
- package/dist/utils/untrusted-content.d.ts +37 -1
- package/dist/utils/untrusted-content.js +61 -6
- package/package.json +1 -1
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { google } from 'googleapis';
|
|
2
2
|
import { BaseGoogleService } from '../../services/base/BaseGoogleService.js';
|
|
3
3
|
import { SLIDES_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 - presentation exceeds character limit]';
|
|
7
7
|
export class SlidesService extends BaseGoogleService {
|
|
@@ -200,6 +200,10 @@ export class SlidesService extends BaseGoogleService {
|
|
|
200
200
|
};
|
|
201
201
|
}
|
|
202
202
|
catch (error) {
|
|
203
|
+
// An expired/revoked grant must keep its reconnect signal — folding it
|
|
204
|
+
// into a plain error string would skip the host's auth_required handoff.
|
|
205
|
+
if (isAuthHandoffError(error))
|
|
206
|
+
throw error;
|
|
203
207
|
return {
|
|
204
208
|
success: false,
|
|
205
209
|
error: describeApiError(error),
|
|
@@ -239,6 +243,10 @@ export class SlidesService extends BaseGoogleService {
|
|
|
239
243
|
};
|
|
240
244
|
}
|
|
241
245
|
catch (error) {
|
|
246
|
+
// An expired/revoked grant must keep its reconnect signal — folding it
|
|
247
|
+
// into a plain error string would skip the host's auth_required handoff.
|
|
248
|
+
if (isAuthHandoffError(error))
|
|
249
|
+
throw error;
|
|
242
250
|
return {
|
|
243
251
|
success: false,
|
|
244
252
|
error: describeApiError(error),
|
|
@@ -265,6 +273,10 @@ export class SlidesService extends BaseGoogleService {
|
|
|
265
273
|
};
|
|
266
274
|
}
|
|
267
275
|
catch (error) {
|
|
276
|
+
// An expired/revoked grant must keep its reconnect signal — folding it
|
|
277
|
+
// into a plain error string would skip the host's auth_required handoff.
|
|
278
|
+
if (isAuthHandoffError(error))
|
|
279
|
+
throw error;
|
|
268
280
|
return {
|
|
269
281
|
success: false,
|
|
270
282
|
error: describeApiError(error),
|
|
@@ -316,6 +328,10 @@ export class SlidesService extends BaseGoogleService {
|
|
|
316
328
|
};
|
|
317
329
|
}
|
|
318
330
|
catch (error) {
|
|
331
|
+
// An expired/revoked grant must keep its reconnect signal — folding it
|
|
332
|
+
// into a plain error string would skip the host's auth_required handoff.
|
|
333
|
+
if (isAuthHandoffError(error))
|
|
334
|
+
throw error;
|
|
319
335
|
return {
|
|
320
336
|
success: false,
|
|
321
337
|
error: describeApiError(error),
|
|
@@ -350,6 +366,10 @@ export class SlidesService extends BaseGoogleService {
|
|
|
350
366
|
};
|
|
351
367
|
}
|
|
352
368
|
catch (error) {
|
|
369
|
+
// An expired/revoked grant must keep its reconnect signal — folding it
|
|
370
|
+
// into a plain error string would skip the host's auth_required handoff.
|
|
371
|
+
if (isAuthHandoffError(error))
|
|
372
|
+
throw error;
|
|
353
373
|
return {
|
|
354
374
|
success: false,
|
|
355
375
|
error: describeApiError(error),
|
|
@@ -385,6 +405,10 @@ export class SlidesService extends BaseGoogleService {
|
|
|
385
405
|
};
|
|
386
406
|
}
|
|
387
407
|
catch (error) {
|
|
408
|
+
// An expired/revoked grant must keep its reconnect signal — folding it
|
|
409
|
+
// into a plain error string would skip the host's auth_required handoff.
|
|
410
|
+
if (isAuthHandoffError(error))
|
|
411
|
+
throw error;
|
|
388
412
|
return {
|
|
389
413
|
success: false,
|
|
390
414
|
error: describeApiError(error),
|
|
@@ -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 { TASKS_SCOPES } from './scopes.js';
|
|
5
5
|
/**
|
|
6
6
|
* Service for interacting with Google Tasks API.
|
|
@@ -79,6 +79,10 @@ export class TasksService extends BaseGoogleService {
|
|
|
79
79
|
};
|
|
80
80
|
}
|
|
81
81
|
catch (error) {
|
|
82
|
+
// An expired/revoked grant must keep its reconnect signal — folding it
|
|
83
|
+
// into a plain error string would skip the host's auth_required handoff.
|
|
84
|
+
if (isAuthHandoffError(error))
|
|
85
|
+
throw error;
|
|
82
86
|
return {
|
|
83
87
|
success: false,
|
|
84
88
|
error: describeApiError(error)
|
|
@@ -139,6 +143,10 @@ export class TasksService extends BaseGoogleService {
|
|
|
139
143
|
};
|
|
140
144
|
}
|
|
141
145
|
catch (error) {
|
|
146
|
+
// An expired/revoked grant must keep its reconnect signal — folding it
|
|
147
|
+
// into a plain error string would skip the host's auth_required handoff.
|
|
148
|
+
if (isAuthHandoffError(error))
|
|
149
|
+
throw error;
|
|
142
150
|
return {
|
|
143
151
|
success: false,
|
|
144
152
|
error: describeApiError(error)
|
|
@@ -187,6 +195,10 @@ export class TasksService extends BaseGoogleService {
|
|
|
187
195
|
};
|
|
188
196
|
}
|
|
189
197
|
catch (error) {
|
|
198
|
+
// An expired/revoked grant must keep its reconnect signal — folding it
|
|
199
|
+
// into a plain error string would skip the host's auth_required handoff.
|
|
200
|
+
if (isAuthHandoffError(error))
|
|
201
|
+
throw error;
|
|
190
202
|
return {
|
|
191
203
|
success: false,
|
|
192
204
|
error: describeApiError(error)
|
|
@@ -228,6 +240,10 @@ export class TasksService extends BaseGoogleService {
|
|
|
228
240
|
};
|
|
229
241
|
}
|
|
230
242
|
catch (error) {
|
|
243
|
+
// An expired/revoked grant must keep its reconnect signal — folding it
|
|
244
|
+
// into a plain error string would skip the host's auth_required handoff.
|
|
245
|
+
if (isAuthHandoffError(error))
|
|
246
|
+
throw error;
|
|
231
247
|
return {
|
|
232
248
|
success: false,
|
|
233
249
|
error: describeApiError(error)
|
|
@@ -283,6 +299,10 @@ export class TasksService extends BaseGoogleService {
|
|
|
283
299
|
};
|
|
284
300
|
}
|
|
285
301
|
catch (error) {
|
|
302
|
+
// An expired/revoked grant must keep its reconnect signal — folding it
|
|
303
|
+
// into a plain error string would skip the host's auth_required handoff.
|
|
304
|
+
if (isAuthHandoffError(error))
|
|
305
|
+
throw error;
|
|
286
306
|
return {
|
|
287
307
|
success: false,
|
|
288
308
|
error: describeApiError(error)
|
|
@@ -310,6 +330,10 @@ export class TasksService extends BaseGoogleService {
|
|
|
310
330
|
};
|
|
311
331
|
}
|
|
312
332
|
catch (error) {
|
|
333
|
+
// An expired/revoked grant must keep its reconnect signal — folding it
|
|
334
|
+
// into a plain error string would skip the host's auth_required handoff.
|
|
335
|
+
if (isAuthHandoffError(error))
|
|
336
|
+
throw error;
|
|
313
337
|
return {
|
|
314
338
|
success: false,
|
|
315
339
|
error: describeApiError(error)
|
|
@@ -37,8 +37,16 @@ export declare abstract class BaseGoogleService<TClient> {
|
|
|
37
37
|
/**
|
|
38
38
|
* Common error handler for Google service operations
|
|
39
39
|
* Maps Google API error codes to appropriate MCP error codes
|
|
40
|
+
*
|
|
41
|
+
* Auth-handoff errors (AccountError with code AUTH_REQUIRED /
|
|
42
|
+
* HOST_ORCHESTRATED_AUTH_REQUIRED) pass through unchanged: rewrapping them
|
|
43
|
+
* here would replace the string `code` that server.ts formatErrorResponse
|
|
44
|
+
* keys the structured `auth_required` reconnect handoff on with a mangled
|
|
45
|
+
* `HTTP_AUTH_REQUIRED`, silently degrading an expired grant to a generic
|
|
46
|
+
* failure — the gap the Tasks/Forms/Docs/Slides/Comments service catches
|
|
47
|
+
* used to hit on a first-request auth failure.
|
|
40
48
|
*/
|
|
41
|
-
protected handleError(error: unknown, context: string):
|
|
49
|
+
protected handleError(error: unknown, context: string): Error;
|
|
42
50
|
/**
|
|
43
51
|
* Validates required scopes are present for an operation.
|
|
44
52
|
*
|
|
@@ -2,6 +2,7 @@ import { McpError, ErrorCode } from '@modelcontextprotocol/sdk/types.js';
|
|
|
2
2
|
import { getAccountManager } from '../../modules/accounts/index.js';
|
|
3
3
|
import { AccountError } from '../../modules/accounts/types.js';
|
|
4
4
|
import { findMissingScopes, getServiceNamesForScopes } from '../../utils/scope-hierarchy.js';
|
|
5
|
+
import { isAuthHandoffError } from '../../utils/apiError.js';
|
|
5
6
|
/**
|
|
6
7
|
* Base error class for Google services
|
|
7
8
|
*/
|
|
@@ -62,7 +63,10 @@ export class BaseGoogleService {
|
|
|
62
63
|
throw new AccountError(`${this.serviceName} token refresh failed temporarily`, 'TEMPORARY_AUTH_ERROR', 'Please try again in a moment');
|
|
63
64
|
}
|
|
64
65
|
if (!tokenStatus.valid || !tokenStatus.token) {
|
|
65
|
-
|
|
66
|
+
// AccountError (string `code`), not GoogleServiceError: the latter's numeric
|
|
67
|
+
// McpError code is invisible to formatErrorResponse's auth handoff, which is
|
|
68
|
+
// how first-request-of-the-session auth failures degraded to plain errors.
|
|
69
|
+
throw new AccountError(`${this.serviceName} authentication required`, 'AUTH_REQUIRED', 'Please authenticate the account');
|
|
66
70
|
}
|
|
67
71
|
this.oauth2Client.setCredentials(tokenStatus.token);
|
|
68
72
|
const client = clientFactory(this.oauth2Client);
|
|
@@ -76,8 +80,19 @@ export class BaseGoogleService {
|
|
|
76
80
|
/**
|
|
77
81
|
* Common error handler for Google service operations
|
|
78
82
|
* Maps Google API error codes to appropriate MCP error codes
|
|
83
|
+
*
|
|
84
|
+
* Auth-handoff errors (AccountError with code AUTH_REQUIRED /
|
|
85
|
+
* HOST_ORCHESTRATED_AUTH_REQUIRED) pass through unchanged: rewrapping them
|
|
86
|
+
* here would replace the string `code` that server.ts formatErrorResponse
|
|
87
|
+
* keys the structured `auth_required` reconnect handoff on with a mangled
|
|
88
|
+
* `HTTP_AUTH_REQUIRED`, silently degrading an expired grant to a generic
|
|
89
|
+
* failure — the gap the Tasks/Forms/Docs/Slides/Comments service catches
|
|
90
|
+
* used to hit on a first-request auth failure.
|
|
79
91
|
*/
|
|
80
92
|
handleError(error, context) {
|
|
93
|
+
if (isAuthHandoffError(error) && error instanceof Error) {
|
|
94
|
+
return error;
|
|
95
|
+
}
|
|
81
96
|
if (error instanceof GoogleServiceError) {
|
|
82
97
|
return error;
|
|
83
98
|
}
|
|
@@ -137,6 +152,16 @@ export class BaseGoogleService {
|
|
|
137
152
|
// Note: tokenInfo.requiredScopes is misleadingly named - it's actually the GRANTED scopes
|
|
138
153
|
const grantedScopes = tokenInfo.requiredScopes;
|
|
139
154
|
if (!grantedScopes || grantedScopes.length === 0) {
|
|
155
|
+
if (!tokenInfo.valid) {
|
|
156
|
+
// Invalid/expired grant — this is an auth failure, not a scope gap. Keep the
|
|
157
|
+
// reconnect signal (or transient-retry signal) intact: reporting it as a
|
|
158
|
+
// generic SCOPE_ERROR let the swallowing service catches (Tasks/Forms/Docs/
|
|
159
|
+
// Slides/Comments/Sheets) flatten an expired sign-in to a plain string.
|
|
160
|
+
if (tokenInfo.canRetry) {
|
|
161
|
+
throw new AccountError(`${this.serviceName} token refresh failed temporarily`, 'TEMPORARY_AUTH_ERROR', 'Please try again in a moment');
|
|
162
|
+
}
|
|
163
|
+
throw new AccountError(`${this.serviceName} authentication required`, 'AUTH_REQUIRED', tokenInfo.reason || 'Connect Google Workspace to continue');
|
|
164
|
+
}
|
|
140
165
|
throw new GoogleServiceError('No permissions found', 'SCOPE_ERROR', 'The Google account connection may be incomplete. ' +
|
|
141
166
|
'Use remove_workspace_account to disconnect, then authenticate_workspace_account to reconnect.');
|
|
142
167
|
}
|
|
@@ -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
|