gogcli-mcp-docs 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 Docs for Claude via gogcli — auth + full Docs and comments support",
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 (Docs)",
16
16
  "source": "./",
17
17
  "description": "Extended Google Docs for Claude via gogcli — auth + full Docs and comments support",
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-docs",
3
3
  "displayName": "gogcli (Docs)",
4
- "version": "4.5.0",
4
+ "version": "4.5.1",
5
5
  "description": "Extended Google Docs for Claude via gogcli — auth + full Docs and comments support",
6
6
  "author": {
7
7
  "name": "Chris Hall",
package/dist/index.js CHANGED
@@ -37,6 +37,33 @@ var storage2 = new AsyncLocalStorage2();
37
37
  function withCallerCapabilities(capabilities, fn) {
38
38
  return capabilities ? storage2.run(capabilities, fn) : fn();
39
39
  }
40
+ function currentCallerCapabilities() {
41
+ return storage2.getStore();
42
+ }
43
+ var ENVELOPE_CAPABILITIES_KEY = "io.modelcontextprotocol/clientCapabilities";
44
+ var ELICITATION_MODES = ["form", "url"];
45
+ function isRecord(value) {
46
+ return typeof value === "object" && value !== null && !Array.isArray(value);
47
+ }
48
+ function callerCapabilities(ctx) {
49
+ const envelope = isRecord(ctx) && isRecord(ctx.mcpReq) ? ctx.mcpReq.envelope : void 0;
50
+ if (isRecord(envelope)) {
51
+ const declared = envelope[ENVELOPE_CAPABILITIES_KEY];
52
+ if (isRecord(declared))
53
+ return declared;
54
+ }
55
+ return currentCallerCapabilities();
56
+ }
57
+ function callerAcceptsFormElicitation(ctx) {
58
+ const capabilities = callerCapabilities(ctx);
59
+ if (!capabilities)
60
+ return void 0;
61
+ const elicitation = capabilities.elicitation;
62
+ if (!isRecord(elicitation))
63
+ return false;
64
+ const namedModes = ELICITATION_MODES.filter((mode) => mode in elicitation);
65
+ return namedModes.length === 0 || namedModes.includes("form");
66
+ }
40
67
 
41
68
  // ../../node_modules/@modelcontextprotocol/server/dist/chunk-Br0eD_fh.mjs
42
69
  var __create = Object.create;
@@ -24101,6 +24128,37 @@ var inputRequired = Object.assign(buildInputRequired, {
24101
24128
  return { method: "roots/list" };
24102
24129
  }
24103
24130
  });
24131
+ function acceptedContent(responses, key, schema) {
24132
+ const view = inputResponse(responses, key);
24133
+ if (view.kind !== "elicit" || view.action !== "accept" || view.content === void 0) return void 0;
24134
+ if (schema === void 0) return view.content;
24135
+ const outcome = schema["~standard"].validate(view.content);
24136
+ if (outcome instanceof Promise) throw new TypeError("acceptedContent(responses, key, schema) requires a synchronously-validating schema");
24137
+ return outcome.issues === void 0 ? outcome.value : void 0;
24138
+ }
24139
+ function inputResponse(responses, key) {
24140
+ if (responses === void 0 || typeof responses !== "object" || responses === null) return { kind: "missing" };
24141
+ const entry = responses[key];
24142
+ if (entry === null || typeof entry !== "object" || Array.isArray(entry)) return { kind: "missing" };
24143
+ const candidate = entry;
24144
+ if (candidate["action"] === "accept" || candidate["action"] === "decline" || candidate["action"] === "cancel") {
24145
+ const content = candidate["content"];
24146
+ return {
24147
+ kind: "elicit",
24148
+ action: candidate["action"],
24149
+ ...content !== null && typeof content === "object" && !Array.isArray(content) && { content }
24150
+ };
24151
+ }
24152
+ if (Array.isArray(candidate["roots"])) return {
24153
+ kind: "roots",
24154
+ roots: candidate["roots"]
24155
+ };
24156
+ if (typeof candidate["role"] === "string" && candidate["content"] !== void 0) return {
24157
+ kind: "sampling",
24158
+ result: candidate
24159
+ };
24160
+ return { kind: "missing" };
24161
+ }
24104
24162
  var REQUEST_STATE_ONLY_LEG_PACING_MS = 250;
