gogcli-mcp 2.28.0 → 2.29.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.
@@ -1,5 +1,6 @@
1
1
  import { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js';
2
2
  import { z } from 'zod';
3
+ import { viewParam, resolveView } from '@chrischall/mcp-utils';
3
4
  import { accountParam, runOrDiagnose, registerRunTool, pageTokenParam, pageAliasParam, resolvePageToken } from './utils.js';
4
5
  import { annotateTruncatedList } from '../pagination.js';
5
6
 
@@ -53,6 +54,27 @@ function pushReminderFlags(
53
54
  for (const reminder of p.reminders) args.push(`--reminder=${reminder}`);
54
55
  }
55
56
 
57
+
58
+ // The `compact` rung for gog_calendar_events, as a Google Calendar field mask.
59
+ //
60
+ // nextPageToken FIRST and always. This tool's own description tells a caller
61
+ // that a wide range is usually incomplete and to page until the cursor is gone;
62
+ // a mask of `items(...)` alone drops that cursor from the envelope, which would
63
+ // turn that instruction into a guarantee of the wrong answer. Verified live
64
+ // against gog 0.39.0.
65
+ //
66
+ // Chosen from the DATA over a 25-event window: description costs 5,951 bytes
67
+ // and attendees 3,145 — the two fat blobs `full` exists to return — while etag,
68
+ // kind, iCalUID, eventType, timezone, guestsCanInviteOthers and privateCopy are
69
+ // internal or single-valued across every row. Net: 21,260 -> 7,292 bytes, 66%
70
+ // smaller. status is kept despite being single-valued in that sample precisely
71
+ // because its whole value is flagging the rare cancelled event.
72
+ //
73
+ // gog's derived fields (startLocal, endDayOfWeek, ...) survive the mask, since
74
+ // gog computes them from start/end, which the mask keeps.
75
+ export const CALENDAR_EVENTS_COMPACT_FIELDS =
76
+ 'nextPageToken,items(id,summary,start,end,location,status,htmlLink)';
77
+
56
78
  export function registerCalendarTools(server: McpServer): void {
57
79
  server.registerTool('gog_calendar_events', {
58
80
  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): '
@@ -78,9 +100,13 @@ export function registerCalendarTools(server: McpServer): void {
78
100
  all: z.boolean().optional().describe('Fetch events from ALL CALENDARS. NOTE: unlike the gmail search tools, this does NOT mean "all pages" — it widens the calendar set, not the page window. Use pageToken to reach later pages.'),
79
101
  eventTypes: z.array(z.enum(['default', 'birthday', 'focus-time', 'from-gmail', 'out-of-office', 'working-location'])).optional().describe('Filter to specific event types (repeatable)'),
80
102
  timezone: z.string().optional().describe('Display timezone for event times (IANA name, e.g. America/New_York, or "local" for the system timezone). Default: each event\'s timezone, then its calendar\'s timezone.'),
103
+ view: viewParam(['compact', 'full'], {
104
+ note: 'compact (the default) drops description and attendees — together two thirds of a '
105
+ + 'listing\'s bytes — plus etag/iCalUID/kind. Ask for full when you need a body or a guest list.',
106
+ }),
81
107
  account: accountParam,
82
108
  },
83
- }, async ({ calendarId, from, to, days, today, query, max, pageToken, page, all, eventTypes, timezone, account }) => {
109
+ }, async ({ calendarId, from, to, days, today, query, max, pageToken, page, all, eventTypes, timezone, view, account }) => {
84
110
  const args = ['calendar', 'events'];
85
111
  if (calendarId) args.push(calendarId);
86
112
  if (from) args.push(`--from=${from}`);
@@ -94,7 +120,11 @@ export function registerCalendarTools(server: McpServer): void {
94
120
  if (all) args.push('--all');
95
121
  if (eventTypes) for (const t of eventTypes) args.push(`--event-types=${t}`);
96
122
  if (timezone) args.push(`--timezone=${timezone}`);
97
- const result = await runOrDiagnose(args, { account });
123
+ const rung = resolveView(view, ['compact', 'full']);
124
+ const result = await runOrDiagnose(args, {
125
+ account,
126
+ fieldsMask: rung === 'compact' ? CALENDAR_EVENTS_COMPACT_FIELDS : undefined,
127
+ });
98
128
  // No count probe here: unlike Gmail's list endpoints, the Calendar API has
99
129
  // no cheap way to count a range exactly, so the warning carries the fact of
100
130
  // truncation without inventing a total.
@@ -1,7 +1,8 @@
1
1
  import { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js';
2
2
  import type { CallToolResult } from '@modelcontextprotocol/sdk/types.js';
3
3
  import { z } from 'zod';
4
- import { rawTextResult } from '@chrischall/mcp-utils';
4
+ import { rawTextResult, viewParam, resolveView } from '@chrischall/mcp-utils';
5
+
5
6
  import { run, runBinary } from '../runner.js';
6
7
  import { accountParam, diagnose, runOrDiagnose, registerRunTool, pageTokenParam, pageAliasParam, resolvePageToken} from './utils.js';
7
8
 
@@ -18,6 +19,21 @@ function fileMeta(raw: string): { name?: string; mimeType?: string } {
18
19
  return { name: f.name, mimeType: f.mimeType };
19
20
  }
20
21
 
22
+
23
+ // The `compact` rung for gog_drive_ls, as a Google Drive field mask.
24
+ //
25
+ // nextPageToken FIRST and always: a mask of `files(...)` alone drops the cursor
26
+ // from the envelope, and a compact listing would then look complete when it was
27
+ // one page of many. Verified live against gog 0.39.0.
28
+ //
29
+ // The dropped fields were chosen from the DATA, not from taste — measured over
30
+ // a 25-row listing: thumbnailLink costs 4,998 bytes at ONE distinct value,
31
+ // owners 1,400 at one, parents 900 at one, hasThumbnail 550 at one. Everything
32
+ // kept below varies across rows. Net: 15,718 -> 8,095 bytes, 48% smaller.
33
+ // A caller who needs an owner or a parent asks for view="full".
34
+ export const DRIVE_LS_COMPACT_FIELDS =
35
+ 'nextPageToken,files(id,name,mimeType,modifiedTime,size,webViewLink)';
36
+
21
37
  export function registerDriveTools(server: McpServer): void {
22
38
  server.registerTool('gog_drive_ls', {
23
39
  description: 'List files in a Google Drive folder (default: root).',
@@ -29,9 +45,13 @@ export function registerDriveTools(server: McpServer): void {
29
45
  page: pageAliasParam,
30
46
  query: z.string().optional().describe('Drive query filter (e.g. "name contains \'budget\'")'),
31
47
  allDrives: z.boolean().optional().describe('Include shared drives (default: true). Set false for My Drive only.'),
48
+ view: viewParam(['compact', 'full'], {
49
+ note: 'compact (the default) drops owners, parents, thumbnailLink and hasThumbnail — '
50
+ + 'near-constant across a listing and 48% of its bytes. Ask for full to get them.',
51
+ }),
32
52
  account: accountParam,
33
53
  },
34
- }, async ({ folderId, max, pageToken, page, query, allDrives, account }) => {
54
+ }, async ({ folderId, max, pageToken, page, query, allDrives, view, account }) => {
35
55
  const args = ['drive', 'ls'];
36
56
  if (folderId) args.push(`--parent=${folderId}`);
37
57
  if (max !== undefined) args.push(`--max=${max}`);
@@ -39,7 +59,11 @@ export function registerDriveTools(server: McpServer): void {
39
59
  if (token) args.push(`--page=${token}`);
40
60
  if (query) args.push(`--query=${query}`);
41
61
  if (allDrives === false) args.push('--no-all-drives');
42
- return runOrDiagnose(args, { account });
62
+ const rung = resolveView(view, ['compact', 'full']);
63
+ return runOrDiagnose(args, {
64
+ account,
65
+ fieldsMask: rung === 'compact' ? DRIVE_LS_COMPACT_FIELDS : undefined,
66
+ });
43
67
  });
44
68
 
45
69
  server.registerTool('gog_drive_search', {
@@ -47,10 +71,17 @@ export function registerDriveTools(server: McpServer): void {
47
71
  annotations: { readOnlyHint: true },
48
72
  inputSchema: {
49
73
  query: z.string().describe('Search query'),
74
+ // gog's `drive search` accepts no --fields mask, so unlike gog_drive_ls
75
+ // this tool's compact rung is a LOCAL projection. Same vocabulary either
76
+ // way: a caller does not need to know which lever is being pulled.
77
+ view: viewParam(['compact', 'full'], { note: 'compact (the default) drops thumbnailLink — a URL a model cannot see, and 30%+ of a Drive file record. Ask for full to get it back.' }),
50
78
  account: accountParam,
51
79
  },
52
- }, async ({ query, account }) => {
53
- return runOrDiagnose(['drive', 'search', query], { account });
80
+ }, async ({ query, view, account }) => {
81
+ return runOrDiagnose(['drive', 'search', query], {
82
+ account,
83
+ stripMedia: resolveView(view, ['compact', 'full']) === 'compact',
84
+ });
54
85
  });
55
86
 
56
87
  server.registerTool('gog_drive_get', {
@@ -58,10 +89,20 @@ export function registerDriveTools(server: McpServer): void {
58
89
  annotations: { readOnlyHint: true },
59
90
  inputSchema: {
60
91
  fileId: z.string().describe('File ID'),
92
+ // A --fields mask saves only 7% here: the default set is already narrow,
93
+ // which is why this tool takes no mask. The media strip saves 27.5% of
94
+ // the tool's actual output, measured end to end over stdio, which is why
95
+ // it takes a view after all. (An earlier note said 32.9%; that was a
96
+ // minified-vs-stripped comparison of the raw gog payload rather than of
97
+ // what the tool returns. The end-to-end figure is the one a caller sees.)
98
+ view: viewParam(['compact', 'full'], { note: 'compact (the default) drops thumbnailLink — a URL a model cannot see, and 30%+ of a Drive file record. Ask for full to get it back.' }),
61
99
  account: accountParam,
62
100
  },
63
- }, async ({ fileId, account }) => {
64
- return runOrDiagnose(['drive', 'get', fileId], { account });
101
+ }, async ({ fileId, view, account }) => {
102
+ return runOrDiagnose(['drive', 'get', fileId], {
103
+ account,
104
+ stripMedia: resolveView(view, ['compact', 'full']) === 'compact',
105
+ });
65
106
  });
66
107
 
67
108
  server.registerTool('gog_drive_mkdir', {
@@ -1,7 +1,7 @@
1
1
  import { z } from 'zod';
2
2
  import type { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js';
3
3
  import type { CallToolResult } from '@modelcontextprotocol/sdk/types.js';
4
- import { errorResult, rawTextResult } from '@chrischall/mcp-utils';
4
+ import { errorResult, rawTextResult, minifiedResult, stripMediaUrls } from '@chrischall/mcp-utils';
5
5
  import { run, isRunnerTransportError } from '../runner.js';
6
6
  import type { GogArg, RunnerFailureKind } from '../runner.js';
7
7
  import { normalizeTimestamps } from '../timestamps.js';
@@ -342,9 +342,89 @@ export async function diagnose(err: unknown): Promise<CallToolResult> {
342
342
  }
343
343
  }
344
344
 
345
+ // gog pretty-prints its `--json` output, and that indentation is roughly a
346
+ // fifth of a large response while carrying no information a caller reads —
347
+ // 18.6% of a 19 KB `drive ls`, 38% of a small deeply-nested one. Dropping it is
348
+ // the largest token saving available to a passthrough wrapper, which is what
349
+ // this repo is: a tool's output IS gog's JSON, so there is no projection to
350
+ // make instead.
351
+ //
352
+ // Only FORMATTING whitespace goes. mcp-utils' `minifiedResult` is
353
+ // `JSON.stringify` with no indent, which touches neither whitespace INSIDE a
354
+ // value (the blank line between paragraphs of a mail body, the indentation of a
355
+ // quoted block) nor key ORDER — gog emits `nextPageToken` before its data array,
356
+ // and a truncated read still has to see it. A regex over the serialised text
357
+ // would corrupt exactly the payloads this exists to shrink.
358
+ //
359
+ // Anything that is not JSON passes through byte-for-byte: `gog auth list` is
360
+ // plain text, an empty body is legal, and a mangled non-answer is worse than a
361
+ // large one. The guard mirrors normalizeTimestamps' so the two agree on what
362
+ // counts as JSON.
363
+ function minifiedOrRawText(text: string, stripMedia = false): CallToolResult {
364
+ const trimmed = text.trim();
365
+ if (trimmed === '' || !/^[[{]/.test(trimmed)) return rawTextResult(text);
366
+ try {
367
+ const parsed: unknown = JSON.parse(trimmed);
368
+ return minifiedResult(stripMedia ? stripMediaUrls(parsed) : parsed);
369
+ } catch {
370
+ return rawTextResult(text);
371
+ }
372
+ }
373
+
374
+ // THE SECOND COMPACT MECHANISM. `--fields` below is a projection GOOGLE
375
+ // performs; `stripMedia` is one performed here, for the tools whose gog
376
+ // subcommand accepts no mask at all — `gog schema --json` lists only nine that
377
+ // do. Both surface through the same `view` vocabulary, so a caller never has to
378
+ // know which lever a given tool pulls.
379
+ //
380
+ // It drops `thumbnailLink` and friends: URLs a model cannot see, cannot fetch,
381
+ // and would not benefit from if it could. Worth 30-33% on every Drive
382
+ // file-metadata read, measured live. It is deliberately OPT-IN per tool, per
383
+ // the rule that a tool whose PRODUCT is the image must never strip — the tool's
384
+ // own name is the test.
385
+ //
386
+ // A Google field mask (`--fields`) is the other `compact` rung's projection,
387
+ // and it is applied UPSTREAM — inside the Google API, not here. Two consequences shape
388
+ // this function.
389
+ //
390
+ // First, the mask MUST name the response envelope's paging field. A mask of
391
+ // `files(...)` alone drops `nextPageToken` from the payload, so a compact read
392
+ // returns page one with an empty cursor and reads as "there is nothing more" —
393
+ // silent truncation, and the exact false negative this repo's pagination guards
394
+ // exist to prevent. Verified live against gog 0.39.0 on both drive and
395
+ // calendar; the per-tool masks are asserted to start with the paging field.
396
+ //
397
+ // Second, a mask this wrapper gets wrong is a hard 400 from Google rather than
398
+ // a thin record, so `projectOrRaw`'s local try/fallback cannot apply. This is
399
+ // its analogue across the network: a rejected mask retries UNPROJECTED and says
400
+ // why on stderr, because a large correct answer beats a failed tool call. Only
401
+ // a rejected mask is retried — a missing file is not a bad mask, and retrying
402
+ // it would just spend a second call to fail the same way.
403
+ function isRejectedFieldMask(err: unknown): boolean {
404
+ return /invalidParameter|invalid field selection/i.test(String(err));
405
+ }
406
+
407
+ async function runProjected(
408
+ args: GogArg[],
409
+ options: { account?: string; lossless?: boolean; fieldsMask?: string },
410
+ ): Promise<string> {
411
+ const { fieldsMask } = options;
412
+ if (!fieldsMask) return run(args, options);
413
+ try {
414
+ return await run([...args, `--fields=${fieldsMask}`], options);
415
+ } catch (err) {
416
+ if (!isRejectedFieldMask(err)) throw err;
417
+ // stderr, never stdout: stdout is the JSON-RPC channel.
418
+ process.stderr.write(
419
+ `gogcli-mcp: Google rejected the compact field mask (${fieldsMask}); retrying unprojected\n`,
420
+ );
421
+ return run(args, options);
422
+ }
423
+ }
424
+
345
425
  export async function runOrDiagnose(
346
426
  args: GogArg[],
347
- options: { account?: string; lossless?: boolean },
427
+ options: { account?: string; lossless?: boolean; fieldsMask?: string; stripMedia?: boolean },
348
428
  ): Promise<CallToolResult> {
349
429
  try {
350
430
  // The single seam every tool's output passes through. Normalizing here —
@@ -357,11 +437,12 @@ export async function runOrDiagnose(
357
437
  // `--pretty` formatting, so the one tool you reach for when you need ground
358
438
  // truth would stop telling it. Losslessness wins over presentation there —
359
439
  // the friendlier views of the same data are already normalized.
360
- const raw = await run(args, options);
440
+ const raw = await runProjected(args, options);
361
441
  // Same seam, same reason as normalizeTimestamps: doing this per call site
362
442
  // would let one paginated tool forget and go on reporting a spent cursor as
363
443
  // if it were a live one. `lossless` opts the raw dumps out of both.
364
- return rawTextResult(options.lossless ? raw : stripConsumedPageToken(normalizeTimestamps(raw)));
444
+ if (options.lossless) return rawTextResult(raw);
445
+ return minifiedOrRawText(stripConsumedPageToken(normalizeTimestamps(raw)), options.stripMedia);
365
446
  } catch (err) {
366
447
  return diagnose(err);
367
448
  }
package/src/worker.ts CHANGED
@@ -38,7 +38,7 @@ import { gogAuth, CONNECTOR_INSTRUCTIONS, type GogProps } from './connector-auth
38
38
  // connector with all ~360 tools at once. Add whichever paths you want as separate
39
39
  // connectors in claude.ai (each authorizes with the same connector key).
40
40
 
41
- const VERSION = '2.28.0'; // x-release-please-version
41
+ const VERSION = '2.29.0'; // x-release-please-version
42
42
 
43
43
  // Build an McpAgent subclass whose init() registers `registrars` onto its server,
44
44
  // each handler wrapped in the ALS scope carrying the per-session Fly executor.
@@ -1,5 +1,5 @@
1
1
  import { describe, it, expect, vi, beforeEach } from 'vitest';
2
- import { registerCalendarTools } from '../../src/tools/calendar.js';
2
+ import { registerCalendarTools, CALENDAR_EVENTS_COMPACT_FIELDS } from '../../src/tools/calendar.js';
3
3
  import * as runner from '../../src/runner.js';
4
4
  import { createTestHarness } from '@chrischall/mcp-utils/test';
5
5
 
@@ -7,6 +7,13 @@ vi.mock('../../src/runner.js');
7
7
 
8
8
  const setupHandlers = () => createTestHarness(registerCalendarTools);
9
9
 
10
+ // gog_calendar_events answers in the compact rung by default, so every call
11
+ // carries the mask. These keep the window-flag tests below about window flags
12
+ // while still asserting the shipped default rather than an opted-out view.
13
+ const evArgs = (...extra: string[]) =>
14
+ ['calendar', 'events', ...extra, `--fields=${CALENDAR_EVENTS_COMPACT_FIELDS}`];
15
+ const evOpts = { account: undefined, fieldsMask: CALENDAR_EVENTS_COMPACT_FIELDS };
16
+
10
17
  beforeEach(() => vi.clearAllMocks());
11
18
 
12
19
  describe('gog_calendar_events', () => {
@@ -14,7 +21,36 @@ describe('gog_calendar_events', () => {
14
21
  vi.mocked(runner.run).mockResolvedValue('{"items":[]}');
15
22
  const harness = await setupHandlers();
16
23
  await harness.callTool('gog_calendar_events', {});
17
- expect(runner.run).toHaveBeenCalledWith(['calendar', 'events'], { account: undefined });
24
+ expect(runner.run).toHaveBeenCalledWith(evArgs(), evOpts);
25
+ });
26
+
27
+ // The cheap rung is the default. Measured at 66% smaller on a 25-event
28
+ // window — the largest saving available in this repo, because a calendar
29
+ // event's description and attendee list dwarf the fields a caller acts on.
30
+ it('sends no mask for the full view', async () => {
31
+ vi.mocked(runner.run).mockResolvedValue('{"items":[]}');
32
+ const harness = await setupHandlers();
33
+ await harness.callTool('gog_calendar_events', { view: 'full' });
34
+ expect(runner.run).toHaveBeenCalledWith(
35
+ ['calendar', 'events'],
36
+ { account: undefined, fieldsMask: undefined },
37
+ );
38
+ });
39
+
40
+ // A Google field mask drops nextPageToken from the envelope, so a compact
41
+ // read returns page one with an EMPTY cursor. This tool's own description
42
+ // warns that a wide range is usually incomplete and to page until the cursor
43
+ // is gone — a mask that silently removes the cursor would turn that guidance
44
+ // into a guarantee of the wrong answer. Verified live against gog 0.39.0.
45
+ it('names the paging field in the mask', () => {
46
+ expect(CALENDAR_EVENTS_COMPACT_FIELDS).toMatch(/^nextPageToken,/);
47
+ });
48
+
49
+ it('rejects a view rung this tool does not honour', async () => {
50
+ const harness = await setupHandlers();
51
+ const result = await harness.callTool('gog_calendar_events', { view: 'raw' });
52
+ expect(result.isError).toBe(true);
53
+ expect(runner.run).not.toHaveBeenCalled();
18
54
  });
19
55
 
20
56
  // The window flags are pinned as SEPARATE cases on purpose: gog >= 0.36.0
@@ -31,54 +67,42 @@ describe('gog_calendar_events', () => {
31
67
  query: 'standup',
32
68
  all: true,
33
69
  });
34
- expect(runner.run).toHaveBeenCalledWith(
35
- ['calendar', 'events', 'primary', '--from=2026-01-01', '--to=2026-01-31', '--query=standup', '--all'],
36
- { account: undefined },
37
- );
70
+ expect(runner.run).toHaveBeenCalledWith(evArgs('primary', '--from=2026-01-01', '--to=2026-01-31', '--query=standup', '--all'), evOpts);
38
71
  });
39
72
 
40
73
  it('appends --today on its own', async () => {
41
74
  vi.mocked(runner.run).mockResolvedValue('{}');
42
75
  const harness = await setupHandlers();
43
76
  await harness.callTool('gog_calendar_events', { today: true });
44
- expect(runner.run).toHaveBeenCalledWith(['calendar', 'events', '--today'], { account: undefined });
77
+ expect(runner.run).toHaveBeenCalledWith(evArgs('--today'), evOpts);
45
78
  });
46
79
 
47
80
  it('anchors --days at --from when both are given', async () => {
48
81
  vi.mocked(runner.run).mockResolvedValue('{}');
49
82
  const harness = await setupHandlers();
50
83
  await harness.callTool('gog_calendar_events', { from: '2026-09-25', days: 5 });
51
- expect(runner.run).toHaveBeenCalledWith(
52
- ['calendar', 'events', '--from=2026-09-25', '--days=5'],
53
- { account: undefined },
54
- );
84
+ expect(runner.run).toHaveBeenCalledWith(evArgs('--from=2026-09-25', '--days=5'), evOpts);
55
85
  });
56
86
 
57
87
  it('passes --days alone as a today-anchored window', async () => {
58
88
  vi.mocked(runner.run).mockResolvedValue('{}');
59
89
  const harness = await setupHandlers();
60
90
  await harness.callTool('gog_calendar_events', { days: 7 });
61
- expect(runner.run).toHaveBeenCalledWith(['calendar', 'events', '--days=7'], { account: undefined });
91
+ expect(runner.run).toHaveBeenCalledWith(evArgs('--days=7'), evOpts);
62
92
  });
63
93
 
64
94
  it('repeats --event-types for each requested type', async () => {
65
95
  vi.mocked(runner.run).mockResolvedValue('{}');
66
96
  const harness = await setupHandlers();
67
97
  await harness.callTool('gog_calendar_events', { eventTypes: ['default', 'out-of-office'] });
68
- expect(runner.run).toHaveBeenCalledWith(
69
- ['calendar', 'events', '--event-types=default', '--event-types=out-of-office'],
70
- { account: undefined },
71
- );
98
+ expect(runner.run).toHaveBeenCalledWith(evArgs('--event-types=default', '--event-types=out-of-office'), evOpts);
72
99
  });
73
100
 
74
101
  it('appends --timezone when provided', async () => {
75
102
  vi.mocked(runner.run).mockResolvedValue('{}');
76
103
  const harness = await setupHandlers();
77
104
  await harness.callTool('gog_calendar_events', { timezone: 'America/New_York' });
78
- expect(runner.run).toHaveBeenCalledWith(
79
- ['calendar', 'events', '--timezone=America/New_York'],
80
- { account: undefined },
81
- );
105
+ expect(runner.run).toHaveBeenCalledWith(evArgs('--timezone=America/New_York'), evOpts);
82
106
  });
83
107
 
84
108
  it('returns error text on failure', async () => {
@@ -1,5 +1,5 @@
1
1
  import { describe, it, expect, vi, beforeEach } from 'vitest';
2
- import { registerDriveTools } from '../../src/tools/drive.js';
2
+ import { registerDriveTools, DRIVE_LS_COMPACT_FIELDS } from '../../src/tools/drive.js';
3
3
  import * as runner from '../../src/runner.js';
4
4
  import { createTestHarness } from '@chrischall/mcp-utils/test';
5
5
 
@@ -7,6 +7,13 @@ vi.mock('../../src/runner.js');
7
7
 
8
8
  const setupHandlers = () => createTestHarness(registerDriveTools);
9
9
 
10
+ // gog_drive_ls answers in the compact rung by default, so every call carries
11
+ // the mask. These keep the flag-mapping tests below about flag mapping while
12
+ // still asserting the shipped default rather than a view they opted out of.
13
+ const lsArgs = (...extra: string[]) =>
14
+ ['drive', 'ls', ...extra, `--fields=${DRIVE_LS_COMPACT_FIELDS}`];
15
+ const lsOpts = { account: undefined, fieldsMask: DRIVE_LS_COMPACT_FIELDS };
16
+
10
17
  beforeEach(() => vi.clearAllMocks());
11
18
 
12
19
  describe('gog_drive_ls', () => {
@@ -14,14 +21,48 @@ describe('gog_drive_ls', () => {
14
21
  vi.mocked(runner.run).mockResolvedValue('{"files":[]}');
15
22
  const harness = await setupHandlers();
16
23
  await harness.callTool('gog_drive_ls', {});
17
- expect(runner.run).toHaveBeenCalledWith(['drive', 'ls'], { account: undefined });
24
+ expect(runner.run).toHaveBeenCalledWith(lsArgs(), lsOpts);
25
+ });
26
+
27
+ // Efficiency is not something a caller should have to ask for: the cheap rung
28
+ // is the default. Measured at 48% smaller on a 25-row listing.
29
+ it('defaults to the compact view, applying the field mask', async () => {
30
+ vi.mocked(runner.run).mockResolvedValue('{"files":[]}');
31
+ const harness = await setupHandlers();
32
+ await harness.callTool('gog_drive_ls', {});
33
+ expect(runner.run).toHaveBeenCalledWith(
34
+ ['drive', 'ls', `--fields=${DRIVE_LS_COMPACT_FIELDS}`],
35
+ lsOpts,
36
+ );
37
+ });
38
+
39
+ it('sends no mask for the full view', async () => {
40
+ vi.mocked(runner.run).mockResolvedValue('{"files":[]}');
41
+ const harness = await setupHandlers();
42
+ await harness.callTool('gog_drive_ls', { view: 'full' });
43
+ expect(runner.run).toHaveBeenCalledWith(['drive', 'ls'], { account: undefined, fieldsMask: undefined });
44
+ });
45
+
46
+ // THE BUG THIS ALMOST SHIPPED: a Google field mask drops nextPageToken from
47
+ // the envelope, so a compact read returns page one with an EMPTY cursor and
48
+ // reads as "no more results" — silent truncation, verified live against gog
49
+ // 0.39.0. Naming the paging field in the mask is what brings it back.
50
+ it('names the paging field in the mask', () => {
51
+ expect(DRIVE_LS_COMPACT_FIELDS).toMatch(/^nextPageToken,/);
52
+ });
53
+
54
+ it('rejects a view rung this tool does not honour', async () => {
55
+ const harness = await setupHandlers();
56
+ const result = await harness.callTool('gog_drive_ls', { view: 'raw' });
57
+ expect(result.isError).toBe(true);
58
+ expect(runner.run).not.toHaveBeenCalled();
18
59
  });
19
60
 
20
61
  it('passes folderId as --parent flag', async () => {
21
62
  vi.mocked(runner.run).mockResolvedValue('{}');
22
63
  const harness = await setupHandlers();
23
64
  await harness.callTool('gog_drive_ls', { folderId: 'folder1' });
24
- expect(runner.run).toHaveBeenCalledWith(['drive', 'ls', '--parent=folder1'], { account: undefined });
65
+ expect(runner.run).toHaveBeenCalledWith(lsArgs('--parent=folder1'), lsOpts);
25
66
  });
26
67
 
27
68
  it('supports max, page, query, and allDrives flags', async () => {
@@ -34,8 +75,8 @@ describe('gog_drive_ls', () => {
34
75
  query: "name contains 'x'",
35
76
  });
36
77
  expect(runner.run).toHaveBeenCalledWith(
37
- ['drive', 'ls', '--parent=folder1', '--max=50', '--page=tok', "--query=name contains 'x'"],
38
- { account: undefined },
78
+ lsArgs('--parent=folder1', '--max=50', '--page=tok', "--query=name contains 'x'"),
79
+ lsOpts,
39
80
  );
40
81
  });
41
82
 
@@ -43,14 +84,14 @@ describe('gog_drive_ls', () => {
43
84
  vi.mocked(runner.run).mockResolvedValue('{}');
44
85
  const harness = await setupHandlers();
45
86
  await harness.callTool('gog_drive_ls', { allDrives: false });
46
- expect(runner.run).toHaveBeenCalledWith(['drive', 'ls', '--no-all-drives'], { account: undefined });
87
+ expect(runner.run).toHaveBeenCalledWith(lsArgs('--no-all-drives'), lsOpts);
47
88
  });
48
89
 
49
90
  it('omits all-drives flag when allDrives is true (default)', async () => {
50
91
  vi.mocked(runner.run).mockResolvedValue('{}');
51
92
  const harness = await setupHandlers();
52
93
  await harness.callTool('gog_drive_ls', { allDrives: true });
53
- expect(runner.run).toHaveBeenCalledWith(['drive', 'ls'], { account: undefined });
94
+ expect(runner.run).toHaveBeenCalledWith(lsArgs(), lsOpts);
54
95
  });
55
96
 
56
97
  it('returns error text on failure', async () => {
@@ -62,11 +103,27 @@ describe('gog_drive_ls', () => {
62
103
  });
63
104
 
64
105
  describe('gog_drive_search', () => {
65
- it('calls run with query', async () => {
106
+ // drive search accepts NO field mask — `gog schema --json` lists only nine
107
+ // commands that do, and this is not one — so the local media strip is the
108
+ // only projection available to it. Measured 27.8% end to end.
109
+ it('calls run with query, defaulting to the compact view', async () => {
66
110
  vi.mocked(runner.run).mockResolvedValue('{"files":[]}');
67
111
  const harness = await setupHandlers();
68
112
  await harness.callTool('gog_drive_search', { query: 'budget' });
69
- expect(runner.run).toHaveBeenCalledWith(['drive', 'search', 'budget'], { account: undefined });
113
+ expect(runner.run).toHaveBeenCalledWith(
114
+ ['drive', 'search', 'budget'],
115
+ { account: undefined, stripMedia: true },
116
+ );
117
+ });
118
+
119
+ it('keeps everything for the full view', async () => {
120
+ vi.mocked(runner.run).mockResolvedValue('{"files":[]}');
121
+ const harness = await setupHandlers();
122
+ await harness.callTool('gog_drive_search', { query: 'budget', view: 'full' });
123
+ expect(runner.run).toHaveBeenCalledWith(
124
+ ['drive', 'search', 'budget'],
125
+ { account: undefined, stripMedia: false },
126
+ );
70
127
  });
71
128
 
72
129
  it('returns error text on failure', async () => {
@@ -78,13 +135,24 @@ describe('gog_drive_search', () => {
78
135
  });
79
136
 
80
137
  describe('gog_drive_get', () => {
81
- it('calls run with fileId', async () => {
82
- vi.mocked(runner.run).mockResolvedValue('{"id":"file1"}');
138
+ // Excluded from the --fields work because a mask saved only 7% there: its
139
+ // default field set is already narrow. The media strip saves 27.5% on the
140
+ // same payload end to end, which clears the bar a parameter has to clear.
141
+ it('calls run with fileId, defaulting to the compact view', async () => {
142
+ vi.mocked(runner.run).mockResolvedValue('{}');
143
+ const harness = await setupHandlers();
144
+ await harness.callTool('gog_drive_get', { fileId: 'f1' });
145
+ expect(runner.run).toHaveBeenCalledWith(['drive', 'get', 'f1'], { account: undefined, stripMedia: true });
146
+ });
147
+
148
+ it('keeps everything for the full view', async () => {
149
+ vi.mocked(runner.run).mockResolvedValue('{}');
83
150
  const harness = await setupHandlers();
84
- await harness.callTool('gog_drive_get', { fileId: 'file1' });
85
- expect(runner.run).toHaveBeenCalledWith(['drive', 'get', 'file1'], { account: undefined });
151
+ await harness.callTool('gog_drive_get', { fileId: 'f1', view: 'full' });
152
+ expect(runner.run).toHaveBeenCalledWith(['drive', 'get', 'f1'], { account: undefined, stripMedia: false });
86
153
  });
87
154
 
155
+
88
156
  it('returns error text on failure', async () => {
89
157
  vi.mocked(runner.run).mockRejectedValue(new Error('Not found'));
90
158
  const harness = await setupHandlers();