gogcli-mcp 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/dist/lib.js +396 -47
- package/manifest.json +1 -1
- package/package.json +3 -3
- package/server.json +2 -2
- package/src/auth-log.ts +147 -0
- package/src/connector-runtime.ts +585 -80
- package/src/google-token.ts +391 -0
- package/src/remote-runner.ts +8 -1
- package/src/runner.ts +67 -2
- package/src/tools/auth.ts +6 -1
- package/src/tools/utils.ts +94 -7
- package/src/worker.ts +12 -1
- package/tests/auth-log.test.ts +508 -0
- package/tests/connector-runtime.test.ts +675 -2
- package/tests/google-token.test.ts +425 -0
- package/tests/runner.test.ts +21 -1
- package/tests/sdk-single-copy.test.ts +48 -0
- package/tests/tools/auth-401-context.test.ts +42 -0
- package/tests/tools/auth-401-shapes.test.ts +50 -0
- package/tests/tools/auth.test.ts +21 -0
- package/tests/tools/utils.test.ts +99 -2
package/dist/lib.js
CHANGED
|
@@ -4263,8 +4263,8 @@ var require_core = __commonJS({
|
|
|
4263
4263
|
return this;
|
|
4264
4264
|
}
|
|
4265
4265
|
case "object": {
|
|
4266
|
-
const
|
|
4267
|
-
this._cache.delete(
|
|
4266
|
+
const cacheKey2 = schemaKeyRef;
|
|
4267
|
+
this._cache.delete(cacheKey2);
|
|
4268
4268
|
let id = schemaKeyRef[this.opts.schemaId];
|
|
4269
4269
|
if (id) {
|
|
4270
4270
|
id = (0, resolve_1.normalizeId)(id);
|
|
@@ -22922,6 +22922,9 @@ var McpZodTypeKind;
|
|
|
22922
22922
|
McpZodTypeKind2["Completable"] = "McpCompletable";
|
|
22923
22923
|
})(McpZodTypeKind || (McpZodTypeKind = {}));
|
|
22924
22924
|
|
|
22925
|
+
// ../../node_modules/@modelcontextprotocol/sdk/dist/esm/shared/stdio.js
|
|
22926
|
+
var STDIO_DEFAULT_MAX_BUFFER_SIZE = 10 * 1024 * 1024;
|
|
22927
|
+
|
|
22925
22928
|
// ../../node_modules/@chrischall/mcp-utils/dist/errors/index.js
|
|
22926
22929
|
var BEARER_RE = /(bearer\s+)[A-Za-z0-9._~+/=-]{8,}/gi;
|
|
22927
22930
|
var JWT_RE = /\b[A-Za-z0-9_-]{10,}\.[A-Za-z0-9_-]{10,}\.[A-Za-z0-9_-]{8,}\b/g;
|
|
@@ -23015,6 +23018,21 @@ import { delimiter, join } from "node:path";
|
|
|
23015
23018
|
function isGogFileArg(arg) {
|
|
23016
23019
|
return typeof arg !== "string";
|
|
23017
23020
|
}
|
|
23021
|
+
var RUNNER_TRANSPORT_BRAND = /* @__PURE__ */ Symbol.for("gogcli.RunnerTransportError");
|
|
23022
|
+
var RunnerTransportError = class extends Error {
|
|
23023
|
+
kind;
|
|
23024
|
+
status;
|
|
23025
|
+
constructor(message, kind, status) {
|
|
23026
|
+
super(message);
|
|
23027
|
+
this.name = "RunnerTransportError";
|
|
23028
|
+
this.kind = kind;
|
|
23029
|
+
this.status = status;
|
|
23030
|
+
Object.defineProperty(this, RUNNER_TRANSPORT_BRAND, { value: true });
|
|
23031
|
+
}
|
|
23032
|
+
};
|
|
23033
|
+
function isRunnerTransportError(err) {
|
|
23034
|
+
return err instanceof Error && err[RUNNER_TRANSPORT_BRAND] === true;
|
|
23035
|
+
}
|
|
23018
23036
|
var runExecutor = new AsyncLocalStorage();
|
|
23019
23037
|
var defaultExecutor;
|
|
23020
23038
|
function setDefaultGogExecutor(executor) {
|
|
@@ -23024,7 +23042,7 @@ function activeExecutor() {
|
|
|
23024
23042
|
return runExecutor.getStore() ?? defaultExecutor;
|
|
23025
23043
|
}
|
|
23026
23044
|
var TIMEOUT_MS = 3e4;
|
|
23027
|
-
var MIN_GOG_VERSION = "0.
|
|
23045
|
+
var MIN_GOG_VERSION = "0.35.0";
|
|
23028
23046
|
function readonlyEnvEnabled() {
|
|
23029
23047
|
return readEnvVar("GOG_READONLY") !== void 0 && parseBoolEnv("GOG_READONLY", { default: true });
|
|
23030
23048
|
}
|
|
@@ -23196,7 +23214,11 @@ async function run(args, options = {}) {
|
|
|
23196
23214
|
}
|
|
23197
23215
|
return redact(output);
|
|
23198
23216
|
} catch (err) {
|
|
23199
|
-
|
|
23217
|
+
const message = redact(err instanceof Error ? err.message : String(err));
|
|
23218
|
+
if (isRunnerTransportError(err)) {
|
|
23219
|
+
throw new RunnerTransportError(message, err.kind, err.status);
|
|
23220
|
+
}
|
|
23221
|
+
throw new Error(message);
|
|
23200
23222
|
}
|
|
23201
23223
|
}
|
|
23202
23224
|
async function runBinary(args, options = {}) {
|
|
@@ -23470,7 +23492,9 @@ function registerRunTool(server, options) {
|
|
|
23470
23492
|
function errorText(err) {
|
|
23471
23493
|
return err instanceof Error ? `Error: ${err.message}` : String(err);
|
|
23472
23494
|
}
|
|
23473
|
-
var
|
|
23495
|
+
var DEFINITE_AUTH_PATTERN = /\b(?:unauthorized|invalid_grant)\b|\b(?:error|status|code|http|responded|response)["']?[\s:=(,]{0,4}401\b/i;
|
|
23496
|
+
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;
|
|
23497
|
+
var AUTH_ERROR_PATTERN = new RegExp(`${DEFINITE_AUTH_PATTERN.source}|${STALE_TOKEN_PATTERN.source}`, "i");
|
|
23474
23498
|
var INVALID_GRANT_PATTERN = /invalid_grant|token has been expired or revoked/i;
|
|
23475
23499
|
var TRANSIENT_ERROR_PATTERN = /\b429\b|\b5\d\d\b|\bquota\b|rateLimit|\bDEADLINE_EXCEEDED\b/i;
|
|
23476
23500
|
var GRID_LIMIT_ERROR_PATTERN = /exceeds grid limits/i;
|
|
@@ -23478,6 +23502,14 @@ var AUTH_HINT = "\n\nAuthentication may have expired. Use gog_auth_add to re-aut
|
|
|
23478
23502
|
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.';
|
|
23479
23503
|
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).";
|
|
23480
23504
|
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.";
|
|
23505
|
+
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.";
|
|
23506
|
+
var RUNNER_TRANSPORT_HINTS = {
|
|
23507
|
+
"transport-auth": RUNNER_TRANSPORT_AUTH_HINT,
|
|
23508
|
+
// The request itself was malformed, so the runner will refuse it identically
|
|
23509
|
+
// every time. Nothing to advise beyond the message the runner already gave.
|
|
23510
|
+
"transport-request": "",
|
|
23511
|
+
"transport-retryable": TRANSIENT_HINT
|
|
23512
|
+
};
|
|
23481
23513
|
function formatAccountList(raw) {
|
|
23482
23514
|
try {
|
|
23483
23515
|
const parsed = JSON.parse(raw);
|
|
@@ -23490,11 +23522,12 @@ function formatAccountList(raw) {
|
|
|
23490
23522
|
}
|
|
23491
23523
|
async function diagnose(err) {
|
|
23492
23524
|
const errText = errorText(err);
|
|
23525
|
+
const transportHint = isRunnerTransportError(err) ? RUNNER_TRANSPORT_HINTS[err.kind] : void 0;
|
|
23493
23526
|
const isInvalidGrant = INVALID_GRANT_PATTERN.test(errText);
|
|
23494
|
-
const
|
|
23495
|
-
const
|
|
23527
|
+
const isTransientError = !DEFINITE_AUTH_PATTERN.test(errText) && TRANSIENT_ERROR_PATTERN.test(errText);
|
|
23528
|
+
const isAuthError = !isTransientError && AUTH_ERROR_PATTERN.test(errText);
|
|
23496
23529
|
const isGridLimitError = GRID_LIMIT_ERROR_PATTERN.test(errText);
|
|
23497
|
-
const hint = isInvalidGrant ? INVALID_GRANT_HINT : isAuthError ? AUTH_HINT : isTransientError ? TRANSIENT_HINT : isGridLimitError ? GRID_LIMIT_HINT : "";
|
|
23530
|
+
const hint = transportHint ?? (isInvalidGrant ? INVALID_GRANT_HINT : isAuthError ? AUTH_HINT : isTransientError ? TRANSIENT_HINT : isGridLimitError ? GRID_LIMIT_HINT : "");
|
|
23498
23531
|
try {
|
|
23499
23532
|
const accounts = formatAccountList(await run(["auth", "list"]));
|
|
23500
23533
|
return errorResult(`${errText}
|
|
@@ -23613,7 +23646,7 @@ function registerApiTools(server) {
|
|
|
23613
23646
|
function registerAuthToolsWith(server, defaultServices) {
|
|
23614
23647
|
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.`;
|
|
23615
23648
|
server.registerTool("gog_auth_list", {
|
|
23616
|
-
description: "List
|
|
23649
|
+
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.",
|
|
23617
23650
|
annotations: { readOnlyHint: true },
|
|
23618
23651
|
inputSchema: {}
|
|
23619
23652
|
}, async () => {
|
|
@@ -24985,7 +25018,7 @@ function registerTasksTools(server) {
|
|
|
24985
25018
|
}
|
|
24986
25019
|
|
|
24987
25020
|
// src/server.ts
|
|
24988
|
-
var VERSION = true ? "2.
|
|
25021
|
+
var VERSION = true ? "2.21.1" : "0.0.0";
|
|
24989
25022
|
var BASE_TOOL_REGISTRARS = [
|
|
24990
25023
|
registerApiTools,
|
|
24991
25024
|
registerAuthTools,
|
|
@@ -25000,57 +25033,373 @@ var BASE_TOOL_REGISTRARS = [
|
|
|
25000
25033
|
registerTasksTools
|
|
25001
25034
|
];
|
|
25002
25035
|
|
|
25036
|
+
// src/auth-log.ts
|
|
25037
|
+
var FAILURES = /* @__PURE__ */ new Set([
|
|
25038
|
+
"token.mint-failed",
|
|
25039
|
+
"grant.dead",
|
|
25040
|
+
"replay.failed",
|
|
25041
|
+
"runner.auth-failed"
|
|
25042
|
+
]);
|
|
25043
|
+
var PREFIX = "gog-auth ";
|
|
25044
|
+
var TAG_CHARS = 12;
|
|
25045
|
+
function credentialTag(cacheKeyHash) {
|
|
25046
|
+
return cacheKeyHash.slice(0, TAG_CHARS);
|
|
25047
|
+
}
|
|
25048
|
+
function logAuthTransition(event, context) {
|
|
25049
|
+
const record2 = JSON.stringify({ at: (/* @__PURE__ */ new Date()).toISOString(), event, ...context });
|
|
25050
|
+
const write = FAILURES.has(event) ? console.error : console.warn;
|
|
25051
|
+
write(PREFIX + redactSecrets2(record2));
|
|
25052
|
+
}
|
|
25053
|
+
|
|
25054
|
+
// src/google-token.ts
|
|
25055
|
+
var TOKEN_ENDPOINT = "https://oauth2.googleapis.com/token";
|
|
25056
|
+
var EXPIRY_MARGIN_MS = 12e4;
|
|
25057
|
+
var cache = /* @__PURE__ */ new Map();
|
|
25058
|
+
var inFlight = /* @__PURE__ */ new Map();
|
|
25059
|
+
async function cacheKey(refreshToken, clientId) {
|
|
25060
|
+
const data = new TextEncoder().encode(`${clientId}\0${refreshToken}`);
|
|
25061
|
+
const digest = await crypto.subtle.digest("SHA-256", data);
|
|
25062
|
+
return Array.from(new Uint8Array(digest), (b) => b.toString(16).padStart(2, "0")).join("");
|
|
25063
|
+
}
|
|
25064
|
+
function makeAccessTokenSource(env) {
|
|
25065
|
+
const direct = readEnvVar("GOG_ACCESS_TOKEN", { env });
|
|
25066
|
+
if (direct) return async () => direct;
|
|
25067
|
+
const refreshToken = readEnvVar("GOG_REFRESH_TOKEN", { env });
|
|
25068
|
+
if (!refreshToken) return void 0;
|
|
25069
|
+
const clientId = readEnvVar("GOG_CLIENT_ID", { env });
|
|
25070
|
+
const clientSecret = readEnvVar("GOG_CLIENT_SECRET", { env });
|
|
25071
|
+
if (!clientId || !clientSecret) {
|
|
25072
|
+
const missing = [!clientId && "GOG_CLIENT_ID", !clientSecret && "GOG_CLIENT_SECRET"].filter(Boolean).join(" and ");
|
|
25073
|
+
return async () => {
|
|
25074
|
+
throw new Error(
|
|
25075
|
+
`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.`
|
|
25076
|
+
);
|
|
25077
|
+
};
|
|
25078
|
+
}
|
|
25079
|
+
let keyPromise;
|
|
25080
|
+
const key = () => keyPromise ??= cacheKey(refreshToken, clientId);
|
|
25081
|
+
const logCacheHits = parseBoolEnv("GOG_AUTH_LOG_CACHE_HITS", { env });
|
|
25082
|
+
const read = async () => {
|
|
25083
|
+
const k = await key();
|
|
25084
|
+
const hit = cache.get(k);
|
|
25085
|
+
if (hit && hit.expiresAt - EXPIRY_MARGIN_MS > Date.now()) {
|
|
25086
|
+
if (logCacheHits) logAuthTransition("token.cache-hit", { credential: credentialTag(k) });
|
|
25087
|
+
return hit.accessToken;
|
|
25088
|
+
}
|
|
25089
|
+
let pending = inFlight.get(k);
|
|
25090
|
+
if (!pending) {
|
|
25091
|
+
pending = exchange(refreshToken, clientId, clientSecret).then((minted2) => {
|
|
25092
|
+
cache.set(k, minted2);
|
|
25093
|
+
logAuthTransition("token.minted", {
|
|
25094
|
+
credential: credentialTag(k),
|
|
25095
|
+
reason: `valid for ${Math.round((minted2.expiresAt - Date.now()) / 1e3)}s`
|
|
25096
|
+
});
|
|
25097
|
+
return minted2;
|
|
25098
|
+
}).catch((err) => {
|
|
25099
|
+
logAuthTransition(err.grantDead ? "grant.dead" : "token.mint-failed", {
|
|
25100
|
+
credential: credentialTag(k),
|
|
25101
|
+
reason: err.message
|
|
25102
|
+
});
|
|
25103
|
+
throw err;
|
|
25104
|
+
}).finally(() => inFlight.delete(k));
|
|
25105
|
+
inFlight.set(k, pending);
|
|
25106
|
+
}
|
|
25107
|
+
const minted = await pending;
|
|
25108
|
+
return minted.accessToken;
|
|
25109
|
+
};
|
|
25110
|
+
const invalidate = async (rejected) => {
|
|
25111
|
+
const k = await key();
|
|
25112
|
+
const hit = cache.get(k);
|
|
25113
|
+
if (!hit || hit.accessToken !== rejected) {
|
|
25114
|
+
logAuthTransition("token.evict-noop", {
|
|
25115
|
+
credential: credentialTag(k),
|
|
25116
|
+
reason: hit ? "a concurrent caller had already replaced this credential\u2019s token" : "no token was cached for this credential"
|
|
25117
|
+
});
|
|
25118
|
+
return false;
|
|
25119
|
+
}
|
|
25120
|
+
cache.delete(k);
|
|
25121
|
+
logAuthTransition("token.evicted", {
|
|
25122
|
+
credential: credentialTag(k),
|
|
25123
|
+
reason: "Google rejected this access token; the next read will mint a new one"
|
|
25124
|
+
});
|
|
25125
|
+
return true;
|
|
25126
|
+
};
|
|
25127
|
+
return Object.assign(read, {
|
|
25128
|
+
invalidate,
|
|
25129
|
+
credentialId: async () => credentialTag(await key())
|
|
25130
|
+
});
|
|
25131
|
+
}
|
|
25132
|
+
var TokenExchangeError = class extends Error {
|
|
25133
|
+
/**
|
|
25134
|
+
* The REFRESH token is dead (Google's `invalid_grant`), not merely the access
|
|
25135
|
+
* token. Carried as a flag rather than re-read from the message, because
|
|
25136
|
+
* inferring the author of a failure from prose several authors can produce is
|
|
25137
|
+
* precisely the mistake this branch exists to undo. `instanceof` is safe: the
|
|
25138
|
+
* class is thrown and caught inside this one module.
|
|
25139
|
+
*/
|
|
25140
|
+
grantDead;
|
|
25141
|
+
constructor(message, grantDead) {
|
|
25142
|
+
super(message);
|
|
25143
|
+
this.grantDead = grantDead;
|
|
25144
|
+
}
|
|
25145
|
+
};
|
|
25146
|
+
async function exchange(refreshToken, clientId, clientSecret) {
|
|
25147
|
+
let res;
|
|
25148
|
+
try {
|
|
25149
|
+
res = await fetch(TOKEN_ENDPOINT, {
|
|
25150
|
+
method: "POST",
|
|
25151
|
+
headers: { "Content-Type": "application/x-www-form-urlencoded" },
|
|
25152
|
+
body: new URLSearchParams({
|
|
25153
|
+
grant_type: "refresh_token",
|
|
25154
|
+
refresh_token: refreshToken,
|
|
25155
|
+
client_id: clientId,
|
|
25156
|
+
client_secret: clientSecret
|
|
25157
|
+
}).toString()
|
|
25158
|
+
});
|
|
25159
|
+
} catch (err) {
|
|
25160
|
+
throw new TokenExchangeError(
|
|
25161
|
+
`the Google token exchange could not be reached: ${err instanceof Error ? err.message : String(err)}`,
|
|
25162
|
+
false
|
|
25163
|
+
);
|
|
25164
|
+
}
|
|
25165
|
+
const body = await res.json().catch(() => ({}));
|
|
25166
|
+
if (!res.ok) {
|
|
25167
|
+
if (body.error === "invalid_grant") {
|
|
25168
|
+
throw new TokenExchangeError(
|
|
25169
|
+
'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.',
|
|
25170
|
+
true
|
|
25171
|
+
);
|
|
25172
|
+
}
|
|
25173
|
+
throw new TokenExchangeError(
|
|
25174
|
+
`the access token could not be refreshed (HTTP ${res.status}${body.error ? `, ${body.error}` : ""})`,
|
|
25175
|
+
false
|
|
25176
|
+
);
|
|
25177
|
+
}
|
|
25178
|
+
if (!body.access_token) {
|
|
25179
|
+
throw new TokenExchangeError(
|
|
25180
|
+
"the access token could not be refreshed: Google returned no access_token",
|
|
25181
|
+
false
|
|
25182
|
+
);
|
|
25183
|
+
}
|
|
25184
|
+
const expiresInMs = (body.expires_in ?? 3600) * 1e3;
|
|
25185
|
+
return { accessToken: body.access_token, expiresAt: Date.now() + expiresInMs };
|
|
25186
|
+
}
|
|
25187
|
+
|
|
25003
25188
|
// src/connector-runtime.ts
|
|
25004
25189
|
var DEFAULT_TIMEOUT_MS = 3e4;
|
|
25005
25190
|
var DEADLINE_GRACE_MS = 5e3;
|
|
25191
|
+
var MIN_REPLAY_BUDGET_MS = 1e3;
|
|
25006
25192
|
var RUNNER_GOG_FAILED = 422;
|
|
25007
25193
|
var RUNNER_DRAINING = 503;
|
|
25194
|
+
var RUNNER_BAD_REQUEST = 400;
|
|
25195
|
+
var RUNNER_BAD_KEY = 401;
|
|
25196
|
+
var GogFailedError = class extends Error {
|
|
25197
|
+
/** gog's stderr alone, with no echoed argv mixed in. */
|
|
25198
|
+
stderr;
|
|
25199
|
+
constructor(message, stderr) {
|
|
25200
|
+
super(message);
|
|
25201
|
+
this.stderr = stderr;
|
|
25202
|
+
}
|
|
25203
|
+
};
|
|
25204
|
+
var GOOGLE_TOKEN_REJECTED_PATTERN = /Google API error \(401\b|invalid[ _]authentication[ _]credentials|\bACCESS_TOKEN_EXPIRED\b|\binvalid_token\b/i;
|
|
25205
|
+
var REFRESH_TOKEN_DEAD_PATTERN = /\binvalid_grant\b/i;
|
|
25206
|
+
var READ_ONLY_SUBCOMMANDS = /* @__PURE__ */ new Set([
|
|
25207
|
+
"cat",
|
|
25208
|
+
"describe",
|
|
25209
|
+
"get",
|
|
25210
|
+
"info",
|
|
25211
|
+
"list",
|
|
25212
|
+
"list-slides",
|
|
25213
|
+
"ls",
|
|
25214
|
+
"metadata",
|
|
25215
|
+
"read-slide",
|
|
25216
|
+
"search",
|
|
25217
|
+
"services",
|
|
25218
|
+
"status",
|
|
25219
|
+
"structure"
|
|
25220
|
+
]);
|
|
25221
|
+
function gogTarget(args) {
|
|
25222
|
+
const words = args.filter((arg) => typeof arg === "string");
|
|
25223
|
+
let service;
|
|
25224
|
+
for (let i = 0; i < words.length; i += 1) {
|
|
25225
|
+
const word = words[i];
|
|
25226
|
+
if (word.startsWith("-")) {
|
|
25227
|
+
if (word === "--account") i += 1;
|
|
25228
|
+
continue;
|
|
25229
|
+
}
|
|
25230
|
+
if (service === void 0) {
|
|
25231
|
+
service = word;
|
|
25232
|
+
continue;
|
|
25233
|
+
}
|
|
25234
|
+
return { service, subcommand: word };
|
|
25235
|
+
}
|
|
25236
|
+
return { service };
|
|
25237
|
+
}
|
|
25238
|
+
async function remintAfterGoogleRejection(err, used, args, readAccessToken, deadlineAt) {
|
|
25239
|
+
if (!(err instanceof GogFailedError)) return void 0;
|
|
25240
|
+
const grantDead = REFRESH_TOKEN_DEAD_PATTERN.test(err.stderr);
|
|
25241
|
+
if (!grantDead && !GOOGLE_TOKEN_REJECTED_PATTERN.test(err.stderr)) return void 0;
|
|
25242
|
+
const { service, subcommand } = gogTarget(args);
|
|
25243
|
+
const credential = await readAccessToken?.credentialId?.();
|
|
25244
|
+
const where = { credential, service };
|
|
25245
|
+
if (grantDead) {
|
|
25246
|
+
logAuthTransition("grant.dead", {
|
|
25247
|
+
...where,
|
|
25248
|
+
reason: "gog reported invalid_grant: the stored refresh token is dead, so no token can be minted and this account must be re-authorized"
|
|
25249
|
+
});
|
|
25250
|
+
return void 0;
|
|
25251
|
+
}
|
|
25252
|
+
if (!used) {
|
|
25253
|
+
logAuthTransition("replay.declined", {
|
|
25254
|
+
...where,
|
|
25255
|
+
reason: "no access token was supplied with the call, so gog acted as the backend volume\u2019s own identity"
|
|
25256
|
+
});
|
|
25257
|
+
return void 0;
|
|
25258
|
+
}
|
|
25259
|
+
if (!readAccessToken?.invalidate) {
|
|
25260
|
+
logAuthTransition("replay.declined", {
|
|
25261
|
+
...where,
|
|
25262
|
+
reason: "this token source cannot mint a replacement, so a replay would resend the rejected token"
|
|
25263
|
+
});
|
|
25264
|
+
return void 0;
|
|
25265
|
+
}
|
|
25266
|
+
const evicted = await readAccessToken.invalidate(used);
|
|
25267
|
+
if (subcommand === void 0 || !READ_ONLY_SUBCOMMANDS.has(subcommand)) {
|
|
25268
|
+
logAuthTransition("replay.declined", {
|
|
25269
|
+
...where,
|
|
25270
|
+
reason: `not replayable: '${subcommand ?? "(none)"}' is not a known read-only subcommand and a write could double-apply`
|
|
25271
|
+
});
|
|
25272
|
+
return void 0;
|
|
25273
|
+
}
|
|
25274
|
+
if (!evicted) {
|
|
25275
|
+
logAuthTransition("replay.declined", {
|
|
25276
|
+
...where,
|
|
25277
|
+
reason: "the rejected token was already superseded, so the cache holds the token a replay would send"
|
|
25278
|
+
});
|
|
25279
|
+
return void 0;
|
|
25280
|
+
}
|
|
25281
|
+
const fresh = await readAccessToken();
|
|
25282
|
+
if (!fresh) {
|
|
25283
|
+
logAuthTransition("replay.declined", {
|
|
25284
|
+
...where,
|
|
25285
|
+
reason: "the token source produced no token after eviction; replaying without one would act as the backend"
|
|
25286
|
+
});
|
|
25287
|
+
return void 0;
|
|
25288
|
+
}
|
|
25289
|
+
const budgetMs = deadlineAt - Date.now();
|
|
25290
|
+
if (budgetMs < MIN_REPLAY_BUDGET_MS) {
|
|
25291
|
+
logAuthTransition("replay.declined", {
|
|
25292
|
+
...where,
|
|
25293
|
+
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`
|
|
25294
|
+
});
|
|
25295
|
+
return void 0;
|
|
25296
|
+
}
|
|
25297
|
+
return { token: fresh, budgetMs, invalidate: readAccessToken.invalidate, ...where };
|
|
25298
|
+
}
|
|
25008
25299
|
function makeFlyExecutor(endpoint, key, readAccessToken) {
|
|
25009
25300
|
return async (args, opts) => {
|
|
25010
25301
|
const deadlineMs = (opts?.timeout ?? DEFAULT_TIMEOUT_MS) + DEADLINE_GRACE_MS;
|
|
25011
|
-
const accessToken = readAccessToken?.();
|
|
25012
|
-
|
|
25302
|
+
const accessToken = await readAccessToken?.();
|
|
25303
|
+
const deadlineAt = Date.now() + deadlineMs;
|
|
25013
25304
|
try {
|
|
25014
|
-
|
|
25015
|
-
method: "POST",
|
|
25016
|
-
headers: {
|
|
25017
|
-
Authorization: "Bearer " + key,
|
|
25018
|
-
"Content-Type": "application/json"
|
|
25019
|
-
},
|
|
25020
|
-
body: JSON.stringify(accessToken ? { args, accessToken } : { args }),
|
|
25021
|
-
signal: AbortSignal.timeout(deadlineMs)
|
|
25022
|
-
});
|
|
25305
|
+
return await attempt(endpoint, key, args, accessToken, deadlineMs);
|
|
25023
25306
|
} catch (err) {
|
|
25024
|
-
const
|
|
25025
|
-
|
|
25026
|
-
|
|
25027
|
-
|
|
25028
|
-
|
|
25307
|
+
const replay = await remintAfterGoogleRejection(
|
|
25308
|
+
err,
|
|
25309
|
+
accessToken,
|
|
25310
|
+
args,
|
|
25311
|
+
readAccessToken,
|
|
25312
|
+
deadlineAt
|
|
25313
|
+
);
|
|
25314
|
+
if (replay === void 0) throw err;
|
|
25315
|
+
const where = { credential: replay.credential, service: replay.service, endpoint };
|
|
25316
|
+
logAuthTransition("replay.attempted", {
|
|
25317
|
+
...where,
|
|
25318
|
+
reason: "Google rejected the access token; replaying this read once with a freshly minted one"
|
|
25319
|
+
});
|
|
25320
|
+
try {
|
|
25321
|
+
const stdout = await attempt(endpoint, key, args, replay.token, replay.budgetMs);
|
|
25322
|
+
logAuthTransition("replay.succeeded", where);
|
|
25323
|
+
return stdout;
|
|
25324
|
+
} catch (replayErr) {
|
|
25325
|
+
logAuthTransition("replay.failed", { ...where, reason: String(replayErr) });
|
|
25326
|
+
if (replayErr instanceof GogFailedError && GOOGLE_TOKEN_REJECTED_PATTERN.test(replayErr.stderr)) {
|
|
25327
|
+
await replay.invalidate(replay.token);
|
|
25328
|
+
}
|
|
25329
|
+
throw replayErr;
|
|
25029
25330
|
}
|
|
25030
|
-
throw err;
|
|
25031
25331
|
}
|
|
25032
|
-
|
|
25033
|
-
|
|
25034
|
-
|
|
25332
|
+
};
|
|
25333
|
+
}
|
|
25334
|
+
async function attempt(endpoint, key, args, accessToken, deadlineMs) {
|
|
25335
|
+
let res;
|
|
25336
|
+
try {
|
|
25337
|
+
res = await fetch(endpoint + "/run", {
|
|
25338
|
+
method: "POST",
|
|
25339
|
+
headers: {
|
|
25340
|
+
Authorization: "Bearer " + key,
|
|
25341
|
+
"Content-Type": "application/json"
|
|
25342
|
+
},
|
|
25343
|
+
body: JSON.stringify(accessToken ? { args, accessToken } : { args }),
|
|
25344
|
+
signal: AbortSignal.timeout(deadlineMs)
|
|
25345
|
+
});
|
|
25346
|
+
} catch (err) {
|
|
25347
|
+
const name = err instanceof Error ? err.name : "";
|
|
25348
|
+
if (name === "TimeoutError" || name === "AbortError") {
|
|
25349
|
+
throw new RunnerTransportError(
|
|
25350
|
+
`gog-runner did not respond within ${deadlineMs}ms (${endpoint}) \u2014 the Fly backend may be cold or wedged`,
|
|
25351
|
+
"transport-retryable"
|
|
25352
|
+
);
|
|
25353
|
+
}
|
|
25354
|
+
throw err;
|
|
25355
|
+
}
|
|
25356
|
+
if (!res.ok) {
|
|
25357
|
+
const body = await res.json().catch(() => null);
|
|
25358
|
+
const detail = body && typeof body.error === "string" ? body.stderr && body.stderr.trim() && body.stderr.trim() !== body.error.trim() ? `${body.error}
|
|
25035
25359
|
${body.stderr}` : body.error : "";
|
|
25036
|
-
|
|
25037
|
-
|
|
25038
|
-
|
|
25039
|
-
|
|
25040
|
-
throw new Error(
|
|
25041
|
-
`gog-runner is restarting; retry this call.${detail ? ` ${detail}` : ""}`
|
|
25042
|
-
);
|
|
25043
|
-
}
|
|
25044
|
-
if (detail) {
|
|
25045
|
-
throw new Error(detail);
|
|
25046
|
-
}
|
|
25047
|
-
throw new Error(
|
|
25048
|
-
`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.`
|
|
25360
|
+
if (res.status === RUNNER_GOG_FAILED) {
|
|
25361
|
+
throw new GogFailedError(
|
|
25362
|
+
detail || "gog failed on the runner (no detail supplied)",
|
|
25363
|
+
typeof body?.stderr === "string" ? body.stderr : ""
|
|
25049
25364
|
);
|
|
25050
25365
|
}
|
|
25051
|
-
|
|
25052
|
-
|
|
25053
|
-
|
|
25366
|
+
if (res.status === RUNNER_BAD_KEY) {
|
|
25367
|
+
logAuthTransition("runner.auth-failed", {
|
|
25368
|
+
service: gogTarget(args).service,
|
|
25369
|
+
endpoint,
|
|
25370
|
+
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"
|
|
25371
|
+
});
|
|
25372
|
+
throw new RunnerTransportError(
|
|
25373
|
+
"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.",
|
|
25374
|
+
"transport-auth",
|
|
25375
|
+
res.status
|
|
25376
|
+
);
|
|
25377
|
+
}
|
|
25378
|
+
if (res.status === RUNNER_BAD_REQUEST) {
|
|
25379
|
+
throw new RunnerTransportError(
|
|
25380
|
+
detail || "gog-runner rejected the request (no detail supplied)",
|
|
25381
|
+
"transport-request",
|
|
25382
|
+
res.status
|
|
25383
|
+
);
|
|
25384
|
+
}
|
|
25385
|
+
if (res.status === RUNNER_DRAINING || body?.retryable === true) {
|
|
25386
|
+
throw new RunnerTransportError(
|
|
25387
|
+
`gog-runner is restarting; retry this call.${detail ? ` ${detail}` : ""}`,
|
|
25388
|
+
"transport-retryable",
|
|
25389
|
+
res.status
|
|
25390
|
+
);
|
|
25391
|
+
}
|
|
25392
|
+
if (detail) {
|
|
25393
|
+
throw new Error(detail);
|
|
25394
|
+
}
|
|
25395
|
+
throw new RunnerTransportError(
|
|
25396
|
+
`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.`,
|
|
25397
|
+
"transport-retryable",
|
|
25398
|
+
res.status
|
|
25399
|
+
);
|
|
25400
|
+
}
|
|
25401
|
+
const { stdout } = await res.json();
|
|
25402
|
+
return stdout;
|
|
25054
25403
|
}
|
|
25055
25404
|
|
|
25056
25405
|
// src/remote-runner.ts
|
|
@@ -25059,7 +25408,7 @@ function useRemoteGogRunner(env = process.env) {
|
|
|
25059
25408
|
const key = readEnvVar("GOG_RUNNER_KEY", { env });
|
|
25060
25409
|
if (!endpoint || !key) return false;
|
|
25061
25410
|
setDefaultGogExecutor(
|
|
25062
|
-
makeFlyExecutor(endpoint.replace(/\/+$/, ""), key, (
|
|
25411
|
+
makeFlyExecutor(endpoint.replace(/\/+$/, ""), key, makeAccessTokenSource(env))
|
|
25063
25412
|
);
|
|
25064
25413
|
return true;
|
|
25065
25414
|
}
|
package/manifest.json
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
"manifest_version": "0.3",
|
|
4
4
|
"name": "gogcli-mcp",
|
|
5
5
|
"display_name": "gogcli",
|
|
6
|
-
"version": "2.
|
|
6
|
+
"version": "2.21.1",
|
|
7
7
|
"description": "Google Sheets (and more) for Claude via gogcli — read, write, and manage spreadsheets",
|
|
8
8
|
"author": {
|
|
9
9
|
"name": "Chris Hall",
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "gogcli-mcp",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.21.1",
|
|
4
4
|
"mcpName": "io.github.chrischall/gogcli-mcp",
|
|
5
5
|
"description": "MCP server wrapping gogcli for Google service access",
|
|
6
6
|
"author": "Claude Code (AI) <https://www.anthropic.com/claude>",
|
|
@@ -41,8 +41,8 @@
|
|
|
41
41
|
"test:coverage": "vitest run --coverage"
|
|
42
42
|
},
|
|
43
43
|
"dependencies": {
|
|
44
|
-
"@chrischall/mcp-utils": "^0.
|
|
45
|
-
"@modelcontextprotocol/sdk": "^1.
|
|
44
|
+
"@chrischall/mcp-utils": "^0.14.0",
|
|
45
|
+
"@modelcontextprotocol/sdk": "^1.30.0",
|
|
46
46
|
"zod": "^4.4.3"
|
|
47
47
|
},
|
|
48
48
|
"devDependencies": {
|
package/server.json
CHANGED
|
@@ -7,12 +7,12 @@
|
|
|
7
7
|
"source": "github",
|
|
8
8
|
"subfolder": "packages/gogcli-mcp"
|
|
9
9
|
},
|
|
10
|
-
"version": "2.
|
|
10
|
+
"version": "2.21.1",
|
|
11
11
|
"packages": [
|
|
12
12
|
{
|
|
13
13
|
"registryType": "npm",
|
|
14
14
|
"identifier": "gogcli-mcp",
|
|
15
|
-
"version": "2.
|
|
15
|
+
"version": "2.21.1",
|
|
16
16
|
"transport": {
|
|
17
17
|
"type": "stdio"
|
|
18
18
|
},
|