@mindstone/mcp-server-google-workspace 0.5.12 → 0.5.14

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.
Files changed (37) hide show
  1. package/README.md +32 -3
  2. package/dist/connectorRenewalClient.d.ts +162 -0
  3. package/dist/connectorRenewalClient.js +212 -0
  4. package/dist/modules/accounts/manager.js +24 -4
  5. package/dist/modules/accounts/oauth.js +5 -2
  6. package/dist/modules/accounts/token.d.ts +1 -0
  7. package/dist/modules/accounts/token.js +18 -8
  8. package/dist/modules/accounts/unauthorized.d.ts +4 -0
  9. package/dist/modules/accounts/unauthorized.js +46 -0
  10. package/dist/modules/calendar/service.js +2 -2
  11. package/dist/modules/docs/markdown.d.ts +67 -0
  12. package/dist/modules/docs/markdown.js +651 -0
  13. package/dist/modules/docs/service.d.ts +1 -1
  14. package/dist/modules/docs/service.js +35 -53
  15. package/dist/modules/docs/types.d.ts +0 -1
  16. package/dist/oauth/coordinatedClient.d.ts +14 -0
  17. package/dist/oauth/coordinatedClient.js +103 -0
  18. package/dist/tools/definitions/chat.js +1 -2
  19. package/dist/tools/definitions/docs.js +4 -8
  20. package/dist/tools/definitions/drive.js +0 -1
  21. package/dist/tools/docs-handlers.d.ts +0 -2
  22. package/dist/tools/docs-handlers.js +0 -2
  23. package/dist/tools/param-normalizer.js +0 -1
  24. package/dist/tools/server.js +8 -23
  25. package/dist/tools/type-guards.d.ts +0 -1
  26. package/dist/tools/type-guards.js +1 -3
  27. package/dist/utils/apiError.d.ts +4 -4
  28. package/dist/utils/apiError.js +7 -6
  29. package/dist/utils/google-retry.d.ts +6 -0
  30. package/dist/utils/google-retry.js +18 -1
  31. package/node_modules/cross-spawn/README.md +19 -3
  32. package/node_modules/cross-spawn/lib/parse.js +38 -10
  33. package/node_modules/cross-spawn/lib/util/escape.js +84 -25
  34. package/node_modules/cross-spawn/lib/util/readShebang.js +8 -2
  35. package/node_modules/cross-spawn/lib/util/resolveCommand.js +8 -1
  36. package/node_modules/cross-spawn/package.json +21 -24
  37. package/package.json +1 -1
