@mcp-z/mcp-gmail 1.0.0 → 1.0.2

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 (139) hide show
  1. package/README.md +33 -3
  2. package/bin/server.js +1 -1
  3. package/dist/cjs/constants.js.map +1 -1
  4. package/dist/cjs/email/composition/rfc822-builder.js.map +1 -1
  5. package/dist/cjs/email/messages/fetch-message.js +7 -7
  6. package/dist/cjs/email/messages/fetch-message.js.map +1 -1
  7. package/dist/cjs/email/messages/messages.js +10 -10
  8. package/dist/cjs/email/messages/messages.js.map +1 -1
  9. package/dist/cjs/email/parsing/header-parsing.js +3 -3
  10. package/dist/cjs/email/parsing/header-parsing.js.map +1 -1
  11. package/dist/cjs/email/parsing/headers-utils.js.map +1 -1
  12. package/dist/cjs/email/parsing/html-processing.js.map +1 -1
  13. package/dist/cjs/email/parsing/message-extraction.js +5 -5
  14. package/dist/cjs/email/parsing/message-extraction.js.map +1 -1
  15. package/dist/cjs/email/querying/execute-query.js +2 -2
  16. package/dist/cjs/email/querying/execute-query.js.map +1 -1
  17. package/dist/cjs/email/querying/pagination.js.map +1 -1
  18. package/dist/cjs/email/querying/query-builder.js.map +1 -1
  19. package/dist/cjs/email/querying/search-execution.js +4 -4
  20. package/dist/cjs/email/querying/search-execution.js.map +1 -1
  21. package/dist/cjs/index.d.cts +4 -0
  22. package/dist/cjs/index.d.ts +4 -0
  23. package/dist/cjs/index.js +21 -13
  24. package/dist/cjs/index.js.map +1 -1
  25. package/dist/cjs/labels/gmail-labels.js.map +1 -1
  26. package/dist/cjs/lib/base64-encoding.js.map +1 -1
  27. package/dist/cjs/lib/create-store.js.map +1 -1
  28. package/dist/cjs/lib/date-conversion.js.map +1 -1
  29. package/dist/cjs/lib/messages-to-row.js.map +1 -1
  30. package/dist/cjs/mcp/index.js +6 -6
  31. package/dist/cjs/mcp/index.js.map +1 -1
  32. package/dist/cjs/mcp/prompts/draft-email.js.map +1 -1
  33. package/dist/cjs/mcp/prompts/index.js +4 -4
  34. package/dist/cjs/mcp/prompts/index.js.map +1 -1
  35. package/dist/cjs/mcp/prompts/query-syntax.js.map +1 -1
  36. package/dist/cjs/mcp/resources/email.js +5 -5
  37. package/dist/cjs/mcp/resources/email.js.map +1 -1
  38. package/dist/cjs/mcp/resources/index.js +2 -2
  39. package/dist/cjs/mcp/resources/index.js.map +1 -1
  40. package/dist/cjs/mcp/tools/categories-list.d.cts +8 -2
  41. package/dist/cjs/mcp/tools/categories-list.d.ts +8 -2
  42. package/dist/cjs/mcp/tools/categories-list.js +12 -4
  43. package/dist/cjs/mcp/tools/categories-list.js.map +1 -1
  44. package/dist/cjs/mcp/tools/index.js +22 -22
  45. package/dist/cjs/mcp/tools/index.js.map +1 -1
  46. package/dist/cjs/mcp/tools/label-add.js +2 -2
  47. package/dist/cjs/mcp/tools/label-add.js.map +1 -1
  48. package/dist/cjs/mcp/tools/label-delete.js.map +1 -1
  49. package/dist/cjs/mcp/tools/labels-list.d.cts +8 -2
  50. package/dist/cjs/mcp/tools/labels-list.d.ts +8 -2
  51. package/dist/cjs/mcp/tools/labels-list.js +12 -4
  52. package/dist/cjs/mcp/tools/labels-list.js.map +1 -1
  53. package/dist/cjs/mcp/tools/message-get.js +8 -8
  54. package/dist/cjs/mcp/tools/message-get.js.map +1 -1
  55. package/dist/cjs/mcp/tools/message-mark-read.js.map +1 -1
  56. package/dist/cjs/mcp/tools/message-move-to-trash.js.map +1 -1
  57. package/dist/cjs/mcp/tools/message-respond.js +4 -4
  58. package/dist/cjs/mcp/tools/message-respond.js.map +1 -1
  59. package/dist/cjs/mcp/tools/message-search.js +6 -6
  60. package/dist/cjs/mcp/tools/message-search.js.map +1 -1
  61. package/dist/cjs/mcp/tools/message-send.js +4 -4
  62. package/dist/cjs/mcp/tools/message-send.js.map +1 -1
  63. package/dist/cjs/mcp/tools/messages-export-csv.js +6 -6
  64. package/dist/cjs/mcp/tools/messages-export-csv.js.map +1 -1
  65. package/dist/cjs/schemas/gmail-query-schema.js.map +1 -1
  66. package/dist/cjs/schemas/index.js.map +1 -1
  67. package/dist/cjs/setup/config.js +11 -1
  68. package/dist/cjs/setup/config.js.map +1 -1
  69. package/dist/cjs/setup/http.js +6 -2
  70. package/dist/cjs/setup/http.js.map +1 -1
  71. package/dist/cjs/setup/index.d.cts +1 -0
  72. package/dist/cjs/setup/index.d.ts +1 -0
  73. package/dist/cjs/setup/index.js +9 -9
  74. package/dist/cjs/setup/index.js.map +1 -1
  75. package/dist/cjs/setup/oauth-google.d.cts +3 -2
  76. package/dist/cjs/setup/oauth-google.d.ts +3 -2
  77. package/dist/cjs/setup/oauth-google.js +15 -12
  78. package/dist/cjs/setup/oauth-google.js.map +1 -1
  79. package/dist/cjs/setup/runtime.js +9 -9
  80. package/dist/cjs/setup/runtime.js.map +1 -1
  81. package/dist/cjs/setup/stdio.js +2 -2
  82. package/dist/cjs/setup/stdio.js.map +1 -1
  83. package/dist/esm/constants.js.map +1 -1
  84. package/dist/esm/email/composition/rfc822-builder.js.map +1 -1
  85. package/dist/esm/email/messages/fetch-message.js.map +1 -1
  86. package/dist/esm/email/messages/messages.js.map +1 -1
  87. package/dist/esm/email/parsing/header-parsing.js.map +1 -1
  88. package/dist/esm/email/parsing/headers-utils.js.map +1 -1
  89. package/dist/esm/email/parsing/html-processing.js.map +1 -1
  90. package/dist/esm/email/parsing/message-extraction.js.map +1 -1
  91. package/dist/esm/email/querying/execute-query.js.map +1 -1
  92. package/dist/esm/email/querying/pagination.js.map +1 -1
  93. package/dist/esm/email/querying/query-builder.js.map +1 -1
  94. package/dist/esm/email/querying/search-execution.js.map +1 -1
  95. package/dist/esm/index.d.ts +4 -0
  96. package/dist/esm/index.js +2 -0
  97. package/dist/esm/index.js.map +1 -1
  98. package/dist/esm/labels/gmail-labels.js.map +1 -1
  99. package/dist/esm/lib/base64-encoding.js.map +1 -1
  100. package/dist/esm/lib/create-store.js.map +1 -1
  101. package/dist/esm/lib/date-conversion.js.map +1 -1
  102. package/dist/esm/lib/messages-to-row.js.map +1 -1
  103. package/dist/esm/mcp/index.js.map +1 -1
  104. package/dist/esm/mcp/prompts/draft-email.js.map +1 -1
  105. package/dist/esm/mcp/prompts/index.js.map +1 -1
  106. package/dist/esm/mcp/prompts/query-syntax.js.map +1 -1
  107. package/dist/esm/mcp/resources/email.js.map +1 -1
  108. package/dist/esm/mcp/resources/index.js.map +1 -1
  109. package/dist/esm/mcp/tools/categories-list.d.ts +8 -2
  110. package/dist/esm/mcp/tools/categories-list.js +4 -2
  111. package/dist/esm/mcp/tools/categories-list.js.map +1 -1
  112. package/dist/esm/mcp/tools/index.js.map +1 -1
  113. package/dist/esm/mcp/tools/label-add.js.map +1 -1
  114. package/dist/esm/mcp/tools/label-delete.js.map +1 -1
  115. package/dist/esm/mcp/tools/labels-list.d.ts +8 -2
  116. package/dist/esm/mcp/tools/labels-list.js +4 -2
  117. package/dist/esm/mcp/tools/labels-list.js.map +1 -1
  118. package/dist/esm/mcp/tools/message-get.js.map +1 -1
  119. package/dist/esm/mcp/tools/message-mark-read.js.map +1 -1
  120. package/dist/esm/mcp/tools/message-move-to-trash.js.map +1 -1
  121. package/dist/esm/mcp/tools/message-respond.js.map +1 -1
  122. package/dist/esm/mcp/tools/message-search.js.map +1 -1
  123. package/dist/esm/mcp/tools/message-send.js.map +1 -1
  124. package/dist/esm/mcp/tools/messages-export-csv.js.map +1 -1
  125. package/dist/esm/schemas/gmail-query-schema.js.map +1 -1
  126. package/dist/esm/schemas/index.js.map +1 -1
  127. package/dist/esm/setup/config.js +12 -2
  128. package/dist/esm/setup/config.js.map +1 -1
  129. package/dist/esm/setup/http.js +4 -0
  130. package/dist/esm/setup/http.js.map +1 -1
  131. package/dist/esm/setup/index.d.ts +1 -0
  132. package/dist/esm/setup/index.js.map +1 -1
  133. package/dist/esm/setup/oauth-google.d.ts +3 -2
  134. package/dist/esm/setup/oauth-google.js +8 -11
  135. package/dist/esm/setup/oauth-google.js.map +1 -1
  136. package/dist/esm/setup/runtime.js.map +1 -1
  137. package/dist/esm/setup/stdio.js.map +1 -1
  138. package/dist/esm/types.js.map +1 -1
  139. package/package.json +2 -2
