@mcp-z/mcp-outlook 1.1.2 → 2.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (113) hide show
  1. package/README.md +5 -1
  2. package/dist/cjs/index.js.map +1 -1
  3. package/dist/cjs/mcp/prompts/draft-email.d.cts +2 -3
  4. package/dist/cjs/mcp/prompts/draft-email.d.ts +2 -3
  5. package/dist/cjs/mcp/prompts/draft-email.js.map +1 -1
  6. package/dist/cjs/mcp/prompts/query-syntax.d.cts +2 -3
  7. package/dist/cjs/mcp/prompts/query-syntax.d.ts +2 -3
  8. package/dist/cjs/mcp/prompts/query-syntax.js.map +1 -1
  9. package/dist/cjs/mcp/resources/email.d.cts +6 -5
  10. package/dist/cjs/mcp/resources/email.d.ts +6 -5
  11. package/dist/cjs/mcp/resources/email.js +2 -2
  12. package/dist/cjs/mcp/resources/email.js.map +1 -1
  13. package/dist/cjs/mcp/tools/categories-list.d.cts +1 -1
  14. package/dist/cjs/mcp/tools/categories-list.d.ts +1 -1
  15. package/dist/cjs/mcp/tools/categories-list.js +2 -2
  16. package/dist/cjs/mcp/tools/categories-list.js.map +1 -1
  17. package/dist/cjs/mcp/tools/label-add.d.cts +1 -1
  18. package/dist/cjs/mcp/tools/label-add.d.ts +1 -1
  19. package/dist/cjs/mcp/tools/label-add.js +2 -2
  20. package/dist/cjs/mcp/tools/label-add.js.map +1 -1
  21. package/dist/cjs/mcp/tools/label-delete.d.cts +1 -1
  22. package/dist/cjs/mcp/tools/label-delete.d.ts +1 -1
  23. package/dist/cjs/mcp/tools/label-delete.js +3 -3
  24. package/dist/cjs/mcp/tools/label-delete.js.map +1 -1
  25. package/dist/cjs/mcp/tools/labels-list.d.cts +1 -1
  26. package/dist/cjs/mcp/tools/labels-list.d.ts +1 -1
  27. package/dist/cjs/mcp/tools/labels-list.js +2 -2
  28. package/dist/cjs/mcp/tools/labels-list.js.map +1 -1
  29. package/dist/cjs/mcp/tools/message-get.d.cts +1 -1
  30. package/dist/cjs/mcp/tools/message-get.d.ts +1 -1
  31. package/dist/cjs/mcp/tools/message-get.js +2 -3
  32. package/dist/cjs/mcp/tools/message-get.js.map +1 -1
  33. package/dist/cjs/mcp/tools/message-mark-read.d.cts +1 -1
  34. package/dist/cjs/mcp/tools/message-mark-read.d.ts +1 -1
  35. package/dist/cjs/mcp/tools/message-mark-read.js +3 -3
  36. package/dist/cjs/mcp/tools/message-mark-read.js.map +1 -1
  37. package/dist/cjs/mcp/tools/message-move-to-trash.d.cts +1 -1
  38. package/dist/cjs/mcp/tools/message-move-to-trash.d.ts +1 -1
  39. package/dist/cjs/mcp/tools/message-move-to-trash.js +6 -6
  40. package/dist/cjs/mcp/tools/message-move-to-trash.js.map +1 -1
  41. package/dist/cjs/mcp/tools/message-respond.d.cts +1 -1
  42. package/dist/cjs/mcp/tools/message-respond.d.ts +1 -1
  43. package/dist/cjs/mcp/tools/message-respond.js +3 -3
  44. package/dist/cjs/mcp/tools/message-respond.js.map +1 -1
  45. package/dist/cjs/mcp/tools/message-search.d.cts +1 -1
  46. package/dist/cjs/mcp/tools/message-search.d.ts +1 -1
  47. package/dist/cjs/mcp/tools/message-search.js +1 -2
  48. package/dist/cjs/mcp/tools/message-search.js.map +1 -1
  49. package/dist/cjs/mcp/tools/message-send.d.cts +1 -1
  50. package/dist/cjs/mcp/tools/message-send.d.ts +1 -1
  51. package/dist/cjs/mcp/tools/message-send.js +3 -3
  52. package/dist/cjs/mcp/tools/message-send.js.map +1 -1
  53. package/dist/cjs/mcp/tools/messages-export-csv.d.cts +1 -1
  54. package/dist/cjs/mcp/tools/messages-export-csv.d.ts +1 -1
  55. package/dist/cjs/mcp/tools/messages-export-csv.js +1 -2
  56. package/dist/cjs/mcp/tools/messages-export-csv.js.map +1 -1
  57. package/dist/cjs/setup/http.d.cts +1 -1
  58. package/dist/cjs/setup/http.d.ts +1 -1
  59. package/dist/cjs/setup/http.js +28 -18
  60. package/dist/cjs/setup/http.js.map +1 -1
  61. package/dist/cjs/setup/stdio.d.cts +1 -1
  62. package/dist/cjs/setup/stdio.d.ts +1 -1
  63. package/dist/cjs/setup/stdio.js +1 -2
  64. package/dist/cjs/setup/stdio.js.map +1 -1
  65. package/dist/esm/index.js +1 -1
  66. package/dist/esm/index.js.map +1 -1
  67. package/dist/esm/mcp/prompts/draft-email.d.ts +2 -3
  68. package/dist/esm/mcp/prompts/draft-email.js.map +1 -1
  69. package/dist/esm/mcp/prompts/query-syntax.d.ts +2 -3
  70. package/dist/esm/mcp/prompts/query-syntax.js.map +1 -1
  71. package/dist/esm/mcp/resources/email.d.ts +6 -5
  72. package/dist/esm/mcp/resources/email.js +1 -1
  73. package/dist/esm/mcp/resources/email.js.map +1 -1
  74. package/dist/esm/mcp/tools/categories-list.d.ts +1 -1
  75. package/dist/esm/mcp/tools/categories-list.js +2 -2
  76. package/dist/esm/mcp/tools/categories-list.js.map +1 -1
  77. package/dist/esm/mcp/tools/label-add.d.ts +1 -1
  78. package/dist/esm/mcp/tools/label-add.js +2 -2
  79. package/dist/esm/mcp/tools/label-add.js.map +1 -1
  80. package/dist/esm/mcp/tools/label-delete.d.ts +1 -1
  81. package/dist/esm/mcp/tools/label-delete.js +3 -3
  82. package/dist/esm/mcp/tools/label-delete.js.map +1 -1
  83. package/dist/esm/mcp/tools/labels-list.d.ts +1 -1
  84. package/dist/esm/mcp/tools/labels-list.js +2 -2
  85. package/dist/esm/mcp/tools/labels-list.js.map +1 -1
  86. package/dist/esm/mcp/tools/message-get.d.ts +1 -1
  87. package/dist/esm/mcp/tools/message-get.js +3 -4
  88. package/dist/esm/mcp/tools/message-get.js.map +1 -1
  89. package/dist/esm/mcp/tools/message-mark-read.d.ts +1 -1
  90. package/dist/esm/mcp/tools/message-mark-read.js +3 -3
  91. package/dist/esm/mcp/tools/message-mark-read.js.map +1 -1
  92. package/dist/esm/mcp/tools/message-move-to-trash.d.ts +1 -1
  93. package/dist/esm/mcp/tools/message-move-to-trash.js +6 -6
  94. package/dist/esm/mcp/tools/message-move-to-trash.js.map +1 -1
  95. package/dist/esm/mcp/tools/message-respond.d.ts +1 -1
  96. package/dist/esm/mcp/tools/message-respond.js +3 -3
  97. package/dist/esm/mcp/tools/message-respond.js.map +1 -1
  98. package/dist/esm/mcp/tools/message-search.d.ts +1 -1
  99. package/dist/esm/mcp/tools/message-search.js +2 -3
  100. package/dist/esm/mcp/tools/message-search.js.map +1 -1
  101. package/dist/esm/mcp/tools/message-send.d.ts +1 -1
  102. package/dist/esm/mcp/tools/message-send.js +3 -3
  103. package/dist/esm/mcp/tools/message-send.js.map +1 -1
  104. package/dist/esm/mcp/tools/messages-export-csv.d.ts +1 -1
  105. package/dist/esm/mcp/tools/messages-export-csv.js +2 -3
  106. package/dist/esm/mcp/tools/messages-export-csv.js.map +1 -1
  107. package/dist/esm/setup/http.d.ts +1 -1
  108. package/dist/esm/setup/http.js +22 -12
  109. package/dist/esm/setup/http.js.map +1 -1
  110. package/dist/esm/setup/stdio.d.ts +1 -1
  111. package/dist/esm/setup/stdio.js +1 -2
  112. package/dist/esm/setup/stdio.js.map +1 -1
  113. package/package.json +7 -13
