Description

The Google Calendar integration connects a Google account to Kommander through OAuth 2.0. The shipped routes are /api/integrations/google-calendar/authorize and /api/integrations/google-calendar/callback; after consent, Kommander stores a refresh token in the user’s calendar MCP server configuration and uses it to check availability, create meetings, and read upcoming events.

Kommander also supports Microsoft 365 / Outlook with the same tools, event types, and public booking page. A context has one active calendar: choose the provider under Integrations > Calendar. Connecting one provider replaces the other while keeping availability settings, event types, and booking keywords.

The current calendar tools are intentionally focused on scheduling basics:

ToolPurposeGoogle Calendar API surface
calendar_check_availabilityFind open business-hour slots on a requested date.freeBusy.query
calendar_create_meetingCreate a calendar event, invite an attendee, and request a Google Meet link.events.insert with conferenceDataVersion=1
calendar_list_upcomingRead upcoming events from the connected calendar.events.list

Prerequisites

  • A Google Cloud project with the Google Calendar API enabled.
  • An OAuth client of type Web application.
  • A deployed Kommander URL that Google can redirect back to.
  • AUTH_SECRET configured as the server-side OAuth state signing secret.
  • CREDENTIAL_ENCRYPTION_KEY (or ENCRYPTION_KEY) configured so refresh tokens can be stored encrypted.
  • GOOGLE_CALENDAR_CLIENT_ID and GOOGLE_CALENDAR_CLIENT_SECRET configured on the Kommander server.
  • A Kommander user with access to the integration settings page. In organizations the user must be an admin or manager with the manage_integrations permission.

The OAuth client belongs to the Kommander deployment. Each user connects their own calendar account from Integrations > Google Calendar; they do not need to create separate Google Cloud credentials.

OAuth 2.0 Setup

Representative Google Calendar setup screen with OAuth status and connect button.
Google Calendar setup starts an OAuth authorization and stores the connected account status.
  1. Open Google Cloud Console and create or select the project used by the Kommander deployment.
  2. Enable Google Calendar API for the project.
  3. Configure the OAuth consent screen with the app name, support email, authorized domains, and the test or production users who can grant consent.
  4. Create OAuth client ID > Web application credentials.
  5. Add this authorized redirect URI, replacing the host with the deployed app host:
https://app.example.com/api/integrations/google-calendar/callback
  1. Add the credentials to the Kommander runtime:
AUTH_SECRET=... CREDENTIAL_ENCRYPTION_KEY=... GOOGLE_CALENDAR_CLIENT_ID=... GOOGLE_CALENDAR_CLIENT_SECRET=... GOOGLE_CALENDAR_ID=primary NEXT_PUBLIC_BASE_URL=https://app.example.com
  1. Restart the server so /api/integrations/google-calendar/authorize can read the credentials.
  2. In Kommander, open Integrations > Calendar, enable the toggle, select Google Calendar, and click Connect with Google Calendar.
  3. Complete the Google consent prompt using the account that owns or can access the target calendar.
  4. After Google redirects back, confirm the integration shows as connected and run a scheduling prompt that checks availability.

Authentication Flow

The authorize route requests access_type=offline and prompt=consent so Google can return a refresh token. The callback route exchanges the authorization code server-side, updates or creates a calendar MCP server with provider: "google_calendar", clears cached MCP server instances, and redirects back to /integrations.

Calendar API Permissions

Kommander requests these Google Calendar scopes:

ScopeWhy it is neededUsed by
https://www.googleapis.com/auth/calendar.readonlyReads calendar metadata and event data needed for upcoming-event views and availability context.calendar_list_upcoming, calendar read operations
https://www.googleapis.com/auth/calendar.eventsCreates and updates events on calendars the connected account can write to.calendar_create_meeting

Release 1 requests both scopes because operator calendar writes and MCP meeting creation are part of the same rollout. If a future deployment needs read-only calendar access, change the authorize route scopes and remove write tools before asking users to grant consent. If production users outside your Google Workspace will connect calendars, complete Google’s OAuth verification process for the requested scopes.

Runtime Configuration

