UNPKG

msexchange-mcp

Version:

MCP server for Microsoft Exchange/Outlook email operations via Microsoft Graph API

70 lines 3.02 kB
import { z } from 'zod'; import { MailService } from '../mail/mailService.js'; import accountsConfig from '../config/accountsLoader.js'; export const deleteMailRuleTool = { name: 'delete_mail_rule', description: 'Delete a mail rule from the user\'s mailbox', parameters: z.object({ user_id: z.string().describe('The user ID or email address'), rule_id: z.string().describe('ID of the rule to delete'), confirm: z.boolean().optional().default(false).describe('Confirmation that you want to delete the rule'), }), 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}`); } if (!params.confirm) { return { content: [ { type: 'text', text: JSON.stringify({ success: false, error: 'Confirmation required', message: 'To delete a mail rule, you must set confirm=true', safety_tip: 'Mail rule deletion is permanent and cannot be undone', }, null, 2), }, ], }; } const mailService = new MailService(account.email); // Get rule details before deletion for confirmation const existingRule = await mailService.getMailRule(params.rule_id); if (!existingRule) { throw new Error(`Rule not found: ${params.rule_id}`); } await mailService.deleteMailRule(params.rule_id); return { content: [ { type: 'text', text: JSON.stringify({ success: true, deleted_rule: { id: existingRule.id, displayName: existingRule.displayName, was_enabled: existingRule.isEnabled, }, message: `Successfully deleted mail rule '${existingRule.displayName}'`, note: 'This action cannot be undone. You would need to recreate the rule if needed.', }, null, 2), }, ], }; } catch (error) { return { content: [ { type: 'text', text: `Error deleting mail rule: ${error instanceof Error ? error.message : 'Unknown error'}`, }, ], }; } }, }; //# sourceMappingURL=deleteMailRule.js.map