@mcp-z/mcp-gmail 1.1.3 → 1.2.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.
Files changed (124) hide show
  1. package/dist/cjs/email/messages/fetch-message.d.cts +1 -1
  2. package/dist/cjs/email/messages/fetch-message.d.ts +1 -1
  3. package/dist/cjs/email/messages/fetch-message.js.map +1 -1
  4. package/dist/cjs/email/messages/messages.d.cts +1 -1
  5. package/dist/cjs/email/messages/messages.d.ts +1 -1
  6. package/dist/cjs/email/messages/messages.js.map +1 -1
  7. package/dist/cjs/email/parsing/html-processing.d.cts +1 -1
  8. package/dist/cjs/email/parsing/html-processing.d.ts +1 -1
  9. package/dist/cjs/email/parsing/html-processing.js.map +1 -1
  10. package/dist/cjs/email/querying/execute-query.d.cts +1 -1
  11. package/dist/cjs/email/querying/execute-query.d.ts +1 -1
  12. package/dist/cjs/email/querying/execute-query.js.map +1 -1
  13. package/dist/cjs/email/querying/pagination.d.cts +1 -1
  14. package/dist/cjs/email/querying/pagination.d.ts +1 -1
  15. package/dist/cjs/email/querying/pagination.js.map +1 -1
  16. package/dist/cjs/email/querying/search-execution.d.cts +1 -1
  17. package/dist/cjs/email/querying/search-execution.d.ts +1 -1
  18. package/dist/cjs/email/querying/search-execution.js.map +1 -1
  19. package/dist/cjs/index.js.map +1 -1
  20. package/dist/cjs/labels/gmail-labels.d.cts +1 -1
  21. package/dist/cjs/labels/gmail-labels.d.ts +1 -1
  22. package/dist/cjs/labels/gmail-labels.js.map +1 -1
  23. package/dist/cjs/lib/google-auth.d.cts +9 -0
  24. package/dist/cjs/lib/google-auth.d.ts +9 -0
  25. package/dist/cjs/lib/google-auth.js +16 -0
  26. package/dist/cjs/lib/google-auth.js.map +1 -0
  27. package/dist/cjs/mcp/prompts/draft-email.d.cts +2 -3
  28. package/dist/cjs/mcp/prompts/draft-email.d.ts +2 -3
  29. package/dist/cjs/mcp/prompts/draft-email.js.map +1 -1
  30. package/dist/cjs/mcp/prompts/query-syntax.d.cts +2 -3
  31. package/dist/cjs/mcp/prompts/query-syntax.d.ts +2 -3
  32. package/dist/cjs/mcp/prompts/query-syntax.js.map +1 -1
  33. package/dist/cjs/mcp/resources/email.d.cts +6 -5
  34. package/dist/cjs/mcp/resources/email.d.ts +6 -5
  35. package/dist/cjs/mcp/resources/email.js +6 -5
  36. package/dist/cjs/mcp/resources/email.js.map +1 -1
  37. package/dist/cjs/mcp/tools/categories-list.js +6 -5
  38. package/dist/cjs/mcp/tools/categories-list.js.map +1 -1
  39. package/dist/cjs/mcp/tools/label-add.js +7 -6
  40. package/dist/cjs/mcp/tools/label-add.js.map +1 -1
  41. package/dist/cjs/mcp/tools/label-delete.js +10 -9
  42. package/dist/cjs/mcp/tools/label-delete.js.map +1 -1
  43. package/dist/cjs/mcp/tools/labels-list.d.cts +3 -3
  44. package/dist/cjs/mcp/tools/labels-list.d.ts +3 -3
  45. package/dist/cjs/mcp/tools/labels-list.js +6 -5
  46. package/dist/cjs/mcp/tools/labels-list.js.map +1 -1
  47. package/dist/cjs/mcp/tools/message-get.js +7 -7
  48. package/dist/cjs/mcp/tools/message-get.js.map +1 -1
  49. package/dist/cjs/mcp/tools/message-mark-read.js +7 -6
  50. package/dist/cjs/mcp/tools/message-mark-read.js.map +1 -1
  51. package/dist/cjs/mcp/tools/message-move-to-trash.js +10 -9
  52. package/dist/cjs/mcp/tools/message-move-to-trash.js.map +1 -1
  53. package/dist/cjs/mcp/tools/message-respond.js +8 -7
  54. package/dist/cjs/mcp/tools/message-respond.js.map +1 -1
  55. package/dist/cjs/mcp/tools/message-search.js +6 -6
  56. package/dist/cjs/mcp/tools/message-search.js.map +1 -1
  57. package/dist/cjs/mcp/tools/message-send.js +7 -6
  58. package/dist/cjs/mcp/tools/message-send.js.map +1 -1
  59. package/dist/cjs/mcp/tools/messages-export-csv.js +5 -5
  60. package/dist/cjs/mcp/tools/messages-export-csv.js.map +1 -1
  61. package/dist/cjs/setup/http.d.cts +0 -2
  62. package/dist/cjs/setup/http.d.ts +0 -2
  63. package/dist/cjs/setup/http.js +18 -11
  64. package/dist/cjs/setup/http.js.map +1 -1
  65. package/dist/cjs/setup/stdio.d.cts +0 -2
  66. package/dist/cjs/setup/stdio.d.ts +0 -2
  67. package/dist/cjs/setup/stdio.js +18 -11
  68. package/dist/cjs/setup/stdio.js.map +1 -1
  69. package/dist/esm/email/messages/fetch-message.d.ts +1 -1
  70. package/dist/esm/email/messages/fetch-message.js.map +1 -1
  71. package/dist/esm/email/messages/messages.d.ts +1 -1
  72. package/dist/esm/email/messages/messages.js.map +1 -1
  73. package/dist/esm/email/parsing/html-processing.d.ts +1 -1
  74. package/dist/esm/email/parsing/html-processing.js.map +1 -1
  75. package/dist/esm/email/querying/execute-query.d.ts +1 -1
  76. package/dist/esm/email/querying/execute-query.js.map +1 -1
  77. package/dist/esm/email/querying/pagination.d.ts +1 -1
  78. package/dist/esm/email/querying/pagination.js.map +1 -1
  79. package/dist/esm/email/querying/search-execution.d.ts +1 -1
  80. package/dist/esm/email/querying/search-execution.js.map +1 -1
  81. package/dist/esm/index.js +1 -1
  82. package/dist/esm/index.js.map +1 -1
  83. package/dist/esm/labels/gmail-labels.d.ts +1 -1
  84. package/dist/esm/labels/gmail-labels.js.map +1 -1
  85. package/dist/esm/lib/google-auth.d.ts +9 -0
  86. package/dist/esm/lib/google-auth.js +11 -0
  87. package/dist/esm/lib/google-auth.js.map +1 -0
  88. package/dist/esm/mcp/prompts/draft-email.d.ts +2 -3
  89. package/dist/esm/mcp/prompts/draft-email.js.map +1 -1
  90. package/dist/esm/mcp/prompts/query-syntax.d.ts +2 -3
  91. package/dist/esm/mcp/prompts/query-syntax.js.map +1 -1
  92. package/dist/esm/mcp/resources/email.d.ts +6 -5
  93. package/dist/esm/mcp/resources/email.js +5 -4
  94. package/dist/esm/mcp/resources/email.js.map +1 -1
  95. package/dist/esm/mcp/tools/categories-list.js +6 -5
  96. package/dist/esm/mcp/tools/categories-list.js.map +1 -1
  97. package/dist/esm/mcp/tools/label-add.js +7 -6
  98. package/dist/esm/mcp/tools/label-add.js.map +1 -1
  99. package/dist/esm/mcp/tools/label-delete.js +10 -9
  100. package/dist/esm/mcp/tools/label-delete.js.map +1 -1
  101. package/dist/esm/mcp/tools/labels-list.d.ts +3 -3
  102. package/dist/esm/mcp/tools/labels-list.js +6 -5
  103. package/dist/esm/mcp/tools/labels-list.js.map +1 -1
  104. package/dist/esm/mcp/tools/message-get.js +8 -8
  105. package/dist/esm/mcp/tools/message-get.js.map +1 -1
  106. package/dist/esm/mcp/tools/message-mark-read.js +7 -6
  107. package/dist/esm/mcp/tools/message-mark-read.js.map +1 -1
  108. package/dist/esm/mcp/tools/message-move-to-trash.js +10 -9
  109. package/dist/esm/mcp/tools/message-move-to-trash.js.map +1 -1
  110. package/dist/esm/mcp/tools/message-respond.js +8 -7
  111. package/dist/esm/mcp/tools/message-respond.js.map +1 -1
  112. package/dist/esm/mcp/tools/message-search.js +6 -5
  113. package/dist/esm/mcp/tools/message-search.js.map +1 -1
  114. package/dist/esm/mcp/tools/message-send.js +7 -6
  115. package/dist/esm/mcp/tools/message-send.js.map +1 -1
  116. package/dist/esm/mcp/tools/messages-export-csv.js +6 -6
  117. package/dist/esm/mcp/tools/messages-export-csv.js.map +1 -1
  118. package/dist/esm/setup/http.d.ts +0 -2
  119. package/dist/esm/setup/http.js +18 -11
  120. package/dist/esm/setup/http.js.map +1 -1
  121. package/dist/esm/setup/stdio.d.ts +0 -2
  122. package/dist/esm/setup/stdio.js +18 -11
  123. package/dist/esm/setup/stdio.js.map +1 -1
  124. package/package.json +9 -10
@@ -1,4 +1,4 @@
1
- import type { gmail_v1 } from 'googleapis';
1
+ import type { gmail_v1 } from '@googleapis/gmail';
2
2
  export type FetchMode = 'metadata' | 'full';
