Skip to main content
Glama

search-events

Search macOS Calendar events by keywords to find specific appointments, meetings, or reminders across your calendars.

Instructions

搜索事件

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
queryYes搜索关键词
calendarNo日历名称个人

Implementation Reference

  • Implementation of the search-events tool handler. Searches for events in the specified calendar using AppleScript by checking if the query is 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}`); } }
  • Implementation of the search-events tool handler in the MCP SDK version. Uses AppleScript to search events matching the query in title or description within the calendar.
    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) { throw new Error(`搜索事件失败: ${error.message}`); } }
  • Implementation of the search-events tool handler in v2. Searches events using AppleScript query 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}`); } }
  • Input schema definition for the search-events tool in getTools().
    { name: "search-events", description: "搜索事件", inputSchema: { type: "object", properties: { query: { type: "string", description: "搜索关键词" }, calendar: { type: "string", description: "日历名称", default: "个人" } }, required: ["query"], additionalProperties: false }
  • Registration of the search-events handler in the callTool switch statement.
    case "search-events": return this.searchEvents(args);

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