@@ -1 +1 @@
1
- {"version":3,"sources":["/Users/kevin/Dev/OpenSource/ai/mcp-z/mcp-outlook/src/mcp/tools/message-get.ts"],"sourcesContent":["import { EMAIL_COMMON_PATTERNS, EMAIL_FIELD_DESCRIPTIONS, EMAIL_FIELDS, EmailContentTypeSchema, EmailDetailSchema, ExcludeThreadHistorySchema, extractCurrentMessageFromHtml, extractCurrentMessageFromHtmlToText, normalizeDateToISO as toIsoUtc } from '@mcp-z/email';\nimport type { EnrichedExtra } from '@mcp-z/oauth-microsoft';\nimport { schemas } from '@mcp-z/oauth-microsoft';\n\nconst { AuthRequiredBranchSchema } = schemas;\n\nimport { createFieldsSchema, filterFields, parseFields, type ToolModule } from '@mcp-z/server';\nimport { Client } from '@microsoft/microsoft-graph-client';\nimport type * as MicrosoftGraph from '@microsoft/microsoft-graph-types';\nimport { type CallToolResult, ErrorCode, McpError } from '@modelcontextprotocol/sdk/types.js';\nimport { z } from 'zod';\n\nconst inputSchema = z.object({\n id: z.coerce.string().trim().min(1).describe('Outlook 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 - uses item: wrapper for consistency with standard vocabulary\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 an Outlook 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): Promise<CallToolResult> {\n const logger = extra.logger;\n\n const requestedFields = parseFields(fields, EMAIL_FIELDS);\n\n logger.info('outlook.message.get called', { id, fields: fields || 'all' });\n\n if (!id) {\n logger.info('outlook.message.get missing id');\n throw new McpError(ErrorCode.InvalidParams, 'Missing id');\n }\n\n try {\n const graph = Client.initWithMiddleware({ authProvider: extra.authContext.auth });\n const message = (await graph.api(`/me/messages/${encodeURIComponent(id)}`).get()) as MicrosoftGraph.Message;\n\n // Process body based on contentType and excludeThreadHistory options\n let bodyContent = message.body?.content ?? '';\n const isHtml = message.body?.contentType?.toLowerCase() === 'html';\n\n if (isHtml && excludeThreadHistory) {\n // Remove thread history from HTML\n bodyContent = extractCurrentMessageFromHtml(bodyContent);\n }\n\n if (isHtml && contentType === 'text') {\n // Convert HTML to plain text (thread extraction happens inside if excludeThreadHistory was true)\n bodyContent = excludeThreadHistory ? extractCurrentMessageFromHtmlToText(bodyContent) : extractCurrentMessageFromHtmlToText(message.body?.content ?? '');\n }\n\n // Build full message data\n const payload = {\n id: message.id,\n subject: message.subject,\n from: message.from?.emailAddress?.address,\n date: toIsoUtc(message.receivedDateTime) || message.receivedDateTime,\n snippet: message.bodyPreview,\n body: bodyContent,\n bodyContentType: contentType,\n };\n\n // Filter based on requested fields\n const filteredPayload = filterFields(payload, requestedFields);\n\n logger.info('outlook.message.get success', { id: payload.id, subject: payload.subject, from: payload.from, date: payload.date, fields: fields || 'all' });\n\n const result: Output = {\n type: 'success' as const,\n item: filteredPayload as z.infer<typeof EmailDetailSchema>,\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('outlook.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","message","graph","bodyContent","isHtml","payload","filteredPayload","error","parseFields","info","McpError","ErrorCode","InvalidParams","Client","initWithMiddleware","authProvider","authContext","auth","api","encodeURIComponent","get","body","content","toLowerCase","extractCurrentMessageFromHtml","extractCurrentMessageFromHtmlToText","subject","from","emailAddress","address","date","toIsoUtc","receivedDateTime","snippet","bodyPreview","bodyContentType","filterFields","text","JSON","stringify","structuredContent","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ContentTypeSchema, EmailDetailSchema, ExcludeThreadHistorySchema, extractCurrentMessageFromHtml, extractCurrentMessageFromHtmlToText, normalizeDateToISO as toIsoUtc } from '@mcp-z/email';\nimport type { EnrichedExtra } from '@mcp-z/oauth-microsoft';\nimport { schemas } from '@mcp-z/oauth-microsoft';\n\nconst { AuthRequiredBranchSchema } = schemas;\n\nimport { type CallToolResult, createFieldsSchema, filterFields, ProtocolError, ProtocolErrorCode, parseFields, type ToolModule } from '@mcp-z/server';\nimport { Client } from '@microsoft/microsoft-graph-client';\nimport type * as MicrosoftGraph from '@microsoft/microsoft-graph-types';\nimport { z } from 'zod';\n\nconst inputSchema = z.object({\n id: z.coerce.string().trim().min(1).describe('Outlook 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 - uses item: wrapper for consistency with standard vocabulary\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 an Outlook 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): Promise<CallToolResult> {\n const logger = extra.logger;\n\n const requestedFields = parseFields(fields, EMAIL_FIELDS);\n\n logger.info('outlook.message.get called', { id, fields: fields || 'all' });\n\n if (!id) {\n logger.info('outlook.message.get missing id');\n throw new ProtocolError(ProtocolErrorCode.InvalidParams, 'Missing id');\n }\n\n try {\n const graph = Client.initWithMiddleware({ authProvider: extra.authContext.auth });\n const message = (await graph.api(`/me/messages/${encodeURIComponent(id)}`).get()) as MicrosoftGraph.Message;\n\n // Process body based on contentType and excludeThreadHistory options\n let bodyContent = message.body?.content ?? '';\n const isHtml = message.body?.contentType?.toLowerCase() === 'html';\n\n if (isHtml && excludeThreadHistory) {\n // Remove thread history from HTML\n bodyContent = extractCurrentMessageFromHtml(bodyContent);\n }\n\n if (isHtml && contentType === 'text') {\n // Convert HTML to plain text (thread extraction happens inside if excludeThreadHistory was true)\n bodyContent = excludeThreadHistory ? extractCurrentMessageFromHtmlToText(bodyContent) : extractCurrentMessageFromHtmlToText(message.body?.content ?? '');\n }\n\n // Build full message data\n const payload = {\n id: message.id,\n subject: message.subject,\n from: message.from?.emailAddress?.address,\n date: toIsoUtc(message.receivedDateTime) || message.receivedDateTime,\n snippet: message.bodyPreview,\n body: bodyContent,\n bodyContentType: contentType,\n };\n\n // Filter based on requested fields\n const filteredPayload = filterFields(payload, requestedFields);\n\n logger.info('outlook.message.get success', { id: payload.id, subject: payload.subject, from: payload.from, date: payload.date, fields: fields || 'all' });\n\n const result: Output = {\n type: 'success' as const,\n item: filteredPayload as z.infer<typeof EmailDetailSchema>,\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('outlook.message.get error', { error: message });\n\n throw new ProtocolError(ProtocolErrorCode.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","message","graph","bodyContent","isHtml","payload","filteredPayload","error","parseFields","info","ProtocolError","ProtocolErrorCode","InvalidParams","Client","initWithMiddleware","authProvider","authContext","auth","api","encodeURIComponent","get","body","content","toLowerCase","extractCurrentMessageFromHtml","extractCurrentMessageFromHtmlToText","subject","from","emailAddress","address","date","toIsoUtc","receivedDateTime","snippet","bodyPreview","bodyContentType","filterFields","text","JSON","stringify","structuredContent","Error","String","InternalError","stack","undefined","name"],"mappings":";;;;+BAiHA;;;eAAwBA;;;qBAjHiO;8BAEjO;sBAI8G;oCAC/G;mBAEL;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AALlB,IAAM,AAAEC,2BAA6BC,uBAAO,CAApCD;AAOR,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,sFAAsF;AACtF,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,S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AAiC,OAAR1C,WAAW;wBAC5F2C,OAAOrC,AAAK,YAALA,OAAiBkC,SAAQlC,MAAMqC,KAAK,GAAGC;oBAChD;;;;;;;IAEJ;;AAEe,SAASnF;IACtB,OAAO;QACLoF,MAAM;QACNpD,QAAAA;QACAG,SAAAA;IACF;AACF"}
@@ -1,5 +1,5 @@
1
1
  import type { EnrichedExtra } from '@mcp-z/oauth-microsoft';
2
- import { type CallToolResult } from '@modelcontextprotocol/sdk/types.js';
2
+ import { type CallToolResult } from '@mcp-z/server';
3
3
  import { z } from 'zod';
