calendar

package
v0.3.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 17, 2026 License: MIT Imports: 13 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// CalendarEventListFields contains fields for event listings (compact format)
	CalendarEventListFields = "nextPageToken,items(id,summary,status,start,end,location,htmlLink,hangoutLink,eventType)"
	// CalendarEventGetFields contains fields for single event retrieval (full format)
	CalendarEventGetFields = "" /* 176-byte string literal not displayed */
	// CalendarListFields contains fields for calendar list
	CalendarListFields = "items(id,summary,description,primary,backgroundColor,accessRole,timeZone)"
)

Calendar API field constants for optimized responses. These reduce response payload size by only requesting needed fields.

Variables

View Source
var DefaultCalendarHandlerDeps = common.NewDefaultHandlerDeps(NewCalendarService)

DefaultCalendarHandlerDeps holds the default dependencies for production use. Initialize with InitDefaultCalendarHandlerDeps after SetDeps to pass deps explicitly.

Functions

func InitDefaultCalendarHandlerDeps added in v0.1.7

func InitDefaultCalendarHandlerDeps(appDeps *common.Deps)

InitDefaultCalendarHandlerDeps initializes the default Calendar handler deps with explicit deps, avoiding reliance on the global singleton at call time.

func RegisterTools

func RegisterTools(s *server.MCPServer)

RegisterTools registers all Calendar tools with the MCP server.

func ResetCalendarIDCounter

func ResetCalendarIDCounter()

ResetCalendarIDCounter resets the event ID counter for predictable IDs in tests.

func TestableCalendarCreateEvent

func TestableCalendarCreateEvent(ctx context.Context, request mcp.CallToolRequest, deps *CalendarHandlerDeps) (*mcp.CallToolResult, error)

TestableCalendarCreateEvent is the testable version of handleCalendarCreateEvent.

func TestableCalendarCreateFocusTime added in v0.1.6

func TestableCalendarCreateFocusTime(ctx context.Context, request mcp.CallToolRequest, deps *CalendarHandlerDeps) (*mcp.CallToolResult, error)

TestableCalendarCreateFocusTime creates a Focus Time event with auto-decline.

func TestableCalendarCreateOutOfOffice added in v0.1.6

func TestableCalendarCreateOutOfOffice(ctx context.Context, request mcp.CallToolRequest, deps *CalendarHandlerDeps) (*mcp.CallToolResult, error)

TestableCalendarCreateOutOfOffice creates an Out of Office event.

func TestableCalendarDeleteEvent

func TestableCalendarDeleteEvent(ctx context.Context, request mcp.CallToolRequest, deps *CalendarHandlerDeps) (*mcp.CallToolResult, error)

TestableCalendarDeleteEvent is the testable version of handleCalendarDeleteEvent.

func TestableCalendarFreeBusy

func TestableCalendarFreeBusy(ctx context.Context, request mcp.CallToolRequest, deps *CalendarHandlerDeps) (*mcp.CallToolResult, error)

TestableCalendarFreeBusy - Query free/busy information for calendars

func TestableCalendarGetEvent

func TestableCalendarGetEvent(ctx context.Context, request mcp.CallToolRequest, deps *CalendarHandlerDeps) (*mcp.CallToolResult, error)

TestableCalendarGetEvent is the testable version of handleCalendarGetEvent.

func TestableCalendarListCalendars

func TestableCalendarListCalendars(ctx context.Context, request mcp.CallToolRequest, deps *CalendarHandlerDeps) (*mcp.CallToolResult, error)

TestableCalendarListCalendars - List all calendars the user has access to

func TestableCalendarListEvents

func TestableCalendarListEvents(ctx context.Context, request mcp.CallToolRequest, deps *CalendarHandlerDeps) (*mcp.CallToolResult, error)

TestableCalendarListEvents is the testable version of handleCalendarListEvents.

func TestableCalendarListInstances

func TestableCalendarListInstances(ctx context.Context, request mcp.CallToolRequest, deps *CalendarHandlerDeps) (*mcp.CallToolResult, error)

TestableCalendarListInstances - List instances of a recurring event

func TestableCalendarQuickAdd

func TestableCalendarQuickAdd(ctx context.Context, request mcp.CallToolRequest, deps *CalendarHandlerDeps) (*mcp.CallToolResult, error)

TestableCalendarQuickAdd creates an event from natural language string.

