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:
| Tool | Purpose | Google Calendar API surface |
|---|---|---|
calendar_check_availability | Find open business-hour slots on a requested date. | freeBusy.query |
calendar_create_meeting | Create a calendar event, invite an attendee, and request a Google Meet link. | events.insert with conferenceDataVersion=1 |
calendar_list_upcoming | Read 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_SECRETconfigured as the server-side OAuth state signing secret.CREDENTIAL_ENCRYPTION_KEY(orENCRYPTION_KEY) configured so refresh tokens can be stored encrypted.GOOGLE_CALENDAR_CLIENT_IDandGOOGLE_CALENDAR_CLIENT_SECRETconfigured 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_integrationspermission.
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
- Open Google Cloud Console and create or select the project used by the Kommander deployment.
- Enable Google Calendar API for the project.
- Configure the OAuth consent screen with the app name, support email, authorized domains, and the test or production users who can grant consent.
- Create OAuth client ID > Web application credentials.
- Add this authorized redirect URI, replacing the host with the deployed app host:
https://app.example.com/api/integrations/google-calendar/callback- 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- Restart the server so
/api/integrations/google-calendar/authorizecan read the credentials. - In Kommander, open Integrations > Calendar, enable the toggle, select Google Calendar, and click Connect with Google Calendar.
- Complete the Google consent prompt using the account that owns or can access the target calendar.
- 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:
| Scope | Why it is needed | Used by |
|---|---|---|
https://www.googleapis.com/auth/calendar.readonly | Reads 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.events | Creates 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
| Setting | Required | Notes |
|---|---|---|
CREDENTIAL_ENCRYPTION_KEY | Yes | 32-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_SECRET | Yes | Required 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_ID | Yes | OAuth client ID used by /api/integrations/google-calendar/authorize. |
GOOGLE_CALENDAR_CLIENT_SECRET | Yes | Server-side secret used by /api/integrations/google-calendar/callback and refresh-token exchange. |
GOOGLE_CALENDAR_ID | No | Defaults to primary; can point to a specific calendar ID for environment-level calendar configs. |
NEXT_PUBLIC_BASE_URL or NEXTAUTH_URL | Recommended | Used to build the callback URL. If neither is set, the request origin is used. |
| Authorized redirect URI | Yes | Must 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_UNAVAILABLEloser.
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_upcomingso 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.
Paid Chat Booking
Event types add a structured booking flow to the calendar tools:
calendar_list_event_typesreturns active booking types, duration, price, and public booking URL.calendar_check_event_type_availabilityapplies the selected type’s duration and the shared availability rules.- After the customer confirms the type, price, date, and time,
calendar_create_event_type_bookingcreates the booking. - Free bookings are confirmed immediately. Paid bookings return a Stripe-hosted
checkout_urland remainpending_payment. - 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.
The current repository ships OAuth authorize and callback routes, but it does not include a dedicated Google Calendar notification endpoint. Add and secure an endpoint before registering push notification channels in production.
Recommended setup:
- Create an HTTPS route such as
/api/integrations/google-calendar/webhook. - Store a per-channel record with
channelId,resourceId,calendarId, connecteduserId, expiration time, and a shared verification token. - Call Google Calendar
events.watchafter OAuth connection or from a scheduled renewal job. - Validate each notification’s
X-Goog-Channel-ID,X-Goog-Resource-ID, andX-Goog-Channel-Tokenheaders. - Treat notifications as change signals only. Fetch the changed event list from Google Calendar using
events.listwith a storedsyncToken. - Renew channels before expiration and call
channels.stopwhen 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 code | Surface | Meaning |
|---|---|---|
calendar_access_denied | OAuth/provider/MCP | Google authorization was denied or the provider denied access. |
calendar_auth_error | OAuth/provider/MCP | Token refresh, OAuth, unauthorized, or forbidden provider failure. |
calendar_config_error | OAuth/provider/MCP | Missing OAuth credentials, missing refresh token, or missing state secret or credential encryption key. |
calendar_forbidden | OAuth | The user lacks manage_integrations for the requested context. |
calendar_invalid_request | OAuth/provider/MCP | Missing or malformed request parameters. |
CALENDAR_INVALID_TIMEZONE | Provider/MCP | Invalid IANA timezone. |
calendar_invalid_state | OAuth | OAuth state was tampered with, replayed, expired, or for the wrong context/user. |
calendar_not_authenticated | OAuth/provider/MCP | User session is missing. |
calendar_provider_error | OAuth/provider/MCP | Redacted fallback for unexpected provider failure. |
calendar_slot_unavailable | Provider/MCP | Requested slot failed availability or race-condition enforcement. |
calendar_token_exchange_failed | OAuth | Google code exchange failed or no refresh token was returned. |
CALENDAR_EVENT_READ_ONLY | HTTP API/UI | Write attempted against an unmanaged/provider read-only event. |
CALENDAR_FORBIDDEN | HTTP API/UI | User lacks the required calendar permission for the context. |
CALENDAR_INVALID_REQUEST | HTTP API/UI | Request body, query, range, event id, or patch is invalid. |
CALENDAR_NOT_AUTHENTICATED | HTTP API/UI | User session is missing. |
CALENDAR_NOT_CONNECTED | HTTP API/UI | No enabled calendar MCP config (Google or Microsoft) with a refresh token exists for the context. |
CALENDAR_PROVIDER_ERROR | HTTP API/UI | Redacted fallback for provider failure. |
CALENDAR_SLOT_UNAVAILABLE | HTTP API/UI | Slot conflict or availability rule rejection. |
tool_budget_exceeded | MCP | Tool-call budget exhausted before execution. |
tool_circuit_open | MCP | Tool circuit breaker is open. |
tool_connector_execution_error | MCP | Connector execution failed. |
tool_execution_error | MCP | Generic tool execution failure. |
tool_identity_required | MCP | Required identity binding is missing. |
tool_rate_limited | MCP | Tool call was rate limited. |
tool_response_too_large | MCP | Tool response exceeded size limits. |
tool_ssrf_blocked | MCP | SSRF protection blocked the request. |
tool_timeout | MCP | Tool execution timed out. |
tool_unavailable | MCP | Tool/provider is unavailable or misconfigured. |
tool_unknown | MCP | Unknown tool name. |
Common setup symptoms:
| Error or symptom | Likely cause | Solution |
|---|---|---|
redirect_uri_mismatch in Google OAuth | The 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_request | Google 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_state | The 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 Connect | The 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 consent | CREDENTIAL_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_authenticated | The 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_failed | Google 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 wrong | The 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 arrive | Google 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.