search-events
Search macOS Calendar events using keywords and specific calendar names for quick access to scheduled activities without OAuth setup.
Instructions
搜索事件
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| calendar | No | 日历名称 | 个人 |
| query | Yes | 搜索关键词 |
Input Schema (JSON Schema)
{
"additionalProperties": false,
"properties": {
"calendar": {
"default": "个人",
"description": "日历名称",
"type": "string"
},
"query": {
"description": "搜索关键词",
"type": "string"
}
},
"required": [
"query"
],
"type": "object"
}
Implementation Reference
- macos-calendar-mcp-v2.js:487-535 (handler)Implements the 'search-events' tool handler. Uses AppleScript to query Calendar app for events matching the search query in summary or description, parses results, and returns formatted list.searchEvents(args) { const { query, calendar = "个人" } = args; const script = ` tell application "Calendar" set theCalendar to calendar "${calendar}" set allEvents to every event of theCalendar set matchingEvents to {} repeat with anEvent in allEvents if (summary of anEvent) contains "${query}" or (description of anEvent) contains "${query}" then set eventInfo to (summary of anEvent) & "|" & (start date of anEvent) & "|" & (end date of anEvent) & "|" & (description of anEvent) & "|" & (location of anEvent) set end of matchingEvents to eventInfo end if end repeat return matchingEvents as string end tell `; try { const result = execSync(`osascript -e '${script}'`, { encoding: 'utf8' }); const events = result.trim(); if (!events || events === '""') { return { content: [{ type: "text", text: `🔍 在 ${calendar} 中未找到包含 "${query}" 的事件` }] }; } const eventList = events.split(',').map(event => { const [title, start, end, desc, loc] = event.trim().split('|'); return `📝 ${title}\n🕒 ${start} - ${end}${loc ? `\n📍 ${loc}` : ''}${desc ? `\n📄 ${desc}` : ''}`; }).join('\n\n'); return { content: [{ type: "text", text: `🔍 在 ${calendar} 中找到 ${events.split(',').length} 个匹配事件:\n\n${eventList}` }] }; } catch (error) { throw new Error(`搜索事件失败: ${error.message}`); } } }
- macos-calendar-mcp-v2.js:167-186 (schema)Input schema definition for the 'search-events' tool in the tools list.{ name: "search-events", description: "搜索事件", inputSchema: { type: "object", properties: { query: { type: "string", description: "搜索关键词" }, calendar: { type: "string", description: "日历名称", default: "个人" } }, required: ["query"], additionalProperties: false } }
- macos-calendar-mcp-v2.js:207-208 (registration)Dispatch registration in the callTool switch statement that routes to the searchEvents handler.case "search-events": return this.searchEvents(args);
- macos-calendar-mcp-sdk.js:559-607 (handler)Implements the 'search-events' tool handler using the MCP SDK framework. Similar logic to other versions, executes AppleScript for event search.async searchEvents(args) { const { query, calendar = '个人' } = args; const script = ` tell application "Calendar" set theCalendar to calendar "${calendar}" set allEvents to every event of theCalendar set matchingEvents to {} repeat with anEvent in allEvents if (summary of anEvent) contains "${query}" or (description of anEvent) contains "${query}" then set eventInfo to (summary of anEvent) & "|" & (start date of anEvent) & "|" & (end date of anEvent) & "|" & (description of anEvent) & "|" & (location of anEvent) set end of matchingEvents to eventInfo end if end repeat return matchingEvents as string end tell `; try { const result = execSync(`osascript -e '${script}'`, { encoding: 'utf8' }); const events = result.trim(); if (!events || events === '""') { return { content: [ { type: 'text', text: `🔍 在 ${calendar} 中未找到包含 "${query}" 的事件`, }, ], }; } const eventList = events.split(',').map(event => { const [title, start, end, desc, loc] = event.trim().split('|'); return `📝 ${title}\n🕒 ${start} - ${end}${loc ? `\n📍 ${loc}` : ''}${desc ? `\n📄 ${desc}` : ''}`; }).join('\n\n'); return { content: [ { type: 'text', text: `🔍 在 ${calendar} 中找到 ${events.split(',').length} 个匹配事件:\n\n${eventList}`, }, ], }; } catch (error) {
- macos-calendar-mcp.js:254-301 (handler)Implements the 'search-events' tool handler in version 1.0.0. Uses AppleScript to search events by keyword in summary or description.searchEvents(args) { const { query, calendar = "个人" } = args; const script = ` tell application "Calendar" set theCalendar to calendar "${calendar}" set allEvents to every event of theCalendar set matchingEvents to {} repeat with anEvent in allEvents if (summary of anEvent) contains "${query}" or (description of anEvent) contains "${query}" then set eventInfo to (summary of anEvent) & "|" & (start date of anEvent) & "|" & (end date of anEvent) & "|" & (description of anEvent) & "|" & (location of anEvent) set end of matchingEvents to eventInfo end if end repeat return matchingEvents as string end tell `; try { const result = execSync(`osascript -e '${script}'`, { encoding: 'utf8' }); const events = result.trim(); if (!events || events === '""') { return { content: [{ type: "text", text: `🔍 在 ${calendar} 中未找到包含 "${query}" 的事件` }] }; } const eventList = events.split(',').map(event => { const [title, start, end, desc, loc] = event.trim().split('|'); return `📝 ${title}\n🕒 ${start} - ${end}${loc ? `\n📍 ${loc}` : ''}${desc ? `\n📄 ${desc}` : ''}`; }).join('\n\n'); return { content: [{ type: "text", text: `🔍 在 ${calendar} 中找到 ${events.split(',').length} 个匹配事件:\n\n${eventList}` }] }; } catch (error) { throw new Error(`搜索事件失败: ${error.message}`); } }