Skip to main content
Glama
xybstone

macOS Calendar MCP Server

by xybstone

fix-event-times

Corrects calendar events that are mistakenly scheduled at midnight by adjusting them to proper daytime hours in your macOS Calendar.

Instructions

修正错误的事件时间(从凌晨修正到正确时间)

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
calendarYes日历名称工作
datePatternYes目标日期模式,如:2025-07-10
correctionsYes时间修正列表

Implementation Reference

  • The main handler function that implements the logic for the 'fix-event-times' tool. It processes each correction by keyword, constructs new start/end datetimes using the provided datePattern, generates AppleScript to find matching events in the calendar, and updates their times using osascript.
    async fixEventTimes(args) {
      const { calendar = '工作', datePattern, corrections } = args;
      const results = [];
      let successCount = 0;
      let failCount = 0;
    
      for (const correction of corrections) {
        try {
          // 构建正确的日期时间
          const newStartDateTime = `${datePattern} ${correction.newStartTime}`;
          const newEndDateTime = `${datePattern} ${correction.newEndTime}`;
          
          const startInfo = this.formatDateForAppleScript(newStartDateTime);
          const endInfo = this.formatDateForAppleScript(newEndDateTime);
          
          const startTimeScript = this.generateTimeScript(startInfo, 'newStartTime');
          const endTimeScript = this.generateTimeScript(endInfo, 'newEndTime');
    
          const script = `
            tell application "Calendar"
              set theCalendar to calendar "${calendar}"
              set allEvents to every event of theCalendar
              set fixedCount to 0
              
              ${startTimeScript}
              ${endTimeScript}
              
              repeat with anEvent in allEvents
                if (summary of anEvent) contains "${correction.keyword}" then
                  set start date of anEvent to newStartTime
                  set end date of anEvent to newEndTime
                  set fixedCount to fixedCount + 1
                end if
              end repeat
              
              return fixedCount
            end tell
          `;
    
          const result = execSync(`osascript -e '${script}'`, { encoding: 'utf8' });
          const fixedCount = parseInt(result.trim()) || 0;
          
          if (fixedCount > 0) {
            results.push(`✅ "${correction.keyword}" - 修正了 ${fixedCount} 个事件到 ${correction.newStartTime}-${correction.newEndTime}`);
            successCount += fixedCount;
          } else {
            results.push(`⚠️ "${correction.keyword}" - 未找到匹配的事件`);
          }
        } catch (error) {
          results.push(`❌ "${correction.keyword}" - 修正失败: ${error.message}`);
          failCount++;
        }
      }
    
      return {
        content: [
          {
            type: 'text',
            text: `🔧 时间修正结果:\n成功修正: ${successCount}个事件\n失败: ${failCount}个修正\n\n详细结果:\n${results.join('\n')}`,
          },
        ],
      };
    }
  • The input schema defining the parameters for the 'fix-event-times' tool: calendar, datePattern, and corrections array with keyword and new times.
    inputSchema: {
      type: 'object',
      properties: {
        calendar: {
          type: 'string',
          description: '日历名称',
          default: '工作',
        },
        datePattern: {
          type: 'string',
          description: '目标日期模式,如:2025-07-10',
        },
        corrections: {
          type: 'array',
          items: {
            type: 'object',
            properties: {
              keyword: { type: 'string', description: '事件关键词' },
              newStartTime: { type: 'string', description: '新开始时间 HH:MM' },
              newEndTime: { type: 'string', description: '新结束时间 HH:MM' }
            },
            required: ['keyword', 'newStartTime', 'newEndTime']
          },
          description: '时间修正列表'
        }
      },
      required: ['calendar', 'datePattern', 'corrections'],
      additionalProperties: false,
    },
  • Registration of the 'fix-event-times' tool in the ListToolsRequestSchema response, providing name, description, and inputSchema.
    {
      name: 'fix-event-times',
      description: '修正错误的事件时间(从凌晨修正到正确时间)',
      inputSchema: {
        type: 'object',
        properties: {
          calendar: {
            type: 'string',
            description: '日历名称',
            default: '工作',
          },
          datePattern: {
            type: 'string',
            description: '目标日期模式,如:2025-07-10',
          },
          corrections: {
            type: 'array',
            items: {
              type: 'object',
              properties: {
                keyword: { type: 'string', description: '事件关键词' },
                newStartTime: { type: 'string', description: '新开始时间 HH:MM' },
                newEndTime: { type: 'string', description: '新结束时间 HH:MM' }
              },
              required: ['keyword', 'newStartTime', 'newEndTime']
            },
            description: '时间修正列表'
          }
        },
        required: ['calendar', 'datePattern', 'corrections'],
        additionalProperties: false,
      },
    },
  • Dispatch/registration in the CallToolRequestSchema switch statement that routes calls to the fixEventTimes handler.
    case 'fix-event-times':
      return await this.fixEventTimes(args);
  • Helper function to parse date string into components for AppleScript date setting, used in fixEventTimes.
    formatDateForAppleScript(dateStr) {
      // 输入格式:YYYY-MM-DD HH:MM
      const [datePart, timePart] = dateStr.split(' ');
      const [year, month, day] = datePart.split('-').map(Number);
      const [hour, minute] = timePart.split(':').map(Number);
      
      if (!year || !month || !day || hour === undefined || minute === undefined) {
        throw new Error(`无效的日期格式: ${dateStr},请使用 YYYY-MM-DD HH:MM 格式`);
      }
      
      return {
        year,
        month,
        day,
        hour,
        minute
      };
    }
Behavior2/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

No annotations are provided, so the description carries the full burden. It states the tool corrects event times from midnight to correct times, implying a mutation operation, but lacks critical behavioral details: it doesn't specify permissions required, whether changes are reversible, how it handles multiple matching events, error conditions, or what the response looks like. For a mutation tool with zero annotation coverage, this is a significant gap in transparency.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness5/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is a single, efficient sentence in Chinese that directly states the tool's purpose without redundancy. It's front-loaded with the core action and resource, and there's no wasted verbiage. Every word earns its place, making it highly concise and well-structured for quick understanding.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness2/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Given the tool's complexity (a mutation operation with 3 required parameters), lack of annotations, and no output schema, the description is incomplete. It doesn't cover behavioral aspects like side effects, error handling, or response format, and it provides minimal usage guidance. For a tool that modifies calendar events, this leaves the agent under-informed about critical operational context.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters3/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Schema description coverage is 100%, so the schema already documents all three parameters (calendar, datePattern, corrections) with descriptions. The description adds no additional parameter semantics beyond implying the tool operates on events with incorrect times (e.g., midnight). Since the schema does the heavy lifting, the baseline score of 3 is appropriate, as the description provides minimal extra value.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose4/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states the action ('修正' meaning 'correct/fix') and the resource ('事件时间' meaning 'event times'), specifying it fixes incorrect times from midnight to correct times. It distinguishes from siblings like create-event or delete-events-by-keyword by focusing on correction rather than creation or deletion. However, it doesn't explicitly differentiate from all siblings (e.g., it could overlap with search-events in finding events).

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines2/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description provides minimal guidance: it implies usage when event times are incorrectly set to midnight. However, it offers no explicit when-to-use criteria, no prerequisites (e.g., requires existing events), no when-not-to-use warnings, and no alternatives among sibling tools (e.g., whether to use search-events first). This leaves the agent with insufficient context for optimal tool selection.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Install Server

Other 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