@mcp-z/mcp-gmail 1.0.9 → 1.0.11

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 (148) hide show
  1. package/dist/cjs/constants.js.map +1 -1
  2. package/dist/cjs/email/composition/rfc822-builder.js.map +1 -1
  3. package/dist/cjs/email/messages/fetch-message.js +15 -21
  4. package/dist/cjs/email/messages/fetch-message.js.map +1 -1
  5. package/dist/cjs/email/messages/messages.js +2 -2
  6. package/dist/cjs/email/messages/messages.js.map +1 -1
  7. package/dist/cjs/email/parsing/header-parsing.js.map +1 -1
  8. package/dist/cjs/email/parsing/headers-utils.js.map +1 -1
  9. package/dist/cjs/email/parsing/html-processing.js.map +1 -1
  10. package/dist/cjs/email/parsing/message-extraction.js.map +1 -1
  11. package/dist/cjs/email/querying/execute-query.js +7 -14
  12. package/dist/cjs/email/querying/execute-query.js.map +1 -1
  13. package/dist/cjs/email/querying/pagination.js +19 -24
  14. package/dist/cjs/email/querying/pagination.js.map +1 -1
  15. package/dist/cjs/email/querying/query-builder.js +4 -2
  16. package/dist/cjs/email/querying/query-builder.js.map +1 -1
  17. package/dist/cjs/email/querying/search-execution.js +2 -5
  18. package/dist/cjs/email/querying/search-execution.js.map +1 -1
  19. package/dist/cjs/index.js +10 -24
  20. package/dist/cjs/index.js.map +1 -1
  21. package/dist/cjs/labels/gmail-labels.js +2 -5
  22. package/dist/cjs/labels/gmail-labels.js.map +1 -1
  23. package/dist/cjs/lib/base64-encoding.js.map +1 -1
  24. package/dist/cjs/lib/create-store.js +2 -5
  25. package/dist/cjs/lib/create-store.js.map +1 -1
  26. package/dist/cjs/lib/date-conversion.js.map +1 -1
  27. package/dist/cjs/lib/messages-to-row.js +2 -2
  28. package/dist/cjs/lib/messages-to-row.js.map +1 -1
  29. package/dist/cjs/mcp/index.js +8 -19
  30. package/dist/cjs/mcp/index.js.map +1 -1
  31. package/dist/cjs/mcp/prompts/draft-email.js +3 -6
  32. package/dist/cjs/mcp/prompts/draft-email.js.map +1 -1
  33. package/dist/cjs/mcp/prompts/index.js.map +1 -1
  34. package/dist/cjs/mcp/prompts/query-syntax.js +3 -6
  35. package/dist/cjs/mcp/prompts/query-syntax.js.map +1 -1
  36. package/dist/cjs/mcp/resources/email.js +3 -6
  37. package/dist/cjs/mcp/resources/email.js.map +1 -1
  38. package/dist/cjs/mcp/resources/index.js.map +1 -1
  39. package/dist/cjs/mcp/tools/categories-list.js +4 -8
  40. package/dist/cjs/mcp/tools/categories-list.js.map +1 -1
  41. package/dist/cjs/mcp/tools/index.js.map +1 -1
  42. package/dist/cjs/mcp/tools/label-add.js +4 -8
  43. package/dist/cjs/mcp/tools/label-add.js.map +1 -1
  44. package/dist/cjs/mcp/tools/label-delete.d.cts +1 -1
  45. package/dist/cjs/mcp/tools/label-delete.d.ts +1 -1
  46. package/dist/cjs/mcp/tools/label-delete.js +36 -32
  47. package/dist/cjs/mcp/tools/label-delete.js.map +1 -1
  48. package/dist/cjs/mcp/tools/labels-list.js +4 -8
  49. package/dist/cjs/mcp/tools/labels-list.js.map +1 -1
  50. package/dist/cjs/mcp/tools/message-get.d.cts +21 -21
  51. package/dist/cjs/mcp/tools/message-get.d.ts +21 -21
  52. package/dist/cjs/mcp/tools/message-get.js +4 -8
  53. package/dist/cjs/mcp/tools/message-get.js.map +1 -1
  54. package/dist/cjs/mcp/tools/message-mark-read.js +4 -8
  55. package/dist/cjs/mcp/tools/message-mark-read.js.map +1 -1
  56. package/dist/cjs/mcp/tools/message-move-to-trash.d.cts +1 -1
  57. package/dist/cjs/mcp/tools/message-move-to-trash.d.ts +1 -1
  58. package/dist/cjs/mcp/tools/message-move-to-trash.js +36 -32
  59. package/dist/cjs/mcp/tools/message-move-to-trash.js.map +1 -1
  60. package/dist/cjs/mcp/tools/message-respond.js +5 -11
  61. package/dist/cjs/mcp/tools/message-respond.js.map +1 -1
  62. package/dist/cjs/mcp/tools/message-search.d.cts +25 -25
  63. package/dist/cjs/mcp/tools/message-search.d.ts +25 -25
  64. package/dist/cjs/mcp/tools/message-search.js +19 -25
  65. package/dist/cjs/mcp/tools/message-search.js.map +1 -1
  66. package/dist/cjs/mcp/tools/message-send.d.cts +3 -3
  67. package/dist/cjs/mcp/tools/message-send.d.ts +3 -3
  68. package/dist/cjs/mcp/tools/message-send.js +4 -8
  69. package/dist/cjs/mcp/tools/message-send.js.map +1 -1
  70. package/dist/cjs/mcp/tools/messages-export-csv.d.cts +2 -2
  71. package/dist/cjs/mcp/tools/messages-export-csv.d.ts +2 -2
  72. package/dist/cjs/mcp/tools/messages-export-csv.js +16 -22
  73. package/dist/cjs/mcp/tools/messages-export-csv.js.map +1 -1
  74. package/dist/cjs/schemas/gmail-query-schema.d.cts +2 -1
  75. package/dist/cjs/schemas/gmail-query-schema.d.ts +2 -1
  76. package/dist/cjs/schemas/gmail-query-schema.js +26 -30
  77. package/dist/cjs/schemas/gmail-query-schema.js.map +1 -1
  78. package/dist/cjs/schemas/index.js.map +1 -1
  79. package/dist/cjs/setup/config.js +11 -25
  80. package/dist/cjs/setup/config.js.map +1 -1
  81. package/dist/cjs/setup/http.js +15 -16
  82. package/dist/cjs/setup/http.js.map +1 -1
  83. package/dist/cjs/setup/index.js.map +1 -1
  84. package/dist/cjs/setup/oauth-google.js +9 -16
  85. package/dist/cjs/setup/oauth-google.js.map +1 -1
  86. package/dist/cjs/setup/runtime.d.cts +1 -1
  87. package/dist/cjs/setup/runtime.d.ts +1 -1
  88. package/dist/cjs/setup/runtime.js +29 -44
  89. package/dist/cjs/setup/runtime.js.map +1 -1
  90. package/dist/cjs/setup/stdio.js +15 -16
  91. package/dist/cjs/setup/stdio.js.map +1 -1
  92. package/dist/esm/constants.js.map +1 -1
  93. package/dist/esm/email/composition/rfc822-builder.js.map +1 -1
  94. package/dist/esm/email/messages/fetch-message.js.map +1 -1
  95. package/dist/esm/email/messages/messages.js.map +1 -1
  96. package/dist/esm/email/parsing/header-parsing.js.map +1 -1
  97. package/dist/esm/email/parsing/headers-utils.js.map +1 -1
  98. package/dist/esm/email/parsing/html-processing.js.map +1 -1
  99. package/dist/esm/email/parsing/message-extraction.js.map +1 -1
  100. package/dist/esm/email/querying/execute-query.js.map +1 -1
  101. package/dist/esm/email/querying/pagination.js.map +1 -1
  102. package/dist/esm/email/querying/query-builder.js.map +1 -1
  103. package/dist/esm/email/querying/search-execution.js.map +1 -1
  104. package/dist/esm/index.js.map +1 -1
  105. package/dist/esm/labels/gmail-labels.js.map +1 -1
  106. package/dist/esm/lib/base64-encoding.js.map +1 -1
  107. package/dist/esm/lib/create-store.js.map +1 -1
  108. package/dist/esm/lib/date-conversion.js.map +1 -1
  109. package/dist/esm/lib/messages-to-row.js.map +1 -1
  110. package/dist/esm/mcp/index.js.map +1 -1
  111. package/dist/esm/mcp/prompts/draft-email.js.map +1 -1
  112. package/dist/esm/mcp/prompts/index.js.map +1 -1
  113. package/dist/esm/mcp/prompts/query-syntax.js.map +1 -1
  114. package/dist/esm/mcp/resources/email.js.map +1 -1
  115. package/dist/esm/mcp/resources/index.js.map +1 -1
  116. package/dist/esm/mcp/tools/categories-list.js.map +1 -1
  117. package/dist/esm/mcp/tools/index.js.map +1 -1
  118. package/dist/esm/mcp/tools/label-add.js.map +1 -1
  119. package/dist/esm/mcp/tools/label-delete.d.ts +1 -1
  120. package/dist/esm/mcp/tools/label-delete.js.map +1 -1
  121. package/dist/esm/mcp/tools/labels-list.js.map +1 -1
  122. package/dist/esm/mcp/tools/message-get.d.ts +21 -21
  123. package/dist/esm/mcp/tools/message-get.js.map +1 -1
  124. package/dist/esm/mcp/tools/message-mark-read.js.map +1 -1
  125. package/dist/esm/mcp/tools/message-move-to-trash.d.ts +1 -1
  126. package/dist/esm/mcp/tools/message-move-to-trash.js.map +1 -1
  127. package/dist/esm/mcp/tools/message-respond.js.map +1 -1
  128. package/dist/esm/mcp/tools/message-search.d.ts +25 -25
  129. package/dist/esm/mcp/tools/message-search.js +13 -12
  130. package/dist/esm/mcp/tools/message-search.js.map +1 -1
  131. package/dist/esm/mcp/tools/message-send.d.ts +3 -3
  132. package/dist/esm/mcp/tools/message-send.js.map +1 -1
  133. package/dist/esm/mcp/tools/messages-export-csv.d.ts +2 -2
  134. package/dist/esm/mcp/tools/messages-export-csv.js +9 -8
  135. package/dist/esm/mcp/tools/messages-export-csv.js.map +1 -1
  136. package/dist/esm/schemas/gmail-query-schema.d.ts +2 -1
  137. package/dist/esm/schemas/gmail-query-schema.js +18 -21
  138. package/dist/esm/schemas/gmail-query-schema.js.map +1 -1
  139. package/dist/esm/schemas/index.js.map +1 -1
  140. package/dist/esm/setup/config.js.map +1 -1
  141. package/dist/esm/setup/http.js.map +1 -1
  142. package/dist/esm/setup/index.js.map +1 -1
  143. package/dist/esm/setup/oauth-google.js.map +1 -1
  144. package/dist/esm/setup/runtime.d.ts +1 -1
  145. package/dist/esm/setup/runtime.js.map +1 -1
  146. package/dist/esm/setup/stdio.js.map +1 -1
  147. package/dist/esm/types.js.map +1 -1
  148. package/package.json +11 -7
