google-workspace-mcp 2.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (75) hide show
  1. package/LICENSE +7 -0
  2. package/README.md +765 -0
  3. package/dist/accounts.d.ts +85 -0
  4. package/dist/accounts.d.ts.map +1 -0
  5. package/dist/accounts.js +520 -0
  6. package/dist/accounts.js.map +1 -0
  7. package/dist/auth.d.ts +4 -0
  8. package/dist/auth.d.ts.map +1 -0
  9. package/dist/auth.js +206 -0
  10. package/dist/auth.js.map +1 -0
  11. package/dist/cli.d.ts +3 -0
  12. package/dist/cli.d.ts.map +1 -0
  13. package/dist/cli.js +426 -0
  14. package/dist/cli.js.map +1 -0
  15. package/dist/errorHelpers.d.ts +40 -0
  16. package/dist/errorHelpers.d.ts.map +1 -0
  17. package/dist/errorHelpers.js +52 -0
  18. package/dist/errorHelpers.js.map +1 -0
  19. package/dist/googleDocsApiHelpers.d.ts +118 -0
  20. package/dist/googleDocsApiHelpers.d.ts.map +1 -0
  21. package/dist/googleDocsApiHelpers.js +850 -0
  22. package/dist/googleDocsApiHelpers.js.map +1 -0
  23. package/dist/googleSheetsApiHelpers.d.ts +75 -0
  24. package/dist/googleSheetsApiHelpers.d.ts.map +1 -0
  25. package/dist/googleSheetsApiHelpers.js +376 -0
  26. package/dist/googleSheetsApiHelpers.js.map +1 -0
  27. package/dist/server.d.ts +2 -0
  28. package/dist/server.d.ts.map +1 -0
  29. package/dist/server.js +119 -0
  30. package/dist/server.js.map +1 -0
  31. package/dist/serverWrapper.d.ts +21 -0
  32. package/dist/serverWrapper.d.ts.map +1 -0
  33. package/dist/serverWrapper.js +74 -0
  34. package/dist/serverWrapper.js.map +1 -0
  35. package/dist/tools/accounts.tools.d.ts +3 -0
  36. package/dist/tools/accounts.tools.d.ts.map +1 -0
  37. package/dist/tools/accounts.tools.js +154 -0
  38. package/dist/tools/accounts.tools.js.map +1 -0
  39. package/dist/tools/calendar.tools.d.ts +3 -0
  40. package/dist/tools/calendar.tools.d.ts.map +1 -0
  41. package/dist/tools/calendar.tools.js +487 -0
  42. package/dist/tools/calendar.tools.js.map +1 -0
  43. package/dist/tools/docs.tools.d.ts +3 -0
  44. package/dist/tools/docs.tools.d.ts.map +1 -0
  45. package/dist/tools/docs.tools.js +1766 -0
  46. package/dist/tools/docs.tools.js.map +1 -0
  47. package/dist/tools/drive.tools.d.ts +3 -0
  48. package/dist/tools/drive.tools.d.ts.map +1 -0
  49. package/dist/tools/drive.tools.js +1001 -0
  50. package/dist/tools/drive.tools.js.map +1 -0
  51. package/dist/tools/forms.tools.d.ts +3 -0
  52. package/dist/tools/forms.tools.d.ts.map +1 -0
  53. package/dist/tools/forms.tools.js +370 -0
  54. package/dist/tools/forms.tools.js.map +1 -0
  55. package/dist/tools/gmail.tools.d.ts +3 -0
  56. package/dist/tools/gmail.tools.d.ts.map +1 -0
  57. package/dist/tools/gmail.tools.js +520 -0
  58. package/dist/tools/gmail.tools.js.map +1 -0
  59. package/dist/tools/sheets.tools.d.ts +3 -0
  60. package/dist/tools/sheets.tools.d.ts.map +1 -0
  61. package/dist/tools/sheets.tools.js +521 -0
  62. package/dist/tools/sheets.tools.js.map +1 -0
  63. package/dist/tools/slides.tools.d.ts +3 -0
  64. package/dist/tools/slides.tools.d.ts.map +1 -0
  65. package/dist/tools/slides.tools.js +323 -0
  66. package/dist/tools/slides.tools.js.map +1 -0
  67. package/dist/types.d.ts +507 -0
  68. package/dist/types.d.ts.map +1 -0
  69. package/dist/types.js +185 -0
  70. package/dist/types.js.map +1 -0
  71. package/dist/urlHelpers.d.ts +60 -0
  72. package/dist/urlHelpers.d.ts.map +1 -0
  73. package/dist/urlHelpers.js +101 -0
  74. package/dist/urlHelpers.js.map +1 -0
  75. package/package.json +77 -0
