@alanse/mcp-server-google-workspace 0.2.0 → 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.
Files changed (34) hide show
  1. package/LICENSE +92 -18
  2. package/README.md +135 -36
  3. package/dist/auth.js +3 -2
  4. package/dist/index.js +6 -6
  5. package/dist/lib/document-id-resolver.js +76 -0
  6. package/dist/lib/response-formatter.js +82 -0
  7. package/dist/lib/validation.js +112 -0
  8. package/dist/tools/docs/basic/gdocs_create.js +37 -0
  9. package/dist/tools/docs/basic/gdocs_get_metadata.js +45 -0
  10. package/dist/tools/docs/basic/gdocs_list_documents.js +59 -0
  11. package/dist/tools/docs/basic/gdocs_read.js +62 -0
  12. package/dist/tools/docs/content/gdocs_append_text.js +57 -0
  13. package/dist/tools/docs/content/gdocs_apply_style.js +86 -0
  14. package/dist/tools/docs/content/gdocs_create_heading.js +89 -0
  15. package/dist/tools/docs/content/gdocs_create_list.js +86 -0
  16. package/dist/tools/docs/content/gdocs_delete_text.js +64 -0
  17. package/dist/tools/docs/content/gdocs_format_text.js +137 -0
  18. package/dist/tools/docs/content/gdocs_insert_text.js +62 -0
  19. package/dist/tools/docs/content/gdocs_replace_text.js +64 -0
  20. package/dist/tools/docs/content/gdocs_set_alignment.js +76 -0
  21. package/dist/tools/docs/content/gdocs_update_text.js +78 -0
  22. package/dist/tools/docs/elements/gdocs_batch_update.js +108 -0
  23. package/dist/tools/docs/elements/gdocs_create_table.js +73 -0
  24. package/dist/tools/docs/elements/gdocs_export.js +62 -0
  25. package/dist/tools/docs/elements/gdocs_insert_image.js +96 -0
  26. package/dist/tools/docs/elements/gdocs_insert_link.js +77 -0
  27. package/dist/tools/docs/elements/gdocs_insert_page_break.js +55 -0
  28. package/dist/tools/docs/elements/gdocs_insert_toc.js +71 -0
  29. package/dist/tools/docs/elements/gdocs_merge_documents.js +104 -0
  30. package/dist/tools/docs/elements/gdocs_suggest_mode.js +41 -0
  31. package/dist/tools/drive/drive_read_file.js +77 -0
  32. package/dist/tools/drive/drive_search.js +71 -0
  33. package/dist/tools/index.js +124 -5
  34. package/package.json +3 -3
package/LICENSE CHANGED
@@ -1,21 +1,95 @@
1
- MIT License
1
+ Elastic License 2.0
2
+
3
+ URL: https://www.elastic.co/licensing/elastic-license
2
4
 
3
5
  Copyright (c) 2026 Alanse inc.
4
6
 