3
3
  export interface NormalizedAddress {
4
4
  address?: string | undefined;
@@ -1,4 +1,4 @@
1
- import type { gmail_v1 } from 'googleapis';
1
+ import type { gmail_v1 } from '@googleapis/gmail';
2
2
  export type FetchMode = 'metadata' | 'full';
3
3
  export interface NormalizedAddress {
4
4
  address?: string | undefined;
@@ -1 +1 @@
1
- {"version":3,"sources":["/Users/kevin/Dev/OpenSource/ai/mcp-z/mcp-gmail/src/email/messages/fetch-message.ts"],"sourcesContent":["import type { gmail_v1 } from 'googleapis';\nimport { toIsoUtc } from '../../lib/date-conversion.ts';\nimport { extractEmails, extractFrom } from '../parsing/headers-utils.ts';\n\nexport type FetchMode = 'metadata' | 'full';\n\nexport interface NormalizedAddress {\n address?: string | undefined;\n name?: string | undefined;\n}\nexport interface NormalizedMessage {\n id: string;\n threadId?: string | undefined;\n date?: string | undefined;\n subject?: string | undefined;\n from?: NormalizedAddress | undefined;\n to?: string[] | undefined;\n cc?: string[] | undefined;\n bcc?: string[] | undefined;\n snippet?: string | undefined;\n labels?: string[] | undefined;\n body?: string | undefined;\n}\n\nexport interface GmailDeps {\n /** googleapis Gmail client created via createGmailClient(provider). */\n gmail: gmail_v1.Gmail;\n}\n\nfunction extractHeader(headers: Array<{ name?: string; value?: string }> | undefined, key: string): string | undefined {\n const h = headers?.find((x) => (x.name ?? '').toLowerCase() === key.toLowerCase());\n return h?.value ?? undefined;\n}\n\nfunction base64UrlDecode(input: string): string {\n let s = String(input).replace(/-/g, '+').replace(/_/g, '/');\n while (s.length % 4 !== 0) s += '=';\n try {\n return Buffer.from(s, 'base64').toString('utf8');\n } catch {\n return '';\n }\n}\n\nfunction extractBody(payload: unknown): string | undefined {\n const find = (parts: unknown[] | undefined, mime: string): string | undefined => {\n for (const p of parts ?? []) {\n if (p && typeof p === 'object' && 'mimeType' in p && 'body' in p) {\n if (p.mimeType === mime && p.body && typeof p.body === 'object' && 'data' in p.body) {\n return base64UrlDecode(p.body.data as string);\n }\n }\n if (p && typeof p === 'object' && 'parts' in p) {\n const nested = find(p.parts as unknown[], mime);\n if (nested) return nested;\n }\n }\n return undefined;\n };\n if (payload && typeof payload === 'object' && 'parts' in payload) {\n return find(payload.parts as unknown[], 'text/plain') ?? find(payload.parts as unknown[], 'text/html')?.replace(/\\r\\n?/g, '\\n');\n }\n return undefined;\n}\n\nexport async function fetchMessage(deps: GmailDeps, id: string, mode: FetchMode): Promise<NormalizedMessage> {\n const { gmail } = deps;\n // When only metadata is requested, ask Gmail for a reduced payload with just the headers we care about.\n const metadataHeaders = ['Date', 'Subject', 'From', 'To', 'Cc', 'Bcc'];\n const format = mode === 'full' ? 'full' : 'metadata';\n const baseParams = { userId: 'me' as const, id, format };\n const resp = format === 'metadata' ? await gmail.users.messages.get({ ...baseParams, metadataHeaders }) : await gmail.users.messages.get(baseParams);\n const data = resp?.data as unknown;\n const headers = data && typeof data === 'object' && 'payload' in data && data.payload && typeof data.payload === 'object' && 'headers' in data.payload ? (data.payload.headers as Array<{ name?: string; value?: string }> | undefined) : undefined;\n const dateRaw = extractHeader(headers, 'Date');\n const fromRaw = extractHeader(headers, 'From');\n const toRaw = extractHeader(headers, 'To');\n const ccRaw = extractHeader(headers, 'Cc');\n const bccRaw = extractHeader(headers, 'Bcc');\n\n const fromObj = (fromRaw ? (extractFrom(fromRaw) as NormalizedAddress) : undefined) ?? undefined;\n const toArr = toRaw ? extractEmails(toRaw) : [];\n const ccArr = ccRaw ? extractEmails(ccRaw) : [];\n const bccArr = bccRaw ? extractEmails(bccRaw) : [];\n\n const getId = (): string => {\n if (data && typeof data === 'object' && 'id' in data) {\n return String(data.id ?? id);\n }\n return id;\n };\n\n const getThreadId = (): string | undefined => {\n if (data && typeof data === 'object' && 'threadId' in data && data.threadId) {\n return String(data.threadId);\n }\n return undefined;\n };\n\n const getSnippet = (): string | undefined => {\n if (data && typeof data === 'object' && 'snippet' in data && data.snippet) {\n return String(data.snippet);\n }\n return undefined;\n };\n\n const getLabelIds = (): string[] | undefined => {\n if (data && typeof data === 'object' && 'labelIds' in data && Array.isArray(data.labelIds)) {\n return data.labelIds.map(String);\n }\n return undefined;\n };\n\n const getPayload = (): unknown => {\n if (data && typeof data === 'object' && 'payload' in data) {\n return data.payload;\n }\n return undefined;\n };\n\n const msg: NormalizedMessage = {\n id: getId(),\n threadId: getThreadId(),\n date: dateRaw ? (toIsoUtc(dateRaw) ?? dateRaw) : undefined,\n subject: extractHeader(headers, 'Subject'),\n from: fromObj,\n to: toArr.length ? toArr : undefined,\n cc: ccArr.length ? ccArr : undefined,\n bcc: bccArr.length ? bccArr : undefined,\n snippet: getSnippet(),\n labels: getLabelIds(),\n };\n if (mode === 'full') {\n const body = extractBody(getPayload());\n if (body) msg.body = body;\n }\n return msg;\n}\n"],"names":["fetchMessage","extractHeader","headers","key","h","find","x","name","toLowerCase","value","undefined","base64UrlDecode","input","s","String","replace","length","Buffer","from","toString","extractBody","payload","parts","mime","p","mimeType","body","data","nested","deps","id","mode","fromRaw","toIsoUtc","gmail","metadataHeaders","format","baseParams","resp","dateRaw","toRaw","ccRaw","bccRaw","fromObj","toArr","ccArr","bccArr","getId","getThreadId","getSnippet","getLabelIds","getPayload","msg","userId","users","messages","get","extractFrom","extractEmails","threadId","snippet","Array","isArray","labelIds","map","date","subject","to","cc","bcc","labels"],"mappings":";;;;+BAiEsBA;;;eAAAA;;;gCAhEG;8BACkB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA2B3C,SAASC,cAAcC,OAA6D,EAAEC,GAAW;;IAC/F,IAAMC,IAAIF,oBAAAA,8BAAAA,QAASG,IAAI,CAAC,SAACC;YAAOA;eAAD,EAACA,UAAAA,EAAEC,IAAI,cAAND,qBAAAA,UAAU,IAAIE,WAAW,OAAOL,IAAIK,WAAW;;IAC/E,eAAOJ,cAAAA,wBAAAA,EAAGK,KAAK,uCAAIC;AACrB;AAEA,SAASC,gBAAgBC,KAAa;IACpC,IAAI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AAG4B,QAAQlC;wBAC3B0D,IAAIvB,MAAM7B,MAAM,GAAG6B,QAAQnC;wBAC3B2D,KAAKvB,OAAO9B,MAAM,GAAG8B,SAASpC;wBAC9BkD,SAASX;wBACTqB,QAAQpB;oBACV;oBACA,IAAInB,SAAS,QAAQ;wBACbL,OAAON,YAAY+B;wBACzB,IAAIzB,MAAM0B,IAAI1B,IAAI,GAAGA;oBACvB;oBACA;;wBAAO0B;;;;IACT"}
1
+ {"version":3,"sources":["/Users/kevin/Dev/OpenSource/ai/mcp-z/mcp-gmail/src/email/messages/fetch-message.ts"],"sourcesContent":["import type { gmail_v1 } from '@googleapis/gmail';\nimport { toIsoUtc } from '../../lib/date-conversion.ts';\nimport { extractEmails, extractFrom } from '../parsing/headers-utils.ts';\n\nexport type FetchMode = 'metadata' | 'full';\n\nexport interface NormalizedAddress {\n address?: string | undefined;\n name?: string | undefined;\n}\nexport interface NormalizedMessage {\n id: string;\n threadId?: string | undefined;\n date?: string | undefined;\n subject?: string | undefined;\n from?: NormalizedAddress | undefined;\n to?: string[] | undefined;\n cc?: string[] | undefined;\n bcc?: string[] | undefined;\n snippet?: string | undefined;\n labels?: string[] | undefined;\n body?: string | undefined;\n}\n\nexport interface GmailDeps {\n /** googleapis Gmail client created via createGmailClient(provider). */\n gmail: gmail_v1.Gmail;\n}\n\nfunction extractHeader(headers: Array<{ name?: string; value?: string }> | undefined, key: string): string | undefined {\n const h = headers?.find((x) => (x.name ?? '').toLowerCase() === key.toLowerCase());\n return h?.value ?? undefined;\n}\n\nfunction base64UrlDecode(input: string): string {\n let s = String(input).replace(/-/g, '+').replace(/_/g, '/');\n while (s.length % 4 !== 0) s += '=';\n try {\n return Buffer.from(s, 'base64').toString('utf8');\n } catch {\n return '';\n }\n}\n\nfunction extractBody(payload: unknown): string | undefined {\n const find = (parts: unknown[] | undefined, mime: string): string | undefined => {\n for (const p of parts ?? []) {\n if (p && typeof p === 'object' && 'mimeType' in p && 'body' in p) {\n if (p.mimeType === mime && p.body && typeof p.body === 'object' && 'data' in p.body) {\n return base64UrlDecode(p.body.data as string);\n }\n }\n if (p && typeof p === 'object' && 'parts' in p) {\n const nested = find(p.parts as unknown[], mime);\n if (nested) return nested;\n }\n }\n return undefined;\n };\n if (payload && typeof payload === 'object' && 'parts' in payload) {\n return find(payload.parts as unknown[], 'text/plain') ?? find(payload.parts as unknown[], 'text/html')?.replace(/\\r\\n?/g, '\\n');\n }\n return undefined;\n}\n\nexport async function fetchMessage(deps: GmailDeps, id: string, mode: FetchMode): Promise<NormalizedMessage> {\n const { gmail } = deps;\n // When only metadata is requested, ask Gmail for a reduced payload with just the headers we care about.\n const metadataHeaders = ['Date', 'Subject', 'From', 'To', 'Cc', 'Bcc'];\n const format = mode === 'full' ? 'full' : 'metadata';\n const baseParams = { userId: 'me' as const, id, format };\n const resp = format === 'metadata' ? await gmail.users.messages.get({ ...baseParams, metadataHeaders }) : await gmail.users.messages.get(baseParams);\n const data = resp?.data as unknown;\n const headers = data && typeof data === 'object' && 'payload' in data && data.payload && typeof data.payload === 'object' && 'headers' in data.payload ? (data.payload.headers as Array<{ name?: string; value?: string }> | undefined) : undefined;\n const dateRaw = extractHeader(headers, 'Date');\n const fromRaw = extractHeader(headers, 'From');\n const toRaw = extractHeader(headers, 'To');\n const ccRaw = extractHeader(headers, 'Cc');\n const bccRaw = extractHeader(headers, 'Bcc');\n\n const fromObj = (fromRaw ? (extractFrom(fromRaw) as NormalizedAddress) : undefined) ?? undefined;\n const toArr = toRaw ? extractEmails(toRaw) : [];\n const ccArr = ccRaw ? extractEmails(ccRaw) : [];\n const bccArr = bccRaw ? extractEmails(bccRaw) : [];\n\n const getId = (): string => {\n if (data && typeof data === 'object' && 'id' in data) {\n return String(data.id ?? id);\n }\n return id;\n };\n\n const getThreadId = (): string | undefined => {\n if (data && typeof data === 'object' && 'threadId' in data && data.threadId) {\n return String(data.threadId);\n }\n return undefined;\n };\n\n const getSnippet = (): string | undefined => {\n if (data && typeof data === 'object' && 'snippet' in data && data.snippet) {\n return String(data.snippet);\n }\n return undefined;\n };\n\n const getLabelIds = (): string[] | undefined => {\n if (data && typeof data === 'object' && 'labelIds' in data && Array.isArray(data.labelIds)) {\n return data.labelIds.map(String);\n }\n return undefined;\n };\n\n const getPayload = (): unknown => {\n if (data && typeof data === 'object' && 'payload' in data) {\n return data.payload;\n }\n return undefined;\n };\n\n const msg: NormalizedMessage = {\n id: getId(),\n threadId: getThreadId(),\n date: dateRaw ? (toIsoUtc(dateRaw) ?? dateRaw) : undefined,\n subject: extractHeader(headers, 'Subject'),\n from: fromObj,\n to: toArr.length ? toArr : undefined,\n cc: ccArr.length ? ccArr : undefined,\n bcc: bccArr.length ? bccArr : undefined,\n snippet: getSnippet(),\n labels: getLabelIds(),\n };\n if (mode === 'full') {\n const body = extractBody(getPayload());\n if (body) msg.body = body;\n }\n return msg;\n}\n"],"names":["fetchMessage","extractHeader","headers","key","h","find","x","name","toLowerCase","value","undefined","base64UrlDecode","input","s","String","replace","length","Buffer","from","toString","extractBody","payload","parts","mime","p","mimeType","body","data","nested","deps","id","mode","fromRaw","toIsoUtc","gmail","metadataHeaders","format","baseParams","resp","dateRaw","toRaw","ccRaw","bccRaw","fromObj","toArr","ccArr","bccArr","getId","getThreadId","getSnippet","getLabelIds","getPayload","msg","userId","users","messages","get","extractFrom","extractEmails","threadId","snippet","Array","isArray","labelIds","map","date","subject","to","cc","bcc","labels"],"mappings":";;;;+BAiEsBA;;;eAAAA;;;gCAhEG;8BACkB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA2B3C,SAASC,cAAcC,OAA6D,EAAEC,GAAW;;IAC/F,IAAMC,IAAIF,oBAAAA,8BAAAA,QAASG,IAAI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MAAyB;wBAC7BtB,IAAIiB;wBACJY,UAAUX;wBACViB,MAAM1B,WAAWN,YAAAA,IAAAA,0BAAQ,EAACM,sBAATN,uBAAAA,YAAqBM,UAAW7B;wBACjDwD,SAASjE,cAAcC,SAAS;wBAChCgB,MAAMyB;wBACNwB,IAAIvB,MAAM5B,MAAM,GAAG4B,QAAQlC;wBAC3B0D,IAAIvB,MAAM7B,MAAM,GAAG6B,QAAQnC;wBAC3B2D,KAAKvB,OAAO9B,MAAM,GAAG8B,SAASpC;wBAC9BkD,SAASX;wBACTqB,QAAQpB;oBACV;oBACA,IAAInB,SAAS,QAAQ;wBACbL,OAAON,YAAY+B;wBACzB,IAAIzB,MAAM0B,IAAI1B,IAAI,GAAGA;oBACvB;oBACA;;wBAAO0B;;;;IACT"}
@@ -1,5 +1,5 @@
1
+ import type { gmail_v1 } from '@googleapis/gmail';
1
2
  import { buildContentForItems } from '@mcp-z/email';
2
- import type { gmail_v1 } from 'googleapis';
3
3
  export { buildContentForItems };
4
4
  export declare function toRowFromGmail(msg?: gmail_v1.Schema$Message, opts?: {
5
5
  body?: boolean;
@@ -1,5 +1,5 @@
1
+ import type { gmail_v1 } from '@googleapis/gmail';
1
2
  import { buildContentForItems } from '@mcp-z/email';
2
- import type { gmail_v1 } from 'googleapis';
3
3
  export { buildContentForItems };
4
4
  export declare function toRowFromGmail(msg?: gmail_v1.Schema$Message, opts?: {
5
5
  body?: boolean;
@@ -1 +1 @@
1
- {"version":3,"sources":["/Users/kevin/Dev/OpenSource/ai/mcp-z/mcp-gmail/src/email/messages/messages.ts"],"sourcesContent":["import { buildContentForItems } from '@mcp-z/email';\nimport type { gmail_v1 } from 'googleapis';\nimport { safeBase64Decode } from '../../lib/base64-encoding.ts';\nimport { toIsoUtc } from '../../lib/date-conversion.ts';\nimport { extractEmails, extractFrom } from '../parsing/headers-utils.ts';\n\nexport { buildContentForItems };\n\n// Convert a Gmail messages.get() response into canonical row shape used by sheets writer\n// [id, provider, threadId, to, from, cc, bcc, date, subject, labels, snippet, body]\nexport function toRowFromGmail(msg: gmail_v1.Schema$Message = {}, opts: { body?: boolean; addressFormat?: 'email' | string } = { body: false, addressFormat: 'email' }) {\n const headers = msg?.payload?.headers || [];\n const headerObj: Record<string, string> = Object.fromEntries((headers || []).map((h) => [String(h?.name ?? ''), String(h?.value ?? '')]));\n const id = msg?.id ?? '';\n const provider = 'gmail';\n const threadId = msg?.threadId ?? '';\n const to = extractEmails(headerObj.To ?? '').join(', ');\n const fromInfo = extractFrom(headerObj.From ?? '');\n const from = ((fromInfo && fromInfo.address) || headerObj.From) ?? '';\n const cc = extractEmails(headerObj.Cc ?? '').join(', ');\n const bcc = extractEmails(headerObj.Bcc ?? '').join(', ');\n const date = (toIsoUtc(headerObj.Date) || headerObj.Date) ?? '';\n const subject = headerObj.Subject ?? '';\n const labelIds = Array.isArray(msg?.labelIds) ? (msg.labelIds as string[]) : [];\n const labels = labelIds.join(';');\n const snippet = msg?.snippet ?? '';\n\n let bodyFull = '';\n if (opts?.body) {\n const parts = msg?.payload?.parts || [];\n const findText = (partsArr: unknown[]): string | null => {\n for (const p of partsArr || []) {\n if (p && typeof p === 'object' && 'mimeType' in p && 'body' in p) {\n if (p.mimeType === 'text/plain' && p.body && typeof p.body === 'object' && 'data' in p.body) {\n return p.body.data as string;\n }\n }\n if (p && typeof p === 'object' && 'parts' in p) {\n const nested = findText(p.parts as unknown[]);\n if (nested) return nested;\n }\n }\n return null;\n };\n const raw = findText(parts as unknown[]) || (msg?.payload?.body && typeof msg.payload.body === 'object' && 'data' in msg.payload.body ? msg.payload.body.data : null) || null;\n if (raw) {\n bodyFull = safeBase64Decode(raw as string);\n } else {\n const findHtml = (partsArr: unknown[]): string | null => {\n for (const p of partsArr || []) {\n if (p && typeof p === 'object' && 'mimeType' in p && 'body' in p) {\n if (p.mimeType === 'text/html' && p.body && typeof p.body === 'object' && 'data' in p.body) {\n return p.body.data as string;\n }\n }\n if (p && typeof p === 'object' && 'parts' in p) {\n const nested = findHtml(p.parts as unknown[]);\n if (nested) return nested;\n }\n }\n return null;\n };\n const htmlPart = findHtml(parts as unknown[]);\n if (htmlPart) {\n bodyFull = safeBase64Decode(htmlPart).replace(/\\r\\n?/g, '\\n');\n }\n }\n }\n return [id, provider, threadId, to, from, cc, bcc, date, subject, labels, snippet, bodyFull];\n}\n"],"names":["buildContentForItems","toRowFromGmail","msg","opts","body","addressFormat","headerObj","toIsoUtc","headers","payload","Object","fromEntries","map","h","String","name","value","id","provider","threadId","to","extractEmails","To","join","fromInfo","extractFrom","From","from","address","cc","Cc","bcc","Bcc","date","Date","subject","Subject","labelIds","Array","isArray","labels","snippet","bodyFull","parts","findText","partsArr","p","mimeType","data","nested","raw","safeBase64Decode","findHtml","htmlPart","replace"],"mappings":";;;;;;;;;;;QAMSA;eAAAA,2BAAoB;;QAIbC;eAAAA;;;qBAVqB;gCAEJ;gCACR;8BACkB;;;;;AAMpC,SAASA;QAAeC,MAAAA,iEAA+B,CAAC,GAAGC,OAAAA,iEAA6D;QAAEC,MAAM;QAAOC,eAAe;IAAQ;qBAM1IC,eACIA,iBACf,OACWA,eACCA,gBACZC,OACED;QAXAJ;IAAhB,IAAMM,UAAUN,CAAAA,gBAAAA,2BAAAA,eAAAA,IAAKO,OAAO,cAAZP,mCAAAA,aAAcM,OAAO,KAAI,EAAE;IAC3C,IAAMF,YAAoCI,OAAOC,WAAW,CAAC,AAACH,CAAAA,WAAW,EAAE,AAAD,EAAGI,GAAG,CAAC,SAACC;;eAAM;YAACC,eAAOD,cAAAA,wBAAAA,EAAGE,IAAI,uCAAI;YAAKD,gBAAOD,cAAAA,wBAAAA,EAAGG,KAAK,yCAAI;SAAI;;IACvI,IAAMC,aAAKf,gBAAAA,0BAAAA,IAAKe,EAAE,uCAAI;IACtB,IAAMC,WAAW;IACjB,IAAMC,oBAAWjB,gBAAAA,0BAAAA,IAAKiB,QAAQ,yCAAI;IAClC,IAAMC,KAAKC,IAAAA,6BAAa,GAACf,gBAAAA,UA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0C,EAAE1C,IAAI,CAAC4C,IAAI;4BACpB;wBACF;wBACA,IAAIF,KAAK,CAAA,OAAOA,kCAAP,SAAOA,EAAAA,MAAM,YAAY,WAAWA,GAAG;4BAC9C,IAAMG,SAASG,SAASN,EAAEH,KAAK;4BAC/B,IAAIM,QAAQ,OAAOA;wBACrB;oBACF;;oBAVK;oBAAA;;;6BAAA,6BAAA;4BAAA;;;4BAAA;kCAAA;;;;gBAWL,OAAO;YACT;YACA,IAAMI,WAAWD,SAAST;YAC1B,IAAIU,UAAU;gBACZX,WAAWS,IAAAA,kCAAgB,EAACE,UAAUC,OAAO,CAAC,UAAU;YAC1D;QACF;IACF;IACA,OAAO;QAACrC;QAAIC;QAAUC;QAAUC;QAAIO;QAAME;QAAIE;QAAKE;QAAME;QAASK;QAAQC;QAASC;KAAS;AAC9F"}
1
+ {"version":3,"sources":["/Users/kevin/Dev/OpenSource/ai/mcp-z/mcp-gmail/src/email/messages/messages.ts"],"sourcesContent":["import type { gmail_v1 } from '@googleapis/gmail';\nimport { buildContentForItems } from '@mcp-z/email';\nimport { safeBase64Decode } from '../../lib/base64-encoding.ts';\nimport { toIsoUtc } from '../../lib/date-conversion.ts';\nimport { extractEmails, extractFrom } from '../parsing/headers-utils.ts';\n\nexport { buildContentForItems };\n\n// Convert a Gmail messages.get() response into canonical row shape used by sheets writer\n// [id, provider, threadId, to, from, cc, bcc, date, subject, labels, snippet, body]\nexport function toRowFromGmail(msg: gmail_v1.Schema$Message = {}, opts: { body?: boolean; addressFormat?: 'email' | string } = { body: false, addressFormat: 'email' }) {\n const headers = msg?.payload?.headers || [];\n const headerObj: Record<string, string> = Object.fromEntries((headers || []).map((h) => [String(h?.name ?? ''), String(h?.value ?? '')]));\n const id = msg?.id ?? '';\n const provider = 'gmail';\n const threadId = msg?.threadId ?? '';\n const to = extractEmails(headerObj.To ?? '').join(', ');\n const fromInfo = extractFrom(headerObj.From ?? '');\n const from = ((fromInfo && fromInfo.address) || headerObj.From) ?? '';\n const cc = extractEmails(headerObj.Cc ?? '').join(', ');\n const bcc = extractEmails(headerObj.Bcc ?? '').join(', ');\n const date = (toIsoUtc(headerObj.Date) || headerObj.Date) ?? '';\n const subject = headerObj.Subject ?? '';\n const labelIds = Array.isArray(msg?.labelIds) ? (msg.labelIds as string[]) : [];\n const labels = labelIds.join(';');\n const snippet = msg?.snippet ?? '';\n\n let bodyFull = '';\n if (opts?.body) {\n const parts = msg?.payload?.parts || [];\n const findText = (partsArr: unknown[]): string | null => {\n for (const p of partsArr || []) {\n if (p && typeof p === 'object' && 'mimeType' in p && 'body' in p) {\n if (p.mimeType === 'text/plain' && p.body && typeof p.body === 'object' && 'data' in p.body) {\n return p.body.data as string;\n }\n }\n if (p && typeof p === 'object' && 'parts' in p) {\n const nested = findText(p.parts as unknown[]);\n if (nested) return nested;\n }\n }\n return null;\n };\n const raw = findText(parts as unknown[]) || (msg?.payload?.body && typeof msg.payload.body === 'object' && 'data' in msg.payload.body ? msg.payload.body.data : null) || null;\n if (raw) {\n bodyFull = safeBase64Decode(raw as string);\n } else {\n const findHtml = (partsArr: unknown[]): string | null => {\n for (const p of partsArr || []) {\n if (p && typeof p === 'object' && 'mimeType' in p && 'body' in p) {\n if (p.mimeType === 'text/html' && p.body && typeof p.body === 'object' && 'data' in p.body) {\n return p.body.data as string;\n }\n }\n if (p && typeof p === 'object' && 'parts' in p) {\n const nested = findHtml(p.parts as unknown[]);\n if (nested) return nested;\n }\n }\n return null;\n };\n const htmlPart = findHtml(parts as unknown[]);\n if (htmlPart) {\n bodyFull = safeBase64Decode(htmlPart).replace(/\\r\\n?/g, '\\n');\n }\n }\n }\n return [id, provider, threadId, to, from, cc, bcc, date, subject, labels, snippet, bodyFull];\n}\n"],"names":["buildContentForItems","toRowFromGmail","msg","opts","body","addressFormat","headerObj","toIsoUtc","headers","payload","Object","fromEntries","map","h","String","name","value","id","provider","threadId","to","extractEmails","To","join","fromInfo","extractFrom","From","from","address","cc","Cc","bcc","Bcc","date","Date","subject","Subject","labelIds","Array","isArray","labels","snippet","bodyFull","parts","findText","partsArr","p","mimeType","data","nested","raw","safeBase64Decode","findHtml","htmlPart","replace"],"mappings":";;;;;;;;;;;QAMSA;eAAAA,2BAAoB;;QAIbC;eAAAA;;;qBATqB;gCACJ;gCACR;8BACkB;;;;;AAMpC,SAASA;QAAeC,MAAAA,iEAA+B,CAAC,GAAGC,OAAAA,iEAA6D;QAAEC,MAAM;QAAOC,eAAe;IAAQ;qBAM1IC,eACIA,iBACf,OACWA,eACCA,gBACZC,OACED;QAXAJ;IAAhB,IAAMM,UAAUN,CAAAA,gBAAAA,2BAAAA,eAAAA,IAAKO,OAAO,cAAZP,mCAAAA,aAAcM,OAAO,KAAI,EAAE;IAC3C,IAAMF,YAAoCI,OAAOC,WAAW,CAAC,AAACH,CAAAA,WAAW,EAAE,AAAD,EAAGI,GAAG,CAAC,SAACC;;eAAM;YAACC,eAAOD,cAAAA,wBAAAA,EAAGE,IAAI,uCAAI;YAAKD,gBAAOD,cAAAA,wBAAAA,EAAGG,KAAK,yCAAI;SAAI;;IACvI,IAAMC,aAAKf,gBAAAA,0BAAAA,IAAKe,EAAE,uCAAI;IACtB,IAAMC,WAAW;IACjB,IAAMC,oBAAWjB,gBAAAA,0BAAAA,IAAKiB,QAAQ,yCAAI;IAClC,IAAMC,KAAKC,IAAAA,6BAAa,GAACf,gBAAAA,UAAUgB,EAAE,cAAZhB,2BAAAA,gBAAgB,IAAIiB,IAAI,CAAC;IAClD,IAAMC,WAAWC,IAAAA,2BAAW,GAACnB,kBAAAA,UAAUoB,IAAI,cAAdpB,6BAAAA,kBAAkB;IAC/C,IAAMqB,QAAQ,QAAA,AAACH,YAAYA,SAASI,OAAO,IAAKtB,UAAUoB,IAAI,cAAhD,mBAAA,QAAqD;IACnE,IAAMG,KAAKR,IAAAA,6BAAa,GAACf,gBAAAA,UAAUwB,EAAE,cAAZxB,2BAAAA,gBAAgB,IAAIiB,IAAI,CAAC;IAClD,IAAMQ,MAAMV,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AAO,CAAC,UAAU;YAC1D;QACF;IACF;IACA,OAAO;QAACrC;QAAIC;QAAUC;QAAUC;QAAIO;QAAME;QAAIE;QAAKE;QAAME;QAASK;QAAQC;QAASC;KAAS;AAC9F"}
@@ -1,4 +1,4 @@
1
- import type { gmail_v1 } from 'googleapis';
1
+ import type { gmail_v1 } from '@googleapis/gmail';
2
2
  export interface BodyExtractionOptions {
3
3
  /** Format to return: 'text' extracts plain text, 'html' preserves HTML structure */
4
4
  contentType?: 'text' | 'html';
@@ -1,4 +1,4 @@
1
- import type { gmail_v1 } from 'googleapis';
1
+ import type { gmail_v1 } from '@googleapis/gmail';
2
2
  export interface BodyExtractionOptions {
3
3
  /** Format to return: 'text' extracts plain text, 'html' preserves HTML structure */
4
4
  contentType?: 'text' | 'html';
@@ -1 +1 @@
1
- {"version":3,"sources":["/Users/kevin/Dev/OpenSource/ai/mcp-z/mcp-gmail/src/email/parsing/html-processing.ts"],"sourcesContent":["import { extractCurrentMessageFromHtml } from '@mcp-z/email';\nimport type { gmail_v1 } from 'googleapis';\nimport { parse } from 'node-html-parser';\n\nexport interface BodyExtractionOptions {\n /** Format to return: 'text' extracts plain text, 'html' preserves HTML structure */\n contentType?: 'text' | 'html';\n /** When true, removes quoted thread history from HTML content */\n excludeThreadHistory?: boolean;\n}\n\nexport function extractBodyFromPayload(payload: gmail_v1.Schema$MessagePart, options: BodyExtractionOptions = {}): string {\n const { contentType = 'text', excludeThreadHistory = false } = options;\n if (!payload) return '';\n\n // If there's a direct body with data\n if (payload.body?.data) {\n return Buffer.from(payload.body.data, 'base64').toString('utf-8');\n }\n\n // If there are parts, look for text/plain or text/html\n if (payload.parts && Array.isArray(payload.parts)) {\n for (const part of payload.parts) {\n if (part.mimeType === 'text/plain' && part.body?.data) {\n return Buffer.from(part.body.data, 'base64').toString('utf-8');\n }\n if (part.mimeType === 'text/html' && part.body?.data) {\n let html = Buffer.from(part.body.data, 'base64').toString('utf-8');\n\n // Remove thread history if requested\n if (excludeThreadHistory) {\n html = extractCurrentMessageFromHtml(html);\n }\n\n // Return HTML directly if requested\n if (contentType === 'html') {\n return html;\n }\n\n // Otherwise extract plain text from HTML\n const doc = parse(html);\n const docUnknown = doc as unknown;\n if (docUnknown && typeof docUnknown === 'object' && 'text' in docUnknown) {\n return docUnknown.text as string;\n }\n return '';\n }\n }\n }\n\n return '';\n}\n"],"names":["extractBodyFromPayload","payload","options","contentType","excludeThreadHistory","body","data","Buffer","from","toString","parts","Array","isArray","part","mimeType","html","extractCurrentMessageFromHtml","doc","parse","docUnknown","text"],"mappings":";;;;+BAWgBA;;;eAAAA;;;qBAX8B;8BAExB;;;;;AASf,SAASA,uBAAuBC,OAAoC;QAAEC,UAAAA,iEAAiC,CAAC;QAKzGD;IAJJ,2BAA+DC,QAAvDC,aAAAA,gDAAc,+DAAyCD,QAAjCE,sBAAAA,kEAAuB;IACrD,IAAI,CAACH,SAAS,OAAO;IAErB,qCAAqC;IACrC,KAAIA,gBAAAA,QAAQI,IAAI,cAAZJ,oCAAAA,cAAcK,IAAI,EAAE;QACtB,OAAOC,OAAOC,IAAI,CAACP,QAAQI,IAAI,CAACC,IAAI,EAAE,UAAUG,QAAQ,CAAC;IAC3D;IAEA,uDAAuD;IACvD,IAAIR,QAAQS,KAAK,IAAIC,MAAMC,OAAO,CAACX,QAAQS,KAAK,GAAG;YAC5C,kCAAA,2BAAA;;YAAL,QAAK,YAAcT,QAAQS,KAAK,qBAA3B,SAAA,6BAAA,QAAA,yBAAA,iCAA6B;gBAA7B,IAAMG,OAAN;oBACmCA,YAGDA;gBAHrC,IAAIA,KAAKC,QAAQ,KAAK,kBAAgBD,aAAAA,KAAKR,IAAI,cAATQ,iCAAAA,WAAWP,IAAI,GAAE;oBACrD,OAAOC,OAAOC,IAAI,CAACK,KAAKR,IAAI,CAACC,IAAI,EAAE,UAAUG,QAAQ,CAAC;gBACxD;gBACA,IAAII,KAAKC,QAAQ,KAAK,iBAAeD,cAAAA,KAAKR,IAAI,cAATQ,kCAAAA,YAAWP,IAAI,GAAE;oBACpD,IAAIS,OAAOR,OAAOC,IAAI,CAACK,KAAKR,IAAI,CAACC,IAAI,EAAE,UAAUG,QAAQ,CAAC;oBAE1D,qCAAqC;oBACrC,IAAIL,sBAAsB;wBACxBW,OAAOC,IAAAA,oCAA6B,EAACD;oBACvC;oBAEA,oCAAoC;oBACpC,IAAIZ,gBAAgB,QAAQ;wBAC1B,OAAOY;oBACT;oBAEA,yCAAyC;oBACzC,IAAME,MAAMC,IAAAA,qBAAK,EAACH;oBAClB,IAAMI,aAAaF;oBACnB,IAAIE,cAAc,CAAA,OAAOA,2CAAP,SAAOA,WAAS,MAAM,YAAY,UAAUA,YAAY;wBACxE,OAAOA,WAAWC,IAAI;oBACxB;oBACA,OAAO;gBACT;YACF;;YAzBK;YAAA;;;qBAAA,6BAAA;oBAAA;;;oBAAA;0BAAA;;;;IA0BP;IAEA,OAAO;AACT"}
1
+ {"version":3,"sources":["/Users/kevin/Dev/OpenSource/ai/mcp-z/mcp-gmail/src/email/parsing/html-processing.ts"],"sourcesContent":["import type { gmail_v1 } from '@googleapis/gmail';\nimport { extractCurrentMessageFromHtml } from '@mcp-z/email';\nimport { parse } from 'node-html-parser';\n\nexport interface BodyExtractionOptions {\n /** Format to return: 'text' extracts plain text, 'html' preserves HTML structure */\n contentType?: 'text' | 'html';\n /** When true, removes quoted thread history from HTML content */\n excludeThreadHistory?: boolean;\n}\n\nexport function extractBodyFromPayload(payload: gmail_v1.Schema$MessagePart, options: BodyExtractionOptions = {}): string {\n const { contentType = 'text', excludeThreadHistory = false } = options;\n if (!payload) return '';\n\n // If there's a direct body with data\n if (payload.body?.data) {\n return Buffer.from(payload.body.data, 'base64').toString('utf-8');\n }\n\n // If there are parts, look for text/plain or text/html\n if (payload.parts && Array.isArray(payload.parts)) {\n for (const part of payload.parts) {\n if (part.mimeType === 'text/plain' && part.body?.data) {\n return Buffer.from(part.body.data, 'base64').toString('utf-8');\n }\n if (part.mimeType === 'text/html' && part.body?.data) {\n let html = Buffer.from(part.body.data, 'base64').toString('utf-8');\n\n // Remove thread history if requested\n if (excludeThreadHistory) {\n html = extractCurrentMessageFromHtml(html);\n }\n\n // Return HTML directly if requested\n if (contentType === 'html') {\n return html;\n }\n\n // Otherwise extract plain text from HTML\n const doc = parse(html);\n const docUnknown = doc as unknown;\n if (docUnknown && typeof docUnknown === 'object' && 'text' in docUnknown) {\n return docUnknown.text as string;\n }\n return '';\n }\n }\n }\n\n return '';\n}\n"],"names":["extractBodyFromPayload","payload","options","contentType","excludeThreadHistory","body","data","Buffer","from","toString","parts","Array","isArray","part","mimeType","html","extractCurrentMessageFromHtml","doc","parse","docUnknown","text"],"mappings":";;;;+BAWgBA;;;eAAAA;;;qBAV8B;8BACxB;;;;;AASf,SAASA,uBAAuBC,OAAoC;QAAEC,UAAAA,iEAAiC,CAAC;QAKzGD;IAJJ,2BAA+DC,QAAvDC,aAAAA,gDAAc,+DAAyCD,QAAjCE,sBAAAA,kEAAuB;IACrD,IAAI,CAACH,SAAS,OAAO;IAErB,qCAAqC;IACrC,KAAIA,gBAAAA,QAAQI,IAAI,cAAZJ,oCAAAA,cAAcK,IAAI,EAAE;QACtB,OAAOC,OAAOC,IAAI,CAACP,QAAQI,IAAI,CAACC,IAAI,EAAE,UAAUG,QAAQ,CAAC;IAC3D;IAEA,uDAAuD;IACvD,IAAIR,QAAQS,KAAK,IAAIC,MAAMC,OAAO,CAACX,QAAQS,KAAK,GAAG;YAC5C,kCAAA,2BAAA;;YAAL,QAAK,YAAcT,QAAQS,KAAK,qBAA3B,SAAA,6BAAA,QAAA,yBAAA,iCAA6B;gBAA7B,IAAMG,OAAN;oBACmCA,YAGDA;gBAHrC,IAAIA,KAAKC,QAAQ,KAAK,kBAAgBD,aAAAA,KAAKR,IAAI,cAATQ,iCAAAA,WAAWP,IAAI,GAAE;oBACrD,OAAOC,OAAOC,IAAI,CAACK,KAAKR,IAAI,CAACC,IAAI,EAAE,UAAUG,QAAQ,CAAC;gBACxD;gBACA,IAAII,KAAKC,QAAQ,KAAK,iBAAeD,cAAAA,KAAKR,IAAI,cAATQ,kCAAAA,YAAWP,IAAI,GAAE;oBACpD,IAAIS,OAAOR,OAAOC,IAAI,CAACK,KAAKR,IAAI,CAACC,IAAI,EAAE,UAAUG,QAAQ,CAAC;oBAE1D,qCAAqC;oBACrC,IAAIL,sBAAsB;wBACxBW,OAAOC,IAAAA,oCAA6B,EAACD;oBACvC;oBAEA,oCAAoC;oBACpC,IAAIZ,gBAAgB,QAAQ;wBAC1B,OAAOY;oBACT;oBAEA,yCAAyC;oBACzC,IAAME,MAAMC,IAAAA,qBAAK,EAACH;oBAClB,IAAMI,aAAaF;oBACnB,IAAIE,cAAc,CAAA,OAAOA,2CAAP,SAAOA,WAAS,MAAM,YAAY,UAAUA,YAAY;wBACxE,OAAOA,WAAWC,IAAI;oBACxB;oBACA,OAAO;gBACT;YACF;;YAzBK;YAAA;;;qBAAA,6BAAA;oBAAA;;;oBAAA;0BAAA;;;;IA0BP;IAEA,OAAO;AACT"}
@@ -1,5 +1,5 @@
1
+ import type { gmail_v1 } from '@googleapis/gmail';
1
2
  import type { ExecutionResult } from '@mcp-z/email';
2
- import type { gmail_v1 } from 'googleapis';
3
3
  import type { GmailQuery as QueryNode } from '../../schemas/gmail-query-schema.js';
4
4
  import type { Logger } from '../../types.js';
5
5
  export interface ExecuteQueryOptions {
@@ -1,5 +1,5 @@
1
+ import type { gmail_v1 } from '@googleapis/gmail';
1
2
  import type { ExecutionResult } from '@mcp-z/email';
2
- import type { gmail_v1 } from 'googleapis';
3
3
  import type { GmailQuery as QueryNode } from '../../schemas/gmail-query-schema.js';
4
4
  import type { Logger } from '../../types.js';
5
5
  export interface ExecuteQueryOptions {
@@ -1 +1 @@
1
- {"version":3,"sources":["/Users/kevin/Dev/OpenSource/ai/mcp-z/mcp-gmail/src/email/querying/execute-query.ts"],"sourcesContent":["import type { ExecutionResult } from '@mcp-z/email';\nimport type { gmail_v1 } from 'googleapis';\nimport { MAX_PAGE_SIZE } from '../../constants.ts';\nimport type { GmailQuery as QueryNode } from '../../schemas/gmail-query-schema.ts';\nimport type { Logger } from '../../types.ts';\nimport { searchMessages } from './search-execution.ts';\n\nexport interface ExecuteQueryOptions {\n client: gmail_v1.Gmail;\n logger: Logger;\n pageSize?: number;\n pageToken?: string;\n includeBody?: boolean;\n}\n\n/**\n * Execute a Gmail query with direct, single-attempt execution.\n * No planning, no fallbacks, no retries.\n * Provider errors are returned directly to the caller for actionable feedback.\n */\nexport async function executeQuery<T>(query: QueryNode | undefined, options: ExecuteQueryOptions, transform: (item: unknown) => T): Promise<ExecutionResult<T>> {\n const { client, logger, pageSize, pageToken, includeBody } = options;\n\n // Validate pagination parameters\n if (pageSize !== undefined && (pageSize < 1 || pageSize > MAX_PAGE_SIZE)) {\n throw new Error(`pageSize must be between 1 and ${MAX_PAGE_SIZE}`);\n }\n\n if (pageToken !== undefined && typeof pageToken === 'string' && pageToken.trim().length === 0) {\n logger.info('Empty pageToken provided, ignoring');\n }\n\n // Single execution - direct query to Gmail API\n logger.info('executeQuery: executing direct Gmail query');\n\n try {\n const result = await searchMessages(client, {\n ...(query !== undefined && { query }),\n pageSize: pageSize ?? 50,\n pageToken: pageToken && pageToken.trim().length > 0 ? pageToken : undefined,\n includeBody: includeBody ?? false,\n logger,\n });\n\n // Transform results\n const transformedResults = result.messages.map(transform);\n\n logger.info(`executeQuery: succeeded with ${transformedResults.length} results`);\n\n return {\n success: true,\n items: transformedResults,\n metadata: {\n nextPageToken: result.nextPageToken,\n },\n };\n } catch (error) {\n // Re-throw errors directly - no fallback logic\n logger.error('executeQuery: failed', { error: error instanceof Error ? error.message : String(error) });\n throw error;\n }\n}\n"],"names":["executeQuery","query","options","transform","client","logger","pageSize","pageToken","includeBody","result","transformedResults","error","undefined","MAX_PAGE_SIZE","Error","trim","length","info","searchMessages","messages","map","success","items","metadata","nextPageToken","message","String"],"mappings":";;;;+BAoBsBA;;;eAAAA;;;2BAlBQ;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wBAAO;4BACLK,SAAS;4BACTC,OAAOZ;4BACPa,UAAU;gCACRC,eAAef,OAAOe,aAAa;4BACrC;wBACF;;;oBACOb;oBACP,+CAA+C;oBAC/CN,OAAOM,KAAK,CAAC,wBAAwB;wBAAEA,OAAOA,AAAK,YAALA,OAAiBG,SAAQH,MAAMc,OAAO,GAAGC,OAAOf;oBAAO;oBACrG,MAAMA;;;;;;;IAEV"}
1
+ {"version":3,"sources":["/Users/kevin/Dev/OpenSource/ai/mcp-z/mcp-gmail/src/email/querying/execute-query.ts"],"sourcesContent":["import type { gmail_v1 } from '@googleapis/gmail';\nimport type { ExecutionResult } from '@mcp-z/email';\nimport { MAX_PAGE_SIZE } from '../../constants.ts';\nimport type { GmailQuery as QueryNode } from '../../schemas/gmail-query-schema.ts';\nimport type { Logger } from '../../types.ts';\nimport { searchMessages } from './search-execution.ts';\n\nexport interface ExecuteQueryOptions {\n client: gmail_v1.Gmail;\n logger: Logger;\n pageSize?: number;\n pageToken?: string;\n includeBody?: boolean;\n}\n\n/**\n * Execute a Gmail query with direct, single-attempt execution.\n * No planning, no fallbacks, no retries.\n * Provider errors are returned directly to the caller for actionable feedback.\n */\nexport async function executeQuery<T>(query: QueryNode | undefined, options: ExecuteQueryOptions, transform: (item: unknown) => T): Promise<ExecutionResult<T>> {\n const { client, logger, pageSize, pageToken, includeBody } = options;\n\n // Validate pagination parameters\n if (pageSize !== undefined && (pageSize < 1 || pageSize > MAX_PAGE_SIZE)) {\n throw new Error(`pageSize must be between 1 and ${MAX_PAGE_SIZE}`);\n }\n\n if (pageToken !== undefined && typeof pageToken === 'string' && pageToken.trim().length === 0) {\n logger.info('Empty pageToken provided, ignoring');\n }\n\n // Single execution - direct query to Gmail API\n logger.info('executeQuery: executing direct Gmail query');\n\n try {\n const result = await searchMessages(client, {\n ...(query !== undefined && { query }),\n pageSize: pageSize ?? 50,\n pageToken: pageToken && pageToken.trim().length > 0 ? pageToken : undefined,\n includeBody: includeBody ?? false,\n logger,\n });\n\n // Transform results\n const transformedResults = result.messages.map(transform);\n\n logger.info(`executeQuery: succeeded with ${transformedResults.length} results`);\n\n return {\n success: true,\n items: transformedResults,\n metadata: {\n nextPageToken: result.nextPageToken,\n },\n };\n } catch (error) {\n // Re-throw errors directly - no fallback logic\n logger.error('executeQuery: failed', { error: error instanceof Error ? error.message : String(error) });\n throw error;\n }\n}\n"],"names":["executeQuery","query","options","transform","client","logger","pageSize","pageToken","includeBody","result","transformedResults","error","undefined","MAX_PAGE_SIZE","Error","trim","length","info","searchMessages","messages","map","success","items","metadata","nextPageToken","message","String"],"mappings":";;;;+BAoBsBA;;;eAAAA;;;2BAlBQ;iCAGC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAexB,SAAeA,aAAgBC,KAA4B,EAAEC,OAA4B,EAAEC,SAA+B;;YACvHC,QAAQC,QAAQC,UAAUC,WAAWC,aAerCC,QASAC,oBAWCC;;;;oBAnCDP,SAAqDF,QAArDE,QAAQC,SAA6CH,QAA7CG,QAAQC,WAAqCJ,QAArCI,UAAUC,YAA2BL,QAA3BK,WAAWC,cAAgBN,QAAhBM;oBAE7C,iCAAiC;oBACjC,IAAIF,aAAaM,aAAcN,CAAAA,WAAW,KAAKA,WAAWO,0BAAa,AAAD,GAAI;wBACxE,MAAM,IAAIC,MAAM,AAAC,kCAA+C,OAAdD,0BAAa;oBACjE;oBAEA,IAAIN,cAAcK,aAAa,OAAOL,cAAc,YAAYA,UAAUQ,IAAI,GAAGC,MAAM,KAAK,GAAG;wBAC7FX,OAAOY,IAAI,CAAC;oBACd;oBAEA,+CAA+C;oBAC/CZ,OAAOY,IAAI,CAAC;;;;;;;;;oBAGK;;wBAAMC,IAAAA,iCAAc,EAACd,QAAQ,wCACtCH,UAAUW,aAAa;4BAAEX,OAAAA;wBAAM;4BACnCK,QAAQ,EAAEA,qBAAAA,sBAAAA,WAAY;4BACtBC,WAAWA,aAAaA,UAAUQ,IAAI,GAAGC,MAAM,GAAG,IAAIT,YAAYK;4BAClEJ,WAAW,EAAEA,wBAAAA,yBAAAA,cAAe;4BAC5BH,QAAAA;;;;oBALII,SAAS;oBAQf,oBAAoB;oBACdC,qBAAqBD,OAAOU,QAAQ,CAACC,GAAG,CAACjB;oBAE/CE,OAAOY,IAAI,CAAC,AAAC,gCAAyD,OAA1BP,mBAAmBM,MAAM,EAAC;oBAEtE;;wBAAO;4BACLK,SAAS;4BACTC,OAAOZ;4BACPa,UAAU;gCACRC,eAAef,OAAOe,aAAa;4BACrC;wBACF;;;oBACOb;oBACP,+CAA+C;oBAC/CN,OAAOM,KAAK,CAAC,wBAAwB;wBAAEA,OAAOA,AAAK,YAALA,OAAiBG,SAAQH,MAAMc,OAAO,GAAGC,OAAOf;oBAAO;oBACrG,MAAMA;;;;;;;IAEV"}
@@ -1,5 +1,5 @@
1
1
  /** Gmail pagination helpers for single-page operations. */
2
- import type { gmail_v1 } from 'googleapis';
2
+ import type { gmail_v1 } from '@googleapis/gmail';
3
3
  import type { Logger } from '../../types.js';
4
4
  export interface SinglePageResult {
5
5
  readonly messages: gmail_v1.Schema$Message[];
@@ -1,5 +1,5 @@
1
1
  /** Gmail pagination helpers for single-page operations. */
2
- import type { gmail_v1 } from 'googleapis';
2
+ import type { gmail_v1 } from '@googleapis/gmail';
3
3
  import type { Logger } from '../../types.js';
4
4
  export interface SinglePageResult {
5
5
  readonly messages: gmail_v1.Schema$Message[];
@@ -1 +1 @@
1
- {"version":3,"sources":["/Users/kevin/Dev/OpenSource/ai/mcp-z/mcp-gmail/src/email/querying/pagination.ts"],"sourcesContent":["/** Gmail pagination helpers for single-page operations. */\n\nimport type { gmail_v1 } from 'googleapis';\nimport type { Logger } from '../../types.ts';\n\nexport interface SinglePageResult {\n readonly messages: gmail_v1.Schema$Message[];\n readonly nextPageToken: string | undefined;\n}\n\n/**\n * Fetch a single page of messages from Gmail\n */\nexport interface FetchMessagesPageParams {\n readonly gmailQ: string;\n readonly pageSize?: number;\n readonly pageToken: string | undefined;\n readonly body?: boolean;\n readonly logger: Logger;\n readonly metadataHeaders?: readonly string[];\n}\n\nexport async function fetchMessagesPage(gmail: gmail_v1.Gmail, params: FetchMessagesPageParams): Promise<SinglePageResult> {\n const { gmailQ, pageSize = 50, pageToken, body = false, logger, metadataHeaders } = params;\n\n // Secure resource bounds checking - prevent security bypasses\n const maxPageSize = 500; // Gmail API maximum - enforced for security\n const minPageSize = 1; // Minimum valid page size\n\n // Validate input is a positive number to prevent bypass attempts\n if (!Number.isInteger(pageSize) || pageSize < 0) {\n throw new Error(`Invalid pageSize: must be a positive integer, got ${pageSize}`);\n }\n\n const safePageSize = Math.min(Math.max(minPageSize, pageSize), maxPageSize);\n\n if (pageSize !== safePageSize && logger) {\n logger.info('Page size bounded for API safety', { requested: pageSize, applied: safePageSize });\n // No fallback to console - would corrupt MCP stdio communication\n }\n\n try {\n const listParams = {\n userId: 'me',\n q: gmailQ,\n maxResults: safePageSize,\n };\n const listResponse = pageToken && pageToken.trim().length > 0 ? await gmail.users.messages.list({ ...listParams, pageToken }) : await gmail.users.messages.list(listParams);\n const response = listResponse.data;\n const messages = response.messages || [];\n\n if (messages.length === 0) {\n if (logger) logger.info('No messages found on page');\n return { messages: [], nextPageToken: undefined };\n }\n\n const items = messages.map((m: gmail_v1.Schema$Message) => m.id).filter(Boolean) as string[];\n if (items.length === 0) {\n if (logger) logger.info('No valid message ids on page');\n return { messages: [], nextPageToken: response.nextPageToken && response.nextPageToken.trim().length > 0 ? response.nextPageToken : undefined };\n }\n\n const concurrentArgs: FetchMessagesConcurrentlyParams = {\n items,\n concurrency: 5,\n body,\n ...(logger && { logger }),\n ...(metadataHeaders && { metadataHeaders }),\n };\n const detailedMessages = await fetchMessagesConcurrently(gmail, concurrentArgs);\n\n if (logger) logger.info(`Fetched page with ${detailedMessages.length} messages`);\n return {\n messages: detailedMessages,\n nextPageToken: response.nextPageToken && response.nextPageToken.trim().length > 0 ? response.nextPageToken : undefined,\n };\n } catch (error) {\n // Standardized error handling for pagination pipeline\n const errorMessage = error instanceof Error ? error.message : String(error);\n if (logger)\n logger.error('Gmail pagination: single page fetch failed', {\n error: errorMessage,\n query: gmailQ,\n pageSize: safePageSize,\n hasPageToken: !!pageToken,\n });\n\n // Preserve original error type for upstream handling\n if (error instanceof Error) {\n // Enhance error with pagination context\n error.message = `Gmail pagination fetch failed: ${error.message}`;\n throw error;\n }\n\n // Convert non-Error objects to proper Error instances\n throw new Error(`Gmail pagination fetch failed: ${errorMessage}`);\n }\n}\n\nexport interface FetchMessagesConcurrentlyParams {\n readonly items: readonly string[];\n readonly concurrency?: number;\n readonly body?: boolean;\n readonly logger: Logger;\n readonly metadataHeaders?: readonly string[];\n}\n\nexport async function fetchMessagesConcurrently(gmail: gmail_v1.Gmail, params: FetchMessagesConcurrentlyParams): Promise<gmail_v1.Schema$Message[]> {\n const { items, concurrency = 2, body = false, logger, metadataHeaders } = params;\n\n // Secure resource bounds checking for concurrent operations\n const maxConcurrency = 10; // Conservative limit to prevent rate limiting and resource exhaustion\n const minConcurrency = 1; // Minimum valid concurrency\n\n // Validate input is a positive number to prevent bypass attempts\n if (!Number.isInteger(concurrency) || concurrency < 0) {\n throw new Error(`Invalid concurrency: must be a positive integer, got ${concurrency}`);\n }\n\n const safeConcurrency = Math.min(Math.max(minConcurrency, concurrency), maxConcurrency);\n\n if (concurrency !== safeConcurrency && logger) {\n logger.info('Concurrency bounded for API safety', { requested: concurrency, applied: safeConcurrency });\n // No fallback to console - would corrupt MCP stdio communication\n }\n\n if (items.length === 0) return [];\n\n const results: (gmail_v1.Schema$Message | null)[] = new Array(items.length);\n const format = body ? 'full' : 'metadata';\n // Always pass metadataHeaders if provided - body doesn't replace headers, it's additional content\n const metadataHeadersForRequest = metadataHeaders;\n\n // Pre-build request parameters to avoid repeated object creation\n const requestParams = items.map((id) => {\n const baseParams = {\n userId: 'me' as const,\n id,\n format,\n };\n // Only include metadataHeaders if defined (exactOptionalPropertyTypes compliance)\n return metadataHeadersForRequest ? { ...baseParams, metadataHeaders: [...metadataHeadersForRequest] } : baseParams;\n });\n\n // Optimize concurrent processing using batching\n const batchSize = safeConcurrency;\n const batches: (typeof requestParams)[] = [];\n for (let i = 0; i < requestParams.length; i += batchSize) {\n batches.push(requestParams.slice(i, i + batchSize));\n }\n\n let processedCount = 0;\n for (const batch of batches) {\n const batchPromises = batch.map(async (params, batchIndex) => {\n try {\n const messageResponse = await gmail.users.messages.get(params);\n const globalIndex = processedCount + batchIndex;\n results[globalIndex] = messageResponse.data;\n return messageResponse.data;\n } catch (error) {\n // Log individual message fetch failures but continue processing\n const errorMessage = error instanceof Error ? error.message : String(error);\n if (logger)\n logger.info('Gmail pagination: individual message fetch failed, continuing', {\n error: errorMessage,\n messageId: params.id,\n globalIndex: processedCount + batchIndex,\n });\n return null; // Mark as failed but continue\n }\n });\n\n await Promise.all(batchPromises);\n processedCount += batch.length;\n\n // Progress logging for large batches\n if (items.length > 20) {\n if (logger) logger.info(`Gmail pagination: processed ${processedCount}/${items.length} messages`);\n }\n }\n\n // Filter out any null results from failed individual fetches\n return results.filter((result) => result !== null && result !== undefined);\n}\n"],"names":["fetchMessagesConcurrently","fetchMessagesPage","gmail","params","gmailQ","pageSize","pageToken","body","logger","metadataHeaders","maxPageSize","minPageSize","safePageSize","listParams","listResponse","response","messages","items","concurrentArgs","detailedMessages","error","errorMessage","Number","isInteger","Error","Math","min","max","info","requested","applied","userId","q","maxResults","trim","length","users","list","data","nextPageToken","undefined","map","m","id","filter","Boolean","concurrency","message","String","query","hasPageToken","maxConcurrency","minConcurrency","safeConcurrency","results","format","metadataHeadersForRequest","requestParams","batchSize","batches","i","processedCount","batch","batchPromises","Array","baseParams","push","slice","batchIndex","messageResponse","globalIndex","get","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2CAAM,8BAA8B;;;;;;;wBAE/C;;oBAEA;;wBAAMK,QAAQC,GAAG,CAACX;;;oBAAlB;oBACAF,kBAAkBC,MAAM3B,MAAM;oBAE9B,qCAAqC;oBACrC,IAAIlB,MAAMkB,MAAM,GAAG,IAAI;wBACrB,IAAI3B,QAAQA,OAAOoB,IAAI,CAAC,AAAC,+BAAgDX,OAAlB4C,gBAAe,KAAgB,OAAb5C,MAAMkB,MAAM,EAAC;oBACxF;;;oBA1BG;;;;;;;;;;;;oBAAA;oBAAA;;;;;;;6BAAA,6BAAA;4BAAA;;;4BAAA;kCAAA;;;;;;;oBA6BL,6DAA6D;oBAC7D;;wBAAOmB,QAAQV,MAAM,CAAC,SAAC+B;mCAAWA,WAAW,QAAQA,WAAWnC;;;;;IAClE"}
1
+ {"version":3,"sources":["/Users/kevin/Dev/OpenSource/ai/mcp-z/mcp-gmail/src/email/querying/pagination.ts"],"sourcesContent":["/** Gmail pagination helpers for single-page operations. */\n\nimport type { gmail_v1 } from '@googleapis/gmail';\nimport type { Logger } from '../../types.ts';\n\nexport interface SinglePageResult {\n readonly messages: gmail_v1.Schema$Message[];\n readonly nextPageToken: string | undefined;\n}\n\n/**\n * Fetch a single page of messages from Gmail\n */\nexport interface FetchMessagesPageParams {\n readonly gmailQ: string;\n readonly pageSize?: number;\n readonly pageToken: string | undefined;\n readonly body?: boolean;\n readonly logger: Logger;\n readonly metadataHeaders?: readonly string[];\n}\n\nexport async function fetchMessagesPage(gmail: gmail_v1.Gmail, params: FetchMessagesPageParams): Promise<SinglePageResult> {\n const { gmailQ, pageSize = 50, pageToken, body = false, logger, metadataHeaders } = params;\n\n // Secure resource bounds checking - prevent security bypasses\n const maxPageSize = 500; // Gmail API maximum - enforced for security\n const minPageSize = 1; // Minimum valid page size\n\n // Validate input is a positive number to prevent bypass attempts\n if (!Number.isInteger(pageSize) || pageSize < 0) {\n throw new Error(`Invalid pageSize: must be a positive integer, got ${pageSize}`);\n }\n\n const safePageSize = Math.min(Math.max(minPageSize, pageSize), maxPageSize);\n\n if (pageSize !== safePageSize && logger) {\n logger.info('Page size bounded for API safety', { requested: pageSize, applied: safePageSize });\n // No fallback to console - would corrupt MCP stdio communication\n }\n\n try {\n const listParams = {\n userId: 'me',\n q: gmailQ,\n maxResults: safePageSize,\n };\n const listResponse = pageToken && pageToken.trim().length > 0 ? await gmail.users.messages.list({ ...listParams, pageToken }) : await gmail.users.messages.list(listParams);\n const response = listResponse.data;\n const messages = response.messages || [];\n\n if (messages.length === 0) {\n if (logger) logger.info('No messages found on page');\n return { messages: [], nextPageToken: undefined };\n }\n\n const items = messages.map((m: gmail_v1.Schema$Message) => m.id).filter(Boolean) as string[];\n if (items.length === 0) {\n if (logger) logger.info('No valid message ids on page');\n return { messages: [], nextPageToken: response.nextPageToken && response.nextPageToken.trim().length > 0 ? response.nextPageToken : undefined };\n }\n\n const concurrentArgs: FetchMessagesConcurrentlyParams = {\n items,\n concurrency: 5,\n body,\n ...(logger && { logger }),\n ...(metadataHeaders && { metadataHeaders }),\n };\n const detailedMessages = await fetchMessagesConcurrently(gmail, concurrentArgs);\n\n if (logger) logger.info(`Fetched page with ${detailedMessages.length} messages`);\n return {\n messages: detailedMessages,\n nextPageToken: response.nextPageToken && response.nextPageToken.trim().length > 0 ? response.nextPageToken : undefined,\n };\n } catch (error) {\n // Standardized error handling for pagination pipeline\n const errorMessage = error instanceof Error ? error.message : String(error);\n if (logger)\n logger.error('Gmail pagination: single page fetch failed', {\n error: errorMessage,\n query: gmailQ,\n pageSize: safePageSize,\n hasPageToken: !!pageToken,\n });\n\n // Preserve original error type for upstream handling\n if (error instanceof Error) {\n // Enhance error with pagination context\n error.message = `Gmail pagination fetch failed: ${error.message}`;\n throw error;\n }\n\n // Convert non-Error objects to proper Error instances\n throw new Error(`Gmail pagination fetch failed: ${errorMessage}`);\n }\n}\n\nexport interface FetchMessagesConcurrentlyParams {\n readonly items: readonly string[];\n readonly concurrency?: number;\n readonly body?: boolean;\n readonly logger: Logger;\n readonly metadataHeaders?: readonly string[];\n}\n\nexport async function fetchMessagesConcurrently(gmail: gmail_v1.Gmail, params: FetchMessagesConcurrentlyParams): Promise<gmail_v1.Schema$Message[]> {\n const { items, concurrency = 2, body = false, logger, metadataHeaders } = params;\n\n // Secure resource bounds checking for concurrent operations\n const maxConcurrency = 10; // Conservative limit to prevent rate limiting and resource exhaustion\n const minConcurrency = 1; // Minimum valid concurrency\n\n // Validate input is a positive number to prevent bypass attempts\n if (!Number.isInteger(concurrency) || concurrency < 0) {\n throw new Error(`Invalid concurrency: must be a positive integer, got ${concurrency}`);\n }\n\n const safeConcurrency = Math.min(Math.max(minConcurrency, concurrency), maxConcurrency);\n\n if (concurrency !== safeConcurrency && logger) {\n logger.info('Concurrency bounded for API safety', { requested: concurrency, applied: safeConcurrency });\n // No fallback to console - would corrupt MCP stdio communication\n }\n\n if (items.length === 0) return [];\n\n const results: (gmail_v1.Schema$Message | null)[] = new Array(items.length);\n const format = body ? 'full' : 'metadata';\n // Always pass metadataHeaders if provided - body doesn't replace headers, it's additional content\n const metadataHeadersForRequest = metadataHeaders;\n\n // Pre-build request parameters to avoid repeated object creation\n const requestParams = items.map((id) => {\n const baseParams = {\n userId: 'me' as const,\n id,\n format,\n };\n // Only include metadataHeaders if defined (exactOptionalPropertyTypes compliance)\n return metadataHeadersForRequest ? { ...baseParams, metadataHeaders: [...metadataHeadersForRequest] } : baseParams;\n });\n\n // Optimize concurrent processing using batching\n const batchSize = safeConcurrency;\n const batches: (typeof requestParams)[] = [];\n for (let i = 0; i < requestParams.length; i += batchSize) {\n batches.push(requestParams.slice(i, i + batchSize));\n }\n\n let processedCount = 0;\n for (const batch of batches) {\n const batchPromises = batch.map(async (params, batchIndex) => {\n try {\n const messageResponse = await gmail.users.messages.get(params);\n const globalIndex = processedCount + batchIndex;\n results[globalIndex] = messageResponse.data;\n return messageResponse.data;\n } catch (error) {\n // Log individual message fetch failures but continue processing\n const errorMessage = error instanceof Error ? error.message : String(error);\n if (logger)\n logger.info('Gmail pagination: individual message fetch failed, continuing', {\n error: errorMessage,\n messageId: params.id,\n globalIndex: processedCount + batchIndex,\n });\n return null; // Mark as failed but continue\n }\n });\n\n await Promise.all(batchPromises);\n processedCount += batch.length;\n\n // Progress logging for large batches\n if (items.length > 20) {\n if (logger) logger.info(`Gmail pagination: processed ${processedCount}/${items.length} messages`);\n }\n }\n\n // Filter out any null results from failed individual fetches\n return results.filter((result) => result !== null && result !== undefined);\n}\n"],"names":["fetchMessagesConcurrently","fetchMessagesPage","gmail","params","gmailQ","pageSize","pageToken","body","logger","metadataHeaders","maxPageSize","minPageSize","safePageSize","listParams","listResponse","response","messages","items","concurrentArgs","detailedMessages","error","errorMessage","Number","isInteger","Error","Math","min","max","info","requested","applied","userId","q","maxResults","trim","length","users","list","data","nextPageToken","undefined","map","m","id","filter","Boolean","concurrency","message","String","query","hasPageToken","maxConcurrency","minConcurrency","safeConcurrency","results","format","metadataHeadersForRequest","requestParams","batchSize","batches","i","processedCount","batch","batchPromises","Array","baseParams","push","slice","batchIndex","messageResponse","globalIndex","get","messageId","Promise","all","result"],"mappings":"AAAA,yDAAyD;;;;;;;;;;;QA2GnCA;eAAAA;;QArFAC;eAAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAf,SAAeA,kBAAkBC,KAAqB,EAAEC,MAA+B;;YACpFC,0BAAQC,UAAeC,yBAAWC,MAAcC,QAAQC,iBAG1DC,aACAC,aAOAC,cAQEC,YAKAC,oBACAC,UACAC,UAOAC,OAMAC,gBAOAC,kBAOCC,OAEDC;;;;oBAvDAjB,SAA4ED,OAA5EC,2BAA4ED,OAApEE,UAA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';
2
2
  import type { GmailQuery as QueryNode } from '../../schemas/gmail-query-schema.js';
3
3
  import type { Logger } from '../../types.js';
4
4
  export interface GmailSearchOptions {
@@ -1,4 +1,4 @@
1
- import type { gmail_v1 } from 'googleapis';
1
+ import type { gmail_v1 } from '@googleapis/gmail';
2
2
  import type { GmailQuery as QueryNode } from '../../schemas/gmail-query-schema.js';
3
3
  import type { Logger } from '../../types.js';
4
4
  export interface GmailSearchOptions {
@@ -1 +1 @@
1
- {"version":3,"sources":["/Users/kevin/Dev/OpenSource/ai/mcp-z/mcp-gmail/src/email/querying/search-execution.ts"],"sourcesContent":["import type { gmail_v1 } from 'googleapis';\nimport type { GmailQuery as QueryNode } from '../../schemas/gmail-query-schema.ts';\nimport type { Logger } from '../../types.ts';\nimport { type FetchMessagesPageParams, fetchMessagesPage } from './pagination.ts';\nimport { toGmailQuery } from './query-builder.ts';\n\nexport interface GmailSearchOptions {\n readonly query?: QueryNode;\n readonly pageSize?: number;\n readonly includeBody?: boolean;\n readonly pageToken: string | undefined; // For pagination support - explicit undefined allowed\n readonly logger: Logger;\n}\n\nexport interface GmailEmailSummary {\n readonly id: string;\n readonly provider: 'gmail';\n readonly threadId?: string;\n readonly date?: string;\n readonly from?: string;\n readonly fromName?: string;\n readonly to?: string;\n readonly cc?: string;\n readonly bcc?: string;\n readonly subject?: string;\n readonly snippet?: string;\n readonly body?: string;\n}\n\nfunction buildGmailQ(query: QueryNode | undefined): string {\n if (!query) return '';\n const emitted = toGmailQuery(query);\n return emitted?.q ?? '';\n}\n\nexport interface GmailSearchResult {\n readonly messages: gmail_v1.Schema$Message[]; // Raw Gmail API messages for transformation by caller\n readonly nextPageToken: string | undefined;\n}\n\nexport async function searchMessages(gmail: gmail_v1.Gmail, opts: GmailSearchOptions): Promise<GmailSearchResult> {\n const { query, pageSize = 50, includeBody = false, pageToken, logger } = opts;\n const gmailQ = buildGmailQ(query);\n const metadataHeaders = ['Date', 'Subject', 'From', 'To', 'Cc', 'Bcc'];\n // Always fetch metadata headers - body is additional content, not a replacement for headers\n const pageParams: FetchMessagesPageParams = {\n gmailQ,\n pageSize,\n body: includeBody,\n metadataHeaders,\n pageToken,\n logger,\n };\n const result = await fetchMessagesPage(gmail, pageParams);\n\n // Return raw Gmail messages - transformation happens in caller\n return {\n messages: result.messages,\n nextPageToken: result.nextPageToken,\n };\n}\n"],"names":["searchMessages","buildGmailQ","query","emitted","toGmailQuery","q","gmail","opts","pageSize","includeBody","pageToken","logger","gmailQ","metadataHeaders","pageParams","result","body","fetchMessagesPage","messages","nextPageToken"],"mappings":";;;;+BAwCsBA;;;eAAAA;;;4BArC0C;8BACnC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAyB7B,SAASC,YAAYC,KAA4B;;IAC/C,IAAI,CAACA,OAAO,OAAO;IACnB,IAAMC,UAAUC,IAAAA,4BAAY,EAACF;IAC7B,eAAOC,oBAAAA,8BAAAA,QAASE,CAAC,uCAAI;AACvB;AAOO,SAAeL,eAAeM,KAAqB,EAAEC,IAAwB;;YAC1EL,uBAAOM,6BAAeC,aAAqBC,WAAWC,QACxDC,QACAC,iBAEAC,YAQAC;;;;oBAZEb,QAAiEK,KAAjEL,wBAAiEK,KAA1DC,UAAAA,uCAAW,yCAA+CD,KAA3CE,aAAAA,6CAAc,2BAAOC,YAAsBH,KAAtBG,WAAWC,SAAWJ,KAAXI;oBACxDC,SAASX,YAAYC;oBACrBW;wBAAmB;wBAAQ;wBAAW;wBAAQ;wBAAM;wBAAM;;oBAChE,4FAA4F;oBACtFC,aAAsC;wBAC1CF,QAAAA;wBACAJ,UAAAA;wBACAQ,MAAMP;wBACNI,iBAAAA;wBACAH,WAAAA;wBACAC,QAAAA;oBACF;oBACe;;wBAAMM,IAAAA,+BAAiB,EAACX,OAAOQ;;;oBAAxCC,SAAS;oBAEf,+DAA+D;oBAC/D;;wBAAO;4BACLG,UAAUH,OAAOG,QAAQ;4BACzBC,eAAeJ,OAAOI,aAAa;wBACrC;;;;IACF"}
1
+ {"version":3,"sources":["/Users/kevin/Dev/OpenSource/ai/mcp-z/mcp-gmail/src/email/querying/search-execution.ts"],"sourcesContent":["import type { gmail_v1 } from '@googleapis/gmail';\nimport type { GmailQuery as QueryNode } from '../../schemas/gmail-query-schema.ts';\nimport type { Logger } from '../../types.ts';\nimport { type FetchMessagesPageParams, fetchMessagesPage } from './pagination.ts';\nimport { toGmailQuery } from './query-builder.ts';\n\nexport interface GmailSearchOptions {\n readonly query?: QueryNode;\n readonly pageSize?: number;\n readonly includeBody?: boolean;\n readonly pageToken: string | undefined; // For pagination support - explicit undefined allowed\n readonly logger: Logger;\n}\n\nexport interface GmailEmailSummary {\n readonly id: string;\n readonly provider: 'gmail';\n readonly threadId?: string;\n readonly date?: string;\n readonly from?: string;\n readonly fromName?: string;\n readonly to?: string;\n readonly cc?: string;\n readonly bcc?: string;\n readonly subject?: string;\n readonly snippet?: string;\n readonly body?: string;\n}\n\nfunction buildGmailQ(query: QueryNode | undefined): string {\n if (!query) return '';\n const emitted = toGmailQuery(query);\n return emitted?.q ?? '';\n}\n\nexport interface GmailSearchResult {\n readonly messages: gmail_v1.Schema$Message[]; // Raw Gmail API messages for transformation by caller\n readonly nextPageToken: string | undefined;\n}\n\nexport async function searchMessages(gmail: gmail_v1.Gmail, opts: GmailSearchOptions): Promise<GmailSearchResult> {\n const { query, pageSize = 50, includeBody = false, pageToken, logger } = opts;\n const gmailQ = buildGmailQ(query);\n const metadataHeaders = ['Date', 'Subject', 'From', 'To', 'Cc', 'Bcc'];\n // Always fetch metadata headers - body is additional content, not a replacement for headers\n const pageParams: FetchMessagesPageParams = {\n gmailQ,\n pageSize,\n body: includeBody,\n metadataHeaders,\n pageToken,\n logger,\n };\n const result = await fetchMessagesPage(gmail, pageParams);\n\n // Return raw Gmail messages - transformation happens in caller\n return {\n messages: result.messages,\n nextPageToken: result.nextPageToken,\n };\n}\n"],"names":["searchMessages","buildGmailQ","query","emitted","toGmailQuery","q","gmail","opts","pageSize","includeBody","pageToken","logger","gmailQ","metadataHeaders","pageParams","result","body","fetchMessagesPage","messages","nextPageToken"],"mappings":";;;;+BAwCsBA;;;eAAAA;;;4BArC0C;8BACnC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAyB7B,SAASC,YAAYC,KAA4B;;IAC/C,IAAI,CAACA,OAAO,OAAO;IACnB,IAAMC,UAAUC,IAAAA,4BAAY,EAACF;IAC7B,eAAOC,oBAAAA,8BAAAA,QAASE,CAAC,uCAAI;AACvB;AAOO,SAAeL,eAAeM,KAAqB,EAAEC,IAAwB;;YAC1EL,uBAAOM,6BAAeC,aAAqBC,WAAWC,QACxDC,QACAC,iBAEAC,YAQAC;;;;oBAZEb,QAAiEK,KAAjEL,wBAAiEK,KAA1DC,UAAAA,uCAAW,yCAA+CD,KAA3CE,aAAAA,6CAAc,2BAAOC,YAAsBH,KAAtBG,WAAWC,SAAWJ,KAAXI;oBACxDC,SAASX,YAAYC;oBACrBW;wBAAmB;wBAAQ;wBAAW;wBAAQ;wBAAM;wBAAM;;oBAChE,4FAA4F;oBACtFC,aAAsC;wBAC1CF,QAAAA;wBACAJ,UAAAA;wBACAQ,MAAMP;wBACNI,iBAAAA;wBACAH,WAAAA;wBACAC,QAAAA;oBACF;oBACe;;wBAAMM,IAAAA,+BAAiB,EAACX,OAAOQ;;;oBAAxCC,SAAS;oBAEf,+DAA+D;oBAC/D;;wBAAO;4BACLG,UAAUH,OAAOG,QAAQ;4BACzBC,eAAeJ,OAAOI,aAAa;wBACrC;;;;IACF"}
@@ -1 +1 @@
1
- {"version":3,"sources":["/Users/kevin/Dev/OpenSource/ai/mcp-z/mcp-gmail/src/index.ts"],"sourcesContent":["import { handleVersionHelp } from './setup/version-help.ts';\nimport type { ServerConfig } from './types.ts';\n\nexport { GOOGLE_SCOPE } from './constants.ts';\nexport * as mcp from './mcp/index.ts';\n// Export types and schemas for documentation\nexport type { Input as CategoriesListInput } from './mcp/tools/categories-list.ts';\nexport { inputSchema as CategoriesListInputSchema } from './mcp/tools/categories-list.ts';\nexport type { Input as LabelsListInput } from './mcp/tools/labels-list.ts';\nexport { inputSchema as LabelsListInputSchema } from './mcp/tools/labels-list.ts';\nexport * as schemas from './schemas/index.ts';\nexport * as setup from './setup/index.ts';\nexport * from './types.ts';\n\nexport async function startServer(config: ServerConfig): Promise<void> {\n // createHTTPServer/createStdioServer pull in @modelcontextprotocol/sdk and every mcp/tools/*.ts\n // (googleapis included); deferred so a --version/--help run never reaches them.\n const { createHTTPServer } = await import('./setup/http.ts');\n const { createStdioServer } = await import('./setup/stdio.ts');\n const { logger, close } = config.transport.type === 'stdio' ? await createStdioServer(config) : await createHTTPServer(config);\n\n process.on('SIGINT', async () => {\n await close();\n process.exit(0);\n });\n\n logger.info(`Server started with ${config.transport.type} transport`);\n await new Promise(() => {});\n}\n\nexport default async function main(): Promise<void> {\n // Check for help/version flags FIRST, before config parsing\n const versionHelpResult = handleVersionHelp(process.argv);\n if (versionHelpResult.handled) {\n console.log(versionHelpResult.output);\n process.exit(0);\n }\n\n // Only parse config if no help/version flags. config.ts's own heavy imports (@mcp-z/oauth-google,\n // @mcp-z/server) are deferred internally, so this static-looking call stays cheap until here.\n const { createConfig } = await import('./setup/config.ts');\n const config = createConfig();\n await startServer(config);\n}\n\nif (process.argv[1] === new URL(import.meta.url).pathname) {\n main();\n}\n"],"names":["CategoriesListInputSchema","inputSchema","GOOGLE_SCOPE","LabelsListInputSchema","main","mcp","schemas","setup","startServer","config","createHTTPServer","createStdioServer","logger","close","transport","type","process","on","exit","info","Promise","versionHelpResult","createConfig","handleVersionHelp","argv","handled","console","log","output","URL","pathname"],"mappings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AAkBO,MAAM;wBACpCZ,QAAQE,IAAI,CAAC;oBACf;oBAIyB;;wBAAM;2EAAA,QAAO;;;;oBAA9BI,eAAiB,cAAjBA;oBACFb,SAASa;oBACf;;wBAAMd,YAAYC;;;oBAAlB;;;;;;IACF;;AAEA,IAAIO,QAAQQ,IAAI,CAAC,EAAE,KAAK,IAAIK,IAAI,qDAAiBC,QAAQ,EAAE;IACzD1B;AACF"}
1
+ {"version":3,"sources":["/Users/kevin/Dev/OpenSource/ai/mcp-z/mcp-gmail/src/index.ts"],"sourcesContent":["import { handleVersionHelp } from './setup/version-help.ts';\nimport type { ServerConfig } from './types.ts';\n\nexport { GOOGLE_SCOPE } from './constants.ts';\nexport * as mcp from './mcp/index.ts';\n// Export types and schemas for documentation\nexport type { Input as CategoriesListInput } from './mcp/tools/categories-list.ts';\nexport { inputSchema as CategoriesListInputSchema } from './mcp/tools/categories-list.ts';\nexport type { Input as LabelsListInput } from './mcp/tools/labels-list.ts';\nexport { inputSchema as LabelsListInputSchema } from './mcp/tools/labels-list.ts';\nexport * as schemas from './schemas/index.ts';\nexport * as setup from './setup/index.ts';\nexport * from './types.ts';\n\nexport async function startServer(config: ServerConfig): Promise<void> {\n // createHTTPServer/createStdioServer pull in @mcp-z/server and every mcp/tools/*.ts\n // (googleapis included); deferred so a --version/--help run never reaches them.\n const { createHTTPServer } = await import('./setup/http.ts');\n const { createStdioServer } = await import('./setup/stdio.ts');\n const { logger, close } = config.transport.type === 'stdio' ? await createStdioServer(config) : await createHTTPServer(config);\n\n process.on('SIGINT', async () => {\n await close();\n process.exit(0);\n });\n\n logger.info(`Server started with ${config.transport.type} transport`);\n await new Promise(() => {});\n}\n\nexport default async function main(): Promise<void> {\n // Check for help/version flags FIRST, before config parsing\n const versionHelpResult = handleVersionHelp(process.argv);\n if (versionHelpResult.handled) {\n console.log(versionHelpResult.output);\n process.exit(0);\n }\n\n // Only parse config if no help/version flags. config.ts's own heavy imports (@mcp-z/oauth-google,\n // @mcp-z/server) are deferred internally, so this static-looking call stays cheap until here.\n const { createConfig } = await import('./setup/config.ts');\n const config = createConfig();\n await startServer(config);\n}\n\nif (process.argv[1] === new URL(import.meta.url).pathname) {\n main();\n}\n"],"names":["CategoriesListInputSchema","inputSchema","GOOGLE_SCOPE","LabelsListInputSchema","main","mcp","schemas","setup","startServer","config","createHTTPServer","createStdioServer","logger","close","transport","type","process","on","exit","info","Promise","versionHelpResult","createConfig","handleVersionHelp","argv","handled","console","log","output","URL","pathname"],"mappings":";;;;;;;;;;;QAOwBA;eAAfC,6BAAW;;QAJXC;eAAAA,yBAAY;;QAMGC;eAAfF,yBAAW;;QAqBpB;eAA8BG;;QA1BlBC;;;QAMAC;;;QACAC;;;QAGUC;eAAAA;;;6BAdY;2BAGL;+DACR;gCAGoC;4BAEJ;gEAC5B;gEACF;qBACT;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAEP,SAAeA,YAAYC,MAAoB;;YAG5CC,kBACAC,mBACkBF,MAAlBG,QAAQC;;;;oBAFa;;wBAAM;2EAAA,QAAO;;;;oBAAlCH,mBAAqB,cAArBA;oBACsB;;wBAAM;2EAAA,QAAO;;;;oBAAnCC,oBAAsB,cAAtBA;yBACkBF,CAAAA,OAAOK,SAAS,CAACC,IAAI,KAAK,OAAM,GAAhCN;;;;oBAAoC;;wBAAME,kBAAkBF;;;2BAAxB;;;;;;oBAAkC;;wBAAMC,iBAAiBD;;;2BAAvB;;;oBAAtEA,aAAlBG,SAAkBH,KAAlBG,QAAQC,QAAUJ,KAAVI;oBAEhBG,QAAQC,EAAE,CAAC,UAAU;;;;;wCACnB;;4CAAMJ;;;wCAAN;wCACAG,QAAQE,IAAI,CAAC;;;;;;wBACf;;oBAEAN,OAAOO,IAAI,CAAC,AAAC,uBAA4C,OAAtBV,OAAOK,SAAS,CAACC,IAAI,EAAC;oBACzD;;wBAAM,IAAIK,QAAQ,YAAO;;;oBAAzB;;;;;;IACF;;AAEe,SAAehB;;YAEtBiB,mBAQEC,cACFb;;;;oBAVN,4DAA4D;oBACtDY,oBAAoBE,IAAAA,gCAAiB,EAACP,QAAQQ,IAAI;oBACxD,IAAIH,kBAAkBI,OAAO,EAAE;wBAC7BC,QAAQC,GAAG,CAACN,kBAAkBO,MAAM;wBACpCZ,QAAQE,IAAI,CAAC;oBACf;oBAIyB;;wBAAM;2EAAA,QAAO;;;;oBAA9BI,eAAiB,cAAjBA;oBACFb,SAASa;oBACf;;wBAAMd,YAAYC;;;oBAAlB;;;;;;IACF;;AAEA,IAAIO,QAAQQ,IAAI,CAAC,EAAE,KAAK,IAAIK,IAAI,qDAAiBC,QAAQ,EAAE;IACzD1B;AACF"}
@@ -1,2 +1,2 @@
1
- import type { gmail_v1 } from 'googleapis';
1
+ import type { gmail_v1 } from '@googleapis/gmail';
2
2
  export declare function ensureLabelId(gmail: gmail_v1.Gmail, userId: string, labelName: string): Promise<string>;
@@ -1,2 +1,2 @@
1
- import type { gmail_v1 } from 'googleapis';
1
+ import type { gmail_v1 } from '@googleapis/gmail';
2
2
  export declare function ensureLabelId(gmail: gmail_v1.Gmail, userId: string, labelName: string): Promise<string>;
@@ -1 +1 @@
1
- {"version":3,"sources":["/Users/kevin/Dev/OpenSource/ai/mcp-z/mcp-gmail/src/labels/gmail-labels.ts"],"sourcesContent":["import type { gmail_v1 } from 'googleapis';\n\nexport async function ensureLabelId(gmail: gmail_v1.Gmail, userId: string, labelName: string): Promise<string> {\n // Built-in system labels: pass through by name\n const builtInLabels: Record<string, string> = {\n INBOX: 'INBOX',\n SPAM: 'SPAM',\n TRASH: 'TRASH',\n UNREAD: 'UNREAD',\n STARRED: 'STARRED',\n IMPORTANT: 'IMPORTANT',\n SENT: 'SENT',\n DRAFT: 'DRAFT',\n CATEGORY_PERSONAL: 'CATEGORY_PERSONAL',\n CATEGORY_SOCIAL: 'CATEGORY_SOCIAL',\n CATEGORY_PROMOTIONS: 'CATEGORY_PROMOTIONS',\n CATEGORY_UPDATES: 'CATEGORY_UPDATES',\n CATEGORY_FORUMS: 'CATEGORY_FORUMS',\n };\n\n const upper = labelName.toUpperCase();\n if (builtInLabels[upper]) return builtInLabels[upper];\n\n // Try to find an existing user label by name\n const listed = await gmail.users.labels.list({ userId });\n const labels = Array.isArray(listed?.data?.labels) ? listed.data.labels : [];\n const existing = labels.find((l: unknown) => {\n const label = l as { name?: unknown; id?: unknown };\n return label?.name === labelName;\n });\n const existingTyped = existing as { id?: unknown } | undefined;\n if (existingTyped?.id) return String(existingTyped.id);\n\n // Create the label if it doesn't exist\n const created = await gmail.users.labels.create({\n userId,\n requestBody: {\n name: labelName,\n labelListVisibility: 'labelShow',\n messageListVisibility: 'show',\n },\n });\n if (!created?.data?.id) throw new Error('Failed to create label');\n return created.data.id as string;\n}\n"],"names":["ensureLabelId","gmail","userId","labelName","listed","created","builtInLabels","upper","labels","existing","existingTyped","INBOX","SPAM","TRASH","UNREAD","STARRED","IMPORTANT","SENT","DRAFT","CATEGORY_PERSONAL","CATEGORY_SOCIAL","CATEGORY_PROMOTIONS","CATEGORY_UPDATES","CATEGORY_FORUMS","toUpperCase","users","list","Array","isArray","data","find","l","label","name","id","String","create","requestBody","labelListVisibility","messageListVisibility","Error"],"mappings":";;;;+BAEsBA;;;eAAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAf,SAAeA,cAAcC,KAAqB,EAAEC,MAAc,EAAEC,SAAiB;;YAuB7DC,cAiBxBC,eAtCCC,eAgBAC,OAIAH,QACAI,QACAC,UAIAC,eAIAL;;;;oBA/BN,+CAA+C;oBACzCC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import type { gmail_v1 } from '@googleapis/gmail';\n\nexport async function ensureLabelId(gmail: gmail_v1.Gmail, userId: string, labelName: string): Promise<string> {\n // Built-in system labels: pass through by name\n const builtInLabels: Record<string, string> = {\n INBOX: 'INBOX',\n SPAM: 'SPAM',\n TRASH: 'TRASH',\n UNREAD: 'UNREAD',\n STARRED: 'STARRED',\n IMPORTANT: 'IMPORTANT',\n SENT: 'SENT',\n DRAFT: 'DRAFT',\n CATEGORY_PERSONAL: 'CATEGORY_PERSONAL',\n CATEGORY_SOCIAL: 'CATEGORY_SOCIAL',\n CATEGORY_PROMOTIONS: 'CATEGORY_PROMOTIONS',\n CATEGORY_UPDATES: 'CATEGORY_UPDATES',\n CATEGORY_FORUMS: 'CATEGORY_FORUMS',\n };\n\n const upper = labelName.toUpperCase();\n if (builtInLabels[upper]) return builtInLabels[upper];\n\n // Try to find an existing user label by name\n const listed = await gmail.users.labels.list({ userId });\n const labels = Array.isArray(listed?.data?.labels) ? listed.data.labels : [];\n const existing = labels.find((l: unknown) => {\n const label = l as { name?: unknown; id?: unknown };\n return label?.name === labelName;\n });\n const existingTyped = existing as { id?: unknown } | undefined;\n if (existingTyped?.id) return String(existingTyped.id);\n\n // Create the label if it doesn't exist\n const created = await gmail.users.labels.create({\n userId,\n requestBody: {\n name: labelName,\n labelListVisibility: 'labelShow',\n messageListVisibility: 'show',\n },\n });\n if (!created?.data?.id) throw new Error('Failed to create label');\n return created.data.id as string;\n}\n"],"names":["ensureLabelId","gmail","userId","labelName","listed","created","builtInLabels","upper","labels","existing","existingTyped","INBOX","SPAM","TRASH","UNREAD","STARRED","IMPORTANT","SENT","DRAFT","CATEGORY_PERSONAL","CATEGORY_SOCIAL","CATEGORY_PROMOTIONS","CATEGORY_UPDATES","CATEGORY_FORUMS","toUpperCase","users","list","Array","isArray","data","find","l","label","name","id","String","create","requestBody","labelListVisibility","messageListVisibility","Error"],"mappings":";;;;+BAEsBA;;;eAAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;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APMlC,UAAU;oBAQhB,IAAI,EAACA,oBAAAA,+BAAAA,gBAAAA,QAASwB,IAAI,cAAbxB,oCAAAA,cAAe6B,EAAE,GAAE,MAAM,IAAIM,MAAM;oBACxC;;wBAAOnC,QAAQwB,IAAI,CAACK,EAAE;;;;IACxB"}
@@ -0,0 +1,9 @@
1
+ import { type GoogleAuthProvider } from '@mcp-z/oauth-google';
2
+ /**
3
+ * A Google API client bound to this request's token provider.
4
+ *
5
+ * `@mcp-z/oauth-google` mints tokens and depends on no Google SDK, so the client
6
+ * is built here, from this package's own `googleapis`. That keeps one copy of
7
+ * `google-auth-library` in the tree by construction rather than by matching pins.
8
+ */
9
+ export declare function googleAuth(auth: GoogleAuthProvider): import("google-auth-library").OAuth2Client;
@@ -0,0 +1,9 @@
1
+ import { type GoogleAuthProvider } from '@mcp-z/oauth-google';
2
+ /**
3
+ * A Google API client bound to this request's token provider.
4
+ *
5
+ * `@mcp-z/oauth-google` mints tokens and depends on no Google SDK, so the client
6
+ * is built here, from this package's own `googleapis`. That keeps one copy of
7
+ * `google-auth-library` in the tree by construction rather than by matching pins.
8
+ */
9
+ export declare function googleAuth(auth: GoogleAuthProvider): import("google-auth-library").OAuth2Client;
@@ -0,0 +1,16 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", {
3
+ value: true
4
+ });
5
+ Object.defineProperty(exports, "googleAuth", {
6
+ enumerable: true,
7
+ get: function() {
8
+ return googleAuth;
9
+ }
10
+ });
11
+ var _gmail = require("@googleapis/gmail");
12
+ var _oauthgoogle = require("@mcp-z/oauth-google");
13
+ function googleAuth(auth) {
14
+ return (0, _oauthgoogle.attachTokenProvider)(new _gmail.auth.OAuth2(), auth);
15
+ }
16
+ /* CJS INTEROP */ if (exports.__esModule && exports.default) { try { Object.defineProperty(exports.default, '__esModule', { value: true }); for (var key in exports) { exports.default[key] = exports[key]; } } catch (_) {}; module.exports = exports.default; }
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["/Users/kevin/Dev/OpenSource/ai/mcp-z/mcp-gmail/src/lib/google-auth.ts"],"sourcesContent":["import { auth as googleAuthPlus } from '@googleapis/gmail';\nimport { attachTokenProvider, type GoogleAuthProvider } from '@mcp-z/oauth-google';\n\n/**\n * A Google API client bound to this request's token provider.\n *\n * `@mcp-z/oauth-google` mints tokens and depends on no Google SDK, so the client\n * is built here, from this package's own `googleapis`. That keeps one copy of\n * `google-auth-library` in the tree by construction rather than by matching pins.\n */\nexport function googleAuth(auth: GoogleAuthProvider) {\n return attachTokenProvider(new googleAuthPlus.OAuth2(), auth);\n}\n"],"names":["googleAuth","auth","attachTokenProvider","googleAuthPlus","OAuth2"],"mappings":";;;;+BAUgBA;;;eAAAA;;;qBAVuB;2BACsB;AAStD,SAASA,WAAWC,IAAwB;IACjD,OAAOC,IAAAA,gCAAmB,EAAC,IAAIC,WAAc,CAACC,MAAM,IAAIH;AAC1D"}
@@ -1,5 +1,4 @@
1
- import type { RequestHandlerExtra } from '@modelcontextprotocol/sdk/shared/protocol.js';
2
- import type { ServerNotification, ServerRequest } from '@modelcontextprotocol/sdk/types.js';
1
+ import type { ServerContext } from '@mcp-z/server';
3
2
  import { z } from 'zod';
4
3
  export default function createPrompt(): {
5
4
  name: string;
@@ -12,7 +11,7 @@ export default function createPrompt(): {
12
11
  };
13
12
  handler: (args: {
14
13
  [x: string]: unknown;
15
- }, _extra: RequestHandlerExtra<ServerRequest, ServerNotification>) => Promise<{
14
+ }, _extra: ServerContext) => Promise<{
16
15
  messages: ({
17
16
  role: "system";
18
17
  content: {
@@ -1,5 +1,4 @@
1
- import type { RequestHandlerExtra } from '@modelcontextprotocol/sdk/shared/protocol.js';
2
- import type { ServerNotification, ServerRequest } from '@modelcontextprotocol/sdk/types.js';
1
+ import type { ServerContext } from '@mcp-z/server';
3
2
  import { z } from 'zod';
4
3
  export default function createPrompt(): {
5
4
  name: string;
@@ -12,7 +11,7 @@ export default function createPrompt(): {
12
11
  };
13
12
  handler: (args: {
14
13
  [x: string]: unknown;
15
- }, _extra: RequestHandlerExtra<ServerRequest, ServerNotification>) => Promise<{
14
+ }, _extra: ServerContext) => Promise<{
16
15
  messages: ({
17
16
  role: "system";
18
17
  content: {
@@ -1 +1 @@
1
- {"version":3,"sources":["/Users/kevin/Dev/OpenSource/ai/mcp-z/mcp-gmail/src/mcp/prompts/draft-email.ts"],"sourcesContent":["import type { PromptModule } from '@mcp-z/server';\nimport type { RequestHandlerExtra } from '@modelcontextprotocol/sdk/shared/protocol.js';\nimport type { ServerNotification, ServerRequest } from '@modelcontextprotocol/sdk/types.js';\nimport { z } from 'zod';\n\nexport default function createPrompt() {\n const argsSchema = z.object({\n context: z.string().min(1).describe('Email context to draft response for'),\n tone: z.string().optional().describe('Email tone (default: professional)'),\n });\n\n const config = {\n description: 'Draft an email response',\n argsSchema: argsSchema.shape,\n };\n\n const handler = async (args: { [x: string]: unknown }, _extra: RequestHandlerExtra<ServerRequest, ServerNotification>) => {\n const { context, tone } = argsSchema.parse(args);\n return {\n messages: [\n { role: 'system' as const, content: { type: 'text' as const, text: 'You are an expert email assistant.' } },\n { role: 'user' as const, content: { type: 'text' as const, text: `Draft a ${tone || 'professional'} email:\\n\\n${context}` } },\n ],\n };\n };\n\n return {\n name: 'draft-email',\n config,\n handler,\n } satisfies PromptModule;\n}\n"],"names":["createPrompt","argsSchema","z","object","context","string","min","describe","tone","optional","config","description","shape","handler","args","_extra","parse","messages","role","content","type","text","name"],"mappings":";;;;+BAKA;;;eAAwBA;;;mBAFN;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAEH,SAASA;IACtB,IAAMC,aAAaC,MAAC,CAACC,MAAM,CAAC;QAC1BC,SAASF,MAAC,CAACG,MAAM,GAAGC,GAAG,CAAC,GAAGC,QAAQ,CAAC;QACpCC,MAAMN,MAAC,CAACG,MAAM,GAAGI,QAAQ,GAAGF,QAAQ,CAAC;IACvC;IAEA,IAAMG,SAAS;QACbC,aAAa;QACbV,YAAYA,WAAWW,KAAK;IAC9B;IAEA,IAAMC,UAAU,iBAAOC,MAAgCC;;gBAC3Bd,mBAAlBG,SAASI;;gBAASP,oBAAAA,WAAWe,KAAK,CAACF,OAAnCV,UAAkBH,kBAAlBG,SAASI,OAASP,kBAATO;gBACjB;;oBAAO;wBACLS,QAAQ;4BACN;gCAAEC,MAAM;gCAAmBC,SAAS;oCAAEC,MAAM;oCAAiBC,MAAM;gCAAqC;4BAAE;4BAC1G;gCAAEH,MAAM;gCAAiBC,SAAS;oCAAEC,MAAM;oCAAiBC,MAAM,AAAC,WAA8CjB,OAApCI,QAAQ,gBAAe,eAAqB,OAARJ;gCAAU;4BAAE;;oBAEhI;;;QACF;;IAEA,OAAO;QACLkB,MAAM;QACNZ,QAAAA;QACAG,SAAAA;IACF;AACF"}
1
+ {"version":3,"sources":["/Users/kevin/Dev/OpenSource/ai/mcp-z/mcp-gmail/src/mcp/prompts/draft-email.ts"],"sourcesContent":["import type { PromptModule, ServerContext } from '@mcp-z/server';\nimport { z } from 'zod';\n\nexport default function createPrompt() {\n const argsSchema = z.object({\n context: z.string().min(1).describe('Email context to draft response for'),\n tone: z.string().optional().describe('Email tone (default: professional)'),\n });\n\n const config = {\n description: 'Draft an email response',\n argsSchema: argsSchema.shape,\n };\n\n const handler = async (args: { [x: string]: unknown }, _extra: ServerContext) => {\n const { context, tone } = argsSchema.parse(args);\n return {\n messages: [\n { role: 'system' as const, content: { type: 'text' as const, text: 'You are an expert email assistant.' } },\n { role: 'user' as const, content: { type: 'text' as const, text: `Draft a ${tone || 'professional'} email:\\n\\n${context}` } },\n ],\n };\n };\n\n return {\n name: 'draft-email',\n config,\n handler,\n } satisfies PromptModule;\n}\n"],"names":["createPrompt","argsSchema","z","object","context","string","min","describe","tone","optional","config","description","shape","handler","args","_extra","parse","messages","role","content","type","text","name"],"mappings":";;;;+BAGA;;;eAAwBA;;;mBAFN;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAEH,SAASA;IACtB,IAAMC,aAAaC,MAAC,CAACC,MAAM,CAAC;QAC1BC,SAASF,MAAC,CAACG,MAAM,GAAGC,GAAG,CAAC,GAAGC,QAAQ,CAAC;QACpCC,MAAMN,MAAC,CAACG,MAAM,GAAGI,QAAQ,GAAGF,QAAQ,CAAC;IACvC;IAEA,IAAMG,SAAS;QACbC,aAAa;QACbV,YAAYA,WAAWW,KAAK;IAC9B;IAEA,IAAMC,UAAU,iBAAOC,MAAgCC;;gBAC3Bd,mBAAlBG,SAASI;;gBAASP,oBAAAA,WAAWe,KAAK,CAACF,OAAnCV,UAAkBH,kBAAlBG,SAASI,OAASP,kBAATO;gBACjB;;oBAAO;wBACLS,QAAQ;4BACN;gCAAEC,MAAM;gCAAmBC,SAAS;oCAAEC,MAAM;oCAAiBC,MAAM;gCAAqC;4BAAE;4BAC1G;gCAAEH,MAAM;gCAAiBC,SAAS;oCAAEC,MAAM;oCAAiBC,MAAM,AAAC,WAA8CjB,OAApCI,QAAQ,gBAAe,eAAqB,OAARJ;gCAAU;4BAAE;;oBAEhI;;;QACF;;IAEA,OAAO;QACLkB,MAAM;QACNZ,QAAAA;QACAG,SAAAA;IACF;AACF"}
@@ -1,5 +1,4 @@
1
- import type { RequestHandlerExtra } from '@modelcontextprotocol/sdk/shared/protocol.js';
2
- import type { ServerNotification, ServerRequest } from '@modelcontextprotocol/sdk/types.js';
1
+ import type { ServerContext } from '@mcp-z/server';
3
2
  export default function createPrompt(): {
4
3
  name: string;
5
4
  config: {
@@ -7,7 +6,7 @@ export default function createPrompt(): {
7
6
  };
8
7
  handler: (_args: {
9
8
  [x: string]: unknown;
10
- }, _extra: RequestHandlerExtra<ServerRequest, ServerNotification>) => Promise<{
9
+ }, _extra: ServerContext) => Promise<{
11
10
  messages: {
12
11
  role: "user";
13
12
  content: {
@@ -1,5 +1,4 @@
1
- import type { RequestHandlerExtra } from '@modelcontextprotocol/sdk/shared/protocol.js';
2
- import type { ServerNotification, ServerRequest } from '@modelcontextprotocol/sdk/types.js';
1
+ import type { ServerContext } from '@mcp-z/server';
3
2
  export default function createPrompt(): {
4
3
  name: string;
5
4
  config: {
@@ -7,7 +6,7 @@ export default function createPrompt(): {
7
6
  };
8
7
  handler: (_args: {
9
8
  [x: string]: unknown;
10
- }, _extra: RequestHandlerExtra<ServerRequest, ServerNotification>) => Promise<{
9
+ }, _extra: ServerContext) => Promise<{
11
10
  messages: {
12
11
  role: "user";
13
12
  content: {
@@ -1 +1 @@
1
- {"version":3,"sources":["/Users/kevin/Dev/OpenSource/ai/mcp-z/mcp-gmail/src/mcp/prompts/query-syntax.ts"],"sourcesContent":["import type { PromptModule } from '@mcp-z/server';\nimport type { RequestHandlerExtra } from '@modelcontextprotocol/sdk/shared/protocol.js';\nimport type { ServerNotification, ServerRequest } from '@modelcontextprotocol/sdk/types.js';\n\nexport default function createPrompt() {\n const config = {\n description: 'Reference guide for Gmail query syntax',\n };\n\n const handler = async (_args: { [x: string]: unknown }, _extra: RequestHandlerExtra<ServerRequest, ServerNotification>) => {\n return {\n messages: [\n {\n role: 'user' as const,\n content: {\n type: 'text' as const,\n text: `# Gmail Query Syntax Reference\n\n## Logical Operators\n- \\`$and\\`: Array of conditions that ALL must match\n- \\`$or\\`: Array of conditions where ANY must match\n- \\`$not\\`: Condition that must NOT match\n\n## Email Address Fields\n- \\`from\\`, \\`to\\`, \\`cc\\`, \\`bcc\\`: String or field operators\n\n## Content Fields\n- \\`subject\\`: Search subject line\n- \\`body\\`: Search message body\n- \\`text\\`: Search all text content\n- \\`fuzzyPhrase\\`: Approximate phrase matching (words appear together)\n\n## Boolean Flags\n- \\`hasAttachment\\`: true/false\n- \\`isRead\\`: true/false\n\n## Date Range\n\\`\\`\\`json\n{ \"date\": { \"$gte\": \"2024-01-01\", \"$lt\": \"2024-12-31\" } }\n\\`\\`\\`\n\n## Gmail-Specific\n- \\`categories\\`: primary, social, promotions, updates, forums\n- \\`label\\`: User labels (case-sensitive, use gmail-labels-list to discover)\n- \\`rawGmailQuery\\`: Escape hatch for advanced Gmail syntax\n\n## Field Operators (for multi-value fields)\n- \\`$any\\`: OR - matches if ANY value matches\n- \\`$all\\`: AND - matches if ALL values match\n- \\`$none\\`: NOT - matches if NONE match\n\n## Example Queries\n\\`\\`\\`json\n// Unread from specific sender\n{ \"from\": \"boss@company.com\", \"isRead\": false }\n\n// Recent with attachment\n{ \"hasAttachment\": true, \"date\": { \"$gte\": \"2024-01-01\" } }\n\n// Multiple senders\n{ \"from\": { \"$any\": [\"alice@example.com\", \"bob@example.com\"] } }\n\n// Complex: promotions OR social, unread\n{ \"$and\": [\n { \"categories\": { \"$any\": [\"promotions\", \"social\"] } },\n { \"isRead\": false }\n]}\n\\`\\`\\``,\n },\n },\n ],\n };\n };\n\n return {\n name: 'query-syntax',\n config,\n handler,\n } satisfies PromptModule;\n}\n"],"names":["createPrompt","config","description","handler","_args","_extra","messages","role","content","type","text","name"],"mappings":";;;;+BAIA;;;eAAwBA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAT,SAASA;IACtB,IAAMC,SAAS;QACbC,aAAa;IACf;IAEA,IAAMC,UAAU,iBAAOC,OAAiCC;;;gBACtD;;oBAAO;wBACLC,QAAQ;4BACN;gCACEC,MAAM;gCACNC,SAAS;oCACPC,MAAM;oCACNC,MAAM;gCAoDR;4BACF;;oBAEJ;;;QACF;;IAEA,OAAO;QACLC,MAAM;QACNV,QAAAA;QACAE,SAAAA;IACF;AACF"}
1
+ {"version":3,"sources":["/Users/kevin/Dev/OpenSource/ai/mcp-z/mcp-gmail/src/mcp/prompts/query-syntax.ts"],"sourcesContent":["import type { PromptModule, ServerContext } from '@mcp-z/server';\n\nexport default function createPrompt() {\n const config = {\n description: 'Reference guide for Gmail query syntax',\n };\n\n const handler = async (_args: { [x: string]: unknown }, _extra: ServerContext) => {\n return {\n messages: [\n {\n role: 'user' as const,\n content: {\n type: 'text' as const,\n text: `# Gmail Query Syntax Reference\n\n## Logical Operators\n- \\`$and\\`: Array of conditions that ALL must match\n- \\`$or\\`: Array of conditions where ANY must match\n- \\`$not\\`: Condition that must NOT match\n\n## Email Address Fields\n- \\`from\\`, \\`to\\`, \\`cc\\`, \\`bcc\\`: String or field operators\n\n## Content Fields\n- \\`subject\\`: Search subject line\n- \\`body\\`: Search message body\n- \\`text\\`: Search all text content\n- \\`fuzzyPhrase\\`: Approximate phrase matching (words appear together)\n\n## Boolean Flags\n- \\`hasAttachment\\`: true/false\n- \\`isRead\\`: true/false\n\n## Date Range\n\\`\\`\\`json\n{ \"date\": { \"$gte\": \"2024-01-01\", \"$lt\": \"2024-12-31\" } }\n\\`\\`\\`\n\n## Gmail-Specific\n- \\`categories\\`: primary, social, promotions, updates, forums\n- \\`label\\`: User labels (case-sensitive, use gmail-labels-list to discover)\n- \\`rawGmailQuery\\`: Escape hatch for advanced Gmail syntax\n\n## Field Operators (for multi-value fields)\n- \\`$any\\`: OR - matches if ANY value matches\n- \\`$all\\`: AND - matches if ALL values match\n- \\`$none\\`: NOT - matches if NONE match\n\n## Example Queries\n\\`\\`\\`json\n// Unread from specific sender\n{ \"from\": \"boss@company.com\", \"isRead\": false }\n\n// Recent with attachment\n{ \"hasAttachment\": true, \"date\": { \"$gte\": \"2024-01-01\" } }\n\n// Multiple senders\n{ \"from\": { \"$any\": [\"alice@example.com\", \"bob@example.com\"] } }\n\n// Complex: promotions OR social, unread\n{ \"$and\": [\n { \"categories\": { \"$any\": [\"promotions\", \"social\"] } },\n { \"isRead\": false }\n]}\n\\`\\`\\``,\n },\n },\n ],\n };\n };\n\n return {\n name: 'query-syntax',\n config,\n handler,\n } satisfies PromptModule;\n}\n"],"names":["createPrompt","config","description","handler","_args","_extra","messages","role","content","type","text","name"],"mappings":";;;;+BAEA;;;eAAwBA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAT,SAASA;IACtB,IAAMC,SAAS;QACbC,aAAa;IACf;IAEA,IAAMC,UAAU,iBAAOC,OAAiCC;;;gBACtD;;oBAAO;wBACLC,QAAQ;4BACN;gCACEC,MAAM;gCACNC,SAAS;oCACPC,MAAM;oCACNC,MAAM;gCAoDR;4BACF;;oBAEJ;;;QACF;;IAEA,OAAO;QACLC,MAAM;QACNV,QAAAA;QACAE,SAAAA;IACF;AACF"}
@@ -1,11 +1,12 @@
1
- import { ResourceTemplate } from '@modelcontextprotocol/sdk/server/mcp.js';
2
- import type { RequestHandlerExtra } from '@modelcontextprotocol/sdk/shared/protocol.js';
3
- import type { ReadResourceResult, ServerNotification, ServerRequest } from '@modelcontextprotocol/sdk/types.js';
1
+ import type { ReadResourceResult, ServerContext } from '@mcp-z/server';
2
+ import { ResourceTemplate } from '@mcp-z/server';
4
3
  export default function createResource(): {
5
4
  name: string;
6
5
  template: ResourceTemplate;
7
- config: import("@modelcontextprotocol/sdk/server/mcp.js").ResourceMetadata;
6
+ config: import("@modelcontextprotocol/server").ResourceMetadata & {
7
+ cacheHint?: import("@mcp-z/server").CacheHint;
8
+ };
8
9
  handler: (uri: URL, variables: {
9
10
  id: string;
10
- }, extra: RequestHandlerExtra<ServerRequest, ServerNotification>) => Promise<ReadResourceResult>;
11
+ }, extra: ServerContext) => Promise<ReadResourceResult>;
11
12
  };
@@ -1,11 +1,12 @@
1
- import { ResourceTemplate } from '@modelcontextprotocol/sdk/server/mcp.js';
2
- import type { RequestHandlerExtra } from '@modelcontextprotocol/sdk/shared/protocol.js';
3
- import type { ReadResourceResult, ServerNotification, ServerRequest } from '@modelcontextprotocol/sdk/types.js';
1
+ import type { ReadResourceResult, ServerContext } from '@mcp-z/server';
2
+ import { ResourceTemplate } from '@mcp-z/server';
4
3
  export default function createResource(): {
5
4
  name: string;
6
5
  template: ResourceTemplate;
7
- config: import("@modelcontextprotocol/sdk/server/mcp.js").ResourceMetadata;
6
+ config: import("@modelcontextprotocol/server").ResourceMetadata & {
7
+ cacheHint?: import("@mcp-z/server").CacheHint;
8
+ };
8
9
  handler: (uri: URL, variables: {
9
10
  id: string;
10
- }, extra: RequestHandlerExtra<ServerRequest, ServerNotification>) => Promise<ReadResourceResult>;
11
+ }, extra: ServerContext) => Promise<ReadResourceResult>;
11
12
  };