mcp-windows-notify
Version:
Windows notification MCP server for AI development tools - Get desktop notifications when AI tasks complete
94 lines • 3.18 kB
JavaScript
import notifier from 'node-notifier';
import { config } from './config.js';
export class WindowsNotifier {
/**
* 发送Windows系统通知
*/
async sendNotification(options) {
try {
const notificationOptions = {
title: options.title || config.notificationDefaults.title,
message: options.message,
sound: options.sound !== undefined ? options.sound : config.notificationDefaults.sound,
time: options.timeout || config.notificationDefaults.timeout,
icon: this.getIconPath(options.icon || config.notificationDefaults.icon),
subtitle: options.subtitle,
actions: options.actions,
wait: false // 不等待用户交互
};
return new Promise((resolve) => {
notifier.notify(notificationOptions, (err, response, metadata) => {
if (err) {
resolve({
success: false,
message: `通知发送失败: ${err.message}`,
timestamp: new Date().toISOString()
});
}
else {
resolve({
success: true,
message: '通知发送成功',
timestamp: new Date().toISOString()
});
}
});
});
}
catch (error) {
return {
success: false,
message: `通知发送异常: ${error instanceof Error ? error.message : String(error)}`,
timestamp: new Date().toISOString()
};
}
}
/**
* 获取图标路径
*/
getIconPath(icon) {
// Windows系统图标路径
const iconMap = {
'info': 'C:\\Windows\\System32\\imageres.dll,76',
'warning': 'C:\\Windows\\System32\\imageres.dll,78',
'error': 'C:\\Windows\\System32\\imageres.dll,93',
'success': 'C:\\Windows\\System32\\imageres.dll,77'
};
return iconMap[icon] || iconMap['info'];
}
/**
* 发送任务完成通知
*/
async notifyTaskComplete(taskName, details) {
return this.sendNotification({
title: '任务完成',
message: `${taskName}${details ? '\n' + details : ''}`,
icon: 'success',
sound: true
});
}
/**
* 发送错误通知
*/
async notifyError(errorMessage, details) {
return this.sendNotification({
title: '发生错误',
message: `${errorMessage}${details ? '\n' + details : ''}`,
icon: 'error',
sound: true
});
}
/**
* 发送提醒通知
*/
async notifyReminder(message, subtitle) {
return this.sendNotification({
title: '提醒',
message,
subtitle,
icon: 'info',
sound: true
});
}
}
//# sourceMappingURL=notification.js.map