Google Calendar MCP Server

repository·main·Indexed 22 days ago

https://github.com/nspady/google-calendar-mcp

A Model Context Protocol (MCP) server providing Google Calendar integration for AI assistants like Claude. It supports multi-account and multi-calendar operations, including tools for listing, searching, creating, updating, and deleting events, as well as checking free/busy status. The server can be installed via npx, local source, or Docker, and requires a Google Cloud project with the Calendar API enabled and OAuth 2.0 credentials.

Tokens
21.2K
Snippets
61
Records
99
Agent score
76%

What's inside google-calendar-mcp

  1. Target specific accounts in tool calls

    main

    When calling MCP tools, you can control which account is used via the account parameter:

    • Omit account (Read-only tools): For tools like get-event or search-events, omitting the parameter causes the server to merge data from all authenticated accounts.
    • Omit account (Write tools): For tools like create-event, the server automatically selects the account with the highest permission (owner or writer) for the requested calendarId.
    • Single account: Pass a string (e.g., account: "work") to target one specific account.
    • Multiple accounts: Pass an array of strings (e.g., account: ["work", "personal"]) to limit the query to those specific accounts.
  2. Security and Token Storage

    main

    The server follows strict security protocols for managing credentials:

    • Permission Scopes: Requests only https://www.googleapis.com/auth/calendar (full calendar and event management). It does not request email, profile, or other Google service access.
    • Local Storage: Tokens are stored locally on your machine with owner-only permissions (0600) at ~/.config/google-calendar-mcp/tokens.json.
    • Privacy: Credentials never leave your machine, are never written to logs, and are not emitted over stdout or stderr.
  3. Use the `account` parameter in MCP tools

    main

    All tools in the Google Calendar MCP server support an optional account parameter to control which authenticated accounts are used for the operation. The parameter accepts a string (single account ID) or a string[] (array of account IDs).

    Parameter Behavior by Tool Type

    Tool TypeNo account paramSingle accountMultiple accounts
    Query (e.g., list-events, search-events)Merges results from all authenticated accountsFilters results to the specified accountMerges results from the specified accounts
    Mutation (e.g., create-event, update-event)Auto-selects the account with write access to the target calendarForces the operation to use the specified accountError: Operation is ambiguous
    Get (e.g., get-event)Tries all authenticated accountsUses the specified accountTries the specified accounts

    Example: Merging results from multiple accounts

    When using a query tool like list-events, providing an array of accounts will return a merged, chronologically sorted list of events from all specified sources.

    // Example tool parameter shape
    {
      "account": ["work", "personal"],
      "timeMin": "2023-01-01T00:00:00Z"
    }
  4. Choose a transport mode for the Google Calendar MCP Server

    main

    The server supports two transport modes depending on your deployment needs:

    1. stdio Transport (Default):

      • Best for local use only.
      • Used for direct communication with Claude Desktop.
      • No network exposure.
      • Handles authentication automatically.
    2. HTTP Transport:

      • Best for remote deployment and cloud environments.
      • Uses Server-Sent Events (SSE) for real-time communication.
      • Includes built-in security features like CORS support, health monitoring, graceful shutdown, and DNS rebinding protection (Origin Validation).
  5. How calendar deduplication works

    main

    The server implements a Unified Calendar Registry to handle cases where the same calendar is accessible via multiple authenticated accounts with different permission levels.

    Deduplication Logic

    1. Discovery: The server queries all authenticated accounts to aggregate available calendars.
    2. Grouping: Calendars are grouped by their unique calendarId (e.g., abc123@group.calendar.google.com).
    3. Permission Ranking: Permissions are ranked as follows:
      • owner (highest)
      • writer
      • reader (lowest)
    4. Write Operations: When a mutation (create/update/delete) is performed and no account is specified, the server automatically uses the preferredAccount (the one with the highest permission level for that specific calendar).
    5. Read Operations: Read operations can use any account that has access, though they prefer the preferredAccount for reliability.
  6. How the Tool Enhancement and Auto-Registration system works

    main

    The project uses an automated system to inject intelligent behaviors into MCP tools without modifying the core handler logic. This is achieved through a three-part mechanism:

    1. Configuration: You define which behaviors (e.g., ContextAware, DuplicateDetection) apply to which tools in config/tool-enhancements.ts.
    2. Auto-Discovery Registry: The ToolRegistry class automatically discovers handlers and wraps them with the configured behaviors during server startup.
    3. Behavior Injection: Behaviors intercept the tool arguments and inject additional data (like _context or _duplicateCheck) before they reach the handler's runTool method.

    This allows for 'Zero Handler Changes'—existing handlers receive enhanced arguments automatically based on the configuration.

    // 1. Configuration in config/tool-enhancements.ts
    export const toolEnhancements = {
      'create-event': [ContextAware, DuplicateDetection, SmartDefaults],
      'list-events': [ContextAware, PatternRecognition],
    };
    
    // 2. Registry application in tools/registry.ts
    export class ToolRegistry {
      static async registerAll(server: McpServer) {
        const handlers = await this.discoverHandlers();
        for (const [name, HandlerClass] of handlers) {
          const enhancements = toolEnhancements[name] || [];
          const enhancedHandler = this.applyEnhancements(HandlerClass, enhancements);
          server.tool(name, enhancedHandler.description, enhancedHandler.schema, 
            (args) => executeWithHandler(enhancedHandler, args)
          );
        }
      }
    }
    
    // 3. Usage in a handler
    export class CreateEventHandler extends BaseToolHandler {
      async runTool(args: any, oauth2Client: OAuth2Client) {
        const context = args._context; // Automatically injected by ContextAware
        const isLikelyDuplicate = args._duplicateCheck; // Automatically injected by DuplicateDetection
        // ... core logic
      }
    }
  7. Supported Transport Layers

    main

    The Google Calendar MCP server supports two transport mechanisms depending on your deployment needs:

    1. stdio (default): Used for direct process communication, typically when running locally with Claude Desktop.
    2. HTTP: A RESTful API using Server-Sent Events (SSE), suitable for remote deployments.
  8. Modify recurring events with different scopes

    main

    When updating recurring events, you can control the scope of the modification to target specific instances or the entire series:

    1. This event only: Modifies a single instance of the recurrence.
    2. This and following events: Modifies the event and all subsequent occurrences starting from a specific date.
    3. All events: Modifies every event in the entire series.

    The server supports all standard Google Calendar recurrence rules, including daily, weekly, monthly, yearly patterns, custom intervals (e.g., every 3 days), specific days (e.g., every Tuesday and Thursday), and end conditions (after N occurrences or by date).

  9. How multi-account support works with tools

    main

    The server supports multiple authenticated Google accounts (e.g., work, personal). Tools behave differently depending on whether they are 'multi-account' or 'single-account' tools.

    Multi-account tools

    These tools (e.g., list-events, list-calendars, search-events, get-freebusy) accept either a single account string or an array of account strings via the account parameter.

    • Omit account: Queries all authenticated accounts and merges the results.
    • account: "name": Queries only that specific account.
    • account: ["name1", "name2"]: Queries and merges the specified accounts.

    Single-account tools

    These tools (e.g., create-event, update-event, delete-event, get-event, get-current-time, list-colors) accept only one account.

    • Omit account: The server auto-selects the best account. For write tools, it picks the account with write permission to the target calendar.
    • account: "name": Uses that specific account.
    // Read-only: Query all accounts (auto-merge)
    use_tool("list-events", {
      timeMin: "2025-02-01T00:00:00",
      timeMax: "2025-02-01T23:59:59"
    });
    
    // Read-only: Query specific accounts
    use_tool("list-events", {
      account: ["work", "personal"],
      timeMin: "2025-02-01T00:00:00",
      timeMax: "2025-02-01T23:59:59"
    });
    
    // Write: Explicitly pick account (must be a single string)
    use_tool("create-event", {
      calendarId: "team@company.com",
      summary: "Status update",
      account: "work",
      start: "2025-02-01T10:00:00",
      end: "2025-02-01T11:00:00"
    });
    
    // Write: Auto-select account (finds account with write access)
    use_tool("create-event", {
      calendarId: "team@company.com",
      summary: "Status update",
      start: "2025-02-01T10:00:00",
      end: "2025-02-01T11:00:00"
    });
  10. Install Google Calendar MCP locally

    main

    To install the server from source:

    git clone https://github.com/nspady/google-calendar-mcp.git
    cd google-calendar-mcp
    npm install
    npm run build

    After building, add it to your Claude Desktop configuration using the local path or by specifying the GOOGLE_OAUTH_CREDENTIALS environment variable.

    git clone https://github.com/nspady/google-calendar-mcp.git
    cd google-calendar-mcp
    npm install
    npm run build
  11. Extract event data from images

    main

    The server can process screenshots (PNG, JPEG, GIF) to extract calendar information. This is useful for adding events from captured UI elements.

    Supported extractions:

    • Date and time information
    • Event titles and descriptions
    • Location details
    • Attendee lists

    Best Practices for Image Recognition:

    • Ensure text is clear and readable.
    • Include full date/time information in the image.
    • Highlight or circle important details.
    • Use high contrast images.