SettingRequiredNotes
CREDENTIAL_ENCRYPTION_KEYYes32-byte key (hex, base64, or utf8) that encrypts stored refresh tokens. Without it the OAuth callback cannot save the connection. Use the same key for every deployment sharing a database.
AUTH_SECRETYesRequired server secret from T18. It signs Google Calendar OAuth state and must be at least 32 bytes of entropy. NEXTAUTH_SECRET is only a legacy fallback for state verification.
GOOGLE_CALENDAR_CLIENT_IDYesOAuth client ID used by /api/integrations/google-calendar/authorize.
GOOGLE_CALENDAR_CLIENT_SECRETYesServer-side secret used by /api/integrations/google-calendar/callback and refresh-token exchange.
GOOGLE_CALENDAR_IDNoDefaults to primary; can point to a specific calendar ID for environment-level calendar configs.
NEXT_PUBLIC_BASE_URL or NEXTAUTH_URLRecommendedUsed to build the callback URL. If neither is set, the request origin is used.
Authorized redirect URIYesMust exactly match {baseUrl}/api/integrations/google-calendar/callback in Google Cloud.

For app-level fallback configuration, Kommander can also read GOOGLE_CALENDAR_REFRESH_TOKEN. User-connected OAuth from the integrations page stores the refresh token in chatbot_settings.mcpServers instead.

Availability Rules And Read-Only Events

Kommander computes availability from the connected Google Calendar busy data plus the assistant’s saved availability settings. The operator and MCP availability paths use the same provider logic:

  • Working ranges are evaluated in the requested IANA timezone.
  • Disabled working days produce no slots.
  • Blackout dates remove all slots for that local date.
  • Minimum notice removes slots that start too soon.
  • Buffers block time before and after busy events.
  • Daily caps stop returning slots once the configured number of Kommander-managed bookings exists for that local day.
  • Existing busy events, all-day events, recurring instances, cancelled instances, and DST boundaries are handled before returning available slots.
  • Create and update operations re-check availability immediately before writing; raced requests for the same slot must produce one winner and a CALENDAR_SLOT_UNAVAILABLE loser.

Google events that were not created or tagged by Kommander are read-only inside Kommander. Operators can view provider, all-day, and recurring events across calendar views, but edits and cancellations stay in Google unless the event has Kommander provenance. The API returns CALENDAR_EVENT_READ_ONLY when a write targets an unmanaged or provider-denied event.

Privacy

Kommander stores only the integration data needed to operate the calendar connection:

  • OAuth refresh tokens are stored in the assistant calendar MCP server configuration and prepared through the existing credential-storage path.
  • Event reads are fetched from Google for the requested range; the operator calendar surfaces event title, time range, meeting link, recurrence/all-day status, attendee metadata when present, and Kommander provenance.
  • Provider event bodies, credentials, attendee PII, and stack traces must not be returned to clients or logs. Calendar routes use stable redacted error codes, and logs use redactErrorForLog.
  • External visitor chat flows hide calendar_list_upcoming so visitors cannot inspect existing calendar events.
  • External visitor chat flows also hide event updates. When active event types exist, they replace generic meeting creation so paid pricing cannot be bypassed.
  • Disconnecting Google Calendar clears the stored refresh token from the MCP config but does not delete events in Google.

Event Reading Example

Assistant flows should read upcoming events through the calendar MCP tool instead of calling Google directly:

{ "tool": "calendar_list_upcoming", "arguments": { "limit": "5" } }

Expected result shape:

{ "meetings": [ { "id": "google-event-id", "title": "Discovery call", "start": "2026-05-18T09:00:00+02:00", "end": "2026-05-18T09:30:00+02:00", "meeting_link": "https://meet.google.com/..." } ], "total": 1, "provider": "google_calendar" }

Event Creation Example

Use calendar_create_meeting when a customer has agreed to a concrete time. Pass ISO 8601 times and the customer’s timezone when known.

{ "tool": "calendar_create_meeting", "arguments": { "title": "Product demo with Ada Lovelace", "start_time": "2026-05-18T10:00:00+02:00", "duration_minutes": "30", "description": "Demo requested from the website chat.", "attendee_email": "ada@example.com", "attendee_name": "Ada Lovelace", "timezone": "Europe/Rome" } }