24105
24163
  function inputRequiredRoundsExceededMessage(method, maxRounds) {
24106
24164
  return `Multi-round-trip request '${method}' still required input after ${maxRounds} rounds (inputRequired.maxRounds)`;
@@ -34148,14 +34206,14 @@ function serveStdio(factory, options = {}) {
34148
34206
  return false;
34149
34207
  };
34150
34208
  const answerLegacyRejection = (request, reason, requestedVersion) => {
34151
- const rejection2 = modernOnlyStrictRejection({
34209
+ const rejection3 = modernOnlyStrictRejection({
34152
34210
  kind: "legacy",
34153
34211
  reason,
34154
34212
  ...requestedVersion !== void 0 && { requestedVersion }
34155
34213
  }, SUPPORTED_MODERN_PROTOCOL_VERSIONS);
34156
- if (rejection2 === void 0) return Promise.resolve();
34157
- reportError(/* @__PURE__ */ new Error(`Rejected 2025-era request on a modern-only stdio connection (${rejection2.cell}): ${rejection2.message}`));
34158
- return writeErrorResponse(request.id, rejection2.code, rejection2.message, rejection2.data);
34214
+ if (rejection3 === void 0) return Promise.resolve();
34215
+ reportError(/* @__PURE__ */ new Error(`Rejected 2025-era request on a modern-only stdio connection (${rejection3.cell}): ${rejection3.message}`));
34216
+ return writeErrorResponse(request.id, rejection3.code, rejection3.message, rejection3.data);
34159
34217
  };
34160
34218
  const onInstanceClosed = (channel) => {
34161
34219
  if (closing || channel === discarding) return;
@@ -34458,6 +34516,11 @@ function walk(value, keep, drop) {
34458
34516
  }
34459
34517
 
34460
34518
  // ../../node_modules/@chrischall/mcp-utils/dist/response/index.js
34519
+ function textResult(data) {
34520
+ return {
34521
+ content: [{ type: "text", text: JSON.stringify(data, null, 2) }]
34522
+ };
34523
+ }
34461
34524
  function rawTextResult(text) {
34462
34525
  return { content: [{ type: "text", text }] };
34463
34526
  }
@@ -34468,7 +34531,160 @@ function errorResult(message) {
34468
34531
  };
34469
34532
  }
34470
34533
 
34534
+ // ../../node_modules/@chrischall/mcp-utils/dist/server/confirmation.js
34535
+ import { createHash, createHmac, timingSafeEqual } from "node:crypto";
34536
+
34537
+ // ../../node_modules/@chrischall/mcp-utils/dist/server/canonical.js
34538
+ function canonicalJson(value) {
34539
+ if (value === null || typeof value === "string" || typeof value === "boolean")
34540
+ return JSON.stringify(value);
34541
+ if (value === void 0)
34542
+ return "null";
34543
+ if (typeof value === "number")
34544
+ return Number.isFinite(value) ? JSON.stringify(value) : `{"$num":"${String(value)}"}`;
34545
+ if (typeof value === "bigint")
34546
+ return `{"$bigint":"${value.toString()}"}`;
34547
+ if (typeof value === "function" || typeof value === "symbol") {
34548
+ throw new TypeError(`confirmation: cannot bind a ${typeof value} argument value.`);
34549
+ }
34550
+ if (Array.isArray(value))
34551
+ return `[${value.map(canonicalJson).join(",")}]`;
34552
+ if (value instanceof Date) {
34553
+ return `{"$date":${JSON.stringify(Number.isNaN(value.getTime()) ? "Invalid Date" : value.toISOString())}}`;
34554
+ }
34555
+ if (ArrayBuffer.isView(value)) {
34556
+ const bytes = Buffer.from(value.buffer, value.byteOffset, value.byteLength);
34557
+ return `{"$bytes":${JSON.stringify(bytes.toString("base64"))}}`;
34558
+ }
34559
+ if (value instanceof ArrayBuffer)
34560
+ return `{"$bytes":${JSON.stringify(Buffer.from(value).toString("base64"))}}`;
34561
+ if (value instanceof Map) {
34562
+ const entries2 = [...value.entries()].map(([k, v]) => `[${canonicalJson(k)},${canonicalJson(v)}]`).sort();
34563
+ return `{"$map":[${entries2.join(",")}]}`;
34564
+ }
34565
+ if (value instanceof Set) {
34566
+ return `{"$set":[${[...value].map(canonicalJson).sort().join(",")}]}`;
34567
+ }
34568
+ const proto = Object.getPrototypeOf(value);
34569
+ if (proto !== Object.prototype && proto !== null) {
34570
+ throw new TypeError("confirmation: cannot bind a non-plain object argument value (class instance).");
34571
+ }
34572
+ const entries = Object.entries(value).filter(([, v]) => v !== void 0).sort(([a], [b]) => a < b ? -1 : a > b ? 1 : 0);
34573
+ return `{${entries.map(([k, v]) => `${JSON.stringify(escapeKey(k))}:${canonicalJson(v)}`).join(",")}}`;
34574
+ }
34575
+ function escapeKey(key) {
34576
+ return key.startsWith("$") ? `$${key}` : key;
34577
+ }
34578
+
34579
+ // ../../node_modules/@chrischall/mcp-utils/dist/server/confirmation.js
34580
+ var DEFAULT_REQUEST_KEY = "confirmation";
34581
+ var DEFAULT_CONFIRMATION_LABEL = "Confirm this action should proceed.";
34582
+ var UNSUPPORTED_NOTE = "Nothing was done because this client cannot show a confirmation prompt (it declares no MCP elicitation capability), and this action is never taken without one";
34583
+ var STATE_PREFIX = "mcpu.confirm.v1.";
34584
+ function bindingKey(binding) {
34585
+ if (binding.ttlSeconds !== void 0 && !(Number.isFinite(binding.ttlSeconds) && binding.ttlSeconds > 0)) {
34586
+ throw new RangeError("requireConfirmation: binding.ttlSeconds must be a finite number greater than 0.");
34587
+ }
34588
+ const key = typeof binding.key === "string" ? Buffer.from(binding.key, "utf8") : Buffer.from(binding.key);
34589
+ if (key.length < 32) {
34590
+ throw new RangeError("requireConfirmation: binding.key must be at least 32 bytes.");
34591
+ }
34592
+ return key;
34593
+ }
34594
+ function commitment(action, args) {
34595
+ return createHash("sha256").update(`${action}\0${canonicalJson(args)}`).digest("base64url");
34596
+ }
34597
+ function mintState(key, action, binding) {
34598
+ const exp = Math.floor(Date.now() / 1e3) + (binding.ttlSeconds ?? 600);
34599
+ const body = Buffer.from(JSON.stringify({ c: commitment(action, binding.args), exp })).toString("base64url");
34600
+ const mac3 = createHmac("sha256", key).update(`${STATE_PREFIX}${body}`).digest("base64url");
34601
+ return `${STATE_PREFIX}${body}.${mac3}`;
34602
+ }
34603
+ function verifyState(key, action, binding, state) {
34604
+ if (typeof state !== "string" || !state.startsWith(STATE_PREFIX))
34605
+ return false;
34606
+ const rest = state.slice(STATE_PREFIX.length);
34607
+ const dot = rest.indexOf(".");
34608
+ if (dot < 0)
34609
+ return false;
34610
+ const body = rest.slice(0, dot);
34611
+ const mac3 = Buffer.from(rest.slice(dot + 1), "base64url");
34612
+ const expected = createHmac("sha256", key).update(`${STATE_PREFIX}${body}`).digest();
34613
+ if (mac3.length !== expected.length || !timingSafeEqual(mac3, expected))
34614
+ return false;
34615
+ let payload;
34616
+ try {
34617
+ payload = JSON.parse(Buffer.from(body, "base64url").toString("utf8"));
34618
+ } catch {
34619
+ return false;
34620
+ }
34621
+ if (typeof payload.exp !== "number" || payload.exp * 1e3 <= Date.now())
34622
+ return false;
34623
+ const want = Buffer.from(commitment(action, binding.args));
34624
+ const got = Buffer.from(typeof payload.c === "string" ? payload.c : "");
34625
+ return got.length === want.length && timingSafeEqual(got, want);
34626
+ }
34627
+ function echoedState(ctx) {
34628
+ const accessor = ctx.mcpReq.requestState;
34629
+ return typeof accessor === "function" ? accessor() : void 0;
34630
+ }
34631
+ function requireConfirmation(ctx, options) {
34632
+ const requestKey = options.requestKey ?? DEFAULT_REQUEST_KEY;
34633
+ const key = options.binding ? bindingKey(options.binding) : void 0;
34634
+ const confirmationSchema = external_exports.object({
34635
+ confirmed: external_exports.boolean().describe(options.confirmationLabel ?? DEFAULT_CONFIRMATION_LABEL)
34636
+ });
34637
+ const ask = () => {
34638
+ const preview = {
34639
+ action: options.action,
34640
+ ...options.details === void 0 ? {} : { details: options.details }
34641
+ };
34642
+ return inputRequired({
34643
+ inputRequests: {
34644
+ [requestKey]: inputRequired.elicit({
34645
+ message: `${options.message}
34646
+ ${JSON.stringify(preview, null, 2)}`,
34647
+ requestedSchema: confirmationSchema
34648
+ })
34649
+ },
34650
+ ...key && options.binding ? { requestState: mintState(key, options.action, options.binding) } : {}
34651
+ });
34652
+ };
34653
+ const response = inputResponse(ctx.mcpReq.inputResponses, requestKey);
34654
+ const accepted = acceptedContent(ctx.mcpReq.inputResponses, requestKey, confirmationSchema);
34655
+ if (response.kind === "missing") {
34656
+ if (callerAcceptsFormElicitation(ctx) === false) {
34657
+ return textResult({
34658
+ confirmed: false,
34659
+ dispatched: false,
34660
+ action: options.action,
34661
+ reason: "confirmation-unsupported",
34662
+ note: options.unsupportedNote ? `${UNSUPPORTED_NOTE}. ${options.unsupportedNote}` : `${UNSUPPORTED_NOTE}.`
34663
+ });
34664
+ }
34665
+ return ask();
34666
+ }
34667
+ if (response.kind === "elicit" && response.action === "accept" && accepted?.confirmed === true) {
34668
+ if (key && options.binding) {
34669
+ const state = echoedState(ctx);
34670
+ if (state === void 0 || state === null) {
34671
+ return errorResult(`Confirmation for ${options.action} was accepted, but the retry carried no requestState, so it cannot be checked against the prompt that was shown. Nothing was done. The likely cause is that the MCP client or host does not round-trip requestState (it must echo the requestState from the input_required result back on the retry); asking again would loop.`);
34672
+ }
34673
+ if (!verifyState(key, options.action, options.binding, state))
34674
+ return ask();
34675
+ }
34676
+ return void 0;
34677
+ }
34678
+ return textResult({
34679
+ confirmed: false,
34680
+ cancelled: true,
34681
+ action: options.action,
34682
+ note: "Nothing was changed because the confirmation was declined, cancelled, or left unchecked."
34683
+ });
34684
+ }
34685
+
34471
34686
  // ../../node_modules/@chrischall/mcp-utils/dist/server/confirm-token.js
34687
+ import { createHash as createHash2, createHmac as createHmac2, randomBytes, timingSafeEqual as timingSafeEqual2 } from "node:crypto";
34472
34688
  function createSpentTokenStore() {
34473
34689
  const spent2 = /* @__PURE__ */ new Map();
34474
34690
  return {
@@ -34488,7 +34704,148 @@ function createSpentTokenStore() {
34488
34704
  };
34489
34705
  }
34490
34706
  var PROCESS_SPENT = createSpentTokenStore();
34707
+ var PREFIX = "mcpu.token.v1.";
34708
+ var DEFAULT_TTL_SECONDS = 600;
34709
+ function tokenKey(key) {
34710
+ const bytes = typeof key === "string" ? Buffer.from(key, "utf8") : Buffer.from(key);
34711
+ if (bytes.length < 32)
34712
+ throw new RangeError("confirm token: key must be at least 32 bytes.");
34713
+ return bytes;
34714
+ }
34715
+ function ttlOf(ttlSeconds) {
34716
+ if (ttlSeconds === void 0)
34717
+ return DEFAULT_TTL_SECONDS;
34718
+ if (!(Number.isFinite(ttlSeconds) && ttlSeconds > 0)) {
34719
+ throw new RangeError("confirm token: ttlSeconds must be a finite number greater than 0.");
34720
+ }
34721
+ return ttlSeconds;
34722
+ }
34723
+ function sign(key, body) {
34724
+ return createHmac2("sha256", key).update(`${PREFIX}${body}`).digest();
34725
+ }
34726
+ function hashConfirmPayload(payload) {
34727
+ return createHash2("sha256").update(canonicalJson(payload)).digest("base64url");
34728
+ }
34729
+ function issueConfirmToken(key, binding, options = {}) {
34730
+ const k = tokenKey(key);
34731
+ const now = options.now ?? Date.now();
34732
+ const exp = now + ttlOf(options.ttlSeconds) * 1e3;
34733
+ const claims = {
34734
+ t: binding.tool,
34735
+ ...binding.account === void 0 ? {} : { a: binding.account },
34736
+ g: binding.target,
34737
+ ...binding.revision === void 0 ? {} : { r: binding.revision },
34738
+ h: binding.payloadHash,
34739
+ exp,
34740
+ n: randomBytes(16).toString("base64url")
34741
+ };
34742
+ const body = Buffer.from(JSON.stringify(claims), "utf8").toString("base64url");
34743
+ return { token: `${PREFIX}${body}.${sign(k, body).toString("base64url")}`, expiresAt: new Date(exp).toISOString() };
34744
+ }
34745
+ function parseClaims(body) {
34746
+ try {
34747
+ const claims = JSON.parse(Buffer.from(body, "base64url").toString("utf8"));
34748
+ return claims && typeof claims === "object" ? claims : void 0;
34749
+ } catch {
34750
+ return void 0;
34751
+ }
34752
+ }
34753
+ function verifyConfirmToken(key, token, binding, options = {}) {
34754
+ const k = tokenKey(key);
34755
+ const now = options.now ?? Date.now();
34756
+ const spent2 = options.spent ?? PROCESS_SPENT;
34757
+ spent2.prune(now);
34758
+ if (!token.startsWith(PREFIX))
34759
+ return { ok: false, error: "TOKEN_INVALID" };
34760
+ const rest = token.slice(PREFIX.length);
34761
+ const dot = rest.indexOf(".");
34762
+ const body = dot < 0 ? "" : rest.slice(0, dot);
34763
+ const mac3 = Buffer.from(dot < 0 ? "" : rest.slice(dot + 1), "base64url");
34764
+ const expected = sign(k, body);
34765
+ if (!body || mac3.length !== expected.length || !timingSafeEqual2(mac3, expected))
34766
+ return { ok: false, error: "TOKEN_INVALID" };
34767
+ const claims = parseClaims(body);
34768
+ if (!claims)
34769
+ return { ok: false, error: "TOKEN_INVALID" };
34770
+ if (claims.t !== binding.tool || claims.a !== binding.account || claims.g !== binding.target) {
34771
+ return { ok: false, error: "TOKEN_INVALID" };
34772
+ }
34773
+ if (spent2.has(claims.n))
34774
+ return { ok: false, error: "TOKEN_REUSED" };
34775
+ if (now > claims.exp)
34776
+ return { ok: false, error: "TOKEN_EXPIRED" };
34777
+ if (claims.r !== binding.revision)
34778
+ return { ok: false, error: "DRAFT_CHANGED", reason: "revision-changed" };
34779
+ if (claims.h !== binding.payloadHash)
34780
+ return { ok: false, error: "DRAFT_CHANGED", reason: "payload-changed" };
34781
+ spent2.add(claims.n, claims.exp);
34782
+ return { ok: true };
34783
+ }
34784
+ var CONFIRM_TOKEN_INSTRUCTION = "Show this preview to the user verbatim and proceed only after they explicitly approve in chat. Then call again with confirmToken.";
34491
34785
  var confirmTokenParam = external_exports.string().optional().describe(`ONLY for the two-step confirmation fallback (a client without MCP elicitation). The confirmToken from this same tool's phase-1 "confirmation-required" response, passed back ONLY after the user has seen that preview and explicitly approved it in chat \u2014 never on the first call, never invented, never reused. Call again with the same arguments. Ignored when the client supports elicitation.`);
34786
+ var TOKEN_ERROR_NOTE = {
34787
+ TOKEN_EXPIRED: "Nothing was sent or changed: the confirmToken expired. Call again WITHOUT confirmToken for a fresh preview, and ask the user to approve it again.",
34788
+ TOKEN_REUSED: "Nothing was sent or changed by this call: this confirmToken was already used, and one approval acts once. If doing it again is really intended, call again WITHOUT confirmToken and get a new approval.",
34789
+ TOKEN_INVALID: "Nothing was sent or changed: this confirmToken was not issued by this server for this tool, account and target (or the server has restarted since). Call again WITHOUT confirmToken for a fresh preview and approval."
34790
+ };
34791
+ var CHANGED_NOTE = {
34792
+ "revision-changed": "Nothing was sent or changed: the target was edited since the user approved it (its version rotated), so what would happen is not what they saw.",
34793
+ "payload-changed": "Nothing was sent or changed: what would happen no longer matches what the user approved."
34794
+ };
34795
+ function isToolResult(value) {
34796
+ return Array.isArray(value.content);
34797
+ }
34798
+ function rejection2(data) {
34799
+ return { ...textResult({ status: "confirmation-rejected", confirmed: false, dispatched: false, ...data }), isError: true };
34800
+ }
34801
+ async function tokenConfirmation(action, fb) {
34802
+ const subject = await fb.subject();
34803
+ if (isToolResult(subject))
34804
+ return subject;
34805
+ const binding = {
34806
+ tool: fb.tool,
34807
+ ...fb.account === void 0 ? {} : { account: fb.account },
34808
+ target: subject.target,
34809
+ ...subject.revision === void 0 ? {} : { revision: subject.revision },
34810
+ payloadHash: hashConfirmPayload(subject.payload)
34811
+ };
34812
+ const phaseOne = () => {
34813
+ const { token, expiresAt } = issueConfirmToken(fb.key, binding, { ttlSeconds: fb.ttlSeconds });
34814
+ return {
34815
+ action,
34816
+ preview: subject.preview,
34817
+ confirmToken: token,
34818
+ expiresAt,
34819
+ ttlSeconds: ttlOf(fb.ttlSeconds),
34820
+ instruction: fb.instruction ?? CONFIRM_TOKEN_INSTRUCTION
34821
+ };
34822
+ };
34823
+ if (!fb.confirmToken) {
34824
+ return textResult({ status: "confirmation-required", confirmed: false, dispatched: false, ...phaseOne() });
34825
+ }
34826
+ const verdict = verifyConfirmToken(fb.key, fb.confirmToken, binding, { spent: fb.spent });
34827
+ if (verdict.ok)
34828
+ return void 0;
34829
+ if (verdict.error === "DRAFT_CHANGED") {
34830
+ return rejection2({
34831
+ error: "DRAFT_CHANGED",
34832
+ reason: verdict.reason,
34833
+ note: `${CHANGED_NOTE[verdict.reason]} The current preview and a fresh confirmToken are below.`,
34834
+ ...phaseOne()
34835
+ });
34836
+ }
34837
+ return rejection2({ error: verdict.error, action, note: TOKEN_ERROR_NOTE[verdict.error] });
34838
+ }
34839
+ async function requireConfirmationWithFallback(ctx, options) {
34840
+ const { tokenFallback, ...confirmation } = options;
34841
+ if (tokenFallback && callerAcceptsFormElicitation(ctx) === false) {
34842
+ return tokenConfirmation(options.action, tokenFallback);
34843
+ }
34844
+ return requireConfirmation(ctx, confirmation);
34845
+ }
34846
+
34847
+ // ../../node_modules/@chrischall/mcp-utils/dist/server/confirm-env.js
34848
+ import { createHash as createHash3, randomBytes as randomBytes2 } from "node:crypto";
34492
34849
 
34493
34850
  // ../../node_modules/@chrischall/mcp-utils/dist/config/index.js
34494
34851
  import { homedir } from "node:os";
@@ -34529,6 +34886,61 @@ function expandPath(p) {
34529
34886
  return isAbsolute(expanded) ? expanded : resolve(expanded);
34530
34887
  }
34531
34888
 
34889
+ // ../../node_modules/@chrischall/mcp-utils/dist/server/confirm-env.js
34890
+ var MODES = /* @__PURE__ */ new Set(["ask-user", "auto", "refuse"]);
34891
+ var DEFAULT_TTL_SECONDS2 = 600;
34892
+ var warned = /* @__PURE__ */ new Set();
34893
+ function readConfirmMode(env = process.env) {
34894
+ const raw = readEnvVar("MCP_CONFIRM_MODE", { env })?.trim().toLowerCase();
34895
+ if (!raw)
34896
+ return "ask-user";
34897
+ if (MODES.has(raw))
34898
+ return raw;
34899
+ if (!warned.has(raw)) {
34900
+ warned.add(raw);
34901
+ process.stderr.write(`MCP_CONFIRM_MODE="${raw}" is not one of ask-user, auto, refuse; treating it as refuse.
34902
+ `);
34903
+ }
34904
+ return "refuse";
34905
+ }
34906
+ function confirmTtlFromEnv(env = process.env) {
34907
+ const raw = readEnvVar("MCP_CONFIRM_TTL_SECONDS", { env })?.trim();
34908
+ return raw && /^[1-9]\d*$/.test(raw) ? Number(raw) : DEFAULT_TTL_SECONDS2;
34909
+ }
34910
+ var processKey;
34911
+ function confirmKeyFromEnv(env = process.env) {
34912
+ const secret = readEnvVar("MCP_CONFIRM_SECRET", { env });
34913
+ if (secret)
34914
+ return createHash3("sha256").update(secret, "utf8").digest();
34915
+ processKey ??= randomBytes2(32);
34916
+ return processKey;
34917
+ }
34918
+ var CONFIRM_TOKEN_AUTO_INSTRUCTION = "Nothing has been done yet. Review this preview; if it is what was intended, call again with the same arguments plus confirmToken. (This server runs with MCP_CONFIRM_MODE=auto, so the user's approval in chat is not required.)";
34919
+ var REFUSE_HINT = "Set MCP_CONFIRM_MODE=ask-user on the server to allow two-step confirmation instead.";
34920
+ function confirmationFromEnv(options) {
34921
+ const { tool, account, confirmToken, subject, instruction, spent: spent2, env = process.env, ...confirmation } = options;
34922
+ const mode = readConfirmMode(env);
34923
+ if (mode === "refuse") {
34924
+ return {
34925
+ ...confirmation,
34926
+ unsupportedNote: confirmation.unsupportedNote ? `${confirmation.unsupportedNote} ${REFUSE_HINT}` : REFUSE_HINT
34927
+ };
34928
+ }
34929
+ return {
34930
+ ...confirmation,
34931
+ tokenFallback: {
34932
+ key: confirmKeyFromEnv(env),
34933
+ tool,
34934
+ ...account === void 0 ? {} : { account },
34935
+ ...confirmToken === void 0 ? {} : { confirmToken },
34936
+ subject,
34937
+ ttlSeconds: confirmTtlFromEnv(env),
34938
+ instruction: mode === "auto" ? CONFIRM_TOKEN_AUTO_INSTRUCTION : instruction ?? CONFIRM_TOKEN_INSTRUCTION,
34939
+ ...spent2 === void 0 ? {} : { spent: spent2 }
34940
+ }
34941
+ };
34942
+ }
34943
+
34532
34944
  // ../../node_modules/@chrischall/mcp-utils/dist/server/index.js
34533
34945
  var SERVER_PROTOCOL_VERSIONS = Object.freeze([
34534
34946
  "2026-07-28",
@@ -34785,9 +35197,9 @@ function offsetAt(instant, tz) {
34785
35197
  const w = wallPartsIn(instant, tz);
34786
35198
  const asUTC = Date.UTC(w.year, w.month - 1, w.day, w.hour, w.minute, w.second, instant.getUTCMilliseconds());
34787
35199
  const minutes = Math.round((asUTC - instant.getTime()) / 6e4);
34788
- const sign = minutes < 0 ? "-" : "+";
35200
+ const sign2 = minutes < 0 ? "-" : "+";
34789
35201
  const abs = Math.abs(minutes);
34790
- return `${sign}${pad(Math.floor(abs / 60))}:${pad(abs % 60)}`;
35202
+ return `${sign2}${pad(Math.floor(abs / 60))}:${pad(abs % 60)}`;
34791
35203
  }
34792
35204
  function wallPartsIn(instant, tz) {
34793
35205
  const parts = new Intl.DateTimeFormat("en-US", {
@@ -35497,6 +35909,7 @@ async function diagnose(err) {
35497
35909
  const isAuthError = !isTransientError && AUTH_ERROR_PATTERN.test(errText);
35498
35910
  const isGridLimitError = GRID_LIMIT_ERROR_PATTERN.test(errText);
35499
35911
  const hint = isInvalidGrant ? INVALID_GRANT_HINT : isAuthError ? AUTH_HINT : isTransientError ? TRANSIENT_HINT : isGridLimitError ? GRID_LIMIT_HINT : "";
35912
+ if (!isAuthError && !isInvalidGrant) return errorResult(`${errText}${hint}`);
35500
35913
  try {
35501
35914
  const accounts = formatAccountList(await run(["auth", "list"]));
35502
35915
  return errorResult(`${errText}
@@ -35587,6 +36000,73 @@ function formatAuthHealth(raw, now) {
35587
36000
 
35588
36001
  // ../gogcli-mcp/src/send-confirm-token.ts
35589
36002
  var spent = createSpentTokenStore();
36003
+ function confirmSpentStore() {
36004
+ return spent;
36005
+ }
36006
+
36007
+ // ../gogcli-mcp/src/dispatch-confirmation.ts
36008
+ var BODY_PREVIEW_MAX = 2048;
36009
+ function bodyPreview(text) {
36010
+ if (!text) return void 0;
36011
+ if (text.length <= BODY_PREVIEW_MAX) return text;
36012
+ return `${text.slice(0, BODY_PREVIEW_MAX)}\u2026 [${text.length - BODY_PREVIEW_MAX} more characters not shown]`;
36013
+ }
36014
+ var CONFIRM_ACTION_INSTRUCTION = CONFIRM_TOKEN_INSTRUCTION;
36015
+ 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.';
36016
+ function refusedInRun(what, via, does, instead) {
36017
+ return `${what} ${does} and is not available through ${via}. ${instead}`;
36018
+ }
36019
+ function gatedElsewhere(what, via, does, tool) {
36020
+ return refusedInRun(what, via, does, `Use ${tool}, which asks the user to confirm.`);
36021
+ }
36022
+ function hasCommandWord(args, words) {
36023
+ return args.find((a) => words.has(a.toLowerCase()));
36024
+ }
36025
+ var COMMENT_ADD_WORDS = /* @__PURE__ */ new Set(["create", "add", "new"]);
36026
+ var COMMENT_REPLY_WORDS = /* @__PURE__ */ new Set(["reply", "respond"]);
36027
+ function vetCommentsRun(service, subcommand, args) {
36028
+ if (subcommand.toLowerCase() !== "comments") return void 0;
36029
+ const reply = hasCommandWord(args, COMMENT_REPLY_WORDS);
36030
+ if (reply) {
36031
+ return gatedElsewhere(
36032
+ `gog ${service} comments ${reply.toLowerCase()}`,
36033
+ `gog_${service}_run`,
36034
+ "notifies the comment thread",
36035
+ `gog_${service}_comments_reply`
36036
+ );
36037
+ }
36038
+ const add = hasCommandWord(args, COMMENT_ADD_WORDS);
36039
+ return add ? gatedElsewhere(
36040
+ `gog ${service} comments ${add.toLowerCase()}`,
36041
+ `gog_${service}_run`,
36042
+ "notifies the file's owner and anyone it mentions",
36043
+ `gog_${service}_comments_add`
36044
+ ) : void 0;
36045
+ }
36046
+ async function requireDispatchConfirmation(ctx, options) {
36047
+ const { action, fallback } = options;
36048
+ const confirmation = {
36049
+ action,
36050
+ message: options.message,
36051
+ details: options.details,
36052
+ confirmationLabel: options.confirmationLabel,
36053
+ ...options.unsupportedNote ? { unsupportedNote: options.unsupportedNote } : {}
36054
+ };
36055
+ if (!fallback) return requireConfirmationWithFallback(ctx, confirmation);
36056
+ return requireConfirmationWithFallback(ctx, confirmationFromEnv({
36057
+ ...confirmation,
36058
+ tool: fallback.tool,
36059
+ account: fallback.account ?? readEnvVar("GOG_ACCOUNT") ?? "",
36060
+ confirmToken: fallback.confirmToken,
36061
+ subject: fallback.subject,
36062
+ instruction: fallback.instruction ?? CONFIRM_ACTION_INSTRUCTION,
36063
+ spent: confirmSpentStore()
36064
+ }));
36065
+ }
36066
+ function resultText(result) {
36067
+ const first = result.content[0];
36068
+ return first && first.type === "text" && typeof first.text === "string" ? first.text : "{}";
36069
+ }
35590
36070
 
35591
36071
  // ../gogcli-mcp/src/tools/auth.ts
35592
36072
  var AUTH_RUN_SUBCOMMANDS = ["list", "status", "services", "remove", "alias"];
@@ -35723,6 +36203,27 @@ function authToolsFor(defaultServices) {
35723
36203
  }
35724
36204
 
35725
36205
  // ../gogcli-mcp/src/tools/calendar.ts
36206
+ var ASKS = (tool) => `Use ${tool}, which asks the user to confirm.`;
36207
+ var CALENDAR_REFUSED = {
36208
+ create: { does: "can change what guests see", instead: ASKS("gog_calendar_create") },
36209
+ add: { does: "can change what guests see", instead: ASKS("gog_calendar_create") },
36210
+ new: { does: "can change what guests see", instead: ASKS("gog_calendar_create") },
36211
+ update: { does: "can change what guests see", instead: ASKS("gog_calendar_update") },
36212
+ edit: { does: "can change what guests see", instead: ASKS("gog_calendar_update") },
36213
+ set: { does: "can change what guests see", instead: ASKS("gog_calendar_update") },
36214
+ respond: { does: "can change what guests see", instead: ASKS("gog_calendar_respond") },
36215
+ rsvp: { does: "can change what guests see", instead: ASKS("gog_calendar_respond") },
36216
+ reply: { does: "can change what guests see", instead: ASKS("gog_calendar_respond") },
36217
+ move: { does: "moves an event off guests' calendars (and can email them)", instead: ASKS("gog_calendar_move") },
36218
+ transfer: { does: "moves an event off guests' calendars (and can email them)", instead: ASKS("gog_calendar_move") },
36219
+ delete: { does: "removes an event from every guest's calendar (the whole series by default)", instead: ASKS("gog_calendar_delete") },
36220
+ del: { does: "removes an event from every guest's calendar (the whole series by default)", instead: ASKS("gog_calendar_delete") },
36221
+ rm: { does: "removes an event from every guest's calendar (the whole series by default)", instead: ASKS("gog_calendar_delete") },
36222
+ remove: { does: "removes an event from every guest's calendar (the whole series by default)", instead: ASKS("gog_calendar_delete") },
36223
+ "delete-calendar": { does: "deletes a calendar and every event on it", instead: ASKS("gog_calendar_delete_calendar") },
36224
+ "out-of-office": { does: "auto-declines invitations and notifies their organizers", instead: ASKS("gog_calendar_out_of_office") },
36225
+ ooo: { does: "auto-declines invitations and notifies their organizers", instead: ASKS("gog_calendar_out_of_office") }
36226
+ };
35726
36227
  var reminderParams = {
35727
36228
  reminders: external_exports.array(external_exports.string()).max(5).optional().describe(
35728
36229
  `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.`
@@ -35753,6 +36254,9 @@ var attachInlineParam = external_exports.array(inlineAttachmentSchema).optional(
35753
36254
  );
35754
36255
 
35755
36256
  // ../gogcli-mcp/src/tools/docs.ts
36257
+ function vetDocsRun(subcommand, args) {
36258
+ return vetCommentsRun("docs", subcommand, args);
36259
+ }
35756
36260
  function registerDocsTools(server) {
35757
36261
  server.registerTool("gog_docs_info", {
35758
36262
  description: "Get Google Doc metadata: title, ID, and other properties.",
@@ -35849,7 +36353,29 @@ function registerDocsTools(server) {
35849
36353
  }, async ({ docId, account }) => {
35850
36354
  return runOrDiagnose(["docs", "structure", pos(docId)], { account });
35851
36355
  });
35852
- registerRunTool(server, { service: "docs", examples: '"copy", "clear", "insert", "sed", "export"' });
36356
+ registerRunTool(server, { service: "docs", examples: '"copy", "clear", "insert", "sed", "export"', vet: vetDocsRun });
36357
+ }
36358
+
36359
+ // ../gogcli-mcp/src/tools/drive.ts
36360
+ function commentSnapshot(raw) {
36361
+ let comment;
36362
+ try {
36363
+ const parsed = JSON.parse(raw);
36364
+ comment = parsed?.comment ?? parsed ?? void 0;
36365
+ } catch {
36366
+ comment = void 0;
36367
+ }
36368
+ const name = typeof comment?.author?.displayName === "string" ? comment.author.displayName : void 0;
36369
+ const email3 = typeof comment?.author?.emailAddress === "string" ? comment.author.emailAddress : void 0;
36370
+ const author = name && email3 ? `${name} <${email3}>` : name ?? email3;
36371
+ return {
36372
+ ...author ? { author } : {},
36373
+ ...typeof comment?.content === "string" ? { content: comment.content } : {},
36374
+ ...typeof comment?.resolved === "boolean" ? { resolved: comment.resolved } : {}
36375
+ };
36376
+ }
36377
+ function commentMentions(text) {
36378
+ return [...new Set(text.match(/(?<=[+@])[\w.+-]+@[\w-]+(?:\.[\w-]+)+/g) ?? [])];
35853
36379
  }
35854
36380
 
35855
36381
  // ../gogcli-mcp/src/tools/gmail.ts
@@ -35885,7 +36411,7 @@ var failIfNotEmptyParam = external_exports.boolean().optional().describe(
35885
36411
  );
35886
36412
 
35887
36413
  // ../gogcli-mcp/src/server.ts
35888
- var VERSION = true ? "4.5.0" : "0.0.0";
36414
+ var VERSION = true ? "4.5.1" : "0.0.0";
35889
36415
 
35890
36416
  // ../gogcli-mcp/src/bootstrap-auth.ts
35891
36417
  import { join as join5 } from "node:path";
@@ -35922,12 +36448,12 @@ async function bootstrapGogAuth(env = process.env, options = {}) {
35922
36448
  const [clientId, clientSecret, refreshToken, account] = values;
35923
36449
  const { spawner } = options;
35924
36450
  try {
35925
- const { createHash } = await import("node:crypto");
36451
+ const { createHash: createHash4 } = await import("node:crypto");
35926
36452
  const { mkdir, readFile, writeFile, chmod } = await import("node:fs/promises");
35927
36453
  const home = options.home ?? (await import("node:os")).homedir();
35928
36454
  const dir = join5(home, ".gogcli-mcp");
35929
36455
  const marker = join5(dir, AUTH_BOOTSTRAP_MARKER);
35930
- const fingerprint = createHash("sha256").update(values.join("\0")).digest("hex");
36456
+ const fingerprint = createHash4("sha256").update(values.join("\0")).digest("hex");
35931
36457
  const previous = await readFile(marker, "utf8").catch(() => void 0);
35932
36458
  if (previous === fingerprint && await accountListed(account, spawner)) return "present";
35933
36459
  await run(
@@ -35960,6 +36486,15 @@ var BLOB_URL_DEFAULT_TTL_MS = 60 * 60 * 1e3;
35960
36486
  var MAX_BLOB_UPLOAD_BYTES = 100 * 1024 * 1024;
35961
36487
 
35962
36488
  // src/tools/docs-extra.ts
36489
+ function docTitle(raw) {
36490
+ try {
36491
+ const parsed = JSON.parse(raw);
36492
+ const title = parsed?.document?.title ?? parsed?.title;
36493
+ return typeof title === "string" ? title : void 0;
36494
+ } catch {
36495
+ return void 0;
36496
+ }
36497
+ }
35963
36498
  function registerExtraDocsTools(server) {
35964
36499
  server.registerTool("gog_docs_copy", {
35965
36500
  description: "Copy a Google Doc to a new document with the given title.",
@@ -36325,29 +36860,78 @@ function registerExtraDocsTools(server) {
36325
36860
  return runOrDiagnose(["docs", "comments", "get", pos(docId), pos(commentId)], { account });
36326
36861
  });
36327
36862
  server.registerTool("gog_docs_comments_add", {
36328
- description: "Add a comment to a Google Doc. Optionally attach quoted text that appears as the highlighted passage in the Google Docs UI.",
36863
+ description: "Add a comment to a Google Doc. Optionally attach quoted text that appears as the highlighted passage in the Google Docs UI. The Doc's owner and everyone the text +mentions are notified, so this reads the Doc and asks the MCP host to show the user a confirmation prompt with the Doc, the text and who is mentioned first; nothing is posted unless they accept." + CONFIRM_FALLBACK_DESCRIPTION,
36329
36864
  annotations: { destructiveHint: false },
36330
36865
  inputSchema: external_exports.object({
36331
36866
  docId: external_exports.string().describe("Doc ID (from the URL)"),
36332
36867
  content: external_exports.string().describe("Comment text"),
36333
36868
  quoted: external_exports.string().optional().describe("Quoted text to attach to the comment (shown in UIs when available)"),
36334
- account: accountParam
36869
+ account: accountParam,
36870
+ confirmToken: confirmTokenParam
36335
36871
  })
36336
- }, async ({ docId, content, quoted, account }) => {
36872
+ }, async ({ docId, content, quoted, account, confirmToken }, ctx) => {
36337
36873
  const args = ["docs", "comments", "add", pos(docId), pos(content)];
36338
36874
  if (quoted) args.push(`--quoted=${quoted}`);
36875
+ const got = await runOrDiagnose(["docs", "info", pos(docId)], { account });
36876
+ if (got.isError) return got;
36877
+ const title = docTitle(resultText(got));
36878
+ const doc = { id: docId, ...title !== void 0 ? { title } : {} };
36879
+ const mentions = commentMentions(content);
36880
+ const confirmation = await requireDispatchConfirmation(ctx, {
36881
+ action: "docs.comment-add",
36882
+ message: "Review and confirm this comment \u2014 the Doc's owner and anyone mentioned are notified:",
36883
+ confirmationLabel: "Confirm that this comment should be posted now.",
36884
+ details: { doc, textPreview: bodyPreview(content), quoted, mentions },
36885
+ unsupportedNote: "Ask the user to comment from Google Docs.",
36886
+ fallback: {
36887
+ tool: "gog_docs_comments_add",
36888
+ account,
36889
+ confirmToken,
36890
+ subject: () => {
36891
+ const view = { doc, text: content, quoted, mentions };
36892
+ return { target: docId, payload: view, preview: view };
36893
+ }
36894
+ }
36895
+ });
36896
+ if (confirmation) return confirmation;
36339
36897
  return runOrDiagnose(args, { account });
36340
36898
  });
36341
36899
  server.registerTool("gog_docs_comments_reply", {
36342
- description: "Reply to an existing comment on a Google Doc.",
36900
+ description: "Reply to an existing comment on a Google Doc. Everyone on the thread and anyone the reply +mentions is notified, so this reads the Doc 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,
36343
36901
  annotations: { destructiveHint: false },
36344
36902
  inputSchema: external_exports.object({
36345
36903
  docId: external_exports.string().describe("Doc ID (from the URL)"),
36346
36904
  commentId: external_exports.string().describe("Comment ID to reply to"),
36347
36905
  content: external_exports.string().describe("Reply text"),
36348
- account: accountParam
36906
+ account: accountParam,
36907
+ confirmToken: confirmTokenParam
36349
36908
  })
36350
- }, async ({ docId, commentId, content, account }) => {
36909
+ }, async ({ docId, commentId, content, account, confirmToken }, ctx) => {
36910
+ const got = await runOrDiagnose(["docs", "info", pos(docId)], { account });
36911
+ if (got.isError) return got;
36912
+ const thread = await runOrDiagnose(["docs", "comments", "get", pos(docId), pos(commentId)], { account });
36913
+ if (thread.isError) return thread;
36914
+ const title = docTitle(resultText(got));
36915
+ const doc = { id: docId, ...title !== void 0 ? { title } : {} };
36916
+ const replyingTo = commentSnapshot(resultText(thread));
36917
+ const mentions = commentMentions(content);
36918
+ const confirmation = await requireDispatchConfirmation(ctx, {
36919
+ action: "docs.comment-reply",
36920
+ message: "Review and confirm this reply \u2014 everyone on the thread and anyone mentioned is notified:",
36921
+ confirmationLabel: "Confirm that this reply should be posted now.",
36922
+ details: { doc, replyingTo, textPreview: bodyPreview(content), mentions },
36923
+ unsupportedNote: "Ask the user to reply from Google Docs.",
36924
+ fallback: {
36925
+ tool: "gog_docs_comments_reply",
36926
+ account,
36927
+ confirmToken,
36928
+ subject: () => {
36929
+ const view = { doc, replyingTo, text: content, mentions };
36930
+ return { target: `${docId}/${commentId}`, payload: view, preview: view };
36931
+ }
36932
+ }
36933
+ });
36934
+ if (confirmation) return confirmation;
36351
36935
  return runOrDiagnose(["docs", "comments", "reply", pos(docId), pos(commentId), pos(content)], { account });
36352
36936
  });
36353
36937
  server.registerTool("gog_docs_comments_resolve", {
package/manifest.json CHANGED
@@ -3,7 +3,7 @@
3
3
  "manifest_version": "0.3",
4
4
  "name": "gogcli-mcp-docs",
5
5
  "display_name": "gogcli (Docs)",
6
- "version": "4.5.0",
6
+ "version": "4.5.1",
7
7
  "description": "Extended Google Docs for Claude via gogcli — auth + full Docs and comments support",
8
8
  "author": {
9
9
  "name": "Chris Hall",
@@ -180,11 +180,11 @@
180
180
  },
181
181
  {
182
182
  "name": "gog_docs_comments_add",
183
- "description": "Add a comment to a Google Doc. Optionally attach quoted text that appears as the highlighted passage in the Google Docs UI."
183
+ "description": "Add a comment to a Google Doc. Optionally attach quoted text that appears as the highlighted passage in the Google Docs UI. Asks the user to confirm."
184
184
  },
185
185
  {
186
186
  "name": "gog_docs_comments_reply",
187
- "description": "Reply to an existing comment on a Google Doc."
187
+ "description": "Reply to an existing comment on a Google Doc. Asks the user to confirm."
188
188
  },
189
189
  {
190
190
  "name": "gog_docs_comments_resolve",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "gogcli-mcp-docs",
3
- "version": "4.5.0",
3
+ "version": "4.5.1",
4
4
  "mcpName": "io.github.chrischall/gogcli-mcp-docs",
5
5
  "description": "Extended Google Docs MCP server via gogcli — all base tools plus full Docs support",
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-docs"
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-docs",
15
- "version": "4.5.0",
15
+ "version": "4.5.1",
16
16
  "transport": {
17
17
  "type": "stdio"
18
18
  },
@@ -1,8 +1,34 @@
1
1
  import { McpServer } from '@modelcontextprotocol/server';
2
2
  import { z } from 'zod';
3
- import { accountParam, runOrDiagnose, paginationParams, pushPaginationFlags, payloadArg, pos, confinePath } from '../../../gogcli-mcp/src/lib.js';
3
+ import {
4
+ accountParam,
5
+ runOrDiagnose,
6
+ paginationParams,
7
+ pushPaginationFlags,
8
+ payloadArg,
9
+ pos,
10
+ confinePath,
11
+ bodyPreview,
12
+ commentMentions,
13
+ commentSnapshot,
14
+ CONFIRM_FALLBACK_DESCRIPTION,
15
+ confirmTokenParam,
16
+ requireDispatchConfirmation,
17
+ resultText,
18
+ } from '../../../gogcli-mcp/src/lib.js';
4
19
  import type { GogArg } from '../../../gogcli-mcp/src/lib.js';
5
20
 
21
+ /** A Doc's title from `gog docs info`, for a comment's prompt. Unreadable output names nothing. */
22
+ export function docTitle(raw: string): string | undefined {
23
+ try {
24
+ const parsed = JSON.parse(raw) as { title?: unknown; document?: { title?: unknown } } | null;
25
+ const title = parsed?.document?.title ?? parsed?.title;
26
+ return typeof title === 'string' ? title : undefined;
27
+ } catch {
28
+ return undefined;
29
+ }
30
+ }
31
+
6
32
  export function registerExtraDocsTools(server: McpServer): void {
7
33
  server.registerTool('gog_docs_copy', {
8
34
  description: 'Copy a Google Doc to a new document with the given title.',
@@ -419,30 +445,84 @@ export function registerExtraDocsTools(server: McpServer): void {
419
445
 
420
446
  server.registerTool('gog_docs_comments_add', {
421
447
  description:
422
- 'Add a comment to a Google Doc. Optionally attach quoted text that appears as the highlighted passage in the Google Docs UI.',
448
+ 'Add a comment to a Google Doc. Optionally attach quoted text that appears as the highlighted passage in the Google Docs UI. '
449
+ + 'The Doc\'s owner and everyone the text +mentions are notified, so this reads the Doc and asks the MCP host to show '
450
+ + 'the user a confirmation prompt with the Doc, the text and who is mentioned first; nothing is posted unless they '
451
+ + 'accept.' + CONFIRM_FALLBACK_DESCRIPTION,
423
452
  annotations: { destructiveHint: false },
424
453
  inputSchema: z.object({
425
454
  docId: z.string().describe('Doc ID (from the URL)'),
426
455
  content: z.string().describe('Comment text'),
427
456
  quoted: z.string().optional().describe('Quoted text to attach to the comment (shown in UIs when available)'),
428
457
  account: accountParam,
458
+ confirmToken: confirmTokenParam,
429
459
  }),
430
- }, async ({ docId, content, quoted, account }) => {
460
+ }, async ({ docId, content, quoted, account, confirmToken }, ctx) => {
431
461
  const args: GogArg[] = ['docs', 'comments', 'add', pos(docId), pos(content)];
432
462
  if (quoted) args.push(`--quoted=${quoted}`);
463
+ const got = await runOrDiagnose(['docs', 'info', pos(docId)], { account });
464
+ if (got.isError) return got;
465
+ const title = docTitle(resultText(got));
466
+ const doc = { id: docId, ...(title !== undefined ? { title } : {}) };
467
+ const mentions = commentMentions(content);
468
+ const confirmation = await requireDispatchConfirmation(ctx, {
469
+ action: 'docs.comment-add',
470
+ message: 'Review and confirm this comment — the Doc\'s owner and anyone mentioned are notified:',
471
+ confirmationLabel: 'Confirm that this comment should be posted now.',
472
+ details: { doc, textPreview: bodyPreview(content), quoted, mentions },
473
+ unsupportedNote: 'Ask the user to comment from Google Docs.',
474
+ fallback: {
475
+ tool: 'gog_docs_comments_add',
476
+ account,
477
+ confirmToken,
478
+ subject: () => {
479
+ const view = { doc, text: content, quoted, mentions };
480
+ return { target: docId, payload: view, preview: view };
481
+ },
482
+ },
483
+ });
484
+ if (confirmation) return confirmation;
433
485
  return runOrDiagnose(args, { account });
434
486
  });
435
487
 
436
488
  server.registerTool('gog_docs_comments_reply', {
437
- description: 'Reply to an existing comment on a Google Doc.',
489
+ description: 'Reply to an existing comment on a Google Doc. Everyone on the thread and anyone the reply +mentions is '
490
+ + 'notified, so this reads the Doc and the comment and asks the MCP host to show the user a confirmation prompt '
491
+ + 'with both and the reply first; nothing is posted unless they accept.' + CONFIRM_FALLBACK_DESCRIPTION,
438
492
  annotations: { destructiveHint: false },
439
493
  inputSchema: z.object({
440
494
  docId: z.string().describe('Doc ID (from the URL)'),
441
495
  commentId: z.string().describe('Comment ID to reply to'),
442
496
  content: z.string().describe('Reply text'),
443
497
  account: accountParam,
444
- }),
445
- }, async ({ docId, commentId, content, account }) => {
498
+ confirmToken: confirmTokenParam,
499
+ }),
500
+ }, async ({ docId, commentId, content, account, confirmToken }, ctx) => {
501
+ const got = await runOrDiagnose(['docs', 'info', pos(docId)], { account });
502
+ if (got.isError) return got;
503
+ const thread = await runOrDiagnose(['docs', 'comments', 'get', pos(docId), pos(commentId)], { account });
504
+ if (thread.isError) return thread;
505
+ const title = docTitle(resultText(got));
506
+ const doc = { id: docId, ...(title !== undefined ? { title } : {}) };
507
+ const replyingTo = commentSnapshot(resultText(thread));
508
+ const mentions = commentMentions(content);
509
+ const confirmation = await requireDispatchConfirmation(ctx, {
510
+ action: 'docs.comment-reply',
511
+ message: 'Review and confirm this reply — everyone on the thread and anyone mentioned is notified:',
512
+ confirmationLabel: 'Confirm that this reply should be posted now.',
513
+ details: { doc, replyingTo, textPreview: bodyPreview(content), mentions },
514
+ unsupportedNote: 'Ask the user to reply from Google Docs.',
515
+ fallback: {
516
+ tool: 'gog_docs_comments_reply',
517
+ account,
518
+ confirmToken,
519
+ subject: () => {
520
+ const view = { doc, replyingTo, text: content, mentions };
521
+ return { target: `${docId}/${commentId}`, payload: view, preview: view };
522
+ },
523
+ },
524
+ });
525
+ if (confirmation) return confirmation;
446
526
  return runOrDiagnose(['docs', 'comments', 'reply', pos(docId), pos(commentId), pos(content)], { account });
447
527
  });
448
528
 
@@ -0,0 +1,137 @@
1
+ import { describe, it, expect, vi, beforeEach, afterEach } from 'vitest';
2
+ import { registerExtraDocsTools, docTitle } from '../../src/tools/docs-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 Doc comment or reply notifies the owner, the
16
+ // thread and everyone it +mentions, so both ask first — naming the Doc.
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(registerExtraDocsTools, { 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(registerExtraDocsTools);
35
+
36
+ const INFO = JSON.stringify({ document: { documentId: 'd1', title: 'Q3 plan' } });
37
+ const COMMENT = JSON.stringify({ comment: { id: 'k1', content: 'Is this final?', author: { displayName: 'Alice' } } });
38
+ function stub(failing?: string, info = INFO) {
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 === 'docs info') return rawTextResult(info);
43
+ if (key === 'docs 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_docs_comments_add', () => {
51
+ const ARGS = { docId: 'd1', content: 'Check with @bob@example.com', quoted: 'Revenue' };
52
+
53
+ it('reads the Doc and asks with its title, the text, the quote and who is mentioned', async () => {
54
+ stub();
55
+ const { harness, details } = await prompted();
56
+ await harness.callTool('gog_docs_comments_add', ARGS);
57
+ expect(details()).toEqual({ doc: { id: 'd1', title: 'Q3 plan' }, textPreview: ARGS.content, quoted: 'Revenue', mentions: ['bob@example.com'] });
58
+ expect(callsTo('docs', 'comments', 'add')[0]![0]).toEqual(['docs', 'comments', 'add', pos('d1'), pos(ARGS.content), '--quoted=Revenue']);
59
+ });
60
+
61
+ it('posts nothing when the user declines or the read fails', async () => {
62
+ stub();
63
+ expect(json(await (await prompted({ action: 'decline' })).harness.callTool('gog_docs_comments_add', ARGS)))
64
+ .toMatchObject({ cancelled: true, action: 'docs.comment-add' });
65
+ stub('docs info');
66
+ expect((await (await prompted()).harness.callTool('gog_docs_comments_add', ARGS)).isError).toBe(true);
67
+ expect(callsTo('docs', 'comments', 'add')).toHaveLength(0);
68
+ });
69
+
70
+ it('refuses a client that cannot be prompted', async () => {
71
+ process.env.MCP_CONFIRM_MODE = 'refuse';
72
+ stub();
73
+ const r = json(await (await unprompted()).callTool('gog_docs_comments_add', ARGS));
74
+ expect(r).toMatchObject({ reason: 'confirmation-unsupported', action: 'docs.comment-add' });
75
+ expect(r.note).toMatch(/Google Docs/);
76
+ });
77
+
78
+ it('token fallback: changed text is DRAFT_CHANGED; the same call posts', async () => {
79
+ process.env.MCP_CONFIRM_MODE = 'ask-user';
80
+ stub(undefined, '{}');
81
+ const harness = await unprompted();
82
+ const args = { docId: 'd1', content: 'Nice' };
83
+ const p1 = json(await harness.callTool('gog_docs_comments_add', args));
84
+ expect(p1.preview).toEqual({ doc: { id: 'd1' }, text: 'Nice', mentions: [] });
85
+ expect(json(await harness.callTool('gog_docs_comments_add', { ...args, content: 'Nicer', confirmToken: p1.confirmToken })))
86
+ .toMatchObject({ error: 'DRAFT_CHANGED' });
87
+ await harness.callTool('gog_docs_comments_add', { ...args, confirmToken: p1.confirmToken });
88
+ expect(callsTo('docs', 'comments', 'add')).toHaveLength(1);
89
+ });
90
+ });
91
+
92
+ describe('gog_docs_comments_reply', () => {
93
+ const ARGS = { docId: 'd1', commentId: 'k1', content: 'Yes.' };
94
+
95
+ it('reads the Doc and the comment and asks with both and the reply', async () => {
96
+ stub();
97
+ const { harness, details } = await prompted();
98
+ await harness.callTool('gog_docs_comments_reply', ARGS);
99
+ expect(details()).toEqual({ doc: { id: 'd1', title: 'Q3 plan' }, replyingTo: { author: 'Alice', content: 'Is this final?' }, textPreview: 'Yes.', mentions: [] });
100
+ expect(callsTo('docs', 'comments', 'reply')[0]![0]).toEqual(['docs', 'comments', 'reply', pos('d1'), pos('k1'), pos('Yes.')]);
101
+ });
102
+
103
+ it.each(['docs info', 'docs comments get'])('returns a failed read (%s) without asking or replying', async (failing) => {
104
+ stub(failing);
105
+ const { harness, seen } = await prompted();
106
+ expect((await harness.callTool('gog_docs_comments_reply', ARGS)).isError).toBe(true);
107
+ expect(seen).toHaveLength(0);
108
+ expect(callsTo('docs', 'comments', 'reply')).toHaveLength(0);
109
+ });
110
+
111
+ it('refuses a client that cannot be prompted', async () => {
112
+ process.env.MCP_CONFIRM_MODE = 'refuse';
113
+ stub();
114
+ const r = json(await (await unprompted()).callTool('gog_docs_comments_reply', ARGS));
115
+ expect(r).toMatchObject({ reason: 'confirmation-unsupported', action: 'docs.comment-reply' });
116
+ });
117
+
118
+ it('token fallback: previews the thread and posts on phase 2', async () => {
119
+ process.env.MCP_CONFIRM_MODE = 'ask-user';
120
+ stub();
121
+ const harness = await unprompted();
122
+ const p1 = json(await harness.callTool('gog_docs_comments_reply', ARGS));
123
+ expect(p1.preview).toEqual({ doc: { id: 'd1', title: 'Q3 plan' }, replyingTo: { author: 'Alice', content: 'Is this final?' }, text: 'Yes.', mentions: [] });
124
+ await harness.callTool('gog_docs_comments_reply', { ...ARGS, confirmToken: p1.confirmToken });
125
+ expect(callsTo('docs', 'comments', 'reply')).toHaveLength(1);
126
+ });
127
+ });
128
+
129
+ describe('docTitle', () => {
130
+ it('reads a nested or top-level title and tolerates unreadable output', () => {
131
+ expect(docTitle(JSON.stringify({ document: { title: 'A' } }))).toBe('A');
132
+ expect(docTitle(JSON.stringify({ title: 'B' }))).toBe('B');
133
+ expect(docTitle(JSON.stringify({ title: 7 }))).toBeUndefined();
134
+ expect(docTitle('null')).toBeUndefined();
135
+ expect(docTitle('nope')).toBeUndefined();
136
+ });
137
+ });
@@ -13,7 +13,10 @@ vi.mock('../../../gogcli-mcp/src/lib.js', async (importOriginal) => {
13
13
  };
14
14
  });
15
15
 
16
- const setupHandlers = () => createTestHarness(registerExtraDocsTools);
16
+ // The comment tools ask first (docs-extra-gates.test.ts covers the prompts); here the user accepts.
17
+ const setupHandlers = () => createTestHarness(registerExtraDocsTools, {
18
+ elicitation: async () => ({ action: 'accept', content: { confirmed: true } }),
19
+ });
17
20
 
18
21
  beforeEach(() => vi.clearAllMocks());
19
22