Google Workspace Code MCP Server

Local setup required. This server has to be cloned and prepared on your machine before you register it in Claude Code.
1

Set the server up locally

Run this once to clone and prepare the server before adding it to Claude Code.

Run in terminal
npm install
2

Register it in Claude Code

After the local setup is done, run this command to point Claude Code at the built server.

Run in terminal
claude mcp add google-workspace-code -- node "<FULL_PATH_TO_GOOGLE_WORKSPACE_MCP>/dist/index.js"

Replace <FULL_PATH_TO_GOOGLE_WORKSPACE_MCP>/dist/index.js with the actual folder you prepared in step 1.

README.md

A code-first MCP server to execute JS/TS with Google Workspace API access.

Google Workspace Code MCP

Important: This is an alternative experiment, not my primary setup

If you are looking for the Google Workspace integration I actually use day-to-day, use this skill instead:

This repository is an alternative code-first MCP experiment built around one execute tool. It is intentionally aligned with the ideas in:

That post explores code-supported/code-first MCP design (fewer fixed tools, more programmable capability).


A local JavaScript/TypeScript MCP server with a single tool: execute.

execute runs JavaScript (or TypeScript with type stripping) and gives that code authenticated access to Google Workspace APIs.

What this server does

  • Exposes one MCP tool: execute
  • Runs user-provided JavaScript/TypeScript (async function body; TS types stripped)
  • Automatically performs OAuth login on first use (browser flow)
  • Reuses stored tokens on subsequent calls
  • Provides a small runtime API inside executed code:
    • auth — Google OAuth client
    • googlegoogleapis SDK root
    • workspace — helper methods (call, service, whoAmI)
    • state — persistent mutable object across calls

This follows a code-mode design: one flexible execution tool instead of many fixed tools.

Requirements

  • Node.js 20+
  • Local desktop/browser access for the initial OAuth sign-in

Install

npm install

Run

npm start

or:

node src/server.js

MCP configuration

This repo already includes .mcp.json:

{
  "mcpServers": {
    "google-workspace-code": {
      "type": "stdio",
      "command": "node",
      "args": [
        "/Users/mitsuhiko/Development/workspace-mcp/src/server.js"
      ],
      "env": {
        "GOOGLE_WORKSPACE_AUTH_MODE": "cloud"
      }
    }
  }
}

If you move the project, update the args path.

Tool contract

Tool name

  • execute

Input schema

  • script (string, required): JavaScript/TypeScript async function body (TS type syntax is stripped before execution)
  • timeoutMs (number, optional): execution timeout in milliseconds (default 30000, max 300000)
  • scopes (string[], optional): override OAuth scopes for the call
  • resetState (boolean, optional): clears persistent state before execution

Execution environment

Your script runs as an async function body with these variables in scope:

  • auth
  • google
  • workspace
  • state

Return values are serialized and sent back as tool output.

Example scripts

1) Who am I + list Drive files

const me = await workspace.whoAmI();
const files = await workspace.call('drive', 'files.list', {
  pageSize: 5,
  fields: 'files(id,name,mimeType)'
});

state.lastEmail = me.email;

return {
  user: me,
  files: files.files,
  remembered: state.lastEmail
};

2) List today’s calendar events

const start = new Date();
start.setHours(0, 0, 0, 0);

const end = new Date(start);
end.setDate(end.getDate() + 1);

return await workspace.call('calendar', 'events.list', {
  calendarId: 'primary',
  timeMin: start.toISOString(),
  timeMax: end.toISOString(),
  singleEvents: true,
  orderBy: 'startTime'
});

OAuth and token storage

  • First call without token triggers browser login automatically
  • Default config directory: ~/.pi/google-workspace
  • Default token path: ~/.pi/google-workspace/token.json
  • Default auth mode: cloud (unless overridden)

Environment variables

  • GOOGLE_WORKSPACE_CONFIG_DIR
  • GOOGLE_WORKSPACE_CREDENTIALS
  • GOOGLE_WORKSPACE_TOKEN
  • GOOGLE_WORKSPACE_AUTH_MODE (cloud or local)
  • GOOGLE_WORKSPACE_CLIENT_ID
  • GOOGLE_WORKSPACE_CLOUD_FUNCTION_URL
  • GOOGLE_WORKSPACE_CALLBACK_HOST

Security notes

  • Uses Node vm for execution convenience, not a hardened sandbox.
  • Treat this as trusted local tooling.
  • Do not expose this server to untrusted users or networks.

Tools (1)

executeRuns user-provided JavaScript or TypeScript code with authenticated access to Google Workspace APIs.

Environment Variables

GOOGLE_WORKSPACE_CONFIG_DIRDirectory for configuration files
GOOGLE_WORKSPACE_CREDENTIALSPath to credentials file
GOOGLE_WORKSPACE_TOKENPath to token file
GOOGLE_WORKSPACE_AUTH_MODEAuthentication mode (cloud or local)
GOOGLE_WORKSPACE_CLIENT_IDGoogle OAuth client ID
GOOGLE_WORKSPACE_CLOUD_FUNCTION_URLURL for cloud function auth
GOOGLE_WORKSPACE_CALLBACK_HOSTHost for OAuth callback

Configuration

claude_desktop_config.json
{"mcpServers": {"google-workspace-code": {"type": "stdio", "command": "node", "args": ["/path/to/server.js"], "env": {"GOOGLE_WORKSPACE_AUTH_MODE": "cloud"}}}}

Try it

List the last 5 files from my Google Drive and return their names and IDs.
Find all calendar events scheduled for today and return them as a list.
Check my current Google Workspace identity and save my email address to the persistent state.
Execute a script to fetch my primary calendar events and filter for those occurring in the next 2 hours.

Frequently Asked Questions

What are the key features of Google Workspace Code MCP?

Single execute tool for flexible code-based interactions. Supports JavaScript and TypeScript execution. Automatic OAuth login and token management. Persistent state object shared across tool calls. Built-in runtime helpers for Google Workspace APIs.

What can I use Google Workspace Code MCP for?

Automating complex Google Calendar event retrieval and filtering. Batch processing or listing files in Google Drive. Building custom, programmable integrations with Google Workspace services. Managing persistent state across multiple AI-driven workspace tasks.

How do I install Google Workspace Code MCP?

Install Google Workspace Code MCP by running: npm install

What MCP clients work with Google Workspace Code MCP?

Google Workspace Code MCP works with any MCP-compatible client including Claude Desktop, Claude Code, Cursor, and other editors with MCP support.

Turn this server into reusable context

Keep Google Workspace Code MCP docs, env vars, and workflow notes in Conare so your agent carries them across sessions.

Need the old visual installer? Open Conare IDE.
Open Conare