update_calendar_event
Modify existing calendar events by updating details like title, time, category, and status to keep schedules accurate and organized.
Instructions
기존 캘린더 이벤트를 수정합니다.
Args:
event_id: 수정할 이벤트 ID
title: 이벤트 제목
start_time: 시작 시간 (ISO 형식: 2025-08-02T10:00:00)
duration: 지속 시간(분)
category: 카테고리 (STUDY, WORK, REST, ACTIVITY)
description: 이벤트 설명 (선택)
location: 장소 (선택)
stamina_cost: 스태미나 소모량 (기본값: 0)
status: 이벤트 상태 (PLANNED, COMPLETED, CANCELED) (선택)
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| event_id | Yes | ||
| title | Yes | ||
| start_time | Yes | ||
| duration | Yes | ||
| category | Yes | ||
| description | No | ||
| location | No | ||
| stamina_cost | No | ||
| status | No |
Implementation Reference
- src/main.py:113-177 (handler)The primary handler function for the 'update_calendar_event' MCP tool. It performs input validation, parses datetime and enums, constructs CalendarEventRequest, delegates to CalendarService.update_event, and returns a CalendarEventResponse or raises exceptions.@mcp.tool() def update_calendar_event( event_id: int, title: str, start_time: str, duration: int, category: str, description: Optional[str] = None, location: Optional[str] = None, stamina_cost: int = 0, status: Optional[str] = None ) -> CalendarEventResponse: """ 기존 캘린더 이벤트를 수정합니다. Args: event_id: 수정할 이벤트 ID title: 이벤트 제목 start_time: 시작 시간 (ISO 형식: 2025-08-02T10:00:00) duration: 지속 시간(분) category: 카테고리 (STUDY, WORK, REST, ACTIVITY) description: 이벤트 설명 (선택) location: 장소 (선택) stamina_cost: 스태미나 소모량 (기본값: 0) status: 이벤트 상태 (PLANNED, COMPLETED, CANCELED) (선택) """ try: # 카테고리 유효성 검사 if category not in [cat.value for cat in EventCategory]: raise InvalidEventData("category", category) # 상태 유효성 검사 event_status = None if status and status not in [stat.value for stat in EventStatus]: raise InvalidEventData("status", status) elif status: event_status = EventStatus(status) # 시간 파싱 try: parsed_start_time = datetime.fromisoformat(start_time.replace('Z', '+00:00')) except ValueError: raise InvalidEventData("start_time", start_time) request = CalendarEventRequest( title=title, description=description, location=location, start_time=parsed_start_time, duration=duration, category=EventCategory(category), stamina_cost=stamina_cost, status=event_status ) result = calendar_service.update_event(event_id, request, DEFAULT_USER_ID) if result.success and result.data: return calendar_service.to_response(result.data) raise Exception(result.error or "이벤트 수정에 실패했습니다") except CalendarException: raise except Exception as e: raise Exception(f"이벤트 수정 중 오류가 발생했습니다: {str(e)}")
- src/models/__init__.py:55-75 (schema)Pydantic BaseModel used as the input schema for event updates. Defines fields with validation (e.g., duration > 0, datetime parsing) and is instantiated in the handler.class CalendarEventRequest(BaseModel): """캘린더 이벤트 생성/수정 요청""" title: str description: Optional[str] = None location: Optional[str] = None start_time: datetime duration: int = Field(gt=0, description="지속 시간(분)") category: EventCategory stamina_cost: int = Field(ge=0, default=0, description="스태미나 소모량") created_at: Optional[datetime] = None status: Optional[EventStatus] = None @field_validator('start_time', 'created_at') @classmethod def validate_datetime(cls, v): if v is None: return v if isinstance(v, str): return datetime.fromisoformat(v.replace('Z', '+00:00')) return v
- src/models/__init__.py:10-15 (schema)Enum defining valid event categories (STUDY, WORK, REST, ACTIVITY), validated in the handler and service.class EventCategory(str, Enum): """이벤트 카테고리""" STUDY = "STUDY" # 학습 WORK = "WORK" # 업무 REST = "REST" # 휴식 ACTIVITY = "ACTIVITY" # 활동
- src/models/__init__.py:18-22 (schema)Enum defining event statuses, optionally validated and set in updates.class EventStatus(str, Enum): """이벤트 상태""" PLANNED = "PLANNED" # 계획됨 COMPLETED = "COMPLETED" # 완료됨 CANCELED = "CANCELED" # 취소됨
- Supporting method in CalendarService that executes the core business logic: authorization check, time conflict detection, entity update in in-memory DB, and result wrapping.def update_event(self, event_id: int, request: CalendarEventRequest, user_id: int) -> McpResult: """이벤트 수정""" try: if event_id not in self.events_db: raise EventNotFound(event_id) existing_event = self.events_db[event_id] if existing_event.user_id != user_id: raise UnauthorizedAccess(user_id, event_id) # 시간 충돌 검사 (자기 자신 제외) if self._has_time_conflict(request.start_time, request.duration, user_id, exclude_id=event_id): return McpResult( success=False, error="해당 시간에 이미 다른 일정이 있습니다" ) updated_event = CalendarEvent( id=event_id, user_id=user_id, title=request.title, description=request.description, location=request.location, start_time=request.start_time, duration=request.duration, category=request.category, stamina_cost=request.stamina_cost, status=request.status or existing_event.status, stamina_after_completion=existing_event.stamina_after_completion, created_at=existing_event.created_at ) self.events_db[event_id] = updated_event return McpResult(success=True, data=updated_event) except CalendarException: raise except Exception as e: return McpResult(success=False, error=str(e))