@mindstone/mcp-server-google-workspace 0.5.2 → 0.5.4

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 (45) hide show
  1. package/README.md +27 -1
  2. package/dist/file-read-context.d.ts +57 -0
  3. package/dist/file-read-context.js +36 -0
  4. package/dist/modules/calendar/service.js +97 -90
  5. package/dist/modules/comments/service.js +6 -6
  6. package/dist/modules/docs/service.js +15 -11
  7. package/dist/modules/docs/types.d.ts +4 -0
  8. package/dist/modules/drive/service.js +1 -17
  9. package/dist/modules/forms/service.js +4 -4
  10. package/dist/modules/gmail/services/attachment.js +3 -1
  11. package/dist/modules/gmail/services/base.js +3 -1
  12. package/dist/modules/gmail/services/draft.js +13 -1
  13. package/dist/modules/gmail/services/email.js +13 -4
  14. package/dist/modules/gmail/services/label.js +19 -1
  15. package/dist/modules/gmail/services/settings.js +7 -1
  16. package/dist/modules/sheets/service.js +18 -18
  17. package/dist/modules/slides/service.js +7 -7
  18. package/dist/modules/tasks/service.js +7 -7
  19. package/dist/resources/compose-email-template.d.ts +1 -1
  20. package/dist/resources/compose-email-template.js +107 -53
  21. package/dist/services/base/BaseGoogleService.js +2 -2
  22. package/dist/services/chat/index.js +3 -0
  23. package/dist/services/contacts/index.js +8 -5
  24. package/dist/services/meet/index.js +3 -0
  25. package/dist/tools/calendar-handlers.js +7 -7
  26. package/dist/tools/chat-handlers.js +4 -4
  27. package/dist/tools/contacts-handlers.js +5 -5
  28. package/dist/tools/definitions/gmail.js +4 -0
  29. package/dist/tools/docs-handlers.js +14 -6
  30. package/dist/tools/drive-handlers.d.ts +2 -1
  31. package/dist/tools/drive-handlers.js +21 -16
  32. package/dist/tools/gmail-handlers.d.ts +6 -5
  33. package/dist/tools/gmail-handlers.js +39 -27
  34. package/dist/tools/meet-handlers.js +4 -4
  35. package/dist/tools/server.js +24 -10
  36. package/dist/tools/sheets-handlers.js +4 -4
  37. package/dist/tools/slides-handlers.js +4 -4
  38. package/dist/utils/apiError.d.ts +7 -3
  39. package/dist/utils/apiError.js +37 -16
  40. package/dist/utils/google-retry.d.ts +15 -0
  41. package/dist/utils/google-retry.js +108 -0
  42. package/dist/utils/request-timeout.js +2 -0
  43. package/dist/utils/untrusted-content.d.ts +9 -0
  44. package/dist/utils/untrusted-content.js +37 -0
  45. package/package.json +3 -2
@@ -482,10 +482,13 @@ export const COMPOSE_EMAIL_HTML = `
482
482
  // already reviewed before clicking Send.
483
483
  var draftApplied = false;
484
484
  var pendingRequestId = null;
485
- var pendingPayload = null;
485
+ var pendingSendPayload = null;
486
+ // Retain across the local timeout so even a late reply clears its payload.
487
+ var pendingSendRequestId = null;
486
488
  var sending = false;
489
+ var hostSending = false;
487
490
  var collapsed = false;
488
- var outcomeUnknown = false;
491
+ var sendMayHaveGone = false;
489
492
  var sent = false;
490
493
  // Which action the in-flight request belongs to ('send' | 'draft').
491
494
  // Captured before clearing on reply/timeout so the response handler can
@@ -660,8 +663,11 @@ export const COMPOSE_EMAIL_HTML = `
660
663
  }
661
664
 
662
665
  function setSending(nextSending) {
666
+ // Only a host outcome can release another copy's in-flight send.
667
+ nextSending = nextSending || hostSending;
663
668
  sending = nextSending;
664
669
  sendButton.disabled = nextSending || sendBlocked;
670
+ retryButton.disabled = nextSending;
665
671
  draftButton.disabled = nextSending;
666
672
  cancelButton.disabled = nextSending;
667
673
  toInput.disabled = nextSending;
@@ -675,11 +681,8 @@ export const COMPOSE_EMAIL_HTML = `
675
681
  postResize();
676
682
  }
677
683
 
678
- // Mirror of setSending for the Save-draft action. One request is in
679
- // flight at a time (both paths share pendingRequestId and set the same
680
- // \`sending\` flag), so the two busy states can never overlap; every
681
- // control locks either way and only the active button shows a spinner
682
- // and aria-busy.
684
+ // One local request is in flight at a time, but a send in another
685
+ // copy can overlap this draft save and must keep the controls locked.
683
686
  function setSavingDraft(nextSaving) {
684
687
  sending = nextSaving;
685
688
  sendButton.disabled = nextSaving || sendBlocked;
@@ -696,6 +699,7 @@ export const COMPOSE_EMAIL_HTML = `
696
699
  draftSpinner.classList.toggle('hidden', !nextSaving);
697
700
  draftLabel.textContent = nextSaving ? 'Saving…' : 'Save draft';
698
701
  draftButton.setAttribute('aria-busy', nextSaving ? 'true' : 'false');
702
+ if (hostSending) setSending(true);
699
703
  postResize();
700
704
  }
