@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.
- package/README.md +28 -9
- package/dist/modules/accounts/manager.js +20 -2
- package/dist/modules/accounts/token.d.ts +13 -0
- package/dist/modules/accounts/token.js +73 -58
- package/dist/modules/accounts/types.d.ts +1 -0
- package/dist/modules/calendar/service.js +9 -0
- 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 +26 -5
- 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/index.js +2 -1
- package/dist/modules/docs/service.js +36 -7
- 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/drive/service.d.ts +2 -1
- package/dist/modules/drive/service.js +29 -0
- package/dist/modules/drive/types.d.ts +8 -0
- package/dist/modules/forms/service.js +16 -3
- package/dist/modules/gmail/services/attachment.js +2 -1
- package/dist/modules/gmail/services/base.d.ts +5 -1
- package/dist/modules/gmail/services/base.js +10 -1
- package/dist/modules/gmail/services/draft.js +13 -7
- package/dist/modules/gmail/services/email.js +4 -3
- package/dist/modules/gmail/services/label.js +10 -9
- package/dist/modules/gmail/services/settings.d.ts +14 -1
- package/dist/modules/gmail/services/settings.js +96 -1
- 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 +31 -6
- package/dist/modules/tasks/service.js +31 -6
- package/dist/resources/compose-email-template.d.ts +1 -1
- package/dist/resources/compose-email-template.js +388 -19
- package/dist/services/base/BaseGoogleService.d.ts +9 -1
- package/dist/services/base/BaseGoogleService.js +33 -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/calendar-handlers.js +28 -23
- 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 +96 -23
- package/dist/tools/definitions/account.js +8 -1
- 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 +12 -0
- package/dist/tools/definitions/drive.js +132 -6
- package/dist/tools/definitions/gmail.js +94 -0
- package/dist/tools/definitions/index.d.ts +2 -0
- package/dist/tools/definitions/index.js +6 -0
- 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 +12 -0
- package/dist/tools/drive-handlers.d.ts +27 -0
- package/dist/tools/drive-handlers.js +93 -2
- package/dist/tools/forms-handlers.js +5 -12
- package/dist/tools/gmail-handlers.d.ts +31 -1
- package/dist/tools/gmail-handlers.js +167 -35
- package/dist/tools/meet-handlers.d.ts +42 -0
- package/dist/tools/meet-handlers.js +144 -0
- package/dist/tools/server.js +67 -5
- package/dist/tools/tasks-handlers.js +7 -18
- package/dist/tools/type-guards.d.ts +3 -1
- package/dist/tools/type-guards.js +22 -2
- package/dist/tools/types.d.ts +13 -0
- package/dist/utils/apiError.d.ts +49 -0
- package/dist/utils/apiError.js +96 -0
- package/dist/utils/scope-hierarchy.js +10 -0
- package/dist/utils/service-initializer.js +9 -0
- package/dist/utils/untrusted-content.d.ts +37 -1
- package/dist/utils/untrusted-content.js +61 -6
- package/package.json +5 -1
- package/dist/services/calendar/index.d.ts +0 -27
- package/dist/services/calendar/index.js +0 -146
- package/dist/services/gmail/index.d.ts +0 -39
- package/dist/services/gmail/index.js +0 -337
|
@@ -0,0 +1,144 @@
|
|
|
1
|
+
import { MeetService } from "../services/meet/index.js";
|
|
2
|
+
import { McpError, ErrorCode } from "@modelcontextprotocol/sdk/types.js";
|
|
3
|
+
import { toMcpError } from "../utils/apiError.js";
|
|
4
|
+
import { getAccountManager, resolveEmail } from "../modules/accounts/index.js";
|
|
5
|
+
import { readAliasedNumber, readAliasedString } from './arg-aliases.js';
|
|
6
|
+
import { wrapUntrustedJsonStrings } from "../utils/untrusted-content.js";
|
|
7
|
+
// Singleton instances - Initialize or inject as per project pattern
|
|
8
|
+
let meetService;
|
|
9
|
+
let accountManager;
|
|
10
|
+
// The Meet API coerces page sizes above 100 to 100; cap client-side so the
|
|
11
|
+
// request we send matches what the tool contract documents.
|
|
12
|
+
const MEET_MAX_PAGE_SIZE = 100;
|
|
13
|
+
/**
|
|
14
|
+
* Initialize required services.
|
|
15
|
+
* This should likely be integrated into a central initialization process.
|
|
16
|
+
*/
|
|
17
|
+
async function initializeServices() {
|
|
18
|
+
if (!meetService) {
|
|
19
|
+
meetService = new MeetService();
|
|
20
|
+
}
|
|
21
|
+
if (!accountManager) {
|
|
22
|
+
accountManager = getAccountManager();
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Normalizes a user-supplied conference record reference into the
|
|
27
|
+
* 'conferenceRecords/{id}' parent format the Meet API expects. Accepts either
|
|
28
|
+
* the bare ID or the full resource name.
|
|
29
|
+
*/
|
|
30
|
+
function toConferenceRecordName(conferenceRecord) {
|
|
31
|
+
const trimmed = conferenceRecord.trim();
|
|
32
|
+
return trimmed.startsWith('conferenceRecords/')
|
|
33
|
+
? trimmed
|
|
34
|
+
: `conferenceRecords/${trimmed}`;
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Normalizes a conference record + transcript pair into the
|
|
38
|
+
* 'conferenceRecords/{id}/transcripts/{tid}' parent format the Meet API
|
|
39
|
+
* expects. The transcript may be given as a bare ID, a 'transcripts/{id}'
|
|
40
|
+
* segment, or a full resource name (in which case it is used as-is).
|
|
41
|
+
*/
|
|
42
|
+
function toTranscriptName(conferenceRecord, transcript) {
|
|
43
|
+
const trimmedTranscript = transcript.trim();
|
|
44
|
+
if (trimmedTranscript.startsWith('conferenceRecords/')) {
|
|
45
|
+
return trimmedTranscript;
|
|
46
|
+
}
|
|
47
|
+
const conferenceRecordName = toConferenceRecordName(conferenceRecord);
|
|
48
|
+
return trimmedTranscript.startsWith('transcripts/')
|
|
49
|
+
? `${conferenceRecordName}/${trimmedTranscript}`
|
|
50
|
+
: `${conferenceRecordName}/transcripts/${trimmedTranscript}`;
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* Handler function for listing Google Meet conference records.
|
|
54
|
+
*/
|
|
55
|
+
export async function handleListMeetConferenceRecords(params) {
|
|
56
|
+
await initializeServices(); // Ensure services are ready
|
|
57
|
+
const pageSize = readAliasedNumber(params, 'page_size', 'pageSize');
|
|
58
|
+
const pageToken = readAliasedString(params, 'page_token', 'pageToken');
|
|
59
|
+
const filter = readAliasedString(params, 'filter', 'filter');
|
|
60
|
+
// Resolve email - uses instance account if not provided, validates if provided
|
|
61
|
+
const email = await resolveEmail(params);
|
|
62
|
+
// Use accountManager for token renewal like in Contacts handlers
|
|
63
|
+
return accountManager.withTokenRenewal(email, async () => {
|
|
64
|
+
try {
|
|
65
|
+
const result = await meetService.listConferenceRecords({
|
|
66
|
+
email,
|
|
67
|
+
pageSize: pageSize !== undefined ? Math.min(pageSize, MEET_MAX_PAGE_SIZE) : undefined,
|
|
68
|
+
pageToken,
|
|
69
|
+
filter
|
|
70
|
+
});
|
|
71
|
+
return wrapUntrustedJsonStrings(result, 'google-workspace:meet:conference-records');
|
|
72
|
+
}
|
|
73
|
+
catch (error) {
|
|
74
|
+
// toMcpError passes an McpError (and auth-handoff errors) through, and folds a
|
|
75
|
+
// MeetError's details into the message (InternalError) so the real cause reaches
|
|
76
|
+
// the user — the host drops an McpError's `data` arg, so details-as-data would
|
|
77
|
+
// be invisible.
|
|
78
|
+
throw toMcpError(error, 'Failed to list conference records');
|
|
79
|
+
}
|
|
80
|
+
});
|
|
81
|
+
}
|
|
82
|
+
/**
|
|
83
|
+
* Handler function for listing the transcripts of a Google Meet conference record.
|
|
84
|
+
*/
|
|
85
|
+
export async function handleListMeetTranscripts(params) {
|
|
86
|
+
await initializeServices();
|
|
87
|
+
const conferenceRecord = readAliasedString(params, 'conference_record', 'conferenceRecord');
|
|
88
|
+
const pageSize = readAliasedNumber(params, 'page_size', 'pageSize');
|
|
89
|
+
const pageToken = readAliasedString(params, 'page_token', 'pageToken');
|
|
90
|
+
// Resolve email - uses instance account if not provided, validates if provided
|
|
91
|
+
const email = await resolveEmail(params);
|
|
92
|
+
if (!conferenceRecord) {
|
|
93
|
+
throw new McpError(ErrorCode.InvalidParams, 'conference_record parameter is required (e.g. "conferenceRecords/abc-123" or just "abc-123")');
|
|
94
|
+
}
|
|
95
|
+
return accountManager.withTokenRenewal(email, async () => {
|
|
96
|
+
try {
|
|
97
|
+
const result = await meetService.listTranscripts({
|
|
98
|
+
email,
|
|
99
|
+
parent: toConferenceRecordName(conferenceRecord),
|
|
100
|
+
pageSize: pageSize !== undefined ? Math.min(pageSize, MEET_MAX_PAGE_SIZE) : undefined,
|
|
101
|
+
pageToken
|
|
102
|
+
});
|
|
103
|
+
return wrapUntrustedJsonStrings(result, 'google-workspace:meet:transcripts');
|
|
104
|
+
}
|
|
105
|
+
catch (error) {
|
|
106
|
+
// See handleListMeetConferenceRecords: toMcpError surfaces the real cause.
|
|
107
|
+
throw toMcpError(error, 'Failed to list transcripts');
|
|
108
|
+
}
|
|
109
|
+
});
|
|
110
|
+
}
|
|
111
|
+
/**
|
|
112
|
+
* Handler function for listing the entries (speaker + text) of one Google Meet transcript.
|
|
113
|
+
*/
|
|
114
|
+
export async function handleGetMeetTranscriptEntries(params) {
|
|
115
|
+
await initializeServices();
|
|
116
|
+
const conferenceRecord = readAliasedString(params, 'conference_record', 'conferenceRecord');
|
|
117
|
+
const transcript = readAliasedString(params, 'transcript', 'transcript');
|
|
118
|
+
const pageSize = readAliasedNumber(params, 'page_size', 'pageSize');
|
|
119
|
+
const pageToken = readAliasedString(params, 'page_token', 'pageToken');
|
|
120
|
+
// Resolve email - uses instance account if not provided, validates if provided
|
|
121
|
+
const email = await resolveEmail(params);
|
|
122
|
+
if (!conferenceRecord) {
|
|
123
|
+
throw new McpError(ErrorCode.InvalidParams, 'conference_record parameter is required (e.g. "conferenceRecords/abc-123" or just "abc-123")');
|
|
124
|
+
}
|
|
125
|
+
if (!transcript) {
|
|
126
|
+
throw new McpError(ErrorCode.InvalidParams, 'transcript parameter is required (e.g. "def-456", "transcripts/def-456", or a full resource name)');
|
|
127
|
+
}
|
|
128
|
+
return accountManager.withTokenRenewal(email, async () => {
|
|
129
|
+
try {
|
|
130
|
+
const result = await meetService.listTranscriptEntries({
|
|
131
|
+
email,
|
|
132
|
+
parent: toTranscriptName(conferenceRecord, transcript),
|
|
133
|
+
pageSize: pageSize !== undefined ? Math.min(pageSize, MEET_MAX_PAGE_SIZE) : undefined,
|
|
134
|
+
pageToken
|
|
135
|
+
});
|
|
136
|
+
return wrapUntrustedJsonStrings(result, 'google-workspace:meet:transcript-entries');
|
|
137
|
+
}
|
|
138
|
+
catch (error) {
|
|
139
|
+
// See handleListMeetConferenceRecords: toMcpError surfaces the real cause.
|
|
140
|
+
throw toMcpError(error, 'Failed to get transcript entries');
|
|
141
|
+
}
|
|
142
|
+
});
|
|
143
|
+
}
|
|
144
|
+
//# sourceMappingURL=meet-handlers.js.map
|
package/dist/tools/server.js
CHANGED
|
@@ -12,11 +12,11 @@ import { allTools } from './definitions.js';
|
|
|
12
12
|
import { ToolRegistry } from '../modules/tools/registry.js';
|
|
13
13
|
// Import handlers
|
|
14
14
|
import { handleListWorkspaceAccounts, handleAuthenticateWorkspaceAccount, handleRemoveWorkspaceAccount } from './account-handlers.js';
|
|
15
|
-
import { handleSearchWorkspaceEmails, handleGetWorkspaceEmailThread, handleComposeWorkspaceEmail, handleSendWorkspaceEmail, handleGetWorkspaceGmailSettings, handleManageWorkspaceDraft, handleManageWorkspaceLabel, handleManageWorkspaceLabelAssignment, handleManageWorkspaceLabelFilter, handleManageWorkspaceAttachment, handleListWorkspaceDrafts, handleGetWorkspaceDraft, handleCreateWorkspaceDraft, handleUpdateWorkspaceDraft, handleDeleteWorkspaceDraft, handleSendWorkspaceDraft, handleDownloadWorkspaceAttachment, handleUploadWorkspaceAttachment, handleDeleteWorkspaceAttachment, handleListWorkspaceLabels, handleGetWorkspaceLabel, handleCreateWorkspaceLabel, handleUpdateWorkspaceLabel, handleDeleteWorkspaceLabel, handleListWorkspaceLabelFilters, handleCreateWorkspaceLabelFilter, handleUpdateWorkspaceLabelFilter, handleDeleteWorkspaceLabelFilter, handleArchiveWorkspaceEmail, handleTrashWorkspaceEmail, handleUntrashWorkspaceEmail, handleMarkWorkspaceEmailRead, handleMarkWorkspaceEmailUnread } from './gmail-handlers.js';
|
|
15
|
+
import { handleSearchWorkspaceEmails, handleGetWorkspaceEmailThread, handleComposeWorkspaceEmail, handleSendWorkspaceEmail, handleGetWorkspaceGmailSettings, handleUpdateWorkspaceVacationResponder, handleListWorkspaceSendAs, handleManageWorkspaceDraft, handleManageWorkspaceLabel, handleManageWorkspaceLabelAssignment, handleManageWorkspaceLabelFilter, handleManageWorkspaceAttachment, handleListWorkspaceDrafts, handleGetWorkspaceDraft, handleCreateWorkspaceDraft, handleUpdateWorkspaceDraft, handleDeleteWorkspaceDraft, handleSendWorkspaceDraft, handleDownloadWorkspaceAttachment, handleUploadWorkspaceAttachment, handleDeleteWorkspaceAttachment, handleListWorkspaceLabels, handleGetWorkspaceLabel, handleCreateWorkspaceLabel, handleUpdateWorkspaceLabel, handleDeleteWorkspaceLabel, handleListWorkspaceLabelFilters, handleCreateWorkspaceLabelFilter, handleUpdateWorkspaceLabelFilter, handleDeleteWorkspaceLabelFilter, handleArchiveWorkspaceEmail, handleTrashWorkspaceEmail, handleUntrashWorkspaceEmail, handleMarkWorkspaceEmailRead, handleMarkWorkspaceEmailUnread } from './gmail-handlers.js';
|
|
16
16
|
import { handleGetCurrentTime, handleFindFreeSlots, handleListWorkspaceCalendars, handleListWorkspaceCalendarEvents, handleGetWorkspaceCalendarEvent, handleManageWorkspaceCalendarEvent, handleCreateWorkspaceCalendarEvent, handleDeleteWorkspaceCalendarEvent } from './calendar-handlers.js';
|
|
17
|
-
import { handleListDriveFiles, handleSearchDriveFiles, handleUploadDriveFile, handleDownloadDriveFile, handleCreateDriveFolder, handleUpdateDrivePermissions, handleDeleteDriveFile, handleCopyDriveFile, handleMoveDriveFile, handleTrashDriveFile, handleUntrashDriveFile, handleListFileRevisions, handleDownloadFileRevision } from './drive-handlers.js';
|
|
17
|
+
import { handleListDriveFiles, handleSearchDriveFiles, handleListSharedDrives, handleUploadDriveFile, handleDownloadDriveFile, handleCreateDriveFolder, handleUpdateDrivePermissions, handleDeleteDriveFile, handleCopyDriveFile, handleMoveDriveFile, handleTrashDriveFile, handleUntrashDriveFile, handleListFileRevisions, handleDownloadFileRevision, handleQueryDriveActivity } from './drive-handlers.js';
|
|
18
18
|
// Import contact handlers
|
|
19
|
-
import { handleGetContacts, handleSearchContacts } from './contacts-handlers.js';
|
|
19
|
+
import { handleGetContacts, handleSearchContacts, handleCreateContact, handleUpdateContact } from './contacts-handlers.js';
|
|
20
20
|
// Import docs handlers
|
|
21
21
|
import { handleReadDocument, handleCreateDocument, handleAppendDocument, handleReplaceDocument, handleFindAndReplace, handleExtractDocumentId, handleListDocumentTabs, handleBatchUpdateDocument } from './docs-handlers.js';
|
|
22
22
|
// Import comments handlers
|
|
@@ -29,6 +29,10 @@ import { handleReadSpreadsheet, handleReadSpreadsheetValues, handleCreateSpreads
|
|
|
29
29
|
import { handleListTaskLists, handleListTasks, handleCreateTask, handleUpdateTask, handleCompleteTask, handleDeleteTask } from './tasks-handlers.js';
|
|
30
30
|
// Import forms handlers
|
|
31
31
|
import { handleListForms, handleGetForm, handleListFormResponses, handleGetFormResponse } from './forms-handlers.js';
|
|
32
|
+
// Import chat handlers
|
|
33
|
+
import { handleListChatSpaces, handleListChatMessages, handleSendChatMessage } from './chat-handlers.js';
|
|
34
|
+
// Import meet handlers
|
|
35
|
+
import { handleListMeetConferenceRecords, handleListMeetTranscripts, handleGetMeetTranscriptEntries } from './meet-handlers.js';
|
|
32
36
|
// Import error types
|
|
33
37
|
import { AccountError } from '../modules/accounts/types.js';
|
|
34
38
|
import { GmailError } from '../modules/gmail/types.js';
|
|
@@ -36,7 +40,7 @@ import { CalendarError } from '../modules/calendar/types.js';
|
|
|
36
40
|
import { ContactsError } from '../modules/contacts/types.js';
|
|
37
41
|
// Import service initializer
|
|
38
42
|
import { initializeAllServices } from '../utils/service-initializer.js';
|
|
39
|
-
import { assertBaseToolArguments, assertListCalendarsArgs, assertCalendarEventParams, assertEmailEventIdArgs, assertSendEmailArgs, assertManageDraftParams, assertManageLabelParams, assertManageLabelAssignmentParams, assertManageLabelFilterParams, assertDriveFileListArgs, assertDriveSearchArgs, assertDriveUploadArgs, assertDriveDownloadArgs, assertDriveFolderArgs, assertDrivePermissionArgs, assertDriveDeleteArgs, assertDriveCopyArgs, assertDriveMoveArgs, assertDriveTrashArgs, assertDriveRevisionsArgs, assertDriveDownloadRevisionArgs, assertManageAttachmentParams, assertGetContactsParams, assertReadDocumentArgs, assertCreateDocumentArgs, assertAppendDocumentArgs, assertReplaceDocumentArgs, assertFindReplaceArgs, assertExtractIdArgs, assertListTabsArgs, assertBatchUpdateDocumentArgs, assertReadPresentationArgs, assertCreatePresentationArgs, assertListSlidesArgs, assertGetSlideArgs, assertExtractPresentationIdArgs, assertReadSpreadsheetArgs, assertReadSpreadsheetValuesArgs, assertCreateSpreadsheetArgs, assertAppendSpreadsheetArgs, assertUpdateSpreadsheetValuesArgs, assertClearSpreadsheetValuesArgs, assertListSpreadsheetSheetsArgs, assertAddSpreadsheetSheetArgs, assertDeleteSpreadsheetSheetArgs, assertExtractSpreadsheetIdArgs, assertBatchGetSpreadsheetValuesArgs, assertBatchUpdateSpreadsheetValuesArgs, assertFindReplaceSpreadsheetArgs, assertFormatSpreadsheetCellsArgs, assertBatchUpdatePresentationArgs, assertGetSlideThumbnailArgs, assertListTaskListsArgs, assertListTasksArgs, assertCreateTaskArgs, assertUpdateTaskArgs, assertCompleteTaskArgs, assertDeleteTaskArgs, assertListFormsArgs, assertGetFormArgs, assertListFormResponsesArgs, assertGetFormResponseArgs, assertListCommentsArgs, assertCreateCommentArgs, assertResolveCommentArgs, assertReplyToCommentArgs, assertDeleteCommentArgs, assertGmailQuickActionArgs } from './type-guards.js';
|
|
43
|
+
import { assertBaseToolArguments, assertListCalendarsArgs, assertCalendarEventParams, assertEmailEventIdArgs, assertSendEmailArgs, assertManageDraftParams, assertManageLabelParams, assertManageLabelAssignmentParams, assertManageLabelFilterParams, assertDriveFileListArgs, assertDriveSearchArgs, assertListSharedDrivesArgs, assertDriveUploadArgs, assertDriveDownloadArgs, assertDriveFolderArgs, assertDrivePermissionArgs, assertDriveDeleteArgs, assertDriveCopyArgs, assertDriveMoveArgs, assertDriveTrashArgs, assertDriveRevisionsArgs, assertDriveDownloadRevisionArgs, assertManageAttachmentParams, assertGetContactsParams, assertReadDocumentArgs, assertCreateDocumentArgs, assertAppendDocumentArgs, assertReplaceDocumentArgs, assertFindReplaceArgs, assertExtractIdArgs, assertListTabsArgs, assertBatchUpdateDocumentArgs, assertReadPresentationArgs, assertCreatePresentationArgs, assertListSlidesArgs, assertGetSlideArgs, assertExtractPresentationIdArgs, assertReadSpreadsheetArgs, assertReadSpreadsheetValuesArgs, assertCreateSpreadsheetArgs, assertAppendSpreadsheetArgs, assertUpdateSpreadsheetValuesArgs, assertClearSpreadsheetValuesArgs, assertListSpreadsheetSheetsArgs, assertAddSpreadsheetSheetArgs, assertDeleteSpreadsheetSheetArgs, assertExtractSpreadsheetIdArgs, assertBatchGetSpreadsheetValuesArgs, assertBatchUpdateSpreadsheetValuesArgs, assertFindReplaceSpreadsheetArgs, assertFormatSpreadsheetCellsArgs, assertBatchUpdatePresentationArgs, assertGetSlideThumbnailArgs, assertListTaskListsArgs, assertListTasksArgs, assertCreateTaskArgs, assertUpdateTaskArgs, assertCompleteTaskArgs, assertDeleteTaskArgs, assertListFormsArgs, assertGetFormArgs, assertListFormResponsesArgs, assertGetFormResponseArgs, assertListCommentsArgs, assertCreateCommentArgs, assertResolveCommentArgs, assertReplyToCommentArgs, assertDeleteCommentArgs, assertGmailQuickActionArgs } from './type-guards.js';
|
|
40
44
|
import { COMPOSE_EMAIL_HTML } from '../resources/compose-email-template.js';
|
|
41
45
|
import { normalizeArgs } from './param-normalizer.js';
|
|
42
46
|
function isInlineUiToolResult(result) {
|
|
@@ -192,6 +196,14 @@ export class GSuiteServer {
|
|
|
192
196
|
assertBaseToolArguments(args);
|
|
193
197
|
result = await handleGetWorkspaceGmailSettings(args);
|
|
194
198
|
break;
|
|
199
|
+
case 'update_workspace_vacation_responder':
|
|
200
|
+
assertBaseToolArguments(args);
|
|
201
|
+
result = await handleUpdateWorkspaceVacationResponder(args);
|
|
202
|
+
break;
|
|
203
|
+
case 'list_workspace_send_as':
|
|
204
|
+
assertBaseToolArguments(args);
|
|
205
|
+
result = await handleListWorkspaceSendAs(args);
|
|
206
|
+
break;
|
|
195
207
|
// Gmail Quick Actions
|
|
196
208
|
case 'archive_workspace_email':
|
|
197
209
|
assertGmailQuickActionArgs(args);
|
|
@@ -358,6 +370,10 @@ export class GSuiteServer {
|
|
|
358
370
|
assertDriveSearchArgs(args);
|
|
359
371
|
result = await handleSearchDriveFiles(args);
|
|
360
372
|
break;
|
|
373
|
+
case 'list_shared_drives':
|
|
374
|
+
assertListSharedDrivesArgs(args);
|
|
375
|
+
result = await handleListSharedDrives(args);
|
|
376
|
+
break;
|
|
361
377
|
case 'upload_drive_file':
|
|
362
378
|
assertDriveUploadArgs(args);
|
|
363
379
|
result = await handleUploadDriveFile(args);
|
|
@@ -402,6 +418,10 @@ export class GSuiteServer {
|
|
|
402
418
|
assertDriveDownloadRevisionArgs(args);
|
|
403
419
|
result = await handleDownloadFileRevision(args);
|
|
404
420
|
break;
|
|
421
|
+
case 'query_drive_activity':
|
|
422
|
+
assertBaseToolArguments(args);
|
|
423
|
+
result = await handleQueryDriveActivity(args);
|
|
424
|
+
break;
|
|
405
425
|
// Contact Operations
|
|
406
426
|
case 'get_workspace_contacts':
|
|
407
427
|
assertGetContactsParams(args);
|
|
@@ -411,6 +431,14 @@ export class GSuiteServer {
|
|
|
411
431
|
assertBaseToolArguments(args);
|
|
412
432
|
result = await handleSearchContacts(args);
|
|
413
433
|
break;
|
|
434
|
+
case 'create_workspace_contact':
|
|
435
|
+
assertBaseToolArguments(args);
|
|
436
|
+
result = await handleCreateContact(args);
|
|
437
|
+
break;
|
|
438
|
+
case 'update_workspace_contact':
|
|
439
|
+
assertBaseToolArguments(args);
|
|
440
|
+
result = await handleUpdateContact(args);
|
|
441
|
+
break;
|
|
414
442
|
// Google Docs Operations
|
|
415
443
|
case 'read_workspace_document':
|
|
416
444
|
assertReadDocumentArgs(args);
|
|
@@ -593,6 +621,32 @@ export class GSuiteServer {
|
|
|
593
621
|
assertGetFormResponseArgs(args);
|
|
594
622
|
result = await handleGetFormResponse(args);
|
|
595
623
|
break;
|
|
624
|
+
// Google Chat Operations
|
|
625
|
+
case 'list_chat_spaces':
|
|
626
|
+
assertBaseToolArguments(args);
|
|
627
|
+
result = await handleListChatSpaces(args);
|
|
628
|
+
break;
|
|
629
|
+
case 'list_chat_messages':
|
|
630
|
+
assertBaseToolArguments(args);
|
|
631
|
+
result = await handleListChatMessages(args);
|
|
632
|
+
break;
|
|
633
|
+
case 'send_chat_message':
|
|
634
|
+
assertBaseToolArguments(args);
|
|
635
|
+
result = await handleSendChatMessage(args);
|
|
636
|
+
break;
|
|
637
|
+
// Google Meet Operations (read-only)
|
|
638
|
+
case 'list_meet_conference_records':
|
|
639
|
+
assertBaseToolArguments(args);
|
|
640
|
+
result = await handleListMeetConferenceRecords(args);
|
|
641
|
+
break;
|
|
642
|
+
case 'list_meet_transcripts':
|
|
643
|
+
assertBaseToolArguments(args);
|
|
644
|
+
result = await handleListMeetTranscripts(args);
|
|
645
|
+
break;
|
|
646
|
+
case 'get_meet_transcript_entries':
|
|
647
|
+
assertBaseToolArguments(args);
|
|
648
|
+
result = await handleGetMeetTranscriptEntries(args);
|
|
649
|
+
break;
|
|
596
650
|
default:
|
|
597
651
|
throw new Error(`Unknown tool: ${request.params.name}`);
|
|
598
652
|
}
|
|
@@ -648,7 +702,15 @@ export class GSuiteServer {
|
|
|
648
702
|
}
|
|
649
703
|
formatErrorResponse(error) {
|
|
650
704
|
const message = error instanceof Error ? error.message : 'Unknown error occurred';
|
|
651
|
-
|
|
705
|
+
// Read the string domain-error `code` from ANY domain error, not just AccountError:
|
|
706
|
+
// CalendarError/GmailError/ContactsError all expose a string `code`, and a
|
|
707
|
+
// `getCalendarClient` auth failure surfaces as `CalendarError('AUTH_REQUIRED')`, not an
|
|
708
|
+
// AccountError. Keying only on `instanceof AccountError` silently dropped those into the
|
|
709
|
+
// generic branch below and skipped the `auth_required` reconnect handoff. McpError's numeric
|
|
710
|
+
// `code` is naturally excluded by the `typeof … === 'string'` guard (its code never matches
|
|
711
|
+
// the string auth codes checked below).
|
|
712
|
+
const rawCode = error?.code;
|
|
713
|
+
const code = typeof rawCode === 'string' ? rawCode : undefined;
|
|
652
714
|
const status = typeof error === 'object' && error !== null
|
|
653
715
|
? error.response?.status
|
|
654
716
|
?? error.status
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { getTasksService } from '../modules/tasks/index.js';
|
|
2
2
|
import { getAccountManager, resolveEmail } from '../modules/accounts/index.js';
|
|
3
3
|
import { McpError, ErrorCode } from '@modelcontextprotocol/sdk/types.js';
|
|
4
|
+
import { toMcpError } from '../utils/apiError.js';
|
|
4
5
|
import { readAliasedBoolean, readAliasedNumber, readAliasedString } from './arg-aliases.js';
|
|
5
6
|
import { wrapUntrustedContent } from '../utils/untrusted-content.js';
|
|
6
7
|
// Singleton instances
|
|
@@ -76,9 +77,7 @@ export async function handleListTaskLists(params) {
|
|
|
76
77
|
return wrapUntrustedContent(lines.join('\n'), 'google-workspace:tasks:task-lists');
|
|
77
78
|
}
|
|
78
79
|
catch (error) {
|
|
79
|
-
|
|
80
|
-
throw error;
|
|
81
|
-
throw new McpError(ErrorCode.InternalError, `Failed to list task lists: ${error instanceof Error ? error.message : 'Unknown error'}`);
|
|
80
|
+
throw toMcpError(error, 'Failed to list task lists');
|
|
82
81
|
}
|
|
83
82
|
});
|
|
84
83
|
}
|
|
@@ -112,9 +111,7 @@ export async function handleListTasks(params) {
|
|
|
112
111
|
return formatTasksAsText(tasks, taskListId, nextPageToken);
|
|
113
112
|
}
|
|
114
113
|
catch (error) {
|
|
115
|
-
|
|
116
|
-
throw error;
|
|
117
|
-
throw new McpError(ErrorCode.InternalError, `Failed to list tasks: ${error instanceof Error ? error.message : 'Unknown error'}`);
|
|
114
|
+
throw toMcpError(error, 'Failed to list tasks');
|
|
118
115
|
}
|
|
119
116
|
});
|
|
120
117
|
}
|
|
@@ -148,9 +145,7 @@ export async function handleCreateTask(params) {
|
|
|
148
145
|
return wrapUntrustedContent(`Task created successfully!\n\nTitle: ${task.title}${dueInfo}${notesInfo}\nID: ${task.id}\nStatus: ${task.status}`, `google-workspace:tasks:task/${task.id}`);
|
|
149
146
|
}
|
|
150
147
|
catch (error) {
|
|
151
|
-
|
|
152
|
-
throw error;
|
|
153
|
-
throw new McpError(ErrorCode.InternalError, `Failed to create task: ${error instanceof Error ? error.message : 'Unknown error'}`);
|
|
148
|
+
throw toMcpError(error, 'Failed to create task');
|
|
154
149
|
}
|
|
155
150
|
});
|
|
156
151
|
}
|
|
@@ -191,9 +186,7 @@ export async function handleUpdateTask(params) {
|
|
|
191
186
|
return wrapUntrustedContent(`Task updated successfully!\n\nTitle: ${task.title}${dueInfo}${notesInfo}\nID: ${task.id}\nStatus: ${task.status}`, `google-workspace:tasks:task/${task.id}`);
|
|
192
187
|
}
|
|
193
188
|
catch (error) {
|
|
194
|
-
|
|
195
|
-
throw error;
|
|
196
|
-
throw new McpError(ErrorCode.InternalError, `Failed to update task: ${error instanceof Error ? error.message : 'Unknown error'}`);
|
|
189
|
+
throw toMcpError(error, 'Failed to update task');
|
|
197
190
|
}
|
|
198
191
|
});
|
|
199
192
|
}
|
|
@@ -225,9 +218,7 @@ export async function handleCompleteTask(params) {
|
|
|
225
218
|
return wrapUntrustedContent(`Task completed!\n\nTitle: ${task.title}\nID: ${task.id}\nCompleted: ${task.completed || 'Yes'}`, `google-workspace:tasks:task/${task.id}`);
|
|
226
219
|
}
|
|
227
220
|
catch (error) {
|
|
228
|
-
|
|
229
|
-
throw error;
|
|
230
|
-
throw new McpError(ErrorCode.InternalError, `Failed to complete task: ${error instanceof Error ? error.message : 'Unknown error'}`);
|
|
221
|
+
throw toMcpError(error, 'Failed to complete task');
|
|
231
222
|
}
|
|
232
223
|
});
|
|
233
224
|
}
|
|
@@ -256,9 +247,7 @@ export async function handleDeleteTask(params) {
|
|
|
256
247
|
return `Task deleted successfully.\n\nTask ID: ${taskId}\nTask List: ${taskListId}`;
|
|
257
248
|
}
|
|
258
249
|
catch (error) {
|
|
259
|
-
|
|
260
|
-
throw error;
|
|
261
|
-
throw new McpError(ErrorCode.InternalError, `Failed to delete task: ${error instanceof Error ? error.message : 'Unknown error'}`);
|
|
250
|
+
throw toMcpError(error, 'Failed to delete task');
|
|
262
251
|
}
|
|
263
252
|
});
|
|
264
253
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { BaseToolArguments, ListCalendarsArgs, CalendarEventParams, SendEmailArgs, ManageLabelParams, ManageLabelAssignmentParams, ManageLabelFilterParams, ManageDraftParams, DriveFileListArgs, DriveSearchArgs, DriveUploadArgs, DriveDownloadArgs, DriveFolderArgs, DrivePermissionArgs, DriveDeleteArgs, ManageAttachmentParams } from './types.js';
|
|
1
|
+
import { BaseToolArguments, ListCalendarsArgs, CalendarEventParams, SendEmailArgs, ManageLabelParams, ManageLabelAssignmentParams, ManageLabelFilterParams, ManageDraftParams, DriveFileListArgs, DriveSearchArgs, ListSharedDrivesArgs, DriveUploadArgs, DriveDownloadArgs, DriveFolderArgs, DrivePermissionArgs, DriveDeleteArgs, ManageAttachmentParams } from './types.js';
|
|
2
2
|
import { GetContactsParams } from '../modules/contacts/types.js';
|
|
3
3
|
export declare function isBaseToolArguments(args: Record<string, unknown>): args is BaseToolArguments;
|
|
4
4
|
export declare function assertBaseToolArguments(args: Record<string, unknown>): asserts args is BaseToolArguments;
|
|
@@ -21,6 +21,8 @@ export declare function isDriveFileListArgs(args: unknown): args is DriveFileLis
|
|
|
21
21
|
export declare function assertDriveFileListArgs(args: unknown): asserts args is DriveFileListArgs;
|
|
22
22
|
export declare function isDriveSearchArgs(args: unknown): args is DriveSearchArgs;
|
|
23
23
|
export declare function assertDriveSearchArgs(args: unknown): asserts args is DriveSearchArgs;
|
|
24
|
+
export declare function isListSharedDrivesArgs(args: Record<string, unknown>): args is ListSharedDrivesArgs;
|
|
25
|
+
export declare function assertListSharedDrivesArgs(args: Record<string, unknown>): asserts args is ListSharedDrivesArgs;
|
|
24
26
|
export declare function isDriveUploadArgs(args: unknown): args is DriveUploadArgs;
|
|
25
27
|
export declare function assertDriveUploadArgs(args: unknown): asserts args is DriveUploadArgs;
|
|
26
28
|
export declare function isDriveDownloadArgs(args: unknown): args is DriveDownloadArgs;
|
|
@@ -111,6 +111,10 @@ export function assertSendEmailArgs(args) {
|
|
|
111
111
|
}
|
|
112
112
|
}
|
|
113
113
|
// Drive Type Guards
|
|
114
|
+
const DRIVE_CORPORA_VALUES = ['user', 'drive', 'allDrives'];
|
|
115
|
+
function isValidCorpora(value) {
|
|
116
|
+
return value === undefined || (typeof value === 'string' && DRIVE_CORPORA_VALUES.includes(value));
|
|
117
|
+
}
|
|
114
118
|
export function isDriveFileListArgs(args) {
|
|
115
119
|
if (typeof args !== 'object' || args === null)
|
|
116
120
|
return false;
|
|
@@ -122,7 +126,9 @@ export function isDriveFileListArgs(args) {
|
|
|
122
126
|
(opts.query === undefined || typeof opts.query === 'string') &&
|
|
123
127
|
(opts.pageSize === undefined || typeof opts.pageSize === 'number') &&
|
|
124
128
|
(opts.orderBy === undefined || (Array.isArray(opts.orderBy) && opts.orderBy.every((o) => typeof o === 'string'))) &&
|
|
125
|
-
(opts.fields === undefined || (Array.isArray(opts.fields) && opts.fields.every((f) => typeof f === 'string')))
|
|
129
|
+
(opts.fields === undefined || (Array.isArray(opts.fields) && opts.fields.every((f) => typeof f === 'string'))) &&
|
|
130
|
+
(opts.driveId === undefined || typeof opts.driveId === 'string') &&
|
|
131
|
+
isValidCorpora(opts.corpora);
|
|
126
132
|
})());
|
|
127
133
|
}
|
|
128
134
|
export function assertDriveFileListArgs(args) {
|
|
@@ -141,13 +147,27 @@ export function isDriveSearchArgs(args) {
|
|
|
141
147
|
(params.options.folderId === undefined || typeof params.options.folderId === 'string') &&
|
|
142
148
|
(params.options.trashed === undefined || typeof params.options.trashed === 'boolean') &&
|
|
143
149
|
(params.options.query === undefined || typeof params.options.query === 'string') &&
|
|
144
|
-
(params.options.pageSize === undefined || typeof params.options.pageSize === 'number')
|
|
150
|
+
(params.options.pageSize === undefined || typeof params.options.pageSize === 'number') &&
|
|
151
|
+
(params.options.driveId === undefined || typeof params.options.driveId === 'string') &&
|
|
152
|
+
isValidCorpora(params.options.corpora);
|
|
145
153
|
}
|
|
146
154
|
export function assertDriveSearchArgs(args) {
|
|
147
155
|
if (!isDriveSearchArgs(args)) {
|
|
148
156
|
throw new Error('Invalid search parameters. Required: email, options');
|
|
149
157
|
}
|
|
150
158
|
}
|
|
159
|
+
export function isListSharedDrivesArgs(args) {
|
|
160
|
+
const pageSize = readAliasedArg(args, 'page_size', 'pageSize');
|
|
161
|
+
const pageToken = readAliasedArg(args, 'page_token', 'pageToken');
|
|
162
|
+
return (args.email === undefined || typeof args.email === 'string') &&
|
|
163
|
+
(pageSize === undefined || typeof pageSize === 'number') &&
|
|
164
|
+
(pageToken === undefined || typeof pageToken === 'string');
|
|
165
|
+
}
|
|
166
|
+
export function assertListSharedDrivesArgs(args) {
|
|
167
|
+
if (!isListSharedDrivesArgs(args)) {
|
|
168
|
+
throw new Error('Invalid list shared drives parameters - page_size must be a number and page_token a string when provided');
|
|
169
|
+
}
|
|
170
|
+
}
|
|
151
171
|
export function isDriveUploadArgs(args) {
|
|
152
172
|
if (typeof args !== 'object' || args === null)
|
|
153
173
|
return false;
|
package/dist/tools/types.d.ts
CHANGED
|
@@ -136,6 +136,8 @@ export interface DriveFileListArgs extends BaseToolArguments {
|
|
|
136
136
|
pageSize?: number;
|
|
137
137
|
orderBy?: string[];
|
|
138
138
|
fields?: string[];
|
|
139
|
+
driveId?: string;
|
|
140
|
+
corpora?: 'user' | 'drive' | 'allDrives';
|
|
139
141
|
};
|
|
140
142
|
}
|
|
141
143
|
/**
|
|
@@ -149,8 +151,19 @@ export interface DriveSearchArgs extends BaseToolArguments {
|
|
|
149
151
|
trashed?: boolean;
|
|
150
152
|
query?: string;
|
|
151
153
|
pageSize?: number;
|
|
154
|
+
driveId?: string;
|
|
155
|
+
corpora?: 'user' | 'drive' | 'allDrives';
|
|
152
156
|
};
|
|
153
157
|
}
|
|
158
|
+
/**
|
|
159
|
+
* Parameters for listing shared drives
|
|
160
|
+
*/
|
|
161
|
+
export interface ListSharedDrivesArgs extends BaseToolArguments {
|
|
162
|
+
page_size?: number;
|
|
163
|
+
pageSize?: number;
|
|
164
|
+
page_token?: string;
|
|
165
|
+
pageToken?: string;
|
|
166
|
+
}
|
|
154
167
|
/**
|
|
155
168
|
* Parameters for uploading files to Drive
|
|
156
169
|
*/
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Extracts the HTTP status from a googleapis (GaxiosError-shaped) failure,
|
|
3
|
+
* preferring `response.status` and falling back to a top-level `status` or a
|
|
4
|
+
* numeric `code`. Returns undefined when no numeric status can be recovered
|
|
5
|
+
* (e.g. a DNS `ENOTFOUND` where `code` is a non-numeric string).
|
|
6
|
+
*/
|
|
7
|
+
export declare function extractHttpStatus(error: unknown): number | undefined;
|
|
8
|
+
/**
|
|
9
|
+
* Turns an unknown thrown value into a diagnosable one-line string: the error
|
|
10
|
+
* message plus the HTTP status when one is recoverable. This is what should be
|
|
11
|
+
* stored in a domain error's `details` field so the real Google cause survives
|
|
12
|
+
* to the user instead of collapsing to "Unknown error".
|
|
13
|
+
*/
|
|
14
|
+
export declare function describeApiError(error: unknown): string;
|
|
15
|
+
/**
|
|
16
|
+
* Structural check for this connector's domain error classes (GmailError,
|
|
17
|
+
* CalendarError, ContactsError, GoogleServiceError). They all share a
|
|
18
|
+
* `{ message, code, details }` shape with string `code` and string `details`,
|
|
19
|
+
* but have no common base class, so we key on that shape rather than any single
|
|
20
|
+
* `instanceof`. Requiring a string `code` (which every domain error sets when
|
|
21
|
+
* it carries details) guards against a raw transport error (e.g. a GaxiosError
|
|
22
|
+
* with a numeric/string HTTP `code` and some string `details`) being mistaken
|
|
23
|
+
* for a domain error.
|
|
24
|
+
*/
|
|
25
|
+
export declare function hasErrorDetails(error: unknown): error is {
|
|
26
|
+
message: string;
|
|
27
|
+
code: string;
|
|
28
|
+
details: string;
|
|
29
|
+
};
|
|
30
|
+
/**
|
|
31
|
+
* True when `error` is a thrown value that signals the account needs
|
|
32
|
+
* (re)authentication — i.e. it exposes a string `code` in {@link AUTH_HANDOFF_CODES}.
|
|
33
|
+
*/
|
|
34
|
+
export declare function isAuthHandoffError(error: unknown): boolean;
|
|
35
|
+
/**
|
|
36
|
+
* Normalizes any thrown value into an error suitable for a tool handler's outer
|
|
37
|
+
* catch. An McpError (e.g. an InvalidParams validation failure raised earlier
|
|
38
|
+
* in the handler) is passed through unchanged so its code and message survive.
|
|
39
|
+
* An **auth-handoff domain error** (code `AUTH_REQUIRED` /
|
|
40
|
+
* `HOST_ORCHESTRATED_AUTH_REQUIRED`) is ALSO passed through unchanged: wrapping
|
|
41
|
+
* it into `McpError(InternalError)` would erase the domain `code` that
|
|
42
|
+
* `formatErrorResponse` reads to emit the `auth_required` reconnect handoff,
|
|
43
|
+
* silently degrading an expired-token failure to a generic "Failed to …"
|
|
44
|
+
* message. Any other domain error surfaces its `details`; anything else is
|
|
45
|
+
* described with its HTTP status. Prevents the "Failed to X" opaque-error class
|
|
46
|
+
* where the real cause was silently dropped.
|
|
47
|
+
*/
|
|
48
|
+
export declare function toMcpError(error: unknown, fallbackContext: string): Error;
|
|
49
|
+
//# sourceMappingURL=apiError.d.ts.map
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
import { McpError, ErrorCode } from '@modelcontextprotocol/sdk/types.js';
|
|
2
|
+
/**
|
|
3
|
+
* Extracts the HTTP status from a googleapis (GaxiosError-shaped) failure,
|
|
4
|
+
* preferring `response.status` and falling back to a top-level `status` or a
|
|
5
|
+
* numeric `code`. Returns undefined when no numeric status can be recovered
|
|
6
|
+
* (e.g. a DNS `ENOTFOUND` where `code` is a non-numeric string).
|
|
7
|
+
*/
|
|
8
|
+
export function extractHttpStatus(error) {
|
|
9
|
+
if (typeof error !== 'object' || error === null)
|
|
10
|
+
return undefined;
|
|
11
|
+
const candidate = error;
|
|
12
|
+
if (typeof candidate.response?.status === 'number')
|
|
13
|
+
return candidate.response.status;
|
|
14
|
+
if (typeof candidate.status === 'number')
|
|
15
|
+
return candidate.status;
|
|
16
|
+
if (typeof candidate.code === 'number')
|
|
17
|
+
return candidate.code;
|
|
18
|
+
if (typeof candidate.code === 'string' && /^\d+$/.test(candidate.code))
|
|
19
|
+
return Number(candidate.code);
|
|
20
|
+
return undefined;
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Turns an unknown thrown value into a diagnosable one-line string: the error
|
|
24
|
+
* message plus the HTTP status when one is recoverable. This is what should be
|
|
25
|
+
* stored in a domain error's `details` field so the real Google cause survives
|
|
26
|
+
* to the user instead of collapsing to "Unknown error".
|
|
27
|
+
*/
|
|
28
|
+
export function describeApiError(error) {
|
|
29
|
+
const message = error instanceof Error ? error.message : 'Unknown error';
|
|
30
|
+
const status = extractHttpStatus(error);
|
|
31
|
+
return status !== undefined ? `${message} (status ${status})` : message;
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Structural check for this connector's domain error classes (GmailError,
|
|
35
|
+
* CalendarError, ContactsError, GoogleServiceError). They all share a
|
|
36
|
+
* `{ message, code, details }` shape with string `code` and string `details`,
|
|
37
|
+
* but have no common base class, so we key on that shape rather than any single
|
|
38
|
+
* `instanceof`. Requiring a string `code` (which every domain error sets when
|
|
39
|
+
* it carries details) guards against a raw transport error (e.g. a GaxiosError
|
|
40
|
+
* with a numeric/string HTTP `code` and some string `details`) being mistaken
|
|
41
|
+
* for a domain error.
|
|
42
|
+
*/
|
|
43
|
+
export function hasErrorDetails(error) {
|
|
44
|
+
if (typeof error !== 'object' || error === null)
|
|
45
|
+
return false;
|
|
46
|
+
const candidate = error;
|
|
47
|
+
return (typeof candidate.message === 'string' &&
|
|
48
|
+
typeof candidate.code === 'string' &&
|
|
49
|
+
typeof candidate.details === 'string');
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* Auth-handoff error codes: a domain error (AccountError / CalendarError / …)
|
|
53
|
+
* carrying one of these codes must NOT be wrapped into a generic McpError —
|
|
54
|
+
* `server.ts` `formatErrorResponse` keys the structured `auth_required`
|
|
55
|
+
* reconnect handoff on the raw domain error's string `code`. TEMPORARY_AUTH_ERROR
|
|
56
|
+
* (a transient refresh blip) is included so its "try again" resolution survives
|
|
57
|
+
* to the user; formatErrorResponse deliberately does NOT map it to the
|
|
58
|
+
* reconnect CTA. Kept as a
|
|
59
|
+
* structural check (no class import) so it works uniformly across every domain
|
|
60
|
+
* error type without coupling this util to the accounts/calendar/gmail modules.
|
|
61
|
+
*/
|
|
62
|
+
const AUTH_HANDOFF_CODES = new Set(['AUTH_REQUIRED', 'HOST_ORCHESTRATED_AUTH_REQUIRED', 'TEMPORARY_AUTH_ERROR']);
|
|
63
|
+
/**
|
|
64
|
+
* True when `error` is a thrown value that signals the account needs
|
|
65
|
+
* (re)authentication — i.e. it exposes a string `code` in {@link AUTH_HANDOFF_CODES}.
|
|
66
|
+
*/
|
|
67
|
+
export function isAuthHandoffError(error) {
|
|
68
|
+
if (typeof error !== 'object' || error === null)
|
|
69
|
+
return false;
|
|
70
|
+
const code = error.code;
|
|
71
|
+
return typeof code === 'string' && AUTH_HANDOFF_CODES.has(code);
|
|
72
|
+
}
|
|
73
|
+
/**
|
|
74
|
+
* Normalizes any thrown value into an error suitable for a tool handler's outer
|
|
75
|
+
* catch. An McpError (e.g. an InvalidParams validation failure raised earlier
|
|
76
|
+
* in the handler) is passed through unchanged so its code and message survive.
|
|
77
|
+
* An **auth-handoff domain error** (code `AUTH_REQUIRED` /
|
|
78
|
+
* `HOST_ORCHESTRATED_AUTH_REQUIRED`) is ALSO passed through unchanged: wrapping
|
|
79
|
+
* it into `McpError(InternalError)` would erase the domain `code` that
|
|
80
|
+
* `formatErrorResponse` reads to emit the `auth_required` reconnect handoff,
|
|
81
|
+
* silently degrading an expired-token failure to a generic "Failed to …"
|
|
82
|
+
* message. Any other domain error surfaces its `details`; anything else is
|
|
83
|
+
* described with its HTTP status. Prevents the "Failed to X" opaque-error class
|
|
84
|
+
* where the real cause was silently dropped.
|
|
85
|
+
*/
|
|
86
|
+
export function toMcpError(error, fallbackContext) {
|
|
87
|
+
if (error instanceof McpError)
|
|
88
|
+
return error;
|
|
89
|
+
if (isAuthHandoffError(error) && error instanceof Error)
|
|
90
|
+
return error;
|
|
91
|
+
const detail = hasErrorDetails(error) && error.details
|
|
92
|
+
? `${error.message}: ${error.details}`
|
|
93
|
+
: describeApiError(error);
|
|
94
|
+
return new McpError(ErrorCode.InternalError, `${fallbackContext}: ${detail}`);
|
|
95
|
+
}
|
|
96
|
+
//# sourceMappingURL=apiError.js.map
|
|
@@ -52,6 +52,10 @@ const SCOPE_HIERARCHY = {
|
|
|
52
52
|
[`${SCOPE_BASE}presentations`]: [
|
|
53
53
|
`${SCOPE_BASE}presentations.readonly`,
|
|
54
54
|
],
|
|
55
|
+
// Contacts: full access includes readonly
|
|
56
|
+
[`${SCOPE_BASE}contacts`]: [
|
|
57
|
+
`${SCOPE_BASE}contacts.readonly`,
|
|
58
|
+
],
|
|
55
59
|
};
|
|
56
60
|
/**
|
|
57
61
|
* Service-friendly names for scopes (used in error messages)
|
|
@@ -71,16 +75,22 @@ export const SCOPE_SERVICE_NAMES = {
|
|
|
71
75
|
[`${SCOPE_BASE}drive.readonly`]: 'Drive',
|
|
72
76
|
[`${SCOPE_BASE}drive.file`]: 'Drive',
|
|
73
77
|
[`${SCOPE_BASE}drive.appdata`]: 'Drive',
|
|
78
|
+
[`${SCOPE_BASE}drive.activity.readonly`]: 'Drive Activity',
|
|
74
79
|
[`${SCOPE_BASE}documents`]: 'Google Docs',
|
|
75
80
|
[`${SCOPE_BASE}documents.readonly`]: 'Google Docs',
|
|
76
81
|
[`${SCOPE_BASE}spreadsheets`]: 'Google Sheets',
|
|
77
82
|
[`${SCOPE_BASE}spreadsheets.readonly`]: 'Google Sheets',
|
|
78
83
|
[`${SCOPE_BASE}presentations`]: 'Google Slides',
|
|
79
84
|
[`${SCOPE_BASE}presentations.readonly`]: 'Google Slides',
|
|
85
|
+
[`${SCOPE_BASE}contacts`]: 'Contacts',
|
|
80
86
|
[`${SCOPE_BASE}contacts.readonly`]: 'Contacts',
|
|
81
87
|
[`${SCOPE_BASE}tasks`]: 'Google Tasks',
|
|
82
88
|
[`${SCOPE_BASE}forms.body.readonly`]: 'Google Forms',
|
|
83
89
|
[`${SCOPE_BASE}forms.responses.readonly`]: 'Google Forms Responses',
|
|
90
|
+
[`${SCOPE_BASE}chat.spaces.readonly`]: 'Google Chat',
|
|
91
|
+
[`${SCOPE_BASE}chat.messages.readonly`]: 'Google Chat',
|
|
92
|
+
[`${SCOPE_BASE}chat.messages.create`]: 'Google Chat',
|
|
93
|
+
[`${SCOPE_BASE}meetings.space.readonly`]: 'Google Meet',
|
|
84
94
|
};
|
|
85
95
|
/**
|
|
86
96
|
* Check if a required scope is satisfied by the granted scopes.
|