Skip to content
API Reference

Google Workspace

Build an MCP server with Google Calendar and Drive tools using Keycard delegated access

Build an MCP server with Calendar and Drive tools that let AI agents manage a user’s Google Workspace on their behalf.

  1. Copy your Keycard redirect URL

    In Keycard Console, navigate to Zone Settings and copy the OAuth2 Redirect URL. You will need this when creating the Google OAuth App.

  2. Create a Google OAuth App

    In Google Cloud ConsoleAPIs & ServicesCredentials, create an OAuth 2.0 Client ID (application type: Web application). Add the redirect URL you copied from Keycard to Authorized redirect URIs. Note the Client ID and Client Secret.

    Also enable the Calendar API and Drive API under APIs & ServicesEnabled APIs.

  3. Add Google from Resource Catalog

    In Keycard Console, navigate to Resource Catalog and add Google Calendar and Google Drive. Enter the Client ID and Client Secret from step 2. This creates the Google OAuth provider and API resources.

  4. Register your MCP server Resource

    Navigate to ResourcesCreate Resource:

    FieldValue
    Resource NameGoogle Workspace MCP Server
    Resource Identifierhttp://localhost:8000/mcp
    Credential ProviderZone Provider
  5. Create an Application

    Navigate to ApplicationsCreate Application:

    FieldValue
    Provided ResourceGoogle Workspace MCP Server (your MCP server)
    DependenciesGoogle Calendar API, Google Drive API

    After creating the Application, generate client credentials and save them.

The implementation follows the same pattern as the GitHub server. The only difference is the API URL you pass to grant() and the API calls you make with the token.

Terminal window
pip install keycardai-fastmcp fastmcp httpx

Create a .env file:

Terminal window
KEYCARD_ZONE_ID=<your-zone-id>
MCP_SERVER_URL=http://localhost:8000
KEYCARD_CLIENT_ID=<your-client-id>
KEYCARD_CLIENT_SECRET=<your-client-secret>

The server setup is identical to GitHub: just change the server name. The tools file uses the same grant pattern with https://www.googleapis.com:

from keycardai.fastmcp import AccessContext, AuthProvider
GOOGLE_API = "https://www.googleapis.com"
def register_tools(mcp: FastMCP, auth_provider: AuthProvider):
@mcp.tool()
@auth_provider.grant(GOOGLE_API)
async def list_calendar_events(ctx: Context, calendar_id: str = "primary") -> dict:
"""List events from a Google Calendar."""
access_context: AccessContext = await ctx.get_state("keycardai")
token = access_context.access(GOOGLE_API).access_token
# Use token to call Google Calendar API
async with httpx.AsyncClient() as client:
response = await client.get(
f"{GOOGLE_API}/calendar/v3/calendars/{calendar_id}/events",
headers={"Authorization": f"Bearer {token}"},
params={"singleEvents": "true", "orderBy": "startTime"},
)
# ... process response
@mcp.tool()
@auth_provider.grant(GOOGLE_API)
async def list_drive_files(ctx: Context, q: str | None = None) -> dict:
"""List or search files in Google Drive."""
access_context: AccessContext = await ctx.get_state("keycardai")
token = access_context.access(GOOGLE_API).access_token
# Use token to call Google Drive API

See the full example with all tools, error handling, and Google Workspace file export logic: Python SDK examples

  1. Start your server

    Terminal window
    python server.py
  2. Configure your agent

    Add the MCP server to your agent configuration:

    Cursor: add to .cursor/mcp.json:

    {
    "mcpServers": {
    "google-mcp": {
    "url": "http://localhost:8000/mcp"
    }
    }
    }

    Claude Code: run in your terminal:

    Terminal window
    claude mcp add --transport http google-mcp http://localhost:8000/mcp
  3. Authenticate

    Restart your coding agent to detect the server. When prompted, complete the OAuth flow. Keycard will prompt you to sign in to your zone. This is a separate account from your Keycard Console login. If it’s your first time, click Sign up to create one. You will then be prompted to authorize Google Calendar and Drive access.

  4. Try these prompts:

    • “Show my calendar events for this week”
    • “List my recent Drive files”
    • “Get the content of the file named ‘Meeting Notes’”
  5. Verify in Audit Logs

    Check Keycard Console Audit Logs. You should see the same users:authenticate, users:authorize, and credentials:issue events, with the identity chain showing your user and the Google Application.