5
- Permission is hereby granted, free of charge, to any person obtaining a copy
6
- of this software and associated documentation files (the "Software"), to deal
7
- in the Software without restriction, including without limitation the rights
8
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
- copies of the Software, and to permit persons to whom the Software is
10
- furnished to do so, subject to the following conditions:
11
-
12
- The above copyright notice and this permission notice shall be included in all
13
- copies or substantial portions of the Software.
14
-
15
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
- SOFTWARE.
7
+ ## Acceptance
8
+
9
+ By using the software, you agree to all of the terms and conditions below.
10
+
11
+ ## Copyright License
12
+
13
+ The licensor grants you a non-exclusive, royalty-free, worldwide,
14
+ non-sublicensable, non-transferable license to use, copy, distribute, make
15
+ available, and prepare derivative works of the software, in each case subject to
16
+ the limitations and conditions below.
17
+
18
+ ## Limitations
19
+
20
+ You may not provide the software to third parties as a hosted or managed
21
+ service, where the service provides users with access to any substantial set of
22
+ the features or functionality of the software.
23
+
24
+ You may not move, change, disable, or circumvent the license key functionality
25
+ in the software, and you may not remove or obscure any functionality in the
26
+ software that is protected by the license key.
27
+
28
+ You may not alter, remove, or obscure any licensing, copyright, or other notices
29
+ of the licensor in the software. Any use of the licensor's trademarks is subject
30
+ to applicable law.
31
+
32
+ ## Patents
33
+
34
+ The licensor grants you a license, under any patent claims the licensor can
35
+ license, or becomes able to license, to make, have made, use, sell, offer for
36
+ sale, import and have imported the software, in each case subject to the
37
+ limitations and conditions in this license. This license does not cover any
38
+ patent claims that you cause to be infringed by modifications or additions to
39
+ the software. If you or your company make any written claim that the software
40
+ infringes or contributes to infringement of any patent, your patent license for
41
+ the software granted under these terms ends immediately. If your company makes
42
+ such a claim, your patent license ends immediately for work on behalf of your
43
+ company.
44
+
45
+ ## Notices
46
+
47
+ You must ensure that anyone who gets a copy of any part of the software from you
48
+ also gets a copy of these terms.
49
+
50
+ If you modify the software, you must include in any modified copies of the
51
+ software prominent notices stating that you have modified the software.
52
+
53
+ ## No Other Rights
54
+
55
+ These terms do not imply any licenses other than those expressly granted in
56
+ these terms.
57
+
58
+ ## Termination
59
+
60
+ If you use the software in violation of these terms, such use is not licensed,
61
+ and your licenses will automatically terminate. If the licensor provides you
62
+ with a notice of your violation, and you cease all violation of this license no
63
+ later than 30 days after you receive that notice, your licenses will be
64
+ reinstated retroactively. However, if you violate these terms after such
65
+ reinstatement, any additional violation of these terms will cause your licenses
66
+ to terminate automatically and permanently.
67
+
68
+ ## No Liability
69
+
70
+ *As far as the law allows, the software comes as is, without any warranty or
71
+ condition, and the licensor will not be liable to you for any damages arising
72
+ out of these terms or the use or nature of the software, under any kind of
73
+ legal claim.*
74
+
75
+ ## Definitions
76
+
77
+ The **licensor** is the entity offering these terms, and the **software** is the
78
+ software the licensor makes available under these terms, including any portion
79
+ of it.
80
+
81
+ **you** refers to the individual or entity agreeing to these terms.
82
+
83
+ **your company** is any legal entity, sole proprietorship, or other kind of
84
+ organization that you work for, plus all organizations that have control over,
85
+ are under the control of, or are under common control with that
86
+ organization. **control** means ownership of substantially all the assets of an
87
+ entity, or the power to direct its management and policies by vote, contract, or
88
+ otherwise. Control can be direct or indirect.
89
+
90
+ **your licenses** are all the licenses granted to you for the software under
91
+ these terms.
92
+
93
+ **use** means anything you do with the software requiring one of your licenses.
94
+
95
+ **trademark** means trademarks, service marks, and similar rights.
package/README.md CHANGED
@@ -1,32 +1,44 @@
1
1
  # MCP Server - Google Workspace
2
2
 
3
- **The most comprehensive MCP server for Google Workspace** - Complete programmatic control over Sheets, Drive, and future Docs, Calendar, Forms integration.
3
+ **The most comprehensive MCP server for Google Workspace** - Complete programmatic control over Sheets, Docs, Drive, and future Calendar, Forms integration.
4
4
 
5
- 🚀 **Current Status**: 59 tools (Drive: 2, Sheets: 57)
6
- 📅 **Roadmap**: Google Docs, Calendar, Forms, Gmail, Slides
5
+ 🚀 **Current Status**: 82 tools (Drive: 2, Sheets: 57, Docs: 23)
6
+ 📅 **Roadmap**: Calendar, Forms, Gmail, Slides
7
7
 