@@ -1,3 +1,4 @@
1
+ import { AccountError } from './types.js';
1
2
  export function isUnauthorizedError(error) {
2
3
  if (!error || typeof error !== 'object')
3
4
  return false;
@@ -13,6 +14,51 @@ export function isUnauthorizedError(error) {
13
14
  || candidate.response?.data?.error === 'unauthorized'
14
15
  || candidate.errors?.some((entry) => entry.reason === 'authError') === true;
15
16
  }
17
+ const SIGN_IN_RENEWED = Symbol.for('google-workspace.sign-in-renewed');
18
+ /** Marks a report whose refusal has been resolved by a renewal, so it is never read as a refusal again. */
19
+ export function markSignInRenewed(target) {
20
+ Object.defineProperty(target, SIGN_IN_RENEWED, { value: true });
21
+ return target;
22
+ }
23
+ function signInRenewed(error) {
24
+ const seen = new Set();
25
+ let current = error;
26
+ for (let depth = 0; depth < 8; depth++) {
27
+ if (!current || typeof current !== 'object' || seen.has(current))
28
+ return false;
29
+ if (current[SIGN_IN_RENEWED] === true)
30
+ return true;
31
+ seen.add(current);
32
+ current = current.cause;
33
+ }
34
+ return false;
35
+ }
36
+ /** Operation-time auth failures, including errors wrapped by services and handlers. */
37
+ export function isGoogleAuthFailure(error) {
38
+ if (signInRenewed(error))
39
+ return false;
40
+ const seen = new Set();
41
+ let current = error;
42
+ for (let depth = 0; depth < 8; depth++) {
43
+ if (!current || typeof current !== 'object' || seen.has(current))
44
+ return false;
45
+ seen.add(current);
46
+ // The connector's own account verdict is final: a temporary refresh failure keeps the
47
+ // refusal as its cause for diagnosis, but it is a retry, not a sign-in.
48
+ if (current instanceof AccountError)
49
+ return current.code === 'AUTH_REQUIRED';
50
+ if (isUnauthorizedError(current))
51
+ return true;
52
+ const candidate = current;
53
+ if (candidate.error === 'invalid_grant'
54
+ || candidate.response?.data?.error === 'invalid_grant'
55
+ || (typeof candidate.message === 'string' && candidate.message.includes('invalid_grant'))) {
56
+ return true;
57
+ }
58
+ current = candidate.cause;
59
+ }
60
+ return false;
61
+ }
16
62
  export function isRefreshTokenInvalidError(error) {
17
63
  const values = [];
18
64
  if (error instanceof Error) {
@@ -4,7 +4,7 @@ import { getAccountManager } from '../accounts/index.js';
4
4
  import { CalendarError } from './types.js';
5
5
  import { DriveService } from '../drive/service.js';
6
6
  import { AccountError } from '../accounts/types.js';
7
- import { isUnauthorizedError } from '../accounts/unauthorized.js';
7
+ import { isGoogleAuthFailure } from '../accounts/unauthorized.js';
8
8
  import { isPassthroughGoogleError } from '../../utils/apiError.js';
9
9
  import { wrapUntrustedContent } from '../../utils/untrusted-controls.js';
10
10
  function toAttachmentReferences(attachments) {
@@ -371,7 +371,7 @@ export class CalendarService {
371
371
  throw error;
372
372
  if (isShortWindowRateLimit(error))
373
373
  throw error;
374
- if (isUnauthorizedError(error)) {
374
+ if (isGoogleAuthFailure(error)) {
375
375
  if (process.env.GOOGLE_WORKSPACE_DISABLE_REFRESH === '1') {
376
376
  throw new AccountError('Calendar authentication required', 'AUTH_REQUIRED', 'Connect Google Workspace to continue');
377
377
  }
@@ -0,0 +1,67 @@
1
+ /**
2
+ * Turns markdown text into the Google Docs requests that write it with real formatting.
3
+ *
4
+ * The create, append and replace tools take text that models write as markdown. Inserted as it
5
+ * stands, a reader sees "## Plan" and "**due Friday**" in the document. This writes the text
6
+ * without the markers and styles it instead: headings, bulleted and numbered lists (nested by
7
+ * indent), quotes, code, bold, italic, strikethrough and links. Anything else (tables, images)
8
+ * stays as the text it was written as, and so do web addresses and file paths.
9
+ *
10
+ * Index arithmetic is in UTF-16 code units, which is what both JavaScript strings and the Docs
11
+ * API count.
12
+ */
13
+ import type { docs_v1 } from 'googleapis';
14
+ type InlineStyle = 'bold' | 'italic' | 'strike' | 'code' | 'link';
15
+ interface Span {
16
+ start: number;
17
+ end: number;
18
+ style: InlineStyle;
19
+ url?: string;
20
+ }
21
+ interface Inline {
22
+ text: string;
23
+ spans: Span[];
24
+ }
25
+ type ListKind = 'bullet' | 'number';
26
+ interface Paragraph {
27
+ text: string;
28
+ spans: Span[];
29
+ heading?: number;
30
+ list?: {
31
+ kind: ListKind;
32
+ level: number;
33
+ };
34
+ quote?: boolean;
35
+ code?: boolean;
36
+ }
37
+ export interface MarkdownInsertOptions {
38
+ /** Where the text goes: 1 for an empty body, the body's end index for an append. */
39
+ index: number;
40
+ tabId?: string;
41
+ /**
42
+ * The text lands at the end of an existing paragraph (an append). Its first line then
43
+ * continues that paragraph and keeps its style, unless it is a heading, list item, quote or
44
+ * code, which start a paragraph of their own.
45
+ */
46
+ continuesParagraph?: boolean;
47
+ }
48
+ /**
49
+ * The scanning one document may do, shared by every forward search and nested parse in it: a
50
+ * backstop for text built to defeat what `Line` remembers. Past it, the rest of the text is
51
+ * written as it stands, markers included, as it was before markdown was formatted.
52
+ */
53
+ interface Scan {
54
+ steps: number;
55
+ }
56
+ /** Strip inline markdown from one paragraph's text, recording the styles it asked for. */
57
+ export declare function parseInline(source: string, scan?: Scan, depth?: number): Inline;
58
+ /** Split markdown into paragraphs, one per line, with block markers removed. */
59
+ export declare function parseBlocks(markdown: string, scan?: Scan): Paragraph[];
60
+ /**
61
+ * The requests that insert `markdown` at `options.index` and format it. Send them in one
62
+ * batchUpdate, in this order: list bullets go last, from the end backwards, because creating
63
+ * them removes the tabs that carry each item's nesting level and so moves the text after it.
64
+ */
65
+ export declare function markdownToDocsRequests(markdown: string, options: MarkdownInsertOptions): docs_v1.Schema$Request[];
66
+ export {};
67
+ //# sourceMappingURL=markdown.d.ts.map