@brainwavesio/google-docs-mcp 1.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.
@@ -0,0 +1,3 @@
1
+ {
2
+ "bundles": {}
3
+ }
package/LICENSE ADDED
@@ -0,0 +1,7 @@
1
+ https://opensource.org/license/MIT
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the β€œSoftware”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
4
+
5
+ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
6
+
7
+ THE SOFTWARE IS PROVIDED β€œAS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,588 @@
1
+ # Ultimate Google Docs, Sheets & Drive MCP Server
2
+
3
+ > **This is the [@brainwavesio](https://github.com/brainwavesio) fork** with npx support and environment variable authentication. Original: [a-bonus/google-docs-mcp](https://github.com/a-bonus/google-docs-mcp)
4
+
5
+ ![Demo Animation](assets/google.docs.mcp.1.gif)
6
+
7
+ Connect Claude Desktop (or other MCP clients) to your Google Docs, Google Sheets, and Google Drive!
8
+
9
+ ## Quick Start (npx)
10
+
11
+ If you have Google OAuth credentials, you can run this server without cloning:
12
+
13
+ ```bash
14
+ npx @brainwavesio/google-docs-mcp
15
+ ```
16
+
17
+ Or configure in Claude Desktop's `mcp_config.json`:
18
+
19
+ ```json
20
+ {
21
+ "mcpServers": {
22
+ "google-docs-mcp": {
23
+ "command": "npx",
24
+ "args": ["@brainwavesio/google-docs-mcp"],
25
+ "env": {
26
+ "GOOGLE_CLIENT_ID": "your-client-id.apps.googleusercontent.com",
27
+ "GOOGLE_CLIENT_SECRET": "your-client-secret",
28
+ "GOOGLE_REFRESH_TOKEN": "your-refresh-token"
29
+ }
30
+ }
31
+ }
32
+ }
33
+ ```
34
+
35
+ See [Environment Variable Authentication](#alternative-environment-variable-authentication-npx--containers) for details on getting a refresh token.
36
+
37
+ ---
38
+
39
+ > πŸ”₯ **Check out [15 powerful tasks](SAMPLE_TASKS.md) you can accomplish with this enhanced server!**
40
+ > πŸ“ **NEW:** Complete Google Drive file management capabilities!
41
+ > πŸ“Š **NEW:** Full Google Sheets support for reading, writing, and managing spreadsheets!
42
+
43
+ This comprehensive server uses the Model Context Protocol (MCP) and the `fastmcp` library to provide tools for reading, writing, formatting, structuring Google Documents and Spreadsheets, and managing your entire Google Drive. It acts as a powerful bridge, allowing AI assistants like Claude to interact with your documents, spreadsheets, and files programmatically with advanced capabilities.
44
+
45
+ **Features:**
46
+
47
+ ### Document Access & Editing
48
+
49
+ - **Read Documents:** Read content with `readGoogleDoc` (plain text, JSON structure, or markdown)
50
+ - **Append to Documents:** Add text to documents with `appendToGoogleDoc`
51
+ - **Insert Text:** Place text at specific positions with `insertText`
52
+ - **Delete Content:** Remove content from a document with `deleteRange`
53
+ - **Tab Support:** Work with multi-tab documents using `listDocumentTabs` and optional `tabId` parameter in read/write operations
54
+
55
+ ### Formatting & Styling
56
+
57
+ - **Text Formatting:** Apply rich styling with `applyTextStyle` (bold, italic, colors, etc.)
58
+ - **Paragraph Formatting:** Control paragraph layout with `applyParagraphStyle` (alignment, spacing, etc.)
59
+ - **Find & Format:** Format by text content using `formatMatchingText` (legacy support)
60
+
61
+ ### Document Structure
62
+
63
+ - **Tables:** Create tables with `insertTable`
64
+ - **Page Breaks:** Insert page breaks with `insertPageBreak`
65
+ - **Images:** Insert images from URLs with `insertImageFromUrl`, or upload local images with `insertLocalImage`
66
+ - **Experimental Features:** Tools like `fixListFormatting` for automatic list detection
67
+
68
+ ### πŸ†• Comment Management
69
+
70
+ - **List Comments:** View all comments in a document with `listComments` (shows author, date, and quoted text)
71
+ - **Get Comment Details:** Get specific comment with replies using `getComment`
72
+ - **Add Comments:** Create new comments anchored to text with `addComment`
73
+ - **Reply to Comments:** Add replies to existing comments with `replyToComment`
74
+ - **Resolve Comments:** Mark comments as resolved with `resolveComment`
75
+ - **Delete Comments:** Remove comments from documents with `deleteComment`
76
+
77
+ ### πŸ†• Google Sheets Support
78
+
79
+ - **Read Spreadsheets:** Read data from ranges with `readSpreadsheet` (supports A1 notation like "A1:B10" or "Sheet1!A1:B10")
80
+ - **Write Data:** Write data to ranges with `writeSpreadsheet` (overwrites existing data)
81
+ - **Append Rows:** Add new rows to sheets with `appendSpreadsheetRows`
82
+ - **Clear Ranges:** Clear cell values with `clearSpreadsheetRange`
83
+ - **Spreadsheet Info:** Get detailed metadata and sheet list with `getSpreadsheetInfo`
84
+ - **Create Spreadsheets:** Create new spreadsheets with `createSpreadsheet` (optionally with initial data)
85
+ - **Add Sheets:** Add new sheets/tabs to spreadsheets with `addSpreadsheetSheet`
86
+ - **List Spreadsheets:** Find and list spreadsheets with `listGoogleSheets`
87
+
88
+ ### πŸ†• Google Drive File Management
89
+
90
+ - **Document Discovery:** Find and list documents with `listGoogleDocs`, `searchGoogleDocs`, `getRecentGoogleDocs`
91
+ - **Document Information:** Get detailed metadata with `getDocumentInfo`
92
+ - **Folder Management:** Create folders (`createFolder`), list contents (`listFolderContents`), get info (`getFolderInfo`)
93
+ - **File Operations:** Move (`moveFile`), copy (`copyFile`), rename (`renameFile`), delete (`deleteFile`)
94
+ - **Document Creation:** Create new docs (`createDocument`) or from templates (`createFromTemplate`)
95
+
96
+ ### Integration
97
+
98
+ - **Google Authentication:** Secure OAuth 2.0 authentication with full Drive, Docs, and Sheets access
99
+ - **MCP Compliant:** Designed for use with Claude and other MCP clients
100
+ - **VS Code Integration:** [Setup guide](vscode.md) for VS Code MCP extension
101
+
102
+ ---
103
+
104
+ ## Prerequisites
105
+
106
+ Before you start, make sure you have:
107
+
108
+ 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).
109
+ 2. **Git:** Required for cloning this repository. ([Download Git](https://git-scm.com/downloads)).
110
+ 3. **A Google Account:** The account that owns or has access to the Google Docs you want to interact with.
111
+ 4. **Command Line Familiarity:** Basic comfort using a terminal or command prompt (like Terminal on macOS/Linux, or Command Prompt/PowerShell on Windows).
112
+ 5. **Claude Desktop (Optional):** If your goal is to connect this server to Claude, you'll need the Claude Desktop application installed.
113
+
114
+ ---
115
+
116
+ ## Setup Instructions
117
+
118
+ Follow these steps carefully to get your own instance of the server running.
119
+
120
+ ### Step 1: Google Cloud Project & Credentials (The Important Bit!)
121
+
122
+ This server needs permission to talk to Google APIs on your behalf. You'll create special "keys" (credentials) that only your server will use.
123
+
124
+ 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.
125
+ 2. **Create or Select a Project:**
126
+ - 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".
127
+ - If you have existing projects, you can select one or create a new one.
128
+ 3. **Enable APIs:** You need to turn on the specific Google services this server uses.
129
+ - In the search bar at the top, type "APIs & Services" and select "Library".
130
+ - Search for "**Google Docs API**" and click on it. Then click the "**ENABLE**" button.
131
+ - Search for "**Google Sheets API**" and click on it. Then click the "**ENABLE**" button.
132
+ - Search for "**Google Drive API**" and click on it. Then click the "**ENABLE**" button (this is often needed for finding files or permissions).
133
+ 4. **Configure OAuth Consent Screen:** This screen tells users (usually just you) what your app wants permission for.
134
+ - On the left menu, click "APIs & Services" -> "**OAuth consent screen**".
135
+ - Choose User Type: Select "**External**" and click "CREATE".
136
+ - Fill in App Information:
137
+ - **App name:** Give it a name users will see (e.g., "Claude Docs MCP Access").
138
+ - **User support email:** Select your email address.
139
+ - **Developer contact information:** Enter your email address.
140
+ - Click "**SAVE AND CONTINUE**".
141
+ - **Scopes:** Click "**ADD OR REMOVE SCOPES**". Search for and add the following scopes:
142
+ - `https://www.googleapis.com/auth/documents` (Allows reading/writing docs)
143
+ - `https://www.googleapis.com/auth/spreadsheets` (Allows reading/writing spreadsheets)
144
+ - `https://www.googleapis.com/auth/drive.file` (Allows access to specific files opened/created by the app)
145
+ - Click "**UPDATE**".
146
+ - Click "**SAVE AND CONTINUE**".
147
+ - **Test Users:** Click "**ADD USERS**". Enter the same Google email address you are logged in with. Click "**ADD**". This allows _you_ to use the app while it's in "testing" mode.
148
+ - Click "**SAVE AND CONTINUE**". Review the summary and click "**BACK TO DASHBOARD**".
149
+ 5. **Create Credentials (The Keys!):**
150
+ - On the left menu, click "APIs & Services" -> "**Credentials**".
151
+ - Click "**+ CREATE CREDENTIALS**" at the top and choose "**OAuth client ID**".
152
+ - **Application type:** Select "**Desktop app**" from the dropdown.
153
+ - **Name:** Give it a name (e.g., "MCP Docs Desktop Client").
154
+ - Click "**CREATE**".
155
+ 6. **⬇️ DOWNLOAD THE CREDENTIALS FILE:** A box will pop up showing your Client ID. Click the "**DOWNLOAD JSON**" button.
156
+ - Save this file. It will likely be named something like `client_secret_....json`.
157
+ - **IMPORTANT:** Rename the downloaded file to exactly `credentials.json`.
158
+ 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).
159
+
160
+ ### Step 2: Get the Server Code
161
+
162
+ 1. **Clone the Repository:** Open your terminal/command prompt and run:
163
+ ```bash
164
+ git clone https://github.com/brainwavesio/google-docs-mcp.git mcp-googledocs-server
165
+ ```
166
+ 2. **Navigate into Directory:**
167
+ ```bash
168
+ cd mcp-googledocs-server
169
+ ```
170
+ 3. **Place Credentials:** Move or copy the `credentials.json` file you downloaded and renamed (from Step 1.6) directly into this `mcp-googledocs-server` folder.
171
+
172
+ ### Step 3: Install Dependencies
173
+
174
+ Your server needs some helper libraries specified in the `package.json` file.
175
+
176
+ 1. In your terminal (make sure you are inside the `mcp-googledocs-server` directory), run:
177
+ ```bash
178
+ npm install
179
+ ```
180
+ This will download and install all the necessary packages into a `node_modules` folder.
181
+
182
+ ### Step 4: Build the Server Code
183
+
184
+ The server is written in TypeScript (`.ts`), but we need to compile it into JavaScript (`.js`) that Node.js can run directly.
185
+
186
+ 1. In your terminal, run:
187
+ ```bash
188
+ npm run build
189
+ ```
190
+ This uses the TypeScript compiler (`tsc`) to create a `dist` folder containing the compiled JavaScript files.
191
+
192
+ ### Step 5: First Run & Google Authorization (One Time Only)
193
+
194
+ Now you need to run the server once manually to grant it permission to access your Google account data. This will create a `token.json` file that saves your permission grant.
195
+
196
+ 1. In your terminal, run the _compiled_ server using `node`:
197
+ ```bash
198
+ node ./dist/server.js
199
+ ```
200
+ 2. **Watch the Terminal:** The script will print:
201
+ - Status messages (like "Attempting to authorize...").
202
+ - An "Authorize this app by visiting this url:" message followed by a long `https://accounts.google.com/...` URL.
203
+ 3. **Authorize in Browser:**
204
+ - Copy the entire long URL from the terminal.
205
+ - Paste the URL into your web browser and press Enter.
206
+ - Log in with the **same Google account** you added as a Test User in Step 1.4.
207
+ - Google will show a screen asking for permission for your app ("Claude Docs MCP Access" or similar) to access Google Docs, Sheets, and Drive. Review and click "**Allow**" or "**Grant**".
208
+ 4. **Get the Authorization Code:**
209
+ - After clicking Allow, your browser will likely try to redirect to `http://localhost` and show a **"This site can't be reached" error**. **THIS IS NORMAL!**
210
+ - Look **carefully** at the URL in your browser's address bar. It will look like `http://localhost/?code=4/0Axxxxxxxxxxxxxx&scope=...`
211
+ - Copy the long string of characters **between `code=` and the `&scope` part**. This is your single-use authorization code.
212
+ 5. **Paste Code into Terminal:** Go back to your terminal where the script is waiting ("Enter the code from that page here:"). Paste the code you just copied.
213
+ 6. **Press Enter.**
214
+ 7. **Success!** The script should print:
215
+ - "Authentication successful!"
216
+ - "Token stored to .../token.json"
217
+ - It will then finish starting and likely print "Awaiting MCP client connection via stdio..." or similar, and then exit (or you can press `Ctrl+C` to stop it).
218
+ 8. βœ… **Check:** You should now see a new file named `token.json` in your `mcp-googledocs-server` folder.
219
+ 9. ⚠️ **SECURITY WARNING:** This `token.json` file contains the key that allows the server to access your Google account _without_ asking again. Protect it like a password. **Do not commit it to GitHub.** The included `.gitignore` file should prevent this automatically.
220
+
221
+ ### Alternative: Service Account with Domain-Wide Delegation (Enterprise)
222
+
223
+ For Google Workspace organizations that need to access documents across the domain without individual user OAuth flows, you can use a service account with domain-wide delegation.
224
+
225
+ **Prerequisites:**
226
+ - Google Workspace admin access to configure domain-wide delegation
227
+ - A service account with domain-wide delegation enabled
228
+
229
+ **Setup:**
230
+
231
+ 1. **Create a Service Account** in Google Cloud Console:
232
+ - Go to "APIs & Services" β†’ "Credentials" β†’ "Create Credentials" β†’ "Service Account"
233
+ - Download the JSON key file
234
+
235
+ 2. **Enable Domain-Wide Delegation** in Google Workspace Admin Console:
236
+ - Go to Security β†’ API Controls β†’ Domain-wide delegation
237
+ - Add the service account's client ID with the required scopes:
238
+ - `https://www.googleapis.com/auth/documents`
239
+ - `https://www.googleapis.com/auth/drive`
240
+ - `https://www.googleapis.com/auth/spreadsheets`
241
+
242
+ 3. **Configure Environment Variables:**
243
+ ```bash
244
+ # Path to your service account key file
245
+ export SERVICE_ACCOUNT_PATH="/path/to/service-account-key.json"
246
+
247
+ # Email of the user to impersonate (required for domain-wide delegation)
248
+ export GOOGLE_IMPERSONATE_USER="user@yourdomain.com"
249
+ ```
250
+
251
+ 4. **Update Claude Desktop Config** (add environment variables):
252
+ ```json
253
+ {
254
+ "mcpServers": {
255
+ "google-docs-mcp": {
256
+ "command": "node",
257
+ "args": ["/PATH/TO/mcp-googledocs-server/dist/server.js"],
258
+ "env": {
259
+ "SERVICE_ACCOUNT_PATH": "/path/to/service-account-key.json",
260
+ "GOOGLE_IMPERSONATE_USER": "user@yourdomain.com"
261
+ }
262
+ }
263
+ }
264
+ }
265
+ ```
266
+
267
+ When `GOOGLE_IMPERSONATE_USER` is set, the server will impersonate that user when accessing Google APIs, allowing access to that user's documents and Drive.
268
+
269
+ ### Alternative: Environment Variable Authentication (npx / Containers)
270
+
271
+ For running via `npx` or in containerized environments where you can't rely on local files, you can pass OAuth credentials entirely via environment variables.
272
+
273
+ **Option A: Individual environment variables**
274
+
275
+ ```bash
276
+ # Your OAuth client credentials (from credentials.json)
277
+ export GOOGLE_CLIENT_ID="your-client-id.apps.googleusercontent.com"
278
+ export GOOGLE_CLIENT_SECRET="your-client-secret"
279
+ export GOOGLE_REFRESH_TOKEN="your-refresh-token"
280
+ ```
281
+
282
+ **Option B: Full credentials JSON as env var**
283
+
284
+ ```bash
285
+ # The entire contents of credentials.json as a single env var
286
+ export GOOGLE_CREDENTIALS_JSON='{"installed":{"client_id":"...","client_secret":"..."}}'
287
+ export GOOGLE_REFRESH_TOKEN="your-refresh-token"
288
+ ```
289
+
290
+ **Getting a refresh token:**
291
+
292
+ If you have the client ID and secret but no refresh token yet, run the server with just those set:
293
+
294
+ ```bash
295
+ GOOGLE_CLIENT_ID="..." GOOGLE_CLIENT_SECRET="..." npx @brainwavesio/google-docs-mcp
296
+ ```
297
+
298
+ The server will prompt you through the OAuth flow and print the refresh token for you to save.
299
+
300
+ **Claude Desktop config with env vars:**
301
+
302
+ ```json
303
+ {
304
+ "mcpServers": {
305
+ "google-docs-mcp": {
306
+ "command": "npx",
307
+ "args": ["@brainwavesio/google-docs-mcp"],
308
+ "env": {
309
+ "GOOGLE_CLIENT_ID": "your-client-id.apps.googleusercontent.com",
310
+ "GOOGLE_CLIENT_SECRET": "your-client-secret",
311
+ "GOOGLE_REFRESH_TOKEN": "your-refresh-token"
312
+ }
313
+ }
314
+ }
315
+ }
316
+ ```
317
+
318
+ **Authentication Priority:**
319
+
320
+ The server checks for credentials in this order:
321
+ 1. Service account (`SERVICE_ACCOUNT_PATH` env var)
322
+ 2. Environment variables (`GOOGLE_CLIENT_ID` + `GOOGLE_CLIENT_SECRET` + `GOOGLE_REFRESH_TOKEN`, or `GOOGLE_CREDENTIALS_JSON`)
323
+ 3. File-based OAuth (`credentials.json` + `token.json` in project root)
324
+
325
+ ### Step 6: Configure Claude Desktop (Optional)
326
+
327
+ If you want to use this server with Claude Desktop, you need to tell Claude how to run it.
328
+
329
+ 1. **Find Your Absolute Path:** You need the full path to the server code.
330
+ - In your terminal, make sure you are still inside the `mcp-googledocs-server` directory.
331
+ - Run the `pwd` command (on macOS/Linux) or `cd` (on Windows, just displays the path).
332
+ - Copy the full path (e.g., `/Users/yourname/projects/mcp-googledocs-server` or `C:\Users\yourname\projects\mcp-googledocs-server`).
333
+ 2. **Locate `mcp_config.json`:** Find Claude's configuration file:
334
+ - **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/`)
335
+ - **Windows:** `%APPDATA%\Claude\mcp_config.json` (Paste `%APPDATA%\Claude` into File Explorer's address bar)
336
+ - **Linux:** `~/.config/Claude/mcp_config.json`
337
+ - _If the `Claude` folder or `mcp_config.json` file doesn't exist, create them._
338
+ 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**:
339
+
340
+ ```json
341
+ {
342
+ "mcpServers": {
343
+ "google-docs-mcp": {
344
+ "command": "node",
345
+ "args": [
346
+ "/PATH/TO/YOUR/CLONED/REPO/mcp-googledocs-server/dist/server.js"
347
+ ],
348
+ "env": {}
349
+ }
350
+ // Add commas here if you have other servers defined
351
+ }
352
+ // Other Claude settings might be here
353
+ }
354
+ ```
355
+
356
+ - **Make sure the path in `"args"` is correct and absolute!**
357
+ - If the file already existed, carefully merge this entry into the existing `mcpServers` object. Ensure the JSON is valid (check commas!).
358
+
359
+ 4. **Save `mcp_config.json`.**
360
+ 5. **Restart Claude Desktop:** Close Claude completely and reopen it.
361
+
362
+ ---
363
+
364
+ ## Usage with Claude Desktop
365
+
366
+ Once configured, you should be able to use the tools in your chats with Claude:
367
+
368
+ - "Use the `google-docs-mcp` server to read the document with ID `YOUR_GOOGLE_DOC_ID`."
369
+ - "Can you get the content of Google Doc `YOUR_GOOGLE_DOC_ID`?"
370
+ - "Append 'This was added by Claude!' to document `YOUR_GOOGLE_DOC_ID` using the `google-docs-mcp` tool."
371
+
372
+ ### Working with Tabs
373
+
374
+ Google Docs now supports multi-tab documents. This MCP server provides full support for working with tabs:
375
+
376
+ **Listing Tabs:**
377
+
378
+ - "List all tabs in document `YOUR_GOOGLE_DOC_ID` using the `listDocumentTabs` tool."
379
+ - "Show me the tab structure with content summary for document `YOUR_GOOGLE_DOC_ID`."
380
+
381
+ **Reading from Specific Tabs:**
382
+
383
+ - "Read the content from tab `TAB_ID` in document `YOUR_GOOGLE_DOC_ID` using the `readGoogleDoc` tool."
384
+ - "Get the markdown content from tab `TAB_ID` in document `YOUR_GOOGLE_DOC_ID`."
385
+
386
+ **Writing to Specific Tabs:**
387
+
388
+ - "Append 'New content' to tab `TAB_ID` in document `YOUR_GOOGLE_DOC_ID`."
389
+ - "Insert text at index 100 in tab `TAB_ID` of document `YOUR_GOOGLE_DOC_ID`."
390
+ - "Delete content from range 50-100 in tab `TAB_ID` of document `YOUR_GOOGLE_DOC_ID`."
391
+
392
+ **Note:** The following tools support the optional `tabId` parameter:
393
+
394
+ - `readGoogleDoc` - Read from a specific tab
395
+ - `appendToGoogleDoc` - Append to a specific tab
396
+ - `insertText` - Insert text into a specific tab
397
+ - `deleteRange` - Delete content from a specific tab
398
+
399
+ When `tabId` is not specified, operations target the first tab (or the legacy document body for older documents without tabs).
400
+
401
+ ### Advanced Usage Examples:
402
+
403
+ **Google Docs:**
404
+ - **Text Styling**: "Use `applyTextStyle` to make the text 'Important Section' bold and red (#FF0000) in document `YOUR_GOOGLE_DOC_ID`."
405
+ - **Paragraph Styling**: "Use `applyParagraphStyle` to center-align the paragraph containing 'Title Here' in document `YOUR_GOOGLE_DOC_ID`."
406
+ - **Table Creation**: "Insert a 3x4 table at index 500 in document `YOUR_GOOGLE_DOC_ID` using the `insertTable` tool."
407
+ - **Image Insertion**: "Use `insertImageFromUrl` to insert an image from 'https://example.com/image.png' at index 100 in document `YOUR_GOOGLE_DOC_ID`."
408
+ - **Local Image Upload**: "Use `insertLocalImage` to upload '/path/to/image.jpg' and insert it at index 200 in document `YOUR_GOOGLE_DOC_ID`."
409
+ - **Legacy Formatting**: "Use `formatMatchingText` to find the second instance of 'Project Alpha' and make it blue (#0000FF) in doc `YOUR_GOOGLE_DOC_ID`."
410
+
411
+ **Google Sheets:**
412
+ - **Read Data**: "Read range A1:B10 from spreadsheet `YOUR_SPREADSHEET_ID` using `readSpreadsheet`."
413
+ - **Write Data**: "Write data [[1, 2], [3, 4]] to range A1:B2 in spreadsheet `YOUR_SPREADSHEET_ID`."
414
+ - **Append Rows**: "Append rows [[5, 6], [7, 8]] to spreadsheet `YOUR_SPREADSHEET_ID` starting at A1."
415
+ - **Create Spreadsheet**: "Create a new spreadsheet titled 'Sales Data' with initial data [[Name, Amount], [Product A, 100]]."
416
+ - **Get Info**: "Get information about spreadsheet `YOUR_SPREADSHEET_ID` including all sheets."
417
+ - **Add Sheet**: "Add a new sheet named 'Summary' to spreadsheet `YOUR_SPREADSHEET_ID`."
418
+ - **Clear Range**: "Clear the range A1:B10 in spreadsheet `YOUR_SPREADSHEET_ID`."
419
+ - **List Spreadsheets**: "List all my Google Spreadsheets modified in the last 30 days."
420
+
421
+ Remember to replace:
422
+ - `YOUR_GOOGLE_DOC_ID` with the actual ID from a Google Doc's URL (the long string between `/d/` and `/edit`)
423
+ - `YOUR_SPREADSHEET_ID` with the actual ID from a Google Sheet's URL (the long string between `/d/` and `/edit`)
424
+
425
+ 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.
426
+
427
+ ---
428
+
429
+ ## Image Insertion
430
+
431
+ This server provides two ways to insert images into Google Documents:
432
+
433
+ ### 1. Insert from Public URL (`insertImageFromUrl`)
434
+
435
+ Inserts an image directly from a publicly accessible URL. The image URL must be accessible without authentication.
436
+
437
+ **Parameters:**
438
+
439
+ - `documentId`: The Google Document ID
440
+ - `imageUrl`: Publicly accessible URL (http:// or https://)
441
+ - `index`: Position in the document (1-based indexing)
442
+ - `width` (optional): Image width in points
443
+ - `height` (optional): Image height in points
444
+
445
+ **Example:**
446
+
447
+ ```
448
+ "Insert an image from https://example.com/logo.png at index 100 in document YOUR_DOC_ID"
449
+ ```
450
+
451
+ ### 2. Upload Local Image (`insertLocalImage`)
452
+
453
+ Uploads a local image file to Google Drive and inserts it into the document. This is a two-step process that:
454
+
455
+ 1. Uploads the image to Google Drive (by default to the same folder as the document)
456
+ 2. Makes the image publicly readable
457
+ 3. Inserts the image into the document using its Drive URL
458
+
459
+ **Parameters:**
460
+
461
+ - `documentId`: The Google Document ID
462
+ - `localImagePath`: Absolute path to the local image file
463
+ - `index`: Position in the document (1-based indexing)
464
+ - `width` (optional): Image width in points
465
+ - `height` (optional): Image height in points
466
+ - `uploadToSameFolder` (optional, default: true): If true, uploads to the document's folder; if false, uploads to Drive root
467
+
468
+ **Supported formats:** .jpg, .jpeg, .png, .gif, .bmp, .webp, .svg
469
+
470
+ **Example:**
471
+
472
+ ```
473
+ "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"
474
+ ```
475
+
476
+ **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.
477
+
478
+ ---
479
+
480
+ ## Security & Token Storage
481
+
482
+ - **`.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`**.
483
+ - **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.
484
+
485
+ ---
486
+
487
+ ## Testing
488
+
489
+ The multi-tab support features have been thoroughly tested and verified:
490
+
491
+ βœ… **Tested Features:**
492
+
493
+ - `listDocumentTabs` - Lists all tabs with IDs, titles, positions, and content summaries
494
+ - `readGoogleDoc` with `tabId` - Reads specific tabs; backward compatible without `tabId`
495
+ - `appendToGoogleDoc` with `tabId` - Appends to specific tabs without affecting others
496
+ - `insertText` with `tabId` - Inserts text at specific positions in specific tabs
497
+ - `deleteRange` with `tabId` - Deletes content from specific tabs in isolation
498
+ - Multi-tab operations - Sequential operations on different tabs work independently
499
+ - Error handling - Invalid tab IDs return clear, helpful error messages
500
+ - Backward compatibility - Operations without `tabId` default to first tab (legacy documents supported)
501
+
502
+ All tab-related features have been validated with real Google Docs containing multiple tabs, confirming:
503
+
504
+ - Tab isolation (operations on one tab don't affect others)
505
+ - Proper tab ID validation and error messages
506
+ - Correct content retrieval and manipulation per tab
507
+ - Full backward compatibility with single-tab and legacy documents
508
+
509
+ ## Google Sheets Usage
510
+
511
+ ### A1 Notation
512
+
513
+ Google Sheets uses A1 notation to specify ranges. Examples:
514
+ - `A1` - Single cell
515
+ - `A1:B10` - Range from A1 to B10
516
+ - `Sheet1!A1:B10` - Range on a specific sheet named "Sheet1"
517
+ - `A:A` - Entire column A
518
+ - `1:1` - Entire row 1
519
+
520
+ ### Value Input Options
521
+
522
+ When writing data to spreadsheets, you can choose how values are interpreted:
523
+ - **USER_ENTERED** (default): Values are parsed as if typed by a user (formulas work, dates are recognized, etc.)
524
+ - **RAW**: Values are stored exactly as provided (no parsing)
525
+
526
+ ### Example Workflow
527
+
528
+ ```bash
529
+ # 1. Create a new spreadsheet
530
+ "Create a spreadsheet titled 'Monthly Report'"
531
+
532
+ # 2. Write headers
533
+ "Write [[Date, Sales, Expenses]] to range A1:C1 in spreadsheet YOUR_SPREADSHEET_ID"
534
+
535
+ # 3. Append data rows
536
+ "Append rows [[2024-01-01, 1000, 500], [2024-01-02, 1200, 600]] to spreadsheet YOUR_SPREADSHEET_ID starting at A2"
537
+
538
+ # 4. Read the data back
539
+ "Read range A1:C3 from spreadsheet YOUR_SPREADSHEET_ID"
540
+
541
+ # 5. Add a new sheet for analysis
542
+ "Add a new sheet named 'Analysis' to spreadsheet YOUR_SPREADSHEET_ID"
543
+ ```
544
+
545
+ ## Known Limitations
546
+
547
+ While this MCP server provides comprehensive Google Docs, Sheets, and Drive functionality, there are some limitations imposed by the Google APIs themselves:
548
+
549
+ ### Comment Anchoring
550
+
551
+ **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.
552
+
553
+ - **Workaround**: Comments created manually in the Google Docs UI are properly anchored
554
+ - **Other Operations**: Reply, delete, and list operations work correctly on all comments regardless of how they were created
555
+
556
+ ### Comment Resolution
557
+
558
+ **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.
559
+
560
+ - **Workaround**: Resolve comments manually in the Google Docs web interface
561
+
562
+ ### Converted Documents
563
+
564
+ **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.
565
+
566
+ ## Troubleshooting
567
+
568
+ - **Claude shows "Failed" or "Could not attach":**
569
+ - Double-check the absolute path in `mcp_config.json`.
570
+ - Ensure you ran `npm run build` successfully and the `dist` folder exists.
571
+ - 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.
572
+ - Check the Claude Desktop logs (see the official MCP debugging guide).
573
+ - Make sure all `console.log` status messages in the server code were changed to `console.error`.
574
+ - **Google Authorization Errors:**
575
+ - Ensure you enabled the correct APIs (Docs, Sheets, Drive).
576
+ - Make sure you added your email as a Test User on the OAuth Consent Screen.
577
+ - Verify the `credentials.json` file is correctly placed in the project root.
578
+ - **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.
579
+ - **Tab-related Errors:**
580
+ - If you get "Tab with ID not found", use `listDocumentTabs` to see all available tab IDs
581
+ - Ensure you're using the correct tab ID format (typically a short alphanumeric string)
582
+ - Single-tab documents don't require `tabId` - operations work on the document body automatically
583
+
584
+ ---
585
+
586
+ ## License
587
+
588
+ This project is licensed under the MIT License - see the `LICENSE` file for details. (Note: You should add a `LICENSE` file containing the MIT License text to your repository).