@@ -1 +1 @@
1
- {"version":3,"sources":["/Users/kevin/Dev/Projects/mcp-z/mcp-gmail/src/mcp/tools/message-get.ts"],"sourcesContent":["import { EMAIL_COMMON_PATTERNS, EMAIL_FIELD_DESCRIPTIONS, EMAIL_FIELDS, EmailContentTypeSchema, type EmailDetail, EmailDetailSchema, ExcludeThreadHistorySchema } from '@mcp-z/email';\nimport type { EnrichedExtra } from '@mcp-z/oauth-google';\nimport { schemas } from '@mcp-z/oauth-google';\n\nconst { AuthRequiredBranchSchema } = schemas;\n\nimport { createFieldsSchema, filterFields, parseFields, type ToolModule } from '@mcp-z/server';\nimport { ErrorCode, McpError } from '@modelcontextprotocol/sdk/types.js';\nimport { type gmail_v1, google } from 'googleapis';\nimport { z } from 'zod';\nimport { extractBodyFromPayload, extractEmails, extractFrom } from '../../email/parsing/message-extraction.ts';\nimport { toIsoUtc } from '../../lib/date-conversion.ts';\n\nconst inputSchema = z.object({\n id: z.coerce.string().trim().min(1).describe('Gmail message ID to retrieve'),\n fields: createFieldsSchema({\n availableFields: EMAIL_FIELDS,\n fieldDescriptions: EMAIL_FIELD_DESCRIPTIONS,\n commonPatterns: EMAIL_COMMON_PATTERNS,\n resourceName: 'email message',\n }),\n contentType: EmailContentTypeSchema,\n excludeThreadHistory: ExcludeThreadHistorySchema,\n});\n\n// Success branch schema\nconst successBranchSchema = z.object({\n type: z.literal('success'),\n item: EmailDetailSchema,\n});\n\n// Output schema with auth_required support\nconst outputSchema = z.discriminatedUnion('type', [successBranchSchema, AuthRequiredBranchSchema]);\n\nconst config = {\n description: 'Get a Gmail message by ID with flexible field selection',\n inputSchema: inputSchema,\n outputSchema: z.object({\n result: outputSchema,\n }),\n} as const;\n\nexport type Input = z.infer<typeof inputSchema>;\nexport type Output = z.infer<typeof outputSchema>;\n\nasync function handler({ id, fields, contentType, excludeThreadHistory }: Input, extra: EnrichedExtra) {\n const logger = extra.logger;\n\n const requestedFields = parseFields(fields, EMAIL_FIELDS);\n\n logger.info('gmail.message.get called', { id: Boolean(id), fields: fields || 'all' });\n\n try {\n if (!id) {\n throw new McpError(ErrorCode.InvalidParams, 'Missing id');\n }\n\n const gmail = google.gmail({ version: 'v1', auth: extra.authContext.auth });\n const response = await gmail.users.messages.get({\n userId: 'me',\n id: id,\n format: 'full',\n metadataHeaders: ['From', 'To', 'Cc', 'Bcc', 'Subject', 'Date'],\n });\n const fullData = response.data;\n if (!fullData) {\n throw new McpError(ErrorCode.InvalidRequest, 'Message not found');\n }\n\n // Build full message data with type guards\n const headers = fullData?.payload?.headers;\n const headersArray = Array.isArray(headers) ? headers : [];\n const headersMap: Record<string, string> = Object.fromEntries(\n headersArray.map((h: unknown) => {\n const header = h as gmail_v1.Schema$MessagePartHeader;\n return [String(header.name ?? ''), String(header.value ?? '')];\n })\n );\n const fromInfo = extractFrom(headersMap.From);\n const toStr = extractEmails(headersMap.To).join(', ');\n const ccStr = extractEmails(headersMap.Cc).join(', ');\n const bccStr = extractEmails(headersMap.Bcc).join(', ');\n const messagePayload = fullData?.payload;\n const bodyContent = messagePayload ? extractBodyFromPayload(messagePayload, { contentType, excludeThreadHistory }) : '';\n const payload: Partial<EmailDetail> = {\n id: fullData.id ?? undefined,\n threadId: fullData.threadId ?? undefined,\n date: toIsoUtc(headersMap.Date) || headersMap.Date,\n from: fromInfo?.address || headersMap.From,\n fromName: fromInfo?.name,\n to: toStr,\n cc: ccStr,\n bcc: bccStr,\n subject: headersMap.Subject ?? '',\n snippet: fullData.snippet ?? undefined,\n body: bodyContent,\n bodyContentType: contentType,\n };\n\n // Filter based on requested fields\n const filteredPayload = filterFields(payload, requestedFields);\n\n logger.info('gmail.message.get result', { id: fullData.id, subject: payload.subject, from: payload.from, fields: fields || 'all' });\n\n const result: Output = {\n type: 'success' as const,\n item: filteredPayload,\n };\n\n return {\n content: [\n {\n type: 'text' as const,\n text: JSON.stringify(result),\n },\n ],\n structuredContent: { result },\n };\n } catch (error) {\n const message = error instanceof Error ? error.message : String(error);\n logger.error('gmail.message.get error', { error: message });\n\n throw new McpError(ErrorCode.InternalError, `Error getting message: ${message}`, {\n stack: error instanceof Error ? error.stack : undefined,\n });\n }\n}\n\nexport default function createTool() {\n return {\n name: 'message-get',\n config,\n handler,\n } satisfies ToolModule;\n}\n"],"names":["createTool","AuthRequiredBranchSchema","schemas","inputSchema","z","object","id","coerce","string","trim","min","describe","fields","createFieldsSchema","availableFields","EMAIL_FIELDS","fieldDescriptions","EMAIL_FIELD_DESCRIPTIONS","commonPatterns","EMAIL_COMMON_PATTERNS","resourceName","contentType","EmailContentTypeSchema","excludeThreadHistory","ExcludeThreadHistorySchema","successBranchSchema","type","literal","item","EmailDetailSchema","outputSchema","discriminatedUnion","config","description","result","handler","extra","logger","requestedFields","fullData","headersMap","gmail","response","headers","headersArray","fromInfo","toStr","ccStr","bccStr","messagePayload","bodyContent","payload","filteredPayload","error","message","parseFields","info","Boolean","McpError","ErrorCode","InvalidParams","google","version","auth","authContext","users","messages","get","userId","format","metadataHeaders","data","InvalidRequest","Array","isArray","Object","fromEntries","map","h","header","String","name","value","extractFrom","From","extractEmails","To","join","Cc","Bcc","extractBodyFromPayload","undefined","threadId","date","toIsoUtc","Date","from","address","fromName","to","cc","bcc","subject","Subject","snippet","body","bodyContentType","filterFields","content","text","JSON","stringify","structuredContent","Error","InternalError","stack"],"mappings":";;;;+BAgIA;;;eAAwBA;;;qBAhI+I;2BAE/I;sBAIuD;qBAC3C;0BACE;mBACpB;mCACiD;gCAC1C;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAPzB,IAAM,AAAEC,2BAA6BC,oBAAO,CAApCD;AASR,IAAME,cAAcC,MAAC,CAACC,MAAM,CAAC;IAC3BC,IAAIF,MAAC,CAACG,MAAM,CAACC,MAAM,GAAGC,IAAI,GAAGC,GAAG,CAAC,GAAGC,QAAQ,CAAC;IAC7CC,QAAQC,IAAAA,0BAAkB,EAAC;QACzBC,iBAAiBC,mBAAY;QAC7BC,mBAAmBC,+BAAwB;QAC3CC,gBAAgBC,4BAAqB;QACrCC,cAAc;IAChB;IACAC,aAAaC,6BAAsB;IACnCC,sBAAsBC,iCAA0B;AAClD;AAEA,wBAAwB;AACxB,IAAMC,sBAAsBrB,MAAC,CAACC,MAAM,CAAC;IACnCqB,MAAMtB,MAAC,CAACuB,OAAO,CAAC;IAChBC,MAAMC,wBAAiB;AACzB;AAEA,2CAA2C;AAC3C,IAAMC,eAAe1B,MAAC,CAAC2B,kBAAkB,CAAC,QAAQ;IAACN;IAAqBxB;CAAyB;AAEjG,IAAM+B,SAAS;IACbC,aAAa;IACb9B,aAAaA;IACb2B,cAAc1B,MAAC,CAACC,MAAM,CAAC;QACrB6B,QAAQJ;IACV;AACF;AAKA,SAAeK;wCAAQ,KAAwD,EAAEC,KAAoB;YAA5E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BAEA,mCAAmC;oBAC7B+B,kBAAkBuD,IAAAA,oBAAY,EAACxD,SAASb;oBAE9CD,OAAOmB,IAAI,CAAC,4BAA4B;wBAAElD,IAAIiC,SAASjC,EAAE;wBAAEgG,SAASnD,QAAQmD,OAAO;wBAAEN,MAAM7C,QAAQ6C,IAAI;wBAAEpF,QAAQA,UAAU;oBAAM;oBAE3HsB,SAAiB;wBACrBR,MAAM;wBACNE,MAAMwB;oBACR;oBAEA;;wBAAO;4BACLwD,OAAO;gCACL;oCACElF,MAAM;oCACNmF,MAAMC,KAAKC,SAAS,CAAC7E;gCACvB;;4BAEF8E,mBAAmB;gCAAE9E,QAAAA;4BAAO;wBAC9B;;;oBACOmB;oBACDC,UAAUD,AAAK,YAALA,OAAiB4D,SAAQ5D,MAAMC,OAAO,GAAG0B,OAAO3B;oBAChEhB,OAAOgB,KAAK,CAAC,2BAA2B;wBAAEA,OAAOC;oBAAQ;oBAEzD,MAAM,IAAII,eAAQ,CAACC,gBAAS,CAACuD,aAAa,EAAE,AAAC,0BAAiC,OAAR5D,UAAW;wBAC/E6D,OAAO9D,AAAK,YAALA,OAAiB4D,SAAQ5D,MAAM8D,KAAK,GAAGxB;oBAChD;;;;;;;IAEJ;;AAEe,SAAS3F;IACtB,OAAO;QACLiF,MAAM;QACNjD,QAAAA;QACAG,SAAAA;IACF;AACF"}
1
+ {"version":3,"sources":["/Users/kevin/Dev/OpenSource/ai/mcp-z/mcp-gmail/src/mcp/tools/message-get.ts"],"sourcesContent":["import { EMAIL_COMMON_PATTERNS, EMAIL_FIELD_DESCRIPTIONS, EMAIL_FIELDS, EmailContentTypeSchema, type EmailDetail, EmailDetailSchema, ExcludeThreadHistorySchema } from '@mcp-z/email';\nimport type { EnrichedExtra } from '@mcp-z/oauth-google';\nimport { schemas } from '@mcp-z/oauth-google';\n\nconst { AuthRequiredBranchSchema } = schemas;\n\nimport { createFieldsSchema, filterFields, parseFields, type ToolModule } from '@mcp-z/server';\nimport { ErrorCode, McpError } from '@modelcontextprotocol/sdk/types.js';\nimport { type gmail_v1, google } from 'googleapis';\nimport { z } from 'zod';\nimport { extractBodyFromPayload, extractEmails, extractFrom } from '../../email/parsing/message-extraction.ts';\nimport { toIsoUtc } from '../../lib/date-conversion.ts';\n\nconst inputSchema = z.object({\n id: z.coerce.string().trim().min(1).describe('Gmail message ID to retrieve'),\n fields: createFieldsSchema({\n availableFields: EMAIL_FIELDS,\n fieldDescriptions: EMAIL_FIELD_DESCRIPTIONS,\n commonPatterns: EMAIL_COMMON_PATTERNS,\n resourceName: 'email message',\n }),\n contentType: EmailContentTypeSchema,\n excludeThreadHistory: ExcludeThreadHistorySchema,\n});\n\n// Success branch schema\nconst successBranchSchema = z.object({\n type: z.literal('success'),\n item: EmailDetailSchema,\n});\n\n// Output schema with auth_required support\nconst outputSchema = z.discriminatedUnion('type', [successBranchSchema, AuthRequiredBranchSchema]);\n\nconst config = {\n description: 'Get a Gmail message by ID with flexible field selection',\n inputSchema: inputSchema,\n outputSchema: z.object({\n result: outputSchema,\n }),\n} as const;\n\nexport type Input = z.infer<typeof inputSchema>;\nexport type Output = z.infer<typeof outputSchema>;\n\nasync function handler({ id, fields, contentType, excludeThreadHistory }: Input, extra: EnrichedExtra) {\n const logger = extra.logger;\n\n const requestedFields = parseFields(fields, EMAIL_FIELDS);\n\n logger.info('gmail.message.get called', { id: Boolean(id), fields: fields || 'all' });\n\n try {\n if (!id) {\n throw new McpError(ErrorCode.InvalidParams, 'Missing id');\n }\n\n const gmail = google.gmail({ version: 'v1', auth: extra.authContext.auth });\n const response = await gmail.users.messages.get({\n userId: 'me',\n id: id,\n format: 'full',\n metadataHeaders: ['From', 'To', 'Cc', 'Bcc', 'Subject', 'Date'],\n });\n const fullData = response.data;\n if (!fullData) {\n throw new McpError(ErrorCode.InvalidRequest, 'Message not found');\n }\n\n // Build full message data with type guards\n const headers = fullData?.payload?.headers;\n const headersArray = Array.isArray(headers) ? headers : [];\n const headersMap: Record<string, string> = Object.fromEntries(\n headersArray.map((h: unknown) => {\n const header = h as gmail_v1.Schema$MessagePartHeader;\n return [String(header.name ?? ''), String(header.value ?? '')];\n })\n );\n const fromInfo = extractFrom(headersMap.From);\n const toStr = extractEmails(headersMap.To).join(', ');\n const ccStr = extractEmails(headersMap.Cc).join(', ');\n const bccStr = extractEmails(headersMap.Bcc).join(', ');\n const messagePayload = fullData?.payload;\n const bodyContent = messagePayload ? extractBodyFromPayload(messagePayload, { contentType, excludeThreadHistory }) : '';\n const payload: Partial<EmailDetail> = {\n id: fullData.id ?? undefined,\n threadId: fullData.threadId ?? undefined,\n date: toIsoUtc(headersMap.Date) || headersMap.Date,\n from: fromInfo?.address || headersMap.From,\n fromName: fromInfo?.name,\n to: toStr,\n cc: ccStr,\n bcc: bccStr,\n subject: headersMap.Subject ?? '',\n snippet: fullData.snippet ?? undefined,\n body: bodyContent,\n bodyContentType: contentType,\n };\n\n // Filter based on requested fields\n const filteredPayload = filterFields(payload, requestedFields);\n\n logger.info('gmail.message.get result', { id: fullData.id, subject: payload.subject, from: payload.from, fields: fields || 'all' });\n\n const result: Output = {\n type: 'success' as const,\n item: filteredPayload,\n };\n\n return {\n content: [\n {\n type: 'text' as const,\n text: JSON.stringify(result),\n },\n ],\n structuredContent: { result },\n };\n } catch (error) {\n const message = error instanceof Error ? error.message : String(error);\n logger.error('gmail.message.get error', { error: message });\n\n throw new McpError(ErrorCode.InternalError, `Error getting message: ${message}`, {\n stack: error instanceof Error ? error.stack : undefined,\n });\n }\n}\n\nexport default function createTool() {\n return {\n name: 'message-get',\n config,\n handler,\n } satisfies ToolModule;\n}\n"],"names":["createTool","AuthRequiredBranchSchema","schemas","inputSchema","z","object","id","coerce","string","trim","min","describe","fields","createFieldsSchema","availableFields","EMAIL_FIELDS","fieldDescriptions","EMAIL_FIELD_DESCRIPTIONS","commonPatterns","EMAIL_COMMON_PATTERNS","resourceName","contentType","EmailContentTypeSchema","excludeThreadHistory","ExcludeThreadHistorySchema","successBranchSchema","type","literal","item","EmailDetailSchema","outputSchema","discriminatedUnion","config","description","result","handler","extra","logger","requestedFields","fullData","headersMap","gmail","response","headers","headersArray","fromInfo","toStr","ccStr","bccStr","messagePayload","bodyContent","payload","filteredPayload","error","message","parseFields","info","Boolean","McpError","ErrorCode","InvalidParams","google","version","auth","authContext","users","messages","get","userId","format","metadataHeaders","data","InvalidRequest","Array","isArray","Object","fromEntries","map","h","header","String","name","value","extractFrom","From","extractEmails","To","join","Cc","Bcc","extractBodyFromPayload","undefined","threadId","date","toIsoUtc","Date","from","address","fromName","to","cc","bcc","subject","Subject","snippet","body","bodyContentType","filterFields","content","text","JSON","stringify","structuredContent","Error","InternalError","stack"],"mappings":";;;;+BAgIA;;;eAAwBA;;;qBAhI+I;2BAE/I;sBAIuD;qBAC3C;0BACE;mBACpB;mCACiD;gCAC1C;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAPzB,IAAM,AAAEC,2BAA6BC,oBAAO,CAApCD;AASR,IAAME,cAAcC,MAAC,CAACC,MAAM,CAAC;IAC3BC,IAAIF,MAAC,CAACG,MAAM,CAACC,MAAM,GAAGC,IAAI,GAAGC,GAAG,CAAC,GAAGC,QAAQ,CAAC;IAC7CC,QAAQC,IAAAA,0BAAkB,EAAC;QACzBC,iBAAiBC,mBAAY;QAC7BC,mBAAmBC,+BAAwB;QAC3CC,gBAAgBC,4BAAqB;QACrCC,cAAc;IAChB;IACAC,aAAaC,6BAAsB;IACnCC,sBAAsBC,iCAA0B;AAClD;AAEA,wBAAwB;AACxB,IAAMC,sBAAsBrB,MAAC,CAACC,MAAM,CAAC;IACnCqB,MAAMtB,MAAC,CAACuB,OAAO,CAAC;IAChBC,MAAMC,wBAAiB;AACzB;AAEA,2CAA2C;AAC3C,IAAMC,eAAe1B,MAAC,CAAC2B,kBAAkB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AKrD;wBACLsD,OAAO,GAAE9D,sBAAAA,WAAW+D,OAAO,cAAlB/D,iCAAAA,sBAAsB;wBAC/BgE,OAAO,GAAEjE,oBAAAA,SAASiE,OAAO,cAAhBjE,+BAAAA,oBAAoBoD;wBAC7Bc,MAAMvD;wBACNwD,iBAAiBrF;oBACnB;oBAEA,mCAAmC;oBAC7B+B,kBAAkBuD,IAAAA,oBAAY,EAACxD,SAASb;oBAE9CD,OAAOmB,IAAI,CAAC,4BAA4B;wBAAElD,IAAIiC,SAASjC,EAAE;wBAAEgG,SAASnD,QAAQmD,OAAO;wBAAEN,MAAM7C,QAAQ6C,IAAI;wBAAEpF,QAAQA,UAAU;oBAAM;oBAE3HsB,SAAiB;wBACrBR,MAAM;wBACNE,MAAMwB;oBACR;oBAEA;;wBAAO;4BACLwD,OAAO;gCACL;oCACElF,MAAM;oCACNmF,MAAMC,KAAKC,SAAS,CAAC7E;gCACvB;;4BAEF8E,mBAAmB;gCAAE9E,QAAAA;4BAAO;wBAC9B;;;oBACOmB;oBACDC,UAAUD,AAAK,YAALA,OAAiB4D,SAAQ5D,MAAMC,OAAO,GAAG0B,OAAO3B;oBAChEhB,OAAOgB,KAAK,CAAC,2BAA2B;wBAAEA,OAAOC;oBAAQ;oBAEzD,MAAM,IAAII,eAAQ,CAACC,gBAAS,CAACuD,aAAa,EAAE,AAAC,0BAAiC,OAAR5D,UAAW;wBAC/E6D,OAAO9D,AAAK,YAALA,OAAiB4D,SAAQ5D,MAAM8D,KAAK,GAAGxB;oBAChD;;;;;;;IAEJ;;AAEe,SAAS3F;IACtB,OAAO;QACLiF,MAAM;QACNjD,QAAAA;QACAG,SAAAA;IACF;AACF"}
@@ -20,11 +20,8 @@ function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) {
20
20
  reject(error);
21
21
  return;
22
22
  }
