msexchange-mcp
Version:
MCP server for Microsoft Exchange/Outlook email operations via Microsoft Graph API
60 lines • 2.79 kB
JavaScript
import { z } from 'zod';
import { MailService } from '../mail/mailService.js';
import accountsConfig from '../config/accountsLoader.js';
export const addAttachmentToDraftTool = {
name: 'add_attachment_to_draft',
description: 'Add an attachment to an existing draft email. For files larger than 4MB, use upload sessions (not yet implemented).',
parameters: z.object({
user_id: z.string().describe('The user ID or email address'),
draft_id: z.string().describe('The draft message ID to add attachment to'),
name: z.string().describe('Attachment filename'),
content: z.string().describe('Base64 encoded file content'),
contentType: z.string().optional().describe('MIME type (e.g., "application/pdf", "image/jpeg")'),
}),
execute: async (params) => {
try {
const account = accountsConfig.accounts.find(acc => acc.id === params.user_id || acc.email === params.user_id);
if (!account) {
throw new Error(`User not found: ${params.user_id}`);
}
const mailService = new MailService(account.email);
// Estimate attachment size (base64 is ~33% larger than binary)
const estimatedSize = (params.content.length * 3) / 4;
if (estimatedSize > 4 * 1024 * 1024) {
throw new Error(`Attachment "${params.name}" exceeds 4MB limit (estimated size: ${(estimatedSize / 1024 / 1024).toFixed(2)}MB)`);
}
const attachment = await mailService.addAttachmentToDraft(params.draft_id, {
name: params.name,
contentType: params.contentType,
contentBytes: params.content,
size: estimatedSize,
});
return {
content: [
{
type: 'text',
text: JSON.stringify({
message: 'Attachment added successfully',
attachmentId: attachment.id,
name: attachment.name,
contentType: attachment.contentType,
size: attachment.size,
sizeInMB: attachment.size ? (attachment.size / 1024 / 1024).toFixed(2) : 'Unknown',
}, null, 2),
},
],
};
}
catch (error) {
return {
content: [
{
type: 'text',
text: `Error adding attachment: ${error instanceof Error ? error.message : 'Unknown error'}`,
},
],
};
}
},
};
//# sourceMappingURL=addAttachmentToDraft.js.map