gogcli-mcp-docs 2.20.0 → 2.21.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 +434 -66
- package/manifest.json +1 -1
- package/package.json +3 -3
- package/server.json +2 -2
|
@@ -7,7 +7,7 @@
|
|
|
7
7
|
},
|
|
8
8
|
"metadata": {
|
|
9
9
|
"description": "Extended Google Docs for Claude via gogcli — auth + full Docs and comments support",
|
|
10
|
-
"version": "2.
|
|
10
|
+
"version": "2.21.1"
|
|
11
11
|
},
|
|
12
12
|
"plugins": [
|
|
13
13
|
{
|
|
@@ -15,7 +15,7 @@
|
|
|
15
15
|
"displayName": "gogcli (Docs)",
|
|
16
16
|
"source": "./",
|
|
17
17
|
"description": "Extended Google Docs for Claude via gogcli — auth + full Docs and comments support",
|
|
18
|
-
"version": "2.
|
|
18
|
+
"version": "2.21.1",
|
|
19
19
|
"author": {
|
|
20
20
|
"name": "Chris Hall"
|
|
21
21
|
},
|
package/dist/index.js
CHANGED
|
@@ -4264,8 +4264,8 @@ var require_core = __commonJS({
|
|
|
4264
4264
|
return this;
|
|
4265
4265
|
}
|
|
4266
4266
|
case "object": {
|
|
4267
|
-
const
|
|
4268
|
-
this._cache.delete(
|
|
4267
|
+
const cacheKey2 = schemaKeyRef;
|
|
4268
|
+
this._cache.delete(cacheKey2);
|
|
4269
4269
|
let id = schemaKeyRef[this.opts.schemaId];
|
|
4270
4270
|
if (id) {
|
|
4271
4271
|
id = (0, resolve_1.normalizeId)(id);
|
|
@@ -23068,17 +23068,33 @@ function normalizeObjectSchema(schema) {
|
|
|
23068
23068
|
}
|
|
23069
23069
|
return void 0;
|
|
23070
23070
|
}
|
|
23071
|
+
function getDotPath(path) {
|
|
23072
|
+
if (path.length === 0) {
|
|
23073
|
+
return "object root";
|
|
23074
|
+
}
|
|
23075
|
+
return path.reduce((acc, seg, index) => {
|
|
23076
|
+
if (index === 0) {
|
|
23077
|
+
return String(seg);
|
|
23078
|
+
}
|
|
23079
|
+
if (typeof seg === "number") {
|
|
23080
|
+
return `${acc}[${seg}]`;
|
|
23081
|
+
}
|
|
23082
|
+
return `${acc}.${seg}`;
|
|
23083
|
+
}, "");
|
|
23084
|
+
}
|
|
23071
23085
|
function getParseErrorMessage(error51) {
|
|
23072
23086
|
if (error51 && typeof error51 === "object") {
|
|
23087
|
+
if ("issues" in error51 && Array.isArray(error51.issues) && error51.issues.length > 0) {
|
|
23088
|
+
return error51.issues.map((i) => {
|
|
23089
|
+
if (!i.path?.length) {
|
|
23090
|
+
return i.message;
|
|
23091
|
+
}
|
|
23092
|
+
return `${i.message} at ${getDotPath(i.path)}`;
|
|
23093
|
+
}).join("\n");
|
|
23094
|
+
}
|
|
23073
23095
|
if ("message" in error51 && typeof error51.message === "string") {
|
|
23074
23096
|
return error51.message;
|
|
23075
23097
|
}
|
|
23076
|
-
if ("issues" in error51 && Array.isArray(error51.issues) && error51.issues.length > 0) {
|
|
23077
|
-
const firstIssue = error51.issues[0];
|
|
23078
|
-
if (firstIssue && typeof firstIssue === "object" && "message" in firstIssue) {
|
|
23079
|
-
return String(firstIssue.message);
|
|
23080
|
-
}
|
|
23081
|
-
}
|
|
23082
23098
|
try {
|
|
23083
23099
|
return JSON.stringify(error51);
|
|
23084
23100
|
} catch {
|
|
@@ -29693,16 +29709,7 @@ var Server = class extends Protocol {
|
|
|
29693
29709
|
if (!methodSchema) {
|
|
29694
29710
|
throw new Error("Schema is missing a method literal");
|
|
29695
29711
|
}
|
|
29696
|
-
|
|
29697
|
-
if (isZ4Schema(methodSchema)) {
|
|
29698
|
-
const v4Schema = methodSchema;
|
|
29699
|
-
const v4Def = v4Schema._zod?.def;
|
|
29700
|
-
methodValue = v4Def?.value ?? v4Schema.value;
|
|
29701
|
-
} else {
|
|
29702
|
-
const v3Schema = methodSchema;
|
|
29703
|
-
const legacyDef = v3Schema._def;
|
|
29704
|
-
methodValue = legacyDef?.value ?? v3Schema.value;
|
|
29705
|
-
}
|
|
29712
|
+
const methodValue = getLiteralValue(methodSchema);
|
|
29706
29713
|
if (typeof methodValue !== "string") {
|
|
29707
29714
|
throw new Error("Schema method literal must be a string");
|
|
29708
29715
|
}
|
|
@@ -30890,8 +30897,17 @@ var EMPTY_COMPLETION_RESULT = {
|
|
|
30890
30897
|
import process3 from "node:process";
|
|
30891
30898
|
|
|
30892
30899
|
// ../../node_modules/@modelcontextprotocol/sdk/dist/esm/shared/stdio.js
|
|
30900
|
+
var STDIO_DEFAULT_MAX_BUFFER_SIZE = 10 * 1024 * 1024;
|
|
30893
30901
|
var ReadBuffer = class {
|
|
30902
|
+
constructor(options) {
|
|
30903
|
+
this._maxBufferSize = options?.maxBufferSize ?? STDIO_DEFAULT_MAX_BUFFER_SIZE;
|
|
30904
|
+
}
|
|
30894
30905
|
append(chunk) {
|
|
30906
|
+
const newSize = (this._buffer?.length ?? 0) + chunk.length;
|
|
30907
|
+
if (newSize > this._maxBufferSize) {
|
|
30908
|
+
this.clear();
|
|
30909
|
+
throw new Error(`ReadBuffer exceeded maximum size of ${this._maxBufferSize} bytes`);
|
|
30910
|
+
}
|
|
30895
30911
|
this._buffer = this._buffer ? Buffer.concat([this._buffer, chunk]) : chunk;
|
|
30896
30912
|
}
|
|
30897
30913
|
readMessage() {
|
|
@@ -30919,18 +30935,24 @@ function serializeMessage(message) {
|
|
|
30919
30935
|
|
|
30920
30936
|
// ../../node_modules/@modelcontextprotocol/sdk/dist/esm/server/stdio.js
|
|
30921
30937
|
var StdioServerTransport = class {
|
|
30922
|
-
constructor(_stdin = process3.stdin, _stdout = process3.stdout) {
|
|
30938
|
+
constructor(_stdin = process3.stdin, _stdout = process3.stdout, options) {
|
|
30923
30939
|
this._stdin = _stdin;
|
|
30924
30940
|
this._stdout = _stdout;
|
|
30925
|
-
this._readBuffer = new ReadBuffer();
|
|
30926
30941
|
this._started = false;
|
|
30927
30942
|
this._ondata = (chunk) => {
|
|
30928
|
-
|
|
30929
|
-
|
|
30943
|
+
try {
|
|
30944
|
+
this._readBuffer.append(chunk);
|
|
30945
|
+
this.processReadBuffer();
|
|
30946
|
+
} catch (error51) {
|
|
30947
|
+
this.onerror?.(error51);
|
|
30948
|
+
this.close().catch(() => {
|
|
30949
|
+
});
|
|
30950
|
+
}
|
|
30930
30951
|
};
|
|
30931
30952
|
this._onerror = (error51) => {
|
|
30932
30953
|
this.onerror?.(error51);
|
|
30933
30954
|
};
|
|
30955
|
+
this._readBuffer = new ReadBuffer({ maxBufferSize: options?.maxBufferSize });
|
|
30934
30956
|
}
|
|
30935
30957
|
/**
|
|
30936
30958
|
* Starts listening for messages on stdin.
|
|
@@ -31118,6 +31140,21 @@ import { delimiter, join } from "node:path";
|
|
|
31118
31140
|
function isGogFileArg(arg) {
|
|
31119
31141
|
return typeof arg !== "string";
|
|
31120
31142
|
}
|
|
31143
|
+
var RUNNER_TRANSPORT_BRAND = /* @__PURE__ */ Symbol.for("gogcli.RunnerTransportError");
|
|
31144
|
+
var RunnerTransportError = class extends Error {
|
|
31145
|
+
kind;
|
|
31146
|
+
status;
|
|
31147
|
+
constructor(message, kind, status) {
|
|
31148
|
+
super(message);
|
|
31149
|
+
this.name = "RunnerTransportError";
|
|
31150
|
+
this.kind = kind;
|
|
31151
|
+
this.status = status;
|
|
31152
|
+
Object.defineProperty(this, RUNNER_TRANSPORT_BRAND, { value: true });
|
|
31153
|
+
}
|
|
31154
|
+
};
|
|
31155
|
+
function isRunnerTransportError(err) {
|
|
31156
|
+
return err instanceof Error && err[RUNNER_TRANSPORT_BRAND] === true;
|
|
31157
|
+
}
|
|
31121
31158
|
var runExecutor = new AsyncLocalStorage();
|
|
31122
31159
|
var defaultExecutor;
|
|
31123
31160
|
function setDefaultGogExecutor(executor) {
|
|
@@ -31298,7 +31335,11 @@ async function run(args, options = {}) {
|
|
|
31298
31335
|
}
|
|
31299
31336
|
return redact(output);
|
|
31300
31337
|
} catch (err) {
|
|
31301
|
-
|
|
31338
|
+
const message = redact(err instanceof Error ? err.message : String(err));
|
|
31339
|
+
if (isRunnerTransportError(err)) {
|
|
31340
|
+
throw new RunnerTransportError(message, err.kind, err.status);
|
|
31341
|
+
}
|
|
31342
|
+
throw new Error(message);
|
|
31302
31343
|
}
|
|
31303
31344
|
}
|
|
31304
31345
|
|
|
@@ -31562,7 +31603,9 @@ function registerRunTool(server, options) {
|
|
|
31562
31603
|
function errorText(err) {
|
|
31563
31604
|
return err instanceof Error ? `Error: ${err.message}` : String(err);
|
|
31564
31605
|
}
|
|
31565
|
-
var
|
|
31606
|
+
var DEFINITE_AUTH_PATTERN = /\b(?:unauthorized|invalid_grant)\b|\b(?:error|status|code|http|responded|response)["']?[\s:=(,]{0,4}401\b/i;
|
|
31607
|
+
var STALE_TOKEN_PATTERN = /\b(?:access[ _-]?)?token\b[^.;\n]{0,40}\b(?:has\s+)?(?:been\s+)?(?:expired|revoked)\b|\b(?:expired|revoked)\s+(?:access[ _-]?)?token\b/i;
|
|
31608
|
+
var AUTH_ERROR_PATTERN = new RegExp(`${DEFINITE_AUTH_PATTERN.source}|${STALE_TOKEN_PATTERN.source}`, "i");
|
|
31566
31609
|
var INVALID_GRANT_PATTERN = /invalid_grant|token has been expired or revoked/i;
|
|
31567
31610
|
var TRANSIENT_ERROR_PATTERN = /\b429\b|\b5\d\d\b|\bquota\b|rateLimit|\bDEADLINE_EXCEEDED\b/i;
|
|
31568
31611
|
var GRID_LIMIT_ERROR_PATTERN = /exceeds grid limits/i;
|
|
@@ -31570,6 +31613,14 @@ var AUTH_HINT = "\n\nAuthentication may have expired. Use gog_auth_add to re-aut
|
|
|
31570
31613
|
var INVALID_GRANT_HINT = '\n\nThe stored refresh token was rejected (invalid_grant): it has expired or been revoked, so the whole account is signed out and re-authorization is required. The most common cause is the 7-day refresh-token limit Google applies to OAuth apps whose consent screen is still in "Testing" mode. Re-authorize with gog_auth_add (opens a browser) or gog_auth_add_url + gog_auth_add_complete (remote/headless). To stop this recurring, publish the OAuth consent screen to "In production" in the Google Cloud project that owns the OAuth client. Ask the user if they would like to re-authenticate.';
|
|
31571
31614
|
var TRANSIENT_HINT = "\n\nThis error is often transient. Retry the same call before trying a different approach (do not fall back to smaller writes or row-by-row operations).";
|
|
31572
31615
|
var GRID_LIMIT_HINT = "\n\nThe target range is outside the sheet's current grid. Add the missing rows or columns first with gog_sheets_insert (dimension: rows or cols), then retry the write.";
|
|
31616
|
+
var RUNNER_TRANSPORT_AUTH_HINT = "\n\nThis is the CONNECTOR's own transport auth failing, not your Google sign-in. The gog-runner backend rejected the bearer token this server sent, so the request never reached gog and no Google credential was checked \u2014 the Google account is not the problem and re-authorizing it cannot fix this. An operator must make the Worker secret GOG_RUNNER_KEY equal RUNNER_KEY on the Fly app (wrangler secret put GOG_RUNNER_KEY / fly secrets set RUNNER_KEY), then retry.";
|
|
31617
|
+
var RUNNER_TRANSPORT_HINTS = {
|
|
31618
|
+
"transport-auth": RUNNER_TRANSPORT_AUTH_HINT,
|
|
31619
|
+
// The request itself was malformed, so the runner will refuse it identically
|
|
31620
|
+
// every time. Nothing to advise beyond the message the runner already gave.
|
|
31621
|
+
"transport-request": "",
|
|
31622
|
+
"transport-retryable": TRANSIENT_HINT
|
|
31623
|
+
};
|
|
31573
31624
|
function formatAccountList(raw) {
|
|
31574
31625
|
try {
|
|
31575
31626
|
const parsed = JSON.parse(raw);
|
|
@@ -31582,11 +31633,12 @@ function formatAccountList(raw) {
|
|
|
31582
31633
|
}
|
|
31583
31634
|
async function diagnose(err) {
|
|
31584
31635
|
const errText = errorText(err);
|
|
31636
|
+
const transportHint = isRunnerTransportError(err) ? RUNNER_TRANSPORT_HINTS[err.kind] : void 0;
|
|
31585
31637
|
const isInvalidGrant = INVALID_GRANT_PATTERN.test(errText);
|
|
31586
|
-
const
|
|
31587
|
-
const
|
|
31638
|
+
const isTransientError = !DEFINITE_AUTH_PATTERN.test(errText) && TRANSIENT_ERROR_PATTERN.test(errText);
|
|
31639
|
+
const isAuthError = !isTransientError && AUTH_ERROR_PATTERN.test(errText);
|
|
31588
31640
|
const isGridLimitError = GRID_LIMIT_ERROR_PATTERN.test(errText);
|
|
31589
|
-
const hint = isInvalidGrant ? INVALID_GRANT_HINT : isAuthError ? AUTH_HINT : isTransientError ? TRANSIENT_HINT : isGridLimitError ? GRID_LIMIT_HINT : "";
|
|
31641
|
+
const hint = transportHint ?? (isInvalidGrant ? INVALID_GRANT_HINT : isAuthError ? AUTH_HINT : isTransientError ? TRANSIENT_HINT : isGridLimitError ? GRID_LIMIT_HINT : "");
|
|
31590
31642
|
try {
|
|
31591
31643
|
const accounts = formatAccountList(await run(["auth", "list"]));
|
|
31592
31644
|
return errorResult(`${errText}
|
|
@@ -31651,7 +31703,7 @@ function formatAuthHealth(raw, now) {
|
|
|
31651
31703
|
function registerAuthToolsWith(server, defaultServices) {
|
|
31652
31704
|
const servicesDescribe = `Services to authorize: "all" or comma-separated list (e.g. "sheets,gmail,calendar"). Default: "${defaultServices}". Prefer the narrowest set you need \u2014 requesting a service whose Google API is not enabled on the OAuth client's project makes Google reject the WHOLE request with invalid_scope.`;
|
|
31653
31705
|
server.registerTool("gog_auth_list", {
|
|
31654
|
-
description: "List
|
|
31706
|
+
description: "List the Google accounts stored in gogcli, with their scopes. This reads local configuration only \u2014 it does not contact Google and does NOT tell you whether an account still works: a signed-out account whose refresh token expired or was revoked is listed here exactly like a healthy one, scopes and all. Use gog_auth_health to check whether an account can actually authenticate.",
|
|
31655
31707
|
annotations: { readOnlyHint: true },
|
|
31656
31708
|
inputSchema: {}
|
|
31657
31709
|
}, async () => {
|
|
@@ -31880,59 +31932,375 @@ var failIfNotEmptyParam = external_exports.boolean().optional().describe(
|
|
|
31880
31932
|
);
|
|
31881
31933
|
|
|
31882
31934
|
// ../gogcli-mcp/src/server.ts
|
|
31883
|
-
var VERSION = true ? "2.
|
|
31935
|
+
var VERSION = true ? "2.21.1" : "0.0.0";
|
|
31936
|
+
|
|
31937
|
+
// ../gogcli-mcp/src/auth-log.ts
|
|
31938
|
+
var FAILURES = /* @__PURE__ */ new Set([
|
|
31939
|
+
"token.mint-failed",
|
|
31940
|
+
"grant.dead",
|
|
31941
|
+
"replay.failed",
|
|
31942
|
+
"runner.auth-failed"
|
|
31943
|
+
]);
|
|
31944
|
+
var PREFIX = "gog-auth ";
|
|
31945
|
+
var TAG_CHARS = 12;
|
|
31946
|
+
function credentialTag(cacheKeyHash) {
|
|
31947
|
+
return cacheKeyHash.slice(0, TAG_CHARS);
|
|
31948
|
+
}
|
|
31949
|
+
function logAuthTransition(event, context) {
|
|
31950
|
+
const record2 = JSON.stringify({ at: (/* @__PURE__ */ new Date()).toISOString(), event, ...context });
|
|
31951
|
+
const write = FAILURES.has(event) ? console.error : console.warn;
|
|
31952
|
+
write(PREFIX + redactSecrets2(record2));
|
|
31953
|
+
}
|
|
31954
|
+
|
|
31955
|
+
// ../gogcli-mcp/src/google-token.ts
|
|
31956
|
+
var TOKEN_ENDPOINT = "https://oauth2.googleapis.com/token";
|
|
31957
|
+
var EXPIRY_MARGIN_MS = 12e4;
|
|
31958
|
+
var cache = /* @__PURE__ */ new Map();
|
|
31959
|
+
var inFlight = /* @__PURE__ */ new Map();
|
|
31960
|
+
async function cacheKey(refreshToken, clientId) {
|
|
31961
|
+
const data = new TextEncoder().encode(`${clientId}\0${refreshToken}`);
|
|
31962
|
+
const digest = await crypto.subtle.digest("SHA-256", data);
|
|
31963
|
+
return Array.from(new Uint8Array(digest), (b) => b.toString(16).padStart(2, "0")).join("");
|
|
31964
|
+
}
|
|
31965
|
+
function makeAccessTokenSource(env) {
|
|
31966
|
+
const direct = readEnvVar("GOG_ACCESS_TOKEN", { env });
|
|
31967
|
+
if (direct) return async () => direct;
|
|
31968
|
+
const refreshToken = readEnvVar("GOG_REFRESH_TOKEN", { env });
|
|
31969
|
+
if (!refreshToken) return void 0;
|
|
31970
|
+
const clientId = readEnvVar("GOG_CLIENT_ID", { env });
|
|
31971
|
+
const clientSecret = readEnvVar("GOG_CLIENT_SECRET", { env });
|
|
31972
|
+
if (!clientId || !clientSecret) {
|
|
31973
|
+
const missing = [!clientId && "GOG_CLIENT_ID", !clientSecret && "GOG_CLIENT_SECRET"].filter(Boolean).join(" and ");
|
|
31974
|
+
return async () => {
|
|
31975
|
+
throw new Error(
|
|
31976
|
+
`GOG_REFRESH_TOKEN is set but ${missing} is not, so no access token can be minted. Set the OAuth client alongside the refresh token, or unset GOG_REFRESH_TOKEN to use the backend\u2019s own identity.`
|
|
31977
|
+
);
|
|
31978
|
+
};
|
|
31979
|
+
}
|
|
31980
|
+
let keyPromise;
|
|
31981
|
+
const key = () => keyPromise ??= cacheKey(refreshToken, clientId);
|
|
31982
|
+
const logCacheHits = parseBoolEnv("GOG_AUTH_LOG_CACHE_HITS", { env });
|
|
31983
|
+
const read = async () => {
|
|
31984
|
+
const k = await key();
|
|
31985
|
+
const hit = cache.get(k);
|
|
31986
|
+
if (hit && hit.expiresAt - EXPIRY_MARGIN_MS > Date.now()) {
|
|
31987
|
+
if (logCacheHits) logAuthTransition("token.cache-hit", { credential: credentialTag(k) });
|
|
31988
|
+
return hit.accessToken;
|
|
31989
|
+
}
|
|
31990
|
+
let pending = inFlight.get(k);
|
|
31991
|
+
if (!pending) {
|
|
31992
|
+
pending = exchange(refreshToken, clientId, clientSecret).then((minted2) => {
|
|
31993
|
+
cache.set(k, minted2);
|
|
31994
|
+
logAuthTransition("token.minted", {
|
|
31995
|
+
credential: credentialTag(k),
|
|
31996
|
+
reason: `valid for ${Math.round((minted2.expiresAt - Date.now()) / 1e3)}s`
|
|
31997
|
+
});
|
|
31998
|
+
return minted2;
|
|
31999
|
+
}).catch((err) => {
|
|
32000
|
+
logAuthTransition(err.grantDead ? "grant.dead" : "token.mint-failed", {
|
|
32001
|
+
credential: credentialTag(k),
|
|
32002
|
+
reason: err.message
|
|
32003
|
+
});
|
|
32004
|
+
throw err;
|
|
32005
|
+
}).finally(() => inFlight.delete(k));
|
|
32006
|
+
inFlight.set(k, pending);
|
|
32007
|
+
}
|
|
32008
|
+
const minted = await pending;
|
|
32009
|
+
return minted.accessToken;
|
|
32010
|
+
};
|
|
32011
|
+
const invalidate = async (rejected) => {
|
|
32012
|
+
const k = await key();
|
|
32013
|
+
const hit = cache.get(k);
|
|
32014
|
+
if (!hit || hit.accessToken !== rejected) {
|
|
32015
|
+
logAuthTransition("token.evict-noop", {
|
|
32016
|
+
credential: credentialTag(k),
|
|
32017
|
+
reason: hit ? "a concurrent caller had already replaced this credential\u2019s token" : "no token was cached for this credential"
|
|
32018
|
+
});
|
|
32019
|
+
return false;
|
|
32020
|
+
}
|
|
32021
|
+
cache.delete(k);
|
|
32022
|
+
logAuthTransition("token.evicted", {
|
|
32023
|
+
credential: credentialTag(k),
|
|
32024
|
+
reason: "Google rejected this access token; the next read will mint a new one"
|
|
32025
|
+
});
|
|
32026
|
+
return true;
|
|
32027
|
+
};
|
|
32028
|
+
return Object.assign(read, {
|
|
32029
|
+
invalidate,
|
|
32030
|
+
credentialId: async () => credentialTag(await key())
|
|
32031
|
+
});
|
|
32032
|
+
}
|
|
32033
|
+
var TokenExchangeError = class extends Error {
|
|
32034
|
+
/**
|
|
32035
|
+
* The REFRESH token is dead (Google's `invalid_grant`), not merely the access
|
|
32036
|
+
* token. Carried as a flag rather than re-read from the message, because
|
|
32037
|
+
* inferring the author of a failure from prose several authors can produce is
|
|
32038
|
+
* precisely the mistake this branch exists to undo. `instanceof` is safe: the
|
|
32039
|
+
* class is thrown and caught inside this one module.
|
|
32040
|
+
*/
|
|
32041
|
+
grantDead;
|
|
32042
|
+
constructor(message, grantDead) {
|
|
32043
|
+
super(message);
|
|
32044
|
+
this.grantDead = grantDead;
|
|
32045
|
+
}
|
|
32046
|
+
};
|
|
32047
|
+
async function exchange(refreshToken, clientId, clientSecret) {
|
|
32048
|
+
let res;
|
|
32049
|
+
try {
|
|
32050
|
+
res = await fetch(TOKEN_ENDPOINT, {
|
|
32051
|
+
method: "POST",
|
|
32052
|
+
headers: { "Content-Type": "application/x-www-form-urlencoded" },
|
|
32053
|
+
body: new URLSearchParams({
|
|
32054
|
+
grant_type: "refresh_token",
|
|
32055
|
+
refresh_token: refreshToken,
|
|
32056
|
+
client_id: clientId,
|
|
32057
|
+
client_secret: clientSecret
|
|
32058
|
+
}).toString()
|
|
32059
|
+
});
|
|
32060
|
+
} catch (err) {
|
|
32061
|
+
throw new TokenExchangeError(
|
|
32062
|
+
`the Google token exchange could not be reached: ${err instanceof Error ? err.message : String(err)}`,
|
|
32063
|
+
false
|
|
32064
|
+
);
|
|
32065
|
+
}
|
|
32066
|
+
const body = await res.json().catch(() => ({}));
|
|
32067
|
+
if (!res.ok) {
|
|
32068
|
+
if (body.error === "invalid_grant") {
|
|
32069
|
+
throw new TokenExchangeError(
|
|
32070
|
+
'the stored refresh token was rejected (invalid_grant): it has expired or been revoked, so this account must be re-authorized (commonly the 7-day limit on OAuth consent screens still in "Testing" mode). Re-enrol with gog_auth_add_url + gog_auth_add_complete and store the new refresh token.',
|
|
32071
|
+
true
|
|
32072
|
+
);
|
|
32073
|
+
}
|
|
32074
|
+
throw new TokenExchangeError(
|
|
32075
|
+
`the access token could not be refreshed (HTTP ${res.status}${body.error ? `, ${body.error}` : ""})`,
|
|
32076
|
+
false
|
|
32077
|
+
);
|
|
32078
|
+
}
|
|
32079
|
+
if (!body.access_token) {
|
|
32080
|
+
throw new TokenExchangeError(
|
|
32081
|
+
"the access token could not be refreshed: Google returned no access_token",
|
|
32082
|
+
false
|
|
32083
|
+
);
|
|
32084
|
+
}
|
|
32085
|
+
const expiresInMs = (body.expires_in ?? 3600) * 1e3;
|
|
32086
|
+
return { accessToken: body.access_token, expiresAt: Date.now() + expiresInMs };
|
|
32087
|
+
}
|
|
31884
32088
|
|
|
31885
32089
|
// ../gogcli-mcp/src/connector-runtime.ts
|
|
31886
32090
|
var DEFAULT_TIMEOUT_MS = 3e4;
|
|
31887
32091
|
var DEADLINE_GRACE_MS = 5e3;
|
|
32092
|
+
var MIN_REPLAY_BUDGET_MS = 1e3;
|
|
31888
32093
|
var RUNNER_GOG_FAILED = 422;
|
|
31889
32094
|
var RUNNER_DRAINING = 503;
|
|
32095
|
+
var RUNNER_BAD_REQUEST = 400;
|
|
32096
|
+
var RUNNER_BAD_KEY = 401;
|
|
32097
|
+
var GogFailedError = class extends Error {
|
|
32098
|
+
/** gog's stderr alone, with no echoed argv mixed in. */
|
|
32099
|
+
stderr;
|
|
32100
|
+
constructor(message, stderr) {
|
|
32101
|
+
super(message);
|
|
32102
|
+
this.stderr = stderr;
|
|
32103
|
+
}
|
|
32104
|
+
};
|
|
32105
|
+
var GOOGLE_TOKEN_REJECTED_PATTERN = /Google API error \(401\b|invalid[ _]authentication[ _]credentials|\bACCESS_TOKEN_EXPIRED\b|\binvalid_token\b/i;
|
|
32106
|
+
var REFRESH_TOKEN_DEAD_PATTERN = /\binvalid_grant\b/i;
|
|
32107
|
+
var READ_ONLY_SUBCOMMANDS = /* @__PURE__ */ new Set([
|
|
32108
|
+
"cat",
|
|
32109
|
+
"describe",
|
|
32110
|
+
"get",
|
|
32111
|
+
"info",
|
|
32112
|
+
"list",
|
|
32113
|
+
"list-slides",
|
|
32114
|
+
"ls",
|
|
32115
|
+
"metadata",
|
|
32116
|
+
"read-slide",
|
|
32117
|
+
"search",
|
|
32118
|
+
"services",
|
|
32119
|
+
"status",
|
|
32120
|
+
"structure"
|
|
32121
|
+
]);
|
|
32122
|
+
function gogTarget(args) {
|
|
32123
|
+
const words = args.filter((arg) => typeof arg === "string");
|
|
32124
|
+
let service;
|
|
32125
|
+
for (let i = 0; i < words.length; i += 1) {
|
|
32126
|
+
const word = words[i];
|
|
32127
|
+
if (word.startsWith("-")) {
|
|
32128
|
+
if (word === "--account") i += 1;
|
|
32129
|
+
continue;
|
|
32130
|
+
}
|
|
32131
|
+
if (service === void 0) {
|
|
32132
|
+
service = word;
|
|
32133
|
+
continue;
|
|
32134
|
+
}
|
|
32135
|
+
return { service, subcommand: word };
|
|
32136
|
+
}
|
|
32137
|
+
return { service };
|
|
32138
|
+
}
|
|
32139
|
+
async function remintAfterGoogleRejection(err, used, args, readAccessToken, deadlineAt) {
|
|
32140
|
+
if (!(err instanceof GogFailedError)) return void 0;
|
|
32141
|
+
const grantDead = REFRESH_TOKEN_DEAD_PATTERN.test(err.stderr);
|
|
32142
|
+
if (!grantDead && !GOOGLE_TOKEN_REJECTED_PATTERN.test(err.stderr)) return void 0;
|
|
32143
|
+
const { service, subcommand } = gogTarget(args);
|
|
32144
|
+
const credential = await readAccessToken?.credentialId?.();
|
|
32145
|
+
const where = { credential, service };
|
|
32146
|
+
if (grantDead) {
|
|
32147
|
+
logAuthTransition("grant.dead", {
|
|
32148
|
+
...where,
|
|
32149
|
+
reason: "gog reported invalid_grant: the stored refresh token is dead, so no token can be minted and this account must be re-authorized"
|
|
32150
|
+
});
|
|
32151
|
+
return void 0;
|
|
32152
|
+
}
|
|
32153
|
+
if (!used) {
|
|
32154
|
+
logAuthTransition("replay.declined", {
|
|
32155
|
+
...where,
|
|
32156
|
+
reason: "no access token was supplied with the call, so gog acted as the backend volume\u2019s own identity"
|
|
32157
|
+
});
|
|
32158
|
+
return void 0;
|
|
32159
|
+
}
|
|
32160
|
+
if (!readAccessToken?.invalidate) {
|
|
32161
|
+
logAuthTransition("replay.declined", {
|
|
32162
|
+
...where,
|
|
32163
|
+
reason: "this token source cannot mint a replacement, so a replay would resend the rejected token"
|
|
32164
|
+
});
|
|
32165
|
+
return void 0;
|
|
32166
|
+
}
|
|
32167
|
+
const evicted = await readAccessToken.invalidate(used);
|
|
32168
|
+
if (subcommand === void 0 || !READ_ONLY_SUBCOMMANDS.has(subcommand)) {
|
|
32169
|
+
logAuthTransition("replay.declined", {
|
|
32170
|
+
...where,
|
|
32171
|
+
reason: `not replayable: '${subcommand ?? "(none)"}' is not a known read-only subcommand and a write could double-apply`
|
|
32172
|
+
});
|
|
32173
|
+
return void 0;
|
|
32174
|
+
}
|
|
32175
|
+
if (!evicted) {
|
|
32176
|
+
logAuthTransition("replay.declined", {
|
|
32177
|
+
...where,
|
|
32178
|
+
reason: "the rejected token was already superseded, so the cache holds the token a replay would send"
|
|
32179
|
+
});
|
|
32180
|
+
return void 0;
|
|
32181
|
+
}
|
|
32182
|
+
const fresh = await readAccessToken();
|
|
32183
|
+
if (!fresh) {
|
|
32184
|
+
logAuthTransition("replay.declined", {
|
|
32185
|
+
...where,
|
|
32186
|
+
reason: "the token source produced no token after eviction; replaying without one would act as the backend"
|
|
32187
|
+
});
|
|
32188
|
+
return void 0;
|
|
32189
|
+
}
|
|
32190
|
+
const budgetMs = deadlineAt - Date.now();
|
|
32191
|
+
if (budgetMs < MIN_REPLAY_BUDGET_MS) {
|
|
32192
|
+
logAuthTransition("replay.declined", {
|
|
32193
|
+
...where,
|
|
32194
|
+
reason: `only ${budgetMs}ms of the call\u2019s deadline remained, so a replay could only time out; the rejected token was evicted, so the next call mints a fresh one`
|
|
32195
|
+
});
|
|
32196
|
+
return void 0;
|
|
32197
|
+
}
|
|
32198
|
+
return { token: fresh, budgetMs, invalidate: readAccessToken.invalidate, ...where };
|
|
32199
|
+
}
|
|
31890
32200
|
function makeFlyExecutor(endpoint, key, readAccessToken) {
|
|
31891
32201
|
return async (args, opts) => {
|
|
31892
32202
|
const deadlineMs = (opts?.timeout ?? DEFAULT_TIMEOUT_MS) + DEADLINE_GRACE_MS;
|
|
31893
|
-
const accessToken = readAccessToken?.();
|
|
31894
|
-
|
|
32203
|
+
const accessToken = await readAccessToken?.();
|
|
32204
|
+
const deadlineAt = Date.now() + deadlineMs;
|
|
31895
32205
|
try {
|
|
31896
|
-
|
|
31897
|
-
method: "POST",
|
|
31898
|
-
headers: {
|
|
31899
|
-
Authorization: "Bearer " + key,
|
|
31900
|
-
"Content-Type": "application/json"
|
|
31901
|
-
},
|
|
31902
|
-
body: JSON.stringify(accessToken ? { args, accessToken } : { args }),
|
|
31903
|
-
signal: AbortSignal.timeout(deadlineMs)
|
|
31904
|
-
});
|
|
32206
|
+
return await attempt(endpoint, key, args, accessToken, deadlineMs);
|
|
31905
32207
|
} catch (err) {
|
|
31906
|
-
const
|
|
31907
|
-
|
|
31908
|
-
|
|
31909
|
-
|
|
31910
|
-
|
|
32208
|
+
const replay = await remintAfterGoogleRejection(
|
|
32209
|
+
err,
|
|
32210
|
+
accessToken,
|
|
32211
|
+
args,
|
|
32212
|
+
readAccessToken,
|
|
32213
|
+
deadlineAt
|
|
32214
|
+
);
|
|
32215
|
+
if (replay === void 0) throw err;
|
|
32216
|
+
const where = { credential: replay.credential, service: replay.service, endpoint };
|
|
32217
|
+
logAuthTransition("replay.attempted", {
|
|
32218
|
+
...where,
|
|
32219
|
+
reason: "Google rejected the access token; replaying this read once with a freshly minted one"
|
|
32220
|
+
});
|
|
32221
|
+
try {
|
|
32222
|
+
const stdout = await attempt(endpoint, key, args, replay.token, replay.budgetMs);
|
|
32223
|
+
logAuthTransition("replay.succeeded", where);
|
|
32224
|
+
return stdout;
|
|
32225
|
+
} catch (replayErr) {
|
|
32226
|
+
logAuthTransition("replay.failed", { ...where, reason: String(replayErr) });
|
|
32227
|
+
if (replayErr instanceof GogFailedError && GOOGLE_TOKEN_REJECTED_PATTERN.test(replayErr.stderr)) {
|
|
32228
|
+
await replay.invalidate(replay.token);
|
|
32229
|
+
}
|
|
32230
|
+
throw replayErr;
|
|
31911
32231
|
}
|
|
31912
|
-
throw err;
|
|
31913
32232
|
}
|
|
31914
|
-
|
|
31915
|
-
|
|
31916
|
-
|
|
32233
|
+
};
|
|
32234
|
+
}
|
|
32235
|
+
async function attempt(endpoint, key, args, accessToken, deadlineMs) {
|
|
32236
|
+
let res;
|
|
32237
|
+
try {
|
|
32238
|
+
res = await fetch(endpoint + "/run", {
|
|
32239
|
+
method: "POST",
|
|
32240
|
+
headers: {
|
|
32241
|
+
Authorization: "Bearer " + key,
|
|
32242
|
+
"Content-Type": "application/json"
|
|
32243
|
+
},
|
|
32244
|
+
body: JSON.stringify(accessToken ? { args, accessToken } : { args }),
|
|
32245
|
+
signal: AbortSignal.timeout(deadlineMs)
|
|
32246
|
+
});
|
|
32247
|
+
} catch (err) {
|
|
32248
|
+
const name = err instanceof Error ? err.name : "";
|
|
32249
|
+
if (name === "TimeoutError" || name === "AbortError") {
|
|
32250
|
+
throw new RunnerTransportError(
|
|
32251
|
+
`gog-runner did not respond within ${deadlineMs}ms (${endpoint}) \u2014 the Fly backend may be cold or wedged`,
|
|
32252
|
+
"transport-retryable"
|
|
32253
|
+
);
|
|
32254
|
+
}
|
|
32255
|
+
throw err;
|
|
32256
|
+
}
|
|
32257
|
+
if (!res.ok) {
|
|
32258
|
+
const body = await res.json().catch(() => null);
|
|
32259
|
+
const detail = body && typeof body.error === "string" ? body.stderr && body.stderr.trim() && body.stderr.trim() !== body.error.trim() ? `${body.error}
|
|
31917
32260
|
${body.stderr}` : body.error : "";
|
|
31918
|
-
|
|
31919
|
-
|
|
31920
|
-
|
|
31921
|
-
|
|
31922
|
-
throw new Error(
|
|
31923
|
-
`gog-runner is restarting; retry this call.${detail ? ` ${detail}` : ""}`
|
|
31924
|
-
);
|
|
31925
|
-
}
|
|
31926
|
-
if (detail) {
|
|
31927
|
-
throw new Error(detail);
|
|
31928
|
-
}
|
|
31929
|
-
throw new Error(
|
|
31930
|
-
`gog-runner HTTP ${res.status}: the response did not come from the runner, so the request never reached gog. The backend Machine was most likely starting or shutting down \u2014 this is transient, retry the same call.`
|
|
32261
|
+
if (res.status === RUNNER_GOG_FAILED) {
|
|
32262
|
+
throw new GogFailedError(
|
|
32263
|
+
detail || "gog failed on the runner (no detail supplied)",
|
|
32264
|
+
typeof body?.stderr === "string" ? body.stderr : ""
|
|
31931
32265
|
);
|
|
31932
32266
|
}
|
|
31933
|
-
|
|
31934
|
-
|
|
31935
|
-
|
|
32267
|
+
if (res.status === RUNNER_BAD_KEY) {
|
|
32268
|
+
logAuthTransition("runner.auth-failed", {
|
|
32269
|
+
service: gogTarget(args).service,
|
|
32270
|
+
endpoint,
|
|
32271
|
+
reason: "the gog-runner rejected the connector\u2019s bearer token, so gog never ran and no Google credential was read; GOG_RUNNER_KEY does not match the Fly app\u2019s RUNNER_KEY"
|
|
32272
|
+
});
|
|
32273
|
+
throw new RunnerTransportError(
|
|
32274
|
+
"gog-runner rejected the connector's bearer token, so the request never reached gog and no Google credential was involved. The Worker secret GOG_RUNNER_KEY no longer matches RUNNER_KEY on the Fly app; set them to the same value (wrangler secret put GOG_RUNNER_KEY / fly secrets set RUNNER_KEY) and retry.",
|
|
32275
|
+
"transport-auth",
|
|
32276
|
+
res.status
|
|
32277
|
+
);
|
|
32278
|
+
}
|
|
32279
|
+
if (res.status === RUNNER_BAD_REQUEST) {
|
|
32280
|
+
throw new RunnerTransportError(
|
|
32281
|
+
detail || "gog-runner rejected the request (no detail supplied)",
|
|
32282
|
+
"transport-request",
|
|
32283
|
+
res.status
|
|
32284
|
+
);
|
|
32285
|
+
}
|
|
32286
|
+
if (res.status === RUNNER_DRAINING || body?.retryable === true) {
|
|
32287
|
+
throw new RunnerTransportError(
|
|
32288
|
+
`gog-runner is restarting; retry this call.${detail ? ` ${detail}` : ""}`,
|
|
32289
|
+
"transport-retryable",
|
|
32290
|
+
res.status
|
|
32291
|
+
);
|
|
32292
|
+
}
|
|
32293
|
+
if (detail) {
|
|
32294
|
+
throw new Error(detail);
|
|
32295
|
+
}
|
|
32296
|
+
throw new RunnerTransportError(
|
|
32297
|
+
`gog-runner HTTP ${res.status}: the response did not come from the runner, so the request never reached gog. The backend Machine was most likely starting or shutting down \u2014 this is transient, retry the same call.`,
|
|
32298
|
+
"transport-retryable",
|
|
32299
|
+
res.status
|
|
32300
|
+
);
|
|
32301
|
+
}
|
|
32302
|
+
const { stdout } = await res.json();
|
|
32303
|
+
return stdout;
|
|
31936
32304
|
}
|
|
31937
32305
|
|
|
31938
32306
|
// ../gogcli-mcp/src/remote-runner.ts
|
|
@@ -31941,7 +32309,7 @@ function useRemoteGogRunner(env = process.env) {
|
|
|
31941
32309
|
const key = readEnvVar("GOG_RUNNER_KEY", { env });
|
|
31942
32310
|
if (!endpoint || !key) return false;
|
|
31943
32311
|
setDefaultGogExecutor(
|
|
31944
|
-
makeFlyExecutor(endpoint.replace(/\/+$/, ""), key, (
|
|
32312
|
+
makeFlyExecutor(endpoint.replace(/\/+$/, ""), key, makeAccessTokenSource(env))
|
|
31945
32313
|
);
|
|
31946
32314
|
return true;
|
|
31947
32315
|
}
|
package/manifest.json
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
"manifest_version": "0.3",
|
|
4
4
|
"name": "gogcli-mcp-docs",
|
|
5
5
|
"display_name": "gogcli (Docs)",
|
|
6
|
-
"version": "2.
|
|
6
|
+
"version": "2.21.1",
|
|
7
7
|
"description": "Extended Google Docs for Claude via gogcli — auth + full Docs and comments support",
|
|
8
8
|
"author": {
|
|
9
9
|
"name": "Chris Hall",
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "gogcli-mcp-docs",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.21.1",
|
|
4
4
|
"mcpName": "io.github.chrischall/gogcli-mcp-docs",
|
|
5
5
|
"description": "Extended Google Docs MCP server via gogcli — all base tools plus full Docs support",
|
|
6
6
|
"author": "Claude Code (AI) <https://www.anthropic.com/claude>",
|
|
@@ -24,8 +24,8 @@
|
|
|
24
24
|
"test:coverage": "vitest run --coverage"
|
|
25
25
|
},
|
|
26
26
|
"dependencies": {
|
|
27
|
-
"@chrischall/mcp-utils": "^0.
|
|
28
|
-
"@modelcontextprotocol/sdk": "^1.
|
|
27
|
+
"@chrischall/mcp-utils": "^0.14.0",
|
|
28
|
+
"@modelcontextprotocol/sdk": "^1.30.0",
|
|
29
29
|
"zod": "^4.4.3"
|
|
30
30
|
},
|
|
31
31
|
"license": "MIT",
|
package/server.json
CHANGED
|
@@ -7,12 +7,12 @@
|
|
|
7
7
|
"source": "github",
|
|
8
8
|
"subfolder": "packages/gogcli-mcp-docs"
|
|
9
9
|
},
|
|
10
|
-
"version": "2.
|
|
10
|
+
"version": "2.21.1",
|
|
11
11
|
"packages": [
|
|
12
12
|
{
|
|
13
13
|
"registryType": "npm",
|
|
14
14
|
"identifier": "gogcli-mcp-docs",
|
|
15
|
-
"version": "2.
|
|
15
|
+
"version": "2.21.1",
|
|
16
16
|
"transport": {
|
|
17
17
|
"type": "stdio"
|
|
18
18
|
},
|