terra-mcp-google 0.1.11
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/README.md +57 -0
- package/dist/cli.d.ts +2 -0
- package/dist/cli.js +94 -0
- package/dist/cli.js.map +1 -0
- package/dist/config/constants.d.ts +43 -0
- package/dist/config/constants.js +54 -0
- package/dist/config/constants.js.map +1 -0
- package/dist/core/local-file.d.ts +3 -0
- package/dist/core/local-file.js +50 -0
- package/dist/core/local-file.js.map +1 -0
- package/dist/core/result.d.ts +44 -0
- package/dist/core/result.js +104 -0
- package/dist/core/result.js.map +1 -0
- package/dist/core/tool.d.ts +61 -0
- package/dist/core/tool.js +63 -0
- package/dist/core/tool.js.map +1 -0
- package/dist/google/auth.d.ts +47 -0
- package/dist/google/auth.js +256 -0
- package/dist/google/auth.js.map +1 -0
- package/dist/google/client.d.ts +11 -0
- package/dist/google/client.js +14 -0
- package/dist/google/client.js.map +1 -0
- package/dist/google/generated/oauth-client.d.ts +5 -0
- package/dist/google/generated/oauth-client.js +2 -0
- package/dist/google/generated/oauth-client.js.map +1 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +24 -0
- package/dist/index.js.map +1 -0
- package/dist/services/auth/tools.d.ts +2 -0
- package/dist/services/auth/tools.js +34 -0
- package/dist/services/auth/tools.js.map +1 -0
- package/dist/services/drive/adapter.d.ts +56 -0
- package/dist/services/drive/adapter.js +168 -0
- package/dist/services/drive/adapter.js.map +1 -0
- package/dist/services/drive/tools.d.ts +65 -0
- package/dist/services/drive/tools.js +324 -0
- package/dist/services/drive/tools.js.map +1 -0
- package/dist/services/registry.d.ts +24 -0
- package/dist/services/registry.js +57 -0
- package/dist/services/registry.js.map +1 -0
- package/dist/services/sheets/adapter.d.ts +112 -0
- package/dist/services/sheets/adapter.js +174 -0
- package/dist/services/sheets/adapter.js.map +1 -0
- package/dist/services/sheets/tools.d.ts +118 -0
- package/dist/services/sheets/tools.js +547 -0
- package/dist/services/sheets/tools.js.map +1 -0
- package/dist/setup/setup.d.ts +31 -0
- package/dist/setup/setup.js +179 -0
- package/dist/setup/setup.js.map +1 -0
- package/package.json +61 -0
- package/scripts/install.sh +16 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"adapter.js","sourceRoot":"","sources":["../../../src/services/drive/adapter.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,MAAM,SAAS,CAAC;AAC3C,OAAO,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AAC7C,OAAO,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AAEvC,OAAO,EAAE,YAAY,EAAE,aAAa,EAAE,MAAM,0BAA0B,CAAC;AAEvE,MAAM,iBAAiB,GACrB,iIAAiI,CAAC;AAEpI,MAAM,iBAAiB,GAAG,wBAAwB,iBAAiB,GAAG,CAAC;AAYvE,MAAM,OAAO,gBAAgB;IACE;IAA7B,YAA6B,KAAqB;QAArB,UAAK,GAAL,KAAK,CAAgB;IAAG,CAAC;IAEtD,KAAK,CAAC,SAAS,CAAC,IAMf;QACC,MAAM,CAAC,GAAG,CAAC,IAAI,CAAC,KAAK,EAAE,IAAI,CAAC,cAAc,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,iBAAiB,CAAC;aACxE,MAAM,CAAC,OAAO,CAAC;aACf,IAAI,CAAC,OAAO,CAAC,CAAC;QACjB,MAAM,EAAE,IAAI,EAAE,GAAG,MAAM,IAAI,CAAC,KAAK,CAAC,KAAK,CAAC,IAAI,CAAC;YAC3C,CAAC,EAAE,CAAC,IAAI,SAAS;YACjB,QAAQ,EAAE,IAAI,CAAC,QAAQ;YACvB,SAAS,EAAE,IAAI,CAAC,SAAS;YACzB,OAAO,EAAE,IAAI,CAAC,OAAO;YACrB,MAAM,EAAE,iBAAiB;YACzB,MAAM,EAAE,OAAO;YACf,iBAAiB,EAAE,IAAI;YACvB,yBAAyB,EAAE,IAAI;SAChC,CAAC,CAAC;Q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CAAC,MAAc;QAC7B,MAAM,IAAI,CAAC,KAAK,CAAC,KAAK,CAAC,MAAM,CAAC,EAAE,MAAM,EAAE,iBAAiB,EAAE,IAAI,EAAE,CAAC,CAAC;IACrE,CAAC;IAED,KAAK,CAAC,SAAS,CAAC,MAAc;QAC5B,MAAM,EAAE,IAAI,EAAE,GAAG,MAAM,IAAI,CAAC,KAAK,CAAC,KAAK,CAAC,MAAM,CAAC;YAC7C,MAAM;YACN,WAAW,EAAE,EAAE,OAAO,EAAE,IAAI,EAAE;YAC9B,MAAM,EAAE,mBAAmB;YAC3B,iBAAiB,EAAE,IAAI;SACxB,CAAC,CAAC;QACH,OAAO,IAAI,CAAC;IACd,CAAC;CACF;AAED,SAAS,iBAAiB,CAAC,QAAgB;IACzC,QAAQ,QAAQ,EAAE,CAAC;QACjB,KAAK,yCAAyC;YAC5C,OAAO,UAAU,CAAC;QACpB,KAAK,sCAAsC;YACzC,OAAO,YAAY,CAAC;QACtB,KAAK,0CAA0C;YAC7C,OAAO,iBAAiB,CAAC;QAC3B;YACE,OAAO,iBAAiB,CAAC;IAC7B,CAAC;AACH,CAAC;AAED,SAAS,cAAc,CAAC,QAAwB;IAC9C,OAAO,CAAC,CAAC,QAAQ,IAAI,QAAQ,CAAC,UAAU,CAAC,8BAA8B,CAAC,CAAC;AAC3E,CAAC;AAED,SAAS,UAAU,CAAC,QAAgB;IAClC,OAAO,uCAAuC,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;AAChE,CAAC"}
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
import type { drive_v3 } from "googleapis";
|
|
3
|
+
import { type ToolResult } from "../../core/result.js";
|
|
4
|
+
import { type ArgsOf, type ToolRegistration } from "../../core/tool.js";
|
|
5
|
+
declare const listFilesInput: {
|
|
6
|
+
query: z.ZodOptional<z.ZodString>;
|
|
7
|
+
page_size: z.ZodDefault<z.ZodNumber>;
|
|
8
|
+
page_token: z.ZodOptional<z.ZodString>;
|
|
9
|
+
order_by: z.ZodOptional<z.ZodString>;
|
|
10
|
+
include_trashed: z.ZodDefault<z.ZodBoolean>;
|
|
11
|
+
response_format: z.ZodDefault<z.ZodEnum<{
|
|
12
|
+
markdown: "markdown";
|
|
13
|
+
json: "json";
|
|
14
|
+
}>>;
|
|
15
|
+
};
|
|
16
|
+
export declare function driveListFiles(drive: drive_v3.Drive, args: ArgsOf<typeof listFilesInput>): Promise<ToolResult>;
|
|
17
|
+
declare const getFileInput: {
|
|
18
|
+
file_id: z.ZodString;
|
|
19
|
+
response_format: z.ZodDefault<z.ZodEnum<{
|
|
20
|
+
markdown: "markdown";
|
|
21
|
+
json: "json";
|
|
22
|
+
}>>;
|
|
23
|
+
};
|
|
24
|
+
export declare function driveGetFile(drive: drive_v3.Drive, args: ArgsOf<typeof getFileInput>): Promise<ToolResult>;
|
|
25
|
+
declare const downloadFileInput: {
|
|
26
|
+
file_id: z.ZodString;
|
|
27
|
+
export_mime_type: z.ZodOptional<z.ZodString>;
|
|
28
|
+
save_path: z.ZodOptional<z.ZodString>;
|
|
29
|
+
};
|
|
30
|
+
export declare function driveDownloadFile(drive: drive_v3.Drive, args: ArgsOf<typeof downloadFileInput>): Promise<ToolResult>;
|
|
31
|
+
declare const createFolderInput: {
|
|
32
|
+
name: z.ZodString;
|
|
33
|
+
parent_id: z.ZodOptional<z.ZodString>;
|
|
34
|
+
};
|
|
35
|
+
export declare function driveCreateFolder(drive: drive_v3.Drive, args: ArgsOf<typeof createFolderInput>): Promise<ToolResult>;
|
|
36
|
+
declare const uploadFileInput: {
|
|
37
|
+
name: z.ZodString;
|
|
38
|
+
content: z.ZodOptional<z.ZodString>;
|
|
39
|
+
local_path: z.ZodOptional<z.ZodString>;
|
|
40
|
+
mime_type: z.ZodOptional<z.ZodString>;
|
|
41
|
+
parent_id: z.ZodOptional<z.ZodString>;
|
|
42
|
+
};
|
|
43
|
+
export declare function driveUploadFile(drive: drive_v3.Drive, args: ArgsOf<typeof uploadFileInput>): Promise<ToolResult>;
|
|
44
|
+
declare const updateFileInput: {
|
|
45
|
+
file_id: z.ZodString;
|
|
46
|
+
new_name: z.ZodOptional<z.ZodString>;
|
|
47
|
+
add_parents: z.ZodOptional<z.ZodString>;
|
|
48
|
+
remove_parents: z.ZodOptional<z.ZodString>;
|
|
49
|
+
content: z.ZodOptional<z.ZodString>;
|
|
50
|
+
mime_type: z.ZodOptional<z.ZodString>;
|
|
51
|
+
};
|
|
52
|
+
export declare function driveUpdateFile(drive: drive_v3.Drive, args: ArgsOf<typeof updateFileInput>): Promise<ToolResult>;
|
|
53
|
+
declare const copyFileInput: {
|
|
54
|
+
file_id: z.ZodString;
|
|
55
|
+
name: z.ZodOptional<z.ZodString>;
|
|
56
|
+
parent_id: z.ZodOptional<z.ZodString>;
|
|
57
|
+
};
|
|
58
|
+
export declare function driveCopyFile(drive: drive_v3.Drive, args: ArgsOf<typeof copyFileInput>): Promise<ToolResult>;
|
|
59
|
+
declare const deleteFileInput: {
|
|
60
|
+
file_id: z.ZodString;
|
|
61
|
+
permanent: z.ZodDefault<z.ZodBoolean>;
|
|
62
|
+
};
|
|
63
|
+
export declare function driveDeleteFile(drive: drive_v3.Drive, args: ArgsOf<typeof deleteFileInput>): Promise<ToolResult>;
|
|
64
|
+
export declare const driveTools: readonly ToolRegistration[];
|
|
65
|
+
export {};
|
|
@@ -0,0 +1,324 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
import { DriveFileAdapter } from "./adapter.js";
|
|
3
|
+
import { errorResult, formatResponse, responseFormatSchema, toolResult, } from "../../core/result.js";
|
|
4
|
+
import { driveTool } from "../../core/tool.js";
|
|
5
|
+
// ── Markdown rendering ────────────────────────────────────────────────────────
|
|
6
|
+
function formatFileMarkdown(f) {
|
|
7
|
+
const lines = [`## ${f.name ?? "(untitled)"} (${f.id})`];
|
|
8
|
+
lines.push(`- **Type**: ${f.mimeType ?? "unknown"}`);
|
|
9
|
+
if (f.size)
|
|
10
|
+
lines.push(`- **Size**: ${f.size} bytes`);
|
|
11
|
+
if (f.modifiedTime)
|
|
12
|
+
lines.push(`- **Modified**: ${f.modifiedTime}`);
|
|
13
|
+
if (f.owners?.length) {
|
|
14
|
+
lines.push(`- **Owner**: ${f.owners.map((o) => o.displayName ?? o.emailAddress).join(", ")}`);
|
|
15
|
+
}
|
|
16
|
+
if (f.trashed)
|
|
17
|
+
lines.push(`- **Trashed**: yes`);
|
|
18
|
+
if (f.webViewLink)
|
|
19
|
+
lines.push(`- **Link**: ${f.webViewLink}`);
|
|
20
|
+
return lines.join("\n");
|
|
21
|
+
}
|
|
22
|
+
function renderFiles(files, format, header, extra = {}) {
|
|
23
|
+
return formatResponse(format, { ...extra, count: files.length, files }, () => {
|
|
24
|
+
if (!files.length)
|
|
25
|
+
return `${header}\n\n(no files)`;
|
|
26
|
+
return [`# ${header}`, "", ...files.map(formatFileMarkdown)].join("\n\n");
|
|
27
|
+
});
|
|
28
|
+
}
|
|
29
|
+
// ── Tools ─────────────────────────────────────────────────────────────────────
|
|
30
|
+
// Each tool: input schema → exported pure handler (unit-tested directly) →
|
|
31
|
+
// registration. The handler's arg type derives from the schema, so the schema
|
|
32
|
+
// is the single source of truth.
|
|
33
|
+
const listFilesInput = {
|
|
34
|
+
query: z.string().optional().describe("Drive 'q' search expression"),
|
|
35
|
+
page_size: z.number().int().min(1).max(100).default(25),
|
|
36
|
+
page_token: z.string().optional(),
|
|
37
|
+
order_by: z.string().optional().describe("e.g. 'modifiedTime desc'"),
|
|
38
|
+
include_trashed: z.boolean().default(false),
|
|
39
|
+
response_format: responseFormatSchema,
|
|
40
|
+
};
|
|
41
|
+
export async function driveListFiles(drive, args) {
|
|
42
|
+
const result = await new DriveFileAdapter(drive).listFiles({
|
|
43
|
+
query: args.query,
|
|
44
|
+
pageSize: args.page_size,
|
|
45
|
+
pageToken: args.page_token,
|
|
46
|
+
orderBy: args.order_by,
|
|
47
|
+
includeTrashed: args.include_trashed,
|
|
48
|
+
});
|
|
49
|
+
const output = {
|
|
50
|
+
count: result.files.length,
|
|
51
|
+
files: result.files,
|
|
52
|
+
next_page_token: result.nextPageToken,
|
|
53
|
+
};
|
|
54
|
+
const text = renderFiles(result.files, args.response_format, `Drive files (${result.files.length})`, {
|
|
55
|
+
next_page_token: result.nextPageToken,
|
|
56
|
+
});
|
|
57
|
+
return toolResult(text, output);
|
|
58
|
+
}
|
|
59
|
+
const listFilesTool = driveTool({
|
|
60
|
+
name: "drive_list_files",
|
|
61
|
+
title: "List / search Drive files",
|
|
62
|
+
description: `List or search files and folders in Google Drive.
|
|
63
|
+
|
|
64
|
+
Args:
|
|
65
|
+
- query (string, optional): Drive search query (the 'q' parameter). Examples:
|
|
66
|
+
name contains 'budget'
|
|
67
|
+
mimeType = 'application/vnd.google-apps.spreadsheet'
|
|
68
|
+
'<folderId>' in parents
|
|
69
|
+
fullText contains 'quarterly report'
|
|
70
|
+
modifiedTime > '2024-01-01T00:00:00'
|
|
71
|
+
Combine with 'and'/'or'. Omit to list recent files.
|
|
72
|
+
- page_size (number 1-100, default 25)
|
|
73
|
+
- page_token (string, optional): from a previous response's next_page_token
|
|
74
|
+
- order_by (string, optional): e.g. 'modifiedTime desc', 'name'
|
|
75
|
+
- include_trashed (boolean, default false)
|
|
76
|
+
- response_format ('markdown'|'json', default markdown)
|
|
77
|
+
|
|
78
|
+
Returns: { count, files:[{id,name,mimeType,modifiedTime,size,parents,webViewLink,owners}], next_page_token }`,
|
|
79
|
+
inputSchema: listFilesInput,
|
|
80
|
+
annotations: { readOnlyHint: true, destructiveHint: false, idempotentHint: true, openWorldHint: true },
|
|
81
|
+
run: driveListFiles,
|
|
82
|
+
});
|
|
83
|
+
const getFileInput = {
|
|
84
|
+
file_id: z.string().min(1).describe("Drive file ID"),
|
|
85
|
+
response_format: responseFormatSchema,
|
|
86
|
+
};
|
|
87
|
+
export async function driveGetFile(drive, args) {
|
|
88
|
+
const file = await new DriveFileAdapter(drive).getFile(args.file_id);
|
|
89
|
+
const text = formatResponse(args.response_format, file, () => formatFileMarkdown(file));
|
|
90
|
+
return toolResult(text, { file });
|
|
91
|
+
}
|
|
92
|
+
const getFileTool = driveTool({
|
|
93
|
+
name: "drive_get_file",
|
|
94
|
+
title: "Get Drive file metadata",
|
|
95
|
+
description: `Get metadata for a single Drive file or folder by ID.
|
|
96
|
+
|
|
97
|
+
Args:
|
|
98
|
+
- file_id (string): the Drive file ID
|
|
99
|
+
- response_format ('markdown'|'json', default markdown)
|
|
100
|
+
|
|
101
|
+
Returns: { file: {id,name,mimeType,size,modifiedTime,parents,owners,webViewLink,...} }`,
|
|
102
|
+
inputSchema: getFileInput,
|
|
103
|
+
annotations: { readOnlyHint: true, destructiveHint: false, idempotentHint: true, openWorldHint: true },
|
|
104
|
+
run: driveGetFile,
|
|
105
|
+
});
|
|
106
|
+
const downloadFileInput = {
|
|
107
|
+
file_id: z.string().min(1),
|
|
108
|
+
export_mime_type: z.string().optional(),
|
|
109
|
+
save_path: z
|
|
110
|
+
.string()
|
|
111
|
+
.optional()
|
|
112
|
+
.describe("Path under TERRA_MCP_LOCAL_FILE_ROOT to write the downloaded bytes"),
|
|
113
|
+
};
|
|
114
|
+
export async function driveDownloadFile(drive, args) {
|
|
115
|
+
const download = await new DriveFileAdapter(drive).downloadFile({
|
|
116
|
+
fileId: args.file_id,
|
|
117
|
+
exportMimeType: args.export_mime_type,
|
|
118
|
+
savePath: args.save_path,
|
|
119
|
+
});
|
|
120
|
+
if (download.savedTo) {
|
|
121
|
+
return toolResult(`Downloaded "${download.name}" (${download.bytes} bytes, ${download.mimeType}) to ${download.savedTo}`, { file_id: args.file_id, saved_to: download.savedTo, bytes: download.bytes, mime_type: download.mimeType });
|
|
122
|
+
}
|
|
123
|
+
if (download.binaryRequiresSavePath) {
|
|
124
|
+
return errorResult(`Error: "${download.name}" is binary (${download.mimeType}). Provide save_path to write it to disk, ` +
|
|
125
|
+
`or set export_mime_type to a text format (e.g. text/csv, text/plain) for Google files.`);
|
|
126
|
+
}
|
|
127
|
+
return toolResult(download.content ?? "", {
|
|
128
|
+
file_id: args.file_id,
|
|
129
|
+
name: download.name,
|
|
130
|
+
mime_type: download.mimeType,
|
|
131
|
+
content: download.content,
|
|
132
|
+
});
|
|
133
|
+
}
|
|
134
|
+
const downloadFileTool = driveTool({
|
|
135
|
+
name: "drive_download_file",
|
|
136
|
+
title: "Download / export Drive file",
|
|
137
|
+
description: `Download a file's content. Google-native files (Docs/Sheets/Slides) are exported.
|
|
138
|
+
|
|
139
|
+
Args:
|
|
140
|
+
- file_id (string)
|
|
141
|
+
- export_mime_type (string, optional): for Google-native files, e.g. 'text/csv', 'text/plain',
|
|
142
|
+
'application/pdf', 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'.
|
|
143
|
+
Defaults: Sheets→text/csv, Docs→text/plain, Slides→application/pdf.
|
|
144
|
+
- save_path (string, optional): write bytes under TERRA_MCP_LOCAL_FILE_ROOT. Required for
|
|
145
|
+
binary content; if omitted, only text content is returned inline.
|
|
146
|
+
|
|
147
|
+
Returns (text content inline) or { file_id, saved_to, bytes, mime_type } when saved to disk.`,
|
|
148
|
+
inputSchema: downloadFileInput,
|
|
149
|
+
annotations: { readOnlyHint: false, destructiveHint: false, idempotentHint: true, openWorldHint: true },
|
|
150
|
+
run: driveDownloadFile,
|
|
151
|
+
});
|
|
152
|
+
const createFolderInput = {
|
|
153
|
+
name: z.string().min(1),
|
|
154
|
+
parent_id: z.string().optional(),
|
|
155
|
+
};
|
|
156
|
+
export async function driveCreateFolder(drive, args) {
|
|
157
|
+
const file = await new DriveFileAdapter(drive).createFolder({
|
|
158
|
+
name: args.name,
|
|
159
|
+
parentId: args.parent_id,
|
|
160
|
+
});
|
|
161
|
+
return toolResult(`Created folder "${file.name}" (${file.id})`, { file });
|
|
162
|
+
}
|
|
163
|
+
const createFolderTool = driveTool({
|
|
164
|
+
name: "drive_create_folder",
|
|
165
|
+
title: "Create Drive folder",
|
|
166
|
+
description: `Create a new folder in Drive.
|
|
167
|
+
|
|
168
|
+
Args:
|
|
169
|
+
- name (string)
|
|
170
|
+
- parent_id (string, optional): parent folder ID; omit for My Drive root
|
|
171
|
+
|
|
172
|
+
Returns: { file: {id, name, ...} }`,
|
|
173
|
+
inputSchema: createFolderInput,
|
|
174
|
+
annotations: { readOnlyHint: false, destructiveHint: false, idempotentHint: false, openWorldHint: true },
|
|
175
|
+
run: driveCreateFolder,
|
|
176
|
+
});
|
|
177
|
+
const uploadFileInput = {
|
|
178
|
+
name: z.string().min(1),
|
|
179
|
+
content: z.string().optional(),
|
|
180
|
+
local_path: z.string().optional(),
|
|
181
|
+
mime_type: z.string().optional(),
|
|
182
|
+
parent_id: z.string().optional(),
|
|
183
|
+
};
|
|
184
|
+
export async function driveUploadFile(drive, args) {
|
|
185
|
+
if (!args.content && !args.local_path) {
|
|
186
|
+
return errorResult("Error: provide either 'content' (inline text) or 'local_path' to upload.");
|
|
187
|
+
}
|
|
188
|
+
const file = await new DriveFileAdapter(drive).uploadFile({
|
|
189
|
+
name: args.name,
|
|
190
|
+
content: args.content,
|
|
191
|
+
localPath: args.local_path,
|
|
192
|
+
mimeType: args.mime_type,
|
|
193
|
+
parentId: args.parent_id,
|
|
194
|
+
});
|
|
195
|
+
return toolResult(`Uploaded "${file.name}" (${file.id})`, { file });
|
|
196
|
+
}
|
|
197
|
+
const uploadFileTool = driveTool({
|
|
198
|
+
name: "drive_upload_file",
|
|
199
|
+
title: "Upload file to Drive",
|
|
200
|
+
description: `Create a new Drive file from inline text or a local file path.
|
|
201
|
+
|
|
202
|
+
Args:
|
|
203
|
+
- name (string): file name to create
|
|
204
|
+
- content (string, optional): inline text content
|
|
205
|
+
- local_path (string, optional): path under TERRA_MCP_LOCAL_FILE_ROOT to upload (takes precedence)
|
|
206
|
+
- mime_type (string, optional): e.g. 'text/plain', 'text/csv', 'application/pdf' (default octet-stream)
|
|
207
|
+
- parent_id (string, optional): destination folder ID
|
|
208
|
+
|
|
209
|
+
Provide exactly one of content/local_path. Returns: { file: {id, name, ...} }`,
|
|
210
|
+
inputSchema: uploadFileInput,
|
|
211
|
+
annotations: { readOnlyHint: false, destructiveHint: false, idempotentHint: false, openWorldHint: true },
|
|
212
|
+
run: driveUploadFile,
|
|
213
|
+
});
|
|
214
|
+
const updateFileInput = {
|
|
215
|
+
file_id: z.string().min(1),
|
|
216
|
+
new_name: z.string().optional(),
|
|
217
|
+
add_parents: z.string().optional(),
|
|
218
|
+
remove_parents: z.string().optional(),
|
|
219
|
+
content: z.string().optional(),
|
|
220
|
+
mime_type: z.string().optional(),
|
|
221
|
+
};
|
|
222
|
+
export async function driveUpdateFile(drive, args) {
|
|
223
|
+
const file = await new DriveFileAdapter(drive).updateFile({
|
|
224
|
+
fileId: args.file_id,
|
|
225
|
+
newName: args.new_name,
|
|
226
|
+
addParents: args.add_parents,
|
|
227
|
+
removeParents: args.remove_parents,
|
|
228
|
+
content: args.content,
|
|
229
|
+
mimeType: args.mime_type,
|
|
230
|
+
});
|
|
231
|
+
return toolResult(`Updated "${file.name}" (${file.id})`, { file });
|
|
232
|
+
}
|
|
233
|
+
const updateFileTool = driveTool({
|
|
234
|
+
name: "drive_update_file",
|
|
235
|
+
title: "Update / rename / move Drive file",
|
|
236
|
+
description: `Rename, move, and/or replace the content of an existing Drive file.
|
|
237
|
+
|
|
238
|
+
Args:
|
|
239
|
+
- file_id (string)
|
|
240
|
+
- new_name (string, optional): rename
|
|
241
|
+
- add_parents (string, optional): comma-separated folder IDs to add (move into)
|
|
242
|
+
- remove_parents (string, optional): comma-separated folder IDs to remove
|
|
243
|
+
- content (string, optional): replace file content with this text
|
|
244
|
+
- mime_type (string, optional): MIME for replaced content (default text/plain)
|
|
245
|
+
|
|
246
|
+
Returns: { file: {id, name, ...} }`,
|
|
247
|
+
inputSchema: updateFileInput,
|
|
248
|
+
annotations: { readOnlyHint: false, destructiveHint: false, idempotentHint: true, openWorldHint: true },
|
|
249
|
+
run: driveUpdateFile,
|
|
250
|
+
});
|
|
251
|
+
const copyFileInput = {
|
|
252
|
+
file_id: z.string().min(1),
|
|
253
|
+
name: z.string().optional(),
|
|
254
|
+
parent_id: z.string().optional(),
|
|
255
|
+
};
|
|
256
|
+
export async function driveCopyFile(drive, args) {
|
|
257
|
+
const file = await new DriveFileAdapter(drive).copyFile({
|
|
258
|
+
fileId: args.file_id,
|
|
259
|
+
name: args.name,
|
|
260
|
+
parentId: args.parent_id,
|
|
261
|
+
});
|
|
262
|
+
return toolResult(`Copied to "${file.name}" (${file.id})`, { file });
|
|
263
|
+
}
|
|
264
|
+
const copyFileTool = driveTool({
|
|
265
|
+
name: "drive_copy_file",
|
|
266
|
+
title: "Copy Drive file",
|
|
267
|
+
description: `Duplicate a Drive file.
|
|
268
|
+
|
|
269
|
+
Args:
|
|
270
|
+
- file_id (string): source file
|
|
271
|
+
- name (string, optional): name for the copy
|
|
272
|
+
- parent_id (string, optional): destination folder
|
|
273
|
+
|
|
274
|
+
Returns: { file: {id, name, ...} } of the new copy`,
|
|
275
|
+
inputSchema: copyFileInput,
|
|
276
|
+
annotations: { readOnlyHint: false, destructiveHint: false, idempotentHint: false, openWorldHint: true },
|
|
277
|
+
run: driveCopyFile,
|
|
278
|
+
});
|
|
279
|
+
const deleteFileInput = {
|
|
280
|
+
file_id: z.string().min(1),
|
|
281
|
+
permanent: z.boolean().default(false).describe("Irreversibly delete instead of trashing"),
|
|
282
|
+
};
|
|
283
|
+
export async function driveDeleteFile(drive, args) {
|
|
284
|
+
const files = new DriveFileAdapter(drive);
|
|
285
|
+
if (args.permanent) {
|
|
286
|
+
await files.deleteFile(args.file_id);
|
|
287
|
+
return toolResult(`Permanently deleted file ${args.file_id}.`, {
|
|
288
|
+
file_id: args.file_id,
|
|
289
|
+
permanent: true,
|
|
290
|
+
});
|
|
291
|
+
}
|
|
292
|
+
const file = await files.trashFile(args.file_id);
|
|
293
|
+
return toolResult(`Moved "${file.name}" (${file.id}) to trash (recoverable).`, {
|
|
294
|
+
file_id: args.file_id,
|
|
295
|
+
permanent: false,
|
|
296
|
+
trashed: file.trashed,
|
|
297
|
+
});
|
|
298
|
+
}
|
|
299
|
+
const deleteFileTool = driveTool({
|
|
300
|
+
name: "drive_delete_file",
|
|
301
|
+
title: "Delete / trash Drive file",
|
|
302
|
+
description: `Move a Drive file to trash (default, recoverable) or delete it permanently.
|
|
303
|
+
|
|
304
|
+
Args:
|
|
305
|
+
- file_id (string)
|
|
306
|
+
- permanent (boolean, default false): true = permanent, irreversible delete
|
|
307
|
+
|
|
308
|
+
Returns: { file_id, permanent, trashed? }`,
|
|
309
|
+
inputSchema: deleteFileInput,
|
|
310
|
+
annotations: { readOnlyHint: false, destructiveHint: true, idempotentHint: true, openWorldHint: true },
|
|
311
|
+
run: driveDeleteFile,
|
|
312
|
+
});
|
|
313
|
+
// ── Registration ────────────────────────────────────────────────────────────
|
|
314
|
+
export const driveTools = [
|
|
315
|
+
listFilesTool,
|
|
316
|
+
getFileTool,
|
|
317
|
+
downloadFileTool,
|
|
318
|
+
createFolderTool,
|
|
319
|
+
uploadFileTool,
|
|
320
|
+
updateFileTool,
|
|
321
|
+
copyFileTool,
|
|
322
|
+
deleteFileTool,
|
|
323
|
+
];
|
|
324
|
+
//# sourceMappingURL=tools.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tools.js","sourceRoot":"","sources":["../../../src/services/drive/tools.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB,OAAO,EAAE,gBAAgB,EAAE,MAAM,cAAc,CAAC;AAChD,OAAO,EACL,WAAW,EACX,cAAc,EACd,oBAAoB,EAGpB,UAAU,GACX,MAAM,sBAAsB,CAAC;AAC9B,OAAO,EAAe,SAAS,EAAyB,MAAM,oBAAoB,CAAC;AAEnF,iFAAiF;AAEjF,SAAS,kBAAkB,CAAC,CAAuB;IACjD,MAAM,KAAK,GAAG,CAAC,MAAM,CAAC,CAAC,IAAI,IAAI,YAAY,KAAK,CAAC,CAA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BAAgB;IAChB,cAAc;IACd,cAAc;IACd,YAAY;IACZ,cAAc;CACf,CAAC"}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import type { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
|
|
2
|
+
import { type ToolRegistration } from "../core/tool.js";
|
|
3
|
+
/** Every Google tool exposed by this server, in registration order. */
|
|
4
|
+
export declare const googleTools: readonly ToolRegistration[];
|
|
5
|
+
/**
|
|
6
|
+
* The tools exposed for a given safety + scope level.
|
|
7
|
+
*
|
|
8
|
+
* - Safe mode keeps only the read-only tools; every mutating tool (create/write/
|
|
9
|
+
* delete) is dropped so a client can browse but never change anything.
|
|
10
|
+
* - `grantedScopes`, when provided, drops a service's tools entirely unless its
|
|
11
|
+
* OAuth scope was granted at login — so a Sheets-only grant exposes no
|
|
12
|
+
* `drive_*` tools. `undefined` means "scope unknown" (e.g. not signed in yet)
|
|
13
|
+
* and keeps every tool. The `google_*` auth tools are never scope-gated.
|
|
14
|
+
*
|
|
15
|
+
* @see isReadOnlyTool
|
|
16
|
+
*/
|
|
17
|
+
export declare function selectGoogleTools(safeMode: boolean, grantedScopes?: readonly string[]): readonly ToolRegistration[];
|
|
18
|
+
/** Read-only tool names — the only ones enabled in safe mode (registration order). */
|
|
19
|
+
export declare const READ_ONLY_TOOL_NAMES: readonly string[];
|
|
20
|
+
/** Mutating ("dangerous") tool names — disabled in safe mode (registration order). */
|
|
21
|
+
export declare const DANGEROUS_TOOL_NAMES: readonly string[];
|
|
22
|
+
export declare function registerGoogleTools(server: McpServer, options?: {
|
|
23
|
+
safeMode?: boolean;
|
|
24
|
+
}): Promise<void>;
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import { authTools } from "./auth/tools.js";
|
|
2
|
+
import { isReadOnlyTool, registerAll } from "../core/tool.js";
|
|
3
|
+
import { driveTools } from "./drive/tools.js";
|
|
4
|
+
import { sheetsTools } from "./sheets/tools.js";
|
|
5
|
+
import { DRIVE_SCOPE, SHEETS_SCOPE } from "../config/constants.js";
|
|
6
|
+
import { getAuthStatus } from "../google/auth.js";
|
|
7
|
+
/** Every Google tool exposed by this server, in registration order. */
|
|
8
|
+
export const googleTools = [...authTools, ...driveTools, ...sheetsTools];
|
|
9
|
+
/** Tools whose API scope must have been granted at login before they work. */
|
|
10
|
+
const SCOPED_TOOLS = [
|
|
11
|
+
{ scope: DRIVE_SCOPE, tools: driveTools },
|
|
12
|
+
{ scope: SHEETS_SCOPE, tools: sheetsTools },
|
|
13
|
+
];
|
|
14
|
+
/**
|
|
15
|
+
* The tools exposed for a given safety + scope level.
|
|
16
|
+
*
|
|
17
|
+
* - Safe mode keeps only the read-only tools; every mutating tool (create/write/
|
|
18
|
+
* delete) is dropped so a client can browse but never change anything.
|
|
19
|
+
* - `grantedScopes`, when provided, drops a service's tools entirely unless its
|
|
20
|
+
* OAuth scope was granted at login — so a Sheets-only grant exposes no
|
|
21
|
+
* `drive_*` tools. `undefined` means "scope unknown" (e.g. not signed in yet)
|
|
22
|
+
* and keeps every tool. The `google_*` auth tools are never scope-gated.
|
|
23
|
+
*
|
|
24
|
+
* @see isReadOnlyTool
|
|
25
|
+
*/
|
|
26
|
+
export function selectGoogleTools(safeMode, grantedScopes) {
|
|
27
|
+
let tools = googleTools;
|
|
28
|
+
if (grantedScopes) {
|
|
29
|
+
const granted = new Set(grantedScopes);
|
|
30
|
+
const ungranted = new Set(SCOPED_TOOLS.filter((s) => !granted.has(s.scope)).flatMap((s) => s.tools));
|
|
31
|
+
tools = tools.filter((t) => !ungranted.has(t));
|
|
32
|
+
}
|
|
33
|
+
return safeMode ? tools.filter(isReadOnlyTool) : tools;
|
|
34
|
+
}
|
|
35
|
+
/** Read-only tool names — the only ones enabled in safe mode (registration order). */
|
|
36
|
+
export const READ_ONLY_TOOL_NAMES = googleTools
|
|
37
|
+
.filter(isReadOnlyTool)
|
|
38
|
+
.map((t) => t.toolName);
|
|
39
|
+
/** Mutating ("dangerous") tool names — disabled in safe mode (registration order). */
|
|
40
|
+
export const DANGEROUS_TOOL_NAMES = googleTools
|
|
41
|
+
.filter((t) => !isReadOnlyTool(t))
|
|
42
|
+
.map((t) => t.toolName);
|
|
43
|
+
export async function registerGoogleTools(server, options = {}) {
|
|
44
|
+
// Honor the scopes the user actually granted at login. If not signed in yet,
|
|
45
|
+
// we can't know the grant, so register everything (calls fail later if a
|
|
46
|
+
// scope is missing). Best-effort: a status lookup failure falls back to all.
|
|
47
|
+
let grantedScopes;
|
|
48
|
+
try {
|
|
49
|
+
const status = await getAuthStatus();
|
|
50
|
+
grantedScopes = status.authenticated ? (status.scopes ?? undefined) : undefined;
|
|
51
|
+
}
|
|
52
|
+
catch {
|
|
53
|
+
grantedScopes = undefined;
|
|
54
|
+
}
|
|
55
|
+
registerAll(server, selectGoogleTools(options.safeMode ?? false, grantedScopes));
|
|
56
|
+
}
|
|
57
|
+
//# sourceMappingURL=registry.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"registry.js","sourceRoot":"","sources":["../../src/services/registry.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAC5C,OAAO,EAAE,cAAc,EAAE,WAAW,EAAyB,MAAM,iBAAiB,CAAC;AACrF,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAC9C,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAChD,OAAO,EAAE,WAAW,EAAE,YAAY,EAAE,MAAM,wBAAwB,CAAC;AACnE,OAAO,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAC;AAElD,uEAAuE;AACvE,MAAM,CAAC,MAAM,WAAW,GAAgC,CAAC,GAAG,SAAS,EAAE,GAAG,UAAU,EAAE,GAAG,WAAW,CAAC,CAAC;AAEtG,8EAA8E;AAC9E,MAAM,YAAY,GAAyE;IACzF,EAAE,KAAK,EAAE,WAAW,EAAE,KAAK,EAAE,UAAU,EAAE;IACzC,EAAE,KAAK,EAA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;IAC7E,yEAAyE;IACzE,6EAA6E;IAC7E,IAAI,aAA4C,CAAC;IACjD,IAAI,CAAC;QACH,MAAM,MAAM,GAAG,MAAM,aAAa,EAAE,CAAC;QACrC,aAAa,GAAG,MAAM,CAAC,aAAa,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,MAAM,IAAI,SAAS,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC;IAClF,CAAC;IAAC,MAAM,CAAC;QACP,aAAa,GAAG,SAAS,CAAC;IAC5B,CAAC;IACD,WAAW,CAAC,MAAM,EAAE,iBAAiB,CAAC,OAAO,CAAC,QAAQ,IAAI,KAAK,EAAE,aAAa,CAAC,CAAC,CAAC;AACnF,CAAC"}
|
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
import type { sheets_v4 } from "googleapis";
|
|
2
|
+
/** A single spreadsheet cell value as exchanged with the Sheets API. */
|
|
3
|
+
export type CellValue = string | number | boolean | null;
|
|
4
|
+
export interface SheetTab {
|
|
5
|
+
sheetId?: number | null;
|
|
6
|
+
title?: string | null;
|
|
7
|
+
index?: number | null;
|
|
8
|
+
rows?: number | null;
|
|
9
|
+
columns?: number | null;
|
|
10
|
+
}
|
|
11
|
+
export interface SpreadsheetSummary {
|
|
12
|
+
spreadsheetId?: string | null;
|
|
13
|
+
title?: string | null;
|
|
14
|
+
sheets: SheetTab[];
|
|
15
|
+
}
|
|
16
|
+
export interface RangeValues {
|
|
17
|
+
range?: string | null;
|
|
18
|
+
values: CellValue[][];
|
|
19
|
+
}
|
|
20
|
+
export interface WriteResult {
|
|
21
|
+
updatedRange?: string | null;
|
|
22
|
+
updatedRows?: number | null;
|
|
23
|
+
updatedColumns?: number | null;
|
|
24
|
+
updatedCells?: number | null;
|
|
25
|
+
}
|
|
26
|
+
export interface AppendResult {
|
|
27
|
+
tableRange?: string | null;
|
|
28
|
+
updatedRange?: string | null;
|
|
29
|
+
updatedRows?: number | null;
|
|
30
|
+
updatedCells?: number | null;
|
|
31
|
+
}
|
|
32
|
+
export interface BatchWriteResult {
|
|
33
|
+
totalUpdatedRows?: number | null;
|
|
34
|
+
totalUpdatedColumns?: number | null;
|
|
35
|
+
totalUpdatedCells?: number | null;
|
|
36
|
+
responses: WriteResult[];
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* Anti-corruption layer over the Sheets v4 API: every Google call lives here so
|
|
40
|
+
* tool handlers deal in plain, intention-revealing shapes. Mirrors
|
|
41
|
+
* {@link ../drive/adapter.DriveFileAdapter} so both services read the same way.
|
|
42
|
+
*/
|
|
43
|
+
export declare class SheetsAdapter {
|
|
44
|
+
private readonly sheets;
|
|
45
|
+
constructor(sheets: sheets_v4.Sheets);
|
|
46
|
+
createSpreadsheet(args: {
|
|
47
|
+
title: string;
|
|
48
|
+
sheetTitles?: string[];
|
|
49
|
+
}): Promise<SpreadsheetSummary>;
|
|
50
|
+
getSpreadsheet(spreadsheetId: string): Promise<SpreadsheetSummary>;
|
|
51
|
+
readRange(args: {
|
|
52
|
+
spreadsheetId: string;
|
|
53
|
+
range: string;
|
|
54
|
+
valueRenderOption: string;
|
|
55
|
+
}): Promise<RangeValues>;
|
|
56
|
+
readRanges(args: {
|
|
57
|
+
spreadsheetId: string;
|
|
58
|
+
ranges: string[];
|
|
59
|
+
valueRenderOption: string;
|
|
60
|
+
}): Promise<RangeValues[]>;
|
|
61
|
+
writeRange(args: {
|
|
62
|
+
spreadsheetId: string;
|
|
63
|
+
range: string;
|
|
64
|
+
values: CellValue[][];
|
|
65
|
+
valueInputOption: string;
|
|
66
|
+
}): Promise<WriteResult>;
|
|
67
|
+
batchWriteRanges(args: {
|
|
68
|
+
spreadsheetId: string;
|
|
69
|
+
data: {
|
|
70
|
+
range: string;
|
|
71
|
+
values: CellValue[][];
|
|
72
|
+
}[];
|
|
73
|
+
valueInputOption: string;
|
|
74
|
+
}): Promise<BatchWriteResult>;
|
|
75
|
+
appendRows(args: {
|
|
76
|
+
spreadsheetId: string;
|
|
77
|
+
range: string;
|
|
78
|
+
values: CellValue[][];
|
|
79
|
+
valueInputOption: string;
|
|
80
|
+
insertDataOption: string;
|
|
81
|
+
}): Promise<AppendResult>;
|
|
82
|
+
clearRange(args: {
|
|
83
|
+
spreadsheetId: string;
|
|
84
|
+
range: string;
|
|
85
|
+
}): Promise<string | null | undefined>;
|
|
86
|
+
addSheet(args: {
|
|
87
|
+
spreadsheetId: string;
|
|
88
|
+
title: string;
|
|
89
|
+
rows?: number;
|
|
90
|
+
columns?: number;
|
|
91
|
+
}): Promise<SheetTab>;
|
|
92
|
+
deleteSheet(args: {
|
|
93
|
+
spreadsheetId: string;
|
|
94
|
+
sheetId: number;
|
|
95
|
+
}): Promise<void>;
|
|
96
|
+
repeatCellFormat(args: {
|
|
97
|
+
spreadsheetId: string;
|
|
98
|
+
range: sheets_v4.Schema$GridRange;
|
|
99
|
+
format: sheets_v4.Schema$CellFormat;
|
|
100
|
+
fields: string;
|
|
101
|
+
}): Promise<void>;
|
|
102
|
+
setDataValidation(args: {
|
|
103
|
+
spreadsheetId: string;
|
|
104
|
+
range: sheets_v4.Schema$GridRange;
|
|
105
|
+
rule: sheets_v4.Schema$DataValidationRule;
|
|
106
|
+
}): Promise<void>;
|
|
107
|
+
/** Escape hatch: send raw batchUpdate requests straight through to the API. */
|
|
108
|
+
batchUpdate(args: {
|
|
109
|
+
spreadsheetId: string;
|
|
110
|
+
requests: Record<string, unknown>[];
|
|
111
|
+
}): Promise<sheets_v4.Schema$Response[]>;
|
|
112
|
+
}
|