create_calendar_event
Create new calendar events with title, time, duration, category, and optional stamina tracking to organize schedules systematically.
Instructions
새로운 캘린더 이벤트를 생성합니다.
Args:
title: 이벤트 제목
start_time: 시작 시간 (ISO 형식: 2025-08-02T10:00:00)
duration: 지속 시간(분)
category: 카테고리 (STUDY, WORK, REST, ACTIVITY)
description: 이벤트 설명 (선택)
location: 장소 (선택)
stamina_cost: 스태미나 소모량 (기본값: 0)
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| title | Yes | ||
| start_time | Yes | ||
| duration | Yes | ||
| category | Yes | ||
| description | No | ||
| location | No | ||
| stamina_cost | No |
Implementation Reference
- src/main.py:58-111 (handler)The primary handler function for the 'create_calendar_event' MCP tool. It validates inputs, constructs a CalendarEventRequest, calls the CalendarService to create the event, and returns a CalendarEventResponse.@mcp.tool() def create_calendar_event( title: str, start_time: str, duration: int, category: str, description: Optional[str] = None, location: Optional[str] = None, stamina_cost: int = 0 ) -> CalendarEventResponse: """ 새로운 캘린더 이벤트를 생성합니다. Args: title: 이벤트 제목 start_time: 시작 시간 (ISO 형식: 2025-08-02T10:00:00) duration: 지속 시간(분) category: 카테고리 (STUDY, WORK, REST, ACTIVITY) description: 이벤트 설명 (선택) location: 장소 (선택) stamina_cost: 스태미나 소모량 (기본값: 0) """ try: # 카테고리 유효성 검사 if category not in [cat.value for cat in EventCategory]: raise InvalidEventData("category", category) # 시간 파싱 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 ) result = calendar_service.create_event(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-76 (schema)Pydantic model defining the input schema (CalendarEventRequest) used by the create_calendar_event handler for validation and type definitions.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 categories for calendar events, used in input validation.class EventCategory(str, Enum): """이벤트 카테고리""" STUDY = "STUDY" # 학습 WORK = "WORK" # 업무 REST = "REST" # 휴식 ACTIVITY = "ACTIVITY" # 활동
- Helper method in CalendarService that implements the core event creation logic, including time conflict detection and in-memory storage.def create_event(self, request: CalendarEventRequest, user_id: int) -> McpResult: """새 이벤트 생성""" try: # 시간 충돌 검사 if self._has_time_conflict(request.start_time, request.duration, user_id): return McpResult( success=False, error="해당 시간에 이미 다른 일정이 있습니다" ) event = CalendarEvent( id=self.next_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 EventStatus.PLANNED, created_at=request.created_at or datetime.now() ) self.events_db[self.next_id] = event self.next_id += 1 return McpResult(success=True, data=event) except Exception as e: return McpResult(success=False, error=str(e))
- Helper method to convert internal CalendarEvent entity to the CalendarEventResponse used in tool output.def to_response(self, event: CalendarEvent) -> CalendarEventResponse: """Entity를 Response로 변환""" return CalendarEventResponse( id=event.id, title=event.title, description=event.description, location=event.location, start_time=event.start_time, duration=event.duration, category=event.category, stamina_cost=event.stamina_cost, status=event.status, stamina_after_completion=event.stamina_after_completion, created_at=event.created_at )