@pipeworx/mcp-google_docs 0.1.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.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Pipeworx
4
+
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.
package/README.md ADDED
@@ -0,0 +1,40 @@
1
+ # mcp-google_docs
2
+
3
+ Google Docs MCP Pack — read, create, and edit Google Docs via OAuth.
4
+
5
+ Part of the [Pipeworx](https://pipeworx.io) open MCP gateway.
6
+
7
+ ## Tools
8
+
9
+ | Tool | Description |
10
+ |------|-------------|
11
+ | `docs_get` | Get a Google Doc by ID — returns title, body content, and document structure. |
12
+ | `docs_get_text` | Get the plain text content of a Google Doc. |
13
+ | `docs_create` | Create a new Google Doc with a title. |
14
+ | `docs_insert_text` | Insert text into a Google Doc at a specified index position. |
15
+ | `docs_append_text` | Append text to the end of a Google Doc. |
16
+ | `docs_replace_text` | Find and replace text in a Google Doc. |
17
+
18
+ ## Quick Start
19
+
20
+ Add to your MCP client config:
21
+
22
+ ```json
23
+ {
24
+ "mcpServers": {
25
+ "google_docs": {
26
+ "url": "https://gateway.pipeworx.io/google_docs/mcp"
27
+ }
28
+ }
29
+ }
30
+ ```
31
+
32
+ Or use the CLI:
33
+
34
+ ```bash
35
+ npx pipeworx use google_docs
36
+ ```
37
+
38
+ ## License
39
+
40
+ MIT
package/package.json ADDED
@@ -0,0 +1,20 @@
1
+ {
2
+ "name": "@pipeworx/mcp-google_docs",
3
+ "version": "0.1.0",
4
+ "description": "Google Docs MCP Pack — read, create, and edit Google Docs via OAuth.",
5
+ "type": "module",
6
+ "main": "src/index.ts",
7
+ "types": "src/index.ts",
8
+ "keywords": ["mcp", "mcp-server", "model-context-protocol", "pipeworx", "google_docs"],
9
+ "license": "MIT",
10
+ "repository": {
11
+ "type": "git",
12
+ "url": "https://github.com/pipeworx-io/mcp-google_docs"
13
+ },
14
+ "scripts": {
15
+ "typecheck": "tsc --noEmit"
16
+ },
17
+ "devDependencies": {
18
+ "typescript": "^5.7.0"
19
+ }
20
+ }
package/server.json ADDED
@@ -0,0 +1,18 @@
1
+ {
2
+ "$schema": "https://static.modelcontextprotocol.io/schemas/2025-12-11/server.schema.json",
3
+ "name": "io.github.pipeworx-io/google_docs",
4
+ "title": "google_docs",
5
+ "description": "Google Docs MCP Pack — read, create, and edit Google Docs via OAuth.",
6
+ "version": "0.1.0",
7
+ "websiteUrl": "https://pipeworx.io/packs/google_docs",
8
+ "repository": {
9
+ "url": "https://github.com/pipeworx-io/mcp-google_docs",
10
+ "source": "github"
11
+ },
12
+ "remotes": [
13
+ {
14
+ "type": "streamable-http",
15
+ "url": "https://gateway.pipeworx.io/google_docs/mcp"
16
+ }
17
+ ]
18
+ }
package/src/index.ts ADDED
@@ -0,0 +1,195 @@
1
+ interface McpToolDefinition {
2
+ name: string;
3
+ description: string;
4
+ inputSchema: {
5
+ type: 'object';
6
+ properties: Record<string, unknown>;
7
+ required?: string[];
8
+ };
9
+ }
10
+
11
+ interface McpToolExport {
12
+ tools: McpToolDefinition[];
13
+ callTool: (name: string, args: Record<string, unknown>) => Promise<unknown>;
14
+ }
15
+
16
+ /**
17
+ * Google Docs MCP Pack — read, create, and edit Google Docs via OAuth.
18
+ * Reuses the google_sheets OAuth connection (same Google OAuth client + scopes).
19
+ */
20
+
21
+
22
+ interface GoogleContext {
23
+ google_docs?: { accessToken: string };
24
+ }
25
+
26
+ const API = 'https://docs.googleapis.com/v1/documents';
27
+
28
+ async function gFetch(ctx: GoogleContext, url: string, options: RequestInit = {}) {
29
+ if (!ctx.google_docs) {
30
+ return { error: 'connection_required', message: 'Connect your Google account at https://pipeworx.io/account' };
31
+ }
32
+ const res = await fetch(url, {
33
+ ...options,
34
+ headers: {
35
+ Authorization: `Bearer ${ctx.google_docs.accessToken}`,
36
+ 'Content-Type': 'application/json',
37
+ ...(options.headers ?? {}),
38
+ },
39
+ });
40
+ if (!res.ok) {
41
+ const text = await res.text();
42
+ throw new Error(`Google Docs API error (${res.status}): ${text}`);
43
+ }
44
+ return res.json();
45
+ }
46
+
47
+ const tools: McpToolExport['tools'] = [
48
+ {
49
+ name: 'docs_get',
50
+ description: 'Get a Google Doc by ID — returns title, body content, and document structure.',
51
+ inputSchema: {
52
+ type: 'object' as const,
53
+ properties: {
54
+ document_id: { type: 'string', description: 'Document ID (from the URL)' },
55
+ },
56
+ required: ['document_id'],
57
+ },
58
+ },
59
+ {
60
+ name: 'docs_get_text',
61
+ description: 'Get the plain text content of a Google Doc.',
62
+ inputSchema: {
63
+ type: 'object' as const,
64
+ properties: {
65
+ document_id: { type: 'string', description: 'Document ID' },
66
+ },
67
+ required: ['document_id'],
68
+ },
69
+ },
70
+ {
71
+ name: 'docs_create',
72
+ description: 'Create a new Google Doc with a title.',
73
+ inputSchema: {
74
+ type: 'object' as const,
75
+ properties: {
76
+ title: { type: 'string', description: 'Title for the new document' },
77
+ },
78
+ required: ['title'],
79
+ },
80
+ },
81
+ {
82
+ name: 'docs_insert_text',
83
+ description: 'Insert text into a Google Doc at a specified index position.',
84
+ inputSchema: {
85
+ type: 'object' as const,
86
+ properties: {
87
+ document_id: { type: 'string', description: 'Document ID' },
88
+ text: { type: 'string', description: 'Text to insert' },
89
+ index: { type: 'number', description: 'Character index to insert at (1 = start of body)' },
90
+ },
91
+ required: ['document_id', 'text'],
92
+ },
93
+ },
94
+ {
95
+ name: 'docs_append_text',
96
+ description: 'Append text to the end of a Google Doc.',
97
+ inputSchema: {
98
+ type: 'object' as const,
99
+ properties: {
100
+ document_id: { type: 'string', description: 'Document ID' },
101
+ text: { type: 'string', description: 'Text to append' },
102
+ },
103
+ required: ['document_id', 'text'],
104
+ },
105
+ },
106
+ {
107
+ name: 'docs_replace_text',
108
+ description: 'Find and replace text in a Google Doc.',
109
+ inputSchema: {
110
+ type: 'object' as const,
111
+ properties: {
112
+ document_id: { type: 'string', description: 'Document ID' },
113
+ find: { type: 'string', description: 'Text to find' },
114
+ replace: { type: 'string', description: 'Replacement text' },
115
+ match_case: { type: 'boolean', description: 'Case-sensitive match (default: false)' },
116
+ },
117
+ required: ['document_id', 'find', 'replace'],
118
+ },
119
+ },
120
+ ];
121
+
122
+ function extractPlainText(doc: Record<string, unknown>): string {
123
+ const body = doc.body as { content?: Array<{ paragraph?: { elements?: Array<{ textRun?: { content?: string } }> } }> } | undefined;
124
+ if (!body?.content) return '';
125
+ return body.content
126
+ .flatMap((block) => block.paragraph?.elements ?? [])
127
+ .map((el) => el.textRun?.content ?? '')
128
+ .join('');
129
+ }
130
+
131
+ async function callTool(name: string, args: Record<string, unknown>): Promise<unknown> {
132
+ const context = (args._context ?? {}) as GoogleContext;
133
+ delete args._context;
134
+
135
+ switch (name) {
136
+ case 'docs_get':
137
+ return gFetch(context, `${API}/${args.document_id}`);
138
+
139
+ case 'docs_get_text': {
140
+ const doc = await gFetch(context, `${API}/${args.document_id}`) as Record<string, unknown>;
141
+ if (doc.error) return doc;
142
+ return { title: doc.title, text: extractPlainText(doc) };
143
+ }
144
+
145
+ case 'docs_create':
146
+ return gFetch(context, API, {
147
+ method: 'POST',
148
+ body: JSON.stringify({ title: args.title }),
149
+ });
150
+
151
+ case 'docs_insert_text': {
152
+ const index = (args.index as number) ?? 1;
153
+ return gFetch(context, `${API}/${args.document_id}:batchUpdate`, {
154
+ method: 'POST',
155
+ body: JSON.stringify({
156
+ requests: [{ insertText: { location: { index }, text: args.text } }],
157
+ }),
158
+ });
159
+ }
160
+
161
+ case 'docs_append_text': {
162
+ // Get doc to find end index, then insert there
163
+ const doc = await gFetch(context, `${API}/${args.document_id}`) as Record<string, unknown>;
164
+ if (doc.error) return doc;
165
+ const body = doc.body as { content?: Array<{ endIndex?: number }> } | undefined;
166
+ const endIndex = body?.content?.at(-1)?.endIndex ?? 1;
167
+ // Insert before the final newline
168
+ const insertAt = Math.max(1, endIndex - 1);
169
+ return gFetch(context, `${API}/${args.document_id}:batchUpdate`, {
170
+ method: 'POST',
171
+ body: JSON.stringify({
172
+ requests: [{ insertText: { location: { index: insertAt }, text: args.text } }],
173
+ }),
174
+ });
175
+ }
176
+
177
+ case 'docs_replace_text':
178
+ return gFetch(context, `${API}/${args.document_id}:batchUpdate`, {
179
+ method: 'POST',
180
+ body: JSON.stringify({
181
+ requests: [{
182
+ replaceAllText: {
183
+ containsText: { text: args.find, matchCase: args.match_case ?? false },
184
+ replaceText: args.replace,
185
+ },
186
+ }],
187
+ }),
188
+ });
189
+
190
+ default:
191
+ throw new Error(`Unknown tool: ${name}`);
192
+ }
193
+ }
194
+
195
+ export default { tools, callTool, meter: { credits: 10 }, provider: 'google_docs' } satisfies McpToolExport;
package/tsconfig.json ADDED
@@ -0,0 +1,14 @@
1
+ {
2
+ "compilerOptions": {
3
+ "target": "ES2022",
4
+ "module": "ESNext",
5
+ "moduleResolution": "bundler",
6
+ "strict": true,
7
+ "esModuleInterop": true,
8
+ "skipLibCheck": true,
9
+ "outDir": "dist",
10
+ "rootDir": "src",
11
+ "declaration": true
12
+ },
13
+ "include": ["src"]
14
+ }