@@ -5,10 +5,10 @@ Object.defineProperty(exports, "__esModule", {
5
5
  Object.defineProperty(exports, "email", {
6
6
  enumerable: true,
7
7
  get: function() {
8
- return _email.default;
8
+ return _emailts.default;
9
9
  }
10
10
  });
11
- var _email = /*#__PURE__*/ _interop_require_default(require("./email.js"));
11
+ var _emailts = /*#__PURE__*/ _interop_require_default(require("./email.js"));
12
12
  function _interop_require_default(obj) {
13
13
  return obj && obj.__esModule ? obj : {
14
14
  default: obj
@@ -1 +1 @@
1
- {"version":3,"sources":["/Users/kevin/Dev/Projects/ai/mcp-z/servers/mcp-gmail/src/mcp/resources/index.ts"],"sourcesContent":["export { default as email } from './email.js';\n"],"names":["email"],"mappings":";;;;+BAAoBA;;;eAAAA,cAAK;;;4DAAQ"}
1
+ {"version":3,"sources":["/Users/kevin/Dev/Projects/mcp-z/mcp-gmail/src/mcp/resources/index.ts"],"sourcesContent":["export { default as email } from './email.ts';\n"],"names":["email"],"mappings":";;;;+BAAoBA;;;eAAAA,gBAAK;;;8DAAQ"}
@@ -1,6 +1,9 @@
1
1
  import type { EnrichedExtra } from '@mcp-z/oauth-google';
2
2
  import { z } from 'zod';
3
- declare const inputSchema: z.ZodObject<{}, z.core.$strip>;
3
+ /**
4
+ * Input schema for the categories-list tool (currently empty as this tool takes no parameters).
5
+ */
6
+ export declare const inputSchema: z.ZodObject<{}, z.core.$strip>;
4
7
  declare const outputSchema: z.ZodDiscriminatedUnion<[z.ZodObject<{
5
8
  type: z.ZodLiteral<"success">;
6
9
  items: z.ZodArray<z.ZodObject<{
@@ -14,9 +17,12 @@ declare const outputSchema: z.ZodDiscriminatedUnion<[z.ZodObject<{
14
17
  message: z.ZodString;
15
18
  url: z.ZodOptional<z.ZodString>;
16
19
  }, z.core.$strip>], "type">;
20
+ /**
21
+ * Input parameters for the categories-list tool.
22
+ */
17
23
  export type Input = z.infer<typeof inputSchema>;
18
24
  export type Output = z.infer<typeof outputSchema>;
19
- declare function handler(_args: Input, extra: EnrichedExtra): Promise<{
25
+ declare function handler(_: Input, extra: EnrichedExtra): Promise<{
20
26
  content: {
21
27
  type: "text";
22
28
  text: string;
@@ -1,6 +1,9 @@
1
1
  import type { EnrichedExtra } from '@mcp-z/oauth-google';
2
2
  import { z } from 'zod';
3
- declare const inputSchema: z.ZodObject<{}, z.core.$strip>;
3
+ /**
4
+ * Input schema for the categories-list tool (currently empty as this tool takes no parameters).
5
+ */
6
+ export declare const inputSchema: z.ZodObject<{}, z.core.$strip>;
4
7
  declare const outputSchema: z.ZodDiscriminatedUnion<[z.ZodObject<{
5
8
  type: z.ZodLiteral<"success">;
6
9
  items: z.ZodArray<z.ZodObject<{
@@ -14,9 +17,12 @@ declare const outputSchema: z.ZodDiscriminatedUnion<[z.ZodObject<{
14
17
  message: z.ZodString;
15
18
  url: z.ZodOptional<z.ZodString>;
16
19
  }, z.core.$strip>], "type">;
20
+ /**
21
+ * Input parameters for the categories-list tool.
22
+ */
17
23
  export type Input = z.infer<typeof inputSchema>;
18
24
  export type Output = z.infer<typeof outputSchema>;
19
- declare function handler(_args: Input, extra: EnrichedExtra): Promise<{
25
+ declare function handler(_: Input, extra: EnrichedExtra): Promise<{
20
26
  content: {
21
27
  type: "text";
22
28
  text: string;
@@ -2,10 +2,18 @@
2
2
  Object.defineProperty(exports, "__esModule", {
3
3
  value: true
4
4
  });
5
- Object.defineProperty(exports, "default", {
6
- enumerable: true,
7
- get: function() {
5
+ function _export(target, all) {
6
+ for(var name in all)Object.defineProperty(target, name, {
7
+ enumerable: true,
8
+ get: Object.getOwnPropertyDescriptor(all, name).get
9
+ });
10
+ }
11
+ _export(exports, {
12
+ get default () {
8
13
  return createTool;
14
+ },
15
+ get inputSchema () {
16
+ return inputSchema;
9
17
  }
10
18
  });
11
19
  var _oauthgoogle = require("@mcp-z/oauth-google");
@@ -172,7 +180,7 @@ var config = {
172
180
  result: outputSchema
173
181
  })
174
182
  };
175
- function handler(_args, extra) {
183
+ function handler(_, extra) {
176
184
  return _async_to_generator(function() {
177
185
  var logger, gmail, started, response, labels, categories, durationMs, result, error, message;
178
186
  return _ts_generator(this, function(_state) {
@@ -1 +1 @@
1
- {"version":3,"sources":["/Users/kevin/Dev/Projects/ai/mcp-z/servers/mcp-gmail/src/mcp/tools/categories-list.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\n// Schema for individual category items\nconst CategorySchema = z.object({\n id: z.string().describe('Gmail category ID (e.g., CATEGORY_PERSONAL)'),\n name: z.string().describe('Human-readable category name'),\n description: z.string().describe('Description of what emails belong in this category'),\n});\n\nconst inputSchema = z.object({});\n\n// Success branch schema\nconst successBranchSchema = z.object({\n type: z.literal('success'),\n items: z.array(CategorySchema),\n});\n\n// Output schema with auth_required support\nconst outputSchema = z.discriminatedUnion('type', [successBranchSchema, AuthRequiredBranchSchema]);\n\nconst config = {\n description: 'List Gmail category labels (CATEGORY_*) with IDs and descriptions.',\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(_args: Input, extra: EnrichedExtra) {\n const logger = extra.logger;\n logger.info('gmail.categories.list called');\n\n try {\n const gmail = google.gmail({ version: 'v1', auth: extra.authContext.auth });\n const started = Date.now();\n\n // Fetch all labels from Gmail API\n const response = await gmail.users.labels.list({ userId: 'me' });\n const labels = response.data.labels || [];\n\n // Filter for CATEGORY_* system labels and map to our schema\n const categories = labels\n .filter((label) => label.id?.startsWith('CATEGORY_'))\n .map((label) => {\n const id = label.id as string;\n let name = label.name || id;\n let description = '';\n\n // Map known category types to user-friendly names and descriptions\n switch (id) {\n case 'CATEGORY_PERSONAL':\n name = 'Primary';\n description = 'Important emails from people you know';\n break;\n case 'CATEGORY_SOCIAL':\n name = 'Social';\n description = 'Social networks and social websites';\n break;\n case 'CATEGORY_PROMOTIONS':\n name = 'Promotions';\n description = 'Deals, offers, and marketing emails';\n break;\n case 'CATEGORY_UPDATES':\n name = 'Updates';\n description = 'Confirmations, receipts, bills, and statements';\n break;\n case 'CATEGORY_FORUMS':\n name = 'Forums';\n description = 'Online groups, discussion boards, mailing lists';\n break;\n default:\n // For any unknown CATEGORY_* labels, use the label name as-is\n name = label.name || id.replace('CATEGORY_', '');\n description = `Gmail category: ${name}`;\n }\n\n return {\n id,\n name,\n description,\n };\n })\n .sort((a, b) => a.name.localeCompare(b.name)); // Sort alphabetically by name\n\n const durationMs = Date.now() - started;\n\n logger.info('gmail.categories.list results', { categoryCount: categories.length, totalLabels: labels.length });\n logger.info('gmail.categories.list metrics', { durationMs });\n\n const result: Output = {\n type: 'success' as const,\n items: categories,\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.categories.list error', { error: message });\n\n throw new McpError(ErrorCode.InternalError, `Error listing categories: ${message}`, {\n stack: error instanceof Error ? error.stack : undefined,\n });\n }\n}\n\nexport default function createTool() {\n return {\n name: 'categories-list',\n config,\n handler,\n } satisfies ToolModule;\n}\n"],"names":["createTool","AuthRequiredBranchSchema","schemas","CategorySchema","z","object","id","string","describe","name","description","inputSchema","successBranchSchema","type","literal","items","array","outputSchema","discriminatedUnion","config","result","handler","_args","extra","logger","gmail","started","response","labels","categories","durationMs","error","message","info","google","version","auth","authContext","Date","now","users","list","userId","data","filter","label","startsWith","map","replace","sort","a","b","localeCompare","categoryCount","length","totalLabels","content","text","JSON","stringify","structuredContent","Error","String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wBAAO;4BACL2B,OAAO;gCACL;oCACE3C,MAAM;oCACN4C,MAAMC,KAAKC,SAAS,CAACvC;gCACvB;;4BAEFwC,mBAAmB;gCAAExC,QAAAA;4BAAO;wBAC9B;;;oBACOW;oBACDC,UAAUD,AAAK,YAALA,OAAiB8B,SAAQ9B,MAAMC,OAAO,GAAG8B,OAAO/B;oBAChEP,OAAOO,KAAK,CAAC,+BAA+B;wBAAEA,OAAOC;oBAAQ;oBAE7D,MAAM,IAAI+B,eAAQ,CAACC,gBAAS,CAACC,aAAa,EAAE,AAAC,6BAAoC,OAARjC,UAAW;wBAClFkC,OAAOnC,AAAK,YAALA,OAAiB8B,SAAQ9B,MAAMmC,KAAK,GAAGC;oBAChD;;;;;;;IAEJ;;AAEe,SAASnE;IACtB,OAAO;QACLS,MAAM;QACNU,QAAAA;QACAE,SAAAA;IACF;AACF"}
1
+ {"version":3,"sources":["/Users/kevin/Dev/Projects/mcp-z/mcp-gmail/src/mcp/tools/categories-list.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\n// Schema for individual category items\nconst CategorySchema = z.object({\n id: z.string().describe('Gmail category ID (e.g., CATEGORY_PERSONAL)'),\n name: z.string().describe('Human-readable category name'),\n description: z.string().describe('Description of what emails belong in this category'),\n});\n\n/**\n * Input schema for the categories-list tool (currently empty as this tool takes no parameters).\n */\nexport const inputSchema = z.object({});\n\n// Success branch schema\nconst successBranchSchema = z.object({\n type: z.literal('success'),\n items: z.array(CategorySchema),\n});\n\n// Output schema with auth_required support\nconst outputSchema = z.discriminatedUnion('type', [successBranchSchema, AuthRequiredBranchSchema]);\n\nconst config = {\n description: 'List Gmail category labels (CATEGORY_*) with IDs and descriptions.',\n inputSchema: inputSchema,\n outputSchema: z.object({\n result: outputSchema,\n }),\n} as const;\n\n/**\n * Input parameters for the categories-list tool.\n */\nexport type Input = z.infer<typeof inputSchema>;\nexport type Output = z.infer<typeof outputSchema>;\n\nasync function handler(_: Input, extra: EnrichedExtra) {\n const logger = extra.logger;\n logger.info('gmail.categories.list called');\n\n try {\n const gmail = google.gmail({ version: 'v1', auth: extra.authContext.auth });\n const started = Date.now();\n\n // Fetch all labels from Gmail API\n const response = await gmail.users.labels.list({ userId: 'me' });\n const labels = response.data.labels || [];\n\n // Filter for CATEGORY_* system labels and map to our schema\n const categories = labels\n .filter((label) => label.id?.startsWith('CATEGORY_'))\n .map((label) => {\n const id = label.id as string;\n let name = label.name || id;\n let description = '';\n\n // Map known category types to user-friendly names and descriptions\n switch (id) {\n case 'CATEGORY_PERSONAL':\n name = 'Primary';\n description = 'Important emails from people you know';\n break;\n case 'CATEGORY_SOCIAL':\n name = 'Social';\n description = 'Social networks and social websites';\n break;\n case 'CATEGORY_PROMOTIONS':\n name = 'Promotions';\n description = 'Deals, offers, and marketing emails';\n break;\n case 'CATEGORY_UPDATES':\n name = 'Updates';\n description = 'Confirmations, receipts, bills, and statements';\n break;\n case 'CATEGORY_FORUMS':\n name = 'Forums';\n description = 'Online groups, discussion boards, mailing lists';\n break;\n default:\n // For any unknown CATEGORY_* labels, use the label name as-is\n name = label.name || id.replace('CATEGORY_', '');\n description = `Gmail category: ${name}`;\n }\n\n return {\n id,\n name,\n description,\n };\n })\n .sort((a, b) => a.name.localeCompare(b.name)); // Sort alphabetically by name\n\n const durationMs = Date.now() - started;\n\n logger.info('gmail.categories.list results', { categoryCount: categories.length, totalLabels: labels.length });\n logger.info('gmail.categories.list metrics', { durationMs });\n\n const result: Output = {\n type: 'success' as const,\n items: categories,\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.categories.list error', { error: message });\n\n throw new McpError(ErrorCode.InternalError, `Error listing categories: ${message}`, {\n stack: error instanceof Error ? error.stack : undefined,\n });\n }\n}\n\nexport default function createTool() {\n return {\n name: 'categories-list',\n config,\n handler,\n } satisfies ToolModule;\n}\n"],"names":["createTool","inputSchema","AuthRequiredBranchSchema","schemas","CategorySchema","z","object","id","string","describe","name","description","successBranchSchema","type","literal","items","array","outputSchema","discriminatedUnion","config","result","handler","_","extra","logger","gmail","started","response","labels","categories","durationMs","error","message","info","google","version","auth","authContext","Date","now","users","list","userId","data","filter","label","startsWith","map","replace","sort","a","b","localeCompare","categoryCount","length","totalLabels","content","text","JSON","stringify","structuredContent","Error","String","McpError","ErrorCode","InternalError","stack","undefined"],"mappings":";;;;;;;;;;;QAkIA;eAAwBA;;QA9GXC;eAAAA;;;2BAnBW;qBAKY;0BACb;mBACL;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AALlB,IAAM,AAAEC,2BAA6BC,oBAAO,CAApCD;AAOR,uCAAuC;AACvC,IAAME,iBAAiBC,MAAC,CAACC,MAAM,CAAC;IAC9BC,IAAIF,MAAC,CAACG,MAAM,GAAGC,QAAQ,CAAC;IACxBC,MAAML,MAAC,CAACG,MAAM,GAAGC,QAAQ,CAAC;IAC1BE,aAAaN,MAAC,CAACG,MAAM,GAAGC,QAAQ,CAAC;AACnC;AAKO,IAAMR,cAAcI,MAAC,CAACC,MAAM,CAAC,CAAC;AAErC,wBAAwB;AACxB,IAAMM,sBAAsBP,MAAC,CAACC,MAAM,CAAC;IACnCO,MAAMR,MAAC,CAACS,OAAO,CAAC;IAChBC,OAAOV,MAAC,CAACW,KAAK,CAACZ;AACjB;AAEA,2CAA2C;AAC3C,IAAMa,eAAeZ,MAAC,CAACa,kBAAkB,CAAC,QA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D;wBACrC;wBAEA,OAAO;4BACLH,IAAAA;4BACAG,MAAAA;4BACAC,aAAAA;wBACF;oBACF,GACCsC,IAAI,CAAC,SAACC,GAAGC;+BAAMD,EAAExC,IAAI,CAAC0C,aAAa,CAACD,EAAEzC,IAAI;wBAAI,8BAA8B;oBAEzEoB,aAAaQ,KAAKC,GAAG,KAAKb;oBAEhCF,OAAOS,IAAI,CAAC,iCAAiC;wBAAEoB,eAAexB,WAAWyB,MAAM;wBAAEC,aAAa3B,OAAO0B,MAAM;oBAAC;oBAC5G9B,OAAOS,IAAI,CAAC,iCAAiC;wBAAEH,YAAAA;oBAAW;oBAEpDV,SAAiB;wBACrBP,MAAM;wBACNE,OAAOc;oBACT;oBAEA;;wBAAO;4BACL2B,OAAO;gCACL;oCACE3C,MAAM;oCACN4C,MAAMC,KAAKC,SAAS,CAACvC;gCACvB;;4BAEFwC,mBAAmB;gCAAExC,QAAAA;4BAAO;wBAC9B;;;oBACOW;oBACDC,UAAUD,AAAK,YAALA,OAAiB8B,SAAQ9B,MAAMC,OAAO,GAAG8B,OAAO/B;oBAChEP,OAAOO,KAAK,CAAC,+BAA+B;wBAAEA,OAAOC;oBAAQ;oBAE7D,MAAM,IAAI+B,eAAQ,CAACC,gBAAS,CAACC,aAAa,EAAE,AAAC,6BAAoC,OAARjC,UAAW;wBAClFkC,OAAOnC,AAAK,YAALA,OAAiB8B,SAAQ9B,MAAMmC,KAAK,GAAGC;oBAChD;;;;;;;IAEJ;;AAEe,SAASnE;IACtB,OAAO;QACLU,MAAM;QACNS,QAAAA;QACAE,SAAAA;IACF;AACF"}
@@ -10,50 +10,50 @@ function _export(target, all) {
10
10
  }
11
11
  _export(exports, {
12
12
  get categoriesList () {
13
- return _categorieslist.default;
13
+ return _categorieslistts.default;
14
14
  },
15
15
  get labelAdd () {
16
- return _labeladd.default;
16
+ return _labeladdts.default;
17
17
  },
18
18
  get labelDelete () {
19
- return _labeldelete.default;
19
+ return _labeldeletets.default;
20
20
  },
21
21
  get labelsList () {
22
- return _labelslist.default;
22
+ return _labelslistts.default;
23
23
  },
24
24
  get messageGet () {
25
- return _messageget.default;
25
+ return _messagegetts.default;
26
26
  },
27
27
  get messageMarkRead () {
28
- return _messagemarkread.default;
28
+ return _messagemarkreadts.default;
29
29
  },
30
30
  get messageMoveToTrash () {
31
- return _messagemovetotrash.default;
31
+ return _messagemovetotrashts.default;
32
32
  },
33
33
  get messageRespond () {
34
- return _messagerespond.default;
34
+ return _messagerespondts.default;
35
35
  },
36
36
  get messageSearch () {
37
- return _messagesearch.default;
37
+ return _messagesearchts.default;
38
38
  },
39
39
  get messageSend () {
40
- return _messagesend.default;
40
+ return _messagesendts.default;
41
41
  },
42
42
  get messagesExportCsv () {
43
- return _messagesexportcsv.default;
43
+ return _messagesexportcsvts.default;
44
44
  }
45
45
  });
46
- var _categorieslist = /*#__PURE__*/ _interop_require_default(require("./categories-list.js"));
47
- var _labeladd = /*#__PURE__*/ _interop_require_default(require("./label-add.js"));
48
- var _labeldelete = /*#__PURE__*/ _interop_require_default(require("./label-delete.js"));
49
- var _labelslist = /*#__PURE__*/ _interop_require_default(require("./labels-list.js"));
50
- var _messageget = /*#__PURE__*/ _interop_require_default(require("./message-get.js"));
51
- var _messagemarkread = /*#__PURE__*/ _interop_require_default(require("./message-mark-read.js"));
52
- var _messagemovetotrash = /*#__PURE__*/ _interop_require_default(require("./message-move-to-trash.js"));
53
- var _messagerespond = /*#__PURE__*/ _interop_require_default(require("./message-respond.js"));
54
- var _messagesearch = /*#__PURE__*/ _interop_require_default(require("./message-search.js"));
55
- var _messagesend = /*#__PURE__*/ _interop_require_default(require("./message-send.js"));
56
- var _messagesexportcsv = /*#__PURE__*/ _interop_require_default(require("./messages-export-csv.js"));
46
+ var _categorieslistts = /*#__PURE__*/ _interop_require_default(require("./categories-list.js"));
47
+ var _labeladdts = /*#__PURE__*/ _interop_require_default(require("./label-add.js"));
48
+ var _labeldeletets = /*#__PURE__*/ _interop_require_default(require("./label-delete.js"));
49
+ var _labelslistts = /*#__PURE__*/ _interop_require_default(require("./labels-list.js"));
50
+ var _messagegetts = /*#__PURE__*/ _interop_require_default(require("./message-get.js"));
51
+ var _messagemarkreadts = /*#__PURE__*/ _interop_require_default(require("./message-mark-read.js"));
52
+ var _messagemovetotrashts = /*#__PURE__*/ _interop_require_default(require("./message-move-to-trash.js"));
53
+ var _messagerespondts = /*#__PURE__*/ _interop_require_default(require("./message-respond.js"));
54
+ var _messagesearchts = /*#__PURE__*/ _interop_require_default(require("./message-search.js"));
55
+ var _messagesendts = /*#__PURE__*/ _interop_require_default(require("./message-send.js"));
56
+ var _messagesexportcsvts = /*#__PURE__*/ _interop_require_default(require("./messages-export-csv.js"));
57
57
  function _interop_require_default(obj) {
58
58
  return obj && obj.__esModule ? obj : {
59
59
  default: obj
@@ -1 +1 @@
1
- {"version":3,"sources":["/Users/kevin/Dev/Projects/ai/mcp-z/servers/mcp-gmail/src/mcp/tools/index.ts"],"sourcesContent":["export { default as categoriesList } from './categories-list.js';\nexport { default as labelAdd } from './label-add.js';\nexport { default as labelDelete } from './label-delete.js';\nexport { default as labelsList } from './labels-list.js';\nexport { default as messageGet } from './message-get.js';\nexport { default as messageMarkRead } from './message-mark-read.js';\nexport { default as messageMoveToTrash } from './message-move-to-trash.js';\nexport { default as messageRespond } from './message-respond.js';\nexport { default as messageSearch } from './message-search.js';\nexport { default as messageSend } from './message-send.js';\nexport { default as messagesExportCsv } from './messages-export-csv.js';\n"],"names":["categoriesList","labelAdd","labelDelete","labelsList","messageGet","messageMarkRead","messageMoveToTrash","messageRespond","messageSearch","messageSend","messagesExportCsv"],"mappings":";;;;;;;;;;;QAAoBA;eAAAA,uBAAc;;QACdC;eAAAA,iBAAQ;;QACRC;eAAAA,oBAAW;;QACXC;eAAAA,mBAAU;;QACVC;eAAAA,mBAAU;;QACVC;eAAAA,wBAAe;;QACfC;eAAAA,2BAAkB;;QAClBC;eAAAA,uBAAc;;QACdC;eAAAA,sBAAa;;QACbC;eAAAA,oBAAW;;QACXC;eAAAA,0BAAiB;;;qEAVK;+DACN;kEACG;iEACD;iEACA;sEACK;yEACG;qEACJ;oEACD;kEACF;wEACM"}
1
+ {"version":3,"sources":["/Users/kevin/Dev/Projects/mcp-z/mcp-gmail/src/mcp/tools/index.ts"],"sourcesContent":["export { default as categoriesList } from './categories-list.ts';\nexport { default as labelAdd } from './label-add.ts';\nexport { default as labelDelete } from './label-delete.ts';\nexport { default as labelsList } from './labels-list.ts';\nexport { default as messageGet } from './message-get.ts';\nexport { default as messageMarkRead } from './message-mark-read.ts';\nexport { default as messageMoveToTrash } from './message-move-to-trash.ts';\nexport { default as messageRespond } from './message-respond.ts';\nexport { default as messageSearch } from './message-search.ts';\nexport { default as messageSend } from './message-send.ts';\nexport { default as messagesExportCsv } from './messages-export-csv.ts';\n"],"names":["categoriesList","labelAdd","labelDelete","labelsList","messageGet","messageMarkRead","messageMoveToTrash","messageRespond","messageSearch","messageSend","messagesExportCsv"],"mappings":";;;;;;;;;;;QAAoBA;eAAAA,yBAAc;;QACdC;eAAAA,mBAAQ;;QACRC;eAAAA,sBAAW;;QACXC;eAAAA,qBAAU;;QACVC;eAAAA,qBAAU;;QACVC;eAAAA,0BAAe;;QACfC;eAAAA,6BAAkB;;QAClBC;eAAAA,yBAAc;;QACdC;eAAAA,wBAAa;;QACbC;eAAAA,sBAAW;;QACXC;eAAAA,4BAAiB;;;uEAVK;iEACN;oEACG;mEACD;mEACA;wEACK;2EACG;uEACJ;sEACD;oEACF;0EACM"}
@@ -12,7 +12,7 @@ var _oauthgoogle = require("@mcp-z/oauth-google");
12
12
  var _types = require("@modelcontextprotocol/sdk/types.js");
13
13
  var _googleapis = require("googleapis");
14
14
  var _zod = require("zod");
15
- var _gmaillabels = require("../../labels/gmail-labels.js");
15
+ var _gmaillabelsts = require("../../labels/gmail-labels.js");
16
16
  function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) {
17
17
  try {
18
18
  var info = gen[key](arg);
@@ -206,7 +206,7 @@ function handler(_0, _1) {
206
206
  });
207
207
  return [
208
208
  4,
209
- (0, _gmaillabels.ensureLabelId)(gmail, 'me', label)
209
+ (0, _gmaillabelsts.ensureLabelId)(gmail, 'me', label)
210
210
  ];
211
211
  case 2:
212
212
  labelId = _state.sent();
@@ -1 +1 @@
1
- {"version":3,"sources":["/Users/kevin/Dev/Projects/ai/mcp-z/servers/mcp-gmail/src/mcp/tools/label-add.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 { ensureLabelId } from '../../labels/gmail-labels.js';\n\nconst inputSchema = z.object({\n id: z.coerce.string().trim().min(1).describe('Gmail message ID to add label to'),\n label: z.coerce.string().trim().min(1).describe('Label name or ID (use gmail-labels-list to discover available labels)'),\n});\n\n// Success branch schema\nconst successBranchSchema = z.object({\n type: z.literal('success'),\n item: z.object({\n id: z.string().describe('Message ID the label was added to'),\n label: z.string().describe('Label that was added'),\n }),\n});\n\n// Output schema with auth_required support\nconst outputSchema = z.discriminatedUnion('type', [successBranchSchema, AuthRequiredBranchSchema]);\n\nconst config = {\n description: 'Add a label 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, label }: Input, extra: EnrichedExtra) {\n const logger = extra.logger;\n logger.info('gmail.label.add called', { id, label });\n\n if (!id || !label) {\n logger.info('gmail.label.add missing parameters', { id, label });\n throw new McpError(ErrorCode.InvalidParams, 'Missing id or label');\n }\n\n try {\n const gmail = google.gmail({ version: 'v1', auth: extra.authContext.auth });\n\n const labelId = await ensureLabelId(gmail, 'me', label);\n await gmail.users.messages.modify({\n userId: 'me',\n id: id,\n requestBody: {\n addLabelIds: [labelId],\n },\n });\n\n logger.info('gmail.label.add success', { id, label });\n logger.info('gmail.label.add result (typed)', { id, label });\n\n const result: Output = {\n type: 'success' as const,\n item: { id, label },\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.label.add error', { error: message });\n\n throw new McpError(ErrorCode.InternalError, `Error adding label to message: ${message}`, {\n stack: error instanceof Error ? error.stack : undefined,\n });\n }\n}\n\nexport default function createTool() {\n return {\n name: 'label-add',\n config,\n handler,\n } satisfies ToolModule;\n}\n"],"names":["createTool","AuthRequiredBranchSchema","schemas","inputSchema","z","object","id","coerce","string","trim","min","describe","label","successBranchSchema","type","literal","item","outputSchema","discriminatedUnion","config","description","result","handler","extra","logger","gmail","labelId","error","message","info","McpError","ErrorCode","InvalidParams","google","version","auth","authContext","ensureLabelId","users","messages","modify","userId","requestBody","addLabelIds","content","text","JSON","stringify","structuredContent","Error","String","InternalError","stack","undefined","name"],"mappings":";;;;+BAuFA;;;eAAwBA;;;2BAtFA;qBAKY;0BACb;mBACL;2BACY;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAN9B,IAAM,AAAEC,2BAA6BC,oBAAO,CAApCD;AAQR,IAAME,cAAcC,MAAC,CAACC,MAAM,CAAC;IAC3BC,IAAIF,MAAC,CAACG,MAAM,CAACC,MAAM,GAAGC,IAAI,GAAGC,GAAG,CAAC,GAAGC,QAAQ,CAAC;IAC7CC,OAAOR,MAAC,CAACG,MAAM,CAACC,MAAM,GAAGC,IAAI,GAAGC,GAAG,CAAC,GAAGC,QAAQ,CAAC;AAClD;AAEA,wBAAw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AOK,IAAI,CAAC,2BAA2B;wBAAEvB,IAAAA;wBAAIM,OAAAA;oBAAM;oBACnDY,OAAOK,IAAI,CAAC,kCAAkC;wBAAEvB,IAAAA;wBAAIM,OAAAA;oBAAM;oBAEpDS,SAAiB;wBACrBP,MAAM;wBACNE,MAAM;4BAAEV,IAAAA;4BAAIM,OAAAA;wBAAM;oBACpB;oBAEA;;wBAAO;4BACLgC,OAAO;gCACL;oCACE9B,MAAM;oCACN+B,MAAMC,KAAKC,SAAS,CAAC1B;gCACvB;;4BAEF2B,mBAAmB;gCAAE3B,QAAAA;4BAAO;wBAC9B;;;oBACOM;oBACDC,UAAUD,AAAK,YAALA,OAAiBsB,SAAQtB,MAAMC,OAAO,GAAGsB,OAAOvB;oBAChEH,OAAOG,KAAK,CAAC,yBAAyB;wBAAEA,OAAOC;oBAAQ;oBAEvD,MAAM,IAAIE,eAAQ,CAACC,gBAAS,CAACoB,aAAa,EAAE,AAAC,kCAAyC,OAARvB,UAAW;wBACvFwB,OAAOzB,AAAK,YAALA,OAAiBsB,SAAQtB,MAAMyB,KAAK,GAAGC;oBAChD;;;;;;;IAEJ;;AAEe,SAASrD;IACtB,OAAO;QACLsD,MAAM;QACNnC,QAAAA;QACAG,SAAAA;IACF;AACF"}
1
+ {"version":3,"sources":["/Users/kevin/Dev/Projects/mcp-z/mcp-gmail/src/mcp/tools/label-add.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 { ensureLabelId } from '../../labels/gmail-labels.ts';\n\nconst inputSchema = z.object({\n id: z.coerce.string().trim().min(1).describe('Gmail message ID to add label to'),\n label: z.coerce.string().trim().min(1).describe('Label name or ID (use gmail-labels-list to discover available labels)'),\n});\n\n// Success branch schema\nconst successBranchSchema = z.object({\n type: z.literal('success'),\n item: z.object({\n id: z.string().describe('Message ID the label was added to'),\n label: z.string().describe('Label that was added'),\n }),\n});\n\n// Output schema with auth_required support\nconst outputSchema = z.discriminatedUnion('type', [successBranchSchema, AuthRequiredBranchSchema]);\n\nconst config = {\n description: 'Add a label 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, label }: Input, extra: EnrichedExtra) {\n const logger = extra.logger;\n logger.info('gmail.label.add called', { id, label });\n\n if (!id || !label) {\n logger.info('gmail.label.add missing parameters', { id, label });\n throw new McpError(ErrorCode.InvalidParams, 'Missing id or label');\n }\n\n try {\n const gmail = google.gmail({ version: 'v1', auth: extra.authContext.auth });\n\n const labelId = await ensureLabelId(gmail, 'me', label);\n await gmail.users.messages.modify({\n userId: 'me',\n id: id,\n requestBody: {\n addLabelIds: [labelId],\n },\n });\n\n logger.info('gmail.label.add success', { id, label });\n logger.info('gmail.label.add result (typed)', { id, label });\n\n const result: Output = {\n type: 'success' as const,\n item: { id, label },\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.label.add error', { error: message });\n\n throw new McpError(ErrorCode.InternalError, `Error adding label to message: ${message}`, {\n stack: error instanceof Error ? error.stack : undefined,\n });\n }\n}\n\nexport default function createTool() {\n return {\n name: 'label-add',\n config,\n handler,\n } satisfies ToolModule;\n}\n"],"names":["createTool","AuthRequiredBranchSchema","schemas","inputSchema","z","object","id","coerce","string","trim","min","describe","label","successBranchSchema","type","literal","item","outputSchema","discriminatedUnion","config","description","result","handler","extra","logger","gmail","labelId","error","message","info","McpError","ErrorCode","InvalidParams","google","version","auth","authContext","ensureLabelId","users","messages","modify","userId","requestBody","addLabelIds","content","text","JSON","stringify","structuredContent","Error","String","InternalError","stack","undefined","name"],"mappings":";;;;+BAuFA;;;eAAwBA;;;2BAtFA;qBAKY;0BACb;mBACL;6BACY;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAN9B,IAAM,AAAEC,2BAA6BC,oBAAO,CAApCD;AAQR,IAAME,cAAcC,MAAC,CAACC,MAAM,CAAC;IAC3BC,IAAIF,MAAC,CAACG,MAAM,CAACC,MAAM,GAAGC,IAAI,GAAGC,GAAG,CAAC,GAAGC,QAAQ,CAAC;IAC7CC,OAAOR,MAAC,CAACG,MAAM,CAACC,MAAM,GAAGC,IAAI,GAAGC,GAAG,CAAC,GAAGC,QAAQ,CAAC;AAClD;AAEA,wBAAwB;AACxB,IAAME,sBAAsBT,MAAC,CAACC,MAAM,CAAC;IACnCS,MAAMV,MAAC,CAACW,OAAO,CAAC;IAChBC,MAAMZ,MAAC,CAACC,MAAM,CAAC;QACbC,IAAIF,MAAC,CAACI,MAAM,GAAGG,QAAQ,CAAC;QACxBC,OAAOR,MAAC,CAACI,MAAM,GAAGG,QAAQ,CAAC;IAC7B;AACF;AAEA,2CAA2C;AAC3C,IAAMM,eAAeb,MAAC,CAACc,kBAAkB,CAAC,QAAQ;IAACL;IAAqBZ;CAAyB;AAEjG,IAAMkB,SAAS;IACbC,aAAa;IACbjB,aAAaA;IACbc,cAAcb,MAAC,CAACC,MAAM,CAAC;QACrBgB,QAAQJ;IACV;AACF;AAKA,SAAeK;wCAAQ,KAAoB,EAAEC,KAAoB;YAAxCjB,IAAIM,OACrBY,QASEC,OAEAC,SAYAL,QAcCM,OACDC;;;;oBAvCetB,KAAF,MAAEA,IAAIM,QAAN,MAAMA;oBACrBY,SAASD,MAAMC,MAAM;oBAC3BA,OAAOK,IAAI,C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sB,SAAQtB,MAAMyB,KAAK,GAAGC;oBAChD;;;;;;;IAEJ;;AAEe,SAASrD;IACtB,OAAO;QACLsD,MAAM;QACNnC,QAAAA;QACAG,SAAAA;IACF;AACF"}
@@ -1 +1 @@
1
- {"version":3,"sources":["/Users/kevin/Dev/Projects/ai/mcp-z/servers/mcp-gmail/src/mcp/tools/label-delete.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 label IDs to delete'),\n});\n\nconst successBranchSchema = z.object({\n type: z.literal('success'),\n totalRequested: z.number().describe('Total number of labels requested to delete'),\n successCount: z.number().describe('Number of labels successfully deleted'),\n failureCount: z.number().describe('Number of labels that failed to delete'),\n results: z\n .array(\n z.object({\n id: z.string().describe('Label 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 label'),\n});\n\nconst outputSchema = z.discriminatedUnion('type', [successBranchSchema, AuthRequiredBranchSchema]);\n\nconst config = {\n description: 'Delete Gmail labels permanently (irreversible). System labels (INBOX, SENT, etc.) cannot be deleted.',\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-label-delete 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 label 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 // Get all labels first to check for system labels\n const labelsResponse = await gmail.users.labels.list({ userId: 'me' });\n const allLabels = labelsResponse.data.labels || [];\n const labelMap = new Map(allLabels.map((label) => [label.id || '', label]));\n\n // Process deletions 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 const label = labelMap.get(id);\n\n // Check if label exists\n if (!label) {\n throw new Error(`Label not found: ${id}`);\n }\n\n // Check if it's a system label\n if (label.type === 'system') {\n throw new Error(`Cannot delete system label: ${label.name} (${id})`);\n }\n\n // Delete the label\n await gmail.users.labels.delete({\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-label-delete 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-label-delete error', { error: message });\n\n throw new McpError(ErrorCode.InternalError, `Error deleting labels: ${message}`, {\n stack: error instanceof Error ? error.stack : undefined,\n });\n }\n}\n\nexport default function createTool() {\n return {\n name: 'label-delete',\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","labelsResponse","allLabels","labelMap","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","label","get","Error","name","users","labels","delete","userId","status","errorMessage","reason","String","google","version","auth","authContext","list","data","Map","filter","r","chunksProcessed","content","text","JSON","stringify","structuredContent","InternalError","stack","undefined"],"mappings":";;;;+BA6LA;;;eAAwBA;;;2BA5LA;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,GAAGL,QAAQ,CAAC;IAClCQ,SAAShB,MAAC,CACPG,KAAK,CACJH,MAAC,CAACC,MAAM,CAAC;QACPgB,IAAIjB,MAAC,CAACK,MAAM,GAAGG,QAAQ,CAAC;QACxBU,SAASlB,MAAC,CAACmB,OAAO,GAAGX,QAAQ,CAAC;QAC9BY,OAAOpB,MAAC,CAACK,M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OAAOtD;oBAChES,OAAOT,KAAK,CAAC,4BAA4B;wBAAEA,OAAOmB;oBAAQ;oBAE1D,MAAM,IAAII,eAAQ,CAACC,gBAAS,CAAC8C,aAAa,EAAE,AAAC,0BAAiC,OAARnD,UAAW;wBAC/EoD,OAAOvE,AAAK,YAALA,OAAiB6C,SAAQ7C,MAAMuE,KAAK,GAAGC;oBAChD;;;;;;;IAEJ;;AAEe,SAAShG;IACtB,OAAO;QACLsE,MAAM;QACN1C,QAAAA;QACAG,SAAAA;IACF;AACF"}
1
+ {"version":3,"sources":["/Users/kevin/Dev/Projects/mcp-z/mcp-gmail/src/mcp/tools/label-delete.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 label IDs to delete'),\n});\n\nconst successBranchSchema = z.object({\n type: z.literal('success'),\n totalRequested: z.number().describe('Total number of labels requested to delete'),\n successCount: z.number().describe('Number of labels successfully deleted'),\n failureCount: z.number().describe('Number of labels that failed to delete'),\n results: z\n .array(\n z.object({\n id: z.string().describe('Label 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 label'),\n});\n\nconst outputSchema = z.discriminatedUnion('type', [successBranchSchema, AuthRequiredBranchSchema]);\n\nconst config = {\n description: 'Delete Gmail labels permanently (irreversible). System labels (INBOX, SENT, etc.) cannot be deleted.',\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-label-delete 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 label 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 // Get all labels first to check for system labels\n const labelsResponse = await gmail.users.labels.list({ userId: 'me' });\n const allLabels = labelsResponse.data.labels || [];\n const labelMap = new Map(allLabels.map((label) => [label.id || '', label]));\n\n // Process deletions 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 const label = labelMap.get(id);\n\n // Check if label exists\n if (!label) {\n throw new Error(`Label not found: ${id}`);\n }\n\n // Check if it's a system label\n if (label.type === 'system') {\n throw new Error(`Cannot delete system label: ${label.name} (${id})`);\n }\n\n // Delete the label\n await gmail.users.labels.delete({\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-label-delete 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-label-delete error', { error: message });\n\n throw new McpError(ErrorCode.InternalError, `Error deleting labels: ${message}`, {\n stack: error instanceof Error ? error.stack : undefined,\n });\n }\n}\n\nexport default function createTool() {\n return {\n name: 'label-delete',\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","labelsResponse","allLabels","labelMap","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","label","get","Error","name","users","labels","delete","userId","status","errorMessage","reason","String","google","version","auth","authContext","list","data","Map","filter","r","chunksProcessed","content","text","JSON","stringify","structuredContent","InternalError","stack","undefined"],"mappings":";;;;+BA6LA;;;eAAwBA;;;2BA5LA;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,GAAGL,QAAQ,CAAC;IAClCQ,SAAShB,MAAC,CACPG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oCACN4E,MAAMC,KAAKC,SAAS,CAAC9D;gCACvB;;4BAEF+D,mBAAmB;gCAAE/D,QAAAA;4BAAO;wBAC9B;;;oBACON;oBACDmB,UAAUnB,AAAK,YAALA,OAAiB6C,SAAQ7C,MAAMmB,OAAO,GAAGmC,OAAOtD;oBAChES,OAAOT,KAAK,CAAC,4BAA4B;wBAAEA,OAAOmB;oBAAQ;oBAE1D,MAAM,IAAII,eAAQ,CAACC,gBAAS,CAAC8C,aAAa,EAAE,AAAC,0BAAiC,OAARnD,UAAW;wBAC/EoD,OAAOvE,AAAK,YAALA,OAAiB6C,SAAQ7C,MAAMuE,KAAK,GAAGC;oBAChD;;;;;;;IAEJ;;AAEe,SAAShG;IACtB,OAAO;QACLsE,MAAM;QACN1C,QAAAA;QACAG,SAAAA;IACF;AACF"}
@@ -1,6 +1,9 @@
1
1
  import type { EnrichedExtra } from '@mcp-z/oauth-google';
2
2
  import { z } from 'zod';
3
- declare const inputSchema: z.ZodObject<{}, z.core.$strip>;
3
+ /**
4
+ * Input schema for the labels-list tool (currently empty as this tool takes no parameters).
5
+ */
6
+ export declare const inputSchema: z.ZodObject<{}, z.core.$strip>;
4
7
  declare const outputSchema: z.ZodDiscriminatedUnion<[z.ZodObject<{
5
8
  type: z.ZodLiteral<"success">;
6
9
  items: z.ZodArray<z.ZodObject<{
@@ -22,9 +25,12 @@ declare const outputSchema: z.ZodDiscriminatedUnion<[z.ZodObject<{
22
25
  message: z.ZodString;
23
26
  url: z.ZodOptional<z.ZodString>;
24
27
  }, z.core.$strip>], "type">;
28
+ /**
29
+ * Input parameters for the labels-list tool.
30
+ */
25
31
  export type Input = z.infer<typeof inputSchema>;
26
32
  export type Output = z.infer<typeof outputSchema>;
27
- declare function handler(_args: Input, extra: EnrichedExtra): Promise<{
33
+ declare function handler(_: Input, extra: EnrichedExtra): Promise<{
28
34
  content: {
29
35
  type: "text";
30
36
  text: string;
@@ -1,6 +1,9 @@
1
1
  import type { EnrichedExtra } from '@mcp-z/oauth-google';
2
2
  import { z } from 'zod';
3
- declare const inputSchema: z.ZodObject<{}, z.core.$strip>;
3
+ /**
4
+ * Input schema for the labels-list tool (currently empty as this tool takes no parameters).
5
+ */
6
+ export declare const inputSchema: z.ZodObject<{}, z.core.$strip>;
4
7
  declare const outputSchema: z.ZodDiscriminatedUnion<[z.ZodObject<{
5
8
  type: z.ZodLiteral<"success">;
6
9
  items: z.ZodArray<z.ZodObject<{
@@ -22,9 +25,12 @@ declare const outputSchema: z.ZodDiscriminatedUnion<[z.ZodObject<{
22
25
  message: z.ZodString;
23
26
  url: z.ZodOptional<z.ZodString>;
24
27
  }, z.core.$strip>], "type">;
28
+ /**
29
+ * Input parameters for the labels-list tool.
30
+ */
25
31
  export type Input = z.infer<typeof inputSchema>;
26
32
  export type Output = z.infer<typeof outputSchema>;
27
- declare function handler(_args: Input, extra: EnrichedExtra): Promise<{
33
+ declare function handler(_: Input, extra: EnrichedExtra): Promise<{
28
34
  content: {
29
35
  type: "text";
30
36
  text: string;
@@ -2,10 +2,18 @@
2
2
  Object.defineProperty(exports, "__esModule", {
3
3
  value: true
4
4
  });
5
- Object.defineProperty(exports, "default", {
6
- enumerable: true,
7
- get: function() {
5
+ function _export(target, all) {
6
+ for(var name in all)Object.defineProperty(target, name, {
7
+ enumerable: true,
8
+ get: Object.getOwnPropertyDescriptor(all, name).get
9
+ });
10
+ }
11
+ _export(exports, {
12
+ get default () {
8
13
  return createTool;
14
+ },
15
+ get inputSchema () {
16
+ return inputSchema;
9
17
  }
10
18
  });
11
19
  var _oauthgoogle = require("@mcp-z/oauth-google");
@@ -178,7 +186,7 @@ var config = {
178
186
  result: outputSchema
179
187
  })
180
188
  };
181
- function handler(_args, extra) {
189
+ function handler(_, extra) {
182
190
  return _async_to_generator(function() {
183
191
  var logger, gmail, started, response, labels, availableLabels, durationMs, result, error, message;
184
192
  return _ts_generator(this, function(_state) {
@@ -1 +1 @@
1
- {"version":3,"sources":["/Users/kevin/Dev/Projects/ai/mcp-z/servers/mcp-gmail/src/mcp/tools/labels-list.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\n// Schema for individual label items\nconst LabelSchema = z.object({\n id: z.string().describe('Gmail label ID'),\n name: z.string().describe('Label name for use in queries (case-sensitive)'),\n type: z.enum(['user', 'system']).describe('Whether this is a user-created or system label'),\n visibility: z.enum(['labelShow', 'labelHide', 'labelShowIfUnread']).describe('Label visibility in Gmail UI'),\n});\n\nconst inputSchema = z.object({});\n\nconst successBranchSchema = z.object({\n type: z.literal('success'),\n items: z.array(LabelSchema),\n});\n\nconst outputSchema = z.discriminatedUnion('type', [successBranchSchema, AuthRequiredBranchSchema]);\n\nconst config = {\n description: 'List Gmail labels for label: query syntax. Case-sensitive.',\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(_args: Input, extra: EnrichedExtra) {\n const logger = extra.logger;\n logger.info('gmail.labels.list called');\n\n try {\n const gmail = google.gmail({ version: 'v1', auth: extra.authContext.auth });\n const started = Date.now();\n\n // Fetch all labels from Gmail API\n const response = await gmail.users.labels.list({ userId: 'me' });\n const labels = response.data.labels || [];\n\n // Filter out CATEGORY_* labels (handled by categories tool) and map to our schema\n const availableLabels = labels\n .filter((label) => {\n // Exclude CATEGORY_* labels as they're handled by the categories tool\n return !label.id?.startsWith('CATEGORY_');\n })\n .map((label) => {\n const id = label.id as string;\n const name = label.name || id;\n\n // Determine label type\n const type: 'user' | 'system' = label.type === 'user' ? 'user' : 'system';\n\n // Map label visibility\n let visibility: 'labelShow' | 'labelHide' | 'labelShowIfUnread' = 'labelShow';\n if (label.labelListVisibility === 'labelHide') {\n visibility = 'labelHide';\n } else if (label.labelListVisibility === 'labelShowIfUnread') {\n visibility = 'labelShowIfUnread';\n }\n\n return {\n id,\n name,\n type,\n visibility,\n };\n })\n .sort((a, b) => {\n // Sort user labels first, then system labels, both alphabetically\n if (a.type !== b.type) {\n return a.type === 'user' ? -1 : 1;\n }\n // Use simple ASCII comparison for consistent, case-sensitive sorting\n return a.name < b.name ? -1 : a.name > b.name ? 1 : 0;\n });\n\n const durationMs = Date.now() - started;\n\n logger.info('gmail.labels.list results', {\n labelCount: availableLabels.length,\n userLabels: availableLabels.filter((l) => l.type === 'user').length,\n systemLabels: availableLabels.filter((l) => l.type === 'system').length,\n totalLabels: labels.length,\n });\n logger.info('gmail.labels.list metrics', { durationMs });\n\n const result: Output = {\n type: 'success' as const,\n items: availableLabels,\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.labels.list error', { error: message });\n\n throw new McpError(ErrorCode.InternalError, `Error listing labels: ${message}`, {\n stack: error instanceof Error ? error.stack : undefined,\n });\n }\n}\n\nexport default function createTool() {\n return {\n name: 'labels-list',\n config,\n handler,\n } satisfies ToolModule;\n}\n"],"names":["createTool","AuthRequiredBranchSchema","schemas","LabelSchema","z","object","id","string","describe","name","type","enum","visibility","inputSchema","successBranchSchema","literal","items","array","outputSchema","discriminatedUnion","config","description","result","handler","_args","extra","logger","gmail","started","response","labels","availableLabels","durationMs","error","message","info","google","version","auth","authContext","Date","now","users","list","userId","data","filter","label","startsWith","map","labelListVisibility","sort","a","b","labelCount","length","userLabels","l","systemLabels","totalLabels","content","text","JSON","stringify","structuredContent","Error","String","McpError","ErrorCode","InternalError","stack","undefined"],"mappings":";;;;+BAyHA;;;eAAwBA;;;2BAxHA;qBAKY;0BACb;mBACL;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;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,MAAM,CAAC,SAACW;mCAAMA,EAAE/C,IAAI,KAAK;2BAAU6C,MAAM;wBACvEI,aAAa7B,OAAOyB,MAAM;oBAC5B;oBACA7B,OAAOS,IAAI,CAAC,6BAA6B;wBAAEH,YAAAA;oBAAW;oBAEhDV,SAAiB;wBACrBZ,MAAM;wBACNM,OAAOe;oBACT;oBAEA;;wBAAO;4BACL6B,OAAO;gCACL;oCACElD,MAAM;oCACNmD,MAAMC,KAAKC,SAAS,CAACzC;gCACvB;;4BAEF0C,mBAAmB;gCAAE1C,QAAAA;4BAAO;wBAC9B;;;oBACOW;oBACDC,UAAUD,AAAK,YAALA,OAAiBgC,SAAQhC,MAAMC,OAAO,GAAGgC,OAAOjC;oBAChEP,OAAOO,KAAK,CAAC,2BAA2B;wBAAEA,OAAOC;oBAAQ;oBAEzD,MAAM,IAAIiC,eAAQ,CAACC,gBAAS,CAACC,aAAa,EAAE,AAAC,yBAAgC,OAARnC,UAAW;wBAC9EoC,OAAOrC,AAAK,YAALA,OAAiBgC,SAAQhC,MAAMqC,KAAK,GAAGC;oBAChD;;;;;;;IAEJ;;AAEe,SAASvE;IACtB,OAAO;QACLS,MAAM;QACNW,QAAAA;QACAG,SAAAA;IACF;AACF"}
1
+ {"version":3,"sources":["/Users/kevin/Dev/Projects/mcp-z/mcp-gmail/src/mcp/tools/labels-list.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\n// Schema for individual label items\nconst LabelSchema = z.object({\n id: z.string().describe('Gmail label ID'),\n name: z.string().describe('Label name for use in queries (case-sensitive)'),\n type: z.enum(['user', 'system']).describe('Whether this is a user-created or system label'),\n visibility: z.enum(['labelShow', 'labelHide', 'labelShowIfUnread']).describe('Label visibility in Gmail UI'),\n});\n\n/**\n * Input schema for the labels-list tool (currently empty as this tool takes no parameters).\n */\nexport const inputSchema = z.object({});\n\nconst successBranchSchema = z.object({\n type: z.literal('success'),\n items: z.array(LabelSchema),\n});\n\nconst outputSchema = z.discriminatedUnion('type', [successBranchSchema, AuthRequiredBranchSchema]);\n\nconst config = {\n description: 'List Gmail labels for label: query syntax. Case-sensitive.',\n inputSchema: inputSchema,\n outputSchema: z.object({\n result: outputSchema,\n }),\n} as const;\n\n/**\n * Input parameters for the labels-list tool.\n */\nexport type Input = z.infer<typeof inputSchema>;\nexport type Output = z.infer<typeof outputSchema>;\n\nasync function handler(_: Input, extra: EnrichedExtra) {\n const logger = extra.logger;\n logger.info('gmail.labels.list called');\n\n try {\n const gmail = google.gmail({ version: 'v1', auth: extra.authContext.auth });\n const started = Date.now();\n\n // Fetch all labels from Gmail API\n const response = await gmail.users.labels.list({ userId: 'me' });\n const labels = response.data.labels || [];\n\n // Filter out CATEGORY_* labels (handled by categories tool) and map to our schema\n const availableLabels = labels\n .filter((label) => {\n // Exclude CATEGORY_* labels as they're handled by the categories tool\n return !label.id?.startsWith('CATEGORY_');\n })\n .map((label) => {\n const id = label.id as string;\n const name = label.name || id;\n\n // Determine label type\n const type: 'user' | 'system' = label.type === 'user' ? 'user' : 'system';\n\n // Map label visibility\n let visibility: 'labelShow' | 'labelHide' | 'labelShowIfUnread' = 'labelShow';\n if (label.labelListVisibility === 'labelHide') {\n visibility = 'labelHide';\n } else if (label.labelListVisibility === 'labelShowIfUnread') {\n visibility = 'labelShowIfUnread';\n }\n\n return {\n id,\n name,\n type,\n visibility,\n };\n })\n .sort((a, b) => {\n // Sort user labels first, then system labels, both alphabetically\n if (a.type !== b.type) {\n return a.type === 'user' ? -1 : 1;\n }\n // Use simple ASCII comparison for consistent, case-sensitive sorting\n return a.name < b.name ? -1 : a.name > b.name ? 1 : 0;\n });\n\n const durationMs = Date.now() - started;\n\n logger.info('gmail.labels.list results', {\n labelCount: availableLabels.length,\n userLabels: availableLabels.filter((l) => l.type === 'user').length,\n systemLabels: availableLabels.filter((l) => l.type === 'system').length,\n totalLabels: labels.length,\n });\n logger.info('gmail.labels.list metrics', { durationMs });\n\n const result: Output = {\n type: 'success' as const,\n items: availableLabels,\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.labels.list error', { error: message });\n\n throw new McpError(ErrorCode.InternalError, `Error listing labels: ${message}`, {\n stack: error instanceof Error ? error.stack : undefined,\n });\n }\n}\n\nexport default function createTool() {\n return {\n name: 'labels-list',\n config,\n handler,\n } satisfies ToolModule;\n}\n"],"names":["createTool","inputSchema","AuthRequiredBranchSchema","schemas","LabelSchema","z","object","id","string","describe","name","type","enum","visibility","successBranchSchema","literal","items","array","outputSchema","discriminatedUnion","config","description","result","handler","_","extra","logger","gmail","started","response","labels","availableLabels","durationMs","error","message","info","google","version","auth","authContext","Date","now","users","list","userId","data","filter","label","startsWith","map","labelListVisibility","sort","a","b","labelCount","length","userLabels","l","systemLabels","totalLabels","content","text","JSON","stringify","structuredContent","Error","String","McpError","ErrorCode","InternalError","stack","undefined"],"mappings":";;;;;;;;;;;QA+HA;eAAwBA;;QA1GXC;eAAAA;;;2BApBW;qBAKY;0BACb;mBACL;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AALlB,IAAM,AAAEC,2BAA6BC,oBAAO,CAApCD;AAOR,oCAAoC;AACpC,IAAME,cAAcC,MAAC,CAACC,MAAM,CAAC;IAC3BC,IAAIF,MAAC,CAACG,MAAM,GAAGC,QAAQ,CAAC;IACxBC,MAAML,MAAC,CAACG,MAAM,GAAGC,QAAQ,CAAC;IAC1BE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CAAE1C,QAAAA;4BAAO;wBAC9B;;;oBACOW;oBACDC,UAAUD,AAAK,YAALA,OAAiBgC,SAAQhC,MAAMC,OAAO,GAAGgC,OAAOjC;oBAChEP,OAAOO,KAAK,CAAC,2BAA2B;wBAAEA,OAAOC;oBAAQ;oBAEzD,MAAM,IAAIiC,eAAQ,CAACC,gBAAS,CAACC,aAAa,EAAE,AAAC,yBAAgC,OAARnC,UAAW;wBAC9EoC,OAAOrC,AAAK,YAALA,OAAiBgC,SAAQhC,MAAMqC,KAAK,GAAGC;oBAChD;;;;;;;IAEJ;;AAEe,SAASvE;IACtB,OAAO;QACLU,MAAM;QACNU,QAAAA;QACAG,SAAAA;IACF;AACF"}
@@ -14,8 +14,8 @@ var _server = require("@mcp-z/server");
14
14
  var _types = require("@modelcontextprotocol/sdk/types.js");
15
15
  var _googleapis = require("googleapis");
16
16
  var _zod = require("zod");
17
- var _messageextraction = require("../../email/parsing/message-extraction.js");
18
- var _dateconversion = require("../../lib/date-conversion.js");
17
+ var _messageextractionts = require("../../email/parsing/message-extraction.js");
18
+ var _dateconversionts = require("../../lib/date-conversion.js");
19
19
  function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) {
20
20
  try {
21
21
  var info = gen[key](arg);
@@ -241,19 +241,19 @@ function handler(_0, _1) {
241
241
  String((_header_value = header.value) !== null && _header_value !== void 0 ? _header_value : '')
242
242
  ];
243
243
  }));
244
- fromInfo = (0, _messageextraction.extractFrom)(headersMap.From);
245
- toStr = (0, _messageextraction.extractEmails)(headersMap.To).join(', ');
246
- ccStr = (0, _messageextraction.extractEmails)(headersMap.Cc).join(', ');
247
- bccStr = (0, _messageextraction.extractEmails)(headersMap.Bcc).join(', ');
244
+ fromInfo = (0, _messageextractionts.extractFrom)(headersMap.From);
245
+ toStr = (0, _messageextractionts.extractEmails)(headersMap.To).join(', ');
246
+ ccStr = (0, _messageextractionts.extractEmails)(headersMap.Cc).join(', ');
247
+ bccStr = (0, _messageextractionts.extractEmails)(headersMap.Bcc).join(', ');
248
248
  messagePayload = fullData === null || fullData === void 0 ? void 0 : fullData.payload;
249
- bodyContent = messagePayload ? (0, _messageextraction.extractBodyFromPayload)(messagePayload, {
249
+ bodyContent = messagePayload ? (0, _messageextractionts.extractBodyFromPayload)(messagePayload, {
250
250
  contentType: contentType,
251
251
  excludeThreadHistory: excludeThreadHistory
252
252
  }) : '';
253
253
  payload = {
254
254
  id: (_fullData_id = fullData.id) !== null && _fullData_id !== void 0 ? _fullData_id : undefined,
255
255
  threadId: (_fullData_threadId = fullData.threadId) !== null && _fullData_threadId !== void 0 ? _fullData_threadId : undefined,
256
- date: (0, _dateconversion.toIsoUtc)(headersMap.Date) || headersMap.Date,
256
+ date: (0, _dateconversionts.toIsoUtc)(headersMap.Date) || headersMap.Date,
257
257
  from: (fromInfo === null || fromInfo === void 0 ? void 0 : fromInfo.address) || headersMap.From,
258
258
  fromName: fromInfo === null || fromInfo === void 0 ? void 0 : fromInfo.name,
259
259
  to: toStr,
@@ -1 +1 @@
1
- {"version":3,"sources":["/Users/kevin/Dev/Projects/ai/mcp-z/servers/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.js';\nimport { toIsoUtc } from '../../lib/date-conversion.js';\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;iCACiD;8BAC1C;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;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;YAA5E9B,I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,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/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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