4
4
  declare const inputSchema: z.ZodObject<{
5
5
  id: z.ZodCoercedString<unknown>;
@@ -1,5 +1,5 @@
1
1
  import type { EnrichedExtra } from '@mcp-z/oauth-microsoft';
2
- import { type CallToolResult } from '@modelcontextprotocol/sdk/types.js';
2
+ import { type CallToolResult } from '@mcp-z/server';
3
3
  import { z } from 'zod';
4
4
  declare const inputSchema: z.ZodObject<{
5
5
  id: z.ZodCoercedString<unknown>;
@@ -9,8 +9,8 @@ Object.defineProperty(exports, "default", {
9
9
  }
10
10
  });
11
11
  var _oauthmicrosoft = require("@mcp-z/oauth-microsoft");
12
+ var _server = require("@mcp-z/server");
12
13
  var _microsoftgraphclient = require("@microsoft/microsoft-graph-client");
13
- var _types = require("@modelcontextprotocol/sdk/types.js");
14
14
  var _zod = require("zod");
15
15
  function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) {
16
16
  try {
@@ -180,7 +180,7 @@ function handler(_0, _1) {
180
180
  });
181
181
  if (!id) {
182
182
  logger.info('outlook-message-mark-read missing id');
183
- throw new _types.McpError(_types.ErrorCode.InvalidParams, 'Missing id');
183
+ throw new _server.ProtocolError(_server.ProtocolErrorCode.InvalidParams, 'Missing id');
184
184
  }
185
185
  _state.label = 1;
186
186
  case 1:
@@ -229,7 +229,7 @@ function handler(_0, _1) {
229
229
  logger.error('outlook-message-mark-read error', {
230
230
  error: message
231
231
  });
232
- throw new _types.McpError(_types.ErrorCode.InternalError, "Error marking message as read: ".concat(message), {
232
+ throw new _server.ProtocolError(_server.ProtocolErrorCode.InternalError, "Error marking message as read: ".concat(message), {
233
233
  stack: _instanceof(error, Error) ? error.stack : undefined
234
234
  });
235
235
  case 4:
@@ -1 +1 @@
1
- {"version":3,"sources":["/Users/kevin/Dev/OpenSource/ai/mcp-z/mcp-outlook/src/mcp/tools/message-mark-read.ts"],"sourcesContent":["import type { EnrichedExtra } from '@mcp-z/oauth-microsoft';\nimport { schemas } from '@mcp-z/oauth-microsoft';\n\nconst { AuthRequiredBranchSchema } = schemas;\n\nimport type { ToolModule } from '@mcp-z/server';\nimport { Client } from '@microsoft/microsoft-graph-client';\nimport { type CallToolResult, ErrorCode, McpError } from '@modelcontextprotocol/sdk/types.js';\nimport { z } from 'zod';\n\nconst SuccessSchema = z.object({\n success: z.boolean().describe('Whether the operation completed successfully'),\n id: z.string().optional().describe('Message ID that was marked as read'),\n});\n\nconst inputSchema = z.object({\n id: z.coerce.string().trim().min(1).describe('Outlook message ID to mark as read'),\n});\n\n// Success branch schema\nconst successBranchSchema = SuccessSchema.extend({\n type: z.literal('success'),\n});\n\n// Output schema with auth_required support\nconst outputSchema = z.discriminatedUnion('type', [successBranchSchema, AuthRequiredBranchSchema]);\n\nconst config = {\n description: 'Mark an Outlook 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): Promise<CallToolResult> {\n const logger = extra.logger;\n logger.info('outlook-message-mark-read called', { id });\n\n if (!id) {\n logger.info('outlook-message-mark-read missing id');\n throw new McpError(ErrorCode.InvalidParams, 'Missing id');\n }\n\n try {\n const graph = Client.initWithMiddleware({ authProvider: extra.authContext.auth });\n await graph.api(`/me/messages/${encodeURIComponent(id)}`).update({ isRead: true });\n\n logger.info('outlook-message-mark-read success', { id });\n\n const result: Output = {\n type: 'success' as const,\n success: true,\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('outlook-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","SuccessSchema","z","object","success","boolean","describe","id","string","optional","inputSchema","coerce","trim","min","successBranchSchema","extend","type","literal","outputSchema","discriminatedUnion","config","description","result","handler","extra","logger","graph","error","message","info","McpError","ErrorCode","InvalidParams","Client","initWithMiddleware","authProvider","authContext","auth","api","encodeURIComponent","update","isRead","content","text","JSON","stringify","structuredContent","Error","String","InternalError","stack","undefined","name"],"mappings":";;;;+BA8EA;;;eAAwBA;;;8BA7EA;oCAKD;qBACkC;mBACvC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AALlB,IAAM,AAAEC,2BAA6BC,uBAAO,CAApCD;AAOR,IAAME,gBAAgBC,MAAC,CAACC,MAAM,CAAC;IAC7BC,SAASF,MAAC,CAACG,OAAO,GAAGC,QAAQ,CAAC;IAC9BC,IAAIL,MAAC,CAACM,MAAM,GAAGC,QAAQ,GAAGH,QAAQ,CAAC;AACrC;AAEA,IAAMI,cAAcR,MAAC,CAACC,MAAM,CAAC;IAC3BI,IAAIL,MAAC,CAACS,MAAM,CAACH,MAAM,GAAGI,IAAI,GAAGC,GAAG,CAAC,GAAGP,QAAQ,CAAC;AAC/C;AAEA,wBAAwB;AACxB,IAAMQ,sBAAsBb,cAAcc,MAAM,CAAC;IA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AIE,eAAQ,CAACC,gBAAS,CAACkB,aAAa,EAAE,AAAC,kCAAyC,OAARrB,UAAW;wBACvFsB,OAAOvB,AAAK,YAALA,OAAiBoB,SAAQpB,MAAMuB,KAAK,GAAGC;oBAChD;;;;;;;IAEJ;;AAEe,SAASrD;IACtB,OAAO;QACLsD,MAAM;QACNhC,QAAAA;QACAG,SAAAA;IACF;AACF"}
1
+ {"version":3,"sources":["/Users/kevin/Dev/OpenSource/ai/mcp-z/mcp-outlook/src/mcp/tools/message-mark-read.ts"],"sourcesContent":["import type { EnrichedExtra } from '@mcp-z/oauth-microsoft';\nimport { schemas } from '@mcp-z/oauth-microsoft';\n\nconst { AuthRequiredBranchSchema } = schemas;\n\nimport type { ToolModule } from '@mcp-z/server';\nimport { type CallToolResult, ProtocolError, ProtocolErrorCode } from '@mcp-z/server';\nimport { Client } from '@microsoft/microsoft-graph-client';\nimport { z } from 'zod';\n\nconst SuccessSchema = z.object({\n success: z.boolean().describe('Whether the operation completed successfully'),\n id: z.string().optional().describe('Message ID that was marked as read'),\n});\n\nconst inputSchema = z.object({\n id: z.coerce.string().trim().min(1).describe('Outlook message ID to mark as read'),\n});\n\n// Success branch schema\nconst successBranchSchema = SuccessSchema.extend({\n type: z.literal('success'),\n});\n\n// Output schema with auth_required support\nconst outputSchema = z.discriminatedUnion('type', [successBranchSchema, AuthRequiredBranchSchema]);\n\nconst config = {\n description: 'Mark an Outlook 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): Promise<CallToolResult> {\n const logger = extra.logger;\n logger.info('outlook-message-mark-read called', { id });\n\n if (!id) {\n logger.info('outlook-message-mark-read missing id');\n throw new ProtocolError(ProtocolErrorCode.InvalidParams, 'Missing id');\n }\n\n try {\n const graph = Client.initWithMiddleware({ authProvider: extra.authContext.auth });\n await graph.api(`/me/messages/${encodeURIComponent(id)}`).update({ isRead: true });\n\n logger.info('outlook-message-mark-read success', { id });\n\n const result: Output = {\n type: 'success' as const,\n success: true,\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('outlook-message-mark-read error', { error: message });\n\n throw new ProtocolError(ProtocolErrorCode.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","SuccessSchema","z","object","success","boolean","describe","id","string","optional","inputSchema","coerce","trim","min","successBranchSchema","extend","type","literal","outputSchema","discriminatedUnion","config","description","result","handler","extra","logger","graph","error","message","info","ProtocolError","ProtocolErrorCode","InvalidParams","Client","initWithMiddleware","authProvider","authContext","auth","api","encodeURIComponent","update","isRead","content","text","JSON","stringify","structuredContent","Error","String","InternalError","stack","undefined","name"],"mappings":";;;;+BA8EA;;;eAAwBA;;;8BA7EA;sBAK8C;oCAC/C;mBACL;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AALlB,IAAM,AAAEC,2BAA6BC,uBAAO,CAApCD;AAOR,IAAME,gBAAgBC,MAAC,CAACC,MAAM,CAAC;IAC7BC,SAASF,MAAC,CAACG,OAAO,GAAGC,QAAQ,CAAC;IAC9BC,IAAIL,MAAC,CAACM,MAAM,GAAGC,QAAQ,GAAGH,QAAQ,CAAC;AACrC;AAEA,IAAMI,cAAcR,MAAC,CAACC,MAAM,CAAC;IAC3BI,IAAIL,MAAC,CAACS,MAAM,CAACH,MAAM,GAAGI,IAAI,GAAG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MC,OAAO,GAAGoB,OAAOrB;oBAChEF,OAAOE,KAAK,CAAC,mCAAmC;wBAAEA,OAAOC;oBAAQ;oBAEjE,MAAM,IAAIE,qBAAa,CAACC,yBAAiB,CAACkB,aAAa,EAAE,AAAC,kCAAyC,OAARrB,UAAW;wBACpGsB,OAAOvB,AAAK,YAALA,OAAiBoB,SAAQpB,MAAMuB,KAAK,GAAGC;oBAChD;;;;;;;IAEJ;;AAEe,SAASrD;IACtB,OAAO;QACLsD,MAAM;QACNhC,QAAAA;QACAG,SAAAA;IACF;AACF"}
@@ -1,5 +1,5 @@
1
1
  import type { EnrichedExtra } from '@mcp-z/oauth-microsoft';
2
- import { type CallToolResult } from '@modelcontextprotocol/sdk/types.js';
2
+ import { type CallToolResult } from '@mcp-z/server';
3
3
  import { z } from 'zod';
4
4
  declare const inputSchema: z.ZodObject<{
5
5
  ids: z.ZodArray<z.ZodCoercedString<unknown>>;
@@ -1,5 +1,5 @@
1
1
  import type { EnrichedExtra } from '@mcp-z/oauth-microsoft';
2
- import { type CallToolResult } from '@modelcontextprotocol/sdk/types.js';
2
+ import { type CallToolResult } from '@mcp-z/server';
3
3
  import { z } from 'zod';
4
4
  declare const inputSchema: z.ZodObject<{
5
5
  ids: z.ZodArray<z.ZodCoercedString<unknown>>;
@@ -9,8 +9,8 @@ Object.defineProperty(exports, "default", {
9
9
  }
10
10
  });
11
11
  var _oauthmicrosoft = require("@mcp-z/oauth-microsoft");
12
+ var _server = require("@mcp-z/server");
12
13
  var _microsoftgraphclient = require("@microsoft/microsoft-graph-client");
13
- var _types = require("@modelcontextprotocol/sdk/types.js");
14
14
  var _zod = require("zod");
15
15
  var _constantsts = require("../../constants.js");
16
16
  function _array_like_to_array(arr, len) {
@@ -238,7 +238,7 @@ function handler(_0, _1) {
238
238
  });
239
239
  if (!ids || ids.length === 0) {
240
240
  logger.info('outlook-message-move-to-trash missing ids');
241
- throw new _types.McpError(_types.ErrorCode.InvalidParams, 'Missing ids');
241
+ throw new _server.ProtocolError(_server.ProtocolErrorCode.InvalidParams, 'Missing ids');
242
242
  }
243
243
  // Validate batch size to prevent memory exhaustion
244
244
  if (ids.length > _constantsts.MAX_BATCH_SIZE) {
@@ -246,7 +246,7 @@ function handler(_0, _1) {
246
246
  requested: ids.length,
247
247
  max: _constantsts.MAX_BATCH_SIZE
248
248
  });
249
- throw new _types.McpError(_types.ErrorCode.InvalidParams, "Batch size ".concat(ids.length, " exceeds maximum allowed size of ").concat(_constantsts.MAX_BATCH_SIZE));
249
+ throw new _server.ProtocolError(_server.ProtocolErrorCode.InvalidParams, "Batch size ".concat(ids.length, " exceeds maximum allowed size of ").concat(_constantsts.MAX_BATCH_SIZE));
250
250
  }
251
251
  // Validate and sanitize IDs
252
252
  validatedIds = [];
@@ -286,11 +286,11 @@ function handler(_0, _1) {
286
286
  invalidIds: invalidIds,
287
287
  count: invalidIds.length
288
288
  });
289
- throw new _types.McpError(_types.ErrorCode.InvalidParams, "Found ".concat(invalidIds.length, " invalid IDs: ").concat(invalidIds.join(', ')));
289
+ throw new _server.ProtocolError(_server.ProtocolErrorCode.InvalidParams, "Found ".concat(invalidIds.length, " invalid IDs: ").concat(invalidIds.join(', ')));
290
290
  }
291
291
  if (validatedIds.length === 0) {
292
292
  logger.info('outlook-message-move-to-trash no valid ids after validation');
293
- throw new _types.McpError(_types.ErrorCode.InvalidParams, 'No valid IDs found after validation');
293
+ throw new _server.ProtocolError(_server.ProtocolErrorCode.InvalidParams, 'No valid IDs found after validation');
294
294
  }
295
295
  _state.label = 1;
296
296
  case 1:
@@ -443,7 +443,7 @@ function handler(_0, _1) {
443
443
  logger.error('outlook-message-move-to-trash error', {
444
444
  error: message
445
445
  });
446
- throw new _types.McpError(_types.ErrorCode.InternalError, "Error moving messages to trash: ".concat(message), {
446
+ throw new _server.ProtocolError(_server.ProtocolErrorCode.InternalError, "Error moving messages to trash: ".concat(message), {
447
447
  stack: _instanceof(error, Error) ? error.stack : undefined
448
448
  });
449
449
  case 7:
@@ -1 +1 @@
1
- {"version":3,"sources":["/Users/kevin/Dev/OpenSource/ai/mcp-z/mcp-outlook/src/mcp/tools/message-move-to-trash.ts"],"sourcesContent":["import type { EnrichedExtra } from '@mcp-z/oauth-microsoft';\nimport { schemas } from '@mcp-z/oauth-microsoft';\n\nconst { AuthRequiredBranchSchema } = schemas;\n\nimport type { ToolModule } from '@mcp-z/server';\nimport { Client } from '@microsoft/microsoft-graph-client';\nimport { type CallToolResult, ErrorCode, McpError } from '@modelcontextprotocol/sdk/types.js';\nimport { z } from 'zod';\nimport { CHUNK_SIZE, MAX_BATCH_SIZE } from '../../constants.ts';\n\nconst BatchResultSchema = z.object({\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 inputSchema = z.object({\n ids: z.array(z.coerce.string().trim().min(1)).min(1).describe('Outlook message IDs to move to trash'),\n});\n\n// Success branch schema\nconst successBranchSchema = BatchResultSchema.extend({\n type: z.literal('success'),\n});\n\n// Output schema with auth_required support\nconst outputSchema = z.discriminatedUnion('type', [successBranchSchema, AuthRequiredBranchSchema]);\n\nconst config = {\n description: 'Move Outlook 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): Promise<CallToolResult> {\n const logger = extra.logger;\n logger.info('outlook-message-move-to-trash called', { count: ids.length });\n\n if (!ids || ids.length === 0) {\n logger.info('outlook-message-move-to-trash missing ids');\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 logger.info('outlook-message-move-to-trash batch size exceeded', { requested: ids.length, max: 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 Outlook 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 logger.info('outlook-message-move-to-trash found invalid ids', { invalidIds, count: invalidIds.length });\n throw new McpError(ErrorCode.InvalidParams, `Found ${invalidIds.length} invalid IDs: ${invalidIds.join(', ')}`);\n }\n\n if (validatedIds.length === 0) {\n logger.info('outlook-message-move-to-trash no valid ids after validation');\n throw new McpError(ErrorCode.InvalidParams, 'No valid IDs found after validation');\n }\n\n try {\n const graph = Client.initWithMiddleware({ authProvider: 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 graph.api(`/me/messages/${encodeURIComponent(id)}`).delete();\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 const result: Output = {\n type: 'success' as const,\n totalRequested: validatedIds.length,\n successCount,\n failureCount,\n results: allResults,\n };\n\n logger.info('outlook-message-move-to-trash completed', {\n totalRequested: validatedIds.length,\n successCount,\n failureCount,\n chunksProcessed: Math.ceil(validatedIds.length / CHUNK_SIZE),\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('outlook-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","BatchResultSchema","z","object","totalRequested","number","describe","successCount","failureCount","results","array","id","string","success","boolean","error","optional","inputSchema","ids","coerce","trim","min","successBranchSchema","extend","type","literal","outputSchema","discriminatedUnion","config","description","result","handler","extra","logger","validatedIds","invalidIds","trimmedId","graph","allResults","i","message","info","count","length","McpError","ErrorCode","InvalidParams","MAX_BATCH_SIZE","requested","max","push","includes","join","chunk","chunkResults","processedChunkResults","slice","CHUNK_SIZE","chunkIndex","chunkSize","totalChunks","Math","ceil","Promise","allSettled","map","api","encodeURIComponent","delete","Error","status","errorMessage","reason","String","Client","initWithMiddleware","authProvider","authContext","auth","filter","r","chunksProcessed","content","text","JSON","stringify","structuredContent","InternalError","stack","undefined","name"],"mappings":";;;;+BAiLA;;;eAAwBA;;;8BAhLA;oCAKD;qBACkC;mBACvC;2BACyB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAN3C,IAAM,AAAEC,2BAA6BC,uBAAO,CAApCD;AAQR,IAAME,oBAAoBC,MAAC,CAACC,MAAM,CAAC;IACjCC,gBAAgBF,MAAC,CAACG,MAAM,GAAGC,QAAQ,CAAC;IACpCC,cAAcL,MAAC,CAACG,MAAM,GAAGC,QAAQ,CAAC;IAClCE,cAAcN,MAAC,CAACG,MAAM,GAAGC,QAAQ,CAAC;IAClCG,SAASP,MAAC,CACPQ,KAAK,CACJR,MAAC,CAACC,MAAM,CAAC;QACPQ,IAAIT,MAAC,CAACU,MAAM,GAAGN,QAAQ,CAAC;QACxBO,SAASX,MAAC,CAACY,OAAO,GAAGR,QAAQ,CAAC;QAC9BS,OAAOb,MAAC,CAACU,MAAM,GAAGI,QAAQ,GAAGV,QAAQ,CAAC;IACxC,IAEDA,QAAQ,CAAC;AACd;AAEA,IAAMW,cAAcf,MAAC,CAACC,MAAM,CAAC;IAC3Be,KAAKhB,MAAC,CAACQ,KAAK,CAACR,MAAC,CAACiB,MAAM,CAACP,MAAM,GAAGQ,IAAI,GAAGC,GAAG,CAAC,IAAIA,GAAG,CAAC,GAAGf,QAAQ,CAAC;AAChE;AAEA,wBAAwB;AACxB,IAAMgB,sBAAsBrB,kBAAkBsB,MAAM,CAAC;IACnDC,MAAMtB,MAAC,CAACuB,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["import type { EnrichedExtra } from '@mcp-z/oauth-microsoft';\nimport { schemas } from '@mcp-z/oauth-microsoft';\n\nconst { AuthRequiredBranchSchema } = schemas;\n\nimport type { ToolModule } from '@mcp-z/server';\nimport { type CallToolResult, ProtocolError, ProtocolErrorCode } from '@mcp-z/server';\nimport { Client } from '@microsoft/microsoft-graph-client';\nimport { z } from 'zod';\nimport { CHUNK_SIZE, MAX_BATCH_SIZE } from '../../constants.ts';\n\nconst BatchResultSchema = z.object({\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 inputSchema = z.object({\n ids: z.array(z.coerce.string().trim().min(1)).min(1).describe('Outlook message IDs to move to trash'),\n});\n\n// Success branch schema\nconst successBranchSchema = BatchResultSchema.extend({\n type: z.literal('success'),\n});\n\n// Output schema with auth_required support\nconst outputSchema = z.discriminatedUnion('type', [successBranchSchema, AuthRequiredBranchSchema]);\n\nconst config = {\n description: 'Move Outlook 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): Promise<CallToolResult> {\n const logger = extra.logger;\n logger.info('outlook-message-move-to-trash called', { count: ids.length });\n\n if (!ids || ids.length === 0) {\n logger.info('outlook-message-move-to-trash missing ids');\n throw new ProtocolError(ProtocolErrorCode.InvalidParams, 'Missing ids');\n }\n\n // Validate batch size to prevent memory exhaustion\n if (ids.length > MAX_BATCH_SIZE) {\n logger.info('outlook-message-move-to-trash batch size exceeded', { requested: ids.length, max: MAX_BATCH_SIZE });\n throw new ProtocolError(ProtocolErrorCode.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 Outlook 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 logger.info('outlook-message-move-to-trash found invalid ids', { invalidIds, count: invalidIds.length });\n throw new ProtocolError(ProtocolErrorCode.InvalidParams, `Found ${invalidIds.length} invalid IDs: ${invalidIds.join(', ')}`);\n }\n\n if (validatedIds.length === 0) {\n logger.info('outlook-message-move-to-trash no valid ids after validation');\n throw new ProtocolError(ProtocolErrorCode.InvalidParams, 'No valid IDs found after validation');\n }\n\n try {\n const graph = Client.initWithMiddleware({ authProvider: 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 graph.api(`/me/messages/${encodeURIComponent(id)}`).delete();\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 const result: Output = {\n type: 'success' as const,\n totalRequested: validatedIds.length,\n successCount,\n failureCount,\n results: allResults,\n };\n\n logger.info('outlook-message-move-to-trash completed', {\n totalRequested: validatedIds.length,\n successCount,\n failureCount,\n chunksProcessed: Math.ceil(validatedIds.length / CHUNK_SIZE),\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('outlook-message-move-to-trash error', { error: message });\n\n throw new ProtocolError(ProtocolErrorCode.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","BatchResultSchema","z","object","totalRequested","number","describe","successCount","failureCount","results","array","id","string","success","boolean","error","optional","inputSchema","ids","coerce","trim","min","successBranchSchema","extend","type","literal","outputSchema","discriminatedUnion","config","description","result","handler","extra","logger","validatedIds","invalidIds","trimmedId","graph","allResults","i","message","info","count","length","ProtocolError","ProtocolErrorCode","InvalidParams","MAX_BATCH_SIZE","requested","max","push","includes","join","chunk","chunkResults","processedChunkResults","slice","CHUNK_SIZE","chunkIndex","chunkSize","totalChunks","Math","ceil","Promise","allSettled","map","api","encodeURIComponent","delete","Error","status","errorMessage","reason","String","Client","initWithMiddleware","authProvider","authContext","auth","filter","r","chunksProcessed","content","text","JSON","stringify","structuredContent","InternalError","stack","undefined","name"],"mappings":";;;;+BAiLA;;;eAAwBA;;;8BAhLA;sBAK8C;oCAC/C;mBACL;2BACyB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAN3C,IAAM,AAAEC,2BAA6BC,uBAAO,CAApCD;AAQR,IAAME,oBAAoBC,MAAC,CAACC,MAAM,CAAC;IACjCC,gBAAgBF,MAAC,CAACG,MAAM,GAAGC,QAAQ,CAAC;IACpCC,cAAcL,MAAC,CAACG,MAAM,GAAGC,QAAQ,CAAC;IAClCE,cAAcN,MAAC,CAACG,MAAM,GAAGC,QAAQ,CAAC;IAClCG,SAASP,MAAC,CACPQ,KAAK,CACJR,MAAC,CAACC,MAAM,CAAC;QACPQ,IAAIT,MAAC,CAACU,MAAM,GAAGN,QAAQ,CAAC;QACxBO,SAASX,MAAC,CAACY,OAAO,GAAGR,QAAQ,CAAC;QAC9BS,OAAOb,MAAC,CAACU,MAAM,GAAGI,QAAQ,GAAGV,QAAQ,CAAC;IACxC,IAEDA,QAAQ,CAAC;AACd;AAEA,IAAMW,cAAcf,MAAC,CAACC,MAAM,CAAC;IAC3Be,KAAKhB,MAAC,CAACQ,KAAK,CAACR,MAAC,CAACiB,MAAM,CAACP,MAAM,GAAGQ,IAAI,GAAGC,GAAG,CAAC,IAAIA,GAAG,CAAC,GAAGf,QAAQ,CAAC;AAChE;AAEA,wBAAwB;AACxB,IAAMgB,sBAAsBrB,kBAAkBsB,MAAM,CAAC;IACnDC,MAAMtB,MAAC,CAACuB,OAAO,CAAC;AAClB;AAEA,2CAA2C;AAC3C,IAAMC,eAAexB,MA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,MAAM,AAAD;;;;;;;;;;;;oBAAGJ,KAAKkB,uBAAU;;;;;;oBA2ClDlD,eAAe+B,WAAWyC,MAAM,CAAC,SAACC;+BAAMA,EAAEnE,OAAO;uBAAE8B,MAAM;oBACzDnC,eAAe8B,WAAWyC,MAAM,CAAC,SAACC;+BAAM,CAACA,EAAEnE,OAAO;uBAAE8B,MAAM;oBAE1Db,SAAiB;wBACrBN,MAAM;wBACNpB,gBAAgB8B,aAAaS,MAAM;wBACnCpC,cAAAA;wBACAC,cAAAA;wBACAC,SAAS6B;oBACX;oBAEAL,OAAOQ,IAAI,CAAC,2CAA2C;wBACrDrC,gBAAgB8B,aAAaS,MAAM;wBACnCpC,cAAAA;wBACAC,cAAAA;wBACAyE,iBAAiBpB,KAAKC,IAAI,CAAC5B,aAAaS,MAAM,GAAGc,uBAAU;oBAC7D;oBAEA;;wBAAO;4BACLyB,OAAO;gCACL;oCACE1D,MAAM;oCACN2D,MAAMC,KAAKC,SAAS,CAACvD;gCACvB;;4BAEFwD,mBAAmB;gCAAExD,QAAAA;4BAAO;wBAC9B;;;oBACOf;oBACDyB,UAAUzB,AAAK,YAALA,OAAiBsD,SAAQtD,MAAMyB,OAAO,GAAGiC,OAAO1D;oBAChEkB,OAAOlB,KAAK,CAAC,uCAAuC;wBAAEA,OAAOyB;oBAAQ;oBAErE,MAAM,IAAII,qBAAa,CAACC,yBAAiB,CAAC0C,aAAa,EAAE,AAAC,mCAA0C,OAAR/C,UAAW;wBACrGgD,OAAOzE,AAAK,YAALA,OAAiBsD,SAAQtD,MAAMyE,KAAK,GAAGC;oBAChD;;;;;;;IAEJ;;AAEe,SAAS3F;IACtB,OAAO;QACL4F,MAAM;QACN9D,QAAAA;QACAG,SAAAA;IACF;AACF"}
@@ -1,5 +1,5 @@
1
1
  import type { EnrichedExtra } from '@mcp-z/oauth-microsoft';
2
- import { type CallToolResult } from '@modelcontextprotocol/sdk/types.js';
2
+ import { type CallToolResult } from '@mcp-z/server';
3
3
  import { z } from 'zod';
4
4
  declare const inputSchema: z.ZodObject<{
5
5
  id: z.ZodCoercedString<unknown>;
@@ -1,5 +1,5 @@
1
1
  import type { EnrichedExtra } from '@mcp-z/oauth-microsoft';
2
- import { type CallToolResult } from '@modelcontextprotocol/sdk/types.js';
2
+ import { type CallToolResult } from '@mcp-z/server';
3
3
  import { z } from 'zod';
4
4
  declare const inputSchema: z.ZodObject<{
5
5
  id: z.ZodCoercedString<unknown>;
@@ -10,8 +10,8 @@ Object.defineProperty(exports, "default", {
10
10
  });
11
11
  var _email = require("@mcp-z/email");
12
12
  var _oauthmicrosoft = require("@mcp-z/oauth-microsoft");
13
+ var _server = require("@mcp-z/server");
13
14
  var _microsoftgraphclient = require("@microsoft/microsoft-graph-client");
14
- var _types = require("@modelcontextprotocol/sdk/types.js");
15
15
  var _zod = require("zod");
16
16
  function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) {
17
17
  try {
@@ -184,7 +184,7 @@ function handler(_0, _1) {
184
184
  });
185
185
  if (!id || !body) {
186
186
  logger.info('outlook.respond missing id or body');
187
- throw new _types.McpError(_types.ErrorCode.InvalidParams, 'Missing id or body');
187
+ throw new _server.ProtocolError(_server.ProtocolErrorCode.InvalidParams, 'Missing id or body');
188
188
  }
189
189
  _state.label = 1;
190
190
  case 1:
@@ -238,7 +238,7 @@ function handler(_0, _1) {
238
238
  logger.error('outlook.respond error', {
239
239
  error: message
240
240
  });
241
- throw new _types.McpError(_types.ErrorCode.InternalError, "Error replying to message: ".concat(message), {
241
+ throw new _server.ProtocolError(_server.ProtocolErrorCode.InternalError, "Error replying to message: ".concat(message), {
242
242
  stack: _instanceof(error, Error) ? error.stack : undefined
243
243
  });
244
244
  case 4:
@@ -1 +1 @@
1
- {"version":3,"sources":["/Users/kevin/Dev/OpenSource/ai/mcp-z/mcp-outlook/src/mcp/tools/message-respond.ts"],"sourcesContent":["import { ComposeContentTypeSchema } from '@mcp-z/email';\nimport type { EnrichedExtra } from '@mcp-z/oauth-microsoft';\nimport { schemas } from '@mcp-z/oauth-microsoft';\n\nconst { AuthRequiredBranchSchema } = schemas;\n\nimport type { ToolModule } from '@mcp-z/server';\nimport { Client } from '@microsoft/microsoft-graph-client';\nimport { type CallToolResult, ErrorCode, McpError } from '@modelcontextprotocol/sdk/types.js';\nimport { z } from 'zod';\n\nconst SuccessSchema = z.object({\n success: z.boolean().describe('Whether the reply was sent successfully'),\n id: z.string().optional().describe('Original message ID that was replied to'),\n});\n\nconst inputSchema = z.object({\n id: z.coerce.string().trim().min(1).describe('Outlook 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\n// Success branch schema\nconst successBranchSchema = SuccessSchema.extend({\n type: z.literal('success'),\n});\n\n// Output schema with auth_required support\nconst outputSchema = z.discriminatedUnion('type', [successBranchSchema, AuthRequiredBranchSchema]);\n\nconst config = {\n description: 'Reply to an Outlook 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): Promise<CallToolResult> {\n const logger = extra.logger;\n logger.info('outlook.respond called', { id, hasBody: !!body });\n\n if (!id || !body) {\n logger.info('outlook.respond missing id or body');\n throw new McpError(ErrorCode.InvalidParams, 'Missing id or body');\n }\n\n try {\n const graph = Client.initWithMiddleware({ authProvider: extra.authContext.auth });\n await graph.api(`/me/messages/${encodeURIComponent(id)}/reply`).post({ message: { body: { contentType: contentType === 'html' ? 'HTML' : 'Text', content: body } } });\n\n logger.info('outlook.respond success', { id });\n\n const result: Output = {\n type: 'success' as const,\n success: true,\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('outlook.respond error', { error: message });\n\n throw new McpError(ErrorCode.InternalError, `Error replying 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","SuccessSchema","z","object","success","boolean","describe","id","string","optional","inputSchema","coerce","trim","min","body","contentType","ComposeContentTypeSchema","successBranchSchema","extend","type","literal","outputSchema","discriminatedUnion","config","description","result","handler","extra","logger","graph","error","message","info","hasBody","McpError","ErrorCode","InvalidParams","Client","initWithMiddleware","authProvider","authContext","auth","api","encodeURIComponent","post","content","text","JSON","stringify","structuredContent","Error","String","InternalError","stack","undefined","name"],"mappings":";;;;+BAiFA;;;eAAwBA;;;qBAjFiB;8BAEjB;oCAKD;qBACkC;mBACvC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AALlB,IAAM,AAAEC,2BAA6BC,uBAAO,CAApCD;AAOR,IAAME,gBAAgBC,MAAC,CAACC,MAAM,CAAC;IAC7BC,SAASF,MAAC,CAACG,OAAO,GAAGC,QAAQ,CAAC;IAC9BC,IAAIL,MAAC,CAACM,MAAM,GAAGC,QAAQ,GAAGH,QAAQ,CAAC;AACrC;AAEA,IAAMI,cAAcR,MAAC,CAACC,MAAM,CAAC;IAC3BI,IAAIL,MAAC,CAACS,MAAM,CAACH,MAAM,GAAGI,IAAI,GAAGC,GAAG,CAAC,GAAGP,QAAQ,CAAC;IAC7CQ,MAAMZ,MAAC,CAACS,MAAM,CAACH,MAAM,GAAGI,IAAI,GAAGC,GAAG,CAAC,GAAGP,QAAQ,CAAC;IAC/CS,aAAaC,+BAAwB;AACvC;AAEA,wBAAwB;AACxB,IAAMC,sBAAsBhB,cAAciB,MAAM,CAAC;IAC/CC,MAAMjB,MAAC,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BAAO;wBAC9B;;;oBACOK;oBACDC,UAAUD,AAAK,YAALA,OAAiBoB,SAAQpB,MAAMC,OAAO,GAAGoB,OAAOrB;oBAChEF,OAAOE,KAAK,CAAC,yBAAyB;wBAAEA,OAAOC;oBAAQ;oBAEvD,MAAM,IAAIG,eAAQ,CAACC,gBAAS,CAACiB,aAAa,EAAE,AAAC,8BAAqC,OAARrB,UAAW;wBACnFsB,OAAOvB,AAAK,YAALA,OAAiBoB,SAAQpB,MAAMuB,KAAK,GAAGC;oBAChD;;;;;;;IAEJ;;AAEe,SAASxD;IACtB,OAAO;QACLyD,MAAM;QACNhC,QAAAA;QACAG,SAAAA;IACF;AACF"}
1
+ {"version":3,"sources":["/Users/kevin/Dev/OpenSource/ai/mcp-z/mcp-outlook/src/mcp/tools/message-respond.ts"],"sourcesContent":["import { ComposeContentTypeSchema } from '@mcp-z/email';\nimport type { EnrichedExtra } from '@mcp-z/oauth-microsoft';\nimport { schemas } from '@mcp-z/oauth-microsoft';\n\nconst { AuthRequiredBranchSchema } = schemas;\n\nimport type { ToolModule } from '@mcp-z/server';\nimport { type CallToolResult, ProtocolError, ProtocolErrorCode } from '@mcp-z/server';\nimport { Client } from '@microsoft/microsoft-graph-client';\nimport { z } from 'zod';\n\nconst SuccessSchema = z.object({\n success: z.boolean().describe('Whether the reply was sent successfully'),\n id: z.string().optional().describe('Original message ID that was replied to'),\n});\n\nconst inputSchema = z.object({\n id: z.coerce.string().trim().min(1).describe('Outlook 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\n// Success branch schema\nconst successBranchSchema = SuccessSchema.extend({\n type: z.literal('success'),\n});\n\n// Output schema with auth_required support\nconst outputSchema = z.discriminatedUnion('type', [successBranchSchema, AuthRequiredBranchSchema]);\n\nconst config = {\n description: 'Reply to an Outlook 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): Promise<CallToolResult> {\n const logger = extra.logger;\n logger.info('outlook.respond called', { id, hasBody: !!body });\n\n if (!id || !body) {\n logger.info('outlook.respond missing id or body');\n throw new ProtocolError(ProtocolErrorCode.InvalidParams, 'Missing id or body');\n }\n\n try {\n const graph = Client.initWithMiddleware({ authProvider: extra.authContext.auth });\n await graph.api(`/me/messages/${encodeURIComponent(id)}/reply`).post({ message: { body: { contentType: contentType === 'html' ? 'HTML' : 'Text', content: body } } });\n\n logger.info('outlook.respond success', { id });\n\n const result: Output = {\n type: 'success' as const,\n success: true,\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('outlook.respond error', { error: message });\n\n throw new ProtocolError(ProtocolErrorCode.InternalError, `Error replying 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","SuccessSchema","z","object","success","boolean","describe","id","string","optional","inputSchema","coerce","trim","min","body","contentType","ComposeContentTypeSchema","successBranchSchema","extend","type","literal","outputSchema","discriminatedUnion","config","description","result","handler","extra","logger","graph","error","message","info","hasBody","ProtocolError","ProtocolErrorCode","InvalidParams","Client","initWithMiddleware","authProvider","authContext","auth","api","encodeURIComponent","post","content","text","JSON","stringify","structuredContent","Error","String","InternalError","stack","undefined","name"],"mappings":";;;;+BAiFA;;;eAAwBA;;;qBAjFiB;8BAEjB;sBAK8C;oCAC/C;mBACL;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;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,CAACC,aAAa,EAAE;oBAC3D;;;;;;;;;oBAGQP,QAAQQ,4BAAM,CAACC,kBAAkB,CAAC;wBAAEC,cAAcZ,MAAMa,WAAW,CAACC,IAAI;oBAAC;oBAC/E;;wBAAMZ,MAAMa,GAAG,CAAC,AAAC,gBAAsC,OAAvBC,mBAAmBpC,KAAI,WAASqC,IAAI,CAAC;4BAAEb,SAAS;gCAAEjB,MAAM;oCAAEC,aAAaA,gBAAgB,SAAS,SAAS;oCAAQ8B,SAAS/B;gCAAK;4BAAE;wBAAE;;;oBAAnK;oBAEAc,OAAOI,IAAI,CAAC,2BAA2B;wBAAEzB,IAAAA;oBAAG;oBAEtCkB,SAAiB;wBACrBN,MAAM;wBACNf,SAAS;wBACTG,IAAAA;oBACF;oBAEA;;wBAAO;4BACLsC,OAAO;gCACL;oCACE1B,MAAM;oCACN2B,MAAMC,KAAKC,SAAS,CAACvB;gCACvB;;4BAEFwB,mBAAmB;gCAAExB,QAAAA;4BAAO;wBAC9B;;;oBACOK;oBACDC,UAAUD,AAAK,YAALA,OAAiBoB,SAAQpB,MAAMC,OAAO,GAAGoB,OAAOrB;oBAChEF,OAAOE,KAAK,CAAC,yBAAyB;wBAAEA,OAAOC;oBAAQ;oBAEvD,MAAM,IAAIG,qBAAa,CAACC,yBAAiB,CAACiB,aAAa,EAAE,AAAC,8BAAqC,OAARrB,UAAW;wBAChGsB,OAAOvB,AAAK,YAALA,OAAiBoB,SAAQpB,MAAMuB,KAAK,GAAGC;oBAChD;;;;;;;IAEJ;;AAEe,SAASxD;IACtB,OAAO;QACLyD,MAAM;QACNhC,QAAAA;QACAG,SAAAA;IACF;AACF"}
@@ -1,5 +1,5 @@
1
1
  import type { EnrichedExtra } from '@mcp-z/oauth-microsoft';
2
- import { type CallToolResult } from '@modelcontextprotocol/sdk/types.js';
2
+ import { type CallToolResult } from '@mcp-z/server';
3
3
  import { z } from 'zod';
4
4
  declare const inputSchema: z.ZodObject<{
5
5
  shape: z.ZodDefault<z.ZodOptional<z.ZodEnum<{
@@ -1,5 +1,5 @@
1
1
  import type { EnrichedExtra } from '@mcp-z/oauth-microsoft';
2
- import { type CallToolResult } from '@modelcontextprotocol/sdk/types.js';
2
+ import { type CallToolResult } from '@mcp-z/server';
3
3
  import { z } from 'zod';
4
4
  declare const inputSchema: z.ZodObject<{
5
5
  shape: z.ZodDefault<z.ZodOptional<z.ZodEnum<{
@@ -12,7 +12,6 @@ var _email = require("@mcp-z/email");
12
12
  var _oauthmicrosoft = require("@mcp-z/oauth-microsoft");
13
13
  var _server = require("@mcp-z/server");
14
14
  var _microsoftgraphclient = require("@microsoft/microsoft-graph-client");
15
- var _types = require("@modelcontextprotocol/sdk/types.js");
16
15
  var _zod = require("zod");
17
16
  var _clientfilterts = require("../../email/querying/client-filter.js");
18
17
  var _executequeryts = require("../../email/querying/execute-query.js");
@@ -383,7 +382,7 @@ function handler(_0, _1) {
383
382
  logger.error('outlook.message.search error', {
384
383
  error: message
385
384
  });
386
- throw new _types.McpError(_types.ErrorCode.InternalError, "Error searching messages: ".concat(message), {
385
+ throw new _server.ProtocolError(_server.ProtocolErrorCode.InternalError, "Error searching messages: ".concat(message), {
387
386
  stack: _instanceof(error, Error) ? error.stack : undefined
388
387
  });
389
388
  case 4:
@@ -1 +1 @@
1
- {"version":3,"sources":["/Users/kevin/Dev/OpenSource/ai/mcp-z/mcp-outlook/src/mcp/tools/message-search.ts"],"sourcesContent":["import { EMAIL_COMMON_PATTERNS, EMAIL_FIELD_DESCRIPTIONS, EMAIL_FIELDS, EmailContentTypeSchema, type EmailDetail, EmailDetailSchema, ExcludeThreadHistorySchema, extractCurrentMessageFromHtml, extractCurrentMessageFromHtmlToText } from '@mcp-z/email';\nimport type { EnrichedExtra } from '@mcp-z/oauth-microsoft';\nimport { schemas } from '@mcp-z/oauth-microsoft';\n\nconst { AuthRequiredBranchSchema } = schemas;\n\nimport { createFieldsSchema, createPaginationSchema, createShapeSchema, filterFields, parseFields, type ToolModule, toColumnarFormat } from '@mcp-z/server';\nimport { Client } from '@microsoft/microsoft-graph-client';\nimport type * as MicrosoftGraph from '@microsoft/microsoft-graph-types';\nimport { type CallToolResult, ErrorCode, McpError } from '@modelcontextprotocol/sdk/types.js';\nimport { z } from 'zod';\nimport { needsBody } from '../../email/querying/client-filter.ts';\nimport { executeQuery as executeOutlookQuery } from '../../email/querying/execute-query.ts';\nimport { OutlookQueryParameterSchema, parseOutlookQueryParameter } from '../../schemas/outlook-query-schema.ts';\n\nconst inputSchema = z.object({\n query: OutlookQueryParameterSchema.optional().describe('Structured query object or JSON string for filtering messages. Use query-syntax prompt for reference and kqlQuery for KQL syntax.'),\n fields: createFieldsSchema({\n availableFields: EMAIL_FIELDS,\n fieldDescriptions: EMAIL_FIELD_DESCRIPTIONS,\n commonPatterns: EMAIL_COMMON_PATTERNS,\n resourceName: 'email message',\n }),\n ...createPaginationSchema({\n defaultPageSize: 50,\n maxPageSize: 500,\n provider: 'outlook',\n }).shape,\n shape: createShapeSchema(),\n contentType: EmailContentTypeSchema,\n excludeThreadHistory: ExcludeThreadHistorySchema,\n});\n\n// Success branch schemas for different shapes\nconst successObjectsBranchSchema = z.object({\n type: z.literal('success'),\n shape: z.literal('objects'),\n items: z.array(EmailDetailSchema).describe('Matching email messages'),\n nextPageToken: z.string().optional().describe('Token for fetching next page of results'),\n});\n\nconst successArraysBranchSchema = z.object({\n type: z.literal('success'),\n shape: z.literal('arrays'),\n columns: z.array(z.string()).describe('Column names in canonical order'),\n rows: z.array(z.array(z.unknown())).describe('Row data matching column order'),\n nextPageToken: z.string().optional().describe('Token for fetching next page of results'),\n});\n\n// Output schema with auth_required support\n// Using z.union instead of discriminatedUnion since we have two success branches with different shapes\nconst outputSchema = z.union([successObjectsBranchSchema, successArraysBranchSchema, AuthRequiredBranchSchema]);\n\nconst config = {\n description: 'Search Outlook messages using structured query objects 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({ query, pageSize = 50, pageToken, fields, shape = 'arrays', contentType, excludeThreadHistory }: Input, extra: EnrichedExtra): Promise<CallToolResult> {\n const logger = extra.logger;\n\n try {\n const parsedQuery = parseOutlookQueryParameter(query);\n const requestedFields = parseFields(fields, EMAIL_FIELDS);\n const needsBodyContent = needsBody(parsedQuery);\n const includeBody = requestedFields === 'all' || requestedFields.has('body') || needsBodyContent;\n\n logger.info('outlook.search called with', {\n query: parsedQuery,\n pageSize,\n pageToken: pageToken ? '[provided]' : undefined,\n fields: fields || 'all',\n includeBody,\n });\n\n const graph = Client.initWithMiddleware({\n authProvider: extra.authContext.auth,\n });\n const started = Date.now();\n const exec = await executeOutlookQuery(\n graph,\n parsedQuery,\n {\n logger,\n pageSize,\n ...(pageToken ? { pageToken } : {}),\n includeBody,\n limit: pageSize,\n },\n (m: unknown) => {\n const message = m as MicrosoftGraph.Message;\n const to = Array.isArray(message?.toRecipients)\n ? message.toRecipients\n .map((r: MicrosoftGraph.Recipient) => r?.emailAddress?.address)\n .filter(Boolean)\n .join(', ')\n : undefined;\n const cc = Array.isArray(message?.ccRecipients)\n ? message.ccRecipients\n .map((r: MicrosoftGraph.Recipient) => r?.emailAddress?.address)\n .filter(Boolean)\n .join(', ')\n : undefined;\n const bcc = Array.isArray(message?.bccRecipients)\n ? message.bccRecipients\n .map((r: MicrosoftGraph.Recipient) => r?.emailAddress?.address)\n .filter(Boolean)\n .join(', ')\n : undefined;\n const fromAddr = message?.from?.emailAddress?.address ?? null;\n const fromName = message?.from?.emailAddress?.name ?? null;\n // Process body based on contentType and excludeThreadHistory options\n let bodyContent: string | undefined;\n if (includeBody && message?.body?.content) {\n const isHtml = message.body.contentType?.toLowerCase() === 'html';\n bodyContent = message.body.content;\n\n if (isHtml && excludeThreadHistory) {\n bodyContent = extractCurrentMessageFromHtml(bodyContent);\n }\n\n if (isHtml && contentType === 'text') {\n bodyContent = excludeThreadHistory ? extractCurrentMessageFromHtmlToText(bodyContent) : extractCurrentMessageFromHtmlToText(message.body.content);\n }\n }\n\n const mapped: Partial<EmailDetail> = {\n id: message?.id ?? undefined,\n subject: message?.subject ?? undefined,\n from: fromAddr ?? undefined,\n fromName: fromName ?? undefined,\n to,\n cc,\n bcc,\n date: message?.receivedDateTime ?? undefined,\n snippet: message?.bodyPreview ?? undefined,\n ...(bodyContent && { body: bodyContent, bodyContentType: contentType }),\n };\n return mapped;\n }\n );\n const durationMs = Date.now() - started;\n\n const filteredItems = exec.items.map((item) => filterFields(item, requestedFields));\n logger.info('outlook.message.search returning', {\n query,\n pageSize,\n itemsLength: filteredItems.length,\n fields: fields || 'all',\n });\n logger.info('outlook.message.search metrics', {\n durationMs,\n metadata: exec.metadata,\n });\n\n // Type-safe metadata access\n const metadataObj = exec.metadata as { nextPageToken?: string } | undefined;\n\n // Build result based on shape\n const result: Output =\n shape === 'arrays'\n ? {\n type: 'success' as const,\n shape: 'arrays' as const,\n ...toColumnarFormat(filteredItems, requestedFields, EMAIL_FIELDS),\n ...(metadataObj?.nextPageToken && { nextPageToken: metadataObj.nextPageToken }),\n }\n : {\n type: 'success' as const,\n shape: 'objects' as const,\n items: filteredItems,\n ...(metadataObj?.nextPageToken && { nextPageToken: metadataObj.nextPageToken }),\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('outlook.message.search error', { error: message });\n\n throw new McpError(ErrorCode.InternalError, `Error searching messages: ${message}`, {\n stack: error instanceof Error ? error.stack : undefined,\n });\n }\n}\n\nexport default function createTool() {\n return {\n name: 'message-search',\n config,\n handler,\n } satisfies ToolModule;\n}\n"],"names":["createTool","AuthRequiredBranchSchema","schemas","inputSchema","z","object","query","OutlookQueryParameterSchema","optional","describe","fields","createFieldsSchema","availableFields","EMAIL_FIELDS","fieldDescriptions","EMAIL_FIELD_DESCRIPTIONS","commonPatterns","EMAIL_COMMON_PATTERNS","resourceName","createPaginationSchema","defaultPageSize","maxPageSize","provider","shape","createShapeSchema","contentType","EmailContentTypeSchema","excludeThreadHistory","ExcludeThreadHistorySchema","successObjectsBranchSchema","type","literal","items","array","EmailDetailSchema","nextPageToken","string","successArraysBranchSchema","columns","rows","unknown","outputSchema","union","config","description","result","handler","extra","pageSize","pageToken","logger","parsedQuery","requestedFields","needsBodyContent","includeBody","graph","started","exec","durationMs","filteredItems","metadataObj","error","message","parseOutlookQueryParameter","parseFields","needsBody","has","info","undefined","Client","initWithMiddleware","authProvider","authContext","auth","Date","now","executeOutlookQuery","limit","m","to","Array","isArray","toRecipients","map","r","emailAddress","address","filter","Boolean","join","cc","ccRecipients","bcc","bccRecipients","fromAddr","from","fromName","name","bodyContent","body","content","isHtml","toLowerCase","extractCurrentMessageFromHtml","extractCurrentMessageFromHtmlToText","mapped","id","subject","date","receivedDateTime","snippet","bodyPreview","bodyContentType","item","filterFields","itemsLength","length","metadata","toColumnarFormat","text","JSON","stringify","structuredContent","Error","String","McpError","ErrorCode","InternalError","stack"],"mappings":";;;;+BAuMA;;;eAAwBA;;;qBAvMmN;8BAEnN;sBAIoH;oCACrH;qBAEkC;mBACvC;8BACQ;8BAC0B;oCACoB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AATxE,IAAM,AAAEC,2BAA6BC,uBAAO,CAApCD;AAWR,IAAME,cAAcC,MAAC,CAACC,MAAM,CAAC;IAC3BC,OAAOC,iDAA2B,CAACC,QAAQ,GAAGC,QAAQ,CAAC;IACvDC,QAAQC,IAAAA,0BAAkB,EAAC;QACzBC,iBAAiBC,mBAAY;QAC7BC,mBAAmBC,+BAA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,eAAeP,iBAAiBvC,mBAAY,GAC5D+C,CAAAA,wBAAAA,kCAAAA,YAAazB,aAAa,KAAI;wBAAEA,eAAeyB,YAAYzB,aAAa;oBAAC,KAE/E;wBACEL,MAAM;wBACNP,OAAO;wBACPS,OAAO2B;uBACHC,CAAAA,wBAAAA,kCAAAA,YAAazB,aAAa,KAAI;wBAAEA,eAAeyB,YAAYzB,aAAa;oBAAC;oBAGrF;;wBAAO;4BACLiE,OAAO;gCACL;oCACEtE,MAAM;oCACNyF,MAAMC,KAAKC,SAAS,CAAC5E;gCACvB;;4BAEF6E,mBAAmB;gCAAE7E,QAAAA;4BAAO;wBAC9B;;;oBACOgB;oBACDC,UAAUD,AAAK,YAALA,OAAiB8D,SAAQ9D,MAAMC,OAAO,GAAG8D,OAAO/D;oBAChEX,OAAOW,KAAK,CAAC,gCAAgC;wBAAEA,OAAOC;oBAAQ;oBAE9D,MAAM,IAAI+D,eAAQ,CAACC,gBAAS,CAACC,aAAa,EAAE,AAAC,6BAAoC,OAARjE,UAAW;wBAClFkE,OAAOnE,AAAK,YAALA,OAAiB8D,SAAQ9D,MAAMmE,KAAK,GAAG5D;oBAChD;;;;;;;IAEJ;;AAEe,SAASpE;IACtB,OAAO;QACLiG,MAAM;QACNtD,QAAAA;QACAG,SAAAA;IACF;AACF"}
1
+ {"version":3,"sources":["/Users/kevin/Dev/OpenSource/ai/mcp-z/mcp-outlook/src/mcp/tools/message-search.ts"],"sourcesContent":["import { EMAIL_COMMON_PATTERNS, EMAIL_FIELD_DESCRIPTIONS, EMAIL_FIELDS, EmailContentTypeSchema, type EmailDetail, EmailDetailSchema, ExcludeThreadHistorySchema, extractCurrentMessageFromHtml, extractCurrentMessageFromHtmlToText } from '@mcp-z/email';\nimport type { EnrichedExtra } from '@mcp-z/oauth-microsoft';\nimport { schemas } from '@mcp-z/oauth-microsoft';\n\nconst { AuthRequiredBranchSchema } = schemas;\n\nimport { type CallToolResult, createFieldsSchema, createPaginationSchema, createShapeSchema, filterFields, ProtocolError, ProtocolErrorCode, parseFields, type ToolModule, toColumnarFormat } from '@mcp-z/server';\nimport { Client } from '@microsoft/microsoft-graph-client';\nimport type * as MicrosoftGraph from '@microsoft/microsoft-graph-types';\nimport { z } from 'zod';\nimport { needsBody } from '../../email/querying/client-filter.ts';\nimport { executeQuery as executeOutlookQuery } from '../../email/querying/execute-query.ts';\nimport { OutlookQueryParameterSchema, parseOutlookQueryParameter } from '../../schemas/outlook-query-schema.ts';\n\nconst inputSchema = z.object({\n query: OutlookQueryParameterSchema.optional().describe('Structured query object or JSON string for filtering messages. Use query-syntax prompt for reference and kqlQuery for KQL syntax.'),\n fields: createFieldsSchema({\n availableFields: EMAIL_FIELDS,\n fieldDescriptions: EMAIL_FIELD_DESCRIPTIONS,\n commonPatterns: EMAIL_COMMON_PATTERNS,\n resourceName: 'email message',\n }),\n ...createPaginationSchema({\n defaultPageSize: 50,\n maxPageSize: 500,\n provider: 'outlook',\n }).shape,\n shape: createShapeSchema(),\n contentType: EmailContentTypeSchema,\n excludeThreadHistory: ExcludeThreadHistorySchema,\n});\n\n// Success branch schemas for different shapes\nconst successObjectsBranchSchema = z.object({\n type: z.literal('success'),\n shape: z.literal('objects'),\n items: z.array(EmailDetailSchema).describe('Matching email messages'),\n nextPageToken: z.string().optional().describe('Token for fetching next page of results'),\n});\n\nconst successArraysBranchSchema = z.object({\n type: z.literal('success'),\n shape: z.literal('arrays'),\n columns: z.array(z.string()).describe('Column names in canonical order'),\n rows: z.array(z.array(z.unknown())).describe('Row data matching column order'),\n nextPageToken: z.string().optional().describe('Token for fetching next page of results'),\n});\n\n// Output schema with auth_required support\n// Using z.union instead of discriminatedUnion since we have two success branches with different shapes\nconst outputSchema = z.union([successObjectsBranchSchema, successArraysBranchSchema, AuthRequiredBranchSchema]);\n\nconst config = {\n description: 'Search Outlook messages using structured query objects 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({ query, pageSize = 50, pageToken, fields, shape = 'arrays', contentType, excludeThreadHistory }: Input, extra: EnrichedExtra): Promise<CallToolResult> {\n const logger = extra.logger;\n\n try {\n const parsedQuery = parseOutlookQueryParameter(query);\n const requestedFields = parseFields(fields, EMAIL_FIELDS);\n const needsBodyContent = needsBody(parsedQuery);\n const includeBody = requestedFields === 'all' || requestedFields.has('body') || needsBodyContent;\n\n logger.info('outlook.search called with', {\n query: parsedQuery,\n pageSize,\n pageToken: pageToken ? '[provided]' : undefined,\n fields: fields || 'all',\n includeBody,\n });\n\n const graph = Client.initWithMiddleware({\n authProvider: extra.authContext.auth,\n });\n const started = Date.now();\n const exec = await executeOutlookQuery(\n graph,\n parsedQuery,\n {\n logger,\n pageSize,\n ...(pageToken ? { pageToken } : {}),\n includeBody,\n limit: pageSize,\n },\n (m: unknown) => {\n const message = m as MicrosoftGraph.Message;\n const to = Array.isArray(message?.toRecipients)\n ? message.toRecipients\n .map((r: MicrosoftGraph.Recipient) => r?.emailAddress?.address)\n .filter(Boolean)\n .join(', ')\n : undefined;\n const cc = Array.isArray(message?.ccRecipients)\n ? message.ccRecipients\n .map((r: MicrosoftGraph.Recipient) => r?.emailAddress?.address)\n .filter(Boolean)\n .join(', ')\n : undefined;\n const bcc = Array.isArray(message?.bccRecipients)\n ? message.bccRecipients\n .map((r: MicrosoftGraph.Recipient) => r?.emailAddress?.address)\n .filter(Boolean)\n .join(', ')\n : undefined;\n const fromAddr = message?.from?.emailAddress?.address ?? null;\n const fromName = message?.from?.emailAddress?.name ?? null;\n // Process body based on contentType and excludeThreadHistory options\n let bodyContent: string | undefined;\n if (includeBody && message?.body?.content) {\n const isHtml = message.body.contentType?.toLowerCase() === 'html';\n bodyContent = message.body.content;\n\n if (isHtml && excludeThreadHistory) {\n bodyContent = extractCurrentMessageFromHtml(bodyContent);\n }\n\n if (isHtml && contentType === 'text') {\n bodyContent = excludeThreadHistory ? extractCurrentMessageFromHtmlToText(bodyContent) : extractCurrentMessageFromHtmlToText(message.body.content);\n }\n }\n\n const mapped: Partial<EmailDetail> = {\n id: message?.id ?? undefined,\n subject: message?.subject ?? undefined,\n from: fromAddr ?? undefined,\n fromName: fromName ?? undefined,\n to,\n cc,\n bcc,\n date: message?.receivedDateTime ?? undefined,\n snippet: message?.bodyPreview ?? undefined,\n ...(bodyContent && { body: bodyContent, bodyContentType: contentType }),\n };\n return mapped;\n }\n );\n const durationMs = Date.now() - started;\n\n const filteredItems = exec.items.map((item) => filterFields(item, requestedFields));\n logger.info('outlook.message.search returning', {\n query,\n pageSize,\n itemsLength: filteredItems.length,\n fields: fields || 'all',\n });\n logger.info('outlook.message.search metrics', {\n durationMs,\n metadata: exec.metadata,\n });\n\n // Type-safe metadata access\n const metadataObj = exec.metadata as { nextPageToken?: string } | undefined;\n\n // Build result based on shape\n const result: Output =\n shape === 'arrays'\n ? {\n type: 'success' as const,\n shape: 'arrays' as const,\n ...toColumnarFormat(filteredItems, requestedFields, EMAIL_FIELDS),\n ...(metadataObj?.nextPageToken && { nextPageToken: metadataObj.nextPageToken }),\n }\n : {\n type: 'success' as const,\n shape: 'objects' as const,\n items: filteredItems,\n ...(metadataObj?.nextPageToken && { nextPageToken: metadataObj.nextPageToken }),\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('outlook.message.search error', { error: message });\n\n throw new ProtocolError(ProtocolErrorCode.InternalError, `Error searching messages: ${message}`, {\n stack: error instanceof Error ? error.stack : undefined,\n });\n }\n}\n\nexport default function createTool() {\n return {\n name: 'message-search',\n config,\n handler,\n } satisfies ToolModule;\n}\n"],"names":["createTool","AuthRequiredBranchSchema","schemas","inputSchema","z","object","query","OutlookQueryParameterSchema","optional","describe","fields","createFieldsSchema","availableFields","EMAIL_FIELDS","fieldDescriptions","EMAIL_FIELD_DESCRIPTIONS","commonPatterns","EMAIL_COMMON_PATTERNS","resourceName","createPaginationSchema","defaultPageSize","maxPageSize","provider","shape","createShapeSchema","contentType","EmailContentTypeSchema","excludeThreadHistory","ExcludeThreadHistorySchema","successObjectsBranchSchema","type","literal","items","array","EmailDetailSchema","nextPageToken","string","successArraysBranchSchema","columns","rows","unknown","outputSchema","union","config","description","result","handler","extra","pageSize","pageToken","logger","parsedQuery","requestedFields","needsBodyContent","includeBody","graph","started","exec","durationMs","filteredItems","metadataObj","error","message","parseOutlookQueryParameter","parseFields","needsBody","has","info","undefined","Client","initWithMiddleware","authProvider","authContext","auth","Date","now","executeOutlookQuery","limit","m","to","Array","isArray","toRecipients","map","r","emailAddress","address","filter","Boolean","join","cc","ccRecipients","bcc","bccRecipients","fromAddr","from","fromName","name","bodyContent","body","content","isHtml","toLowerCase","extractCurrentMessageFromHtml","extractCurrentMessageFromHtmlToText","mapped","id","subject","date","receivedDateTime","snippet","bodyPreview","bodyContentType","item","filterFields","itemsLength","length","metadata","toColumnarFormat","text","JSON","stringify","structuredContent","Error","String","ProtocolError","ProtocolErrorCode","InternalError","stack"],"mappings":";;;;+BAsMA;;;eAAwBA;;;qBAtMmN;8BAEnN;sBAI2K;oCAC5K;mBAEL;8BACQ;8BAC0B;oCACoB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AARxE,IAAM,AAAEC,2BAA6BC,uBAAO,CAApCD;AAUR,IAAME,cAAcC,MAAC,CAACC,MAAM,CAAC;IAC3BC,OAAOC,iDAA2B,CAACC,QAAQ,GAAGC,QAAQ,CAAC;IACvDC,QAAQC,IAAAA,0BAAkB,EAAC;QACzBC,iBAAiBC,mBAAY;QAC7BC,mBAAm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,EAAC3D,eAAeP,iBAAiBvC,mBAAY,GAC5D+C,CAAAA,wBAAAA,kCAAAA,YAAazB,aAAa,KAAI;wBAAEA,eAAeyB,YAAYzB,aAAa;oBAAC,KAE/E;wBACEL,MAAM;wBACNP,OAAO;wBACPS,OAAO2B;uBACHC,CAAAA,wBAAAA,kCAAAA,YAAazB,aAAa,KAAI;wBAAEA,eAAeyB,YAAYzB,aAAa;oBAAC;oBAGrF;;wBAAO;4BACLiE,OAAO;gCACL;oCACEtE,MAAM;oCACNyF,MAAMC,KAAKC,SAAS,CAAC5E;gCACvB;;4BAEF6E,mBAAmB;gCAAE7E,QAAAA;4BAAO;wBAC9B;;;oBACOgB;oBACDC,UAAUD,AAAK,YAALA,OAAiB8D,SAAQ9D,MAAMC,OAAO,GAAG8D,OAAO/D;oBAChEX,OAAOW,KAAK,CAAC,gCAAgC;wBAAEA,OAAOC;oBAAQ;oBAE9D,MAAM,IAAI+D,qBAAa,CAACC,yBAAiB,CAACC,aAAa,EAAE,AAAC,6BAAoC,OAARjE,UAAW;wBAC/FkE,OAAOnE,AAAK,YAALA,OAAiB8D,SAAQ9D,MAAMmE,KAAK,GAAG5D;oBAChD;;;;;;;IAEJ;;AAEe,SAASpE;IACtB,OAAO;QACLiG,MAAM;QACNtD,QAAAA;QACAG,SAAAA;IACF;AACF"}
@@ -1,5 +1,5 @@
1
1
  import type { EnrichedExtra } from '@mcp-z/oauth-microsoft';
2
- import { type CallToolResult } from '@modelcontextprotocol/sdk/types.js';
2
+ import { type CallToolResult } from '@mcp-z/server';
3
3
  import { z } from 'zod';
4
4
  declare const inputSchema: z.ZodObject<{
5
5
  to: z.ZodString | z.ZodOptional<z.ZodString>;
@@ -1,5 +1,5 @@
1
1
  import type { EnrichedExtra } from '@mcp-z/oauth-microsoft';
2
- import { type CallToolResult } from '@modelcontextprotocol/sdk/types.js';
2
+ import { type CallToolResult } from '@mcp-z/server';
3
3
  import { z } from 'zod';
4
4
  declare const inputSchema: z.ZodObject<{
5
5
  to: z.ZodString | z.ZodOptional<z.ZodString>;
@@ -10,8 +10,8 @@ Object.defineProperty(exports, "default", {
10
10
  });
11
11
  var _email = require("@mcp-z/email");
12
12
  var _oauthmicrosoft = require("@mcp-z/oauth-microsoft");
13
+ var _server = require("@mcp-z/server");
13
14
  var _microsoftgraphclient = require("@microsoft/microsoft-graph-client");
14
- var _types = require("@modelcontextprotocol/sdk/types.js");
15
15
  var _zod = require("zod");
16
16
  var _outlookmessagebuilderts = require("../../email/composition/outlook-message-builder.js");
17
17
  function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) {
@@ -223,7 +223,7 @@ function handler(_0, _1) {
223
223
  messageId = draft.id;
224
224
  if (!messageId) {
225
225
  logger.error('outlook.message.send draft creation failed - no ID returned');
226
- throw new _types.McpError(_types.ErrorCode.InternalError, 'Failed to create draft message');
226
+ throw new _server.ProtocolError(_server.ProtocolErrorCode.InternalError, 'Failed to create draft message');
227
227
  }
228
228
  // 2. Send the draft
229
229
  return [
@@ -273,7 +273,7 @@ function handler(_0, _1) {
273
273
  logger.error('outlook.message.send error', {
274
274
  error: message1
275
275
  });
276
- throw new _types.McpError(_types.ErrorCode.InternalError, "Error sending message: ".concat(message1), {
276
+ throw new _server.ProtocolError(_server.ProtocolErrorCode.InternalError, "Error sending message: ".concat(message1), {
277
277
  stack: _instanceof(error, Error) ? error.stack : undefined
278
278
  });
279
279
  case 5:
@@ -1 +1 @@
1
- {"version":3,"sources":["/Users/kevin/Dev/OpenSource/ai/mcp-z/mcp-outlook/src/mcp/tools/message-send.ts"],"sourcesContent":["import { ComposeContentTypeSchema, createEmailRecipientsSchema, createMessageResultSchema } from '@mcp-z/email';\nimport type { EnrichedExtra } from '@mcp-z/oauth-microsoft';\nimport { schemas } from '@mcp-z/oauth-microsoft';\n\nconst { AuthRequiredBranchSchema } = schemas;\n\nimport type { ToolModule } from '@mcp-z/server';\nimport { Client } from '@microsoft/microsoft-graph-client';\nimport { type CallToolResult, ErrorCode, McpError } from '@modelcontextprotocol/sdk/types.js';\nimport { z } from 'zod';\nimport { buildOutlookMessage } from '../../email/composition/outlook-message-builder.ts';\n\nconst MessageResultSchema = createMessageResultSchema('outlook');\n\nconst inputSchema = z.object({\n to: createEmailRecipientsSchema('to', true),\n cc: createEmailRecipientsSchema('cc', false),\n bcc: createEmailRecipientsSchema('bcc', false),\n subject: z.string().describe('Email subject line').default(''),\n body: z.string().trim().min(1).describe('Email body content (plain text or HTML)'),\n contentType: ComposeContentTypeSchema,\n});\n\n// Success branch schema\nconst successBranchSchema = MessageResultSchema.extend({\n type: z.literal('success'),\n});\n\n// Output schema with auth_required support\nconst outputSchema = z.discriminatedUnion('type', [successBranchSchema, AuthRequiredBranchSchema]);\n\nconst config = {\n description: 'Send an email message through Outlook',\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({ to, cc, bcc, subject, body, contentType }: Input, extra: EnrichedExtra): Promise<CallToolResult> {\n const logger = extra.logger;\n\n try {\n const graph = Client.initWithMiddleware({ authProvider: extra.authContext.auth });\n\n // Use composition module to build the message\n const toArray = to\n ?.split(',')\n .map((addr) => addr.trim())\n .filter((addr) => addr);\n const ccArray = cc\n ?.split(',')\n .map((addr) => addr.trim())\n .filter((addr) => addr);\n const bccArray = bcc\n ?.split(',')\n .map((addr) => addr.trim())\n .filter((addr) => addr);\n\n const message = buildOutlookMessage({\n to: toArray,\n cc: ccArray && ccArray.length > 0 ? ccArray : undefined,\n bcc: bccArray && bccArray.length > 0 ? bccArray : undefined,\n subject: subject ?? '',\n body,\n contentType: contentType === 'html' ? 'HTML' : 'Text',\n });\n\n // Use draft-send pattern to get message ID\n // 1. Create draft message\n const draft = await graph.api('/me/messages').post(message);\n const messageId = draft.id;\n\n if (!messageId) {\n logger.error('outlook.message.send draft creation failed - no ID returned');\n throw new McpError(ErrorCode.InternalError, 'Failed to create draft message');\n }\n\n // 2. Send the draft\n await graph.api(`/me/messages/${messageId}/send`).post({});\n logger.info('Outlook: sent mail successfully', { messageId });\n\n const toCount = message.toRecipients?.length ?? 0;\n const ccCount = message.ccRecipients?.length ?? 0;\n const bccCount = message.bccRecipients?.length ?? 0;\n\n logger.info('outlook.message.send success', { toCount, ccCount, bccCount, subject: subject ?? '', messageId });\n\n const totalRecipients = toCount + ccCount + bccCount;\n const result: Output = {\n type: 'success' as const,\n id: messageId,\n sentAt: new Date().toISOString(),\n recipientCount: totalRecipients,\n webLink: 'https://outlook.live.com/mail/0/sentitems',\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('outlook.message.send error', { error: message });\n\n throw new McpError(ErrorCode.InternalError, `Error sending message: ${message}`, {\n stack: error instanceof Error ? error.stack : undefined,\n });\n }\n}\n\nexport default function createTool() {\n return {\n name: 'message-send',\n config,\n handler,\n } satisfies ToolModule;\n}\n"],"names":["createTool","AuthRequiredBranchSchema","schemas","MessageResultSchema","createMessageResultSchema","inputSchema","z","object","to","createEmailRecipientsSchema","cc","bcc","subject","string","describe","default","body","trim","min","contentType","ComposeContentTypeSchema","successBranchSchema","extend","type","literal","outputSchema","discriminatedUnion","config","description","result","handler","extra","logger","message","graph","toArray","ccArray","bccArray","draft","messageId","toCount","ccCount","bccCount","totalRecipients","error","Client","initWithMiddleware","authProvider","authContext","auth","split","map","addr","filter","buildOutlookMessage","length","undefined","api","post","id","McpError","ErrorCode","InternalError","info","toRecipients","ccRecipients","bccRecipients","sentAt","Date","toISOString","recipientCount","webLink","content","text","JSON","stringify","structuredContent","Error","String","stack","name"],"mappings":";;;;+BAuHA;;;eAAwBA;;;qBAvHyE;8BAEzE;oCAKD;qBACkC;mBACvC;uCACkB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;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P,wBAAAA,QAAQ+B,YAAY,cAApB/B,4CAAAA,sBAAsBsB,MAAM,uCAAI;oBAC1Cd,oBAAUR,wBAAAA,QAAQgC,YAAY,cAApBhC,4CAAAA,sBAAsBsB,MAAM,yCAAI;oBAC1Cb,qBAAWT,yBAAAA,QAAQiC,aAAa,cAArBjC,6CAAAA,uBAAuBsB,MAAM,yCAAI;oBAElDvB,OAAO+B,IAAI,CAAC,gCAAgC;wBAAEvB,SAAAA;wBAASC,SAAAA;wBAASC,UAAAA;wBAAU9B,OAAO,EAAEA,oBAAAA,qBAAAA,UAAW;wBAAI2B,WAAAA;oBAAU;oBAEtGI,kBAAkBH,UAAUC,UAAUC;oBACtCb,SAAiB;wBACrBN,MAAM;wBACNoC,IAAIpB;wBACJ4B,QAAQ,IAAIC,OAAOC,WAAW;wBAC9BC,gBAAgB3B;wBAChB4B,SAAS;oBACX;oBAEA;;wBAAO;4BACLC,OAAO;gCACL;oCACEjD,MAAM;oCACNkD,MAAMC,KAAKC,SAAS,CAAC9C;gCACvB;;4BAEF+C,mBAAmB;gCAAE/C,QAAAA;4BAAO;wBAC9B;;;oBACOe;oBACDX,WAAUW,AAAK,YAALA,OAAiBiC,SAAQjC,MAAMX,OAAO,GAAG6C,OAAOlC;oBAChEZ,OAAOY,KAAK,CAAC,8BAA8B;wBAAEA,OAAOX;oBAAQ;oBAE5D,MAAM,IAAI2B,eAAQ,CAACC,gBAAS,CAACC,aAAa,EAAE,AAAC,0BAAiC,OAAR7B,WAAW;wBAC/E8C,OAAOnC,AAAK,YAALA,OAAiBiC,SAAQjC,MAAMmC,KAAK,GAAGvB;oBAChD;;;;;;;IAEJ;;AAEe,SAASxD;IACtB,OAAO;QACLgF,MAAM;QACNrD,QAAAA;QACAG,SAAAA;IACF;AACF"}
1
+ {"version":3,"sources":["/Users/kevin/Dev/OpenSource/ai/mcp-z/mcp-outlook/src/mcp/tools/message-send.ts"],"sourcesContent":["import { ComposeContentTypeSchema, createEmailRecipientsSchema, createMessageResultSchema } from '@mcp-z/email';\nimport type { EnrichedExtra } from '@mcp-z/oauth-microsoft';\nimport { schemas } from '@mcp-z/oauth-microsoft';\n\nconst { AuthRequiredBranchSchema } = schemas;\n\nimport type { ToolModule } from '@mcp-z/server';\nimport { type CallToolResult, ProtocolError, ProtocolErrorCode } from '@mcp-z/server';\nimport { Client } from '@microsoft/microsoft-graph-client';\nimport { z } from 'zod';\nimport { buildOutlookMessage } from '../../email/composition/outlook-message-builder.ts';\n\nconst MessageResultSchema = createMessageResultSchema('outlook');\n\nconst inputSchema = z.object({\n to: createEmailRecipientsSchema('to', true),\n cc: createEmailRecipientsSchema('cc', false),\n bcc: createEmailRecipientsSchema('bcc', false),\n subject: z.string().describe('Email subject line').default(''),\n body: z.string().trim().min(1).describe('Email body content (plain text or HTML)'),\n contentType: ComposeContentTypeSchema,\n});\n\n// Success branch schema\nconst successBranchSchema = MessageResultSchema.extend({\n type: z.literal('success'),\n});\n\n// Output schema with auth_required support\nconst outputSchema = z.discriminatedUnion('type', [successBranchSchema, AuthRequiredBranchSchema]);\n\nconst config = {\n description: 'Send an email message through Outlook',\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({ to, cc, bcc, subject, body, contentType }: Input, extra: EnrichedExtra): Promise<CallToolResult> {\n const logger = extra.logger;\n\n try {\n const graph = Client.initWithMiddleware({ authProvider: extra.authContext.auth });\n\n // Use composition module to build the message\n const toArray = to\n ?.split(',')\n .map((addr) => addr.trim())\n .filter((addr) => addr);\n const ccArray = cc\n ?.split(',')\n .map((addr) => addr.trim())\n .filter((addr) => addr);\n const bccArray = bcc\n ?.split(',')\n .map((addr) => addr.trim())\n .filter((addr) => addr);\n\n const message = buildOutlookMessage({\n to: toArray,\n cc: ccArray && ccArray.length > 0 ? ccArray : undefined,\n bcc: bccArray && bccArray.length > 0 ? bccArray : undefined,\n subject: subject ?? '',\n body,\n contentType: contentType === 'html' ? 'HTML' : 'Text',\n });\n\n // Use draft-send pattern to get message ID\n // 1. Create draft message\n const draft = await graph.api('/me/messages').post(message);\n const messageId = draft.id;\n\n if (!messageId) {\n logger.error('outlook.message.send draft creation failed - no ID returned');\n throw new ProtocolError(ProtocolErrorCode.InternalError, 'Failed to create draft message');\n }\n\n // 2. Send the draft\n await graph.api(`/me/messages/${messageId}/send`).post({});\n logger.info('Outlook: sent mail successfully', { messageId });\n\n const toCount = message.toRecipients?.length ?? 0;\n const ccCount = message.ccRecipients?.length ?? 0;\n const bccCount = message.bccRecipients?.length ?? 0;\n\n logger.info('outlook.message.send success', { toCount, ccCount, bccCount, subject: subject ?? '', messageId });\n\n const totalRecipients = toCount + ccCount + bccCount;\n const result: Output = {\n type: 'success' as const,\n id: messageId,\n sentAt: new Date().toISOString(),\n recipientCount: totalRecipients,\n webLink: 'https://outlook.live.com/mail/0/sentitems',\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('outlook.message.send error', { error: message });\n\n throw new ProtocolError(ProtocolErrorCode.InternalError, `Error sending message: ${message}`, {\n stack: error instanceof Error ? error.stack : undefined,\n });\n }\n}\n\nexport default function createTool() {\n return {\n name: 'message-send',\n config,\n handler,\n } satisfies ToolModule;\n}\n"],"names":["createTool","AuthRequiredBranchSchema","schemas","MessageResultSchema","createMessageResultSchema","inputSchema","z","object","to","createEmailRecipientsSchema","cc","bcc","subject","string","describe","default","body","trim","min","contentType","ComposeContentTypeSchema","successBranchSchema","extend","type","literal","outputSchema","discriminatedUnion","config","description","result","handler","extra","logger","message","graph","toArray","ccArray","bccArray","draft","messageId","toCount","ccCount","bccCount","totalRecipients","error","Client","initWithMiddleware","authProvider","authContext","auth","split","map","addr","filter","buildOutlookMessage","length","undefined","api","post","id","ProtocolError","ProtocolErrorCode","InternalError","info","toRecipients","ccRecipients","bccRecipients","sentAt","Date","toISOString","recipientCount","webLink","content","text","JSON","stringify","structuredContent","Error","String","stack","name"],"mappings":";;;;+BAuHA;;;eAAwBA;;;qBAvHyE;8BAEzE;sBAK8C;oCAC/C;mBACL;uCACkB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AANpC,IAAM,AAAEC,2BAA6BC,uBAAO,CAApCD;AAQR,IAAME,sBAAsBC,IAAAA,gCAAyB,EAAC;AAEtD,IAAMC,cAAcC,MAAC,CAACC,MAAM,CAAC;IAC3BC,IAAIC,IAAAA,kCAA2B,EAAC,MAAM;IACtCC,IAAID,IAAAA,kCAA2B,EAAC,MAAM;IACtCE,KAAKF,IAAAA,kCAA2B,EAAC,OAAO;IACxCG,SAASN,MAAC,CAACO,MAAM,GAAGC,QAAQ,CAAC,sBAAsBC,OAAO,CAAC;IAC3DC,MAAMV,MAAC,CAACO,MAAM,GAAGI,IAAI,GAAGC,GAAG,CAAC,GAAGJ,QAAQ,CAAC;IACxCK,aAAaC,+BAAwB;AACvC;AAEA,wBAAwB;AACxB,IAAMC,sBAAsBlB,oBAAoBmB,MAAM,CAAC;IACrDC,MAAMjB,MAAC,CAACkB,OAAO,CAAC;AAClB;AAEA,2CAA2C;AAC3C,IAAMC,eAAenB,MAAC,CAACoB,kBAAkB,CAAC,QAAQ;IAACL;IAAqBpB;CAAyB;AAEjG,IAAM0B,SAAS;IACbC,aAAa;IACbvB,aAAaA;IACboB,cAAcnB,MAAC,CAACC,MAAM,CAAC;QACrBsB,QAAQJ;IACV;AACF;AAKA,SAAeK;wCAAQ,KAAkD,EAAEC,KAAoB;YAAtEvB,IAAIE,IAAIC,KAAKC,SAASI,MAAMG,aAC7Ca,4BA0CYC,uBACAA,uBACCA,wBAzCXC,OAGAC,SAIAC,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GAAGvB;oBAChD;;;;;;;IAEJ;;AAEe,SAASxD;IACtB,OAAO;QACLgF,MAAM;QACNrD,QAAAA;QACAG,SAAAA;IACF;AACF"}
@@ -1,6 +1,6 @@
1
1
  /** Outlook message CSV export tool - streams results to file without loading all data into context */
2
2
  import type { EnrichedExtra } from '@mcp-z/oauth-microsoft';
3
- import { type CallToolResult } from '@modelcontextprotocol/sdk/types.js';
3
+ import { type CallToolResult } from '@mcp-z/server';
4
4
  import { z } from 'zod';
5
5
  import type { StorageExtra } from '../../types.js';
6
6
  declare const inputSchema: z.ZodObject<{
@@ -1,6 +1,6 @@
1
1
  /** Outlook message CSV export tool - streams results to file without loading all data into context */
2
2
  import type { EnrichedExtra } from '@mcp-z/oauth-microsoft';
3
- import { type CallToolResult } from '@modelcontextprotocol/sdk/types.js';
3
+ import { type CallToolResult } from '@mcp-z/server';
4
4
  import { z } from 'zod';
5
5
  import type { StorageExtra } from '../../types.js';
6
6
  declare const inputSchema: z.ZodObject<{
@@ -12,7 +12,6 @@ var _email = require("@mcp-z/email");
12
12
  var _oauthmicrosoft = require("@mcp-z/oauth-microsoft");
13
13
  var _server = require("@mcp-z/server");
14
14
  var _microsoftgraphclient = require("@microsoft/microsoft-graph-client");
15
- var _types = require("@modelcontextprotocol/sdk/types.js");
16
15
  var _sync = require("csv-stringify/sync");
17
16
  var _fs = require("fs");
18
17
  var _promises = require("fs/promises");
@@ -513,7 +512,7 @@ var config = {
513
512
  logger.error('outlook.messages.export-csv error', {
514
513
  error: message
515
514
  });
516
- throw new _types.McpError(_types.ErrorCode.InternalError, "Error exporting messages to CSV: ".concat(message), {
515
+ throw new _server.ProtocolError(_server.ProtocolErrorCode.InternalError, "Error exporting messages to CSV: ".concat(message), {
517
516
  stack: _instanceof(error, Error) ? error.stack : undefined
518
517
  });
519
518
  case 12: