gogcli-mcp-drive 4.4.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.
- package/.claude-plugin/marketplace.json +2 -2
- package/.claude-plugin/plugin.json +1 -1
- package/dist/index.js +470 -209
- package/manifest.json +4 -4
- package/package.json +2 -2
- package/server.json +2 -2
- package/src/tools/drive-extra.ts +78 -5
- package/tests/tools/drive-extra-gates.test.ts +154 -0
- package/tests/tools/drive-extra.test.ts +4 -1
|
@@ -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.
|
|
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.
|
|
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.
|
|
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
|
@@ -34554,10 +34554,8 @@ function errorResult(message) {
|
|
|
34554
34554
|
|
|
34555
34555
|
// ../../node_modules/@chrischall/mcp-utils/dist/server/confirmation.js
|
|
34556
34556
|
import { createHash, createHmac, timingSafeEqual } from "node:crypto";
|
|
34557
|
-
|
|
34558
|
-
|
|
34559
|
-
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";
|
|
34560
|
-
var STATE_PREFIX = "mcpu.confirm.v1.";
|
|
34557
|
+
|
|
34558
|
+
// ../../node_modules/@chrischall/mcp-utils/dist/server/canonical.js
|
|
34561
34559
|
function canonicalJson(value) {
|
|
34562
34560
|
if (value === null || typeof value === "string" || typeof value === "boolean")
|
|
34563
34561
|
return JSON.stringify(value);
|
|
@@ -34568,7 +34566,7 @@ function canonicalJson(value) {
|
|
|
34568
34566
|
if (typeof value === "bigint")
|
|
34569
34567
|
return `{"$bigint":"${value.toString()}"}`;
|
|
34570
34568
|
if (typeof value === "function" || typeof value === "symbol") {
|
|
34571
|
-
throw new TypeError(`
|
|
34569
|
+
throw new TypeError(`confirmation: cannot bind a ${typeof value} argument value.`);
|
|
34572
34570
|
}
|
|
34573
34571
|
if (Array.isArray(value))
|
|
34574
34572
|
return `[${value.map(canonicalJson).join(",")}]`;
|
|
@@ -34590,7 +34588,7 @@ function canonicalJson(value) {
|
|
|
34590
34588
|
}
|
|
34591
34589
|
const proto = Object.getPrototypeOf(value);
|
|
34592
34590
|
if (proto !== Object.prototype && proto !== null) {
|
|
34593
|
-
throw new TypeError("
|
|
34591
|
+
throw new TypeError("confirmation: cannot bind a non-plain object argument value (class instance).");
|
|
34594
34592
|
}
|
|
34595
34593
|
const entries = Object.entries(value).filter(([, v]) => v !== void 0).sort(([a], [b]) => a < b ? -1 : a > b ? 1 : 0);
|
|
34596
34594
|
return `{${entries.map(([k, v]) => `${JSON.stringify(escapeKey(k))}:${canonicalJson(v)}`).join(",")}}`;
|
|
@@ -34598,6 +34596,12 @@ function canonicalJson(value) {
|
|
|
34598
34596
|
function escapeKey(key) {
|
|
34599
34597
|
return key.startsWith("$") ? `$${key}` : key;
|
|
34600
34598
|
}
|
|
34599
|
+
|
|
34600
|
+
// ../../node_modules/@chrischall/mcp-utils/dist/server/confirmation.js
|
|
34601
|
+
var DEFAULT_REQUEST_KEY = "confirmation";
|
|
34602
|
+
var DEFAULT_CONFIRMATION_LABEL = "Confirm this action should proceed.";
|
|
34603
|
+
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";
|
|
34604
|
+
var STATE_PREFIX = "mcpu.confirm.v1.";
|
|
34601
34605
|
function bindingKey(binding) {
|
|
34602
34606
|
if (binding.ttlSeconds !== void 0 && !(Number.isFinite(binding.ttlSeconds) && binding.ttlSeconds > 0)) {
|
|
34603
34607
|
throw new RangeError("requireConfirmation: binding.ttlSeconds must be a finite number greater than 0.");
|
|
@@ -34700,6 +34704,264 @@ ${JSON.stringify(preview, null, 2)}`,
|
|
|
34700
34704
|
});
|
|
34701
34705
|
}
|
|
34702
34706
|
|
|
34707
|
+
// ../../node_modules/@chrischall/mcp-utils/dist/server/confirm-token.js
|
|
34708
|
+
import { createHash as createHash2, createHmac as createHmac2, randomBytes, timingSafeEqual as timingSafeEqual2 } from "node:crypto";
|
|
34709
|
+
function createSpentTokenStore() {
|
|
34710
|
+
const spent2 = /* @__PURE__ */ new Map();
|
|
34711
|
+
return {
|
|
34712
|
+
has: (nonce) => spent2.has(nonce),
|
|
34713
|
+
add: (nonce, exp) => {
|
|
34714
|
+
spent2.set(nonce, exp);
|
|
34715
|
+
},
|
|
34716
|
+
prune: (now) => {
|
|
34717
|
+
for (const [nonce, exp] of spent2)
|
|
34718
|
+
if (exp < now)
|
|
34719
|
+
spent2.delete(nonce);
|
|
34720
|
+
},
|
|
34721
|
+
clear: () => spent2.clear(),
|
|
34722
|
+
get size() {
|
|
34723
|
+
return spent2.size;
|
|
34724
|
+
}
|
|
34725
|
+
};
|
|
34726
|
+
}
|
|
34727
|
+
var PROCESS_SPENT = createSpentTokenStore();
|
|
34728
|
+
var PREFIX = "mcpu.token.v1.";
|
|
34729
|
+
var DEFAULT_TTL_SECONDS = 600;
|
|
34730
|
+
function tokenKey(key) {
|
|
34731
|
+
const bytes = typeof key === "string" ? Buffer.from(key, "utf8") : Buffer.from(key);
|
|
34732
|
+
if (bytes.length < 32)
|
|
34733
|
+
throw new RangeError("confirm token: key must be at least 32 bytes.");
|
|
34734
|
+
return bytes;
|
|
34735
|
+
}
|
|
34736
|
+
function ttlOf(ttlSeconds) {
|
|
34737
|
+
if (ttlSeconds === void 0)
|
|
34738
|
+
return DEFAULT_TTL_SECONDS;
|
|
34739
|
+
if (!(Number.isFinite(ttlSeconds) && ttlSeconds > 0)) {
|
|
34740
|
+
throw new RangeError("confirm token: ttlSeconds must be a finite number greater than 0.");
|
|
34741
|
+
}
|
|
34742
|
+
return ttlSeconds;
|
|
34743
|
+
}
|
|
34744
|
+
function sign(key, body) {
|
|
34745
|
+
return createHmac2("sha256", key).update(`${PREFIX}${body}`).digest();
|
|
34746
|
+
}
|
|
34747
|
+
function hashConfirmPayload(payload) {
|
|
34748
|
+
return createHash2("sha256").update(canonicalJson(payload)).digest("base64url");
|
|
34749
|
+
}
|
|
34750
|
+
function issueConfirmToken(key, binding, options = {}) {
|
|
34751
|
+
const k = tokenKey(key);
|
|
34752
|
+
const now = options.now ?? Date.now();
|
|
34753
|
+
const exp = now + ttlOf(options.ttlSeconds) * 1e3;
|
|
34754
|
+
const claims = {
|
|
34755
|
+
t: binding.tool,
|
|
34756
|
+
...binding.account === void 0 ? {} : { a: binding.account },
|
|
34757
|
+
g: binding.target,
|
|
34758
|
+
...binding.revision === void 0 ? {} : { r: binding.revision },
|
|
34759
|
+
h: binding.payloadHash,
|
|
34760
|
+
exp,
|
|
34761
|
+
n: randomBytes(16).toString("base64url")
|
|
34762
|
+
};
|
|
34763
|
+
const body = Buffer.from(JSON.stringify(claims), "utf8").toString("base64url");
|
|
34764
|
+
return { token: `${PREFIX}${body}.${sign(k, body).toString("base64url")}`, expiresAt: new Date(exp).toISOString() };
|
|
34765
|
+
}
|
|
34766
|
+
function parseClaims(body) {
|
|
34767
|
+
try {
|
|
34768
|
+
const claims = JSON.parse(Buffer.from(body, "base64url").toString("utf8"));
|
|
34769
|
+
return claims && typeof claims === "object" ? claims : void 0;
|
|
34770
|
+
} catch {
|
|
34771
|
+
return void 0;
|
|
34772
|
+
}
|
|
34773
|
+
}
|
|
34774
|
+
function verifyConfirmToken(key, token, binding, options = {}) {
|
|
34775
|
+
const k = tokenKey(key);
|
|
34776
|
+
const now = options.now ?? Date.now();
|
|
34777
|
+
const spent2 = options.spent ?? PROCESS_SPENT;
|
|
34778
|
+
spent2.prune(now);
|
|
34779
|
+
if (!token.startsWith(PREFIX))
|
|
34780
|
+
return { ok: false, error: "TOKEN_INVALID" };
|
|
34781
|
+
const rest = token.slice(PREFIX.length);
|
|
34782
|
+
const dot = rest.indexOf(".");
|
|
34783
|
+
const body = dot < 0 ? "" : rest.slice(0, dot);
|
|
34784
|
+
const mac3 = Buffer.from(dot < 0 ? "" : rest.slice(dot + 1), "base64url");
|
|
34785
|
+
const expected = sign(k, body);
|
|
34786
|
+
if (!body || mac3.length !== expected.length || !timingSafeEqual2(mac3, expected))
|
|
34787
|
+
return { ok: false, error: "TOKEN_INVALID" };
|
|
34788
|
+
const claims = parseClaims(body);
|
|
34789
|
+
if (!claims)
|
|
34790
|
+
return { ok: false, error: "TOKEN_INVALID" };
|
|
34791
|
+
if (claims.t !== binding.tool || claims.a !== binding.account || claims.g !== binding.target) {
|
|
34792
|
+
return { ok: false, error: "TOKEN_INVALID" };
|
|
34793
|
+
}
|
|
34794
|
+
if (spent2.has(claims.n))
|
|
34795
|
+
return { ok: false, error: "TOKEN_REUSED" };
|
|
34796
|
+
if (now > claims.exp)
|
|
34797
|
+
return { ok: false, error: "TOKEN_EXPIRED" };
|
|
34798
|
+
if (claims.r !== binding.revision)
|
|
34799
|
+
return { ok: false, error: "DRAFT_CHANGED", reason: "revision-changed" };
|
|
34800
|
+
if (claims.h !== binding.payloadHash)
|
|
34801
|
+
return { ok: false, error: "DRAFT_CHANGED", reason: "payload-changed" };
|
|
34802
|
+
spent2.add(claims.n, claims.exp);
|
|
34803
|
+
return { ok: true };
|
|
34804
|
+
}
|
|
34805
|
+
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.";
|
|
34806
|
+
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.`);
|
|
34807
|
+
var TOKEN_ERROR_NOTE = {
|
|
34808
|
+
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.",
|
|
34809
|
+
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.",
|
|
34810
|
+
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."
|
|
34811
|
+
};
|
|
34812
|
+
var CHANGED_NOTE = {
|
|
34813
|
+
"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.",
|
|
34814
|
+
"payload-changed": "Nothing was sent or changed: what would happen no longer matches what the user approved."
|
|
34815
|
+
};
|
|
34816
|
+
function isToolResult(value) {
|
|
34817
|
+
return Array.isArray(value.content);
|
|
34818
|
+
}
|
|
34819
|
+
function rejection2(data) {
|
|
34820
|
+
return { ...textResult({ status: "confirmation-rejected", confirmed: false, dispatched: false, ...data }), isError: true };
|
|
34821
|
+
}
|
|
34822
|
+
async function tokenConfirmation(action, fb) {
|
|
34823
|
+
const subject = await fb.subject();
|
|
34824
|
+
if (isToolResult(subject))
|
|
34825
|
+
return subject;
|
|
34826
|
+
const binding = {
|
|
34827
|
+
tool: fb.tool,
|
|
34828
|
+
...fb.account === void 0 ? {} : { account: fb.account },
|
|
34829
|
+
target: subject.target,
|
|
34830
|
+
...subject.revision === void 0 ? {} : { revision: subject.revision },
|
|
34831
|
+
payloadHash: hashConfirmPayload(subject.payload)
|
|
34832
|
+
};
|
|
34833
|
+
const phaseOne = () => {
|
|
34834
|
+
const { token, expiresAt } = issueConfirmToken(fb.key, binding, { ttlSeconds: fb.ttlSeconds });
|
|
34835
|
+
return {
|
|
34836
|
+
action,
|
|
34837
|
+
preview: subject.preview,
|
|
34838
|
+
confirmToken: token,
|
|
34839
|
+
expiresAt,
|
|
34840
|
+
ttlSeconds: ttlOf(fb.ttlSeconds),
|
|
34841
|
+
instruction: fb.instruction ?? CONFIRM_TOKEN_INSTRUCTION
|
|
34842
|
+
};
|
|
34843
|
+
};
|
|
34844
|
+
if (!fb.confirmToken) {
|
|
34845
|
+
return textResult({ status: "confirmation-required", confirmed: false, dispatched: false, ...phaseOne() });
|
|
34846
|
+
}
|
|
34847
|
+
const verdict = verifyConfirmToken(fb.key, fb.confirmToken, binding, { spent: fb.spent });
|
|
34848
|
+
if (verdict.ok)
|
|
34849
|
+
return void 0;
|
|
34850
|
+
if (verdict.error === "DRAFT_CHANGED") {
|
|
34851
|
+
return rejection2({
|
|
34852
|
+
error: "DRAFT_CHANGED",
|
|
34853
|
+
reason: verdict.reason,
|
|
34854
|
+
note: `${CHANGED_NOTE[verdict.reason]} The current preview and a fresh confirmToken are below.`,
|
|
34855
|
+
...phaseOne()
|
|
34856
|
+
});
|
|
34857
|
+
}
|
|
34858
|
+
return rejection2({ error: verdict.error, action, note: TOKEN_ERROR_NOTE[verdict.error] });
|
|
34859
|
+
}
|
|
34860
|
+
async function requireConfirmationWithFallback(ctx, options) {
|
|
34861
|
+
const { tokenFallback, ...confirmation } = options;
|
|
34862
|
+
if (tokenFallback && callerAcceptsFormElicitation(ctx) === false) {
|
|
34863
|
+
return tokenConfirmation(options.action, tokenFallback);
|
|
34864
|
+
}
|
|
34865
|
+
return requireConfirmation(ctx, confirmation);
|
|
34866
|
+
}
|
|
34867
|
+
|
|
34868
|
+
// ../../node_modules/@chrischall/mcp-utils/dist/server/confirm-env.js
|
|
34869
|
+
import { createHash as createHash3, randomBytes as randomBytes2 } from "node:crypto";
|
|
34870
|
+
|
|
34871
|
+
// ../../node_modules/@chrischall/mcp-utils/dist/config/index.js
|
|
34872
|
+
import { homedir } from "node:os";
|
|
34873
|
+
import { isAbsolute, join, resolve } from "node:path";
|
|
34874
|
+
var PLACEHOLDER_RE = /^\$\{[^}]*\}$/;
|
|
34875
|
+
function readEnvVar(key, opts = {}) {
|
|
34876
|
+
const env = opts.env ?? process.env;
|
|
34877
|
+
const raw = env[key];
|
|
34878
|
+
if (typeof raw === "string") {
|
|
34879
|
+
const trimmed = raw.trim();
|
|
34880
|
+
if (trimmed.length > 0 && trimmed !== "undefined" && trimmed !== "null" && !PLACEHOLDER_RE.test(trimmed)) {
|
|
34881
|
+
return trimmed;
|
|
34882
|
+
}
|
|
34883
|
+
}
|
|
34884
|
+
return opts.default;
|
|
34885
|
+
}
|
|
34886
|
+
var TRUE_TOKENS = /* @__PURE__ */ new Set(["1", "true", "yes", "on"]);
|
|
34887
|
+
var FALSE_TOKENS = /* @__PURE__ */ new Set(["0", "false", "no", "off"]);
|
|
34888
|
+
function parseBoolEnv(key, opts = {}) {
|
|
34889
|
+
const fallback = opts.default ?? false;
|
|
34890
|
+
const raw = readEnvVar(key, { env: opts.env });
|
|
34891
|
+
if (raw === void 0)
|
|
34892
|
+
return fallback;
|
|
34893
|
+
const token = raw.toLowerCase();
|
|
34894
|
+
if (TRUE_TOKENS.has(token))
|
|
34895
|
+
return true;
|
|
34896
|
+
if (FALSE_TOKENS.has(token))
|
|
34897
|
+
return false;
|
|
34898
|
+
return fallback;
|
|
34899
|
+
}
|
|
34900
|
+
function expandPath(p) {
|
|
34901
|
+
let expanded = p;
|
|
34902
|
+
if (p === "~") {
|
|
34903
|
+
expanded = homedir();
|
|
34904
|
+
} else if (p.startsWith("~/")) {
|
|
34905
|
+
expanded = join(homedir(), p.slice(2));
|
|
34906
|
+
}
|
|
34907
|
+
return isAbsolute(expanded) ? expanded : resolve(expanded);
|
|
34908
|
+
}
|
|
34909
|
+
|
|
34910
|
+
// ../../node_modules/@chrischall/mcp-utils/dist/server/confirm-env.js
|
|
34911
|
+
var MODES = /* @__PURE__ */ new Set(["ask-user", "auto", "refuse"]);
|
|
34912
|
+
var DEFAULT_TTL_SECONDS2 = 600;
|
|
34913
|
+
var warned = /* @__PURE__ */ new Set();
|
|
34914
|
+
function readConfirmMode(env = process.env) {
|
|
34915
|
+
const raw = readEnvVar("MCP_CONFIRM_MODE", { env })?.trim().toLowerCase();
|
|
34916
|
+
if (!raw)
|
|
34917
|
+
return "ask-user";
|
|
34918
|
+
if (MODES.has(raw))
|
|
34919
|
+
return raw;
|
|
34920
|
+
if (!warned.has(raw)) {
|
|
34921
|
+
warned.add(raw);
|
|
34922
|
+
process.stderr.write(`MCP_CONFIRM_MODE="${raw}" is not one of ask-user, auto, refuse; treating it as refuse.
|
|
34923
|
+
`);
|
|
34924
|
+
}
|
|
34925
|
+
return "refuse";
|
|
34926
|
+
}
|
|
34927
|
+
function confirmTtlFromEnv(env = process.env) {
|
|
34928
|
+
const raw = readEnvVar("MCP_CONFIRM_TTL_SECONDS", { env })?.trim();
|
|
34929
|
+
return raw && /^[1-9]\d*$/.test(raw) ? Number(raw) : DEFAULT_TTL_SECONDS2;
|
|
34930
|
+
}
|
|
34931
|
+
var processKey;
|
|
34932
|
+
function confirmKeyFromEnv(env = process.env) {
|
|
34933
|
+
const secret = readEnvVar("MCP_CONFIRM_SECRET", { env });
|
|
34934
|
+
if (secret)
|
|
34935
|
+
return createHash3("sha256").update(secret, "utf8").digest();
|
|
34936
|
+
processKey ??= randomBytes2(32);
|
|
34937
|
+
return processKey;
|
|
34938
|
+
}
|
|
34939
|
+
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.)";
|
|
34940
|
+
var REFUSE_HINT = "Set MCP_CONFIRM_MODE=ask-user on the server to allow two-step confirmation instead.";
|
|
34941
|
+
function confirmationFromEnv(options) {
|
|
34942
|
+
const { tool, account, confirmToken, subject, instruction, spent: spent2, env = process.env, ...confirmation } = options;
|
|
34943
|
+
const mode = readConfirmMode(env);
|
|
34944
|
+
if (mode === "refuse") {
|
|
34945
|
+
return {
|
|
34946
|
+
...confirmation,
|
|
34947
|
+
unsupportedNote: confirmation.unsupportedNote ? `${confirmation.unsupportedNote} ${REFUSE_HINT}` : REFUSE_HINT
|
|
34948
|
+
};
|
|
34949
|
+
}
|
|
34950
|
+
return {
|
|
34951
|
+
...confirmation,
|
|
34952
|
+
tokenFallback: {
|
|
34953
|
+
key: confirmKeyFromEnv(env),
|
|
34954
|
+
tool,
|
|
34955
|
+
...account === void 0 ? {} : { account },
|
|
34956
|
+
...confirmToken === void 0 ? {} : { confirmToken },
|
|
34957
|
+
subject,
|
|
34958
|
+
ttlSeconds: confirmTtlFromEnv(env),
|
|
34959
|
+
instruction: mode === "auto" ? CONFIRM_TOKEN_AUTO_INSTRUCTION : instruction ?? CONFIRM_TOKEN_INSTRUCTION,
|
|
34960
|
+
...spent2 === void 0 ? {} : { spent: spent2 }
|
|
34961
|
+
}
|
|
34962
|
+
};
|
|
34963
|
+
}
|
|
34964
|
+
|
|
34703
34965
|
// ../../node_modules/@chrischall/mcp-utils/dist/server/index.js
|
|
34704
34966
|
var SERVER_PROTOCOL_VERSIONS = Object.freeze([
|
|
34705
34967
|
"2026-07-28",
|
|
@@ -34875,45 +35137,6 @@ function runMcp(opts) {
|
|
|
34875
35137
|
return handle;
|
|
34876
35138
|
}
|
|
34877
35139
|
|
|
34878
|
-
// ../../node_modules/@chrischall/mcp-utils/dist/config/index.js
|
|
34879
|
-
import { homedir } from "node:os";
|
|
34880
|
-
import { isAbsolute, join, resolve } from "node:path";
|
|
34881
|
-
var PLACEHOLDER_RE = /^\$\{[^}]*\}$/;
|
|
34882
|
-
function readEnvVar(key, opts = {}) {
|
|
34883
|
-
const env = opts.env ?? process.env;
|
|
34884
|
-
const raw = env[key];
|
|
34885
|
-
if (typeof raw === "string") {
|
|
34886
|
-
const trimmed = raw.trim();
|
|
34887
|
-
if (trimmed.length > 0 && trimmed !== "undefined" && trimmed !== "null" && !PLACEHOLDER_RE.test(trimmed)) {
|
|
34888
|
-
return trimmed;
|
|
34889
|
-
}
|
|
34890
|
-
}
|
|
34891
|
-
return opts.default;
|
|
34892
|
-
}
|
|
34893
|
-
var TRUE_TOKENS = /* @__PURE__ */ new Set(["1", "true", "yes", "on"]);
|
|
34894
|
-
var FALSE_TOKENS = /* @__PURE__ */ new Set(["0", "false", "no", "off"]);
|
|
34895
|
-
function parseBoolEnv(key, opts = {}) {
|
|
34896
|
-
const fallback = opts.default ?? false;
|
|
34897
|
-
const raw = readEnvVar(key, { env: opts.env });
|
|
34898
|
-
if (raw === void 0)
|
|
34899
|
-
return fallback;
|
|
34900
|
-
const token = raw.toLowerCase();
|
|
34901
|
-
if (TRUE_TOKENS.has(token))
|
|
34902
|
-
return true;
|
|
34903
|
-
if (FALSE_TOKENS.has(token))
|
|
34904
|
-
return false;
|
|
34905
|
-
return fallback;
|
|
34906
|
-
}
|
|
34907
|
-
function expandPath(p) {
|
|
34908
|
-
let expanded = p;
|
|
34909
|
-
if (p === "~") {
|
|
34910
|
-
expanded = homedir();
|
|
34911
|
-
} else if (p.startsWith("~/")) {
|
|
34912
|
-
expanded = join(homedir(), p.slice(2));
|
|
34913
|
-
}
|
|
34914
|
-
return isAbsolute(expanded) ? expanded : resolve(expanded);
|
|
34915
|
-
}
|
|
34916
|
-
|
|
34917
35140
|
// ../../node_modules/@chrischall/mcp-utils/dist/fs/confine.js
|
|
34918
35141
|
import { existsSync, realpathSync } from "node:fs";
|
|
34919
35142
|
import { dirname, isAbsolute as isAbsolute2, relative, resolve as resolve2, sep } from "node:path";
|
|
@@ -35705,6 +35928,7 @@ async function diagnose(err) {
|
|
|
35705
35928
|
const isAuthError = !isTransientError && AUTH_ERROR_PATTERN.test(errText);
|
|
35706
35929
|
const isGridLimitError = GRID_LIMIT_ERROR_PATTERN.test(errText);
|
|
35707
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}`);
|
|
35708
35932
|
try {
|
|
35709
35933
|
const accounts = formatAccountList(await run(["auth", "list"]));
|
|
35710
35934
|
return errorResult(`${errText}
|
|
@@ -35794,167 +36018,77 @@ function formatAuthHealth(raw, now) {
|
|
|
35794
36018
|
}
|
|
35795
36019
|
|
|
35796
36020
|
// ../gogcli-mcp/src/send-confirm-token.ts
|
|
35797
|
-
|
|
35798
|
-
|
|
35799
|
-
|
|
35800
|
-
var secret;
|
|
35801
|
-
var spent = /* @__PURE__ */ new Map();
|
|
35802
|
-
function sendConfirmFallbackEnabled() {
|
|
35803
|
-
return readEnvVar("GOG_SEND_CONFIRM_FALLBACK")?.trim().toLowerCase() === "token";
|
|
35804
|
-
}
|
|
35805
|
-
function confirmTokenTtlSeconds() {
|
|
35806
|
-
const raw = readEnvVar("GOG_CONFIRM_TTL_SECONDS")?.trim();
|
|
35807
|
-
if (raw && /^\d+$/.test(raw)) {
|
|
35808
|
-
const n = Number(raw);
|
|
35809
|
-
if (n > 0) return n;
|
|
35810
|
-
}
|
|
35811
|
-
return CONFIRM_TOKEN_TTL_DEFAULT_SECONDS;
|
|
35812
|
-
}
|
|
35813
|
-
function hmacKey() {
|
|
35814
|
-
if (!secret) {
|
|
35815
|
-
const configured = readEnvVar("GOG_CONFIRM_SECRET");
|
|
35816
|
-
secret = configured ? Buffer.from(configured, "utf8") : randomBytes(32);
|
|
35817
|
-
}
|
|
35818
|
-
return secret;
|
|
35819
|
-
}
|
|
35820
|
-
function canonicalize(value) {
|
|
35821
|
-
if (Array.isArray(value)) return value.map(canonicalize);
|
|
35822
|
-
if (value && typeof value === "object") {
|
|
35823
|
-
const out = {};
|
|
35824
|
-
for (const key of Object.keys(value).sort()) {
|
|
35825
|
-
const v = value[key];
|
|
35826
|
-
if (v !== void 0) out[key] = canonicalize(v);
|
|
35827
|
-
}
|
|
35828
|
-
return out;
|
|
35829
|
-
}
|
|
35830
|
-
return value;
|
|
35831
|
-
}
|
|
35832
|
-
function hashSendPayload(payload) {
|
|
35833
|
-
return createHash2("sha256").update(JSON.stringify(canonicalize(payload))).digest("hex");
|
|
35834
|
-
}
|
|
35835
|
-
function sign(body) {
|
|
35836
|
-
return createHmac2("sha256", hmacKey()).update(`${PREFIX}.${body}`).digest("base64url");
|
|
35837
|
-
}
|
|
35838
|
-
function issueConfirmToken(binding, now = Date.now()) {
|
|
35839
|
-
const exp = now + confirmTokenTtlSeconds() * 1e3;
|
|
35840
|
-
const claims = {
|
|
35841
|
-
t: binding.tool,
|
|
35842
|
-
a: binding.account,
|
|
35843
|
-
g: binding.target,
|
|
35844
|
-
...binding.revision === void 0 ? {} : { r: binding.revision },
|
|
35845
|
-
h: binding.payloadHash,
|
|
35846
|
-
iat: now,
|
|
35847
|
-
exp,
|
|
35848
|
-
n: randomBytes(16).toString("base64url")
|
|
35849
|
-
};
|
|
35850
|
-
const body = Buffer.from(JSON.stringify(claims), "utf8").toString("base64url");
|
|
35851
|
-
return { token: `${PREFIX}.${body}.${sign(body)}`, expiresAt: new Date(exp).toISOString() };
|
|
35852
|
-
}
|
|
35853
|
-
function signatureMatches(body, sig) {
|
|
35854
|
-
const expected = Buffer.from(sign(body), "utf8");
|
|
35855
|
-
const actual = Buffer.from(sig, "utf8");
|
|
35856
|
-
return expected.length === actual.length && timingSafeEqual2(expected, actual);
|
|
35857
|
-
}
|
|
35858
|
-
function parseClaims(body) {
|
|
35859
|
-
try {
|
|
35860
|
-
return JSON.parse(Buffer.from(body, "base64url").toString("utf8"));
|
|
35861
|
-
} catch {
|
|
35862
|
-
return void 0;
|
|
35863
|
-
}
|
|
35864
|
-
}
|
|
35865
|
-
function verifyConfirmToken(token, binding, now = Date.now()) {
|
|
35866
|
-
for (const [nonce, exp] of spent) if (exp < now) spent.delete(nonce);
|
|
35867
|
-
const parts = token.split(".");
|
|
35868
|
-
if (parts.length !== 3 || parts[0] !== PREFIX || !parts[1] || !parts[2]) return { ok: false, error: "TOKEN_INVALID" };
|
|
35869
|
-
const [, body, sig] = parts;
|
|
35870
|
-
if (!signatureMatches(body, sig)) return { ok: false, error: "TOKEN_INVALID" };
|
|
35871
|
-
const claims = parseClaims(body);
|
|
35872
|
-
if (!claims) return { ok: false, error: "TOKEN_INVALID" };
|
|
35873
|
-
if (claims.t !== binding.tool || claims.a !== binding.account || claims.g !== binding.target) {
|
|
35874
|
-
return { ok: false, error: "TOKEN_INVALID" };
|
|
35875
|
-
}
|
|
35876
|
-
if (spent.has(claims.n)) return { ok: false, error: "TOKEN_REUSED" };
|
|
35877
|
-
if (now > claims.exp) return { ok: false, error: "TOKEN_EXPIRED" };
|
|
35878
|
-
if (claims.r !== binding.revision) return { ok: false, error: "DRAFT_CHANGED", reason: "message-id-rotated" };
|
|
35879
|
-
if (claims.h !== binding.payloadHash) return { ok: false, error: "DRAFT_CHANGED", reason: "payload-changed" };
|
|
35880
|
-
spent.set(claims.n, claims.exp);
|
|
35881
|
-
return { ok: true };
|
|
36021
|
+
var spent = createSpentTokenStore();
|
|
36022
|
+
function confirmSpentStore() {
|
|
36023
|
+
return spent;
|
|
35882
36024
|
}
|
|
35883
36025
|
|
|
35884
36026
|
// ../gogcli-mcp/src/dispatch-confirmation.ts
|
|
35885
|
-
var
|
|
35886
|
-
|
|
35887
|
-
|
|
35888
|
-
|
|
35889
|
-
|
|
35890
|
-
);
|
|
35891
|
-
var TOKEN_ERROR_NOTE = {
|
|
35892
|
-
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.",
|
|
35893
|
-
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.",
|
|
35894
|
-
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."
|
|
35895
|
-
};
|
|
35896
|
-
var DRAFT_CHANGED_NOTE = {
|
|
35897
|
-
"message-id-rotated": "Nothing was sent or changed: the target was edited since the user approved it (a draft's messageId or an event's version rotated), so what would happen is not what they saw.",
|
|
35898
|
-
"payload-changed": "Nothing was sent or changed: what would happen no longer matches what the user approved."
|
|
35899
|
-
};
|
|
35900
|
-
function isToolResult(value) {
|
|
35901
|
-
return Array.isArray(value.content);
|
|
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]`;
|
|
35902
36032
|
}
|
|
35903
|
-
|
|
35904
|
-
|
|
35905
|
-
|
|
35906
|
-
|
|
35907
|
-
const subject = await fallback.subject();
|
|
35908
|
-
if (isToolResult(subject)) return subject;
|
|
35909
|
-
const binding = {
|
|
35910
|
-
tool: fallback.tool,
|
|
35911
|
-
account: fallback.account ?? readEnvVar("GOG_ACCOUNT") ?? "",
|
|
35912
|
-
target: subject.target,
|
|
35913
|
-
...subject.revision === void 0 ? {} : { revision: subject.revision },
|
|
35914
|
-
payloadHash: hashSendPayload(subject.payload)
|
|
35915
|
-
};
|
|
35916
|
-
const phaseOne = () => {
|
|
35917
|
-
const { token, expiresAt } = issueConfirmToken(binding);
|
|
35918
|
-
return {
|
|
35919
|
-
action: op,
|
|
35920
|
-
preview: subject.preview,
|
|
35921
|
-
confirmToken: token,
|
|
35922
|
-
expiresAt,
|
|
35923
|
-
ttlSeconds: confirmTokenTtlSeconds(),
|
|
35924
|
-
instruction: fallback.instruction ?? CONFIRM_ACTION_INSTRUCTION
|
|
35925
|
-
};
|
|
35926
|
-
};
|
|
35927
|
-
if (!fallback.confirmToken) {
|
|
35928
|
-
return textResult({ status: "confirmation-required", confirmed: false, dispatched: false, ...phaseOne() });
|
|
35929
|
-
}
|
|
35930
|
-
const verdict = verifyConfirmToken(fallback.confirmToken, binding);
|
|
35931
|
-
if (verdict.ok) return void 0;
|
|
35932
|
-
if (verdict.error === "DRAFT_CHANGED") {
|
|
35933
|
-
return rejection2({
|
|
35934
|
-
error: "DRAFT_CHANGED",
|
|
35935
|
-
reason: verdict.reason,
|
|
35936
|
-
note: `${DRAFT_CHANGED_NOTE[verdict.reason]} The current preview and a fresh confirmToken are below.`,
|
|
35937
|
-
...phaseOne()
|
|
35938
|
-
});
|
|
35939
|
-
}
|
|
35940
|
-
return rejection2({ error: verdict.error, action: op, note: TOKEN_ERROR_NOTE[verdict.error] });
|
|
36033
|
+
var CONFIRM_ACTION_INSTRUCTION = CONFIRM_TOKEN_INSTRUCTION;
|
|
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}`;
|
|
35941
36037
|
}
|
|
35942
36038
|
function gatedElsewhere(what, via, does, tool) {
|
|
35943
|
-
return
|
|
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;
|
|
35944
36072
|
}
|
|
35945
36073
|
async function requireDispatchConfirmation(ctx, options) {
|
|
35946
36074
|
const { action, fallback } = options;
|
|
35947
|
-
|
|
35948
|
-
return tokenConfirmation(action, fallback);
|
|
35949
|
-
}
|
|
35950
|
-
const note = fallback ? [options.unsupportedNote, FALLBACK_HINT].filter(Boolean).join(" ") : options.unsupportedNote;
|
|
35951
|
-
return requireConfirmation(ctx, {
|
|
36075
|
+
const confirmation = {
|
|
35952
36076
|
action,
|
|
35953
36077
|
message: options.message,
|
|
35954
36078
|
details: options.details,
|
|
35955
36079
|
confirmationLabel: options.confirmationLabel,
|
|
35956
|
-
...
|
|
35957
|
-
}
|
|
36080
|
+
...options.unsupportedNote ? { unsupportedNote: options.unsupportedNote } : {}
|
|
36081
|
+
};
|
|
36082
|
+
if (!fallback) return requireConfirmationWithFallback(ctx, confirmation);
|
|
36083
|
+
return requireConfirmationWithFallback(ctx, confirmationFromEnv({
|
|
36084
|
+
...confirmation,
|
|
36085
|
+
tool: fallback.tool,
|
|
36086
|
+
account: fallback.account ?? readEnvVar("GOG_ACCOUNT") ?? "",
|
|
36087
|
+
confirmToken: fallback.confirmToken,
|
|
36088
|
+
subject: fallback.subject,
|
|
36089
|
+
instruction: fallback.instruction ?? CONFIRM_ACTION_INSTRUCTION,
|
|
36090
|
+
spent: confirmSpentStore()
|
|
36091
|
+
}));
|
|
35958
36092
|
}
|
|
35959
36093
|
function resultText(result) {
|
|
35960
36094
|
const first = result.content[0];
|
|
@@ -36096,6 +36230,27 @@ function authToolsFor(defaultServices) {
|
|
|
36096
36230
|
}
|
|
36097
36231
|
|
|
36098
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
|
+
};
|
|
36099
36254
|
var reminderParams = {
|
|
36100
36255
|
reminders: external_exports.array(external_exports.string()).max(5).optional().describe(
|
|
36101
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.`
|
|
@@ -36161,8 +36316,25 @@ function inlineFileArg(flag, attachment, opts = {}) {
|
|
|
36161
36316
|
}
|
|
36162
36317
|
|
|
36163
36318
|
// ../gogcli-mcp/src/tools/drive.ts
|
|
36164
|
-
|
|
36165
|
-
|
|
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);
|
|
36166
36338
|
}
|
|
36167
36339
|
var GOOGLE_DOC_MIME = "application/vnd.google-apps.document";
|
|
36168
36340
|
function shareTargetMeta(raw) {
|
|
@@ -36173,6 +36345,26 @@ function shareTargetMeta(raw) {
|
|
|
36173
36345
|
return {};
|
|
36174
36346
|
}
|
|
36175
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
|
+
}
|
|
36176
36368
|
function fileMeta(raw) {
|
|
36177
36369
|
const parsed = JSON.parse(raw);
|
|
36178
36370
|
const f = parsed.file ?? parsed;
|
|
@@ -36281,16 +36473,36 @@ function registerDriveTools(server) {
|
|
|
36281
36473
|
return runOrDiagnose(["drive", "move", pos(fileId), `--parent=${parentId}`], { account });
|
|
36282
36474
|
});
|
|
36283
36475
|
server.registerTool("gog_drive_delete", {
|
|
36284
|
-
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,
|
|
36285
36477
|
annotations: { destructiveHint: true },
|
|
36286
36478
|
inputSchema: external_exports.object({
|
|
36287
36479
|
fileId: external_exports.string().describe("File ID to delete"),
|
|
36288
|
-
permanent: external_exports.boolean().optional().describe("Permanently delete instead of moving to trash (irreversible)"),
|
|
36289
|
-
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
|
|
36290
36483
|
})
|
|
36291
|
-
}, async ({ fileId, permanent, account }) => {
|
|
36484
|
+
}, async ({ fileId, permanent, account, confirmToken }, ctx) => {
|
|
36292
36485
|
const args = ["drive", "delete", pos(fileId)];
|
|
36293
|
-
if (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
|
+
}
|
|
36294
36506
|
args.push("--force");
|
|
36295
36507
|
return runOrDiagnose(args, { account });
|
|
36296
36508
|
});
|
|
@@ -36480,7 +36692,7 @@ var failIfNotEmptyParam = external_exports.boolean().optional().describe(
|
|
|
36480
36692
|
);
|
|
36481
36693
|
|
|
36482
36694
|
// ../gogcli-mcp/src/server.ts
|
|
36483
|
-
var VERSION = true ? "4.
|
|
36695
|
+
var VERSION = true ? "4.5.1" : "0.0.0";
|
|
36484
36696
|
|
|
36485
36697
|
// ../gogcli-mcp/src/bootstrap-auth.ts
|
|
36486
36698
|
import { join as join5 } from "node:path";
|
|
@@ -36517,12 +36729,12 @@ async function bootstrapGogAuth(env = process.env, options = {}) {
|
|
|
36517
36729
|
const [clientId, clientSecret, refreshToken, account] = values;
|
|
36518
36730
|
const { spawner } = options;
|
|
36519
36731
|
try {
|
|
36520
|
-
const { createHash:
|
|
36732
|
+
const { createHash: createHash4 } = await import("node:crypto");
|
|
36521
36733
|
const { mkdir, readFile, writeFile, chmod } = await import("node:fs/promises");
|
|
36522
36734
|
const home = options.home ?? (await import("node:os")).homedir();
|
|
36523
36735
|
const dir = join5(home, ".gogcli-mcp");
|
|
36524
36736
|
const marker = join5(dir, AUTH_BOOTSTRAP_MARKER);
|
|
36525
|
-
const fingerprint =
|
|
36737
|
+
const fingerprint = createHash4("sha256").update(values.join("\0")).digest("hex");
|
|
36526
36738
|
const previous = await readFile(marker, "utf8").catch(() => void 0);
|
|
36527
36739
|
if (previous === fingerprint && await accountListed(account, spawner)) return "present";
|
|
36528
36740
|
await run(
|
|
@@ -36744,14 +36956,37 @@ function registerExtraDriveTools(server) {
|
|
|
36744
36956
|
return runOrDiagnose(["drive", "comments", "get", pos(fileId), pos(commentId)], { account });
|
|
36745
36957
|
});
|
|
36746
36958
|
server.registerTool("gog_drive_comments_add", {
|
|
36747
|
-
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,
|
|
36748
36960
|
annotations: { destructiveHint: false },
|
|
36749
36961
|
inputSchema: external_exports.object({
|
|
36750
36962
|
fileId: external_exports.string().describe("File ID"),
|
|
36751
36963
|
content: external_exports.string().describe("Comment text"),
|
|
36752
|
-
account: accountParam
|
|
36964
|
+
account: accountParam,
|
|
36965
|
+
confirmToken: confirmTokenParam
|
|
36753
36966
|
})
|
|
36754
|
-
}, 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;
|
|
36755
36990
|
return runOrDiagnose(["drive", "comments", "create", pos(fileId), pos(content)], { account });
|
|
36756
36991
|
});
|
|
36757
36992
|
server.registerTool("gog_drive_comments_update", {
|
|
@@ -36778,18 +37013,44 @@ function registerExtraDriveTools(server) {
|
|
|
36778
37013
|
return runOrDiagnose(["drive", "comments", "delete", pos(fileId), pos(commentId), "--force"], { account });
|
|
36779
37014
|
});
|
|
36780
37015
|
server.registerTool("gog_drive_comments_reply", {
|
|
36781
|
-
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,
|
|
36782
37017
|
annotations: { destructiveHint: false },
|
|
36783
37018
|
inputSchema: external_exports.object({
|
|
36784
37019
|
fileId: external_exports.string().describe("File ID"),
|
|
36785
37020
|
commentId: external_exports.string().describe("Comment ID to reply to"),
|
|
36786
37021
|
content: external_exports.string().describe("Reply text"),
|
|
36787
37022
|
action: external_exports.enum(["resolve", "reopen"]).optional().describe("Optional action on the parent comment alongside the reply"),
|
|
36788
|
-
account: accountParam
|
|
37023
|
+
account: accountParam,
|
|
37024
|
+
confirmToken: confirmTokenParam
|
|
36789
37025
|
})
|
|
36790
|
-
}, async ({ fileId, commentId, content, action, account }) => {
|
|
37026
|
+
}, async ({ fileId, commentId, content, action, account, confirmToken }, ctx) => {
|
|
36791
37027
|
const args = ["drive", "comments", "reply", pos(fileId), pos(commentId), pos(content)];
|
|
36792
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;
|
|
36793
37054
|
return runOrDiagnose(args, { account });
|
|
36794
37055
|
});
|
|
36795
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.
|
|
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.
|
|
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>",
|
|
@@ -24,7 +24,7 @@
|
|
|
24
24
|
"test:coverage": "vitest run --coverage"
|
|
25
25
|
},
|
|
26
26
|
"dependencies": {
|
|
27
|
-
"@chrischall/mcp-utils": "^2.
|
|
27
|
+
"@chrischall/mcp-utils": "^2.6.0",
|
|
28
28
|
"@modelcontextprotocol/server": "^2.0.0",
|
|
29
29
|
"zod": "^4.6.1"
|
|
30
30
|
},
|
package/server.json
CHANGED
|
@@ -7,12 +7,12 @@
|
|
|
7
7
|
"source": "github",
|
|
8
8
|
"subfolder": "packages/gogcli-mcp-drive"
|
|
9
9
|
},
|
|
10
|
-
"version": "4.
|
|
10
|
+
"version": "4.5.1",
|
|
11
11
|
"packages": [
|
|
12
12
|
{
|
|
13
13
|
"registryType": "npm",
|
|
14
14
|
"identifier": "gogcli-mcp-drive",
|
|
15
|
-
"version": "4.
|
|
15
|
+
"version": "4.5.1",
|
|
16
16
|
"transport": {
|
|
17
17
|
"type": "stdio"
|
|
18
18
|
},
|
package/src/tools/drive-extra.ts
CHANGED
|
@@ -1,6 +1,25 @@
|
|
|
1
1
|
import { McpServer } from '@modelcontextprotocol/server';
|
|
2
2
|
import { z } from 'zod';
|
|
3
|
-
import {
|
|
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
|
-
|
|
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', () => {
|