701
705
 
@@ -705,6 +709,7 @@ export const COMPOSE_EMAIL_HTML = `
705
709
  }
706
710
 
707
711
  function showError(message) {
712
+ retryButton.classList.toggle('hidden', sendBlocked && retryAction !== 'draft');
708
713
  errorText.textContent = message || 'Failed to send email.';
709
714
  errorBox.classList.remove('hidden');
710
715
  postResize();
@@ -729,10 +734,10 @@ export const COMPOSE_EMAIL_HTML = `
729
734
  }
730
735
 
731
736
  function clearUnknown() {
732
- outcomeUnknown = false;
733
737
  unknownTitle.textContent = '';
734
738
  unknownText.textContent = '';
735
739
  unknownBox.classList.add('hidden');
740
+ errorBox.appendChild(retryButton);
736
741
  }
737
742
 
738
743
  // No reply ever came back for the send (e.g. the host's response was lost
@@ -741,18 +746,19 @@ export const COMPOSE_EMAIL_HTML = `
741
746
  // tell the user to verify before resending (the send is not idempotent, so
742
747
  // a blind retry could send a duplicate).
743
748
  function showSendUnknown() {
744
- outcomeUnknown = true;
749
+ sendMayHaveGone = true;
745
750
  clearError();
746
751
  clearSuccess();
747
752
  unknownTitle.textContent = 'Not sure if this sent.';
748
753
  unknownText.textContent = "No confirmation came back in time. Check your Sent folder before sending again, so it doesn't go out twice.";
749
754
  unknownBox.classList.remove('hidden');
755
+ if (!sendBlocked) unknownBox.appendChild(retryButton);
750
756
  postResize();
751
757
  }
752
758
 
753
759
  function handleSendTimeout() {
754
760
  sendTimeoutId = null;
755
- if (!pendingRequestId) {
761
+ if (!pendingRequestId || sent) {
756
762
  return;
757
763
  }
758
764
  pendingRequestId = null;
@@ -771,7 +777,6 @@ export const COMPOSE_EMAIL_HTML = `
771
777
  // could create a duplicate draft, so we say we're not sure and point at
772
778
  // the Drafts folder instead of offering Retry.
773
779
  function showDraftSaveUnknown() {
774
- outcomeUnknown = true;
775
780
  clearError();
776
781
  clearSuccess();
777
782
  unknownTitle.textContent = 'Not sure if the draft was saved.';
@@ -837,8 +842,9 @@ export const COMPOSE_EMAIL_HTML = `
837
842
  }
838
843
 
839
844
  function sendPayload(payload) {
840
- pendingPayload = payload;
845
+ pendingSendPayload = payload;
841
846
  pendingRequestId = 'send-' + Date.now() + '-' + Math.random().toString(16).slice(2);
847
+ pendingSendRequestId = pendingRequestId;
842
848
  pendingAction = 'send';
843
849
  retryAction = null;
844
850
  setSending(true);
@@ -854,6 +860,7 @@ export const COMPOSE_EMAIL_HTML = `
854
860
  method: 'tools/call',
855
861
  params: {
856
862
  name: 'send_workspace_email',
863
+ _meta: { 'mcp-app/cardOutcome': 'sent' },
857
864
  arguments: payload
858
865
  },
859
866
  id: pendingRequestId
@@ -863,7 +870,6 @@ export const COMPOSE_EMAIL_HTML = `
863
870
  }
864
871
 
865
872
  function saveDraftPayload(payload) {
866
- pendingPayload = payload;
867
873
  pendingRequestId = 'draft-' + Date.now() + '-' + Math.random().toString(16).slice(2);
868
874
  pendingAction = 'draft';
869
875
  retryAction = null;
@@ -993,13 +999,13 @@ export const COMPOSE_EMAIL_HTML = `
993
999
  }
994
1000
 
995
1001
  // ---- Blocked-send Gmail escape hatch ----
996
- // Shown ONLY when the user's own choice blocks sending (structured
997
- // user-disabled reason, or legacy -33008 + "disabled by user preference"). We
1002
+ // Shown ONLY when the user's own choice blocks sending (the host's
1003
+ // closed 'user-disabled' reason). We
998
1004
  // never call the disabled tool; instead we open a prefilled Gmail compose
999
1005
  // window so the user finishes the send in Gmail (no copy-paste). This is
1000
1006
  // deliberately narrow: admin-disabled ("disabled by your organization…")
