gogcli-mcp 2.24.0 → 2.26.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/dist/lib.js CHANGED
@@ -23042,7 +23042,7 @@ function activeExecutor() {
23042
23042
  return runExecutor.getStore() ?? defaultExecutor;
23043
23043
  }
23044
23044
  var TIMEOUT_MS = 3e4;
23045
- var MIN_GOG_VERSION = "0.37.0";
23045
+ var MIN_GOG_VERSION = "0.38.1";
23046
23046
  function readonlyEnvEnabled() {
23047
23047
  return readEnvVar("GOG_READONLY") !== void 0 && parseBoolEnv("GOG_READONLY", { default: true });
23048
23048
  }
@@ -23056,10 +23056,11 @@ function sanitizedEnv() {
23056
23056
  }
23057
23057
  return result;
23058
23058
  }
23059
+ var TOKEN_LEFT_BOUNDARY = "(?<![A-Za-z0-9+/])";
23059
23060
  var GOOGLE_TOKEN_PATTERNS = [
23060
- /ya29\.[A-Za-z0-9._\-]+/g,
23061
+ new RegExp(`${TOKEN_LEFT_BOUNDARY}ya29\\.[A-Za-z0-9._\\-]+`, "g"),
23061
23062
  // OAuth2 access tokens
23062
- /1\/\/[A-Za-z0-9._\-]+/g
23063
+ new RegExp(`${TOKEN_LEFT_BOUNDARY}1//[A-Za-z0-9._\\-]+`, "g")
23063
23064
  // OAuth2 refresh tokens
23064
23065
  ];
