Skip to main content
Glama

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

TableJSON Schema
NameRequiredDescriptionDefault
calendarNo日历名称个人
descriptionNo事件描述
endDateYes结束时间,格式:YYYY-MM-DD HH:MM
locationNo事件地点
startDateYes开始时间,格式:YYYY-MM-DD HH:MM
titleYes事件标题

Implementation Reference

  • 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}`); } }
  • 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, }, },
  • 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}`); } }
  • 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}`); } }
  • 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, }; } }); }

Other Tools

Related Tools

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/xybstone/macos-calendar-mcp'

If you have feedback or need assistance with the MCP directory API, please join our Discord server