23
- if (info.done) {
24
- resolve(value);
25
- } else {
26
- Promise.resolve(value).then(_next, _throw);
27
- }
23
+ if (info.done) resolve(value);
24
+ else Promise.resolve(value).then(_next, _throw);
28
25
  }
29
26
  function _async_to_generator(fn) {
30
27
  return function() {
@@ -42,11 +39,10 @@ function _async_to_generator(fn) {
42
39
  };
43
40
  }
44
41
  function _instanceof(left, right) {
42
+ "@swc/helpers - instanceof";
45
43
  if (right != null && typeof Symbol !== "undefined" && right[Symbol.hasInstance]) {
46
44
  return !!right[Symbol.hasInstance](left);
47
- } else {
48
- return left instanceof right;
49
- }
45
+ } else return left instanceof right;
50
46
  }
51
47
  function _ts_generator(thisArg, body) {
52
48
  var f, y, t, _ = {
@@ -1 +1 @@
1
- {"version":3,"sources":["/Users/kevin/Dev/Projects/mcp-z/mcp-gmail/src/mcp/tools/message-mark-read.ts"],"sourcesContent":["import type { EnrichedExtra } from '@mcp-z/oauth-google';\nimport { schemas } from '@mcp-z/oauth-google';\n\nconst { AuthRequiredBranchSchema } = schemas;\n\nimport type { ToolModule } from '@mcp-z/server';\nimport { ErrorCode, McpError } from '@modelcontextprotocol/sdk/types.js';\nimport { google } from 'googleapis';\nimport { z } from 'zod';\n\nconst inputSchema = z.object({\n id: z.coerce.string().trim().min(1).describe('Gmail message ID to mark as read'),\n});\n\nconst successBranchSchema = z.object({\n type: z.literal('success'),\n id: z.string().describe('Message ID that was marked as read'),\n});\n\nconst outputSchema = z.discriminatedUnion('type', [successBranchSchema, AuthRequiredBranchSchema]);\n\nconst config = {\n description: 'Mark a Gmail message as read',\n inputSchema: inputSchema,\n outputSchema: z.object({\n result: outputSchema,\n }),\n} as const;\n\nexport type Input = z.infer<typeof inputSchema>;\nexport type Output = z.infer<typeof outputSchema>;\n\nasync function handler({ id }: Input, extra: EnrichedExtra) {\n const logger = extra.logger;\n logger.info('gmail-message-mark-read called', { id: Boolean(id) });\n\n if (!id) {\n throw new McpError(ErrorCode.InvalidParams, 'Missing id');\n }\n\n try {\n const gmail = google.gmail({ version: 'v1', auth: extra.authContext.auth });\n await gmail.users.messages.modify({\n userId: 'me',\n id: id,\n requestBody: {\n removeLabelIds: ['UNREAD'],\n },\n });\n\n logger.info('gmail-message-mark-read success', { id });\n\n const result: Output = {\n type: 'success' as const,\n id,\n };\n\n return {\n content: [\n {\n type: 'text' as const,\n text: JSON.stringify(result),\n },\n ],\n structuredContent: { result },\n };\n } catch (error) {\n const message = error instanceof Error ? error.message : String(error);\n logger.error('gmail-message-mark-read error', { error: message });\n\n throw new McpError(ErrorCode.InternalError, `Error marking message as read: ${message}`, {\n stack: error instanceof Error ? error.stack : undefined,\n });\n }\n}\n\nexport default function createTool() {\n return {\n name: 'message-mark-read',\n config,\n handler,\n } satisfies ToolModule;\n}\n"],"names":["createTool","AuthRequiredBranchSchema","schemas","inputSchema","z","object","id","coerce","string","trim","min","describe","successBranchSchema","type","literal","outputSchema","discriminatedUnion","config","description","result","handler","extra","logger","gmail","error","message","info","Boolean","McpError","ErrorCode","InvalidParams","google","version","auth","authContext","users","messages","modify","userId","requestBody","removeLabelIds","content","text","JSON","stringify","structuredContent","Error","String","InternalError","stack","undefined","name"],"mappings":";;;;+BA4EA;;;eAAwBA;;;2BA3EA;qBAKY;0BACb;mBACL;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AALlB,IAAM,AAAEC,2BAA6BC,oBAAO,CAApCD;AAOR,IAAME,cAAcC,MAAC,CAACC,MAAM,CAAC;IAC3BC,IAAIF,MAAC,CAACG,MAAM,CAACC,MAAM,GAAGC,IAAI,GAAGC,GAAG,CAAC,GAAGC,QAAQ,CAAC;AAC/C;AAEA,IAAMC,sBAAsBR,MAAC,CAACC,MAAM,CAAC;IACnCQ,MAAMT,MAAC,CAACU,OAAO,CAAC;IAChBR,IAAIF,MAAC,CAACI,MAAM,GAAGG,QAAQ,CAAC;AAC1B;AAEA,IAAMI,eAAeX,MAAC,CAACY,kBAAkB,CAAC,QAAQ;I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BsB,SAAQtB,MAAMyB,KAAK,GAAGC;oBAChD;;;;;;;IAEJ;;AAEe,SAASlD;IACtB,OAAO;QACLmD,MAAM;QACNlC,QAAAA;QACAG,SAAAA;IACF;AACF"}
1
+ {"version":3,"sources":["/Users/kevin/Dev/OpenSource/ai/mcp-z/mcp-gmail/src/mcp/tools/message-mark-read.ts"],"sourcesContent":["import type { EnrichedExtra } from '@mcp-z/oauth-google';\nimport { schemas } from '@mcp-z/oauth-google';\n\nconst { AuthRequiredBranchSchema } = schemas;\n\nimport type { ToolModule } from '@mcp-z/server';\nimport { ErrorCode, McpError } from '@modelcontextprotocol/sdk/types.js';\nimport { google } from 'googleapis';\nimport { z } from 'zod';\n\nconst inputSchema = z.object({\n id: z.coerce.string().trim().min(1).describe('Gmail message ID to mark as read'),\n});\n\nconst successBranchSchema = z.object({\n type: z.literal('success'),\n id: z.string().describe('Message ID that was marked as read'),\n});\n\nconst outputSchema = z.discriminatedUnion('type', [successBranchSchema, AuthRequiredBranchSchema]);\n\nconst config = {\n description: 'Mark a Gmail message as read',\n inputSchema: inputSchema,\n outputSchema: z.object({\n result: outputSchema,\n }),\n} as const;\n\nexport type Input = z.infer<typeof inputSchema>;\nexport type Output = z.infer<typeof outputSchema>;\n\nasync function handler({ id }: Input, extra: EnrichedExtra) {\n const logger = extra.logger;\n logger.info('gmail-message-mark-read called', { id: Boolean(id) });\n\n if (!id) {\n throw new McpError(ErrorCode.InvalidParams, 'Missing id');\n }\n\n try {\n const gmail = google.gmail({ version: 'v1', auth: extra.authContext.auth });\n await gmail.users.messages.modify({\n userId: 'me',\n id: id,\n requestBody: {\n removeLabelIds: ['UNREAD'],\n },\n });\n\n logger.info('gmail-message-mark-read success', { id });\n\n const result: Output = {\n type: 'success' as const,\n id,\n };\n\n return {\n content: [\n {\n type: 'text' as const,\n text: JSON.stringify(result),\n },\n ],\n structuredContent: { result },\n };\n } catch (error) {\n const message = error instanceof Error ? error.message : String(error);\n logger.error('gmail-message-mark-read error', { error: message });\n\n throw new McpError(ErrorCode.InternalError, `Error marking message as read: ${message}`, {\n stack: error instanceof Error ? error.stack : undefined,\n });\n }\n}\n\nexport default function createTool() {\n return {\n name: 'message-mark-read',\n config,\n handler,\n } satisfies ToolModule;\n}\n"],"names":["createTool","AuthRequiredBranchSchema","schemas","inputSchema","z","object","id","coerce","string","trim","min","describe","successBranchSchema","type","literal","outputSchema","discriminatedUnion","config","description","result","handler","extra","logger","gmail","error","message","info","Boolean","McpError","ErrorCode","InvalidParams","google","version","auth","authContext","users","messages","modify","userId","requestBody","removeLabelIds","content","text","JSON","stringify","structuredContent","Error","String","InternalError","stack","undefined","name"],"mappings":";;;;+BA4EA;;;eAAwBA;;;2BA3EA;qBAKY;0BACb;mBACL;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AALlB,IAAM,AAAEC,2BAA6BC,oBAAO,CAApCD;AAOR,IAAME,cAAcC,MAAC,CAACC,MAAM,CAAC;IAC3BC,IAAIF,MAAC,CAACG,MAAM,CAACC,MAAM,GAAGC,IAAI,GAAGC,GAAG,CAAC,GAAGC,QAAQ,CAAC;AAC/C;AAEA,IAAMC,sBAAsBR,MAAC,CAACC,MAAM,CAAC;IACnCQ,MAAMT,MAAC,CAACU,OAAO,CAAC;IAChBR,IAAIF,MAAC,CAACI,MAAM,GAAGG,QAAQ,CAAC;AAC1B;AAEA,IAAMI,eAAeX,MAAC,CAACY,kBAAkB,CAAC,QAAQ;IAACJ;IAAqBX;CAAyB;AAEjG,IAAMgB,SAAS;IACbC,aAAa;IACbf,aAAaA;IACbY,cAAcX,MAAC,CAACC,MAAM,CAAC;QACrBc,QAAQJ;IACV;AACF;AAKA,SAAeK;wCAAQ,KAAa,EAAEC,KAAoB;YAAjCf,IACjBgB,QAQEC,OAWAJ,QAcCK,OACDC;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37
  success: boolean;
38
- error?: string;
38
+ error?: string | undefined;
39
39
  }[];
40
40
  };
41
41
  };