23065
23066
  function redactGoogleTokens(text) {
@@ -23072,6 +23073,26 @@ function redactGoogleTokens(text) {
23072
23073
  function redactSecrets2(text) {
23073
23074
  return redactGoogleTokens(redactSecrets(text));
23074
23075
  }
23076
+ var OPAQUE_FIELD_VALUE = "[A-Za-z0-9+/_-]{16,}={0,2}";
23077
+ var opaquePlaceholder = (i) => `\0gogOpaque${i}\0`;
23078
+ function redactPreservingOpaqueFields(text, fields, redact) {
23079
+ const lifted = [];
23080
+ let staged = text;
23081
+ for (const field of fields) {
23082
+ const escaped = field.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
23083
+ const re = new RegExp(`("${escaped}"\\s*:\\s*")(${OPAQUE_FIELD_VALUE})(")`, "g");
23084
+ staged = staged.replace(re, (_m, open, value, close) => {
23085
+ lifted.push(value);
23086
+ return `${open}${opaquePlaceholder(lifted.length - 1)}${close}`;
23087
+ });
23088
+ }
23089
+ if (lifted.length === 0) return redact(text);
23090
+ let redacted = redact(staged);
23091
+ lifted.forEach((value, i) => {
23092
+ redacted = redacted.split(opaquePlaceholder(i)).join(value);
23093
+ });
23094
+ return redacted;
23095
+ }
23075
23096
  function augmentedPath() {
23076
23097
  const home = process.env.HOME;
23077
23098
  const candidates = [
@@ -23102,19 +23123,24 @@ function formatTimeout(ms) {
23102
23123
  return `${ms}ms`;
23103
23124
  }
23104
23125
  async function spawnWithTempFiles(args, opts) {
23105
- const { mkdtemp, writeFile, rm } = await import("node:fs/promises");
23126
+ const { mkdtemp, mkdir, writeFile, rm } = await import("node:fs/promises");
23106
23127
  const { tmpdir } = await import("node:os");
23107
23128
  const dir = await mkdtemp(join(tmpdir(), "gogcli-mcp-"));
23108
23129
  try {
23109
23130
  const argv = [];
23131
+ let seq = 0;
23110
23132
  for (const arg of args) {
23111
23133
  if (!isGogFileArg(arg)) {
23112
23134
  argv.push(arg);
23113
23135
  continue;
23114
23136
  }
23115
- const path = join(dir, `${arg.flag}.${arg.ext ?? "txt"}`);
23116
- await writeFile(path, arg.contents, { encoding: "utf8", mode: 384 });
23117
- argv.push(`--${arg.flag}=${path}`);
23137
+ const sub = join(dir, String(seq));
23138
+ seq += 1;
23139
+ await mkdir(sub, { recursive: true, mode: 448 });
23140
+ const path = join(sub, arg.filename ?? `${arg.flag}.${arg.ext ?? "txt"}`);
23141
+ const data = arg.encoding === "base64" ? Buffer.from(arg.contents, "base64") : Buffer.from(arg.contents, "utf8");
23142
+ await writeFile(path, data, { mode: 384 });
23143
+ argv.push(arg.positional ? path : `--${arg.flag}=${path}`);
23118
23144
  }
23119
23145
  return await spawnGog(argv, opts);
23120
23146
  } finally {
@@ -23199,8 +23225,9 @@ function assembleArgs(args, opts) {
23199
23225
  return fullArgs;
23200
23226
  }
23201
23227
  async function run(args, options = {}) {
23202
- const { account, spawner, interactive = false, timeout, readonly: readonly2 = false, redactMode = "full" } = options;
23203
- const redact = redactMode === "tokens" ? redactGoogleTokens : redactSecrets2;
23228
+ const { account, spawner, interactive = false, timeout, readonly: readonly2 = false, redactMode = "full", opaqueFields } = options;
23229
+ const base = redactMode === "tokens" ? redactGoogleTokens : redactSecrets2;
23230
+ const redact = opaqueFields?.length ? (text) => redactPreservingOpaqueFields(text, opaqueFields, base) : base;
23204
23231
  const fullArgs = assembleArgs(args, { account, interactive, readonly: readonly2 });
23205
23232
  const store = activeExecutor();
23206
23233
  try {
@@ -23214,7 +23241,7 @@ async function run(args, options = {}) {
23214
23241
  }
23215
23242
  return redact(output);
23216
23243
  } catch (err) {
23217
- const message = redact(err instanceof Error ? err.message : String(err));
23244
+ const message = base(err instanceof Error ? err.message : String(err));
23218
23245
  if (isRunnerTransportError(err)) {
23219
23246
  throw new RunnerTransportError(message, err.kind, err.status);
23220
23247
  }
@@ -23709,6 +23736,117 @@ function registerApiTools(server) {
23709
23736
  });
23710
23737
  }
23711
23738
 
23739
+ // src/tools/appscript.ts
23740
+ function registerAppScriptTools(server) {
23741
+ const scriptIdParam = external_exports.string().describe(
23742
+ "Apps Script project ID \u2014 the long ID in script.google.com/\u2026/projects/<scriptId>/\u2026, NOT the Drive file ID of a container document"
23743
+ );
23744
+ const apiEnableNote = " Needs the Apps Script API enabled on the OAuth client's Google Cloud project; if it is not, gog says so and prints the console URL to enable it. That is a project setting, not a missing scope \u2014 re-authorizing will not fix it.";
23745
+ server.registerTool("gog_appscript_get", {
23746
+ description: "Get an Apps Script project's metadata: title, creator, create/update times, and the parent Drive file when the project is bound to a Sheet, Doc or Form. Use gog_appscript_content to read the actual code." + apiEnableNote,
23747
+ annotations: { readOnlyHint: true },
23748
+ inputSchema: {
23749
+ scriptId: scriptIdParam,
23750
+ account: accountParam
23751
+ }
23752
+ }, async ({ scriptId, account }) => {
23753
+ return runOrDiagnose(["appscript", "get", scriptId], { account });
23754
+ });
23755
+ server.registerTool("gog_appscript_content", {
23756
+ description: `Read a project's source \u2014 every .gs file and its appsscript.json manifest \u2014 INLINE in the response. This is the tool to reach for when the question is "what does this script do"; it needs no filesystem, so it works the same on a hosted deployment as it does locally, unlike gog_appscript_pull.` + apiEnableNote,
23757
+ annotations: { readOnlyHint: true },
23758
+ inputSchema: {
23759
+ scriptId: scriptIdParam,
23760
+ account: accountParam
23761
+ }
23762
+ }, async ({ scriptId, account }) => {
23763
+ return runOrDiagnose(["appscript", "content", scriptId], { account });
23764
+ });
23765
+ server.registerTool("gog_appscript_pull", {
23766
+ description: "Write a project's files into a local directory, for editing a script as ordinary files. THE DIRECTORY IS RESOLVED WHERE GOG RUNS, which is the caller's own machine only on a local (stdio) deployment: on the hosted connector, or any GOG_RUNNER_URL backend, the files land on that server where the caller cannot reach them. Use gog_appscript_content there instead \u2014 it returns the same source in the response. Existing files are left alone unless overwrite is set. Read-only as far as Google is concerned: nothing is pushed back." + apiEnableNote,
23767
+ inputSchema: {
23768
+ scriptId: scriptIdParam,
23769
+ dir: external_exports.string().describe("Destination directory, resolved on the machine where gog runs"),
23770
+ overwrite: external_exports.boolean().optional().describe("Overwrite files that already exist in dir"),
23771
+ account: accountParam
23772
+ }
23773
+ }, async ({ scriptId, dir, overwrite, account }) => {
23774
+ const args = ["appscript", "pull", scriptId, dir];
23775
+ if (overwrite) args.push("--overwrite");
23776
+ return runOrDiagnose(args, { account });
23777
+ });
23778
+ server.registerTool("gog_appscript_create", {
23779
+ description: "Create a new, empty Apps Script project. Pass parentId to bind it to a Drive file (a Sheet, Doc or Form), which is what makes the script a container-bound script with access to that document; omit it for a standalone project. gog cannot upload code, so the project starts empty either way." + apiEnableNote,
23780
+ inputSchema: {
23781
+ title: external_exports.string().describe("Project title"),
23782
+ parentId: external_exports.string().optional().describe("Drive file ID to bind the project to (Sheet, Doc or Form). Omit for a standalone project."),
23783
+ account: accountParam
23784
+ }
23785
+ }, async ({ title, parentId, account }) => {
23786
+ const args = ["appscript", "create", `--title=${title}`];
23787
+ if (parentId) args.push(`--parent-id=${parentId}`);
23788
+ return runOrDiagnose(args, { account });
23789
+ });
23790
+ server.registerTool("gog_appscript_deployments", {
23791
+ description: "List a project's deployments \u2014 the published web apps, add-ons and API executables, each pinned to a version. A deployment ID from here is what gog_appscript_run_function needs when a script is not running in dev mode." + apiEnableNote,
23792
+ annotations: { readOnlyHint: true },
23793
+ inputSchema: {
23794
+ scriptId: scriptIdParam,
23795
+ ...paginationParams,
23796
+ account: accountParam
23797
+ }
23798
+ }, async ({ scriptId, max, pageToken, page, all, account }) => {
23799
+ const args = ["appscript", "deployments", scriptId];
23800
+ pushPaginationFlags(args, { max, pageToken, page, all });
23801
+ return runOrDiagnose(args, { account });
23802
+ });
23803
+ server.registerTool("gog_appscript_versions", {
23804
+ description: `List a project's saved versions \u2014 the immutable snapshots deployments point at, with their numbers and descriptions. Useful for answering "what is actually deployed" next to gog_appscript_deployments.` + apiEnableNote,
23805
+ annotations: { readOnlyHint: true },
23806
+ inputSchema: {
23807
+ scriptId: scriptIdParam,
23808
+ ...paginationParams,
23809
+ account: accountParam
23810
+ }
23811
+ }, async ({ scriptId, max, pageToken, page, all, account }) => {
23812
+ const args = ["appscript", "versions", scriptId];
23813
+ pushPaginationFlags(args, { max, pageToken, page, all });
23814
+ return runOrDiagnose(args, { account });
23815
+ });
23816
+ server.registerTool("gog_appscript_run_function", {
23817
+ description: "Execute a function in a deployed Apps Script project. TREAT THIS AS ARBITRARY CODE EXECUTION: the script runs with this Google account's authority and can send mail, edit Drive files or call external services, and the wrapper cannot tell a read from a write \u2014 read the code with gog_appscript_content first if you did not write it. Requires the project to be deployed as an API executable and to share the OAuth client with the calling credentials, otherwise Google refuses regardless of scopes. devMode runs the latest saved code instead of the deployed version, and only works if the account owns the script. This is NOT the escape hatch \u2014 gog_appscript_run is that." + apiEnableNote,
23818
+ annotations: { destructiveHint: true },
23819
+ inputSchema: {
23820
+ scriptId: scriptIdParam,
23821
+ functionName: external_exports.string().describe('Name of the function to call, e.g. "doWork"'),
23822
+ params: external_exports.string().optional().describe(`Function parameters as a JSON ARRAY of positional arguments, e.g. '["a", 1]' \u2014 not an object`),
23823
+ devMode: external_exports.boolean().optional().describe("Run the latest saved code rather than the deployed version (owner only)"),
23824
+ account: accountParam
23825
+ }
23826
+ }, async ({ scriptId, functionName, params, devMode, account }) => {
23827
+ if (params !== void 0) {
23828
+ let parsed;
23829
+ try {
23830
+ parsed = JSON.parse(params);
23831
+ } catch {
23832
+ throw new Error(`params must be a JSON array of positional arguments, e.g. '["a", 1]'. Received: ${params}`);
23833
+ }
23834
+ if (!Array.isArray(parsed)) {
23835
+ throw new Error(`params must be a JSON ARRAY of positional arguments, e.g. '["a", 1]' \u2014 Apps Script takes positional arguments, not named ones. Received: ${params}`);
23836
+ }
23837
+ }
23838
+ const args = ["appscript", "run", scriptId, functionName];
23839
+ if (params !== void 0) args.push(`--params=${params}`);
23840
+ if (devMode) args.push("--dev-mode");
23841
+ return runOrDiagnose(args, { account });
23842
+ });
23843
+ registerRunTool(server, {
23844
+ service: "appscript",
23845
+ examples: '"get", "content", "deployments"',
23846
+ note: "To execute a function, use gog_appscript_run_function \u2014 this tool is the generic escape hatch."
23847
+ });
23848
+ }
23849
+
23712
23850
  // src/tools/auth.ts
23713
23851
  function registerAuthToolsWith(server, defaultServices) {
23714
23852
  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.`;
@@ -23844,6 +23982,29 @@ function authToolsFor(defaultServices) {
23844
23982
  }
23845
23983
 
23846
23984
  // src/tools/calendar.ts
23985
+ var reminderParams = {
23986
+ reminders: external_exports.array(external_exports.string()).max(5).optional().describe(
23987
+ `Reminders as method:duration, e.g. ["popup:30m", "email:1d"]. Method is popup or email; duration accepts m/h/d (max 40320 minutes = 4 weeks). Google allows at most 5. These REPLACE the event's reminders \u2014 on update, pass an EMPTY array to drop custom reminders and go back to the calendar's defaults. Cannot be combined with noReminders.`
23988
+ ),
23989
+ noReminders: external_exports.boolean().optional().describe(
23990
+ "Give the event no reminders at all, overriding the calendar's defaults. Different from an empty reminders array, which RESTORES those defaults. Cannot be combined with reminders."
23991
+ )
23992
+ };
23993
+ function pushReminderFlags(args, p) {
23994
+ if (p.noReminders) {
23995
+ if (p.reminders !== void 0) {
23996
+ throw new Error("reminders and noReminders are mutually exclusive: pass reminders to set custom ones, noReminders for none, or an empty reminders array to restore the calendar defaults.");
23997
+ }
23998
+ args.push("--no-reminders");
23999
+ return;
24000
+ }
24001
+ if (p.reminders === void 0) return;
24002
+ if (p.reminders.length === 0) {
24003
+ args.push("--reminder=");
24004
+ return;
24005
+ }
24006
+ for (const reminder of p.reminders) args.push(`--reminder=${reminder}`);
24007
+ }
23847
24008
  function registerCalendarTools(server) {
23848
24009
  server.registerTool("gog_calendar_events", {
23849
24010
  description: 'List calendar events. Describe the window ONE way and one way only (gog >= 0.36.0 rejects the rest as ambiguous rather than silently discarding a flag): today on its own; or from + to; or from + days; or days on its own (a window of that many days starting today). today cannot be combined with from, to or days, and days cannot be combined with to. gog returns only 10 events by default, so a wide date range is USUALLY INCOMPLETE: raise max, or page with pageToken until the response carries no nextPageToken. A response carrying "truncated": true is an incomplete view \u2014 never conclude an event does not exist from one.',
@@ -23913,9 +24074,10 @@ function registerCalendarTools(server) {
23913
24074
  allDay: external_exports.boolean().optional().describe("All-day event (use date-only in from/to)"),
23914
24075
  timezone: external_exports.string().optional().describe("IANA timezone metadata applied to from/to (e.g. America/New_York). Sets both start and end timezone unless start/end timezone are overridden."),
23915
24076
  withZoom: external_exports.boolean().optional().describe("Create a Zoom video conference for this event (requires Zoom S2S OAuth setup)"),
24077
+ ...reminderParams,
23916
24078
  account: accountParam
23917
24079
  }
23918
- }, async ({ calendarId, summary, from, to, description, location, attendees, allDay, timezone, withZoom, account }) => {
24080
+ }, async ({ calendarId, summary, from, to, description, location, attendees, allDay, timezone, withZoom, reminders, noReminders, account }) => {
23919
24081
  const args = ["calendar", "create", calendarId, `--summary=${summary}`, `--from=${from}`, `--to=${to}`];
23920
24082
  if (description) args.push(`--description=${description}`);
23921
24083
  if (location) args.push(`--location=${location}`);
@@ -23923,6 +24085,7 @@ function registerCalendarTools(server) {
23923
24085
  if (allDay) args.push("--all-day");
23924
24086
  if (timezone) args.push(`--timezone=${timezone}`);
23925
24087
  if (withZoom) args.push("--with-zoom");
24088
+ pushReminderFlags(args, { reminders, noReminders });
23926
24089
  return runOrDiagnose(args, { account });
23927
24090
  });
23928
24091
  server.registerTool("gog_calendar_update", {
@@ -23943,9 +24106,10 @@ function registerCalendarTools(server) {
23943
24106
  regenerateZoom: external_exports.boolean().optional().describe("Replace the event's existing Zoom video conference"),
23944
24107
  removeZoom: external_exports.boolean().optional().describe("Remove the event's Zoom video conference"),
23945
24108
  removeMeet: external_exports.boolean().optional().describe("Remove the event's Google Meet video conference (clears conference data only)"),
24109
+ ...reminderParams,
23946
24110
  account: accountParam
23947
24111
  }
23948
- }, async ({ calendarId, eventId, summary, from, to, description, location, attendees, addAttendees, attachments, withZoom, regenerateZoom, removeZoom, removeMeet, account }) => {
24112
+ }, async ({ calendarId, eventId, summary, from, to, description, location, attendees, addAttendees, attachments, withZoom, regenerateZoom, removeZoom, removeMeet, reminders, noReminders, account }) => {
23949
24113
  const args = ["calendar", "update", calendarId, eventId];
23950
24114
  if (summary !== void 0) args.push(`--summary=${summary}`);
23951
24115
  if (from !== void 0) args.push(`--from=${from}`);
@@ -23959,6 +24123,7 @@ function registerCalendarTools(server) {
23959
24123
  if (regenerateZoom) args.push("--regenerate-zoom");
23960
24124
  if (removeZoom) args.push("--remove-zoom");
23961
24125
  if (removeMeet) args.push("--remove-meet");
24126
+ pushReminderFlags(args, { reminders, noReminders });
23962
24127
  return runOrDiagnose(args, { account });
23963
24128
  });
23964
24129
  server.registerTool("gog_calendar_delete", {
@@ -23990,6 +24155,255 @@ function registerCalendarTools(server) {
23990
24155
  registerRunTool(server, { service: "calendar", examples: '"calendars", "freebusy"' });
23991
24156
  }
23992
24157
 
24158
+ // src/attachments.ts
24159
+ var MAX_INLINE_ATTACHMENT_BYTES = 8 * 1024 * 1024;
24160
+ var RUNNER_MAX_BODY_BYTES = 32 * 1024 * 1024;
24161
+ var RUNNER_BODY_JSON_RESERVE_BYTES = 256 * 1024;
24162
+ var MAX_REQUEST_PAYLOAD_WIRE_BYTES = RUNNER_MAX_BODY_BYTES - RUNNER_BODY_JSON_RESERVE_BYTES;
24163
+ var MAX_INLINE_ATTACHMENT_TOTAL_BYTES = Math.floor(MAX_REQUEST_PAYLOAD_WIRE_BYTES * 3 / 4);
24164
+ function wireBytesOf(arg) {
24165
+ if (typeof arg === "string") return Buffer.byteLength(arg, "utf8");
24166
+ return arg.encoding === "base64" ? arg.contents.length : Buffer.byteLength(arg.contents, "utf8");
24167
+ }
24168
+ var formatMiB = (bytes) => `${Math.floor(bytes / (1024 * 1024))} MiB`;
24169
+ var INLINE_ATTACHMENT_LIMITS_TEXT = `up to ${formatMiB(MAX_INLINE_ATTACHMENT_BYTES)} per file and ${formatMiB(MAX_INLINE_ATTACHMENT_TOTAL_BYTES)} in total`;
24170
+ var inlineAttachmentSchema = external_exports.object({
24171
+ filename: external_exports.string().min(1).describe(
24172
+ `Filename the recipient will see, e.g. "pendant-layouts.png". gog infers the attachment's MIME type from this extension, so give it the right one \u2014 a .png sent as "layouts" arrives as an untyped blob. Must be a single filename, not a path.`
24173
+ ),
24174
+ contentBase64: external_exports.string().min(1).describe(
24175
+ "The file's bytes, base64-encoded (standard alphabet, with padding). This is the whole point of this parameter: the bytes travel with the request, so nothing needs to exist on the gog server's filesystem."
24176
+ )
24177
+ });
24178
+ var attachInlineParam = external_exports.array(inlineAttachmentSchema).optional().describe(
24179
+ `Attachments supplied as BYTES rather than as server-side paths \u2014 use this whenever you hold a file and the gog server does not, which is always the case on the hosted connector and on any remote deployment. Each entry is {filename, contentBase64} (${INLINE_ATTACHMENT_LIMITS_TEXT}). Can be combined with \`attach\`: the two name disjoint files (paths read on the server vs. bytes sent with the call), and both end up as ordinary attachments on the message.`
24180
+ );
24181
+ function validateFilename(filename, where) {
24182
+ if (/[/\\]/.test(filename)) {
24183
+ throw new Error(
24184
+ `${where}: filename ${JSON.stringify(filename)} must be a bare filename, not a path. Pass just the name the recipient should see, e.g. "report.pdf".`
24185
+ );
24186
+ }
24187
+ if (/[\x00-\x1f]/.test(filename) || /^\.+$/.test(filename) || filename.length > 200) {
24188
+ throw new Error(
24189
+ `${where}: filename ${JSON.stringify(filename)} is not a usable filename (no control characters, not "."/"..", 200 characters max).`
24190
+ );
24191
+ }
24192
+ }
24193
+ function decodedLength(contentBase64) {
24194
+ const buf = Buffer.from(contentBase64, "base64");
24195
+ return buf.toString("base64") === contentBase64 ? buf.length : null;
24196
+ }
24197
+ function inlineFileArg(flag, attachment, opts = {}) {
24198
+ const { filename, contentBase64 } = attachment;
24199
+ const where = opts.where ?? `attachInline entry ${JSON.stringify(filename)}`;
24200
+ validateFilename(filename, where);
24201
+ const bytes = decodedLength(contentBase64);
24202
+ if (bytes === null) {
24203
+ throw new Error(
24204
+ `${where}: contents are not valid base64. Send the standard alphabet with padding and no line breaks \u2014 the value must survive a decode/re-encode round trip unchanged.`
24205
+ );
24206
+ }
24207
+ if (bytes > MAX_INLINE_ATTACHMENT_BYTES) {
24208
+ throw new Error(
24209
+ `${where}: ${bytes} bytes exceeds the ${MAX_INLINE_ATTACHMENT_BYTES}-byte (${formatMiB(MAX_INLINE_ATTACHMENT_BYTES)}) per-file limit for inline content. Upload it to Drive and link to it instead, or send it from a local (stdio) deployment using a real server-side path.`
24210
+ );
24211
+ }
24212
+ const arg = { kind: "file", flag, contents: contentBase64, encoding: "base64", filename };
24213
+ if (opts.positional) arg.positional = true;
24214
+ return { arg, bytes };
24215
+ }
24216
+ function inlineAttachmentArgs(flag, attachments, siblingArgs = []) {
24217
+ if (!attachments?.length) return [];
24218
+ const args = [];
24219
+ const siblingWire = siblingArgs.reduce((sum, arg) => sum + wireBytesOf(arg), 0);
24220
+ let attachmentWire = 0;
24221
+ let decodedTotal = 0;
24222
+ for (const attachment of attachments) {
24223
+ const { arg, bytes } = inlineFileArg(flag, attachment);
24224
+ attachmentWire += arg.contents.length;
24225
+ decodedTotal += bytes;
24226
+ if (siblingWire + attachmentWire > MAX_REQUEST_PAYLOAD_WIRE_BYTES) {
24227
+ const blame = attachmentWire <= MAX_REQUEST_PAYLOAD_WIRE_BYTES ? ` These attachments would fit on their own; the rest of the message (its body, mostly) spends ${siblingWire} bytes of the same budget.` : "";
24228
+ throw new Error(
24229
+ `This message is too large to send: ${decodedTotal} bytes of attachments (${attachmentWire} bytes once base64-encoded for transit) exceed the ${MAX_REQUEST_PAYLOAD_WIRE_BYTES}-byte request limit.${blame} The ceiling for attachments alone is ${MAX_INLINE_ATTACHMENT_TOTAL_BYTES} bytes (${formatMiB(MAX_INLINE_ATTACHMENT_TOTAL_BYTES)}); a long body lowers it. Send fewer or smaller files per message, shorten the body, or upload the large files to Drive and link them.`
24230
+ );
24231
+ }
24232
+ args.push(arg);
24233
+ }
24234
+ return args;
24235
+ }
24236
+
24237
+ // src/tools/chat.ts
24238
+ function registerChatTools(server) {
24239
+ const workspaceOnlyNote = ' WORKSPACE ONLY: Google Chat has no API for consumer accounts, so this fails on an @gmail.com account with "chat requires a Google Workspace account". That is the ACCOUNT, not the token \u2014 re-authorizing or adding scopes will not help.';
24240
+ const spaceParam = external_exports.string().describe(
24241
+ 'Space resource name, e.g. "spaces/AAAAsomeID" (from gog_chat_spaces_list, gog_chat_spaces_find or gog_chat_dm_space)'
24242
+ );
24243
+ const threadParam = external_exports.string().optional().describe(
24244
+ 'Thread resource name, e.g. "spaces/AAAA/threads/CCCC" \u2014 reply inside that thread instead of starting a new one'
24245
+ );
24246
+ server.registerTool("gog_chat_spaces_list", {
24247
+ description: "List the Google Chat spaces the account belongs to \u2014 named rooms and DMs alike \u2014 with their resource names. Start here when you do not yet have a space name; gog_chat_spaces_find is faster when you know the room's title." + workspaceOnlyNote,
24248
+ annotations: { readOnlyHint: true },
24249
+ inputSchema: {
24250
+ ...paginationParams,
24251
+ account: accountParam
24252
+ }
24253
+ }, async ({ max, pageToken, page, all, account }) => {
24254
+ const args = ["chat", "spaces", "list"];
24255
+ pushPaginationFlags(args, { max, pageToken, page, all });
24256
+ return runOrDiagnose(args, { account });
24257
+ });
24258
+ server.registerTool("gog_chat_spaces_find", {
24259
+ description: 'Find spaces whose display name matches. Substring and case-insensitive by default, which is what you want when the user names a room approximately ("the launch room"); pass exact=true to require the whole title. DMs have no display name \u2014 use gog_chat_dm_space to reach a person.' + workspaceOnlyNote,
24260
+ annotations: { readOnlyHint: true },
24261
+ inputSchema: {
24262
+ displayName: external_exports.string().describe("Space display name, or part of one"),
24263
+ exact: external_exports.boolean().optional().describe("Require an exact (still case-insensitive) match on the whole display name"),
24264
+ max: external_exports.number().int().optional().describe("Max results per page"),
24265
+ account: accountParam
24266
+ }
24267
+ }, async ({ displayName, exact, max, account }) => {
24268
+ const args = ["chat", "spaces", "find", displayName];
24269
+ if (exact) args.push("--exact");
24270
+ if (max !== void 0) args.push(`--max=${max}`);
24271
+ return runOrDiagnose(args, { account });
24272
+ });
24273
+ server.registerTool("gog_chat_spaces_create", {
24274
+ description: "Create a named Chat space, optionally seeding its membership. Members are added immediately and are notified \u2014 this is visible to other people the moment it runs, so confirm the member list before calling it." + workspaceOnlyNote,
24275
+ inputSchema: {
24276
+ displayName: external_exports.string().describe("Display name for the new space"),
24277
+ members: external_exports.array(external_exports.string()).optional().describe('Initial members, as email addresses or "users/..." resource names'),
24278
+ account: accountParam
24279
+ }
24280
+ }, async ({ displayName, members, account }) => {
24281
+ const args = ["chat", "spaces", "create", displayName];
24282
+ if (members) for (const member of members) args.push(`--member=${member}`);
24283
+ return runOrDiagnose(args, { account });
24284
+ });
24285
+ server.registerTool("gog_chat_threads_list", {
24286
+ description: "List the threads in a space, so a reply can be targeted at an existing conversation rather than starting a new one. Pass a thread name from here as `thread` to gog_chat_messages_send." + workspaceOnlyNote,
24287
+ annotations: { readOnlyHint: true },
24288
+ inputSchema: {
24289
+ space: spaceParam,
24290
+ ...paginationParams,
24291
+ account: accountParam
24292
+ }
24293
+ }, async ({ space, max, pageToken, page, all, account }) => {
24294
+ const args = ["chat", "threads", "list", space];
24295
+ pushPaginationFlags(args, { max, pageToken, page, all });
24296
+ return runOrDiagnose(args, { account });
24297
+ });
24298
+ server.registerTool("gog_chat_messages_list", {
24299
+ description: `Read messages in a space. The JSON carries each message's @-mentions and a summary of its emoji reactions (gog >= 0.38.0) alongside the text, so "who was tagged" and "did anyone react" are answerable without extra calls. unread=true returns only what arrived after the account last read the space \u2014 the cheap way to answer "what did I miss". Newest-first needs an explicit order="createTime desc"; Chat's own default is oldest-first.` + workspaceOnlyNote,
24300
+ annotations: { readOnlyHint: true },
24301
+ inputSchema: {
24302
+ space: spaceParam,
24303
+ thread: threadParam,
24304
+ unread: external_exports.boolean().optional().describe("Only messages posted after the account last read this space"),
24305
+ order: external_exports.enum(["createTime asc", "createTime desc", "lastUpdateTime asc", "lastUpdateTime desc"]).optional().describe('Sort order (Chat default: "createTime asc", i.e. OLDEST first \u2014 ask for "createTime desc" when you want the latest messages)'),
24306
+ ...paginationParams,
24307
+ account: accountParam
24308
+ }
24309
+ }, async ({ space, thread, unread, order, max, pageToken, page, all, account }) => {
24310
+ const args = ["chat", "messages", "list", space];
24311
+ if (thread) args.push(`--thread=${thread}`);
24312
+ if (unread) args.push("--unread");
24313
+ if (order) args.push(`--order=${order}`);
24314
+ pushPaginationFlags(args, { max, pageToken, page, all });
24315
+ return runOrDiagnose(args, { account });
24316
+ });
24317
+ server.registerTool("gog_chat_messages_send", {
24318
+ description: "Post a message to a Chat space. THIS IS IMMEDIATELY VISIBLE TO EVERYONE IN THE SPACE and cannot be unsent through this tool, so treat it like sending mail, not like saving a draft. Pass `thread` to reply inside an existing conversation (from gog_chat_threads_list or a message's thread field); omit it to start a new one. Text supports Chat's markdown-ish formatting (*bold*, _italic_, `code`)." + workspaceOnlyNote,
24319
+ inputSchema: {
24320
+ space: spaceParam,
24321
+ text: external_exports.string().optional().describe("Message text. Optional only when an attachment is supplied."),
24322
+ thread: threadParam,
24323
+ attach: external_exports.array(external_exports.string()).optional().describe(
24324
+ "Attachment file paths, read WHERE GOG RUNS. On a hosted or remote deployment that is not your machine \u2014 use attachInline there instead."
24325
+ ),
24326
+ attachInline: attachInlineParam,
24327
+ account: accountParam
24328
+ }
24329
+ }, async ({ space, text, thread, attach, attachInline, account }) => {
24330
+ if (text === void 0 && !attach?.length && !attachInline?.length) {
24331
+ throw new Error("A Chat message needs text, an attachment, or both.");
24332
+ }
24333
+ const args = ["chat", "messages", "send", space];
24334
+ if (text !== void 0) args.push(`--text=${text}`);
24335
+ if (thread) args.push(`--thread=${thread}`);
24336
+ if (attach) for (const path of attach) args.push(`--attach=${path}`);
24337
+ args.push(...inlineAttachmentArgs("attach", attachInline, args));
24338
+ return runOrDiagnose(args, { account });
24339
+ });
24340
+ server.registerTool("gog_chat_dm_send", {
24341
+ description: "Send a direct message to one person by email address, creating the DM space if this is the first message. Delivered immediately and cannot be unsent through this tool. For a room rather than a person, use gog_chat_messages_send." + workspaceOnlyNote,
24342
+ inputSchema: {
24343
+ email: external_exports.string().describe("Recipient email address"),
24344
+ text: external_exports.string().describe("Message text"),
24345
+ thread: threadParam,
24346
+ account: accountParam
24347
+ }
24348
+ }, async ({ email: email3, text, thread, account }) => {
24349
+ const args = ["chat", "dm", "send", email3, `--text=${text}`];
24350
+ if (thread) args.push(`--thread=${thread}`);
24351
+ return runOrDiagnose(args, { account });
24352
+ });
24353
+ server.registerTool("gog_chat_dm_space", {
24354
+ description: 'Resolve the DM space for an email address \u2014 the bridge from a person to the "spaces/..." name the message tools want. Creates the space if none exists yet, which is silent: it does not message the person.' + workspaceOnlyNote,
24355
+ inputSchema: {
24356
+ email: external_exports.string().describe("The other person's email address"),
24357
+ account: accountParam
24358
+ }
24359
+ }, async ({ email: email3, account }) => {
24360
+ return runOrDiagnose(["chat", "dm", "space", email3], { account });
24361
+ });
24362
+ server.registerTool("gog_chat_reactions_list", {
24363
+ description: "List the emoji reactions on one message, with who reacted. gog_chat_messages_list already returns a reaction SUMMARY per message; come here when you need the individual reactors, or the reaction resource names that gog_chat_reactions_delete takes." + workspaceOnlyNote,
24364
+ annotations: { readOnlyHint: true },
24365
+ inputSchema: {
24366
+ message: external_exports.string().describe('Message resource name ("spaces/AAAA/messages/BBBB"), or a bare message ID together with `space`'),
24367
+ space: external_exports.string().optional().describe("Space resource name \u2014 required only when `message` is a bare ID"),
24368
+ ...paginationParams,
24369
+ account: accountParam
24370
+ }
24371
+ }, async ({ message, space, max, pageToken, page, all, account }) => {
24372
+ const args = ["chat", "messages", "reactions", "list", message];
24373
+ if (space) args.push(`--space=${space}`);
24374
+ pushPaginationFlags(args, { max, pageToken, page, all });
24375
+ return runOrDiagnose(args, { account });
24376
+ });
24377
+ server.registerTool("gog_chat_reactions_create", {
24378
+ description: 'React to a message with an emoji. Visible to the space immediately. Pass the emoji itself ("\u{1F44D}"), not a :shortcode:.' + workspaceOnlyNote,
24379
+ inputSchema: {
24380
+ message: external_exports.string().describe('Message resource name ("spaces/AAAA/messages/BBBB"), or a bare message ID together with `space`'),
24381
+ emoji: external_exports.string().describe('The emoji character to react with, e.g. "\u{1F44D}"'),
24382
+ space: external_exports.string().optional().describe("Space resource name \u2014 required only when `message` is a bare ID"),
24383
+ account: accountParam
24384
+ }
24385
+ }, async ({ message, emoji: emoji3, space, account }) => {
24386
+ const args = ["chat", "messages", "reactions", "create", message, emoji3];
24387
+ if (space) args.push(`--space=${space}`);
24388
+ return runOrDiagnose(args, { account });
24389
+ });
24390
+ server.registerTool("gog_chat_reactions_delete", {
24391
+ description: `Remove one emoji reaction. Takes the REACTION's own resource name ("spaces/.../messages/.../reactions/..."), not the message's and not the emoji \u2014 get it from gog_chat_reactions_list. An account can only remove its own reaction.` + workspaceOnlyNote,
24392
+ annotations: { destructiveHint: true },
24393
+ inputSchema: {
24394
+ reaction: external_exports.string().describe('Reaction resource name, e.g. "spaces/AAAA/messages/BBBB/reactions/CCCC"'),
24395
+ account: accountParam
24396
+ }
24397
+ }, async ({ reaction, account }) => {
24398
+ return runOrDiagnose(["chat", "messages", "reactions", "delete", reaction], { account });
24399
+ });
24400
+ registerRunTool(server, {
24401
+ service: "chat",
24402
+ examples: '"spaces", "messages", "dm"',
24403
+ note: "Google Chat has no API for consumer accounts: every chat subcommand fails on an @gmail.com account regardless of scopes."
24404
+ });
24405
+ }
24406
+
23993
24407
  // src/tools/classroom.ts
23994
24408
  function registerClassroomTools(server) {
23995
24409
  server.registerTool("gog_classroom_courses_list", {
@@ -24805,6 +25219,7 @@ async function fetchGmailPages(runPage, itemsKey, maxPages, startToken) {
24805
25219
  const merged = [];
24806
25220
  let base;
24807
25221
  let token = startToken;
25222
+ const fetched = new Set(startToken === void 0 ? [] : [startToken]);
24808
25223
  for (let pages = 0; pages < maxPages; pages++) {
24809
25224
  const result = await runPage(token);
24810
25225
  const parsed = parsePage(result, itemsKey);
@@ -24813,8 +25228,17 @@ async function fetchGmailPages(runPage, itemsKey, maxPages, startToken) {
24813
25228
  }
24814
25229
  base = parsed;
24815
25230
  merged.push(...parsed[itemsKey]);
24816
- token = typeof parsed.nextPageToken === "string" && parsed.nextPageToken !== "" ? parsed.nextPageToken : void 0;
24817
- if (token === void 0) break;
25231
+ const next = typeof parsed.nextPageToken === "string" && parsed.nextPageToken !== "" ? parsed.nextPageToken : void 0;
25232
+ if (next === void 0) {
25233
+ token = void 0;
25234
+ break;
25235
+ }
25236
+ if (fetched.has(next)) {
25237
+ token = next;
25238
+ break;
25239
+ }
25240
+ fetched.add(next);
25241
+ token = next;
24818
25242
  }
24819
25243
  return finish(base, itemsKey, merged, token);
24820
25244
  }
@@ -24891,7 +25315,7 @@ function registerGmailTools(server) {
24891
25315
  return runOrDiagnose(args, { account });
24892
25316
  });
24893
25317
  server.registerTool("gog_gmail_send", {
24894
- description: "Send an email. When attach is used, the JSON result echoes the attached filenames and byte sizes \u2014 check it to confirm the files were found and embedded.",
25318
+ description: 'Send an email. Two ways to attach a file: `attach` takes paths READ ON THE GOG SERVER, and `attachInline` takes the bytes themselves. Use attachInline unless you know the file exists on the same machine gog runs on \u2014 on the hosted connector and any remote deployment there is no shared filesystem, so no path you can name resolves there and `attach` will fail with "no such file or directory". When either is used, the JSON result echoes the attached filenames and byte sizes \u2014 check it to confirm the files were embedded.',
24895
25319
  annotations: { destructiveHint: true },
24896
25320
  inputSchema: {
24897
25321
  to: external_exports.string().describe("Recipient(s), comma-separated"),
@@ -24901,16 +25325,19 @@ function registerGmailTools(server) {
24901
25325
  bcc: external_exports.string().optional().describe("BCC recipients, comma-separated"),
24902
25326
  replyToMessageId: external_exports.string().optional().describe("Message ID to reply to"),
24903
25327
  threadId: external_exports.string().optional().describe("Thread ID to reply within"),
24904
- attach: external_exports.array(external_exports.string()).optional().describe("Local file paths to attach (repeatable). Each file is read on the gog server (not this client), base64-encoded with a MIME type inferred from its extension, and added as a multipart attachment. Keep the total under Gmail's ~35 MB inline-upload limit."),
25328
+ attach: external_exports.array(external_exports.string()).optional().describe(`File paths to attach (repeatable), resolved ON THE GOG SERVER's filesystem \u2014 NOT this client's. Only usable when gog runs on the same machine you do (local stdio); on the hosted connector or any GOG_RUNNER_URL backend these paths do not exist and the call fails with "no such file or directory" \u2014 use attachInline there. Each file is read on the server, base64-encoded with a MIME type inferred from its extension, and added as a multipart attachment.`),
25329
+ attachInline: attachInlineParam,
24905
25330
  account: accountParam
24906
25331
  }
24907
- }, async ({ to, subject, body, cc, bcc, replyToMessageId, threadId, attach, account }) => {
25332
+ }, async ({ to, subject, body, cc, bcc, replyToMessageId, threadId, attach, attachInline, account }) => {
24908
25333
  const args = ["gmail", "send", `--to=${to}`, `--subject=${subject}`, payloadArg("body", "body-file", body)];
24909
25334
  if (cc) args.push(`--cc=${cc}`);
24910
25335
  if (bcc) args.push(`--bcc=${bcc}`);
24911
25336
  if (replyToMessageId) args.push(`--reply-to-message-id=${replyToMessageId}`);
24912
25337
  if (threadId) args.push(`--thread-id=${threadId}`);
24913
25338
  if (attach) for (const path of attach) args.push(`--attach=${path}`);
25339
+ const inline = inlineAttachmentArgs("attach", attachInline, args);
25340
+ args.push(...inline);
24914
25341
  return runOrDiagnose(args, { account });
24915
25342
  });
24916
25343
  registerRunTool(server, { service: "gmail", examples: '"archive", "mark-read", "labels"' });
@@ -25240,11 +25667,13 @@ function registerTasksTools(server) {
25240
25667
  }
25241
25668
 
25242
25669
  // src/server.ts
25243
- var VERSION = true ? "2.24.0" : "0.0.0";
25670
+ var VERSION = true ? "2.26.0" : "0.0.0";
25244
25671
  var BASE_TOOL_REGISTRARS = [
25245
25672
  registerApiTools,
25673
+ registerAppScriptTools,
25246
25674
  registerAuthTools,
25247
25675
  registerCalendarTools,
25676
+ registerChatTools,
25248
25677
  registerClassroomTools,
25249
25678
  registerContactsTools,
25250
25679
  registerDocsTools,
@@ -25740,17 +26169,25 @@ function useRemoteGogRunner(env = process.env) {
25740
26169
  }
25741
26170
  export {
25742
26171
  BASE_TOOL_REGISTRARS,
26172
+ INLINE_ATTACHMENT_LIMITS_TEXT,
26173
+ MAX_INLINE_ATTACHMENT_BYTES,
26174
+ MAX_INLINE_ATTACHMENT_TOTAL_BYTES,
26175
+ MAX_REQUEST_PAYLOAD_WIRE_BYTES,
25743
26176
  MIN_GOG_VERSION,
25744
26177
  PAYLOAD_INLINE_MAX,
25745
26178
  VERSION,
25746
26179
  accountParam,
25747
26180
  annotateTruncatedList,
26181
+ attachInlineParam,
25748
26182
  authToolsFor,
25749
26183
  diagnose,
25750
26184
  errorText,
25751
26185
  fetchGmailPages,
25752
26186
  finalizeGmailSearch,
25753
26187
  ids,
26188
+ inlineAttachmentArgs,
26189
+ inlineAttachmentSchema,
26190
+ inlineFileArg,
25754
26191
  isGogFileArg,
25755
26192
  normalizeTimestamps,
25756
26193
  pageAliasParam,
@@ -25759,8 +26196,10 @@ export {
25759
26196
  payloadArg,
25760
26197
  pushPaginationFlags,
25761
26198
  registerApiTools,
26199
+ registerAppScriptTools,
25762
26200
  registerAuthTools,
25763
26201
  registerCalendarTools,
26202
+ registerChatTools,
25764
26203
  registerClassroomTools,
25765
26204
  registerContactsTools,
25766
26205
  registerDocsTools,