create-event
Utilize AppleScript integration to create new events in macOS Calendar with specified title, start and end times, location, and description.
Instructions
在macOS日历中创建新事件
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| calendar | No | 日历名称 | 个人 |
| description | No | 事件描述 | |
| endDate | Yes | 结束时间,格式:YYYY-MM-DD HH:MM | |
| location | No | 事件地点 | |
| startDate | Yes | 开始时间,格式:YYYY-MM-DD HH:MM | |
| title | Yes | 事件标题 |
Input Schema (JSON Schema)
{
"additionalProperties": false,
"properties": {
"calendar": {
"default": "个人",
"description": "日历名称",
"type": "string"
},
"description": {
"default": "",
"description": "事件描述",
"type": "string"
},
"endDate": {
"description": "结束时间,格式:YYYY-MM-DD HH:MM",
"type": "string"
},
"location": {
"default": "",
"description": "事件地点",
"type": "string"
},
"startDate": {
"description": "开始时间,格式:YYYY-MM-DD HH:MM",
"type": "string"
},
"title": {
"description": "事件标题",
"type": "string"
}
},
"required": [
"title",
"startDate",
"endDate"
],
"type": "object"
}
Implementation Reference
- macos-calendar-mcp-sdk.js:317-350 (handler)Handler function for 'create-event' tool in the MCP SDK version, uses precise AppleScript date setting to create events reliably.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-sdk.js:42-79 (schema)Input schema definition for the 'create-event' tool.{ 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, }, },
- macos-calendar-mcp-v2.js:264-291 (handler)Handler function for 'create-event' tool in v2 implementation, formats dates for AppleScript.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 function for 'create-event' tool in the original implementation, uses toLocaleString for date formatting.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:229-265 (registration)Tool dispatch registration in the MCP SDK server handler, routes 'create-event' to the createEvent method.this.server.setRequestHandler(CallToolRequestSchema, async (request) => { try { const { name, arguments: args } = request.params; switch (name) { case 'list-calendars': return await this.listCalendars(); case 'create-event': return await this.createEvent(args); case 'create-batch-events': return await this.createBatchEvents(args); case 'delete-events-by-keyword': return await this.deleteEventsByKeyword(args); case 'list-today-events': return await this.listTodayEvents(args); case 'list-week-events': return await this.listWeekEvents(args); case 'search-events': return await this.searchEvents(args); case 'fix-event-times': return await this.fixEventTimes(args); default: throw new Error(`Unknown tool: ${name}`); } } catch (error) { return { content: [ { type: 'text', text: `错误: ${error.message}`, }, ], isError: true, }; } }); }