@@ -35,7 +35,7 @@ declare function handler({ ids }: Input, extra: EnrichedExtra): Promise<{
35
35
  results: {
36
36
  id: string;
37
37
  success: boolean;
38
- error?: string;
38
+ error?: string | undefined;
39
39
  }[];
40
40
  };
41
41
  };
@@ -29,11 +29,8 @@ function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) {
29
29
  reject(error);
30
30
  return;
31
31
  }
32
- if (info.done) {
33
- resolve(value);
34
- } else {
35
- Promise.resolve(value).then(_next, _throw);
36
- }
32
+ if (info.done) resolve(value);
33
+ else Promise.resolve(value).then(_next, _throw);
37
34
  }
38
35
  function _async_to_generator(fn) {
39
36
  return function() {
@@ -51,33 +48,22 @@ function _async_to_generator(fn) {
51
48
  };
52
49
  }
53
50
  function _instanceof(left, right) {
51
+ "@swc/helpers - instanceof";
54
52
  if (right != null && typeof Symbol !== "undefined" && right[Symbol.hasInstance]) {
55
53
  return !!right[Symbol.hasInstance](left);
56
- } else {
57
- return left instanceof right;
58
- }
54
+ } else return left instanceof right;
59
55
  }
60
56
  function _iterable_to_array(iter) {
61
- if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter);
57
+ if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) {
58
+ return Array.from(iter);
59
+ }
62
60
  }