1001
- // and generic security-policy blocks fall through to the normal retryable
1002
- // error, because offering a Gmail bypass there would route around a control
1007
+ // and generic security-policy blocks show the reason without Retry,
1008
+ // because offering a Gmail bypass there would route around a control
1003
1009
  // the user did not set.
1004
1010
  //
1005
1011
  // Gmail compose URLs that get too long can silently fail to open, so we cap
@@ -1009,14 +1015,6 @@ export const COMPOSE_EMAIL_HTML = `
1009
1015
  var BLOCKED_SEND_MESSAGE =
1010
1016
  "You've blocked sending this email, so this card can't send it. You can finish and send it in Gmail instead.";
1011
1017
 
1012
- function isUserDisabledSendError(message) {
1013
- var m = String(message || '').toLowerCase();
1014
- // Anchor the code so it can't match inside a longer number (-330080),
1015
- // and require the user-preference phrase so admin-disabled / generic
1016
- // security blocks fall through to the ordinary retryable error.
1017
- return /-33008\\b/.test(m) && m.indexOf('disabled by user preference') !== -1;
1018
- }
1019
-
1020
1018
  // Base URL + path are constant (code-reviewed here, never config-provided);
1021
1019
  // only the field VALUES vary and go through URLSearchParams, so query
1022
1020
  // delimiters, newlines, and reserved characters become encoded data — no
@@ -1044,10 +1042,10 @@ export const COMPOSE_EMAIL_HTML = `
1044
1042
  }
1045
1043
 
1046
1044
  function showBlockedSend() {
1047
- sendBlocked = true;
1048
1045
  clearError();
1049
1046
  clearSuccess();
1050
1047
  clearUnknown();
1048
+ if (sendMayHaveGone) showSendUnknown();
1051
1049
  sendButton.disabled = true;
1052
1050
  sendButton.title =
1053
1051
  "You've blocked sending this email. Open it in Gmail to send it there.";
@@ -1100,9 +1098,12 @@ export const COMPOSE_EMAIL_HTML = `
1100
1098
  return 'https://mail.google.com/mail/u/' + userPart + '/#all/' + encodeURIComponent(id);
1101
1099
  }
1102
1100
 
1103
- function formatSentTime() {
1101
+ function formatSentTime(at) {
1102
+ if (typeof at !== 'number' || !Number.isFinite(at)) return '';
1103
+ var date = new Date(at);
1104
+ if (!Number.isFinite(date.getTime())) return '';
1104
1105
  try {
1105
- return new Date().toLocaleString(undefined, {
1106
+ return date.toLocaleString(undefined, {
1106
1107
  month: 'short', day: 'numeric', hour: 'numeric', minute: '2-digit'
1107
1108
  });
1108
1109
  } catch (_) {
@@ -1110,6 +1111,41 @@ export const COMPOSE_EMAIL_HTML = `
1110
1111
  }
1111
1112
  }
1112
1113
 
1114
+ function applyCardOutcome(o) {
1115
+ if (sent) return;
1116
+ if (pendingRequestId && pendingRequestId === pendingSendRequestId &&
1117
+ (!o || o.outcome === 'sending' || o.outcome === 'maybe-sent')) return;
1118
+ if (hostSending) {
1119
+ hostSending = false;
1120
+ setSending(false);
1121
+ if (sendMayHaveGone) showSendUnknown();
1122
+ }
1123
+ if (!o || typeof o !== 'object') return;
1124
+ if (o.outcome === 'sending') {
1125
+ hostSending = true;
1126
+ setCollapsed(false);
1127
+ setSending(true);
1128
+ clearUnknown();
1129
+ return;
1130
+ }
1131
+ if (o.outcome === 'maybe-sent') {
1132
+ showSendUnknown();
1133
+ setCollapsed(false);
1134
+ return;
1135
+ }
1136
+ if (o.outcome !== 'sent' && o.outcome !== 'submitted') return;
1137
+ sent = true;
1138
+ sendMayHaveGone = false;
1139
+ clearSendTimeout();
1140
+ clearError();
1141
+ clearSuccess();
1142
+ clearUnknown();
1143
+ var stamp = formatSentTime(o.at);
1144
+ setCollapsed(true, stamp ? 'Email sent · ' + stamp : 'Email sent.');
1145
+ if (pendingSendPayload) renderSentView(pendingSendPayload, null, stamp);
1146
+ reopenButton.classList.toggle('hidden', !pendingSendPayload);
1147
+ }
1148
+
1113
1149
  function renderSentView(payload, meta, stamp) {
1114
1150
  payload = payload && typeof payload === 'object' ? payload : {};
1115
1151
  sentTimestamp.textContent = stamp ? 'Sent ' + stamp : 'Sent';
@@ -1128,13 +1164,9 @@ export const COMPOSE_EMAIL_HTML = `
1128
1164
  }
1129
1165
 
1130
1166
  function handleSendRequest() {
1167
+ if (sent) return;
1131
1168
  if (sending) return;
1132
- // Once the user's own send preference has blocked this tool, never
1133
- // re-invoke it — the escape hatch is the only path out. The Send button
1134
- // is already disabled, but this also fends off a future host that grants
1135
- // allow-forms (a submit could otherwise re-fire the disabled tool).
1136
1169
  if (sendBlocked) return;
1137
-
1138
1170
  var payload = readFormPayload();
1139
1171
  var validationError = validatePayload(payload);
1140
1172
  if (validationError) {
@@ -1178,7 +1210,9 @@ export const COMPOSE_EMAIL_HTML = `
1178
1210
  });
