Bug fixes (non-breaking): - Register accept-event tool in calendar module (was dead code) - Add missing callGraphAPI + ensureAuthenticated imports to rules/index.js (edit-rule-sequence would throw ReferenceError at runtime) - Make calendar event timezone configurable via MS_TIMEZONE env var (was hardcoded to UTC; default is now Eastern Standard Time) Version bump: 1.0.0 → 1.0.1 README updated: 21 tools, MS_TIMEZONE in config table, known issues pruned
178 lines
4.8 KiB
JavaScript
178 lines
4.8 KiB
JavaScript
/**
|
|
* Email rules management module for Outlook MCP server
|
|
*/
|
|
const handleListRules = require('./list');
|
|
const handleCreateRule = require('./create');
|
|
const { callGraphAPI } = require('../utils/graph-api');
|
|
const { ensureAuthenticated } = require('../auth');
|
|
|
|
// Import getInboxRules for the edit sequence tool
|
|
const { getInboxRules } = require('./list');
|
|
|
|
/**
|
|
* Edit rule sequence handler
|
|
* @param {object} args - Tool arguments
|
|
* @returns {object} - MCP response
|
|
*/
|
|
async function handleEditRuleSequence(args) {
|
|
const { ruleName } = args;
|
|
const sequence = args.sequence !== undefined ? parseInt(args.sequence, 10) : undefined;
|
|
|
|
if (!ruleName) {
|
|
return {
|
|
content: [{
|
|
type: "text",
|
|
text: "Rule name is required. Please specify the exact name of an existing rule."
|
|
}]
|
|
};
|
|
}
|
|
|
|
if (!sequence || isNaN(sequence) || sequence < 1) {
|
|
return {
|
|
content: [{
|
|
type: "text",
|
|
text: "A positive sequence number is required. Lower numbers run first (higher priority)."
|
|
}]
|
|
};
|
|
}
|
|
|
|
try {
|
|
// Get access token
|
|
const accessToken = await ensureAuthenticated();
|
|
|
|
// Get all rules
|
|
const rules = await getInboxRules(accessToken);
|
|
|
|
// Find the rule by name
|
|
const rule = rules.find(r => r.displayName === ruleName);
|
|
if (!rule) {
|
|
return {
|
|
content: [{
|
|
type: "text",
|
|
text: `Rule with name "${ruleName}" not found.`
|
|
}]
|
|
};
|
|
}
|
|
|
|
// Update the rule sequence
|
|
const updateResult = await callGraphAPI(
|
|
accessToken,
|
|
'PATCH',
|
|
`me/mailFolders/inbox/messageRules/${rule.id}`,
|
|
{
|
|
sequence: sequence
|
|
}
|
|
);
|
|
|
|
return {
|
|
content: [{
|
|
type: "text",
|
|
text: `Successfully updated the sequence of rule "${ruleName}" to ${sequence}.`
|
|
}]
|
|
};
|
|
} catch (error) {
|
|
if (error.message === 'Authentication required') {
|
|
return {
|
|
content: [{
|
|
type: "text",
|
|
text: "Authentication required. Please use the 'authenticate' tool first."
|
|
}]
|
|
};
|
|
}
|
|
|
|
return {
|
|
content: [{
|
|
type: "text",
|
|
text: `Error updating rule sequence: ${error.message}`
|
|
}]
|
|
};
|
|
}
|
|
}
|
|
|
|
// Rules management tool definitions
|
|
const rulesTools = [
|
|
{
|
|
name: "list-rules",
|
|
description: "Lists inbox rules in your Outlook account",
|
|
inputSchema: {
|
|
type: "object",
|
|
properties: {
|
|
includeDetails: {
|
|
type: "boolean",
|
|
description: "Include detailed rule conditions and actions"
|
|
}
|
|
},
|
|
required: []
|
|
},
|
|
handler: handleListRules
|
|
},
|
|
{
|
|
name: "create-rule",
|
|
description: "Creates a new inbox rule",
|
|
inputSchema: {
|
|
type: "object",
|
|
properties: {
|
|
name: {
|
|
type: "string",
|
|
description: "Name of the rule to create"
|
|
},
|
|
fromAddresses: {
|
|
type: "string",
|
|
description: "Comma-separated list of sender email addresses for the rule"
|
|
},
|
|
containsSubject: {
|
|
type: "string",
|
|
description: "Subject text the email must contain"
|
|
},
|
|
hasAttachments: {
|
|
anyOf: [{ type: "boolean" }, { type: "string" }],
|
|
description: "Whether the rule applies to emails with attachments"
|
|
},
|
|
moveToFolder: {
|
|
type: "string",
|
|
description: "Name of the folder to move matching emails to"
|
|
},
|
|
markAsRead: {
|
|
anyOf: [{ type: "boolean" }, { type: "string" }],
|
|
description: "Whether to mark matching emails as read"
|
|
},
|
|
isEnabled: {
|
|
anyOf: [{ type: "boolean" }, { type: "string" }],
|
|
description: "Whether the rule should be enabled after creation (default: true)"
|
|
},
|
|
sequence: {
|
|
anyOf: [{ type: "number" }, { type: "string" }],
|
|
description: "Order in which the rule is executed (lower numbers run first, default: 100)"
|
|
}
|
|
},
|
|
required: ["name"]
|
|
},
|
|
handler: handleCreateRule
|
|
},
|
|
{
|
|
name: "edit-rule-sequence",
|
|
description: "Changes the execution order of an existing inbox rule",
|
|
inputSchema: {
|
|
type: "object",
|
|
properties: {
|
|
ruleName: {
|
|
type: "string",
|
|
description: "Name of the rule to modify"
|
|
},
|
|
sequence: {
|
|
anyOf: [{ type: "number" }, { type: "string" }],
|
|
description: "New sequence value for the rule (lower numbers run first)"
|
|
}
|
|
},
|
|
required: ["ruleName", "sequence"]
|
|
},
|
|
handler: handleEditRuleSequence
|
|
}
|
|
];
|
|
|
|
module.exports = {
|
|
rulesTools,
|
|
handleListRules,
|
|
handleCreateRule,
|
|
handleEditRuleSequence
|
|
};
|