The provider creates the event on the configured calendar, sends attendee updates, and asks Google Calendar to attach a Google Meet conference link.

Chat Booking Keywords

Clients can customize the phrases that explicitly start the booking flow from Integrations > Calendar > Booking keywords or Settings > Trigger keywords > Calendar booking. Keywords are grouped by language and use the shared Match keywords across all languages preference.

When a visitor message contains a configured phrase, the agent prioritizes Calendar over the contact form and begins collecting the missing booking details. The phrase does not bypass connection or payment requirements:

  • Calendar must be enabled and have a stored Google refresh token.
  • Paid event types still require a ready Stripe Connect account.
  • Follow-up messages can continue the active booking conversation without repeating the keyword.

Event types add a structured booking flow to the calendar tools:

  1. calendar_list_event_types returns active booking types, duration, price, and public booking URL.
  2. calendar_check_event_type_availability applies the selected type’s duration and the shared availability rules.
  3. After the customer confirms the type, price, date, and time, calendar_create_event_type_booking creates the booking.
  4. Free bookings are confirmed immediately. Paid bookings return a Stripe-hosted checkout_url and remain pending_payment.
  5. The Stripe Connect webhook confirms the calendar booking and adds the attendee only after payment succeeds.

Paid Checkout runs on the organization’s connected Stripe account. The slot is held while Checkout is open, and failed, cancelled, or expired payment sessions release the calendar hold.

Availability Example

Availability checks use Google Calendar freeBusy data for the configured calendar and return open slots during the provider’s business-hour window.

{ "tool": "calendar_check_availability", "arguments": { "date": "2026-05-18", "timezone": "Europe/Rome", "duration_minutes": "30" } }

Webhook Setup For Calendar Changes

Google Calendar calls webhooks “push notifications”. They are useful when Kommander needs to react to external calendar edits, cancellations, or new events without polling.

Recommended setup:

  1. Create an HTTPS route such as /api/integrations/google-calendar/webhook.
  2. Store a per-channel record with channelId, resourceId, calendarId, connected userId, expiration time, and a shared verification token.
  3. Call Google Calendar events.watch after OAuth connection or from a scheduled renewal job.
  4. Validate each notification’s X-Goog-Channel-ID, X-Goog-Resource-ID, and X-Goog-Channel-Token headers.
  5. Treat notifications as change signals only. Fetch the changed event list from Google Calendar using events.list with a stored syncToken.
  6. Renew channels before expiration and call channels.stop when a user disconnects Google Calendar.

Minimal watch request shape:

const channelId = crypto.randomUUID(); const response = await fetch( `https://www.googleapis.com/calendar/v3/calendars/${encodeURIComponent(calendarId)}/events/watch`, { method: 'POST', headers: { Authorization: `Bearer ${accessToken}`, 'Content-Type': 'application/json', }, body: JSON.stringify({ id: channelId, type: 'web_hook', address: 'https://app.example.com/api/integrations/google-calendar/webhook', token: signedChannelToken, }), }, );

Common Errors

Calendar routes return stable error codes with the same value in error and error_code. OAuth callback errors are surfaced in /integrations?gcal_error={code}.

