create-event
Add new events to macOS Calendar with title, dates, and optional details like location and description.
Instructions
在macOS日历中创建新事件
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| calendar | No | 日历名称 | 个人 |
| title | Yes | 事件标题 | |
| startDate | Yes | 开始时间,格式:YYYY-MM-DD HH:MM | |
| endDate | Yes | 结束时间,格式:YYYY-MM-DD HH:MM | |
| description | No | 事件描述 | |
| location | No | 事件地点 |
Implementation Reference
- macos-calendar-mcp-sdk.js:317-350 (handler)Handler for 'create-event' tool using MCP SDK. Formats dates, generates AppleScript to create event in specified calendar, executes via osascript.async createEvent(args) { const { calendar = '个人', title, startDate, endDate, description = '', location = '' } = args; const startInfo = this.formatDateForAppleScript(startDate); const endInfo = this.formatDateForAppleScript(endDate); const startTimeScript = this.generateTimeScript(startInfo, 'startTime'); const endTimeScript = this.generateTimeScript(endInfo, 'endTime'); const script = ` tell application "Calendar" set theCalendar to calendar "${calendar}" ${startTimeScript} ${endTimeScript} make new event at end of events of theCalendar with properties {summary:"${title}", start date:startTime, end date:endTime, description:"${description}", location:"${location}"} end tell `; try { const result = execSync(`osascript -e '${script}'`, { encoding: 'utf8' }); return { content: [ { type: 'text', text: `✅ 事件创建成功!\n📅 日历: ${calendar}\n📝 标题: ${title}\n🕒 时间: ${startDate} - ${endDate}\n📍 地点: ${location || '无'}\n📄 描述: ${description || '无'}`, }, ], }; } catch (error) { throw new Error(`创建事件失败: ${error.message}`); } }
- macos-calendar-mcp-v2.js:264-291 (handler)Handler for 'create-event' tool. Formats dates for AppleScript, creates event in macOS Calendar.createEvent(args) { const { calendar = "个人", title, startDate, endDate, description = "", location = "" } = args; const formattedStart = this.formatDateForAppleScript(startDate); const formattedEnd = this.formatDateForAppleScript(endDate); const script = ` tell application "Calendar" set theCalendar to calendar "${calendar}" set startDate to date "${formattedStart}" set endDate to date "${formattedEnd}" make new event at end of events of theCalendar with properties {summary:"${title}", start date:startDate, end date:endDate, description:"${description}", location:"${location}"} end tell `; try { const result = execSync(`osascript -e '${script}'`, { encoding: 'utf8' }); return { content: [{ type: "text", text: `✅ 事件创建成功!\n📅 日历: ${calendar}\n📝 标题: ${title}\n🕒 时间: ${startDate} - ${endDate}\n📍 地点: ${location || '无'}\n📄 描述: ${description || '无'}` }] }; } catch (error) { throw new Error(`创建事件失败: ${error.message}`); } }
- macos-calendar-mcp.js:160-200 (handler)Handler for 'create-event' tool in v1. Uses toLocaleString for date formatting to AppleScript format, executes osascript to create calendar event.createEvent(args) { const { calendar = "个人", title, startDate, endDate, description = "", location = "" } = args; // 转换时间格式 const formatDate = (dateStr) => { const date = new Date(dateStr); return date.toLocaleString('en-US', { month: 'numeric', day: 'numeric', year: 'numeric', hour: 'numeric', minute: '2-digit', hour12: true }); }; const formattedStart = formatDate(startDate); const formattedEnd = formatDate(endDate); const script = ` tell application "Calendar" set theCalendar to calendar "${calendar}" set startDate to date "${formattedStart}" set endDate to date "${formattedEnd}" make new event at end of events of theCalendar with properties {summary:"${title}", start date:startDate, end date:endDate, description:"${description}", location:"${location}"} end tell `; try { const result = execSync(`osascript -e '${script}'`, { encoding: 'utf8' }); return { content: [{ type: "text", text: `✅ 事件创建成功!\n📅 日历: ${calendar}\n📝 标题: ${title}\n🕒 时间: ${startDate} - ${endDate}\n📍 地点: ${location || '无'}\n📄 描述: ${description || '无'}` }] }; } catch (error) { throw new Error(`创建事件失败: ${error.message}`); } }
- macos-calendar-mcp-sdk.js:43-79 (schema)Input schema definition for the 'create-event' tool, defining parameters like calendar, title, dates, etc.name: 'create-event', description: '在macOS日历中创建新事件', inputSchema: { type: 'object', properties: { calendar: { type: 'string', description: '日历名称', default: '个人', }, title: { type: 'string', description: '事件标题', }, startDate: { type: 'string', description: '开始时间,格式:YYYY-MM-DD HH:MM', }, endDate: { type: 'string', description: '结束时间,格式:YYYY-MM-DD HH:MM', }, description: { type: 'string', description: '事件描述', default: '', }, location: { type: 'string', description: '事件地点', default: '', }, }, required: ['title', 'startDate', 'endDate'], additionalProperties: false, }, },