@pipeworx/mcp-google_drive 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,39 @@
1
+ # mcp-google_drive
2
+
3
+ Google Drive MCP Pack
4
+
5
+ Part of the [Pipeworx](https://pipeworx.io) open MCP gateway.
6
+
7
+ ## Tools
8
+
9
+ | Tool | Description |
10
+ |------|-------------|
11
+ | `drive_list_files` | List files in Google Drive. Optionally filter with a search query using Drive query syntax. |
12
+ | `drive_get_file` | Get metadata for a specific Google Drive file by ID. Returns name, mimeType, size, owners, permissions, and more. |
13
+ | `drive_get_content` | Download or export the content of a Google Drive file. For Google Docs/Sheets/Slides, exports to a specified format. For binary files, returns the raw content. |
14
+ | `drive_create_file` | Create a new file in Google Drive with the given name, content, and MIME type. |
15
+ | `drive_search` | Search Google Drive files using Drive query syntax. Supports operators like name, mimeType, fullText, modifiedTime, owners, etc. |
16
+
17
+ ## Quick Start
18
+
19
+ Add to your MCP client config:
20
+
21
+ ```json
22
+ {
23
+ "mcpServers": {
24
+ "google_drive": {
25
+ "url": "https://gateway.pipeworx.io/google_drive/mcp"
26
+ }
27
+ }
28
+ }
29
+ ```
30
+
31
+ Or use the CLI:
32
+
33
+ ```bash
34
+ npx pipeworx use google_drive
35
+ ```
36
+
37
+ ## License
38
+
39
+ MIT
package/package.json ADDED
@@ -0,0 +1,20 @@
1
+ {
2
+ "name": "@pipeworx/mcp-google_drive",
3
+ "version": "0.1.0",
4
+ "description": "Google Drive MCP Pack",
5
+ "type": "module",
6
+ "main": "src/index.ts",
7
+ "types": "src/index.ts",
8
+ "keywords": ["mcp", "mcp-server", "model-context-protocol", "pipeworx", "google_drive"],
9
+ "license": "MIT",
10
+ "repository": {
11
+ "type": "git",
12
+ "url": "https://github.com/pipeworx-io/mcp-google_drive"
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_drive",
4
+ "title": "google_drive",
5
+ "description": "Google Drive MCP Pack",
6
+ "version": "0.1.0",
7
+ "websiteUrl": "https://pipeworx.io/packs/google_drive",
8
+ "repository": {
9
+ "url": "https://github.com/pipeworx-io/mcp-google_drive",
10
+ "source": "github"
11
+ },
12
+ "remotes": [
13
+ {
14
+ "type": "streamable-http",
15
+ "url": "https://gateway.pipeworx.io/google_drive/mcp"
16
+ }
17
+ ]
18
+ }
package/src/index.ts ADDED
@@ -0,0 +1,217 @@
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 Drive MCP Pack
18
+ *
19
+ * Requires OAuth connection — gateway injects credentials via _context.google_drive.
20
+ * Tools: list files, get file metadata, get file content, create file, search.
21
+ */
22
+
23
+
24
+ interface DriveContext {
25
+ google_drive?: { accessToken: string };
26
+ }
27
+
28
+ const API = 'https://www.googleapis.com/drive/v3';
29
+
30
+ async function gFetch(ctx: DriveContext, url: string, options: RequestInit = {}) {
31
+ if (!ctx.google_drive) {
32
+ return { error: 'connection_required', message: 'Connect your Google account at https://pipeworx.io/account' };
33
+ }
34
+ const res = await fetch(url, {
35
+ ...options,
36
+ headers: {
37
+ Authorization: `Bearer ${ctx.google_drive.accessToken}`,
38
+ 'Content-Type': 'application/json',
39
+ ...(options.headers ?? {}),
40
+ },
41
+ });
42
+ if (!res.ok) {
43
+ const text = await res.text();
44
+ throw new Error(`Google Drive API error (${res.status}): ${text}`);
45
+ }
46
+ return res.json();
47
+ }
48
+
49
+ async function gFetchText(ctx: DriveContext, url: string) {
50
+ if (!ctx.google_drive) {
51
+ return { error: 'connection_required', message: 'Connect your Google account at https://pipeworx.io/account' };
52
+ }
53
+ const res = await fetch(url, {
54
+ headers: {
55
+ Authorization: `Bearer ${ctx.google_drive.accessToken}`,
56
+ },
57
+ });
58
+ if (!res.ok) {
59
+ const text = await res.text();
60
+ throw new Error(`Google Drive API error (${res.status}): ${text}`);
61
+ }
62
+ return res.text();
63
+ }
64
+
65
+ const tools: McpToolExport['tools'] = [
66
+ {
67
+ name: 'drive_list_files',
68
+ description: 'List files in Google Drive. Optionally filter with a search query using Drive query syntax.',
69
+ inputSchema: {
70
+ type: 'object' as const,
71
+ properties: {
72
+ q: { type: 'string', description: 'Drive search query (e.g., "name contains \'report\'" or "mimeType=\'application/pdf\'")' },
73
+ page_size: { type: 'number', description: 'Maximum number of files to return (default 10, max 100)' },
74
+ page_token: { type: 'string', description: 'Token for fetching the next page of results' },
75
+ order_by: { type: 'string', description: 'Sort order (e.g., "modifiedTime desc", "name")' },
76
+ },
77
+ required: [],
78
+ },
79
+ },
80
+ {
81
+ name: 'drive_get_file',
82
+ description: 'Get metadata for a specific Google Drive file by ID. Returns name, mimeType, size, owners, permissions, and more.',
83
+ inputSchema: {
84
+ type: 'object' as const,
85
+ properties: {
86
+ file_id: { type: 'string', description: 'The ID of the file to retrieve' },
87
+ fields: { type: 'string', description: 'Comma-separated list of fields to include (default: id,name,mimeType,size,createdTime,modifiedTime,owners,webViewLink)' },
88
+ },
89
+ required: ['file_id'],
90
+ },
91
+ },
92
+ {
93
+ name: 'drive_get_content',
94
+ description: 'Download or export the content of a Google Drive file. For Google Docs/Sheets/Slides, exports to a specified format. For binary files, returns the raw content.',
95
+ inputSchema: {
96
+ type: 'object' as const,
97
+ properties: {
98
+ file_id: { type: 'string', description: 'The ID of the file to download' },
99
+ export_mime_type: { type: 'string', description: 'MIME type to export Google Workspace files to (e.g., "text/plain", "application/pdf", "text/csv"). Required for Google Docs/Sheets/Slides.' },
100
+ },
101
+ required: ['file_id'],
102
+ },
103
+ },
104
+ {
105
+ name: 'drive_create_file',
106
+ description: 'Create a new file in Google Drive with the given name, content, and MIME type.',
107
+ inputSchema: {
108
+ type: 'object' as const,
109
+ properties: {
110
+ name: { type: 'string', description: 'Name for the new file' },
111
+ content: { type: 'string', description: 'Text content of the file' },
112
+ mime_type: { type: 'string', description: 'MIME type of the file (e.g., "text/plain", "application/json", "text/html")' },
113
+ parent_folder_id: { type: 'string', description: 'ID of the parent folder (optional, defaults to root)' },
114
+ },
115
+ required: ['name', 'content', 'mime_type'],
116
+ },
117
+ },
118
+ {
119
+ name: 'drive_search',
120
+ description: 'Search Google Drive files using Drive query syntax. Supports operators like name, mimeType, fullText, modifiedTime, owners, etc.',
121
+ inputSchema: {
122
+ type: 'object' as const,
123
+ properties: {
124
+ query: { type: 'string', description: 'Drive search query (e.g., "fullText contains \'quarterly report\'" or "modifiedTime > \'2024-01-01\'")' },
125
+ page_size: { type: 'number', description: 'Maximum number of results (default 10, max 100)' },
126
+ },
127
+ required: ['query'],
128
+ },
129
+ },
130
+ ];
131
+
132
+ async function callTool(name: string, args: Record<string, unknown>): Promise<unknown> {
133
+ const context = (args._context ?? {}) as DriveContext;
134
+ delete args._context;
135
+
136
+ switch (name) {
137
+ case 'drive_list_files': {
138
+ const pageSize = Math.min(100, Math.max(1, (args.page_size as number) ?? 10));
139
+ const params = new URLSearchParams({
140
+ pageSize: String(pageSize),
141
+ fields: 'nextPageToken,files(id,name,mimeType,size,createdTime,modifiedTime,owners,webViewLink)',
142
+ });
143
+ if (args.q) params.set('q', args.q as string);
144
+ if (args.page_token) params.set('pageToken', args.page_token as string);
145
+ if (args.order_by) params.set('orderBy', args.order_by as string);
146
+ return gFetch(context, `${API}/files?${params}`);
147
+ }
148
+ case 'drive_get_file': {
149
+ const fileId = args.file_id as string;
150
+ const fields = (args.fields as string) ?? 'id,name,mimeType,size,createdTime,modifiedTime,owners,webViewLink,parents,shared,permissions';
151
+ const params = new URLSearchParams({ fields });
152
+ return gFetch(context, `${API}/files/${encodeURIComponent(fileId)}?${params}`);
153
+ }
154
+ case 'drive_get_content': {
155
+ const fileId = args.file_id as string;
156
+ const exportMimeType = args.export_mime_type as string | undefined;
157
+ if (exportMimeType) {
158
+ const params = new URLSearchParams({ mimeType: exportMimeType });
159
+ const content = await gFetchText(context, `${API}/files/${encodeURIComponent(fileId)}/export?${params}`);
160
+ return { file_id: fileId, export_mime_type: exportMimeType, content };
161
+ }
162
+ const content = await gFetchText(context, `${API}/files/${encodeURIComponent(fileId)}?alt=media`);
163
+ return { file_id: fileId, content };
164
+ }
165
+ case 'drive_create_file': {
166
+ const { name: fileName, content, mime_type, parent_folder_id } = args as {
167
+ name: string; content: string; mime_type: string; parent_folder_id?: string;
168
+ };
169
+ const metadata: Record<string, unknown> = { name: fileName, mimeType: mime_type };
170
+ if (parent_folder_id) metadata.parents = [parent_folder_id];
171
+ // Use multipart upload
172
+ const boundary = '-------pipeworx_boundary';
173
+ const body = [
174
+ `--${boundary}`,
175
+ 'Content-Type: application/json; charset=UTF-8',
176
+ '',
177
+ JSON.stringify(metadata),
178
+ `--${boundary}`,
179
+ `Content-Type: ${mime_type}`,
180
+ '',
181
+ content,
182
+ `--${boundary}--`,
183
+ ].join('\r\n');
184
+
185
+ if (!context.google_drive) {
186
+ return { error: 'connection_required', message: 'Connect your Google account at https://pipeworx.io/account' };
187
+ }
188
+ const res = await fetch('https://www.googleapis.com/upload/drive/v3/files?uploadType=multipart&fields=id,name,mimeType,webViewLink', {
189
+ method: 'POST',
190
+ headers: {
191
+ Authorization: `Bearer ${context.google_drive.accessToken}`,
192
+ 'Content-Type': `multipart/related; boundary=${boundary}`,
193
+ },
194
+ body,
195
+ });
196
+ if (!res.ok) {
197
+ const text = await res.text();
198
+ throw new Error(`Google Drive API error (${res.status}): ${text}`);
199
+ }
200
+ return res.json();
201
+ }
202
+ case 'drive_search': {
203
+ const query = args.query as string;
204
+ const pageSize = Math.min(100, Math.max(1, (args.page_size as number) ?? 10));
205
+ const params = new URLSearchParams({
206
+ q: query,
207
+ pageSize: String(pageSize),
208
+ fields: 'nextPageToken,files(id,name,mimeType,size,createdTime,modifiedTime,owners,webViewLink)',
209
+ });
210
+ return gFetch(context, `${API}/files?${params}`);
211
+ }
212
+ default:
213
+ throw new Error(`Unknown tool: ${name}`);
214
+ }
215
+ }
216
+
217
+ export default { tools, callTool, meter: { credits: 10 }, provider: 'google_drive' } 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
+ }