1179
1211
 
1180
1212
  retryButton.addEventListener('click', function () {
1213
+ if (sent) return;
1181
1214
  if (sending) return;
1215
+ if (sendBlocked && retryAction !== 'draft') return;
1182
1216
  var payload = readFormPayload();
1183
1217
  if (retryAction === 'draft') {
1184
1218
  var draftValidationError = validateDraftPayload(payload);
@@ -1200,9 +1234,8 @@ export const COMPOSE_EMAIL_HTML = `
1200
1234
 
1201
1235
  cancelButton.addEventListener('click', function () {
1202
1236
  if (sending) return;
1203
- // After a lost-reply timeout we don't know if the email sent, so don't
1204
- // claim "Nothing sent." on collapse — point the user to verify instead.
1205
- var collapseMessage = outcomeUnknown
1237
+ // Hiding the notice does not resolve whether an earlier send went out.
1238
+ var collapseMessage = sendMayHaveGone
1206
1239
  ? 'Collapsed. Check your Sent folder if you are not sure.'
1207
1240
  : 'Draft collapsed. Nothing sent.';
1208
1241
  clearError();
@@ -1213,6 +1246,7 @@ export const COMPOSE_EMAIL_HTML = `
1213
1246
 
1214
1247
  reopenButton.addEventListener('click', function () {
1215
1248
  setCollapsed(false);
1249
+ if (!sent && sendMayHaveGone) showSendUnknown();
1216
1250
  });
1217
1251
 
1218
1252
  sentCollapseButton.addEventListener('click', function () {
@@ -1243,9 +1277,9 @@ export const COMPOSE_EMAIL_HTML = `
1243
1277
 
1244
1278
  [toInput, ccInput, bccInput, subjectInput, bodyInput].forEach(function (element) {
1245
1279
  element.addEventListener('input', function () {
1246
- clearError();
1280
+ if (!sendBlocked) clearError();
1247
1281
  clearSuccess();
1248
- clearUnknown();
1282
+ if (!sendMayHaveGone) clearUnknown();
1249
1283
  postResize();
1250
1284
  });
1251
1285
  });
@@ -1269,6 +1303,11 @@ export const COMPOSE_EMAIL_HTML = `
1269
1303
  return;
1270
1304
  }
1271
1305
 
1306
+ if (data.method === 'mcp-app:card-outcome') {
1307
+ if (event.source === window.parent) applyCardOutcome(data.params);
1308
+ return;
1309
+ }
1310
+
1272
1311
  if (data.method === 'ui/notifications/tool-result') {
1273
1312
  // Always parse (so the migration-shim's malformed-envelope warning
1274
1313
  // still fires), but apply only the first successful prefill: a stray
@@ -1282,7 +1321,14 @@ export const COMPOSE_EMAIL_HTML = `
1282
1321
  return;
1283
1322
  }
1284
1323
 
1285
- if (data.jsonrpc !== '2.0' || !pendingRequestId || data.id !== pendingRequestId) {
1324
+ if (data.jsonrpc !== '2.0') return;
1325
+ var completedSendPayload = null;
1326
+ if (pendingSendRequestId && data.id === pendingSendRequestId) {
1327
+ completedSendPayload = pendingSendPayload;
1328
+ pendingSendPayload = null;
1329
+ pendingSendRequestId = null;
1330
+ }
1331
+ if (!pendingRequestId || data.id !== pendingRequestId) {
1286
1332
  return;
1287
1333
  }
1288
1334
 
@@ -1306,16 +1352,20 @@ export const COMPOSE_EMAIL_HTML = `
1306
1352
  // is already cleared, so this is what the Retry handler routes on.
1307
1353
  retryAction = 'draft';
1308
1354
  }
1309
- // Prefer the host-vetted structured reason (a closed enum the host
1310
- // derives from the tool-block error data) and fall back to
1311
- // text-matching the flattened message for hosts that don't forward it
1312
- // yet. Only 'user-disabled' opens the Gmail escape hatch —
1313
- // admin-disabled and security-policy blocks stay ordinary errors (see
1314
- // the detector comment above for why).
1315
- // Send-failure only: a blocked DRAFT tool must never surface the
1316
- // "sending is turned off" copy or the Open-in-Gmail bypass.
1317
1355
  var blockedReason = data.error.data && data.error.data.reason;
1318
- if (completedAction !== 'draft' && (blockedReason === 'user-disabled' || isUserDisabledSendError(errorMessage))) {
1356
+ var retryCannotChangeBlock = blockedReason === 'user-disabled' || blockedReason === 'admin-disabled' || blockedReason === 'security-policy';
1357
+ var blockedBeforeSend = retryCannotChangeBlock || blockedReason === 'not-dispatched';
1358
+ if (completedAction !== 'draft' && retryCannotChangeBlock) {
1359
+ sendBlocked = true;
1360
+ sendButton.disabled = true;
1361
+ }
1362
+ if (completedAction !== 'draft' && (!blockedBeforeSend || sendMayHaveGone)) {
1363
+ showSendUnknown();
1364
+ }
1365
+ // Only the host's closed user-disabled reason permits the Gmail
1366
+ // escape hatch; message text cannot establish why a call failed.
1367
+ // Draft failures must never open the send-only escape hatch.
1368
+ if (completedAction !== 'draft' && blockedReason === 'user-disabled') {
1319
1369
  showBlockedSend();
1320
1370
  return;
1321
1371
  }
@@ -1330,19 +1380,21 @@ export const COMPOSE_EMAIL_HTML = `
1330
1380
  // Collapse to a stamped confirmation and retire the form — Reopen
1331
1381
  // would resurrect an editable copy whose next Save/Send silently
1332
1382
  // diverges from (or duplicates) the saved draft.
1333
- var draftStamp = formatSentTime();
1383
+ var draftStamp = formatSentTime(Date.now());
1334
1384
  setCollapsed(true, draftStamp ? 'Draft saved · ' + draftStamp : 'Draft saved.');
1335
1385
  reopenButton.classList.add('hidden');
1336
1386
  return;
1337
1387
  }
1338
1388
  // Preserve what was sent (and how to reach it) instead of discarding the
1339
- // draft. pendingPayload is the exact payload we posted; the reply carries
1389
+ // draft. completedSendPayload is the exact payload we posted; the reply carries
1340
1390
  // the Gmail message/thread ids. We default to the collapsed summary, but
1341
1391
  // Reopen now restores a read-only view of the sent message.
1342
- var sentPayload = pendingPayload || readFormPayload();
1343
- var stamp = formatSentTime();
1392
+ var sentPayload = completedSendPayload || readFormPayload();
1393
+ var stamp = formatSentTime(Date.now());
1344
1394
  renderSentView(sentPayload, getSendMetaFromResult(data.result), stamp);
1345
1395
  sent = true;
1396
+ sendMayHaveGone = false;
1397
+ reopenButton.classList.remove('hidden');
1346
1398
  setCollapsed(true, stamp ? 'Email sent · ' + stamp : 'Email sent.');
1347
1399
  });
1348
1400
 
@@ -1354,7 +1406,9 @@ export const COMPOSE_EMAIL_HTML = `
1354
1406
  applyThemeFromHostContext();
1355
1407
  setCcVisible(false);
1356
1408
  setBccVisible(false);
1357
- setCollapsed(false);
1409
+ var hostOutcome = (window.__MCP_HOST_CONTEXT__ || {}).cardOutcome;
1410
+ if (hostOutcome) applyCardOutcome(hostOutcome);
1411
+ else setCollapsed(false);
1358
1412
  postResize();
1359
1413
  postReady();
1360
1414
 
@@ -2,7 +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
+ import { isPassthroughGoogleError } from '../../utils/apiError.js';
6
6
  /**
7
7
  * Base error class for Google services
8
8
  */
@@ -90,7 +90,7 @@ export class BaseGoogleService {
90
90
  * used to hit on a first-request auth failure.
91
91
  */
92
92
  handleError(error, context) {
93
- if (isAuthHandoffError(error) && error instanceof Error) {
93
+ if (isPassthroughGoogleError(error) && error instanceof Error) {
94
94
  return error;
95
95
  }
96
96
  if (error instanceof GoogleServiceError) {
@@ -1,3 +1,4 @@
1
+ import { isPassthroughGoogleError } from '../../utils/apiError.js';
1
2
  import { google } from "googleapis";
2
3
  import { BaseGoogleService, GoogleServiceError } from "../base/BaseGoogleService.js";
3
4
  import { ChatError } from "../../modules/chat/types.js";
@@ -97,6 +98,8 @@ export class ChatService extends BaseGoogleService {
97
98
  * GoogleServiceError keeps its code/details, anything else becomes an unknown error.
98
99
  */
99
100
  toChatError(error, fallbackMessage) {
101
+ if (isPassthroughGoogleError(error))
102
+ throw error;
100
103
  // Handle known GoogleServiceError specifically
101
104
  if (error instanceof GoogleServiceError) {
102
105
  // Assuming GoogleServiceError inherits message and data from McpError
@@ -1,6 +1,7 @@
1
1
  import { google } from "googleapis";
2
2
  import { BaseGoogleService, GoogleServiceError } from "../base/BaseGoogleService.js";
3
- import { describeApiError, isAuthHandoffError } from "../../utils/apiError.js";
3
+ import { describeApiError, isPassthroughGoogleError } from "../../utils/apiError.js";
4
+ import { isGoogleRecoveryExhausted } from "../../utils/google-retry.js";
4
5
  import { ContactsError } from "../../modules/contacts/types.js";
5
6
  import { CONTACTS_SCOPES } from "../../modules/contacts/scopes.js";
6
7
  /**
@@ -49,7 +50,7 @@ export class ContactsService extends BaseGoogleService {
49
50
  return response.data;
50
51
  }
51
52
  catch (error) {
52
- if (isAuthHandoffError(error))
53
+ if (isPassthroughGoogleError(error))
53
54
  throw error;
54
55
  // Handle known GoogleServiceError specifically
55
56
  if (error instanceof GoogleServiceError) {
@@ -91,7 +92,9 @@ export class ContactsService extends BaseGoogleService {
91
92
  pageSize: 1,
92
93
  });
93
94
  }
94
- catch {
95
+ catch (error) {
96
+ if (isGoogleRecoveryExhausted(error))
97
+ throw error;
95
98
  // Warmup failures are non-fatal - continue with actual search
96
99
  }
97
100
  // Actual search
@@ -116,7 +119,7 @@ export class ContactsService extends BaseGoogleService {
116
119
  };
117
120
  }
118
121
  catch (error) {
119
- if (isAuthHandoffError(error))
122
+ if (isPassthroughGoogleError(error))
120
123
  throw error;
121
124
  if (error instanceof GoogleServiceError) {
122
125
  const gError = error;
@@ -183,7 +186,7 @@ export class ContactsService extends BaseGoogleService {
183
186
  };
184
187
  }
185
188
  wrapWriteError(error, action) {
186
- if (isAuthHandoffError(error) && error instanceof Error)
189
+ if (isPassthroughGoogleError(error) && error instanceof Error)
187
190
  return error;
188
191
  if (error instanceof GoogleServiceError) {
189
192
  const gError = error;
@@ -1,3 +1,4 @@
1
+ import { isPassthroughGoogleError } from '../../utils/apiError.js';
1
2
  import { google } from "googleapis";
2
3
  import { BaseGoogleService, GoogleServiceError } from "../base/BaseGoogleService.js";
3
4
  import { MeetError } from "../../modules/meet/types.js";
@@ -27,6 +28,8 @@ export class MeetService extends BaseGoogleService {
27
28
  * Maps a thrown error into a MeetError, mirroring the Contacts service.
28
29
  */
29
30
  toMeetError(error, action) {
31
+ if (isPassthroughGoogleError(error))
32
+ throw error;
30
33
  if (error instanceof GoogleServiceError) {
31
34
  // Assuming GoogleServiceError inherits message and data from McpError
32
35
  // Use type assertion as the linter seems unsure
@@ -4,7 +4,7 @@ import { McpError, ErrorCode } from '@modelcontextprotocol/sdk/types.js';
4
4
  import { toMcpError } from '../utils/apiError.js';
5
5
  import { getAccountManager, validateEmail, resolveEmail } from '../modules/accounts/index.js';
6
6
  import { google } from 'googleapis';
7
- import { wrapUntrustedContent, wrapUntrustedJsonStrings } from '../utils/untrusted-content.js';
7
+ import { wrapUntrustedContent, wrapUntrustedJsonStrings, wrapUntrustedJsonControls } from '../utils/untrusted-content.js';
8
8
  // Singleton instances
9
9
  let driveService;
10
10
  let calendarService;
@@ -388,7 +388,7 @@ export async function handleListWorkspaceCalendars(params) {
388
388
  return accountManager.withTokenRenewal(email, async () => {
389
389
  try {
390
390
  const calendars = await calendarService.listCalendars(email);
391
- return wrapUntrustedJsonStrings(calendars, 'google-workspace:calendar:list');
391
+ return wrapUntrustedJsonControls(calendars, 'google-workspace:calendar:list', [], [], ['*.id']);
392
392
  }
393
393
  catch (error) {
394
394
  throw toMcpError(error, 'Failed to list calendars');
@@ -455,7 +455,7 @@ export async function handleListWorkspaceCalendarEvents(params) {
455
455
  const tzInfo = await resolveTimezone(email, events[0]?.start?.timeZone, deviceTimezone);
456
456
  // Return JSON if requested, otherwise format as human-readable text
457
457
  if (returnJson) {
458
- return wrapUntrustedJsonStrings({
458
+ return wrapUntrustedJsonControls({
459
459
  timezoneInfo: {
460
460
  resolved: tzInfo.resolved,
461
461
  source: tzInfo.source,
@@ -465,7 +465,7 @@ export async function handleListWorkspaceCalendarEvents(params) {
465
465
  },
466
466
  referenceTimeUTC: new Date().toISOString(),
467
467
  events
468
- }, 'google-workspace:calendar:events');
468
+ }, 'google-workspace:calendar:events', ['events.*.attachments.*.fileId'], ['events.*.id']);
469
469
  }
470
470
  return formatEventsAsText(events, tzInfo);
471
471
  }
@@ -485,7 +485,7 @@ export async function handleGetWorkspaceCalendarEvent(params) {
485
485
  }
486
486
  return accountManager.withTokenRenewal(email, async () => {
487
487
  try {
488
- return wrapUntrustedJsonStrings(await calendarService.getEvent(email, eventId, calendarId), `google-workspace:calendar:event/${eventId}`);
488
+ return wrapUntrustedJsonControls(await calendarService.getEvent(email, eventId, calendarId), `google-workspace:calendar:event/${eventId}`, ['attachments.*.fileId'], ['id']);
489
489
  }
490
490
  catch (error) {
491
491
  throw toMcpError(error, 'Failed to get calendar event');
@@ -582,7 +582,7 @@ export async function handleCreateWorkspaceCalendarEvent(params) {
582
582
  colorId,
583
583
  transparency
584
584
  });
585
- return wrapUntrustedJsonStrings(createdEvent, 'google-workspace:calendar:event/create');
585
+ return wrapUntrustedJsonControls(createdEvent, 'google-workspace:calendar:event/create', ['attachments.*.fileId'], ['id']);
586
586
  }
587
587
  catch (error) {
588
588
  // CalendarError here is operational (auth/permission/API failure), not caller-arg
@@ -619,7 +619,7 @@ export async function handleManageWorkspaceCalendarEvent(params) {
619
619
  newTimes,
620
620
  colorId
621
621
  });
622
- return wrapUntrustedJsonStrings(managedEvent, `google-workspace:calendar:event/${eventId}`);
622
+ return wrapUntrustedJsonControls(managedEvent, `google-workspace:calendar:event/${eventId}`, ['attachments.*.fileId'], ['eventId']);
623
623
  }
624
624
  catch (error) {
625
625
  throw toMcpError(error, 'Failed to manage calendar event');
@@ -3,7 +3,7 @@ import { McpError, ErrorCode } from "@modelcontextprotocol/sdk/types.js";
3
3
  import { toMcpError } from "../utils/apiError.js";
4
4
  import { getAccountManager, resolveEmail } from "../modules/accounts/index.js";
5
5
  import { readAliasedNumber, readAliasedString } from './arg-aliases.js';
6
- import { wrapUntrustedJsonStrings } from "../utils/untrusted-content.js";
6
+ import { wrapUntrustedJsonControls } from "../utils/untrusted-content.js";
7
7
  // Cap page sizes well below the Chat API maximum (1000) to keep responses manageable
8
8
  const MAX_CHAT_PAGE_SIZE = 100;
9
9
  // Google Chat documents a maximum TOTAL message size of 32,000 bytes
@@ -55,7 +55,7 @@ export async function handleListChatSpaces(params) {
55
55
  pageToken,
56
56
  filter
57
57
  });
58
- return wrapUntrustedJsonStrings(result, 'google-workspace:chat:spaces');
58
+ return wrapUntrustedJsonControls(result, 'google-workspace:chat:spaces', ['nextPageToken', 'spaces.*.name']);
59
59
  }
60
60
  catch (error) {
61
61
  // toMcpError passes an McpError (and auth-handoff errors) through unchanged, and folds
@@ -86,7 +86,7 @@ export async function handleListChatMessages(params) {
86
86
  filter,
87
87
  orderBy
88
88
  });
89
- return wrapUntrustedJsonStrings(result, 'google-workspace:chat:messages');
89
+ return wrapUntrustedJsonControls(result, 'google-workspace:chat:messages', ['nextPageToken', 'messages.*.name', 'messages.*.thread.name']);
90
90
  }
91
91
  catch (error) {
92
92
  throw toMcpError(error, 'Failed to list chat messages');
@@ -116,7 +116,7 @@ export async function handleSendChatMessage(params) {
116
116
  parent: space,
117
117
  text
118
118
  });
119
- return wrapUntrustedJsonStrings(result, 'google-workspace:chat:message');
119
+ return wrapUntrustedJsonControls(result, 'google-workspace:chat:message', ['name', 'thread.name']);
120
120
  }
121
121
  catch (error) {
122
122
  throw toMcpError(error, 'Failed to send chat message');
@@ -3,7 +3,7 @@ import { McpError, ErrorCode } from "@modelcontextprotocol/sdk/types.js";
3
3
  import { toMcpError } from "../utils/apiError.js";
4
4
  import { getAccountManager, resolveEmail } from "../modules/accounts/index.js";
5
5
  import { readAliasedBoolean, readAliasedNumber, readAliasedString } from './arg-aliases.js';
6
- import { wrapUntrustedContent, wrapUntrustedJsonStrings } from "../utils/untrusted-content.js";
6
+ import { wrapUntrustedContent, wrapUntrustedJsonControls } from "../utils/untrusted-content.js";
7
7
  // Singleton instances - Initialize or inject as per project pattern
8
8
  let contactsService;
9
9
  let accountManager;
@@ -45,7 +45,7 @@ export async function handleGetContacts(params) {
45
45
  pageSize,
46
46
  pageToken
47
47
  });
48
- return wrapUntrustedJsonStrings(result, 'google-workspace:contacts:list');
48
+ return wrapUntrustedJsonControls(result, 'google-workspace:contacts:list', ['nextPageToken', 'connections.*.resourceName']);
49
49
  }
50
50
  catch (error) {
51
51
  // toMcpError passes an McpError through, and folds a ContactsError's details into
@@ -99,7 +99,7 @@ export async function handleSearchContacts(params) {
99
99
  pageSize,
100
100
  });
101
101
  if (returnJson) {
102
- return wrapUntrustedJsonStrings(result, 'google-workspace:contacts:search');
102
+ return wrapUntrustedJsonControls(result, 'google-workspace:contacts:search', ['results.*.resourceName']);
103
103
  }
104
104
  return formatContactsAsText(result.results, result.totalResults);
105
105
  }
@@ -144,8 +144,8 @@ function hasAnyWriteField(fields) {
144
144
  return Object.values(fields).some(value => value !== undefined);
145
145
  }
146
146
  function formatWriteResult(action, result) {
147
- // Every string field is enveloped, matching the read handlers' whole-result wrapping.
148
- return wrapUntrustedJsonStrings({ status: 'success', action, contact: result }, 'google-workspace:contacts:write');
147
+ // The provider-generated resource name is reusable; contact text stays enveloped.
148
+ return wrapUntrustedJsonControls({ status: 'success', action, contact: result }, 'google-workspace:contacts:write', ['contact.resourceName']);
149
149
  }
150
150
  /**
151
151
  * Handler for creating a new Google Contact.
@@ -433,6 +433,7 @@ This tool does not send the email directly. It prepares the draft and launches t
433
433
  },
434
434
  {
435
435
  name: 'send_workspace_email',
436
+ _meta: { 'files/readInputs': { version: 1, inputs: [{ selector: ['attachments', '*', 'path'], base: 'connectorCwd', expandTilde: false, when: [{ relativeTo: 'parent', selector: ['content'], test: 'falsy' }] }] } },
436
437
  category: 'Gmail/Messages',
437
438
  description: `Send an email from a Gmail account.
438
439
 
@@ -868,6 +869,7 @@ Attachments are NOT automatically carried over — you must explicitly download
868
869
  },
869
870
  {
870
871
  name: 'create_workspace_draft',
872
+ _meta: { 'files/readInputs': { version: 1, inputs: [{ selector: ['attachments', '*', 'path'], base: 'connectorCwd', expandTilde: false, when: [{ relativeTo: 'parent', selector: ['content'], test: 'falsy' }] }] } },
871
873
  category: 'Gmail/Drafts',
872
874
  description: `Create a new Gmail draft. Use this when the user asks to save to drafts, save/create a Gmail draft, or save an already-drafted email without sending or opening another review UI. Supports plain text and HTML bodies, CC/BCC, reply threading, and attachments.`,
873
875
  annotations: { readOnlyHint: false, destructiveHint: false },
@@ -944,6 +946,7 @@ Attachments are NOT automatically carried over — you must explicitly download
944
946
  },
945
947
  {
946
948
  name: 'update_workspace_draft',
949
+ _meta: { 'files/readInputs': { version: 1, inputs: [{ selector: ['attachments', '*', 'path'], base: 'connectorCwd', expandTilde: false, when: [{ relativeTo: 'parent', selector: ['content'], test: 'falsy' }] }] } },
947
950
  category: 'Gmail/Drafts',
948
951
  description: `Update an existing Gmail draft. Replaces the draft content with the provided fields. Supports attachments and reply threading.`,
949
952
  annotations: { readOnlyHint: false, destructiveHint: false, idempotentHint: true },
@@ -1064,6 +1067,7 @@ Attachments are NOT automatically carried over — you must explicitly download
1064
1067
  },
1065
1068
  {
1066
1069
  name: 'manage_workspace_draft',
1070
+ _meta: { 'files/readInputs': { version: 1, inputs: [{ selector: ['data', 'attachments', '*', 'path'], base: 'connectorCwd', expandTilde: false, when: [{ relativeTo: 'parent', selector: ['content'], test: 'falsy' }, { relativeTo: 'root', selector: ['action'], test: 'equals', value: 'create' }] }, { selector: ['data', 'attachments', '*', 'path'], base: 'connectorCwd', expandTilde: false, when: [{ relativeTo: 'parent', selector: ['content'], test: 'falsy' }, { relativeTo: 'root', selector: ['action'], test: 'equals', value: 'update' }] }] } },
1067
1071
  category: 'Gmail/Drafts',
1068
1072
  description: `Legacy consolidated draft tool. Prefer the individual draft tools for new calls.`,
1069
1073
  aliases: ['manage_draft'],