Skip to main content
Glama
xybstone

macOS Calendar MCP Server

by xybstone

delete-events-by-keyword

Remove calendar events by matching keywords to clean up your macOS Calendar. Specify a keyword to delete matching events from a selected calendar.

Instructions

根据关键词删除事件

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
keywordYes要删除的事件关键词
calendarNo日历名称工作
confirmNo确认删除

Implementation Reference

  • Handler function that implements the delete-events-by-keyword tool. Parses arguments, checks confirmation, executes AppleScript to delete matching events from the specified calendar, and returns the count of deleted events.
    async deleteEventsByKeyword(args) {
      const { keyword, calendar = '工作', confirm = false } = args;
      
      if (!confirm) {
        return {
          content: [
            {
              type: 'text',
              text: `⚠️ 请确认删除操作!\n将删除日历"${calendar}"中包含关键词"${keyword}"的所有事件。\n要执行删除,请设置 confirm: true`,
            },
          ],
        };
      }
    
      const script = `
        tell application "Calendar"
          set theCalendar to calendar "${calendar}"
          set allEvents to every event of theCalendar
          set deletedCount to 0
          
          repeat with anEvent in reverse of allEvents
            if (summary of anEvent) contains "${keyword}" then
              delete anEvent
              set deletedCount to deletedCount + 1
            end if
          end repeat
          
          return deletedCount
        end tell
      `;
    
      try {
        const result = execSync(`osascript -e '${script}'`, { encoding: 'utf8' });
        const deletedCount = parseInt(result.trim()) || 0;
        
        return {
          content: [
            {
              type: 'text',
              text: `🗑️ 删除完成!\n删除了 ${deletedCount} 个包含"${keyword}"的事件`,
            },
          ],
        };
      } catch (error) {
        throw new Error(`删除事件失败: ${error.message}`);
      }
    }
  • Input schema definition for the delete-events-by-keyword tool in the listTools response.
    {
      name: 'delete-events-by-keyword',
      description: '根据关键词删除事件',
      inputSchema: {
        type: 'object',
        properties: {
          keyword: {
            type: 'string',
            description: '要删除的事件关键词',
          },
          calendar: {
            type: 'string',
            description: '日历名称',
            default: '工作',
          },
          confirm: {
            type: 'boolean',
            description: '确认删除',
            default: false,
          },
        },
        required: ['keyword'],
        additionalProperties: false,
      },
    },
  • Handler function that implements the delete-events-by-keyword tool. Parses arguments, checks confirmation, executes AppleScript to delete matching events, and returns the deletion count.
    // 根据关键词删除事件
    deleteEventsByKeyword(args) {
      const { keyword, calendar = "工作", confirm = false } = args;
      
      if (!confirm) {
        return {
          content: [{
            type: "text",
            text: `⚠️ 请确认删除操作!\n将删除日历"${calendar}"中包含关键词"${keyword}"的所有事件。\n要执行删除,请设置 confirm: true`
          }]
        };
      }
    
      const script = `
        tell application "Calendar"
          set theCalendar to calendar "${calendar}"
          set allEvents to every event of theCalendar
          set deletedCount to 0
          
          repeat with anEvent in reverse of allEvents
            if (summary of anEvent) contains "${keyword}" then
              delete anEvent
              set deletedCount to deletedCount + 1
            end if
          end repeat
          
          return deletedCount
        end tell
      `;
    
      try {
        const result = execSync(`osascript -e '${script}'`, { encoding: 'utf8' });
        const deletedCount = parseInt(result.trim()) || 0;
        
        return {
          content: [{
            type: "text",
            text: `🗑️ 删除完成!\n删除了 ${deletedCount} 个包含"${keyword}"的事件`
          }]
        };
      } catch (error) {
        throw new Error(`删除事件失败: ${error.message}`);
      }
    }
  • Input schema for delete-events-by-keyword tool returned by getTools method.
    {
      name: "delete-events-by-keyword",
      description: "根据关键词删除事件",
      inputSchema: {
        type: "object",
        properties: {
          keyword: {
            type: "string",
            description: "要删除的事件关键词"
          },
          calendar: {
            type: "string",
            description: "日历名称",
            default: "工作"
          },
          confirm: {
            type: "boolean",
            description: "确认删除",
            default: false
          }
        },
        required: ["keyword", "confirm"],
        additionalProperties: false
      }
    },
  • Switch statement in CallToolRequestSchema handler registering the delete-events-by-keyword tool.
    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}`);
    }

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