func TestableCalendarUpdateEvent

func TestableCalendarUpdateEvent(ctx context.Context, request mcp.CallToolRequest, deps *CalendarHandlerDeps) (*mcp.CallToolResult, error)

TestableCalendarUpdateEvent is the testable version of handleCalendarUpdateEvent.

func TestableCalendarUpdateInstance

func TestableCalendarUpdateInstance(ctx context.Context, request mcp.CallToolRequest, deps *CalendarHandlerDeps) (*mcp.CallToolResult, error)

TestableCalendarUpdateInstance - Update a single instance of a recurring event

Types

type CalendarHandlerDeps

type CalendarHandlerDeps = common.HandlerDeps[CalendarService]

Type alias using generic types from common package.

type CalendarService

type CalendarService interface {
	// Calendars
	ListCalendars(ctx context.Context, fields string) (*calendar.CalendarList, error)

	// Events
	ListEvents(ctx context.Context, calendarID string, opts *ListEventsOptions) (*calendar.Events, error)
	GetEvent(ctx context.Context, calendarID string, eventID string, fields string) (*calendar.Event, error)
	CreateEvent(ctx context.Context, calendarID string, event *calendar.Event, conferenceDataVersion int) (*calendar.Event, error)
	UpdateEvent(ctx context.Context, calendarID string, eventID string, event *calendar.Event) (*calendar.Event, error)
	DeleteEvent(ctx context.Context, calendarID string, eventID string) error
	QuickAddEvent(ctx context.Context, calendarID string, text string) (*calendar.Event, error)

	// Recurring Events
	ListInstances(ctx context.Context, calendarID string, eventID string, opts *ListInstancesOptions) (*calendar.Events, error)

	// FreeBusy
	GetFreeBusy(ctx context.Context, req *calendar.FreeBusyRequest) (*calendar.FreeBusyResponse, error)
}

CalendarService defines the interface for Calendar API operations. This interface enables dependency injection and testing with mocks.

func NewCalendarService

func NewCalendarService(ctx context.Context, client *http.Client) (CalendarService, error)

NewCalendarService creates a CalendarService from an authenticated HTTP client.

func ResolveCalendarServiceOrError

func ResolveCalendarServiceOrError(ctx context.Context, request mcp.CallToolRequest, deps *CalendarHandlerDeps) (CalendarService, *mcp.CallToolResult, bool)

ResolveCalendarServiceOrError resolves a Calendar service, returning an MCP error result on failure.

type CalendarTestFixtures

type CalendarTestFixtures struct {
	DefaultEmail string
	MockService  *MockCalendarService
	Deps         *CalendarHandlerDeps
}

CalendarTestFixtures provides pre-configured test data for Calendar tests.

func NewCalendarTestFixtures

func NewCalendarTestFixtures() *CalendarTestFixtures

NewCalendarTestFixtures creates a new test fixtures instance with default configuration.

type ListEventsOptions

type ListEventsOptions struct {
	MaxResults   int64
	PageToken    string
	TimeMin      string // RFC3339 timestamp
	TimeMax      string // RFC3339 timestamp
	SingleEvents bool   // Expand recurring events
	OrderBy      string // "startTime" or "updated"
	Query        string // Free text search
	ShowDeleted  bool
	UpdatedMin   string   // RFC3339 timestamp
	Fields       string   // Selector specifying which fields to include in a partial response
	EventTypes   []string // Filter by event types (e.g., "default", "focusTime", "outOfOffice")
}

ListEventsOptions contains optional parameters for listing events.

type ListInstancesOptions

type ListInstancesOptions struct {
	MaxResults int64
	PageToken  string
	TimeMin    string // RFC3339 timestamp
	TimeMax    string // RFC3339 timestamp
	Fields     string // Selector specifying which fields to include in a partial response
}

ListInstancesOptions contains optional parameters for listing recurring event instances.

type MethodCall

type MethodCall = common.MethodCall

MethodCall is an alias to the common.MethodCall for backward compatibility in tests

type MockCalendarService

type MockCalendarService struct {
	// Storage
	Calendars map[string]*calendar.CalendarListEntry
	Events    map[string]map[string]*calendar.Event // calendarID -> eventID -> event

	// Error injection for testing error handling
	Error error

	// Track method calls for verification
	MethodCalls []MethodCall
}