8
- This is an extended version of [@isaacphi/mcp-gdrive](https://github.com/isaacphi/mcp-gdrive), adding **53 additional Google Sheets API tools** for complete spreadsheet management and preparing for comprehensive Google Workspace coverage.
8
+ Extended implementation by Alanse inc.
9
9
 
10
- ## Credits
11
-
12
- This project is based on:
13
- - Original code by **Anthropic, PBC** from [MCP Servers](https://github.com/modelcontextprotocol/servers/tree/main/src/gdrive) (MIT License)
14
- - Enhanced by **Phil Isaac** in [@isaacphi/mcp-gdrive](https://github.com/isaacphi/mcp-gdrive) (MIT License)
15
- - **Extended implementation** by **Alanse株式会社 / Daichi Okazaki** (2026)
16
-
17
- All contributions are licensed under the MIT License.
10
+ ---
18
11
 
19
12
  ## 🚀 Features
20
13
 
21
- ### 📊 Extended Google Sheets API Implementation
14
+ ### 📊 Extended Google Workspace API Implementation
22
15
 
23
- **59 Total Tools** = 2 GDrive + **57 Google Sheets** operations
16
+ **82 Total Tools** = 2 GDrive + **57 Google Sheets** + **23 Google Docs** operations
24
17
 
25
18
  #### Tool Categories
26
19
 
27
20
  **Google Drive Operations (2 tools)**
28
21
  - Search & File Management
29
22
 
23
+ **Google Docs Operations (23 tools)**
24
+
25
+ **Basic Operations (4 tools)**
26
+ - Create, Read, Get Metadata, List Documents
27
+
28
+ **Content & Formatting (10 tools)**
29
+ - Insert/Update/Delete/Replace/Append Text
30
+ - Format Text (Bold, Italic, Font, Color)
31
+ - Create Headings (H1-H6)
32
+ - Create Lists (Bulleted/Numbered)
33
+ - Set Paragraph Alignment & Apply Styles
34
+
35
+ **Elements & Advanced (9 tools)**
36
+ - Insert Images, Tables, Page Breaks, Links
37
+ - Insert Table of Contents
38
+ - Batch Update Operations
39
+ - Merge Documents, Export to PDF/DOCX/HTML
40
+ - Suggestion Mode
41
+
30
42
  **Sheet Management (13 tools)**
31
43
  - Create, Read, List, Add, Delete, Rename Sheets
32
44
  - Insert/Delete Rows & Columns
@@ -65,7 +77,7 @@ For complete tool documentation, see [docs/api-comparison.md](./docs/api-compari
65
77
 
66
78
  The server provides access to Google Drive files:
67
79
 
68
- - **Files** (`gdrive:///<file_id>`)
80
+ - **Files** (`gworkspace:///<file_id>`)
69
81
  - Supports all file types
70
82
  - Google Workspace files are automatically exported:
71
83
  - Docs → Markdown
@@ -83,12 +95,12 @@ The server provides access to Google Drive files:
83
95
  5. In order to allow interaction with sheets and docs you will also need to enable the [Google Sheets API](https://console.cloud.google.com/apis/api/sheets.googleapis.com/) and [Google Docs API](https://console.cloud.google.com/marketplace/product/google/docs.googleapis.com) in your workspaces Enabled API and Services section.
84
96
  6. [Create an OAuth Client ID](https://console.cloud.google.com/apis/credentials/oauthclient) for application type "Desktop App"
85
97
  7. Download the JSON file of your client's OAuth keys
86
- 8. Rename the key file to `gcp-oauth.keys.json` and place into the path you specify with `GDRIVE_CREDS_DIR` (i.e. `/Users/username/.config/mcp-gdrive`)
98
+ 8. Rename the key file to `gcp-oauth.keys.json` and place into the path you specify with `GWORKSPACE_CREDS_DIR` (i.e. `/Users/username/.config/mcp-google-workspace`)
87
99
  9. Note your OAuth Client ID and Client Secret. They must be provided as environment variables along with your configuration directory.
88
100
  10. You will also need to setup a .env file within the project with the following fields. You can find the Client ID and Client Secret in the Credentials section of the Google Cloud Console.
89
101
 
90
- ```
91
- GDRIVE_CREDS_DIR=/path/to/config/directory
102
+ ```bash
103
+ GWORKSPACE_CREDS_DIR=/path/to/config/directory
92
104
  CLIENT_ID=<CLIENT_ID>
93
105
  CLIENT_SECRET=<CLIENT_SECRET>
94
106
  ```
@@ -101,9 +113,7 @@ Next you will need to run `node ./dist/index.js` to trigger the authentication s
101
113
 
102
114
  You will be prompted to authenticate with your browser. You must authenticate with an account in the same organization as your Google Cloud project.
103
115
 
104
- Your OAuth token is saved in the directory specified by the `GDRIVE_CREDS_DIR` environment variable.
105
-
106
- ![Authentication Prompt](https://i.imgur.com/TbyV6Yq.png)
116
+ Your OAuth token is saved in the directory specified by the `GWORKSPACE_CREDS_DIR` environment variable.
107
117
 
108
118
  ### Usage with Desktop App
109
119
 
@@ -118,13 +128,28 @@ To integrate this server with the desktop app, add the following to your app's s
118
128
  "env": {
119
129
  "CLIENT_ID": "<CLIENT_ID>",
120
130
  "CLIENT_SECRET": "<CLIENT_SECRET>",
121
- "GDRIVE_CREDS_DIR": "/path/to/config/directory"
131
+ "GWORKSPACE_CREDS_DIR": "/path/to/config/directory"
122
132
  }
123
133
  }
124
134
  }
125
135
  }
126
136
  ```
127
137
 
138
+ ### Usage with Claude Code CLI
139
+
140
+ To add this server to Claude Code CLI, use the following command:
141
+
142
+ ```bash
143
+ claude mcp add google-workspace \
144
+ -e CLIENT_ID=<YOUR_CLIENT_ID> \
145
+ -e CLIENT_SECRET=<YOUR_CLIENT_SECRET> \
146
+ -e GWORKSPACE_CREDS_DIR=/path/to/config/directory \
147
+ -- npx -y @alanse/mcp-server-google-workspace \
148
+ -s user
149
+ ```
150
+
151
+ Replace `<YOUR_CLIENT_ID>`, `<YOUR_CLIENT_SECRET>`, and `/path/to/config/directory` with your actual values.
152
+
128
153
  ## 📈 Project Status
129
154
 
130
155
  ✅ **Phase 1-12 Complete** (2026-01-06)
@@ -149,25 +174,99 @@ To integrate this server with the desktop app, add the following to your app's s
149
174
 
150
175
  **Goal**: 100+ tools covering the entire Google Workspace ecosystem
151
176
 
152
- ## 📄 License
177
+ ## 🛠️ Development
178
+
179
+ ### Prerequisites
153
180
 
154
- This project is licensed under the **MIT License**.
181
+ - Node.js 20 or higher
182
+ - npm or pnpm
183
+ - Google Cloud Platform account with OAuth credentials
155
184
 
156
- ### Copyright Notices
185
+ ### Local Development
157
186
 
158
- - Original code: © 2024 Anthropic, PBC
159
- - Base implementation: © 2024 Phil Isaac
160
- - Extended implementation: © 2026 Alanse株式会社 / Daichi Okazaki
187
+ ```bash
188
+ # Clone the repository
189
+ git clone https://github.com/alanse-inc/mcp-server-google-workspace.git
190
+ cd mcp-server-google-workspace
191
+
192
+ # Install dependencies
193
+ npm install
194
+
195
+ # Build the project
196
+ npm run build
197
+
198
+ # Run tests
199
+ npm test
200
+
201
+ # Watch mode for development
202
+ npm run watch
203
+ ```
161
204
 
162
- You are free to use, modify, and distribute this software under the terms of the MIT License. See the [LICENSE](./LICENSE) file for details.
205
+ ### Testing
206
+
207
+ The project uses [Vitest](https://vitest.dev/) for testing:
208
+
209
+ ```bash
210
+ # Run all tests
211
+ npm test
212
+
213
+ # Watch mode
214
+ npm run test:watch
215
+
216
+ # UI mode
217
+ npm run test:ui
218
+
219
+ # Coverage report
220
+ npm run test:coverage
221
+ ```
222
+
223
+ ### Release Process
224
+
225
+ This project uses [release-please](https://github.com/googleapis/release-please) for automated releases.
226
+
227
+ **How it works:**
228
+
229
+ 1. Follow [Conventional Commits](https://www.conventionalcommits.org/) specification for commit messages
230
+ 2. When commits are merged to `main`, release-please creates/updates a release PR
231
+ 3. Merging the release PR triggers:
232
+ - CHANGELOG.md update
233
+ - Version bump in package.json
234
+ - GitHub Release creation
235
+ - npm package publication
236
+
237
+ **Commit message format:**
238
+
239
+ ```text
240
+ feat: add new feature
241
+ fix: fix a bug
242
+ docs: update documentation
243
+ chore: update dependencies
244
+ refactor: code refactoring
245
+ test: add tests
246
+ ```
247
+
248
+ **Example workflow:**
249
+
250
+ ```bash
251
+ # Make changes
252
+ git checkout -b feature/new-tool
253
+ # ... make changes ...
254
+ git commit -m "feat: add gdocs_insert_table tool"
255
+ git push origin feature/new-tool
256
+
257
+ # Create PR and merge to main
258
+ # → release-please creates a release PR automatically
259
+ # → Merge the release PR to publish
260
+ ```
261
+
262
+ ## 📄 License
163
263
 
164
- ## 🙏 Acknowledgments
264
+ This project is licensed under the **Elastic License 2.0**.
165
265
 
166
- Special thanks to:
167
- - **Anthropic, PBC** for the original MCP server implementation
168
- - **Phil Isaac** for the enhanced Google Drive & Sheets integration
169
- - The **Model Context Protocol** team for the excellent framework
266
+ Copyright © 2026 Alanse inc.
170
267
 
171
- ## 📚 Related Documentation
268
+ See the [LICENSE](./LICENSE) file for details.
172
269
 
173
- - [docs/api-comparison.md](./docs/api-comparison.md) - MCP vs Google Sheets API comparison
270
+ **Key restrictions**:
271
+ - You may not provide the software to third parties as a hosted or managed service where the service provides users with access to any substantial set of the features or functionality of the software.
272
+ - You may not alter, remove, or obscure any licensing, copyright, or other notices of the licensor in the software.
package/dist/auth.js CHANGED
@@ -5,9 +5,10 @@ import path from "path";
5
5
  export const SCOPES = [
6
6
  "https://www.googleapis.com/auth/drive.readonly",
7
7
  "https://www.googleapis.com/auth/spreadsheets",
8
+ "https://www.googleapis.com/auth/documents",
8
9
  ];
9
10
  // Get credentials directory from environment variable or use default
10
- const CREDS_DIR = process.env.GDRIVE_CREDS_DIR ||
11
+ const CREDS_DIR = process.env.GWORKSPACE_CREDS_DIR ||
11
12
  path.join(path.dirname(new URL(import.meta.url).pathname), "../../../");
12
13
  // Ensure the credentials directory exists
13
14
  function ensureCredsDirectory() {
@@ -20,7 +21,7 @@ function ensureCredsDirectory() {
20
21
  throw error;
21
22
  }
22
23
  }
23
- const credentialsPath = path.join(CREDS_DIR, ".gdrive-server-credentials.json");
24
+ const credentialsPath = path.join(CREDS_DIR, ".gworkspace-credentials.json");
24
25
  async function authenticateWithTimeout(keyfilePath, SCOPES, timeoutMs = 30000) {
25
26
  const timeoutPromise = new Promise((_, reject) => setTimeout(() => reject(new Error("Authentication timed out")), timeoutMs));
26
27
  const authPromise = authenticate({
package/dist/index.js CHANGED
@@ -8,12 +8,12 @@ import { getValidCredentials, setupTokenRefresh, loadCredentialsQuietly, } from
8
8
  import { tools } from "./tools/index.js";
9
9
  const drive = google.drive("v3");
10
10
  const server = new Server({
11
- name: "example-servers/gdrive",
12
- version: "0.1.0",
11
+ name: "@alanse/mcp-server-google-workspace",
12
+ version: "0.2.2",
13
13
  }, {
14
14
  capabilities: {
15
15
  resources: {
16
- schemes: ["gdrive"], // Declare that we handle gdrive:/// URIs
16
+ schemes: ["gworkspace"], // Declare that we handle gworkspace:/// URIs
17
17
  listable: true, // Support listing available resources
18
18
  readable: true, // Support reading resource contents
19
19
  },
@@ -47,7 +47,7 @@ server.setRequestHandler(ListResourcesRequestSchema, async (request) => {
47
47
  const files = res.data.files;
48
48
  return {
49
49
  resources: files.map((file) => ({
50
- uri: `gdrive:///${file.id}`,
50
+ uri: `gworkspace:///${file.id}`,
51
51
  mimeType: file.mimeType,
52
52
  name: file.name,
53
53
  })),
@@ -56,8 +56,8 @@ server.setRequestHandler(ListResourcesRequestSchema, async (request) => {
56
56
  });
57
57
  server.setRequestHandler(ReadResourceRequestSchema, async (request) => {
58
58
  await ensureAuthQuietly();
59
- const fileId = request.params.uri.replace("gdrive:///", "");
60
- const readFileTool = tools[1]; // gdrive_read_file is the second tool
59
+ const fileId = request.params.uri.replace("gworkspace:///", "");
60
+ const readFileTool = tools[1]; // drive_read_file is the second tool
61
61
  const result = await readFileTool.handler({ fileId });
62
62
  // Extract the file contents from the tool response
63
63
  const fileContents = result.content[0].text.split("\n\n")[1]; // Skip the "Contents of file:" prefix
@@ -0,0 +1,76 @@
1
+ /**
2
+ * DocumentIdResolver - Resolves various document ID formats across Google Workspace
3
+ *
4
+ * Supports:
5
+ * - Direct document IDs
6
+ * - Full Google Workspace URLs (Docs, Sheets, Slides, Drive)
7
+ * - Service type detection
8
+ */
9
+ export class DocumentIdResolver {
10
+ static URL_PATTERNS = {
11
+ docs: /docs\.google\.com\/document\/d\/([a-zA-Z0-9-_]+)/,
12
+ sheets: /docs\.google\.com\/spreadsheets\/d\/([a-zA-Z0-9-_]+)/,
13
+ slides: /docs\.google\.com\/presentation\/d\/([a-zA-Z0-9-_]+)/,
14
+ drive: /drive\.google\.com\/file\/d\/([a-zA-Z0-9-_]+)/,
15
+ };
16
+ static ID_PATTERN = /^[a-zA-Z0-9-_]{25,}$/;
17
+ /**
18
+ * Resolve a document reference from ID or URL
19
+ */
20
+ static resolve(input) {
21
+ // Try URL extraction first
22
+ const fromUrl = this.extractFromUrl(input);
23
+ if (fromUrl) {
24
+ return { id: fromUrl.id, type: fromUrl.type, url: input };
25
+ }
26
+ // Validate as direct ID
27
+ if (this.validate(input)) {
28
+ return { id: input, type: "unknown" };
29
+ }
30
+ throw new Error(`Invalid document reference: ${input}. Expected a Google Workspace URL or document ID.`);
31
+ }
32
+ /**
33
+ * Extract document ID from Google Workspace URL
34
+ */
35
+ static extractFromUrl(url) {
36
+ for (const [type, pattern] of Object.entries(this.URL_PATTERNS)) {
37
+ const match = url.match(pattern);
38
+ if (match) {
39
+ return {
40
+ id: match[1],
41
+ type: type,
42
+ };
43
+ }
44
+ }
45
+ return null;
46
+ }
47
+ /**
48
+ * Validate document ID format
49
+ */
50
+ static validate(id, type) {
51
+ if (!this.ID_PATTERN.test(id)) {
52
+ return false;
53
+ }
54
+ // Additional type-specific validation could go here
55
+ return true;
56
+ }
57
+ /**
58
+ * Get service type from URL or ID
59
+ */
60
+ static getServiceType(input) {
61
+ const ref = this.resolve(input);
62
+ return ref.type;
63
+ }
64
+ /**
65
+ * Create a Google Workspace URL from document ID and type
66
+ */
67
+ static createUrl(documentId, type) {
68
+ const urlTemplates = {
69
+ docs: `https://docs.google.com/document/d/${documentId}/edit`,
70
+ sheets: `https://docs.google.com/spreadsheets/d/${documentId}/edit`,
71
+ slides: `https://docs.google.com/presentation/d/${documentId}/edit`,
72
+ drive: `https://drive.google.com/file/d/${documentId}/view`,
73
+ };
74
+ return urlTemplates[type];
75
+ }
76
+ }
@@ -0,0 +1,82 @@
1
+ /**
2
+ * ResponseFormatter - Consistent response formatting across all tools
3
+ */
4
+ export class ResponseFormatter {
5
+ /**
6
+ * Create a success response
7
+ */
8
+ static success(data, message) {
9
+ let text;
10
+ if (message) {
11
+ // If message is provided, combine it with data
12
+ if (typeof data === "object" && data !== null) {
13
+ text = `${message}\n\n${JSON.stringify(data, null, 2)}`;
14
+ }
15
+ else {
16
+ text = message;
17
+ }
18
+ }
19
+ else {
20
+ // Format data only
21
+ text = typeof data === "object" && data !== null
22
+ ? JSON.stringify(data, null, 2)
23
+ : String(data);
24
+ }
25
+ return {
26
+ content: [{ type: "text", text }],
27
+ isError: false,
28
+ };
29
+ }
30
+ /**
31
+ * Create an error response
32
+ */
33
+ static error(error) {
34
+ const message = error instanceof Error ? error.message : error;
35
+ return {
36
+ content: [
37
+ {
38
+ type: "text",
39
+ text: `Error: ${message}`,
40
+ },
41
+ ],
42
+ isError: true,
43
+ };
44
+ }
45
+ /**
46
+ * Format Google Docs document data
47
+ */
48
+ static formatDocumentData(doc) {
49
+ const formatted = {
50
+ documentId: doc.documentId,
51
+ title: doc.title,
52
+ revisionId: doc.revisionId,
53
+ suggestionsViewMode: doc.suggestionsViewMode,
54
+ };
55
+ return JSON.stringify(formatted, null, 2);
56
+ }
57
+ /**
58
+ * Format metadata
59
+ */
60
+ static formatMetadata(metadata) {
61
+ return JSON.stringify(metadata, null, 2);
62
+ }
63
+ /**
64
+ * Format a simple success message
65
+ */
66
+ static simpleSuccess(message) {
67
+ return {
68
+ content: [{ type: "text", text: message }],
69
+ isError: false,
70
+ };
71
+ }
72
+ /**
73
+ * Format operation result with details
74
+ */
75
+ static operationResult(operation, details) {
76
+ const text = `${operation} completed successfully\n\n${JSON.stringify(details, null, 2)}`;
77
+ return {
78
+ content: [{ type: "text", text }],
79
+ isError: false,
80
+ };
81
+ }
82
+ }
@@ -0,0 +1,112 @@
1
+ /**
2
+ * Validation - Shared validation logic for tool inputs
3
+ */
4
+ export class Validator {
5
+ /**
6
+ * Validate that required fields exist in an object
7
+ */
8
+ static validateRequired(obj, fields) {
9
+ const missing = fields.filter((field) => obj[field] === undefined);
10
+ if (missing.length > 0) {
11
+ throw new Error(`Missing required fields: ${missing.join(", ")}`);
12
+ }
13
+ }
14
+ /**
15
+ * Validate RGB color values (0-1 range)
16
+ */
17
+ static validateColor(color) {
18
+ const values = [color.red, color.green, color.blue];
19
+ return values.every((v) => typeof v === "number" && v >= 0 && v <= 1);
20
+ }
21
+ /**
22
+ * Validate dimension type
23
+ */
24
+ static validateDimension(dimension) {
25
+ return dimension === "ROWS" || dimension === "COLUMNS";
26
+ }
27
+ /**
28
+ * Validate text style object
29
+ */
30
+ static validateTextStyle(style) {
31
+ // Check for at least one style property
32
+ const validProperties = [
33
+ "bold",
34
+ "italic",
35
+ "underline",
36
+ "fontSize",
37
+ "fontFamily",
38
+ "foregroundColor",
39
+ "backgroundColor",
40
+ ];
41
+ const hasValidProperty = validProperties.some((prop) => style[prop] !== undefined);
42
+ if (!hasValidProperty) {
43
+ return false;
44
+ }
45
+ // Validate color properties if they exist
46
+ if (style.foregroundColor && !this.validateColor(style.foregroundColor)) {
47
+ return false;
48
+ }
49
+ if (style.backgroundColor && !this.validateColor(style.backgroundColor)) {
50
+ return false;
51
+ }
52
+ return true;
53
+ }
54
+ /**
55
+ * Validate index is a positive integer
56
+ */
57
+ static validateIndex(index, allowZero = false) {
58
+ if (!Number.isInteger(index)) {
59
+ return false;
60
+ }
61
+ return allowZero ? index >= 0 : index > 0;
62
+ }
63
+ /**
64
+ * Validate range (startIndex < endIndex)
65
+ */
66
+ static validateRange(startIndex, endIndex) {
67
+ return (this.validateIndex(startIndex) &&
68
+ this.validateIndex(endIndex) &&
69
+ startIndex < endIndex);
70
+ }
71
+ /**
72
+ * Validate alignment value
73
+ */
74
+ static validateAlignment(alignment) {
75
+ return ["START", "CENTER", "END", "JUSTIFIED"].includes(alignment);
76
+ }
77
+ /**
78
+ * Validate named style type
79
+ */
80
+ static validateNamedStyleType(styleType) {
81
+ const validTypes = [
82
+ "NORMAL_TEXT",
83
+ "HEADING_1",
84
+ "HEADING_2",
85
+ "HEADING_3",
86
+ "HEADING_4",
87
+ "HEADING_5",
88
+ "HEADING_6",
89
+ "TITLE",
90
+ "SUBTITLE",
91
+ ];
92
+ return validTypes.includes(styleType);
93
+ }
94
+ /**
95
+ * Validate URL format
96
+ */
97
+ static validateUrl(url) {
98
+ try {
99
+ new URL(url);
100
+ return url.startsWith("http://") || url.startsWith("https://");
101
+ }
102
+ catch {
103
+ return false;
104
+ }
105
+ }
106
+ /**
107
+ * Validate positive number
108
+ */
109
+ static validatePositiveNumber(value) {
110
+ return typeof value === "number" && value > 0 && !isNaN(value);
111
+ }
112
+ }