gogcli-mcp-drive 4.5.0 → 4.5.1

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.
@@ -7,7 +7,7 @@
7
7
  },
8
8
  "metadata": {
9
9
  "description": "Extended Google Drive for Claude via gogcli — auth + full Drive support (upload, download, permissions, comments, shared drives)",
10
- "version": "4.5.0"
10
+ "version": "4.5.1"
11
11
  },
12
12
  "plugins": [
13
13
  {
@@ -15,7 +15,7 @@
15
15
  "displayName": "gogcli (Drive)",
16
16
  "source": "./",
17
17
  "description": "Extended Google Drive for Claude via gogcli — auth + full Drive support (upload, download, permissions, comments, shared drives)",
18
- "version": "4.5.0",
18
+ "version": "4.5.1",
19
19
  "author": {
20
20
  "name": "Chris Hall"
21
21
  },
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "gogcli-mcp-drive",
3
3
  "displayName": "gogcli (Drive)",
4
- "version": "4.5.0",
4
+ "version": "4.5.1",
5
5
  "description": "Extended Google Drive for Claude via gogcli — auth + full Drive support (upload, download, permissions, comments, shared drives)",
6
6
  "author": {
7
7
  "name": "Chris Hall",
package/dist/index.js CHANGED
@@ -35928,6 +35928,7 @@ async function diagnose(err) {
35928
35928
  const isAuthError = !isTransientError && AUTH_ERROR_PATTERN.test(errText);
35929
35929
  const isGridLimitError = GRID_LIMIT_ERROR_PATTERN.test(errText);
35930
35930
  const hint = isInvalidGrant ? INVALID_GRANT_HINT : isAuthError ? AUTH_HINT : isTransientError ? TRANSIENT_HINT : isGridLimitError ? GRID_LIMIT_HINT : "";
35931
+ if (!isAuthError && !isInvalidGrant) return errorResult(`${errText}${hint}`);
35931
35932
  try {
35932
35933
  const accounts = formatAccountList(await run(["auth", "list"]));
35933
35934
  return errorResult(`${errText}
@@ -36023,10 +36024,51 @@ function confirmSpentStore() {
36023
36024
  }
36024
36025
 
36025
36026
  // ../gogcli-mcp/src/dispatch-confirmation.ts
36027
+ var BODY_PREVIEW_MAX = 2048;
36028
+ function bodyPreview(text) {
36029
+ if (!text) return void 0;
36030
+ if (text.length <= BODY_PREVIEW_MAX) return text;
36031
+ return `${text.slice(0, BODY_PREVIEW_MAX)}\u2026 [${text.length - BODY_PREVIEW_MAX} more characters not shown]`;
36032
+ }
36026
36033
  var CONFIRM_ACTION_INSTRUCTION = CONFIRM_TOKEN_INSTRUCTION;
36027
36034
  var CONFIRM_FALLBACK_DESCRIPTION = ' If the client cannot show that prompt (no MCP elicitation, e.g. claude.ai), a two-step flow applies instead: call WITHOUT confirmToken and nothing is sent or changed \u2014 the result has status "confirmation-required", the full preview and a confirmToken. Follow its instruction (by default: show the preview to the user verbatim and only after they explicitly approve it in chat, call again with the SAME arguments plus confirmToken). The tool re-reads what it would act on and refuses (DRAFT_CHANGED, with a fresh preview and token) if it changed; TOKEN_EXPIRED / TOKEN_REUSED / TOKEN_INVALID also do nothing. A server set to MCP_CONFIRM_MODE=refuse refuses instead.';
36035
+ function refusedInRun(what, via, does, instead) {
36036
+ return `${what} ${does} and is not available through ${via}. ${instead}`;
36037
+ }
36028
36038
  function gatedElsewhere(what, via, does, tool) {
36029
- return `${what} ${does} and is not available through ${via}. Use ${tool}, which asks the user to confirm.`;
36039
+ return refusedInRun(what, via, does, `Use ${tool}, which asks the user to confirm.`);
36040
+ }
36041
+ function hasCommandWord(args, words) {
36042
+ return args.find((a) => words.has(a.toLowerCase()));
36043
+ }
36044
+ var COMMENT_ADD_WORDS = /* @__PURE__ */ new Set(["create", "add", "new"]);
36045
+ var COMMENT_REPLY_WORDS = /* @__PURE__ */ new Set(["reply", "respond"]);
36046
+ function hasTrueFlag(args, flag) {
36047
+ const name = `--${flag}`;
36048
+ return args.some((a) => {
36049
+ const lower = a.toLowerCase();
36050
+ if (lower === name) return true;
36051
+ return lower.startsWith(`${name}=`) && lower.slice(name.length + 1) !== "false";
36052
+ });
36053
+ }
36054
+ function vetCommentsRun(service, subcommand, args) {
36055
+ if (subcommand.toLowerCase() !== "comments") return void 0;
36056
+ const reply = hasCommandWord(args, COMMENT_REPLY_WORDS);
36057
+ if (reply) {
36058
+ return gatedElsewhere(
36059
+ `gog ${service} comments ${reply.toLowerCase()}`,
36060
+ `gog_${service}_run`,
36061
+ "notifies the comment thread",
36062
+ `gog_${service}_comments_reply`
36063
+ );
36064
+ }
36065
+ const add = hasCommandWord(args, COMMENT_ADD_WORDS);
36066
+ return add ? gatedElsewhere(
36067
+ `gog ${service} comments ${add.toLowerCase()}`,
36068
+ `gog_${service}_run`,
36069
+ "notifies the file's owner and anyone it mentions",
36070
+ `gog_${service}_comments_add`
36071
+ ) : void 0;
36030
36072
  }
36031
36073
  async function requireDispatchConfirmation(ctx, options) {
36032
36074
  const { action, fallback } = options;
@@ -36188,6 +36230,27 @@ function authToolsFor(defaultServices) {
36188
36230
  }
36189
36231
 
36190
36232
  // ../gogcli-mcp/src/tools/calendar.ts
36233
+ var ASKS = (tool) => `Use ${tool}, which asks the user to confirm.`;
36234
+ var CALENDAR_REFUSED = {
36235
+ create: { does: "can change what guests see", instead: ASKS("gog_calendar_create") },
36236
+ add: { does: "can change what guests see", instead: ASKS("gog_calendar_create") },
36237
+ new: { does: "can change what guests see", instead: ASKS("gog_calendar_create") },
36238
+ update: { does: "can change what guests see", instead: ASKS("gog_calendar_update") },
36239
+ edit: { does: "can change what guests see", instead: ASKS("gog_calendar_update") },
36240
+ set: { does: "can change what guests see", instead: ASKS("gog_calendar_update") },
36241
+ respond: { does: "can change what guests see", instead: ASKS("gog_calendar_respond") },
36242
+ rsvp: { does: "can change what guests see", instead: ASKS("gog_calendar_respond") },
36243
+ reply: { does: "can change what guests see", instead: ASKS("gog_calendar_respond") },
36244
+ move: { does: "moves an event off guests' calendars (and can email them)", instead: ASKS("gog_calendar_move") },
36245
+ transfer: { does: "moves an event off guests' calendars (and can email them)", instead: ASKS("gog_calendar_move") },
36246
+ delete: { does: "removes an event from every guest's calendar (the whole series by default)", instead: ASKS("gog_calendar_delete") },
36247
+ del: { does: "removes an event from every guest's calendar (the whole series by default)", instead: ASKS("gog_calendar_delete") },
36248
+ rm: { does: "removes an event from every guest's calendar (the whole series by default)", instead: ASKS("gog_calendar_delete") },
36249
+ remove: { does: "removes an event from every guest's calendar (the whole series by default)", instead: ASKS("gog_calendar_delete") },
36250
+ "delete-calendar": { does: "deletes a calendar and every event on it", instead: ASKS("gog_calendar_delete_calendar") },
36251
+ "out-of-office": { does: "auto-declines invitations and notifies their organizers", instead: ASKS("gog_calendar_out_of_office") },
36252
+ ooo: { does: "auto-declines invitations and notifies their organizers", instead: ASKS("gog_calendar_out_of_office") }
36253
+ };
36191
36254
  var reminderParams = {
36192
36255
  reminders: external_exports.array(external_exports.string()).max(5).optional().describe(
36193
36256
  `Reminders as method:duration, e.g. ["popup:30m", "email:1d"]. Method is popup or email; duration accepts m/h/d (max 40320 minutes = 4 weeks). Google allows at most 5. These REPLACE the event's reminders \u2014 on update, pass an EMPTY array to drop custom reminders and go back to the calendar's defaults. Cannot be combined with noReminders.`
@@ -36253,8 +36316,25 @@ function inlineFileArg(flag, attachment, opts = {}) {
36253
36316
  }
36254
36317
 
36255
36318
  // ../gogcli-mcp/src/tools/drive.ts
36256
- function vetDriveRun(subcommand, _args) {
36257
- return subcommand.toLowerCase() === "share" ? gatedElsewhere("gog drive share", "gog_drive_run", "grants access to a file", "gog_drive_share") : void 0;
36319
+ var DRIVE_DELETE_WORDS = /* @__PURE__ */ new Set(["delete", "rm", "del"]);
36320
+ function vetDriveRun(subcommand, args) {
36321
+ const sub = subcommand.toLowerCase();
36322
+ if (sub === "share") return gatedElsewhere("gog drive share", "gog_drive_run", "grants access to a file", "gog_drive_share");
36323
+ if (DRIVE_DELETE_WORDS.has(sub) && hasTrueFlag(args, "permanent")) {
36324
+ return gatedElsewhere(`gog drive ${sub} --permanent`, "gog_drive_run", "deletes a file for good, bypassing the trash", "gog_drive_delete");
36325
+ }
36326
+ if (sub === "bulk") {
36327
+ return gatedElsewhere(
36328
+ "gog drive bulk",
36329
+ "gog_drive_run",
36330
+ "rewrites sharing permissions across every matching file in a tree",
36331
+ "gog_drive_share (one file at a time)"
36332
+ );
36333
+ }
36334
+ if (sub === "unshare") {
36335
+ return refusedInRun("gog drive unshare", "gog_drive_run", "removes someone's access to a file", "Use gog_drive_unshare.");
36336
+ }
36337
+ return vetCommentsRun("drive", sub, args);
36258
36338
  }
36259
36339
  var GOOGLE_DOC_MIME = "application/vnd.google-apps.document";
36260
36340
  function shareTargetMeta(raw) {
@@ -36265,6 +36345,26 @@ function shareTargetMeta(raw) {
36265
36345
  return {};
36266
36346
  }
36267
36347
  }
36348
+ function commentSnapshot(raw) {
36349
+ let comment;
36350
+ try {
36351
+ const parsed = JSON.parse(raw);
36352
+ comment = parsed?.comment ?? parsed ?? void 0;
36353
+ } catch {
36354
+ comment = void 0;
36355
+ }
36356
+ const name = typeof comment?.author?.displayName === "string" ? comment.author.displayName : void 0;
36357
+ const email3 = typeof comment?.author?.emailAddress === "string" ? comment.author.emailAddress : void 0;
36358
+ const author = name && email3 ? `${name} <${email3}>` : name ?? email3;
36359
+ return {
36360
+ ...author ? { author } : {},
36361
+ ...typeof comment?.content === "string" ? { content: comment.content } : {},
36362
+ ...typeof comment?.resolved === "boolean" ? { resolved: comment.resolved } : {}
36363
+ };
36364
+ }
36365
+ function commentMentions(text) {
36366
+ return [...new Set(text.match(/(?<=[+@])[\w.+-]+@[\w-]+(?:\.[\w-]+)+/g) ?? [])];
36367
+ }
36268
36368
  function fileMeta(raw) {
36269
36369
  const parsed = JSON.parse(raw);
36270
36370
  const f = parsed.file ?? parsed;
@@ -36373,16 +36473,36 @@ function registerDriveTools(server) {
36373
36473
  return runOrDiagnose(["drive", "move", pos(fileId), `--parent=${parentId}`], { account });
36374
36474
  });
36375
36475
  server.registerTool("gog_drive_delete", {
36376
- description: "Move a Google Drive file to trash, or permanently delete it with permanent=true (irreversible).",
36476
+ description: "Move a Google Drive file to trash, or permanently delete it with permanent=true (irreversible). A permanent delete reads the file and asks the MCP host to show the user a confirmation prompt naming it first; nothing is deleted unless they accept. Moving to trash is recoverable and does not ask." + CONFIRM_FALLBACK_DESCRIPTION,
36377
36477
  annotations: { destructiveHint: true },
36378
36478
  inputSchema: external_exports.object({
36379
36479
  fileId: external_exports.string().describe("File ID to delete"),
36380
- permanent: external_exports.boolean().optional().describe("Permanently delete instead of moving to trash (irreversible)"),
36381
- account: accountParam
36480
+ permanent: external_exports.boolean().optional().describe("Permanently delete instead of moving to trash (irreversible; asks the user first)"),
36481
+ account: accountParam,
36482
+ confirmToken: confirmTokenParam
36382
36483
  })
36383
- }, async ({ fileId, permanent, account }) => {
36484
+ }, async ({ fileId, permanent, account, confirmToken }, ctx) => {
36384
36485
  const args = ["drive", "delete", pos(fileId)];
36385
- if (permanent) args.push("--permanent");
36486
+ if (permanent) {
36487
+ const got = await runOrDiagnose(["drive", "get", pos(fileId)], { account });
36488
+ if (got.isError) return got;
36489
+ const target = { file: { id: fileId, ...shareTargetMeta(resultText(got)) }, permanent: true };
36490
+ const confirmation = await requireDispatchConfirmation(ctx, {
36491
+ action: "drive.delete-permanent",
36492
+ message: "Review and confirm PERMANENTLY deleting this file \u2014 it skips the trash and cannot be recovered:",
36493
+ confirmationLabel: "Confirm that this file should be permanently deleted now.",
36494
+ details: target,
36495
+ unsupportedNote: "Move it to the trash instead (permanent=false); the user can empty the trash from Google Drive.",
36496
+ fallback: {
36497
+ tool: "gog_drive_delete",
36498
+ account,
36499
+ confirmToken,
36500
+ subject: () => ({ target: fileId, payload: target, preview: target })
36501
+ }
36502
+ });
36503
+ if (confirmation) return confirmation;
36504
+ args.push("--permanent");
36505
+ }
36386
36506
  args.push("--force");
36387
36507
  return runOrDiagnose(args, { account });
36388
36508
  });
@@ -36572,7 +36692,7 @@ var failIfNotEmptyParam = external_exports.boolean().optional().describe(
36572
36692
  );
36573
36693
 
36574
36694
  // ../gogcli-mcp/src/server.ts
36575
- var VERSION = true ? "4.5.0" : "0.0.0";
36695
+ var VERSION = true ? "4.5.1" : "0.0.0";
36576
36696
 
36577
36697
  // ../gogcli-mcp/src/bootstrap-auth.ts
36578
36698
  import { join as join5 } from "node:path";
@@ -36836,14 +36956,37 @@ function registerExtraDriveTools(server) {
36836
36956
  return runOrDiagnose(["drive", "comments", "get", pos(fileId), pos(commentId)], { account });
36837
36957
  });
36838
36958
  server.registerTool("gog_drive_comments_add", {
36839
- description: "Add a new comment to a Drive file.",
36959
+ description: "Add a new comment to a Drive file. Drive notifies the file's owner and everyone the text +mentions, so this reads the file and asks the MCP host to show the user a confirmation prompt with the file, the text and who is mentioned first; nothing is posted unless they accept." + CONFIRM_FALLBACK_DESCRIPTION,
36840
36960
  annotations: { destructiveHint: false },
36841
36961
  inputSchema: external_exports.object({
36842
36962
  fileId: external_exports.string().describe("File ID"),
36843
36963
  content: external_exports.string().describe("Comment text"),
36844
- account: accountParam
36964
+ account: accountParam,
36965
+ confirmToken: confirmTokenParam
36845
36966
  })
36846
- }, async ({ fileId, content, account }) => {
36967
+ }, async ({ fileId, content, account, confirmToken }, ctx) => {
36968
+ const got = await runOrDiagnose(["drive", "get", pos(fileId)], { account });
36969
+ if (got.isError) return got;
36970
+ const { name } = shareTargetMeta(resultText(got));
36971
+ const file2 = { id: fileId, ...name !== void 0 ? { name } : {} };
36972
+ const mentions = commentMentions(content);
36973
+ const confirmation = await requireDispatchConfirmation(ctx, {
36974
+ action: "drive.comment-add",
36975
+ message: "Review and confirm this comment \u2014 the file's owner and anyone mentioned are notified:",
36976
+ confirmationLabel: "Confirm that this comment should be posted now.",
36977
+ details: { file: file2, textPreview: bodyPreview(content), mentions },
36978
+ unsupportedNote: "Ask the user to comment from Google Drive.",
36979
+ fallback: {
36980
+ tool: "gog_drive_comments_add",
36981
+ account,
36982
+ confirmToken,
36983
+ subject: () => {
36984
+ const view = { file: file2, text: content, mentions };
36985
+ return { target: fileId, payload: view, preview: view };
36986
+ }
36987
+ }
36988
+ });
36989
+ if (confirmation) return confirmation;
36847
36990
  return runOrDiagnose(["drive", "comments", "create", pos(fileId), pos(content)], { account });
36848
36991
  });
36849
36992
  server.registerTool("gog_drive_comments_update", {
@@ -36870,18 +37013,44 @@ function registerExtraDriveTools(server) {
36870
37013
  return runOrDiagnose(["drive", "comments", "delete", pos(fileId), pos(commentId), "--force"], { account });
36871
37014
  });
36872
37015
  server.registerTool("gog_drive_comments_reply", {
36873
- description: 'Reply to an existing comment on a Drive file. Pass `action: "resolve"` or `"reopen"` to atomically flip the parent comment\'s resolved state via the Drive API\'s Reply.action field \u2014 avoids the older workaround of deleting the comment (which destroys review-thread context).',
37016
+ description: 'Reply to an existing comment on a Drive file. Pass `action: "resolve"` or `"reopen"` to atomically flip the parent comment\'s resolved state via the Drive API\'s Reply.action field \u2014 avoids the older workaround of deleting the comment (which destroys review-thread context). Everyone on the thread and anyone the reply +mentions is notified, so this reads the file and the comment and asks the MCP host to show the user a confirmation prompt with both and the reply first; nothing is posted unless they accept.' + CONFIRM_FALLBACK_DESCRIPTION,
36874
37017
  annotations: { destructiveHint: false },
36875
37018
  inputSchema: external_exports.object({
36876
37019
  fileId: external_exports.string().describe("File ID"),
36877
37020
  commentId: external_exports.string().describe("Comment ID to reply to"),
36878
37021
  content: external_exports.string().describe("Reply text"),
36879
37022
  action: external_exports.enum(["resolve", "reopen"]).optional().describe("Optional action on the parent comment alongside the reply"),
36880
- account: accountParam
37023
+ account: accountParam,
37024
+ confirmToken: confirmTokenParam
36881
37025
  })
36882
- }, async ({ fileId, commentId, content, action, account }) => {
37026
+ }, async ({ fileId, commentId, content, action, account, confirmToken }, ctx) => {
36883
37027
  const args = ["drive", "comments", "reply", pos(fileId), pos(commentId), pos(content)];
36884
37028
  if (action) args.push(`--action=${action}`);
37029
+ const got = await runOrDiagnose(["drive", "get", pos(fileId)], { account });
37030
+ if (got.isError) return got;
37031
+ const thread = await runOrDiagnose(["drive", "comments", "get", pos(fileId), pos(commentId)], { account });
37032
+ if (thread.isError) return thread;
37033
+ const { name } = shareTargetMeta(resultText(got));
37034
+ const file2 = { id: fileId, ...name !== void 0 ? { name } : {} };
37035
+ const replyingTo = commentSnapshot(resultText(thread));
37036
+ const mentions = commentMentions(content);
37037
+ const confirmation = await requireDispatchConfirmation(ctx, {
37038
+ action: "drive.comment-reply",
37039
+ message: "Review and confirm this reply \u2014 everyone on the thread and anyone mentioned is notified:",
37040
+ confirmationLabel: "Confirm that this reply should be posted now.",
37041
+ details: { file: file2, replyingTo, textPreview: bodyPreview(content), mentions, ...action ? { action } : {} },
37042
+ unsupportedNote: "Ask the user to reply from Google Drive.",
37043
+ fallback: {
37044
+ tool: "gog_drive_comments_reply",
37045
+ account,
37046
+ confirmToken,
37047
+ subject: () => {
37048
+ const view = { file: file2, replyingTo, text: content, mentions, ...action ? { action } : {} };
37049
+ return { target: `${fileId}/${commentId}`, payload: view, preview: view };
37050
+ }
37051
+ }
37052
+ });
37053
+ if (confirmation) return confirmation;
36885
37054
  return runOrDiagnose(args, { account });
36886
37055
  });
36887
37056
  server.registerTool("gog_drive_comments_resolve", {
package/manifest.json CHANGED
@@ -3,7 +3,7 @@
3
3
  "manifest_version": "0.3",
4
4
  "name": "gogcli-mcp-drive",
5
5
  "display_name": "gogcli (Drive)",
6
- "version": "4.5.0",
6
+ "version": "4.5.1",
7
7
  "description": "Extended Google Drive for Claude via gogcli — auth + full Drive support (upload, download, permissions, comments, shared drives)",
8
8
  "author": {
9
9
  "name": "Chris Hall",
@@ -130,7 +130,7 @@
130
130
  },
131
131
  {
132
132
  "name": "gog_drive_delete",
133
- "description": "Delete a file (trash by default, or permanent=true for irreversible delete)"
133
+ "description": "Delete a file (trash by default, or permanent=true for irreversible delete) (a permanent delete asks the user to confirm)"
134
134
  },
135
135
  {
136
136
  "name": "gog_drive_share",
@@ -182,7 +182,7 @@
182
182
  },
183
183
  {
184
184
  "name": "gog_drive_comments_add",
185
- "description": "Add a new comment"
185
+ "description": "Add a new comment (asks the user to confirm)"
186
186
  },
187
187
  {
188
188
  "name": "gog_drive_comments_update",
@@ -194,7 +194,7 @@
194
194
  },
195
195
  {
196
196
  "name": "gog_drive_comments_reply",
197
- "description": "Reply to an existing comment (optionally resolve/reopen the parent atomically via action)"
197
+ "description": "Reply to an existing comment (optionally resolve/reopen the parent atomically via action) (asks the user to confirm)"
198
198
  },
199
199
  {
200
200
  "name": "gog_drive_comments_resolve",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "gogcli-mcp-drive",
3
- "version": "4.5.0",
3
+ "version": "4.5.1",
4
4
  "mcpName": "io.github.chrischall/gogcli-mcp-drive",
5
5
  "description": "Extended Google Drive MCP server via gogcli — auth + full Drive support (upload/download/permissions/comments/shared drives)",
6
6
  "author": "Claude Code (AI) <https://www.anthropic.com/claude>",
package/server.json CHANGED
@@ -7,12 +7,12 @@
7
7
  "source": "github",
8
8
  "subfolder": "packages/gogcli-mcp-drive"
9
9
  },
10
- "version": "4.5.0",
10
+ "version": "4.5.1",
11
11
  "packages": [
12
12
  {
13
13
  "registryType": "npm",
14
14
  "identifier": "gogcli-mcp-drive",
15
- "version": "4.5.0",
15
+ "version": "4.5.1",
16
16
  "transport": {
17
17
  "type": "stdio"
18
18
  },
@@ -1,6 +1,25 @@
1
1
  import { McpServer } from '@modelcontextprotocol/server';
2
2
  import { z } from 'zod';
3
- import { accountParam, runOrDiagnose, paginationParams, pushPaginationFlags, pageTokenParam, pageAliasParam, resolvePageToken, inlineFileArg, pos, confinePath } from '../../../gogcli-mcp/src/lib.js';
3
+ import {
4
+ accountParam,
5
+ runOrDiagnose,
6
+ paginationParams,
7
+ pushPaginationFlags,
8
+ pageTokenParam,
9
+ pageAliasParam,
10
+ resolvePageToken,
11
+ inlineFileArg,
12
+ pos,
13
+ confinePath,
14
+ bodyPreview,
15
+ commentMentions,
16
+ commentSnapshot,
17
+ CONFIRM_FALLBACK_DESCRIPTION,
18
+ confirmTokenParam,
19
+ requireDispatchConfirmation,
20
+ resultText,
21
+ shareTargetMeta,
22
+ } from '../../../gogcli-mcp/src/lib.js';
4
23
  import type { GogArg } from '../../../gogcli-mcp/src/lib.js';
5
24
 
6
25
  export function registerExtraDriveTools(server: McpServer): void {
@@ -222,14 +241,39 @@ export function registerExtraDriveTools(server: McpServer): void {
222
241
  });
223
242
 
224
243
  server.registerTool('gog_drive_comments_add', {
225
- description: 'Add a new comment to a Drive file.',
244
+ description: 'Add a new comment to a Drive file. Drive notifies the file\'s owner and everyone the text +mentions, so '
245
+ + 'this reads the file and asks the MCP host to show the user a confirmation prompt with the file, the text and who '
246
+ + 'is mentioned first; nothing is posted unless they accept.' + CONFIRM_FALLBACK_DESCRIPTION,
226
247
  annotations: { destructiveHint: false },
227
248
  inputSchema: z.object({
228
249
  fileId: z.string().describe('File ID'),
229
250
  content: z.string().describe('Comment text'),
230
251
  account: accountParam,
252
+ confirmToken: confirmTokenParam,
231
253
  }),
232
- }, async ({ fileId, content, account }) => {
254
+ }, async ({ fileId, content, account, confirmToken }, ctx) => {
255
+ const got = await runOrDiagnose(['drive', 'get', pos(fileId)], { account });
256
+ if (got.isError) return got;
257
+ const { name } = shareTargetMeta(resultText(got));
258
+ const file = { id: fileId, ...(name !== undefined ? { name } : {}) };
259
+ const mentions = commentMentions(content);
260
+ const confirmation = await requireDispatchConfirmation(ctx, {
261
+ action: 'drive.comment-add',
262
+ message: 'Review and confirm this comment — the file\'s owner and anyone mentioned are notified:',
263
+ confirmationLabel: 'Confirm that this comment should be posted now.',
264
+ details: { file, textPreview: bodyPreview(content), mentions },
265
+ unsupportedNote: 'Ask the user to comment from Google Drive.',
266
+ fallback: {
267
+ tool: 'gog_drive_comments_add',
268
+ account,
269
+ confirmToken,
270
+ subject: () => {
271
+ const view = { file, text: content, mentions };
272
+ return { target: fileId, payload: view, preview: view };
273
+ },
274
+ },
275
+ });
276
+ if (confirmation) return confirmation;
233
277
  return runOrDiagnose(['drive', 'comments', 'create', pos(fileId), pos(content)], { account });
234
278
  });
235
279
 
@@ -259,7 +303,10 @@ export function registerExtraDriveTools(server: McpServer): void {
259
303
  });
260
304
 
261
305
  server.registerTool('gog_drive_comments_reply', {
262
- description: 'Reply to an existing comment on a Drive file. Pass `action: "resolve"` or `"reopen"` to atomically flip the parent comment\'s resolved state via the Drive API\'s Reply.action field — avoids the older workaround of deleting the comment (which destroys review-thread context).',
306
+ description: 'Reply to an existing comment on a Drive file. Pass `action: "resolve"` or `"reopen"` to atomically flip the parent comment\'s resolved state via the Drive API\'s Reply.action field — avoids the older workaround of deleting the comment (which destroys review-thread context). '
307
+ + 'Everyone on the thread and anyone the reply +mentions is notified, so this reads the file and the comment and '
308
+ + 'asks the MCP host to show the user a confirmation prompt with both and the reply first; nothing is posted unless '
309
+ + 'they accept.' + CONFIRM_FALLBACK_DESCRIPTION,
263
310
  annotations: { destructiveHint: false },
264
311
  inputSchema: z.object({
265
312
  fileId: z.string().describe('File ID'),
@@ -267,10 +314,36 @@ export function registerExtraDriveTools(server: McpServer): void {
267
314
  content: z.string().describe('Reply text'),
268
315
  action: z.enum(['resolve', 'reopen']).optional().describe('Optional action on the parent comment alongside the reply'),
269
316
  account: accountParam,
317
+ confirmToken: confirmTokenParam,
270
318
  }),
271
- }, async ({ fileId, commentId, content, action, account }) => {
319
+ }, async ({ fileId, commentId, content, action, account, confirmToken }, ctx) => {
272
320
  const args: GogArg[] = ['drive', 'comments', 'reply', pos(fileId), pos(commentId), pos(content)];
273
321
  if (action) args.push(`--action=${action}`);
322
+ const got = await runOrDiagnose(['drive', 'get', pos(fileId)], { account });
323
+ if (got.isError) return got;
324
+ const thread = await runOrDiagnose(['drive', 'comments', 'get', pos(fileId), pos(commentId)], { account });
325
+ if (thread.isError) return thread;
326
+ const { name } = shareTargetMeta(resultText(got));
327
+ const file = { id: fileId, ...(name !== undefined ? { name } : {}) };
328
+ const replyingTo = commentSnapshot(resultText(thread));
329
+ const mentions = commentMentions(content);
330
+ const confirmation = await requireDispatchConfirmation(ctx, {
331
+ action: 'drive.comment-reply',
332
+ message: 'Review and confirm this reply — everyone on the thread and anyone mentioned is notified:',
333
+ confirmationLabel: 'Confirm that this reply should be posted now.',
334
+ details: { file, replyingTo, textPreview: bodyPreview(content), mentions, ...(action ? { action } : {}) },
335
+ unsupportedNote: 'Ask the user to reply from Google Drive.',
336
+ fallback: {
337
+ tool: 'gog_drive_comments_reply',
338
+ account,
339
+ confirmToken,
340
+ subject: () => {
341
+ const view = { file, replyingTo, text: content, mentions, ...(action ? { action } : {}) };
342
+ return { target: `${fileId}/${commentId}`, payload: view, preview: view };
343
+ },
344
+ },
345
+ });
346
+ if (confirmation) return confirmation;
274
347
  return runOrDiagnose(args, { account });
275
348
  });
276
349
 
@@ -0,0 +1,154 @@
1
+ import { describe, it, expect, vi, beforeEach, afterEach } from 'vitest';
2
+ import { registerExtraDriveTools } from '../../src/tools/drive-extra.js';
3
+ import * as lib from '../../../gogcli-mcp/src/lib.js';
4
+ import { createTestHarness } from '@chrischall/mcp-utils/test';
5
+ import { rawTextResult } from '@chrischall/mcp-utils';
6
+ import type { ElicitRequest, ElicitResult } from '@modelcontextprotocol/server';
7
+ import { pos } from '../../../gogcli-mcp/src/argv.js';
8
+ import { resetConfirmTokenState } from '../../../gogcli-mcp/src/send-confirm-token.js';
9
+
10
+ vi.mock('../../../gogcli-mcp/src/lib.js', async (importOriginal) => {
11
+ const actual = await importOriginal<typeof lib>();
12
+ return { ...actual, runOrDiagnose: vi.fn() };
13
+ });
14
+
15
+ // Fleet audit 2026-09-24 SEC-6: a Drive comment or reply notifies the owner, the
16
+ // thread and everyone it +mentions, so both ask first — naming the file.
17
+
18
+ const ORIGINAL_ENV = { ...process.env };
19
+ beforeEach(() => {
20
+ vi.clearAllMocks();
21
+ process.env = { ...ORIGINAL_ENV };
22
+ delete process.env.MCP_CONFIRM_MODE;
23
+ resetConfirmTokenState();
24
+ });
25
+ afterEach(() => { process.env = ORIGINAL_ENV; });
26
+
27
+ const json = (r: { content: Array<{ text?: string }> }) => JSON.parse(r.content[0]!.text as string);
28
+ async function prompted(answer: ElicitResult = { action: 'accept', content: { confirmed: true } }) {
29
+ const seen: ElicitRequest[] = [];
30
+ const harness = await createTestHarness(registerExtraDriveTools, { elicitation: async (r) => { seen.push(r); return answer; } });
31
+ const details = () => JSON.parse(seen[0]!.params.message.split('\n').slice(1).join('\n')).details;
32
+ return { harness, seen, details };
33
+ }
34
+ const unprompted = () => createTestHarness(registerExtraDriveTools);
35
+
36
+ const FILE = JSON.stringify({ file: { id: 'f1', name: 'Q3 plan', mimeType: 'application/vnd.google-apps.document' } });
37
+ const COMMENT = JSON.stringify({ comment: { id: 'k1', content: 'Is this final?', author: { displayName: 'Alice', emailAddress: 'alice@example.com' }, resolved: false } });
38
+ function stub(failing?: string, file = FILE) {
39
+ vi.mocked(lib.runOrDiagnose).mockImplementation(async (args) => {
40
+ const key = args.filter((a): a is string => typeof a === 'string' && !a.startsWith('--')).join(' ');
41
+ if (failing && key.startsWith(failing)) return { content: [{ type: 'text', text: 'Error: not found' }], isError: true };
42
+ if (key === 'drive get') return rawTextResult(file);
43
+ if (key === 'drive comments get') return rawTextResult(COMMENT);
44
+ return rawTextResult('{"ok":true}');
45
+ });
46
+ }
47
+ const callsTo = (...words: string[]) => vi.mocked(lib.runOrDiagnose).mock.calls.filter(([args]) =>
48
+ words.every((w, i) => args[i] === w));
49
+
50
+ describe('gog_drive_comments_add', () => {
51
+ const ARGS = { fileId: 'f1', content: 'Looks good +bob@example.com' };
52
+
53
+ it('reads the file and asks with its name, the text and who is mentioned', async () => {
54
+ stub();
55
+ const { harness, details } = await prompted();
56
+ await harness.callTool('gog_drive_comments_add', ARGS);
57
+ expect(details()).toEqual({ file: { id: 'f1', name: 'Q3 plan' }, textPreview: 'Looks good +bob@example.com', mentions: ['bob@example.com'] });
58
+ expect(callsTo('drive', 'comments', 'create')[0]![0]).toEqual(['drive', 'comments', 'create', pos('f1'), pos(ARGS.content)]);
59
+ });
60
+
61
+ it('names only the id when the file read carries no name', async () => {
62
+ stub(undefined, '{}');
63
+ const { harness, details } = await prompted({ action: 'decline' });
64
+ await harness.callTool('gog_drive_comments_add', ARGS);
65
+ expect(details().file).toEqual({ id: 'f1' });
66
+ });
67
+
68
+ it('posts nothing when the user declines or the read fails', async () => {
69
+ stub();
70
+ expect(json(await (await prompted({ action: 'decline' })).harness.callTool('gog_drive_comments_add', ARGS)))
71
+ .toMatchObject({ cancelled: true, action: 'drive.comment-add' });
72
+ stub('drive get');
73
+ expect((await (await prompted()).harness.callTool('gog_drive_comments_add', ARGS)).isError).toBe(true);
74
+ expect(callsTo('drive', 'comments', 'create')).toHaveLength(0);
75
+ });
76
+
77
+ it('refuses a client that cannot be prompted', async () => {
78
+ process.env.MCP_CONFIRM_MODE = 'refuse';
79
+ stub();
80
+ const r = json(await (await unprompted()).callTool('gog_drive_comments_add', ARGS));
81
+ expect(r).toMatchObject({ reason: 'confirmation-unsupported', action: 'drive.comment-add' });
82
+ expect(r.note).toMatch(/Google Drive/);
83
+ });
84
+
85
+ it('token fallback: changed text is DRAFT_CHANGED; the same call posts', async () => {
86
+ process.env.MCP_CONFIRM_MODE = 'ask-user';
87
+ stub();
88
+ const harness = await unprompted();
89
+ const p1 = json(await harness.callTool('gog_drive_comments_add', ARGS));
90
+ expect(p1.preview).toEqual({ file: { id: 'f1', name: 'Q3 plan' }, text: ARGS.content, mentions: ['bob@example.com'] });
91
+ expect(json(await harness.callTool('gog_drive_comments_add', { ...ARGS, content: 'Nope', confirmToken: p1.confirmToken })))
92
+ .toMatchObject({ error: 'DRAFT_CHANGED' });
93
+ await harness.callTool('gog_drive_comments_add', { ...ARGS, confirmToken: p1.confirmToken });
94
+ expect(callsTo('drive', 'comments', 'create')).toHaveLength(1);
95
+ });
96
+ });
97
+
98
+ describe('gog_drive_comments_reply', () => {
99
+ const ARGS = { fileId: 'f1', commentId: 'k1', content: 'Yes, final.', action: 'resolve' as const };
100
+
101
+ it('reads the file and the comment and asks with both and the reply', async () => {
102
+ stub();
103
+ const { harness, details } = await prompted();
104
+ await harness.callTool('gog_drive_comments_reply', ARGS);
105
+ expect(details()).toEqual({
106
+ file: { id: 'f1', name: 'Q3 plan' },
107
+ replyingTo: { author: 'Alice <alice@example.com>', content: 'Is this final?', resolved: false },
108
+ textPreview: 'Yes, final.', mentions: [], action: 'resolve',
109
+ });
110
+ expect(callsTo('drive', 'comments', 'reply')[0]![0]).toEqual(
111
+ ['drive', 'comments', 'reply', pos('f1'), pos('k1'), pos('Yes, final.'), '--action=resolve']);
112
+ });
113
+
114
+ it.each(['drive get', 'drive comments get'])('returns a failed read (%s) without asking or replying', async (failing) => {
115
+ stub(failing);
116
+ const { harness, seen } = await prompted();
117
+ expect((await harness.callTool('gog_drive_comments_reply', ARGS)).isError).toBe(true);
118
+ expect(seen).toHaveLength(0);
119
+ expect(callsTo('drive', 'comments', 'reply')).toHaveLength(0);
120
+ });
121
+
122
+ it('refuses a client that cannot be prompted', async () => {
123
+ process.env.MCP_CONFIRM_MODE = 'refuse';
124
+ stub();
125
+ const r = json(await (await unprompted()).callTool('gog_drive_comments_reply', ARGS));
126
+ expect(r).toMatchObject({ reason: 'confirmation-unsupported', action: 'drive.comment-reply' });
127
+ });
128
+
129
+ it('token fallback: the thread action is part of what was approved', async () => {
130
+ process.env.MCP_CONFIRM_MODE = 'ask-user';
131
+ stub();
132
+ const harness = await unprompted();
133
+ const p1 = json(await harness.callTool('gog_drive_comments_reply', ARGS));
134
+ expect(p1.preview.action).toBe('resolve');
135
+ expect(json(await harness.callTool('gog_drive_comments_reply', { ...ARGS, action: 'reopen', confirmToken: p1.confirmToken })))
136
+ .toMatchObject({ error: 'DRAFT_CHANGED' });
137
+ expect(callsTo('drive', 'comments', 'reply')).toHaveLength(0);
138
+ });
139
+
140
+ it('token fallback: previews the thread; a reply with no action posts on phase 2', async () => {
141
+ process.env.MCP_CONFIRM_MODE = 'ask-user';
142
+ stub();
143
+ const harness = await unprompted();
144
+ const args = { fileId: 'f1', commentId: 'k1', content: 'Yes.' };
145
+ const p1 = json(await harness.callTool('gog_drive_comments_reply', args));
146
+ expect(p1.preview).toEqual({
147
+ file: { id: 'f1', name: 'Q3 plan' },
148
+ replyingTo: { author: 'Alice <alice@example.com>', content: 'Is this final?', resolved: false },
149
+ text: 'Yes.', mentions: [],
150
+ });
151
+ await harness.callTool('gog_drive_comments_reply', { ...args, confirmToken: p1.confirmToken });
152
+ expect(callsTo('drive', 'comments', 'reply')).toHaveLength(1);
153
+ });
154
+ });
@@ -18,7 +18,10 @@ let harness: TestHarness;
18
18
  beforeEach(async () => {
19
19
  vi.clearAllMocks();
20
20
  vi.mocked(lib.runOrDiagnose).mockResolvedValue(rawTextResult('{}'));
21
- harness = await createTestHarness(registerExtraDriveTools);
21
+ // The comment tools ask first (drive-extra-gates.test.ts covers the prompts); here the user accepts.
22
+ harness = await createTestHarness(registerExtraDriveTools, {
23
+ elicitation: async () => ({ action: 'accept', content: { confirmed: true } }),
24
+ });
22
25
  });
23
26
 
24
27
  describe('gog_drive_download', () => {