gogcli-mcp 4.4.0 → 4.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.claude-plugin/marketplace.json +2 -2
- package/.claude-plugin/plugin.json +1 -1
- package/dist/index.js +292 -200
- package/dist/lib.js +258 -166
- package/manifest.json +1 -1
- package/package.json +2 -2
- package/server.json +2 -2
- package/src/dispatch-confirmation.ts +40 -113
- package/src/gmail-dispatch-guard.ts +9 -9
- package/src/send-confirm-token.ts +17 -155
- package/tests/gmail-dispatch-guard.test.ts +36 -17
- package/tests/send-confirm-token.test.ts +17 -197
- package/tests/tools/dispatch-gates.test.ts +22 -12
- package/tests/tools/gmail-confirm-token.test.ts +13 -11
|
@@ -7,7 +7,7 @@
|
|
|
7
7
|
},
|
|
8
8
|
"metadata": {
|
|
9
9
|
"description": "Google Sheets (and more) for Claude via gogcli — read, write, and manage spreadsheets",
|
|
10
|
-
"version": "4.
|
|
10
|
+
"version": "4.5.0"
|
|
11
11
|
},
|
|
12
12
|
"plugins": [
|
|
13
13
|
{
|
|
@@ -15,7 +15,7 @@
|
|
|
15
15
|
"displayName": "gogcli",
|
|
16
16
|
"source": "./",
|
|
17
17
|
"description": "Google Sheets (and more) for Claude via gogcli — read, write, and manage spreadsheets",
|
|
18
|
-
"version": "4.
|
|
18
|
+
"version": "4.5.0",
|
|
19
19
|
"author": {
|
|
20
20
|
"name": "Chris Hall"
|
|
21
21
|
},
|
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";
|
|
@@ -35844,95 +36067,13 @@ function assertNotBoth(inlineParam, fileParam, inlineValue, fileValue) {
|
|
|
35844
36067
|
}
|
|
35845
36068
|
|
|
35846
36069
|
// src/dispatch-confirmation.ts
|
|
35847
|
-
import { createHash as
|
|
36070
|
+
import { createHash as createHash4 } from "node:crypto";
|
|
35848
36071
|
import { readFileSync } from "node:fs";
|
|
35849
36072
|
|
|
35850
36073
|
// src/send-confirm-token.ts
|
|
35851
|
-
|
|
35852
|
-
|
|
35853
|
-
|
|
35854
|
-
var secret;
|
|
35855
|
-
var spent = /* @__PURE__ */ new Map();
|
|
35856
|
-
function sendConfirmFallbackEnabled() {
|
|
35857
|
-
return readEnvVar("GOG_SEND_CONFIRM_FALLBACK")?.trim().toLowerCase() === "token";
|
|
35858
|
-
}
|
|
35859
|
-
function confirmTokenTtlSeconds() {
|
|
35860
|
-
const raw = readEnvVar("GOG_CONFIRM_TTL_SECONDS")?.trim();
|
|
35861
|
-
if (raw && /^\d+$/.test(raw)) {
|
|
35862
|
-
const n = Number(raw);
|
|
35863
|
-
if (n > 0) return n;
|
|
35864
|
-
}
|
|
35865
|
-
return CONFIRM_TOKEN_TTL_DEFAULT_SECONDS;
|
|
35866
|
-
}
|
|
35867
|
-
function hmacKey() {
|
|
35868
|
-
if (!secret) {
|
|
35869
|
-
const configured = readEnvVar("GOG_CONFIRM_SECRET");
|
|
35870
|
-
secret = configured ? Buffer.from(configured, "utf8") : randomBytes(32);
|
|
35871
|
-
}
|
|
35872
|
-
return secret;
|
|
35873
|
-
}
|
|
35874
|
-
function canonicalize(value) {
|
|
35875
|
-
if (Array.isArray(value)) return value.map(canonicalize);
|
|
35876
|
-
if (value && typeof value === "object") {
|
|
35877
|
-
const out = {};
|
|
35878
|
-
for (const key of Object.keys(value).sort()) {
|
|
35879
|
-
const v = value[key];
|
|
35880
|
-
if (v !== void 0) out[key] = canonicalize(v);
|
|
35881
|
-
}
|
|
35882
|
-
return out;
|
|
35883
|
-
}
|
|
35884
|
-
return value;
|
|
35885
|
-
}
|
|
35886
|
-
function hashSendPayload(payload) {
|
|
35887
|
-
return createHash2("sha256").update(JSON.stringify(canonicalize(payload))).digest("hex");
|
|
35888
|
-
}
|
|
35889
|
-
function sign(body) {
|
|
35890
|
-
return createHmac2("sha256", hmacKey()).update(`${PREFIX}.${body}`).digest("base64url");
|
|
35891
|
-
}
|
|
35892
|
-
function issueConfirmToken(binding, now = Date.now()) {
|
|
35893
|
-
const exp = now + confirmTokenTtlSeconds() * 1e3;
|
|
35894
|
-
const claims = {
|
|
35895
|
-
t: binding.tool,
|
|
35896
|
-
a: binding.account,
|
|
35897
|
-
g: binding.target,
|
|
35898
|
-
...binding.revision === void 0 ? {} : { r: binding.revision },
|
|
35899
|
-
h: binding.payloadHash,
|
|
35900
|
-
iat: now,
|
|
35901
|
-
exp,
|
|
35902
|
-
n: randomBytes(16).toString("base64url")
|
|
35903
|
-
};
|
|
35904
|
-
const body = Buffer.from(JSON.stringify(claims), "utf8").toString("base64url");
|
|
35905
|
-
return { token: `${PREFIX}.${body}.${sign(body)}`, expiresAt: new Date(exp).toISOString() };
|
|
35906
|
-
}
|
|
35907
|
-
function signatureMatches(body, sig) {
|
|
35908
|
-
const expected = Buffer.from(sign(body), "utf8");
|
|
35909
|
-
const actual = Buffer.from(sig, "utf8");
|
|
35910
|
-
return expected.length === actual.length && timingSafeEqual2(expected, actual);
|
|
35911
|
-
}
|
|
35912
|
-
function parseClaims(body) {
|
|
35913
|
-
try {
|
|
35914
|
-
return JSON.parse(Buffer.from(body, "base64url").toString("utf8"));
|
|
35915
|
-
} catch {
|
|
35916
|
-
return void 0;
|
|
35917
|
-
}
|
|
35918
|
-
}
|
|
35919
|
-
function verifyConfirmToken(token, binding, now = Date.now()) {
|
|
35920
|
-
for (const [nonce, exp] of spent) if (exp < now) spent.delete(nonce);
|
|
35921
|
-
const parts = token.split(".");
|
|
35922
|
-
if (parts.length !== 3 || parts[0] !== PREFIX || !parts[1] || !parts[2]) return { ok: false, error: "TOKEN_INVALID" };
|
|
35923
|
-
const [, body, sig] = parts;
|
|
35924
|
-
if (!signatureMatches(body, sig)) return { ok: false, error: "TOKEN_INVALID" };
|
|
35925
|
-
const claims = parseClaims(body);
|
|
35926
|
-
if (!claims) return { ok: false, error: "TOKEN_INVALID" };
|
|
35927
|
-
if (claims.t !== binding.tool || claims.a !== binding.account || claims.g !== binding.target) {
|
|
35928
|
-
return { ok: false, error: "TOKEN_INVALID" };
|
|
35929
|
-
}
|
|
35930
|
-
if (spent.has(claims.n)) return { ok: false, error: "TOKEN_REUSED" };
|
|
35931
|
-
if (now > claims.exp) return { ok: false, error: "TOKEN_EXPIRED" };
|
|
35932
|
-
if (claims.r !== binding.revision) return { ok: false, error: "DRAFT_CHANGED", reason: "message-id-rotated" };
|
|
35933
|
-
if (claims.h !== binding.payloadHash) return { ok: false, error: "DRAFT_CHANGED", reason: "payload-changed" };
|
|
35934
|
-
spent.set(claims.n, claims.exp);
|
|
35935
|
-
return { ok: true };
|
|
36074
|
+
var spent = createSpentTokenStore();
|
|
36075
|
+
function confirmSpentStore() {
|
|
36076
|
+
return spent;
|
|
35936
36077
|
}
|
|
35937
36078
|
|
|
35938
36079
|
// src/dispatch-confirmation.ts
|
|
@@ -35954,13 +36095,13 @@ function attachmentDetails(paths, inline) {
|
|
|
35954
36095
|
} catch {
|
|
35955
36096
|
bytes = void 0;
|
|
35956
36097
|
}
|
|
35957
|
-
out.push(bytes ? { name: path, size: bytes.length, sha256:
|
|
36098
|
+
out.push(bytes ? { name: path, size: bytes.length, sha256: createHash4("sha256").update(bytes).digest("hex") } : { name: path, size: null });
|
|
35958
36099
|
}
|
|
35959
36100
|
for (const a of inline ?? []) {
|
|
35960
36101
|
out.push({
|
|
35961
36102
|
name: a.filename,
|
|
35962
36103
|
size: Buffer.from(a.contentBase64, "base64").length,
|
|
35963
|
-
sha256:
|
|
36104
|
+
sha256: createHash4("sha256").update(a.contentBase64).digest("hex")
|
|
35964
36105
|
});
|
|
35965
36106
|
}
|
|
35966
36107
|
return out;
|
|
@@ -35972,63 +36113,8 @@ function attachmentPreview(details) {
|
|
|
35972
36113
|
return details.map(({ name, size }) => ({ name, size }));
|
|
35973
36114
|
}
|
|
35974
36115
|
var CONFIRM_SEND_INSTRUCTION = "Show this preview to the user verbatim and send only after they explicitly approve in chat. Then call again with confirmToken.";
|
|
35975
|
-
var CONFIRM_ACTION_INSTRUCTION =
|
|
35976
|
-
var
|
|
35977
|
-
var CONFIRM_FALLBACK_DESCRIPTION = ' If the client cannot show that prompt (no MCP elicitation, e.g. claude.ai) and the server sets GOG_SEND_CONFIRM_FALLBACK=token, 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. Show that preview to the user verbatim; 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.';
|
|
35978
|
-
var confirmTokenParam = external_exports.string().optional().describe(
|
|
35979
|
-
`ONLY for the two-step fallback (client without MCP elicitation, server with GOG_SEND_CONFIRM_FALLBACK=token). 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.`
|
|
35980
|
-
);
|
|
35981
|
-
var TOKEN_ERROR_NOTE = {
|
|
35982
|
-
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.",
|
|
35983
|
-
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.",
|
|
35984
|
-
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."
|
|
35985
|
-
};
|
|
35986
|
-
var DRAFT_CHANGED_NOTE = {
|
|
35987
|
-
"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.",
|
|
35988
|
-
"payload-changed": "Nothing was sent or changed: what would happen no longer matches what the user approved."
|
|
35989
|
-
};
|
|
35990
|
-
function isToolResult(value) {
|
|
35991
|
-
return Array.isArray(value.content);
|
|
35992
|
-
}
|
|
35993
|
-
function rejection2(data) {
|
|
35994
|
-
return { ...textResult({ status: "confirmation-rejected", confirmed: false, dispatched: false, ...data }), isError: true };
|
|
35995
|
-
}
|
|
35996
|
-
async function tokenConfirmation(op, fallback) {
|
|
35997
|
-
const subject = await fallback.subject();
|
|
35998
|
-
if (isToolResult(subject)) return subject;
|
|
35999
|
-
const binding = {
|
|
36000
|
-
tool: fallback.tool,
|
|
36001
|
-
account: fallback.account ?? readEnvVar("GOG_ACCOUNT") ?? "",
|
|
36002
|
-
target: subject.target,
|
|
36003
|
-
...subject.revision === void 0 ? {} : { revision: subject.revision },
|
|
36004
|
-
payloadHash: hashSendPayload(subject.payload)
|
|
36005
|
-
};
|
|
36006
|
-
const phaseOne = () => {
|
|
36007
|
-
const { token, expiresAt } = issueConfirmToken(binding);
|
|
36008
|
-
return {
|
|
36009
|
-
action: op,
|
|
36010
|
-
preview: subject.preview,
|
|
36011
|
-
confirmToken: token,
|
|
36012
|
-
expiresAt,
|
|
36013
|
-
ttlSeconds: confirmTokenTtlSeconds(),
|
|
36014
|
-
instruction: fallback.instruction ?? CONFIRM_ACTION_INSTRUCTION
|
|
36015
|
-
};
|
|
36016
|
-
};
|
|
36017
|
-
if (!fallback.confirmToken) {
|
|
36018
|
-
return textResult({ status: "confirmation-required", confirmed: false, dispatched: false, ...phaseOne() });
|
|
36019
|
-
}
|
|
36020
|
-
const verdict = verifyConfirmToken(fallback.confirmToken, binding);
|
|
36021
|
-
if (verdict.ok) return void 0;
|
|
36022
|
-
if (verdict.error === "DRAFT_CHANGED") {
|
|
36023
|
-
return rejection2({
|
|
36024
|
-
error: "DRAFT_CHANGED",
|
|
36025
|
-
reason: verdict.reason,
|
|
36026
|
-
note: `${DRAFT_CHANGED_NOTE[verdict.reason]} The current preview and a fresh confirmToken are below.`,
|
|
36027
|
-
...phaseOne()
|
|
36028
|
-
});
|
|
36029
|
-
}
|
|
36030
|
-
return rejection2({ error: verdict.error, action: op, note: TOKEN_ERROR_NOTE[verdict.error] });
|
|
36031
|
-
}
|
|
36116
|
+
var CONFIRM_ACTION_INSTRUCTION = CONFIRM_TOKEN_INSTRUCTION;
|
|
36117
|
+
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.';
|
|
36032
36118
|
function gatedElsewhere(what, via, does, tool) {
|
|
36033
36119
|
return `${what} ${does} and is not available through ${via}. Use ${tool}, which asks the user to confirm.`;
|
|
36034
36120
|
}
|
|
@@ -36037,17 +36123,23 @@ function hasCommandWord(args, words) {
|
|
|
36037
36123
|
}
|
|
36038
36124
|
async function requireDispatchConfirmation(ctx, options) {
|
|
36039
36125
|
const { action, fallback } = options;
|
|
36040
|
-
|
|
36041
|
-
return tokenConfirmation(action, fallback);
|
|
36042
|
-
}
|
|
36043
|
-
const note = fallback ? [options.unsupportedNote, FALLBACK_HINT].filter(Boolean).join(" ") : options.unsupportedNote;
|
|
36044
|
-
return requireConfirmation(ctx, {
|
|
36126
|
+
const confirmation = {
|
|
36045
36127
|
action,
|
|
36046
36128
|
message: options.message,
|
|
36047
36129
|
details: options.details,
|
|
36048
36130
|
confirmationLabel: options.confirmationLabel,
|
|
36049
|
-
...
|
|
36050
|
-
}
|
|
36131
|
+
...options.unsupportedNote ? { unsupportedNote: options.unsupportedNote } : {}
|
|
36132
|
+
};
|
|
36133
|
+
if (!fallback) return requireConfirmationWithFallback(ctx, confirmation);
|
|
36134
|
+
return requireConfirmationWithFallback(ctx, confirmationFromEnv({
|
|
36135
|
+
...confirmation,
|
|
36136
|
+
tool: fallback.tool,
|
|
36137
|
+
account: fallback.account ?? readEnvVar("GOG_ACCOUNT") ?? "",
|
|
36138
|
+
confirmToken: fallback.confirmToken,
|
|
36139
|
+
subject: fallback.subject,
|
|
36140
|
+
instruction: fallback.instruction ?? CONFIRM_ACTION_INSTRUCTION,
|
|
36141
|
+
spent: confirmSpentStore()
|
|
36142
|
+
}));
|
|
36051
36143
|
}
|
|
36052
36144
|
function resultText(result) {
|
|
36053
36145
|
const first = result.content[0];
|
|
@@ -38762,7 +38854,7 @@ function registerTasksTools(server) {
|
|
|
38762
38854
|
}
|
|
38763
38855
|
|
|
38764
38856
|
// src/server.ts
|
|
38765
|
-
var VERSION = true ? "4.
|
|
38857
|
+
var VERSION = true ? "4.5.0" : "0.0.0";
|
|
38766
38858
|
var BASE_TOOL_REGISTRARS = [
|
|
38767
38859
|
registerApiTools,
|
|
38768
38860
|
registerAppScriptTools,
|
|
@@ -38814,12 +38906,12 @@ async function bootstrapGogAuth(env = process.env, options = {}) {
|
|
|
38814
38906
|
const [clientId, clientSecret, refreshToken, account] = values;
|
|
38815
38907
|
const { spawner } = options;
|
|
38816
38908
|
try {
|
|
38817
|
-
const { createHash:
|
|
38909
|
+
const { createHash: createHash5 } = await import("node:crypto");
|
|
38818
38910
|
const { mkdir, readFile, writeFile, chmod } = await import("node:fs/promises");
|
|
38819
38911
|
const home = options.home ?? (await import("node:os")).homedir();
|
|
38820
38912
|
const dir = join5(home, ".gogcli-mcp");
|
|
38821
38913
|
const marker = join5(dir, AUTH_BOOTSTRAP_MARKER);
|
|
38822
|
-
const fingerprint =
|
|
38914
|
+
const fingerprint = createHash5("sha256").update(values.join("\0")).digest("hex");
|
|
38823
38915
|
const previous = await readFile(marker, "utf8").catch(() => void 0);
|
|
38824
38916
|
if (previous === fingerprint && await accountListed(account, spawner)) return "present";
|
|
38825
38917
|
await run(
|