package/README.md ADDED
@@ -0,0 +1,765 @@
1
+ # Google Workspace MCP Server
2
+
3
+ Connect Claude Desktop (or other MCP clients) to your entire Google Workspace: Docs, Sheets, Drive, Gmail, Calendar, Slides, and Forms!
4
+
5
+ > 🔥 **Check out [15 powerful tasks](SAMPLE_TASKS.md) you can accomplish with this enhanced server!**
6
+ > 📧 **NEW:** Full Gmail support (send, read, search, labels, drafts)
7
+ > 📅 **NEW:** Google Calendar integration (events, calendars, CRUD)
8
+ > 📽️ **NEW:** Google Slides support (presentations, slides, text)
9
+ > 📝 **NEW:** Google Forms support (create forms, questions, responses)
10
+ > 👥 **NEW:** Multi-account support (connect multiple Google accounts)
11
+ > 🔧 **NEW:** CLI for easy setup and account management
12
+
13
+ This comprehensive server uses the Model Context Protocol (MCP) and the `fastmcp` library to provide **65+ tools** for reading, writing, formatting, and managing your entire Google Workspace. It acts as a powerful bridge, allowing AI assistants like Claude to interact with your documents, emails, calendars, and files programmatically.
14
+
15
+ **Upgrading from [a-bonus/google-docs-mcp](https://github.com/a-bonus/google-docs-mcp)?** See [UPGRADE.md](UPGRADE.md) for migration instructions.
16
+
17
+ **Features:**
18
+
19
+ ### Document Access & Editing
20
+
21
+ - **Read Documents:** Read content with `readGoogleDoc` (plain text, JSON structure, or markdown)
22
+ - **Append to Documents:** Add text to documents with `appendToGoogleDoc`
23
+ - **Insert Text:** Place text at specific positions with `insertText`
24
+ - **Delete Content:** Remove content from a document with `deleteRange`
25
+ - **Tab Support:** Work with multi-tab documents using `listDocumentTabs` and optional `tabId` parameter in read/write operations
26
+
27
+ ### Formatting & Styling
28
+
29
+ - **Text Formatting:** Apply rich styling with `applyTextStyle` (bold, italic, colors, etc.)
30
+ - **Paragraph Formatting:** Control paragraph layout with `applyParagraphStyle` (alignment, spacing, etc.)
31
+ - **Find & Format:** Format by text content using `formatMatchingText` (legacy support)
32
+
33
+ ### Document Structure
34
+
35
+ - **Tables:** Create tables with `insertTable`
36
+ - **Page Breaks:** Insert page breaks with `insertPageBreak`
37
+ - **Images:** Insert images from URLs with `insertImageFromUrl`, or upload local images with `insertLocalImage`
38
+ - **Experimental Features:** Tools like `fixListFormatting` for automatic list detection
39
+
40
+ ### 🆕 Comment Management
41
+
42
+ - **List Comments:** View all comments in a document with `listComments` (shows author, date, and quoted text)
43
+ - **Get Comment Details:** Get specific comment with replies using `getComment`
44
+ - **Add Comments:** Create new comments anchored to text with `addComment`
45
+ - **Reply to Comments:** Add replies to existing comments with `replyToComment`
46
+ - **Resolve Comments:** Mark comments as resolved with `resolveComment`
47
+ - **Delete Comments:** Remove comments from documents with `deleteComment`
48
+
49
+ ### 🆕 Google Sheets Support
50
+
51
+ - **Read Spreadsheets:** Read data from ranges with `readSpreadsheet` (supports A1 notation like "A1:B10" or "Sheet1!A1:B10")
52
+ - **Write Data:** Write data to ranges with `writeSpreadsheet` (overwrites existing data)
53
+ - **Append Rows:** Add new rows to sheets with `appendSpreadsheetRows`
54
+ - **Clear Ranges:** Clear cell values with `clearSpreadsheetRange`
55
+ - **Spreadsheet Info:** Get detailed metadata and sheet list with `getSpreadsheetInfo`
56
+ - **Create Spreadsheets:** Create new spreadsheets with `createSpreadsheet` (optionally with initial data)
57
+ - **Add Sheets:** Add new sheets/tabs to spreadsheets with `addSpreadsheetSheet`
58
+ - **List Spreadsheets:** Find and list spreadsheets with `listGoogleSheets`
59
+
60
+ ### 🆕 Google Drive File Management
61
+
62
+ - **Document Discovery:** Find and list documents with `listGoogleDocs`, `searchGoogleDocs`, `getRecentGoogleDocs`
63
+ - **Document Information:** Get detailed metadata with `getDocumentInfo`
64
+ - **Folder Management:** Create folders (`createFolder`), list contents (`listFolderContents`), get info (`getFolderInfo`)
65
+ - **File Operations:** Move (`moveFile`), copy (`copyFile`), rename (`renameFile`), delete (`deleteFile`)
66
+ - **Document Creation:** Create new docs (`createDocument`) or from templates (`createFromTemplate`)
67
+
68
+ ### 🆕 Gmail
69
+
70
+ - **List Messages:** View inbox messages with `listGmailMessages` (with optional query filters)
71
+ - **Read Messages:** Get full message content with `readGmailMessage`
72
+ - **Send Email:** Compose and send emails with `sendGmailMessage` (supports HTML, CC, BCC)
73
+ - **Search:** Find emails with `searchGmail` using Gmail query syntax
74
+ - **Labels:** List labels with `listGmailLabels`, modify with `modifyGmailLabels`
75
+ - **Drafts:** Create email drafts with `createGmailDraft`
76
+ - **Delete:** Remove messages with `deleteGmailMessage`
77
+
78
+ ### 🆕 Google Calendar
79
+
80
+ - **List Calendars:** View all calendars with `listCalendars`
81
+ - **List Events:** Get events from a calendar with `listCalendarEvents` (with date range filters)
82
+ - **Get Event:** Get detailed event info with `getCalendarEvent`
83
+ - **Create Events:** Create new events with `createCalendarEvent` (supports attendees, reminders)
84
+ - **Update Events:** Modify existing events with `updateCalendarEvent`
85
+ - **Delete Events:** Remove events with `deleteCalendarEvent`
86
+
87
+ ### 🆕 Google Slides
88
+
89
+ - **List Presentations:** Find presentations with `listPresentations`
90
+ - **Read Presentation:** Get full presentation content with `readPresentation`
91
+ - **Create Presentation:** Create new presentations with `createPresentation`
92
+ - **Add Slides:** Add new slides with `addSlide` (supports layout selection)
93
+ - **Add Text:** Insert text into slides with `addTextToSlide`
94
+
95
+ ### 🆕 Google Forms
96
+
97
+ - **List Forms:** Find forms with `listForms`
98
+ - **Read Form:** Get form structure and questions with `readForm`
99
+ - **Get Responses:** Retrieve form responses with `getFormResponses`
100
+ - **Create Form:** Create new forms with `createForm`
101
+ - **Add Questions:** Add questions with `addFormQuestion` (supports multiple types)
102
+
103
+ ### Multi-Account Support
104
+
105
+ - **Multiple Google Accounts:** Connect multiple Google accounts (personal, work, etc.) to a single server instance
106
+ - **Account Management:** Add, list, and remove accounts with `addAccount`, `listAccounts`, `removeAccount`
107
+ - **Explicit Account Selection:** Every tool requires specifying which account to use (no implicit defaults)
108
+
109
+ ### Integration
110
+
111
+ - **Google Authentication:** Secure OAuth 2.0 authentication with full Drive, Docs, and Sheets access
112
+ - **MCP Compliant:** Designed for use with Claude and other MCP clients
113
+ - **VS Code Integration:** [Setup guide](vscode.md) for VS Code MCP extension
114
+
115
+ ---
116
+
117
+ ## Prerequisites
118
+
119
+ Before you start, make sure you have:
120
+
121
+ 1. **Node.js and npm:** A recent version of Node.js (which includes npm) installed on your computer. You can download it from [nodejs.org](https://nodejs.org/). (Version 18 or higher recommended).
122
+ 2. **Git:** Required for cloning this repository. ([Download Git](https://git-scm.com/downloads)).
123
+ 3. **A Google Account:** The account that owns or has access to the Google Docs you want to interact with.
124
+ 4. **Command Line Familiarity:** Basic comfort using a terminal or command prompt (like Terminal on macOS/Linux, or Command Prompt/PowerShell on Windows).
125
+ 5. **Claude Desktop (Optional):** If your goal is to connect this server to Claude, you'll need the Claude Desktop application installed.
126
+
127
+ ---
128
+
129
+ ## Setup Instructions
130
+
131
+ Follow these steps carefully to get your own instance of the server running.
132
+
133
+ ### Step 1: Google Cloud Project & Credentials (The Important Bit!)
134
+
135
+ This server needs permission to talk to Google APIs on your behalf. You'll create special "keys" (credentials) that only your server will use.
136
+
137
+ You can set this up using either the **Web UI** (easier for beginners) or the **CLI** (faster for experienced users).
138
+
139
+ <details>
140
+ <summary><strong>Option A: CLI Setup (using gcloud)</strong></summary>
141
+
142
+ If you have the [Google Cloud CLI](https://cloud.google.com/sdk/docs/install) installed, run these commands:
143
+
144
+ ```bash
145
+ # Set your project name
146
+ PROJECT_ID="my-mcp-workspace"
147
+
148
+ # Create a new project (or skip if using existing)
149
+ gcloud projects create $PROJECT_ID --name="MCP Workspace Server"
150
+ gcloud config set project $PROJECT_ID
151
+
152
+ # Enable billing (required for APIs) - you'll need to do this in the console
153
+ echo "Enable billing at: https://console.cloud.google.com/billing/linkedaccount?project=$PROJECT_ID"
154
+
155
+ # Enable all required APIs
156
+ gcloud services enable \
157
+ docs.googleapis.com \
158
+ sheets.googleapis.com \
159
+ drive.googleapis.com \
160
+ gmail.googleapis.com \
161
+ calendar-json.googleapis.com \
162
+ slides.googleapis.com \
163
+ forms.googleapis.com
164
+
165
+ # Create OAuth consent screen (external, for testing)
166
+ gcloud alpha iap oauth-brands create \
167
+ --application_title="MCP Workspace Server" \
168
+ --support_email="$(gcloud config get-value account)"
169
+
170
+ # Create OAuth 2.0 credentials (Desktop app)
171
+ gcloud alpha iap oauth-clients create \
172
+ "projects/$PROJECT_ID/brands/$(gcloud alpha iap oauth-brands list --format='value(name)' | head -1 | xargs basename)" \
173
+ --display_name="MCP Desktop Client"
174
+
175
+ # Download the credentials
176
+ # Note: You may need to download from the console for Desktop app type:
177
+ echo "Download credentials from: https://console.cloud.google.com/apis/credentials?project=$PROJECT_ID"
178
+ echo "Click on your OAuth client, then 'Download JSON', rename to credentials.json"
179
+
180
+ # Move to config directory
181
+ mkdir -p ~/.google-mcp
182
+ # mv ~/Downloads/client_secret_*.json ~/.google-mcp/credentials.json
183
+
184
+ # Add yourself as a test user (do this in console under OAuth consent screen > Test users)
185
+ echo "Add test users at: https://console.cloud.google.com/apis/credentials/consent?project=$PROJECT_ID"
186
+ ```
187
+
188
+ **Note:** Some gcloud commands for OAuth are in alpha/beta. If they don't work, use the Web UI method below.
189
+
190
+ </details>
191
+
192
+ <details>
193
+ <summary><strong>Option B: Web UI Setup (step-by-step)</strong></summary>
194
+
195
+ 1. **Go to Google Cloud Console:** Open your web browser and go to the [Google Cloud Console](https://console.cloud.google.com/). You might need to log in with your Google Account.
196
+ 2. **Create or Select a Project:**
197
+ - If you don't have a project, click the project dropdown near the top and select "NEW PROJECT". Give it a name (e.g., "My MCP Docs Server") and click "CREATE".
198
+ - If you have existing projects, you can select one or create a new one.
199
+ 3. **Enable APIs:** You need to turn on the specific Google services this server uses.
200
+ - In the search bar at the top, type "APIs & Services" and select "Library".
201
+ - Search for and enable each of these APIs:
202
+ - **Google Docs API** - for document operations
203
+ - **Google Sheets API** - for spreadsheet operations
204
+ - **Google Drive API** - for file management
205
+ - **Gmail API** - for email operations
206
+ - **Google Calendar API** - for calendar operations
207
+ - **Google Slides API** - for presentation operations
208
+ - **Google Forms API** - for forms operations
209
+ 4. **Configure OAuth Consent Screen:** This screen tells users (usually just you) what your app wants permission for.
210
+ - On the left menu, click "APIs & Services" -> "**OAuth consent screen**" (or search for "**Google Auth Platform**" and go to "Audience").
211
+ - Choose User Type: Select "**External**" and click "CREATE".
212
+ - ⚠️ **Important:** If you're in a Google Workspace organization and select "Internal", only users within your organization can authorize. Choose "External" if you need to connect accounts from multiple organizations/domains.
213
+ - Fill in App Information:
214
+ - **App name:** Give it a name users will see (e.g., "Claude Docs MCP Access").
215
+ - **User support email:** Select your email address.
216
+ - **Developer contact information:** Enter your email address.
217
+ - Click "**SAVE AND CONTINUE**".
218
+ - **Scopes:** Click "**ADD OR REMOVE SCOPES**". Search for and add the following scopes:
219
+ - `https://www.googleapis.com/auth/documents` (Google Docs)
220
+ - `https://www.googleapis.com/auth/spreadsheets` (Google Sheets)
221
+ - `https://www.googleapis.com/auth/drive` (Google Drive - full access)
222
+ - `https://www.googleapis.com/auth/gmail.modify` (Gmail)
223
+ - `https://www.googleapis.com/auth/calendar` (Google Calendar)
224
+ - `https://www.googleapis.com/auth/presentations` (Google Slides)
225
+ - `https://www.googleapis.com/auth/forms.body` (Google Forms)
226
+ - `https://www.googleapis.com/auth/forms.responses.readonly` (Form responses)
227
+ - Click "**UPDATE**".
228
+ - Click "**SAVE AND CONTINUE**".
229
+ - **Test Users:** Click "**ADD USERS**". Add **all** the Google email addresses you plan to connect (including accounts from different domains). Click "**ADD**". This allows those users to authorize while the app is in "testing" mode.
230
+ - ⚠️ **Multi-account setup:** If you want to connect multiple Google accounts (e.g., `work@company.com` and `personal@gmail.com`), add each email address as a test user.
231
+ - Click "**SAVE AND CONTINUE**". Review the summary and click "**BACK TO DASHBOARD**".
232
+ 5. **Create Credentials (The Keys!):**
233
+ - On the left menu, click "APIs & Services" -> "**Credentials**".
234
+ - Click "**+ CREATE CREDENTIALS**" at the top and choose "**OAuth client ID**".
235
+ - **Application type:** Select "**Desktop app**" from the dropdown.
236
+ - **Name:** Give it a name (e.g., "MCP Docs Desktop Client").
237
+ - Click "**CREATE**".
238
+ 6. **⬇️ DOWNLOAD THE CREDENTIALS FILE:** A box will pop up showing your Client ID. Click the "**DOWNLOAD JSON**" button.
239
+ - Save this file. It will likely be named something like `client_secret_....json`.
240
+ - **IMPORTANT:** Rename the downloaded file to exactly `credentials.json`.
241
+ 7. ⚠️ **SECURITY WARNING:** Treat this `credentials.json` file like a password! Do not share it publicly, and **never commit it to GitHub.** Anyone with this file could potentially pretend to be _your application_ (though they'd still need user consent to access data).
242
+
243
+ </details>
244
+
245
+ ### Step 2: Get the Server Code
246
+
247
+ 1. **Clone the Repository:** Open your terminal/command prompt and run:
248
+ ```bash
249
+ git clone https://github.com/YOUR_USERNAME/google-workspace-mcp.git
250
+ ```
251
+ 2. **Navigate into Directory:**
252
+ ```bash
253
+ cd google-workspace-mcp
254
+ ```
255
+ 3. **Place Credentials:** Move or copy the `credentials.json` file you downloaded and renamed (from Step 1.6) to the config directory:
256
+ ```bash
257
+ mkdir -p ~/.google-mcp
258
+ mv credentials.json ~/.google-mcp/credentials.json
259
+ ```
260
+
261
+ ### Step 3: Install Dependencies
262
+
263
+ Your server needs some helper libraries specified in the `package.json` file.
264
+
265
+ 1. In your terminal (make sure you are inside the `mcp-googledocs-server` directory), run:
266
+ ```bash
267
+ npm install
268
+ ```
269
+ This will download and install all the necessary packages into a `node_modules` folder.
270
+
271
+ ### Step 4: Build the Server Code
272
+
273
+ The server is written in TypeScript (`.ts`), but we need to compile it into JavaScript (`.js`) that Node.js can run directly.
274
+
275
+ 1. In your terminal, run:
276
+ ```bash
277
+ npm run build
278
+ ```
279
+ This uses the TypeScript compiler (`tsc`) to create a `dist` folder containing the compiled JavaScript files.
280
+
281
+ ### Step 5: First Run & Google Authorization (One Time Only)
282
+
283
+ Now you need to add your first Google account. The server includes a CLI to make this easy.
284
+
285
+ #### Option A: Using the CLI (Recommended)
286
+
287
+ 1. **Check your setup:**
288
+ ```bash
289
+ npx google-workspace-mcp setup
290
+ ```
291
+ This will verify your credentials file is in place and show you the next steps.
292
+
293
+ 2. **Add your first Google account:**
294
+ ```bash
295
+ npx google-workspace-mcp accounts add personal
296
+ ```
297
+ Replace `personal` with any name you want (e.g., `work`, `main`, etc.)
298
+
299
+ 3. **Authorize in Browser:**
300
+ - The CLI will display an authorization URL
301
+ - Open it in your browser and sign in with your Google account
302
+ - After authorizing, the account is automatically added
303
+
304
+ 4. **Verify the account was added:**
305
+ ```bash
306
+ npx google-workspace-mcp accounts list
307
+ ```
308
+
309
+ 5. **Check overall status:**
310
+ ```bash
311
+ npx google-workspace-mcp status
312
+ ```
313
+
314
+ #### CLI Commands Reference
315
+
316
+ ```bash
317
+ # Show help
318
+ npx google-workspace-mcp --help
319
+
320
+ # Start the MCP server (for Claude Desktop)
321
+ npx google-workspace-mcp serve
322
+
323
+ # Interactive setup wizard
324
+ npx google-workspace-mcp setup
325
+
326
+ # Account management
327
+ npx google-workspace-mcp accounts list # List all accounts
328
+ npx google-workspace-mcp accounts add <name> # Add a new account (opens browser automatically)
329
+ npx google-workspace-mcp accounts add <name> --no-open # Add account without auto-opening browser
330
+ npx google-workspace-mcp accounts add <name> -c /path/to/credentials.json # Add with custom credentials
331
+ npx google-workspace-mcp accounts remove <name> # Remove an account
332
+ npx google-workspace-mcp accounts test-permissions # Test API permissions for all accounts
333
+ npx google-workspace-mcp accounts test-permissions <name> # Test permissions for a specific account
334
+
335
+ # Configuration
336
+ npx google-workspace-mcp config path # Show config directory path
337
+ npx google-workspace-mcp config show # Show current configuration
338
+
339
+ # Server status
340
+ npx google-workspace-mcp status # Check if server is ready
341
+
342
+ # Read-only mode (blocks all write operations)
343
+ npx google-workspace-mcp serve --read-only
344
+ ```
345
+
346
+ #### Testing API Permissions
347
+
348
+ After adding accounts, you can verify that all Google API permissions are correctly configured:
349
+
350
+ ```bash
351
+ # Test all accounts
352
+ npx google-workspace-mcp accounts test-permissions
353
+
354
+ # Test a specific account
355
+ npx google-workspace-mcp accounts test-permissions personal
356
+ ```
357
+
358
+ This command tests access to all 7 Google services (Drive, Docs, Sheets, Gmail, Calendar, Slides, Forms) and reports which permissions are working and which need attention. Use this to diagnose permission issues after adding an account.
359
+
360
+ #### Read-Only Mode
361
+
362
+ Start the server in read-only mode to disable all write operations:
363
+
364
+ ```bash
365
+ npx google-workspace-mcp serve --read-only
366
+
367
+ # Or via environment variable
368
+ GOOGLE_MCP_READ_ONLY=true npx google-workspace-mcp serve
369
+ ```
370
+
371
+ In read-only mode:
372
+ - Tools that modify data (send emails, edit documents, create events, etc.) are blocked
373
+ - Read operations (list, search, read) continue to work normally
374
+ - Blocked tools show `[READ-ONLY MODE - DISABLED]` in their description
375
+ - Attempting to use a blocked tool returns an error message
376
+
377
+ This is useful for:
378
+ - Safe exploration of your Google Workspace data
379
+ - Demos and testing without risk of accidental changes
380
+ - Restricting access when you only need to read data
381
+
382
+ #### Option B: Manual Authorization (Legacy)
383
+
384
+ If you prefer the old method:
385
+
386
+ 1. In your terminal, run the _compiled_ server using `node`:
387
+ ```bash
388
+ node ./dist/server.js
389
+ ```
390
+ 2. **Watch the Terminal:** The script will print status messages and an authorization URL.
391
+ 3. **Authorize in Browser:** Copy the URL, open it in your browser, and sign in.
392
+ 4. **Complete the OAuth flow** as prompted.
393
+
394
+ After authorization, a token file is saved and you won't need to authorize again unless you remove the account.
395
+
396
+ ### Step 5b: Multi-Account Setup (Optional)
397
+
398
+ This server supports connecting multiple Google accounts simultaneously. This is useful if you have separate work and personal accounts, or need to access documents across different Google Workspace organizations.
399
+
400
+ **How It Works:**
401
+ - Accounts are stored in `~/.google-mcp/` with individual token files
402
+ - Each tool requires an `account` parameter to specify which account to use
403
+ - Use the CLI or MCP tools to manage accounts
404
+
405
+ **Adding Multiple Accounts with CLI (Recommended):**
406
+
407
+ ```bash
408
+ # Add your personal account
409
+ npx google-workspace-mcp accounts add personal
410
+
411
+ # Add your work account
412
+ npx google-workspace-mcp accounts add work
413
+
414
+ # List all accounts
415
+ npx google-workspace-mcp accounts list
416
+ ```
417
+
418
+ **Adding Accounts via MCP Tools (Alternative):**
419
+
420
+ If you prefer to add accounts through Claude or another MCP client:
421
+ - Call the `addAccount` tool with a name for the account (e.g., "work" or "personal")
422
+ - The tool returns an authorization URL - open it in your browser
423
+ - Sign in with the Google account you want to add
424
+ - Authorize the app when prompted
425
+
426
+ **Example Usage in Claude:**
427
+ ```
428
+ "List all my connected Google accounts using listAccounts"
429
+ "Read document YOUR_DOC_ID using account 'work'"
430
+ "List my Google Docs in account 'personal'"
431
+ ```
432
+
433
+ **Troubleshooting Multi-Account OAuth:**
434
+
435
+ If you get an error like **"Access blocked: App can only be used within its organization"** (error 403: org_internal), your OAuth consent screen is set to "Internal". To fix this:
436
+
437
+ 1. Go to [Google Cloud Console](https://console.cloud.google.com/) → **Google Auth Platform** → **Audience**
438
+ 2. Change **User type** from "Internal" to "**External**"
439
+ 3. Add all email addresses you want to connect as **Test Users** (under the "Testing" section)
440
+ 4. Retry the `addAccount` flow
441
+
442
+ **Note:** Apps in "Testing" mode are limited to 100 test users total. If you need more, you'll need to submit your app for verification.
443
+
444
+ ### Step 5c: Per-Account OAuth Apps (Advanced)
445
+
446
+ For advanced use cases, you can use different OAuth apps (different Google Cloud projects) for different accounts. This is useful when:
447
+ - Different accounts belong to different organizations with separate Google Cloud projects
448
+ - You want to isolate OAuth permissions between accounts
449
+ - Different accounts need different OAuth scopes
450
+
451
+ **Option 1: Name-based credentials (recommended)**
452
+
453
+ Place credentials files in `~/.google-mcp/credentials/` using the account name:
454
+
455
+ ```
456
+ ~/.google-mcp/
457
+ ├── credentials.json # Global default
458
+ ├── credentials/
459
+ │ ├── work.json # Used for account "work"
460
+ │ └── personal.json # Used for account "personal"
461
+ └── tokens/
462
+ ├── work.json
463
+ └── personal.json
464
+ ```
465
+
466
+ When you call `addAccount` with name "work", it will automatically look for `~/.google-mcp/credentials/work.json` first.
467
+
468
+ **Option 2: Explicit credentials path**
469
+
470
+ Specify a custom credentials file when adding an account:
471
+
472
+ ```
473
+ "Add account 'client-abc' with credentialsPath '/path/to/client-abc-credentials.json'"
474
+ ```
475
+
476
+ The credentials path will be stored in the account config and used for all subsequent API calls.
477
+
478
+ **Lookup Priority:**
479
+ 1. Explicit `credentialsPath` stored in account config
480
+ 2. `~/.google-mcp/credentials/{accountName}.json`
481
+ 3. Global `~/.google-mcp/credentials.json`
482
+
483
+ ### Service Account Authentication
484
+
485
+ Service account authentication is not currently supported. Please use the standard OAuth flow with `npx google-workspace-mcp accounts add <name>`.
486
+
487
+ ### Step 6: Configure Claude Desktop (Optional)
488
+
489
+ If you want to use this server with Claude Desktop, you need to tell Claude how to run it.
490
+
491
+ 1. **Find Your Absolute Path:** You need the full path to the server code.
492
+ - In your terminal, make sure you are still inside the `mcp-googledocs-server` directory.
493
+ - Run the `pwd` command (on macOS/Linux) or `cd` (on Windows, just displays the path).
494
+ - Copy the full path (e.g., `/Users/yourname/projects/mcp-googledocs-server` or `C:\Users\yourname\projects\mcp-googledocs-server`).
495
+ 2. **Locate `mcp_config.json`:** Find Claude's configuration file:
496
+ - **macOS:** `~/Library/Application Support/Claude/mcp_config.json` (You might need to use Finder's "Go" -> "Go to Folder..." menu and paste `~/Library/Application Support/Claude/`)
497
+ - **Windows:** `%APPDATA%\Claude\mcp_config.json` (Paste `%APPDATA%\Claude` into File Explorer's address bar)
498
+ - **Linux:** `~/.config/Claude/mcp_config.json`
499
+ - _If the `Claude` folder or `mcp_config.json` file doesn't exist, create them._
500
+ 3. **Edit `mcp_config.json`:** Open the file in a text editor. Add or modify the `mcpServers` section like this, **replacing `/PATH/TO/YOUR/CLONED/REPO` with the actual absolute path you copied in Step 6.1**:
501
+
502
+ ```json
503
+ {
504
+ "mcpServers": {
505
+ "google-docs-mcp": {
506
+ "command": "node",
507
+ "args": [
508
+ "/PATH/TO/YOUR/CLONED/REPO/mcp-googledocs-server/dist/server.js"
509
+ ],
510
+ "env": {}
511
+ }
512
+ // Add commas here if you have other servers defined
513
+ }
514
+ // Other Claude settings might be here
515
+ }
516
+ ```
517
+
518
+ - **Make sure the path in `"args"` is correct and absolute!**
519
+ - If the file already existed, carefully merge this entry into the existing `mcpServers` object. Ensure the JSON is valid (check commas!).
520
+
521
+ 4. **Save `mcp_config.json`.**
522
+ 5. **Restart Claude Desktop:** Close Claude completely and reopen it.
523
+
524
+ ---
525
+
526
+ ## Usage with Claude Desktop
527
+
528
+ Once configured, you should be able to use the tools in your chats with Claude:
529
+
530
+ - "Use the `google-docs-mcp` server to read the document with ID `YOUR_GOOGLE_DOC_ID`."
531
+ - "Can you get the content of Google Doc `YOUR_GOOGLE_DOC_ID`?"
532
+ - "Append 'This was added by Claude!' to document `YOUR_GOOGLE_DOC_ID` using the `google-docs-mcp` tool."
533
+
534
+ ### Working with Tabs
535
+
536
+ Google Docs now supports multi-tab documents. This MCP server provides full support for working with tabs:
537
+
538
+ **Listing Tabs:**
539
+
540
+ - "List all tabs in document `YOUR_GOOGLE_DOC_ID` using the `listDocumentTabs` tool."
541
+ - "Show me the tab structure with content summary for document `YOUR_GOOGLE_DOC_ID`."
542
+
543
+ **Reading from Specific Tabs:**
544
+
545
+ - "Read the content from tab `TAB_ID` in document `YOUR_GOOGLE_DOC_ID` using the `readGoogleDoc` tool."
546
+ - "Get the markdown content from tab `TAB_ID` in document `YOUR_GOOGLE_DOC_ID`."
547
+
548
+ **Writing to Specific Tabs:**
549
+
550
+ - "Append 'New content' to tab `TAB_ID` in document `YOUR_GOOGLE_DOC_ID`."
551
+ - "Insert text at index 100 in tab `TAB_ID` of document `YOUR_GOOGLE_DOC_ID`."
552
+ - "Delete content from range 50-100 in tab `TAB_ID` of document `YOUR_GOOGLE_DOC_ID`."
553
+
554
+ **Note:** The following tools support the optional `tabId` parameter:
555
+
556
+ - `readGoogleDoc` - Read from a specific tab
557
+ - `appendToGoogleDoc` - Append to a specific tab
558
+ - `insertText` - Insert text into a specific tab
559
+ - `deleteRange` - Delete content from a specific tab
560
+
561
+ When `tabId` is not specified, operations target the first tab (or the legacy document body for older documents without tabs).
562
+
563
+ ### Advanced Usage Examples:
564
+
565
+ **Google Docs:**
566
+ - **Text Styling**: "Use `applyTextStyle` to make the text 'Important Section' bold and red (#FF0000) in document `YOUR_GOOGLE_DOC_ID`."
567
+ - **Paragraph Styling**: "Use `applyParagraphStyle` to center-align the paragraph containing 'Title Here' in document `YOUR_GOOGLE_DOC_ID`."
568
+ - **Table Creation**: "Insert a 3x4 table at index 500 in document `YOUR_GOOGLE_DOC_ID` using the `insertTable` tool."
569
+ - **Image Insertion**: "Use `insertImageFromUrl` to insert an image from 'https://example.com/image.png' at index 100 in document `YOUR_GOOGLE_DOC_ID`."
570
+ - **Local Image Upload**: "Use `insertLocalImage` to upload '/path/to/image.jpg' and insert it at index 200 in document `YOUR_GOOGLE_DOC_ID`."
571
+ - **Legacy Formatting**: "Use `formatMatchingText` to find the second instance of 'Project Alpha' and make it blue (#0000FF) in doc `YOUR_GOOGLE_DOC_ID`."
572
+
573
+ **Google Sheets:**
574
+ - **Read Data**: "Read range A1:B10 from spreadsheet `YOUR_SPREADSHEET_ID` using `readSpreadsheet`."
575
+ - **Write Data**: "Write data [[1, 2], [3, 4]] to range A1:B2 in spreadsheet `YOUR_SPREADSHEET_ID`."
576
+ - **Append Rows**: "Append rows [[5, 6], [7, 8]] to spreadsheet `YOUR_SPREADSHEET_ID` starting at A1."
577
+ - **Create Spreadsheet**: "Create a new spreadsheet titled 'Sales Data' with initial data [[Name, Amount], [Product A, 100]]."
578
+ - **Get Info**: "Get information about spreadsheet `YOUR_SPREADSHEET_ID` including all sheets."
579
+ - **Add Sheet**: "Add a new sheet named 'Summary' to spreadsheet `YOUR_SPREADSHEET_ID`."
580
+ - **Clear Range**: "Clear the range A1:B10 in spreadsheet `YOUR_SPREADSHEET_ID`."
581
+ - **List Spreadsheets**: "List all my Google Spreadsheets modified in the last 30 days."
582
+
583
+ Remember to replace:
584
+ - `YOUR_GOOGLE_DOC_ID` with the actual ID from a Google Doc's URL (the long string between `/d/` and `/edit`)
585
+ - `YOUR_SPREADSHEET_ID` with the actual ID from a Google Sheet's URL (the long string between `/d/` and `/edit`)
586
+
587
+ Claude will automatically launch your server in the background when needed using the command you provided. You do **not** need to run `node ./dist/server.js` manually anymore.
588
+
589
+ ---
590
+
591
+ ## Image Insertion
592
+
593
+ This server provides two ways to insert images into Google Documents:
594
+
595
+ ### 1. Insert from Public URL (`insertImageFromUrl`)
596
+
597
+ Inserts an image directly from a publicly accessible URL. The image URL must be accessible without authentication.
598
+
599
+ **Parameters:**
600
+
601
+ - `documentId`: The Google Document ID
602
+ - `imageUrl`: Publicly accessible URL (http:// or https://)
603
+ - `index`: Position in the document (1-based indexing)
604
+ - `width` (optional): Image width in points
605
+ - `height` (optional): Image height in points
606
+
607
+ **Example:**
608
+
609
+ ```
610
+ "Insert an image from https://example.com/logo.png at index 100 in document YOUR_DOC_ID"
611
+ ```
612
+
613
+ ### 2. Upload Local Image (`insertLocalImage`)
614
+
615
+ Uploads a local image file to Google Drive and inserts it into the document. This is a two-step process that:
616
+
617
+ 1. Uploads the image to Google Drive (by default to the same folder as the document)
618
+ 2. Makes the image publicly readable
619
+ 3. Inserts the image into the document using its Drive URL
620
+
621
+ **Parameters:**
622
+
623
+ - `documentId`: The Google Document ID
624
+ - `localImagePath`: Absolute path to the local image file
625
+ - `index`: Position in the document (1-based indexing)
626
+ - `width` (optional): Image width in points
627
+ - `height` (optional): Image height in points
628
+ - `uploadToSameFolder` (optional, default: true): If true, uploads to the document's folder; if false, uploads to Drive root
629
+
630
+ **Supported formats:** .jpg, .jpeg, .png, .gif, .bmp, .webp, .svg
631
+
632
+ **Example:**
633
+
634
+ ```
635
+ "Upload and insert the image at /Users/myname/Pictures/chart.png at index 200 in document YOUR_DOC_ID with width 400 and height 300"
636
+ ```
637
+
638
+ **Note:** The uploaded image will be made publicly readable so it can be displayed in the document. The image file will remain in your Google Drive and can be managed separately.
639
+
640
+ ---
641
+
642
+ ## Security & Token Storage
643
+
644
+ - **`.gitignore`:** This repository includes a `.gitignore` file which should prevent you from accidentally committing your sensitive `credentials.json` and `token.json` files. **Do not remove these lines from `.gitignore`**.
645
+ - **Token Storage:** This server stores the Google authorization token (`token.json`) directly in the project folder for simplicity during setup. In production or more security-sensitive environments, consider storing this token more securely, such as using system keychains, encrypted files, or dedicated secret management services.
646
+
647
+ ---
648
+
649
+ ## Testing
650
+
651
+ The multi-tab support features have been thoroughly tested and verified:
652
+
653
+ ✅ **Tested Features:**
654
+
655
+ - `listDocumentTabs` - Lists all tabs with IDs, titles, positions, and content summaries
656
+ - `readGoogleDoc` with `tabId` - Reads specific tabs; backward compatible without `tabId`
657
+ - `appendToGoogleDoc` with `tabId` - Appends to specific tabs without affecting others
658
+ - `insertText` with `tabId` - Inserts text at specific positions in specific tabs
659
+ - `deleteRange` with `tabId` - Deletes content from specific tabs in isolation
660
+ - Multi-tab operations - Sequential operations on different tabs work independently
661
+ - Error handling - Invalid tab IDs return clear, helpful error messages
662
+ - Backward compatibility - Operations without `tabId` default to first tab (legacy documents supported)
663
+
664
+ All tab-related features have been validated with real Google Docs containing multiple tabs, confirming:
665
+
666
+ - Tab isolation (operations on one tab don't affect others)
667
+ - Proper tab ID validation and error messages
668
+ - Correct content retrieval and manipulation per tab
669
+ - Full backward compatibility with single-tab and legacy documents
670
+
671
+ ## Google Sheets Usage
672
+
673
+ ### A1 Notation
674
+
675
+ Google Sheets uses A1 notation to specify ranges. Examples:
676
+ - `A1` - Single cell
677
+ - `A1:B10` - Range from A1 to B10
678
+ - `Sheet1!A1:B10` - Range on a specific sheet named "Sheet1"
679
+ - `A:A` - Entire column A
680
+ - `1:1` - Entire row 1
681
+
682
+ ### Value Input Options
683
+
684
+ When writing data to spreadsheets, you can choose how values are interpreted:
685
+ - **USER_ENTERED** (default): Values are parsed as if typed by a user (formulas work, dates are recognized, etc.)
686
+ - **RAW**: Values are stored exactly as provided (no parsing)
687
+
688
+ ### Example Workflow
689
+
690
+ ```bash
691
+ # 1. Create a new spreadsheet
692
+ "Create a spreadsheet titled 'Monthly Report'"
693
+
694
+ # 2. Write headers
695
+ "Write [[Date, Sales, Expenses]] to range A1:C1 in spreadsheet YOUR_SPREADSHEET_ID"
696
+
697
+ # 3. Append data rows
698
+ "Append rows [[2024-01-01, 1000, 500], [2024-01-02, 1200, 600]] to spreadsheet YOUR_SPREADSHEET_ID starting at A2"
699
+
700
+ # 4. Read the data back
701
+ "Read range A1:C3 from spreadsheet YOUR_SPREADSHEET_ID"
702
+
703
+ # 5. Add a new sheet for analysis
704
+ "Add a new sheet named 'Analysis' to spreadsheet YOUR_SPREADSHEET_ID"
705
+ ```
706
+
707
+ ## Known Limitations
708
+
709
+ While this MCP server provides comprehensive Google Docs, Sheets, and Drive functionality, there are some limitations imposed by the Google APIs themselves:
710
+
711
+ ### Comment Anchoring
712
+
713
+ **Programmatically Created Comments Are Not Anchored**: Comments created via the `addComment` tool appear in the "All Comments" list but are not visibly anchored to specific text in the Google Docs UI. They will show "original content deleted" instead of highlighting the intended text range. This is a limitation of the Google Drive API v3 when working with Google Docs files.
714
+
715
+ - **Workaround**: Comments created manually in the Google Docs UI are properly anchored
716
+ - **Other Operations**: Reply, delete, and list operations work correctly on all comments regardless of how they were created
717
+
718
+ ### Comment Resolution
719
+
720
+ **Resolved Status May Not Persist**: The `resolveComment` tool attempts to mark comments as resolved, but the Drive API v3 does not fully support this operation for Google Docs files. The resolved status may not persist or be visible in the Google Docs UI.
721
+
722
+ - **Workaround**: Resolve comments manually in the Google Docs web interface
723
+
724
+ ### Converted Documents
725
+
726
+ **Limited Support for Converted Documents**: Some Google Docs that were converted from other formats (especially Microsoft Word documents) may not support all Docs API operations. You may encounter errors like "This operation is not supported for this document" when trying to read or modify these files.
727
+
728
+ ## Troubleshooting
729
+
730
+ - **Claude shows "Failed" or "Could not attach":**
731
+ - Double-check the absolute path in `mcp_config.json`.
732
+ - Ensure you ran `npm run build` successfully and the `dist` folder exists.
733
+ - Try running the command from `mcp_config.json` manually in your terminal: `node /PATH/TO/YOUR/CLONED/REPO/mcp-googledocs-server/dist/server.js`. Look for any errors printed.
734
+ - Check the Claude Desktop logs (see the official MCP debugging guide).
735
+ - Make sure all `console.log` status messages in the server code were changed to `console.error`.
736
+ - **Google Authorization Errors:**
737
+ - Ensure you enabled the correct APIs (Docs, Sheets, Drive).
738
+ - Make sure you added your email as a Test User on the OAuth Consent Screen.
739
+ - Verify the `credentials.json` file is correctly placed in the project root (or `~/.google-mcp/credentials.json` for multi-account setup).
740
+ - **If you're upgrading from an older version:** You may need to delete your existing `token.json` file and re-authenticate to grant the new Sheets API scope.
741
+ - **"Access blocked: org_internal" Error (403):**
742
+ - This occurs when your OAuth consent screen is set to "Internal" but you're trying to authorize an account from a different Google Workspace organization.
743
+ - **Fix:** Go to Google Cloud Console → Google Auth Platform → Audience → Change User type to "External"
744
+ - Add all the email addresses you want to authorize as Test Users
745
+ - See "Troubleshooting Multi-Account OAuth" in Step 5b for detailed instructions.
746
+ - **Tab-related Errors:**
747
+ - If you get "Tab with ID not found", use `listDocumentTabs` to see all available tab IDs
748
+ - Ensure you're using the correct tab ID format (typically a short alphanumeric string)
749
+ - Single-tab documents don't require `tabId` - operations work on the document body automatically
750
+
751
+ ---
752
+
753
+ ## Disclaimer
754
+
755
+ This is an independent, open-source project and is **not affiliated with, endorsed by, or sponsored by Google LLC**. "Google", "Google Workspace", "Google Docs", "Gmail", "Google Calendar", "Google Drive", "Google Sheets", "Google Slides", and "Google Forms" are trademarks of Google LLC.
756
+
757
+ This project uses official Google APIs through the user's own Google Cloud credentials. The authors are not responsible for any misuse or for any damages arising from the use of this software.
758
+
759
+ ## License
760
+
761
+ This project is licensed under the MIT License - see the `LICENSE` file for details.
762
+
763
+ ## Star History
764
+
765
+ [![Star History Chart](https://api.star-history.com/svg?repos=pm990320/google-workspace-mcp&type=date&legend=top-left)](https://www.star-history.com/#pm990320/google-workspace-mcp&type=date&legend=top-left)