MockCalendarService is a mock implementation of CalendarService for testing.

func NewMockCalendarService

func NewMockCalendarService() *MockCalendarService

NewMockCalendarService creates a new mock Calendar service with empty storage.

func (*MockCalendarService) CreateEvent

func (m *MockCalendarService) CreateEvent(ctx context.Context, calendarID string, event *calendar.Event, conferenceDataVersion int) (*calendar.Event, error)

CreateEvent creates a new event.

func (*MockCalendarService) DeleteEvent

func (m *MockCalendarService) DeleteEvent(ctx context.Context, calendarID string, eventID string) error

DeleteEvent deletes an event.

func (*MockCalendarService) GetEvent

func (m *MockCalendarService) GetEvent(ctx context.Context, calendarID string, eventID string, fields string) (*calendar.Event, error)

GetEvent returns an event by ID.

func (*MockCalendarService) GetFreeBusy

GetFreeBusy queries free/busy information.

func (*MockCalendarService) ListCalendars

func (m *MockCalendarService) ListCalendars(ctx context.Context, fields string) (*calendar.CalendarList, error)

ListCalendars returns all calendars.

func (*MockCalendarService) ListEvents

func (m *MockCalendarService) ListEvents(ctx context.Context, calendarID string, opts *ListEventsOptions) (*calendar.Events, error)

ListEvents returns events from a calendar.

func (*MockCalendarService) ListInstances

func (m *MockCalendarService) ListInstances(ctx context.Context, calendarID string, eventID string, opts *ListInstancesOptions) (*calendar.Events, error)

ListInstances lists instances of a recurring event.

func (*MockCalendarService) QuickAddEvent

func (m *MockCalendarService) QuickAddEvent(ctx context.Context, calendarID string, text string) (*calendar.Event, error)

QuickAddEvent creates an event from text.

func (*MockCalendarService) UpdateEvent

func (m *MockCalendarService) UpdateEvent(ctx context.Context, calendarID string, eventID string, event *calendar.Event) (*calendar.Event, error)

UpdateEvent updates an existing event.

type RealCalendarService

type RealCalendarService struct {
	// contains filtered or unexported fields
}

RealCalendarService wraps the Calendar API client and implements CalendarService.

func NewRealCalendarService

func NewRealCalendarService(service *calendar.Service) *RealCalendarService

NewRealCalendarService creates a new RealCalendarService wrapping the given Calendar API service.

func (*RealCalendarService) CreateEvent

func (s *RealCalendarService) CreateEvent(ctx context.Context, calendarID string, event *calendar.Event, conferenceDataVersion int) (*calendar.Event, error)

CreateEvent creates a new calendar event.

func (*RealCalendarService) DeleteEvent

func (s *RealCalendarService) DeleteEvent(ctx context.Context, calendarID string, eventID string) error

DeleteEvent deletes a calendar event.

func (*RealCalendarService) GetEvent

func (s *RealCalendarService) GetEvent(ctx context.Context, calendarID string, eventID string, fields string) (*calendar.Event, error)

GetEvent retrieves a single event by ID.

func (*RealCalendarService) GetFreeBusy

GetFreeBusy queries free/busy information for a set of calendars.

func (*RealCalendarService) ListCalendars

func (s *RealCalendarService) ListCalendars(ctx context.Context, fields string) (*calendar.CalendarList, error)

ListCalendars lists all calendars the user has access to.

func (*RealCalendarService) ListEvents

func (s *RealCalendarService) ListEvents(ctx context.Context, calendarID string, opts *ListEventsOptions) (*calendar.Events, error)

ListEvents lists events from a calendar with optional filters.

func (*RealCalendarService) ListInstances

func (s *RealCalendarService) ListInstances(ctx context.Context, calendarID string, eventID string, opts *ListInstancesOptions) (*calendar.Events, error)

ListInstances lists instances of a recurring event.

func (*RealCalendarService) QuickAddEvent

func (s *RealCalendarService) QuickAddEvent(ctx context.Context, calendarID string, text string) (*calendar.Event, error)

QuickAddEvent creates an event from a natural language string.

func (*RealCalendarService) UpdateEvent

func (s *RealCalendarService) UpdateEvent(ctx context.Context, calendarID string, eventID string, event *calendar.Event) (*calendar.Event, error)

UpdateEvent updates an existing calendar event.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL