Skip to content
API Reference
Guides
MCP Servers
Delegated Access

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. Add Google from Resource Catalog

    In Keycard Console, navigate to Resource Catalog and add Google Calendar and Google Drive. This automatically creates the Google OAuth provider and API resources.

  2. Set up the Google OAuth App callback

    1. Go to Zone Settings in Keycard Console and copy the OAuth2 Redirect URL
    2. In Google Cloud ConsoleAPIs & ServicesCredentials, create or edit your OAuth 2.0 Client ID
    3. Add the Keycard redirect URL to Authorized redirect URIs
    4. Ensure the Calendar API and Drive API are enabled under APIs & ServicesEnabled APIs
  3. Register your MCP server resource

    Navigate to ResourcesCreate Resource:

    FieldValue
    Resource NameGoogle Workspace MCP Server
    Resource Identifierhttp://localhost:8000/mcp
    Credential ProviderZone Provider
  4. 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-mcp-fastmcp fastmcp httpx

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:

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

  2. Connect from Cursor and complete the OAuth flow — you will be prompted to authorize Google Calendar and Drive access

  3. Try these prompts:

    • “Show my calendar events for this week”
    • “List my recent Drive files”
    • “Get the content of the file named ‘Meeting Notes’”
  4. 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.