Stable codeSurfaceMeaning
calendar_access_deniedOAuth/provider/MCPGoogle authorization was denied or the provider denied access.
calendar_auth_errorOAuth/provider/MCPToken refresh, OAuth, unauthorized, or forbidden provider failure.
calendar_config_errorOAuth/provider/MCPMissing OAuth credentials, missing refresh token, or missing state secret or credential encryption key.
calendar_forbiddenOAuthThe user lacks manage_integrations for the requested context.
calendar_invalid_requestOAuth/provider/MCPMissing or malformed request parameters.
CALENDAR_INVALID_TIMEZONEProvider/MCPInvalid IANA timezone.
calendar_invalid_stateOAuthOAuth state was tampered with, replayed, expired, or for the wrong context/user.
calendar_not_authenticatedOAuth/provider/MCPUser session is missing.
calendar_provider_errorOAuth/provider/MCPRedacted fallback for unexpected provider failure.
calendar_slot_unavailableProvider/MCPRequested slot failed availability or race-condition enforcement.
calendar_token_exchange_failedOAuthGoogle code exchange failed or no refresh token was returned.
CALENDAR_EVENT_READ_ONLYHTTP API/UIWrite attempted against an unmanaged/provider read-only event.
CALENDAR_FORBIDDENHTTP API/UIUser lacks the required calendar permission for the context.
CALENDAR_INVALID_REQUESTHTTP API/UIRequest body, query, range, event id, or patch is invalid.
CALENDAR_NOT_AUTHENTICATEDHTTP API/UIUser session is missing.
CALENDAR_NOT_CONNECTEDHTTP API/UINo enabled calendar MCP config (Google or Microsoft) with a refresh token exists for the context.
CALENDAR_PROVIDER_ERRORHTTP API/UIRedacted fallback for provider failure.
CALENDAR_SLOT_UNAVAILABLEHTTP API/UISlot conflict or availability rule rejection.
tool_budget_exceededMCPTool-call budget exhausted before execution.
tool_circuit_openMCPTool circuit breaker is open.
tool_connector_execution_errorMCPConnector execution failed.
tool_execution_errorMCPGeneric tool execution failure.
tool_identity_requiredMCPRequired identity binding is missing.
tool_rate_limitedMCPTool call was rate limited.
tool_response_too_largeMCPTool response exceeded size limits.
tool_ssrf_blockedMCPSSRF protection blocked the request.
tool_timeoutMCPTool execution timed out.
tool_unavailableMCPTool/provider is unavailable or misconfigured.
tool_unknownMCPUnknown tool name.

Common setup symptoms:

Error or symptomLikely causeSolution
redirect_uri_mismatch in Google OAuthThe Google Cloud redirect URI does not exactly match the runtime callback URL.Compare Google Cloud’s authorized redirect URI with {NEXT_PUBLIC_BASE_URL}/api/integrations/google-calendar/callback. Scheme, host, path, and trailing slash must match.
/integrations?gcal_error=calendar_invalid_requestGoogle redirected without code or state.Restart the OAuth flow from the integrations page and check whether a proxy stripped query parameters.
/integrations?gcal_error=calendar_invalid_stateThe callback state value was invalid, expired, replayed, or for another context.Start the connection from Kommander and repeat consent in the same authenticated browser.
calendar_forbidden (You need the Manage integrations permission…) when clicking ConnectThe organization member lacks manage_integrations. Before this error code existed it surfaced as calendar_invalid_state.Run npm run migrate:manage-integrations-permission for that environment’s database or grant the permission.
gcal_error=calendar_config_error after consentCREDENTIAL_ENCRYPTION_KEY / ENCRYPTION_KEY is missing, so the refresh token cannot be stored.Set the key, restart, and connect again.
/integrations?gcal_error=calendar_not_authenticatedThe user session was missing on callback.Sign in again, keep cookies enabled for the app domain, and repeat consent in the same browser.
/integrations?gcal_error=calendar_token_exchange_failedGoogle did not return a refresh token or rejected the code exchange.Ensure access_type=offline and prompt=consent are used, remove the old app grant from the Google account, then reconnect.
Availability appears empty or wrongThe wrong calendar ID, timezone, or account was connected.Confirm GOOGLE_CALENDAR_ID or user config is primary or the intended calendar ID, and pass the customer’s timezone in tool calls.
Webhook notifications never arriveGoogle cannot reach the webhook URL or the channel expired.Use a public HTTPS URL, persist channel expiration, renew channels before expiry, and verify notification headers.

Limitations

  • OAuth tokens are tied to the account that completed consent.
  • The built-in provider uses a simple business-hours availability model and does not expose advanced scheduling rules.
  • Event creation targets one configured calendar and one optional attendee.
  • Webhook push notifications require an additional endpoint and channel persistence layer before use.
  • Advanced calendar features such as recurring event management, room resources, multi-calendar conflict resolution, and domain-wide delegation are out of scope for this guide.