add_alarm
Set alarms with natural language time input like 'tomorrow at 10am' or specific dates to receive notifications for important events through the MCP Reminder server.
Instructions
添加闹钟
Args: time: 闹钟时间,支持自然语言如"下午2点30分"、"明天上午10点"或精确时间"2025-09-02 14:30" description: 闹钟描述(可选)
Returns: 包含闹钟ID和确认信息的字典
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| time | Yes | ||
| description | No |
Implementation Reference
- src/mcp_reminder/server.py:34-71 (handler)The add_alarm tool implementation in src/mcp_reminder/server.py. It uses mcp.tool() to register the tool and handles the input validation, alarm creation, and storage.
@mcp.tool() def add_alarm(time: str, description: str = "") -> dict: """ 添加闹钟 Args: time: 闹钟时间,支持自然语言如"下午2点30分"、"明天上午10点"或精确时间"2025-09-02 14:30" description: 闹钟描述(可选) Returns: 包含闹钟ID和确认信息的字典 """ # 解析时间 parsed_time = parse_time(time) if not parsed_time: return { "success": False, "error": f"无法解析时间: {time},请使用如'下午2点30分'或'2025-09-02 14:30'格式" } # 创建闹钟 alarm = Alarm( time=parsed_time, description=description ) # 保存闹钟 storage.add_alarm(alarm) logger.info(f"添加闹钟: {alarm.time}, 描述: {alarm.description}") return { "success": True, "alarm_id": alarm.id, "time": alarm.time, "description": alarm.description, "message": f"闹钟已设置在 {alarm.time}" + (f": {description}" if description else "") }