63
61
  function _non_iterable_spread() {
64
- throw new TypeError("Invalid attempt to spread non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
62
+ throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
65
63
  }
66
64
  function _to_consumable_array(arr) {
67
65
  return _array_without_holes(arr) || _iterable_to_array(arr) || _unsupported_iterable_to_array(arr) || _non_iterable_spread();
68
66
  }
69
- function _type_of(obj) {
70
- "@swc/helpers - typeof";
71
- return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj;
72
- }
73
- function _unsupported_iterable_to_array(o, minLen) {
74
- if (!o) return;
75
- if (typeof o === "string") return _array_like_to_array(o, minLen);
76
- var n = Object.prototype.toString.call(o).slice(8, -1);
77
- if (n === "Object" && o.constructor) n = o.constructor.name;
78
- if (n === "Map" || n === "Set") return Array.from(n);
79
- if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _array_like_to_array(o, minLen);
80
- }
81
67
  function _ts_generator(thisArg, body) {
82
68
  var f, y, t, _ = {
83
69
  label: 0,
@@ -179,18 +165,36 @@ function _ts_generator(thisArg, body) {
179
165
  }
180
166
  function _ts_values(o) {
181
167
  var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
182
- if (m) return m.call(o);
183
- if (o && typeof o.length === "number") return {
184
- next: function() {
185
- if (o && i >= o.length) o = void 0;
186
- return {
187
- value: o && o[i++],
188
- done: !o
189
- };
190
- }
191
- };
168
+ if (m) {
169
+ return m.call(o);
170
+ }
171
+ if (o && typeof o.length === "number") {
172
+ return {
173
+ next: function() {
174
+ if (o && i >= o.length) {
175
+ o = void 0;
176
+ }
177
+ return {
178
+ value: o && o[i++],
179
+ done: !o
180
+ };
181
+ }
182
+ };
183
+ }
192
184
  throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
193
185
  }
186
+ function _type_of(obj) {
187
+ "@swc/helpers - typeof";
188
+ return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj;
189
+ }
190
+ function _unsupported_iterable_to_array(o, minLen) {
191
+ if (!o) return;
192
+ if (typeof o === "string") return _array_like_to_array(o, minLen);
193
+ var n = Object.prototype.toString.call(o).slice(8, -1);
194
+ if (n === "Object" && o.constructor) n = o.constructor.name;
195
+ if (n === "Map" || n === "Set") return Array.from(n);
196
+ if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _array_like_to_array(o, minLen);
197
+ }
194
198
  var AuthRequiredBranchSchema = _oauthgoogle.schemas.AuthRequiredBranchSchema;
195
199
  var inputSchema = _zod.z.object({
196
200
  ids: _zod.z.array(_zod.z.coerce.string().trim().min(1)).min(1).describe('Gmail message IDs to move to trash')
@@ -1 +1 @@
1
- {"version":3,"sources":["/Users/kevin/Dev/Projects/mcp-z/mcp-gmail/src/mcp/tools/message-move-to-trash.ts"],"sourcesContent":["import type { EnrichedExtra } from '@mcp-z/oauth-google';\nimport { schemas } from '@mcp-z/oauth-google';\n\nconst { AuthRequiredBranchSchema } = schemas;\n\nimport type { ToolModule } from '@mcp-z/server';\nimport { ErrorCode, McpError } from '@modelcontextprotocol/sdk/types.js';\nimport { google } from 'googleapis';\nimport { z } from 'zod';\nimport { CHUNK_SIZE, MAX_BATCH_SIZE } from '../../constants.ts';\n\nconst inputSchema = z.object({\n ids: z.array(z.coerce.string().trim().min(1)).min(1).describe('Gmail message IDs to move to trash'),\n});\n\nconst successBranchSchema = z.object({\n type: z.literal('success'),\n totalRequested: z.number().describe('Total number of messages requested to trash'),\n successCount: z.number().describe('Number of messages successfully moved to trash'),\n failureCount: z.number().describe('Number of messages that failed to move'),\n results: z\n .array(\n z.object({\n id: z.string().describe('Message ID'),\n success: z.boolean().describe('Whether the operation succeeded'),\n error: z.string().optional().describe('Error message if operation failed'),\n })\n )\n .describe('Individual results for each message'),\n});\n\nconst outputSchema = z.discriminatedUnion('type', [successBranchSchema, AuthRequiredBranchSchema]);\n\nconst config = {\n description: 'Move Gmail messages to trash (recoverable).',\n inputSchema: inputSchema,\n outputSchema: z.object({\n result: outputSchema,\n }),\n} as const;\n\nexport type Input = z.infer<typeof inputSchema>;\nexport type Output = z.infer<typeof outputSchema>;\n\nasync function handler({ ids }: Input, extra: EnrichedExtra) {\n const logger = extra.logger;\n logger.info('gmail-message-move-to-trash called', { count: ids.length });\n\n if (!ids || ids.length === 0) {\n throw new McpError(ErrorCode.InvalidParams, 'Missing ids');\n }\n\n // Validate batch size to prevent memory exhaustion\n if (ids.length > MAX_BATCH_SIZE) {\n throw new McpError(ErrorCode.InvalidParams, `Batch size ${ids.length} exceeds maximum allowed size of ${MAX_BATCH_SIZE}`);\n }\n\n // Validate and sanitize IDs\n const validatedIds: string[] = [];\n const invalidIds: string[] = [];\n\n for (const id of ids) {\n const trimmedId = id.trim();\n if (!trimmedId) {\n invalidIds.push(id);\n continue;\n }\n // Basic Gmail message ID validation - should not contain certain characters\n if (trimmedId.includes('/') || trimmedId.includes('\\\\') || trimmedId.includes('<') || trimmedId.includes('>')) {\n invalidIds.push(id);\n continue;\n }\n validatedIds.push(trimmedId);\n }\n\n if (invalidIds.length > 0) {\n throw new McpError(ErrorCode.InvalidParams, `Found ${invalidIds.length} invalid IDs: ${invalidIds.join(', ')}`);\n }\n\n if (validatedIds.length === 0) {\n throw new McpError(ErrorCode.InvalidParams, 'No valid IDs found after validation');\n }\n\n try {\n const gmail = google.gmail({ version: 'v1', auth: extra.authContext.auth });\n // Process operations in chunks to prevent memory exhaustion\n const allResults: Array<{ id: string; success: boolean; error?: string }> = [];\n\n for (let i = 0; i < validatedIds.length; i += CHUNK_SIZE) {\n const chunk = validatedIds.slice(i, i + CHUNK_SIZE);\n logger.info('Processing chunk', { chunkIndex: i / CHUNK_SIZE + 1, chunkSize: chunk.length, totalChunks: Math.ceil(validatedIds.length / CHUNK_SIZE) });\n\n const chunkResults = await Promise.allSettled(\n chunk.map(async (id) => {\n await gmail.users.messages.trash({\n userId: 'me',\n id: id,\n });\n return { id, success: true };\n })\n );\n\n // Process chunk results\n const processedChunkResults = chunkResults.map((result, chunkIndex) => {\n const id = chunk[chunkIndex];\n if (!id) {\n throw new Error(`Chunk index ${chunkIndex} is out of bounds for chunk of size ${chunk.length}`);\n }\n if (result.status === 'fulfilled') {\n return { id, success: true };\n }\n\n // Extract error message more robustly\n let errorMessage = 'Unknown error';\n if (result.reason) {\n if (typeof result.reason === 'string') {\n errorMessage = result.reason;\n } else if (result.reason instanceof Error) {\n errorMessage = result.reason.message;\n } else if (result.reason && typeof result.reason === 'object' && 'message' in result.reason) {\n errorMessage = String(result.reason.message);\n } else if (result.reason && typeof result.reason === 'object' && 'error' in result.reason) {\n errorMessage = String(result.reason.error);\n } else {\n errorMessage = String(result.reason);\n }\n }\n\n return { id, success: false, error: errorMessage };\n });\n\n allResults.push(...processedChunkResults);\n }\n\n const successCount = allResults.filter((r) => r.success).length;\n const failureCount = allResults.filter((r) => !r.success).length;\n\n logger.info('gmail-message-move-to-trash completed', {\n totalRequested: validatedIds.length,\n successCount,\n failureCount,\n chunksProcessed: Math.ceil(validatedIds.length / CHUNK_SIZE),\n });\n\n const result: Output = {\n type: 'success' as const,\n totalRequested: validatedIds.length,\n successCount,\n failureCount,\n results: allResults,\n };\n\n return {\n content: [\n {\n type: 'text' as const,\n text: JSON.stringify(result),\n },\n ],\n structuredContent: { result },\n };\n } catch (error) {\n const message = error instanceof Error ? error.message : String(error);\n logger.error('gmail-message-move-to-trash error', { error: message });\n\n throw new McpError(ErrorCode.InternalError, `Error moving messages to trash: ${message}`, {\n stack: error instanceof Error ? error.stack : undefined,\n });\n }\n}\n\nexport default function createTool() {\n return {\n name: 'message-move-to-trash',\n config,\n handler,\n } satisfies ToolModule;\n}\n"],"names":["createTool","AuthRequiredBranchSchema","schemas","inputSchema","z","object","ids","array","coerce","string","trim","min","describe","successBranchSchema","type","literal","totalRequested","number","successCount","failureCount","results","id","success","boolean","error","optional","outputSchema","discriminatedUnion","config","description","result","handler","extra","logger","validatedIds","invalidIds","trimmedId","gmail","allResults","i","message","info","count","length","McpError","ErrorCode","InvalidParams","MAX_BATCH_SIZE","push","includes","join","chunk","chunkResults","processedChunkResults","slice","CHUNK_SIZE","chunkIndex","chunkSize","totalChunks","Math","ceil","Promise","allSettled","map","users","messages","trash","userId","Error","status","errorMessage","reason","String","google","version","auth","authContext","filter","r","chunksProcessed","content","text","JSON","stringify","structuredContent","InternalError","stack","undefined","name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C7D;oBAEMzB,SAAiB;wBACrBhB,MAAM;wBACNE,gBAAgBkB,aAAaS,MAAM;wBACnCzB,cAAAA;wBACAC,cAAAA;wBACAC,SAASkB;oBACX;oBAEA;;wBAAO;4BACL0C,OAAO;gCACL;oCACElE,MAAM;oCACNmE,MAAMC,KAAKC,SAAS,CAACrD;gCACvB;;4BAEFsD,mBAAmB;gCAAEtD,QAAAA;4BAAO;wBAC9B;;;oBACON;oBACDgB,UAAUhB,AAAK,YAALA,OAAiB4C,SAAQ5C,MAAMgB,OAAO,GAAGgC,OAAOhD;oBAChES,OAAOT,KAAK,CAAC,qCAAqC;wBAAEA,OAAOgB;oBAAQ;oBAEnE,MAAM,IAAII,eAAQ,CAACC,gBAAS,CAACwC,aAAa,EAAE,AAAC,mCAA0C,OAAR7C,UAAW;wBACxF8C,OAAO9D,AAAK,YAALA,OAAiB4C,SAAQ5C,MAAM8D,KAAK,GAAGC;oBAChD;;;;;;;IAEJ;;AAEe,SAASvF;IACtB,OAAO;QACLwF,MAAM;QACN5D,QAAAA;QACAG,SAAAA;IACF;AACF"}
1
+ {"version":3,"sources":["/Users/kevin/Dev/OpenSource/ai/mcp-z/mcp-gmail/src/mcp/tools/message-move-to-trash.ts"],"sourcesContent":["import type { EnrichedExtra } from '@mcp-z/oauth-google';\nimport { schemas } from '@mcp-z/oauth-google';\n\nconst { AuthRequiredBranchSchema } = schemas;\n\nimport type { ToolModule } from '@mcp-z/server';\nimport { ErrorCode, McpError } from '@modelcontextprotocol/sdk/types.js';\nimport { google } from 'googleapis';\nimport { z } from 'zod';\nimport { CHUNK_SIZE, MAX_BATCH_SIZE } from '../../constants.ts';\n\nconst inputSchema = z.object({\n ids: z.array(z.coerce.string().trim().min(1)).min(1).describe('Gmail message IDs to move to trash'),\n});\n\nconst successBranchSchema = z.object({\n type: z.literal('success'),\n totalRequested: z.number().describe('Total number of messages requested to trash'),\n successCount: z.number().describe('Number of messages successfully moved to trash'),\n failureCount: z.number().describe('Number of messages that failed to move'),\n results: z\n .array(\n z.object({\n id: z.string().describe('Message ID'),\n success: z.boolean().describe('Whether the operation succeeded'),\n error: z.string().optional().describe('Error message if operation failed'),\n })\n )\n .describe('Individual results for each message'),\n});\n\nconst outputSchema = z.discriminatedUnion('type', [successBranchSchema, AuthRequiredBranchSchema]);\n\nconst config = {\n description: 'Move Gmail messages to trash (recoverable).',\n inputSchema: inputSchema,\n outputSchema: z.object({\n result: outputSchema,\n }),\n} as const;\n\nexport type Input = z.infer<typeof inputSchema>;\nexport type Output = z.infer<typeof outputSchema>;\n\nasync function handler({ ids }: Input, extra: EnrichedExtra) {\n const logger = extra.logger;\n logger.info('gmail-message-move-to-trash called', { count: ids.length });\n\n if (!ids || ids.length === 0) {\n throw new McpError(ErrorCode.InvalidParams, 'Missing ids');\n }\n\n // Validate batch size to prevent memory exhaustion\n if (ids.length > MAX_BATCH_SIZE) {\n throw new McpError(ErrorCode.InvalidParams, `Batch size ${ids.length} exceeds maximum allowed size of ${MAX_BATCH_SIZE}`);\n }\n\n // Validate and sanitize IDs\n const validatedIds: string[] = [];\n const invalidIds: string[] = [];\n\n for (const id of ids) {\n const trimmedId = id.trim();\n if (!trimmedId) {\n invalidIds.push(id);\n continue;\n }\n // Basic Gmail message ID validation - should not contain certain characters\n if (trimmedId.includes('/') || trimmedId.includes('\\\\') || trimmedId.includes('<') || trimmedId.includes('>')) {\n invalidIds.push(id);\n continue;\n }\n validatedIds.push(trimmedId);\n }\n\n if (invalidIds.length > 0) {\n throw new McpError(ErrorCode.InvalidParams, `Found ${invalidIds.length} invalid IDs: ${invalidIds.join(', ')}`);\n }\n\n if (validatedIds.length === 0) {\n throw new McpError(ErrorCode.InvalidParams, 'No valid IDs found after validation');\n }\n\n try {\n const gmail = google.gmail({ version: 'v1', auth: extra.authContext.auth });\n // Process operations in chunks to prevent memory exhaustion\n const allResults: Array<{ id: string; success: boolean; error?: string }> = [];\n\n for (let i = 0; i < validatedIds.length; i += CHUNK_SIZE) {\n const chunk = validatedIds.slice(i, i + CHUNK_SIZE);\n logger.info('Processing chunk', { chunkIndex: i / CHUNK_SIZE + 1, chunkSize: chunk.length, totalChunks: Math.ceil(validatedIds.length / CHUNK_SIZE) });\n\n const chunkResults = await Promise.allSettled(\n chunk.map(async (id) => {\n await gmail.users.messages.trash({\n userId: 'me',\n id: id,\n });\n return { id, success: true };\n })\n );\n\n // Process chunk results\n const processedChunkResults = chunkResults.map((result, chunkIndex) => {\n const id = chunk[chunkIndex];\n if (!id) {\n throw new Error(`Chunk index ${chunkIndex} is out of bounds for chunk of size ${chunk.length}`);\n }\n if (result.status === 'fulfilled') {\n return { id, success: true };\n }\n\n // Extract error message more robustly\n let errorMessage = 'Unknown error';\n if (result.reason) {\n if (typeof result.reason === 'string') {\n errorMessage = result.reason;\n } else if (result.reason instanceof Error) {\n errorMessage = result.reason.message;\n } else if (result.reason && typeof result.reason === 'object' && 'message' in result.reason) {\n errorMessage = String(result.reason.message);\n } else if (result.reason && typeof result.reason === 'object' && 'error' in result.reason) {\n errorMessage = String(result.reason.error);\n } else {\n errorMessage = String(result.reason);\n }\n }\n\n return { id, success: false, error: errorMessage };\n });\n\n allResults.push(...processedChunkResults);\n }\n\n const successCount = allResults.filter((r) => r.success).length;\n const failureCount = allResults.filter((r) => !r.success).length;\n\n logger.info('gmail-message-move-to-trash completed', {\n totalRequested: validatedIds.length,\n successCount,\n failureCount,\n chunksProcessed: Math.ceil(validatedIds.length / CHUNK_SIZE),\n });\n\n const result: Output = {\n type: 'success' as const,\n totalRequested: validatedIds.length,\n successCount,\n failureCount,\n results: allResults,\n };\n\n return {\n content: [\n {\n type: 'text' as const,\n text: JSON.stringify(result),\n },\n ],\n structuredContent: { result },\n };\n } catch (error) {\n const message = error instanceof Error ? error.message : String(error);\n logger.error('gmail-message-move-to-trash error', { error: message });\n\n throw new McpError(ErrorCode.InternalError, `Error moving messages to trash: ${message}`, {\n stack: error instanceof Error ? error.stack : undefined,\n });\n }\n}\n\nexport default function createTool() {\n return {\n name: 'message-move-to-trash',\n config,\n handler,\n } satisfies ToolModule;\n}\n"],"names":["createTool","AuthRequiredBranchSchema","schemas","inputSchema","z","object","ids","array","coerce","string","trim","min","describe","successBranchSchema","type","literal","totalRequested","number","successCount","failureCount","results","id","success","boolean","error","optional","outputSchema","discriminatedUnion","config","description","result","handler","extra","logger","validatedIds","invalidIds","trimmedId","gmail","allResults","i","message","info","count","length","McpError","ErrorCode","InvalidParams","MAX_BATCH_SIZE","push","includes","join","chunk","chunkResults","processedChunkResults","slice","CHUNK_SIZE","chunkIndex","chunkSize","totalChunks","Math","ceil","Promise","allSettled","map","users","messages","trash","userId","Error","status","errorMessage","reason","String","google","version","auth","authContext","filter","r","chunksProcessed","content","text","JSON","stringify","structuredContent","InternalError","stack","undefined","name"],"mappings":";;;;+BA2KA;;;eAAwBA;;;2BA1KA;qBAKY;0BACb;mBACL;2BACyB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAN3C,IAAM,AAAEC,2BAA6BC,oBAAO,CAApCD;AAQR,IAAME,cAAcC,MAAC,CAACC,MAAM,CAAC;IAC3BC,KAAKF,MAAC,CAACG,KAAK,CAACH,MAAC,CAACI,MAAM,CAACC,MAAM,GAAGC,IAAI,GAAGC,GAAG,CAAC,IAAIA,GAAG,CAAC,GAAGC,QAAQ,CAAC;AAChE;AAEA,IAAMC,sBAAsBT,MAAC,CAACC,MAAM,CAAC;IACnCS,MAAMV,MAAC,CAACW,OAAO,CAAC;IAChBC,gBAAgBZ,MAAC,CAACa,MAAM,GAAGL,QAAQ,CAAC;IACpCM,cAAcd,MAAC,CAACa,MAAM,GAAGL,QAAQ,CAAC;IAClCO,cAAcf,MAAC,CAACa,MAAM,GA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24
24
  return;
25
25
  }
26
- if (info.done) {
27
- resolve(value);
28
- } else {
29
- Promise.resolve(value).then(_next, _throw);
30
- }
26
+ if (info.done) resolve(value);
27
+ else Promise.resolve(value).then(_next, _throw);
31
28
  }
32
29
  function _async_to_generator(fn) {
33
30
  return function() {
@@ -52,17 +49,14 @@ function _define_property(obj, key, value) {
52
49
  configurable: true,
53
50
  writable: true
54
51
  });
55
- } else {
56
- obj[key] = value;
57
- }
52
+ } else obj[key] = value;
58
53
  return obj;
59
54
  }
60
55
  function _instanceof(left, right) {
56
+ "@swc/helpers - instanceof";
61
57
  if (right != null && typeof Symbol !== "undefined" && right[Symbol.hasInstance]) {
62
58
  return !!right[Symbol.hasInstance](left);
63
- } else {
64
- return left instanceof right;
65
- }
59
+ } else return left instanceof right;
66
60
  }
67
61
  function _object_spread(target) {
68
62
  for(var i = 1; i < arguments.length; i++){
@@ -1 +1 @@
1
- {"version":3,"sources":["/Users/kevin/Dev/Projects/mcp-z/mcp-gmail/src/mcp/tools/message-respond.ts"],"sourcesContent":["import { ComposeContentTypeSchema } from '@mcp-z/email';\nimport type { EnrichedExtra } from '@mcp-z/oauth-google';\nimport { schemas } from '@mcp-z/oauth-google';\n\nconst { AuthRequiredBranchSchema } = schemas;\n\nimport type { ToolModule } from '@mcp-z/server';\nimport { ErrorCode, McpError } from '@modelcontextprotocol/sdk/types.js';\nimport { google } from 'googleapis';\nimport { z } from 'zod';\nimport { extractEmails } from '../../email/parsing/headers-utils.ts';\nimport { b64url } from '../../lib/base64-encoding.ts';\n\nconst inputSchema = z.object({\n id: z.coerce.string().trim().min(1).describe('Gmail message ID to reply to'),\n body: z.coerce.string().trim().min(1).describe('Reply body content (plain text or HTML)'),\n contentType: ComposeContentTypeSchema,\n});\n\nconst successBranchSchema = z.object({\n type: z.literal('success'),\n id: z.string().describe('Original message ID that was replied to'),\n});\n\nconst outputSchema = z.discriminatedUnion('type', [successBranchSchema, AuthRequiredBranchSchema]);\n\nconst config = {\n description: 'Send a reply to a Gmail message',\n inputSchema: inputSchema,\n outputSchema: z.object({\n result: outputSchema,\n }),\n} as const;\n\nexport type Input = z.infer<typeof inputSchema>;\nexport type Output = z.infer<typeof outputSchema>;\n\nasync function handler({ id, body, contentType }: Input, extra: EnrichedExtra) {\n const logger = extra.logger;\n\n if (!id || !body) {\n throw new McpError(ErrorCode.InvalidParams, 'Missing id or body');\n }\n\n logger.info('gmail.message.respond called', { id, contentType });\n\n try {\n const gmail = google.gmail({ version: 'v1', auth: extra.authContext.auth });\n\n let full: unknown;\n try {\n const response = await gmail.users.messages.get({\n userId: 'me',\n id: id,\n format: 'metadata',\n metadataHeaders: ['From', 'To', 'Reply-To', 'Subject', 'Message-ID', 'References', 'In-Reply-To', 'Date'],\n });\n full = response.data;\n } catch (error) {\n const message = error instanceof Error ? error.message : String(error);\n logger.error('gmail.message.respond fetch error', { error: message });\n\n throw new McpError(ErrorCode.InternalError, `Error fetching message metadata: ${message}`, {\n stack: error instanceof Error ? error.stack : undefined,\n });\n }\n\n // Type-safe header extraction\n const fullData = full as { payload?: { headers?: unknown[] }; threadId?: unknown };\n const headersArray = Array.isArray(fullData?.payload?.headers) ? fullData.payload.headers : [];\n const headers = Object.fromEntries(\n headersArray.map((h: unknown) => {\n const header = h as { name?: unknown; value?: unknown };\n return [String(header.name ?? ''), String(header.value ?? '')];\n })\n );\n const fromHdr = headers.From || headers.from;\n const replyToHdr = headers['Reply-To'] || headers['reply-to'];\n const toAddr = (replyToHdr ? extractEmails(replyToHdr)[0] : extractEmails(fromHdr)[0]) ?? '';\n const subject = (headers.Subject || headers.subject) ?? '';\n const messageIdHeader = headers['Message-ID'] || headers['Message-Id'] || headers['message-id'];\n const references = (headers.References || headers.references) ?? '';\n const replySubject = /^re:/i.test(subject) ? subject : `Re: ${subject}`;\n const inReplyTo = messageIdHeader?.startsWith('<') ? messageIdHeader : messageIdHeader ? `<${messageIdHeader}>` : undefined;\n const refs = [references, inReplyTo].filter(Boolean).join(' ').trim();\n const mimeType = contentType === 'html' ? 'text/html' : 'text/plain';\n const lines = [`To: ${toAddr}`, `Subject: ${replySubject}`, `In-Reply-To: ${inReplyTo ?? ''}`, `References: ${refs}`, 'MIME-Version: 1.0', `Content-Type: ${mimeType}; charset=UTF-8`, '', body].join('\\r\\n');\n const raw = b64url(lines);\n\n // Prepare request body with conditional threadId for exactOptionalPropertyTypes\n const threadId = fullData?.threadId ? String(fullData.threadId) : undefined;\n await gmail.users.messages.send({\n userId: 'me',\n requestBody: {\n raw: raw,\n ...(threadId && { threadId }),\n },\n });\n\n logger.info('gmail.message.respond sent reply', { id });\n\n const result: Output = {\n type: 'success' as const,\n id,\n };\n\n return {\n content: [\n {\n type: 'text' as const,\n text: JSON.stringify(result),\n },\n ],\n structuredContent: { result },\n };\n } catch (error) {\n const message = error instanceof Error ? error.message : String(error);\n logger.error('gmail.message.respond error', { error: message });\n\n throw new McpError(ErrorCode.InternalError, `Error responding to message: ${message}`, {\n stack: error instanceof Error ? error.stack : undefined,\n });\n }\n}\n\nexport default function createTool() {\n return {\n name: 'message-respond',\n config,\n handler,\n } satisfies ToolModule;\n}\n"],"names":["createTool","AuthRequiredBranchSchema","schemas","inputSchema","z","object","id","coerce","string","trim","min","describe","body","contentType","ComposeContentTypeSchema","successBranchSchema","type","literal","outputSchema","discriminatedUnion","config","description","result","handler","extra","logger","replyToHdr","headers","fullData","gmail","full","response","error","message","headersArray","fromHdr","toAddr","subject","messageIdHeader","references","replySubject","inReplyTo","refs","mimeType","lines","raw","threadId","McpError","ErrorCode","InvalidParams","info","google","version","auth","authContext","users","messages","get","userId","format","metadataHeaders","data","Error","String","InternalError","stack","undefined","Array","isArray","payload","Object","fromEntries","map","h","header","name","value","From","from","extractEmails","Subject","References","test","startsWith","filter","Boolean","join","b64url","send","requestBody","content","text","JSON","stringify","structuredContent"],"mappings":";;;;+BA6HA;;;eAAwBA;;;qBA7HiB;2BAEjB;qBAKY;0BACb;mBACL;8BACY;gCACP;;;;;;;;;;;;;;;;;;;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MrC,MAAM0B,KAAK,CAACC,QAAQ,CAACgC,IAAI,CAAC;4BAC9B9B,QAAQ;4BACR+B,aAAa;gCACX5C,KAAKA;+BACDC,YAAY;gCAAEA,UAAAA;4BAAS;wBAE/B;;;oBANA;oBAQArB,OAAOyB,IAAI,CAAC,oCAAoC;wBAAE5C,IAAAA;oBAAG;oBAE/CgB,SAAiB;wBACrBN,MAAM;wBACNV,IAAAA;oBACF;oBAEA;;wBAAO;4BACLoF,OAAO;gCACL;oCACE1E,MAAM;oCACN2E,MAAMC,KAAKC,SAAS,CAACvE;gCACvB;;4BAEFwE,mBAAmB;gCAAExE,QAAAA;4BAAO;wBAC9B;;;oBACOU;oBACDC,WAAUD,AAAK,YAALA,QAAiB8B,SAAQ9B,OAAMC,OAAO,GAAG8B,OAAO/B;oBAChEP,OAAOO,KAAK,CAAC,+BAA+B;wBAAEA,OAAOC;oBAAQ;oBAE7D,MAAM,IAAIc,eAAQ,CAACC,gBAAS,CAACgB,aAAa,EAAE,AAAC,gCAAuC,OAAR/B,WAAW;wBACrFgC,OAAOjC,AAAK,YAALA,QAAiB8B,SAAQ9B,OAAMiC,KAAK,GAAGC;oBAChD;;;;;;;IAEJ;;AAEe,SAASlE;IACtB,OAAO;QACL2E,MAAM;QACNvD,QAAAA;QACAG,SAAAA;IACF;AACF"}
1
+ {"version":3,"sources":["/Users/kevin/Dev/OpenSource/ai/mcp-z/mcp-gmail/src/mcp/tools/message-respond.ts"],"sourcesContent":["import { ComposeContentTypeSchema } from '@mcp-z/email';\nimport type { EnrichedExtra } from '@mcp-z/oauth-google';\nimport { schemas } from '@mcp-z/oauth-google';\n\nconst { AuthRequiredBranchSchema } = schemas;\n\nimport type { ToolModule } from '@mcp-z/server';\nimport { ErrorCode, McpError } from '@modelcontextprotocol/sdk/types.js';\nimport { google } from 'googleapis';\nimport { z } from 'zod';\nimport { extractEmails } from '../../email/parsing/headers-utils.ts';\nimport { b64url } from '../../lib/base64-encoding.ts';\n\nconst inputSchema = z.object({\n id: z.coerce.string().trim().min(1).describe('Gmail message ID to reply to'),\n body: z.coerce.string().trim().min(1).describe('Reply body content (plain text or HTML)'),\n contentType: ComposeContentTypeSchema,\n});\n\nconst successBranchSchema = z.object({\n type: z.literal('success'),\n id: z.string().describe('Original message ID that was replied to'),\n});\n\nconst outputSchema = z.discriminatedUnion('type', [successBranchSchema, AuthRequiredBranchSchema]);\n\nconst config = {\n description: 'Send a reply to a Gmail message',\n inputSchema: inputSchema,\n outputSchema: z.object({\n result: outputSchema,\n }),\n} as const;\n\nexport type Input = z.infer<typeof inputSchema>;\nexport type Output = z.infer<typeof outputSchema>;\n\nasync function handler({ id, body, contentType }: Input, extra: EnrichedExtra) {\n const logger = extra.logger;\n\n if (!id || !body) {\n throw new McpError(ErrorCode.InvalidParams, 'Missing id or body');\n }\n\n logger.info('gmail.message.respond called', { id, contentType });\n\n try {\n const gmail = google.gmail({ version: 'v1', auth: extra.authContext.auth });\n\n let full: unknown;\n try {\n const response = await gmail.users.messages.get({\n userId: 'me',\n id: id,\n format: 'metadata',\n metadataHeaders: ['From', 'To', 'Reply-To', 'Subject', 'Message-ID', 'References', 'In-Reply-To', 'Date'],\n });\n full = response.data;\n } catch (error) {\n const message = error instanceof Error ? error.message : String(error);\n logger.error('gmail.message.respond fetch error', { error: message });\n\n throw new McpError(ErrorCode.InternalError, `Error fetching message metadata: ${message}`, {\n stack: error instanceof Error ? error.stack : undefined,\n });\n }\n\n // Type-safe header extraction\n const fullData = full as { payload?: { headers?: unknown[] }; threadId?: unknown };\n const headersArray = Array.isArray(fullData?.payload?.headers) ? fullData.payload.headers : [];\n const headers = Object.fromEntries(\n headersArray.map((h: unknown) => {\n const header = h as { name?: unknown; value?: unknown };\n return [String(header.name ?? ''), String(header.value ?? '')];\n })\n );\n const fromHdr = headers.From || headers.from;\n const replyToHdr = headers['Reply-To'] || headers['reply-to'];\n const toAddr = (replyToHdr ? extractEmails(replyToHdr)[0] : extractEmails(fromHdr)[0]) ?? '';\n const subject = (headers.Subject || headers.subject) ?? '';\n const messageIdHeader = headers['Message-ID'] || headers['Message-Id'] || headers['message-id'];\n const references = (headers.References || headers.references) ?? '';\n const replySubject = /^re:/i.test(subject) ? subject : `Re: ${subject}`;\n const inReplyTo = messageIdHeader?.startsWith('<') ? messageIdHeader : messageIdHeader ? `<${messageIdHeader}>` : undefined;\n const refs = [references, inReplyTo].filter(Boolean).join(' ').trim();\n const mimeType = contentType === 'html' ? 'text/html' : 'text/plain';\n const lines = [`To: ${toAddr}`, `Subject: ${replySubject}`, `In-Reply-To: ${inReplyTo ?? ''}`, `References: ${refs}`, 'MIME-Version: 1.0', `Content-Type: ${mimeType}; charset=UTF-8`, '', body].join('\\r\\n');\n const raw = b64url(lines);\n\n // Prepare request body with conditional threadId for exactOptionalPropertyTypes\n const threadId = fullData?.threadId ? String(fullData.threadId) : undefined;\n await gmail.users.messages.send({\n userId: 'me',\n requestBody: {\n raw: raw,\n ...(threadId && { threadId }),\n },\n });\n\n logger.info('gmail.message.respond sent reply', { id });\n\n const result: Output = {\n type: 'success' as const,\n id,\n };\n\n return {\n content: [\n {\n type: 'text' as const,\n text: JSON.stringify(result),\n },\n ],\n structuredContent: { result },\n };\n } catch (error) {\n const message = error instanceof Error ? error.message : String(error);\n logger.error('gmail.message.respond error', { error: message });\n\n throw new McpError(ErrorCode.InternalError, `Error responding to message: ${message}`, {\n stack: error instanceof Error ? error.stack : undefined,\n });\n }\n}\n\nexport default function createTool() {\n return {\n name: 'message-respond',\n config,\n handler,\n } satisfies ToolModule;\n}\n"],"names":["createTool","AuthRequiredBranchSchema","schemas","inputSchema","z","object","id","coerce","string","trim","min","describe","body","contentType","ComposeContentTypeSchema","successBranchSchema","type","literal","outputSchema","discriminatedUnion","config","description","result","handler","extra","logger","replyToHdr","headers","fullData","gmail","full","response","error","message","headersArray","fromHdr","toAddr","subject","messageIdHeader","references","replySubject","inReplyTo","refs","mimeType","lines","raw","threadId","McpError","ErrorCode","InvalidParams","info","google","version","auth","authContext","users","messages","get","userId","format","metadataHeaders","data","Error","String","InternalError","stack","undefined","Array","isArray","payload","Object","fromEntries","map","h","header","name","value","From","from","extractEmails","Subject","References","test","startsWith","filter","Boolean","join","b64url","send","requestBody","content","text","JSON","stringify","structuredContent"],"mappings":";;;;+BA6HA;;;eAAwBA;;;qBA7HiB;2BAEjB;qBAKY;0BACb;mBACL;8BACY;gCACP;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAPvB,IAAM,AAAEC,2BAA6BC,oBAAO,CAApCD;AASR,IAAME,cAAcC,MAAC,CAACC,MAAM,CAAC;IAC3BC,IAAIF,MAAC,CAACG,MAAM,CAACC,MAAM,GAAGC,IAAI,GAAGC,GAAG,CAAC,GAAGC,QAAQ,CAAC;IAC7CC,MAAMR,MAAC,CAACG,MAAM,CAACC,MAAM,GAAGC,IAAI,GAAGC,GAAG,CAAC,GAAGC,QAAQ,CAAC;IAC/CE,aAAaC,+BAAwB;AACvC;AAEA,IAAMC,sBAAsBX,MAAC,CAACC,MAAM,CAAC;IACnCW,MAAMZ,MAAC,CAACa,OAAO,CAAC;IAChBX,IAAIF,MAAC,CAACI,MAAM,GAAGG,QAAQ,CAAC;AAC1B;AAEA,IAAMO,eAAed,MAAC,CAACe,kBAAkB,CAAC,QAAQ;IAACJ;IAAqBd;CAAyB;AAEjG,IAAMmB,SAAS;IACbC,aAAa;IACblB,aAAaA;IACbe,cAAcd,MAAC,CAACC,MAAM,CAAC;QACrBiB,QAAQJ;IACV;AACF;AAKA,SAAeK;wCAAQ,KAAgC,EAAEC,KAAoB;YAApDlB,IAAIM,MAAMC,aAC3BY,QAwCYC,MACCC,OAEGA,OAZeC,mBAtB7BC,OAEFC,MAEIC,UAOCC,OACDC,SASFL,UACAM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AAmB,OAALC;wBAAQ;wBAAsB,iBAAyB,OAATC,UAAS;wBAAkB;wBAAI/B;sBAAM0E,IAAI,CAAC;oBAChMzC,MAAM0C,IAAAA,wBAAM,EAAC3C;oBAEnB,gFAAgF;oBAC1EE,WAAWlB,CAAAA,qBAAAA,+BAAAA,SAAUkB,QAAQ,IAAGiB,OAAOnC,SAASkB,QAAQ,IAAIoB;oBAClE;;wBAAMrC,MAAM0B,KAAK,CAACC,QAAQ,CAACgC,IAAI,CAAC;4BAC9B9B,QAAQ;4BACR+B,aAAa;gCACX5C,KAAKA;+BACDC,YAAY;gCAAEA,UAAAA;4BAAS;wBAE/B;;;oBANA;oBAQArB,OAAOyB,IAAI,CAAC,oCAAoC;wBAAE5C,IAAAA;oBAAG;oBAE/CgB,SAAiB;wBACrBN,MAAM;wBACNV,IAAAA;oBACF;oBAEA;;wBAAO;4BACLoF,OAAO;gCACL;oCACE1E,MAAM;oCACN2E,MAAMC,KAAKC,SAAS,CAACvE;gCACvB;;4BAEFwE,mBAAmB;gCAAExE,QAAAA;4BAAO;wBAC9B;;;oBACOU;oBACDC,WAAUD,AAAK,YAALA,QAAiB8B,SAAQ9B,OAAMC,OAAO,GAAG8B,OAAO/B;oBAChEP,OAAOO,KAAK,CAAC,+BAA+B;wBAAEA,OAAOC;oBAAQ;oBAE7D,MAAM,IAAIc,eAAQ,CAACC,gBAAS,CAACgB,aAAa,EAAE,AAAC,gCAAuC,OAAR/B,WAAW;wBACrFgC,OAAOjC,AAAK,YAALA,QAAiB8B,SAAQ9B,OAAMiC,KAAK,GAAGC;oBAChD;;;;;;;IAEJ;;AAEe,SAASlE;IACtB,OAAO;QACL2E,MAAM;QACNvD,QAAAA;QACAG,SAAAA;IACF;AACF"}
@@ -12,7 +12,7 @@ declare const inputSchema: z.ZodObject<{
12
12
  excludeThreadHistory: z.ZodDefault<z.ZodOptional<z.ZodBoolean>>;
13
13
  pageSize: z.ZodDefault<z.ZodOptional<z.ZodCoercedNumber<unknown>>>;
14
14
  pageToken: z.ZodOptional<z.ZodString>;
15
- query: z.ZodOptional<z.ZodType<import("../../schemas/gmail-query-schema.js").GmailQuery, unknown, z.core.$ZodTypeInternals<import("../../schemas/gmail-query-schema.js").GmailQuery, unknown>>>;
15
+ query: z.ZodOptional<z.ZodType<string | import("../../schemas/gmail-query-schema.js").GmailQuery, unknown, z.core.$ZodTypeInternals<string | import("../../schemas/gmail-query-schema.js").GmailQuery, unknown>>>;
16
16
  fields: z.ZodOptional<z.ZodString>;
17
17
  }, z.core.$strip>;
18
18
  declare const outputSchema: z.ZodUnion<readonly [z.ZodObject<{
@@ -73,39 +73,39 @@ declare function handler({ query, pageSize, pageToken, fields, shape, contentTyp
73
73
  type: "success";
74
74
  shape: "objects";
75
75
  items: {
76
- id?: string;
77
- threadId?: string;
78
- subject?: string;
79
- from?: string;
80
- fromName?: string;
81
- to?: string;
82
- cc?: string;
83
- bcc?: string;
84
- date?: string;
85
- receivedDateTime?: string;
86
- snippet?: string;
87
- isRead?: boolean;
88
- isImportant?: boolean;
89
- hasAttachments?: boolean;
90
- attachmentCount?: number;
91
- labelIds?: string[];
92
- folderName?: string;
93
- body?: string;
94
- bodyContentType?: "text" | "html";
76
+ id?: string | undefined;
77
+ threadId?: string | undefined;
78
+ subject?: string | undefined;
79
+ from?: string | undefined;
80
+ fromName?: string | undefined;
81
+ to?: string | undefined;
82
+ cc?: string | undefined;
83
+ bcc?: string | undefined;
84
+ date?: string | undefined;
85
+ receivedDateTime?: string | undefined;
86
+ snippet?: string | undefined;
87
+ isRead?: boolean | undefined;
88
+ isImportant?: boolean | undefined;
89
+ hasAttachments?: boolean | undefined;
90
+ attachmentCount?: number | undefined;
91
+ labelIds?: string[] | undefined;
92
+ folderName?: string | undefined;
93
+ body?: string | undefined;
94
+ bodyContentType?: "text" | "html" | undefined;
95
95
  attachments?: {
96
96
  id: string;
97
97
  filename: string;
98
98
  mimeType: string;
99
- size?: number;
100
- }[];
99
+ size?: number | undefined;
100
+ }[] | undefined;
101
101
  }[];
102
- nextPageToken?: string;
102
+ nextPageToken?: string | undefined;
103
103
  } | {
104
104
  type: "success";
105
105
  shape: "arrays";
106
106
  columns: string[];
107
107
  rows: unknown[][];
108
- nextPageToken?: string;
108
+ nextPageToken?: string | undefined;
109
109
  };
110
110
  };
111
111
  }>;
@@ -125,7 +125,7 @@ export default function createTool(): {
125
125
  excludeThreadHistory: z.ZodDefault<z.ZodOptional<z.ZodBoolean>>;
126
126
  pageSize: z.ZodDefault<z.ZodOptional<z.ZodCoercedNumber<unknown>>>;
127
127
  pageToken: z.ZodOptional<z.ZodString>;
128
- query: z.ZodOptional<z.ZodType<import("../../schemas/gmail-query-schema.js").GmailQuery, unknown, z.core.$ZodTypeInternals<import("../../schemas/gmail-query-schema.js").GmailQuery, unknown>>>;
128
+ query: z.ZodOptional<z.ZodType<string | import("../../schemas/gmail-query-schema.js").GmailQuery, unknown, z.core.$ZodTypeInternals<string | import("../../schemas/gmail-query-schema.js").GmailQuery, unknown>>>;
129
129
  fields: z.ZodOptional<z.ZodString>;
130
130
  }, z.core.$strip>;
131
131
  readonly outputSchema: z.ZodObject<{
@@ -12,7 +12,7 @@ declare const inputSchema: z.ZodObject<{
12
12
  excludeThreadHistory: z.ZodDefault<z.ZodOptional<z.ZodBoolean>>;
13
13
  pageSize: z.ZodDefault<z.ZodOptional<z.ZodCoercedNumber<unknown>>>;
14
14
  pageToken: z.ZodOptional<z.ZodString>;
15
- query: z.ZodOptional<z.ZodType<import("../../schemas/gmail-query-schema.js").GmailQuery, unknown, z.core.$ZodTypeInternals<import("../../schemas/gmail-query-schema.js").GmailQuery, unknown>>>;
15
+ query: z.ZodOptional<z.ZodType<string | import("../../schemas/gmail-query-schema.js").GmailQuery, unknown, z.core.$ZodTypeInternals<string | import("../../schemas/gmail-query-schema.js").GmailQuery, unknown>>>;
16
16
  fields: z.ZodOptional<z.ZodString>;
17
17
  }, z.core.$strip>;
18
18
  declare const outputSchema: z.ZodUnion<readonly [z.ZodObject<{
@@ -73,39 +73,39 @@ declare function handler({ query, pageSize, pageToken, fields, shape, contentTyp
73
73
  type: "success";
74
74
  shape: "objects";
75
75
  items: {
76
- id?: string;
77
- threadId?: string;
78
- subject?: string;
79
- from?: string;
80
- fromName?: string;
81
- to?: string;
82
- cc?: string;
83
- bcc?: string;
84
- date?: string;
85
- receivedDateTime?: string;
86
- snippet?: string;
87
- isRead?: boolean;
88
- isImportant?: boolean;
89
- hasAttachments?: boolean;
90
- attachmentCount?: number;
91
- labelIds?: string[];
92
- folderName?: string;
93
- body?: string;
94
- bodyContentType?: "text" | "html";
76
+ id?: string | undefined;
77
+ threadId?: string | undefined;
78
+ subject?: string | undefined;
79
+ from?: string | undefined;
80
+ fromName?: string | undefined;
81
+ to?: string | undefined;
82
+ cc?: string | undefined;
83
+ bcc?: string | undefined;
84
+ date?: string | undefined;
85
+ receivedDateTime?: string | undefined;
86
+ snippet?: string | undefined;
87
+ isRead?: boolean | undefined;
88
+ isImportant?: boolean | undefined;
89
+ hasAttachments?: boolean | undefined;
90
+ attachmentCount?: number | undefined;
91
+ labelIds?: string[] | undefined;
92
+ folderName?: string | undefined;
93
+ body?: string | undefined;
94
+ bodyContentType?: "text" | "html" | undefined;
95
95
  attachments?: {
96
96
  id: string;
97
97
  filename: string;
98
98
  mimeType: string;
99
- size?: number;
100
- }[];
99
+ size?: number | undefined;
100
+ }[] | undefined;
101
101
  }[];
102
- nextPageToken?: string;
102
+ nextPageToken?: string | undefined;
103
103
  } | {
104
104
  type: "success";
105
105
  shape: "arrays";
106
106
  columns: string[];
107
107
  rows: unknown[][];
108
- nextPageToken?: string;
108
+ nextPageToken?: string | undefined;
109
109
  };
110
110
  };
111
111
  }>;
@@ -125,7 +125,7 @@ export default function createTool(): {
125
125
  excludeThreadHistory: z.ZodDefault<z.ZodOptional<z.ZodBoolean>>;
126
126
  pageSize: z.ZodDefault<z.ZodOptional<z.ZodCoercedNumber<unknown>>>;
127
127
  pageToken: z.ZodOptional<z.ZodString>;
128
- query: z.ZodOptional<z.ZodType<import("../../schemas/gmail-query-schema.js").GmailQuery, unknown, z.core.$ZodTypeInternals<import("../../schemas/gmail-query-schema.js").GmailQuery, unknown>>>;
128
+ query: z.ZodOptional<z.ZodType<string | import("../../schemas/gmail-query-schema.js").GmailQuery, unknown, z.core.$ZodTypeInternals<string | import("../../schemas/gmail-query-schema.js").GmailQuery, unknown>>>;
129
129
  fields: z.ZodOptional<z.ZodString>;
130
130
  }, z.core.$strip>;
131
131
  readonly outputSchema: z.ZodObject<{