@mcp-z/mcp-drive 1.0.8 → 1.0.10
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/dist/cjs/constants.js.map +1 -1
- package/dist/cjs/index.js +10 -24
- package/dist/cjs/index.js.map +1 -1
- package/dist/cjs/lib/create-store.js +2 -5
- package/dist/cjs/lib/create-store.js.map +1 -1
- package/dist/cjs/lib/file-streaming.d.cts +35 -0
- package/dist/cjs/lib/file-streaming.d.ts +35 -0
- package/dist/cjs/lib/file-streaming.js +289 -0
- package/dist/cjs/lib/file-streaming.js.map +1 -0
- package/dist/cjs/lib/query-builder.js.map +1 -1
- package/dist/cjs/mcp/index.js +8 -19
- package/dist/cjs/mcp/index.js.map +1 -1
- package/dist/cjs/mcp/prompts/index.js.map +1 -1
- package/dist/cjs/mcp/prompts/organize-files.js +3 -6
- package/dist/cjs/mcp/prompts/organize-files.js.map +1 -1
- package/dist/cjs/mcp/prompts/query-syntax.js +3 -6
- package/dist/cjs/mcp/prompts/query-syntax.js.map +1 -1
- package/dist/cjs/mcp/resources/file.js +3 -6
- package/dist/cjs/mcp/resources/file.js.map +1 -1
- package/dist/cjs/mcp/resources/index.js.map +1 -1
- package/dist/cjs/mcp/tools/file-move-to-trash.js +5 -11
- package/dist/cjs/mcp/tools/file-move-to-trash.js.map +1 -1
- package/dist/cjs/mcp/tools/file-move.js +11 -18
- package/dist/cjs/mcp/tools/file-move.js.map +1 -1
- package/dist/cjs/mcp/tools/file-upload.d.cts +69 -0
- package/dist/cjs/mcp/tools/file-upload.d.ts +69 -0
- package/dist/cjs/mcp/tools/file-upload.js +387 -0
- package/dist/cjs/mcp/tools/file-upload.js.map +1 -0
- package/dist/cjs/mcp/tools/files-search.js +7 -14
- package/dist/cjs/mcp/tools/files-search.js.map +1 -1
- package/dist/cjs/mcp/tools/folder-contents.js +7 -14
- package/dist/cjs/mcp/tools/folder-contents.js.map +1 -1
- package/dist/cjs/mcp/tools/folder-create.js +5 -11
- package/dist/cjs/mcp/tools/folder-create.js.map +1 -1
- package/dist/cjs/mcp/tools/folder-path.js +4 -8
- package/dist/cjs/mcp/tools/folder-path.js.map +1 -1
- package/dist/cjs/mcp/tools/folder-search.js +19 -24
- package/dist/cjs/mcp/tools/folder-search.js.map +1 -1
- package/dist/cjs/mcp/tools/index.d.cts +1 -0
- package/dist/cjs/mcp/tools/index.d.ts +1 -0
- package/dist/cjs/mcp/tools/index.js +4 -0
- package/dist/cjs/mcp/tools/index.js.map +1 -1
- package/dist/cjs/schemas/drive-query-schema.js +2 -3
- package/dist/cjs/schemas/drive-query-schema.js.map +1 -1
- package/dist/cjs/schemas/drive-validation.js.map +1 -1
- package/dist/cjs/schemas/index.js.map +1 -1
- package/dist/cjs/setup/config.js +11 -25
- package/dist/cjs/setup/config.js.map +1 -1
- package/dist/cjs/setup/http.js +15 -16
- package/dist/cjs/setup/http.js.map +1 -1
- package/dist/cjs/setup/index.js.map +1 -1
- package/dist/cjs/setup/oauth-google.js +9 -16
- package/dist/cjs/setup/oauth-google.js.map +1 -1
- package/dist/cjs/setup/runtime.d.cts +1 -1
- package/dist/cjs/setup/runtime.d.ts +1 -1
- package/dist/cjs/setup/runtime.js +11 -25
- package/dist/cjs/setup/runtime.js.map +1 -1
- package/dist/cjs/setup/stdio.js +15 -16
- package/dist/cjs/setup/stdio.js.map +1 -1
- package/dist/esm/constants.js.map +1 -1
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/lib/create-store.js.map +1 -1
- package/dist/esm/lib/file-streaming.d.ts +35 -0
- package/dist/esm/lib/file-streaming.js +111 -0
- package/dist/esm/lib/file-streaming.js.map +1 -0
- package/dist/esm/lib/query-builder.js.map +1 -1
- package/dist/esm/mcp/index.js.map +1 -1
- package/dist/esm/mcp/prompts/index.js.map +1 -1
- package/dist/esm/mcp/prompts/organize-files.js.map +1 -1
- package/dist/esm/mcp/prompts/query-syntax.js.map +1 -1
- package/dist/esm/mcp/resources/file.js.map +1 -1
- package/dist/esm/mcp/resources/index.js.map +1 -1
- package/dist/esm/mcp/tools/file-move-to-trash.js.map +1 -1
- package/dist/esm/mcp/tools/file-move.js.map +1 -1
- package/dist/esm/mcp/tools/file-upload.d.ts +69 -0
- package/dist/esm/mcp/tools/file-upload.js +163 -0
- package/dist/esm/mcp/tools/file-upload.js.map +1 -0
- package/dist/esm/mcp/tools/files-search.js.map +1 -1
- package/dist/esm/mcp/tools/folder-contents.js.map +1 -1
- package/dist/esm/mcp/tools/folder-create.js.map +1 -1
- package/dist/esm/mcp/tools/folder-path.js.map +1 -1
- package/dist/esm/mcp/tools/folder-search.js.map +1 -1
- package/dist/esm/mcp/tools/index.d.ts +1 -0
- package/dist/esm/mcp/tools/index.js +1 -0
- package/dist/esm/mcp/tools/index.js.map +1 -1
- package/dist/esm/schemas/drive-query-schema.js.map +1 -1
- package/dist/esm/schemas/drive-validation.js.map +1 -1
- package/dist/esm/schemas/index.js.map +1 -1
- package/dist/esm/setup/config.js.map +1 -1
- package/dist/esm/setup/http.js.map +1 -1
- package/dist/esm/setup/index.js.map +1 -1
- package/dist/esm/setup/oauth-google.js.map +1 -1
- package/dist/esm/setup/runtime.d.ts +1 -1
- package/dist/esm/setup/runtime.js.map +1 -1
- package/dist/esm/setup/stdio.js.map +1 -1
- package/dist/esm/types.js.map +1 -1
- package/package.json +10 -6
|
@@ -0,0 +1,387 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", {
|
|
3
|
+
value: true
|
|
4
|
+
});
|
|
5
|
+
Object.defineProperty(exports, "default", {
|
|
6
|
+
enumerable: true,
|
|
7
|
+
get: function() {
|
|
8
|
+
return createTool;
|
|
9
|
+
}
|
|
10
|
+
});
|
|
11
|
+
var _oauthgoogle = require("@mcp-z/oauth-google");
|
|
12
|
+
var _types = require("@modelcontextprotocol/sdk/types.js");
|
|
13
|
+
var _googleapis = require("googleapis");
|
|
14
|
+
var _zod = require("zod");
|
|
15
|
+
var _filestreamingts = require("../../lib/file-streaming.js");
|
|
16
|
+
function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) {
|
|
17
|
+
try {
|
|
18
|
+
var info = gen[key](arg);
|
|
19
|
+
var value = info.value;
|
|
20
|
+
} catch (error) {
|
|
21
|
+
reject(error);
|
|
22
|
+
return;
|
|
23
|
+
}
|
|
24
|
+
if (info.done) resolve(value);
|
|
25
|
+
else Promise.resolve(value).then(_next, _throw);
|
|
26
|
+
}
|
|
27
|
+
function _async_to_generator(fn) {
|
|
28
|
+
return function() {
|
|
29
|
+
var self = this, args = arguments;
|
|
30
|
+
return new Promise(function(resolve, reject) {
|
|
31
|
+
var gen = fn.apply(self, args);
|
|
32
|
+
function _next(value) {
|
|
33
|
+
asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value);
|
|
34
|
+
}
|
|
35
|
+
function _throw(err) {
|
|
36
|
+
asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err);
|
|
37
|
+
}
|
|
38
|
+
_next(undefined);
|
|
39
|
+
});
|
|
40
|
+
};
|
|
41
|
+
}
|
|
42
|
+
function _define_property(obj, key, value) {
|
|
43
|
+
if (key in obj) {
|
|
44
|
+
Object.defineProperty(obj, key, {
|
|
45
|
+
value: value,
|
|
46
|
+
enumerable: true,
|
|
47
|
+
configurable: true,
|
|
48
|
+
writable: true
|
|
49
|
+
});
|
|
50
|
+
} else obj[key] = value;
|
|
51
|
+
return obj;
|
|
52
|
+
}
|
|
53
|
+
function _instanceof(left, right) {
|
|
54
|
+
"@swc/helpers - instanceof";
|
|
55
|
+
if (right != null && typeof Symbol !== "undefined" && right[Symbol.hasInstance]) {
|
|
56
|
+
return !!right[Symbol.hasInstance](left);
|
|
57
|
+
} else return left instanceof right;
|
|
58
|
+
}
|
|
59
|
+
function _object_spread(target) {
|
|
60
|
+
for(var i = 1; i < arguments.length; i++){
|
|
61
|
+
var source = arguments[i] != null ? arguments[i] : {};
|
|
62
|
+
var ownKeys = Object.keys(source);
|
|
63
|
+
if (typeof Object.getOwnPropertySymbols === "function") {
|
|
64
|
+
ownKeys = ownKeys.concat(Object.getOwnPropertySymbols(source).filter(function(sym) {
|
|
65
|
+
return Object.getOwnPropertyDescriptor(source, sym).enumerable;
|
|
66
|
+
}));
|
|
67
|
+
}
|
|
68
|
+
ownKeys.forEach(function(key) {
|
|
69
|
+
_define_property(target, key, source[key]);
|
|
70
|
+
});
|
|
71
|
+
}
|
|
72
|
+
return target;
|
|
73
|
+
}
|
|
74
|
+
function _ts_generator(thisArg, body) {
|
|
75
|
+
var f, y, t, _ = {
|
|
76
|
+
label: 0,
|
|
77
|
+
sent: function() {
|
|
78
|
+
if (t[0] & 1) throw t[1];
|
|
79
|
+
return t[1];
|
|
80
|
+
},
|
|
81
|
+
trys: [],
|
|
82
|
+
ops: []
|
|
83
|
+
}, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype), d = Object.defineProperty;
|
|
84
|
+
return d(g, "next", {
|
|
85
|
+
value: verb(0)
|
|
86
|
+
}), d(g, "throw", {
|
|
87
|
+
value: verb(1)
|
|
88
|
+
}), d(g, "return", {
|
|
89
|
+
value: verb(2)
|
|
90
|
+
}), typeof Symbol === "function" && d(g, Symbol.iterator, {
|
|
91
|
+
value: function() {
|
|
92
|
+
return this;
|
|
93
|
+
}
|
|
94
|
+
}), g;
|
|
95
|
+
function verb(n) {
|
|
96
|
+
return function(v) {
|
|
97
|
+
return step([
|
|
98
|
+
n,
|
|
99
|
+
v
|
|
100
|
+
]);
|
|
101
|
+
};
|
|
102
|
+
}
|
|
103
|
+
function step(op) {
|
|
104
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
105
|
+
while(g && (g = 0, op[0] && (_ = 0)), _)try {
|
|
106
|
+
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
107
|
+
if (y = 0, t) op = [
|
|
108
|
+
op[0] & 2,
|
|
109
|
+
t.value
|
|
110
|
+
];
|
|
111
|
+
switch(op[0]){
|
|
112
|
+
case 0:
|
|
113
|
+
case 1:
|
|
114
|
+
t = op;
|
|
115
|
+
break;
|
|
116
|
+
case 4:
|
|
117
|
+
_.label++;
|
|
118
|
+
return {
|
|
119
|
+
value: op[1],
|
|
120
|
+
done: false
|
|
121
|
+
};
|
|
122
|
+
case 5:
|
|
123
|
+
_.label++;
|
|
124
|
+
y = op[1];
|
|
125
|
+
op = [
|
|
126
|
+
0
|
|
127
|
+
];
|
|
128
|
+
continue;
|
|
129
|
+
case 7:
|
|
130
|
+
op = _.ops.pop();
|
|
131
|
+
_.trys.pop();
|
|
132
|
+
continue;
|
|
133
|
+
default:
|
|
134
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) {
|
|
135
|
+
_ = 0;
|
|
136
|
+
continue;
|
|
137
|
+
}
|
|
138
|
+
if (op[0] === 3 && (!t || op[1] > t[0] && op[1] < t[3])) {
|
|
139
|
+
_.label = op[1];
|
|
140
|
+
break;
|
|
141
|
+
}
|
|
142
|
+
if (op[0] === 6 && _.label < t[1]) {
|
|
143
|
+
_.label = t[1];
|
|
144
|
+
t = op;
|
|
145
|
+
break;
|
|
146
|
+
}
|
|
147
|
+
if (t && _.label < t[2]) {
|
|
148
|
+
_.label = t[2];
|
|
149
|
+
_.ops.push(op);
|
|
150
|
+
break;
|
|
151
|
+
}
|
|
152
|
+
if (t[2]) _.ops.pop();
|
|
153
|
+
_.trys.pop();
|
|
154
|
+
continue;
|
|
155
|
+
}
|
|
156
|
+
op = body.call(thisArg, _);
|
|
157
|
+
} catch (e) {
|
|
158
|
+
op = [
|
|
159
|
+
6,
|
|
160
|
+
e
|
|
161
|
+
];
|
|
162
|
+
y = 0;
|
|
163
|
+
} finally{
|
|
164
|
+
f = t = 0;
|
|
165
|
+
}
|
|
166
|
+
if (op[0] & 5) throw op[1];
|
|
167
|
+
return {
|
|
168
|
+
value: op[0] ? op[1] : void 0,
|
|
169
|
+
done: true
|
|
170
|
+
};
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
var AuthRequiredBranchSchema = _oauthgoogle.schemas.AuthRequiredBranchSchema;
|
|
174
|
+
var inputSchema = _zod.z.object({
|
|
175
|
+
sourceUri: _zod.z.string().trim().min(1).describe('File URI to upload (file://, http://, https://)'),
|
|
176
|
+
name: _zod.z.string().trim().min(1).optional().describe('File name in Drive, including extension (defaults to the source file name)'),
|
|
177
|
+
mimeType: _zod.z.string().trim().min(1).optional().describe('MIME type, e.g. application/pdf (defaults to the Content-Type header or detection from the file extension)'),
|
|
178
|
+
parentId: _zod.z.string().optional().describe('Parent folder ID (omit to upload to My Drive root)'),
|
|
179
|
+
description: _zod.z.string().optional().describe('Description to store in the file metadata')
|
|
180
|
+
});
|
|
181
|
+
// Success branch schema
|
|
182
|
+
var successBranchSchema = _zod.z.object({
|
|
183
|
+
type: _zod.z.literal('success'),
|
|
184
|
+
operationSummary: _zod.z.string().describe('Summary of the file upload operation'),
|
|
185
|
+
itemsProcessed: _zod.z.number().describe('Total items attempted (always 1 for single file)'),
|
|
186
|
+
itemsChanged: _zod.z.number().describe('Successfully uploaded files (always 1 on success)'),
|
|
187
|
+
completedAt: _zod.z.string().describe('ISO datetime when operation completed'),
|
|
188
|
+
id: _zod.z.string().describe('ID of the uploaded file'),
|
|
189
|
+
name: _zod.z.string().describe('Name of the uploaded file'),
|
|
190
|
+
mimeType: _zod.z.string().describe('MIME type of the uploaded file'),
|
|
191
|
+
size: _zod.z.string().describe('Size of the uploaded file in bytes'),
|
|
192
|
+
webViewLink: _zod.z.string().describe('URL to view the file in Drive'),
|
|
193
|
+
parentId: _zod.z.string().optional().describe('ID of the parent folder'),
|
|
194
|
+
parentName: _zod.z.string().optional().describe('Name of the parent folder')
|
|
195
|
+
});
|
|
196
|
+
// Output schema with auth_required support
|
|
197
|
+
var outputSchema = _zod.z.discriminatedUnion('type', [
|
|
198
|
+
successBranchSchema,
|
|
199
|
+
AuthRequiredBranchSchema
|
|
200
|
+
]);
|
|
201
|
+
var config = {
|
|
202
|
+
title: 'Upload File',
|
|
203
|
+
description: 'Upload a file to Google Drive from a file:// or http(s):// URI. Content is streamed from the source (no temp files) in a single multipart request. Returns file ID for use in other operations.',
|
|
204
|
+
inputSchema: inputSchema,
|
|
205
|
+
outputSchema: _zod.z.object({
|
|
206
|
+
result: outputSchema
|
|
207
|
+
})
|
|
208
|
+
};
|
|
209
|
+
function handler(_0, _1) {
|
|
210
|
+
return _async_to_generator(function(param, extra) {
|
|
211
|
+
var sourceUri, name, mimeType, parentId, description, logger, _res_id, _res_name, _res_mimeType, _res_size, _source_size, _res_webViewLink, drive, source, finalName, finalMimeType, response, res, id, resultName, resultMimeType, size, webViewLink, parents, parentName, actualParentId, parentResponse, e, locationSummary, result, error, message;
|
|
212
|
+
return _ts_generator(this, function(_state) {
|
|
213
|
+
switch(_state.label){
|
|
214
|
+
case 0:
|
|
215
|
+
sourceUri = param.sourceUri, name = param.name, mimeType = param.mimeType, parentId = param.parentId, description = param.description;
|
|
216
|
+
logger = extra.logger;
|
|
217
|
+
logger.info('drive.file.upload called', {
|
|
218
|
+
sourceUri: sourceUri,
|
|
219
|
+
name: name || 'auto',
|
|
220
|
+
parentId: parentId || 'root'
|
|
221
|
+
});
|
|
222
|
+
_state.label = 1;
|
|
223
|
+
case 1:
|
|
224
|
+
_state.trys.push([
|
|
225
|
+
1,
|
|
226
|
+
9,
|
|
227
|
+
,
|
|
228
|
+
10
|
|
229
|
+
]);
|
|
230
|
+
drive = _googleapis.google.drive({
|
|
231
|
+
version: 'v3',
|
|
232
|
+
auth: extra.authContext.auth
|
|
233
|
+
});
|
|
234
|
+
return [
|
|
235
|
+
4,
|
|
236
|
+
(0, _filestreamingts.getFileReadStream)(sourceUri)
|
|
237
|
+
];
|
|
238
|
+
case 2:
|
|
239
|
+
source = _state.sent();
|
|
240
|
+
finalName = name || source.fileName;
|
|
241
|
+
finalMimeType = mimeType || source.contentType || (0, _filestreamingts.guessMimeType)(finalName);
|
|
242
|
+
return [
|
|
243
|
+
4,
|
|
244
|
+
drive.files.create({
|
|
245
|
+
requestBody: _object_spread({
|
|
246
|
+
name: finalName,
|
|
247
|
+
mimeType: finalMimeType,
|
|
248
|
+
parents: parentId ? [
|
|
249
|
+
parentId
|
|
250
|
+
] : null
|
|
251
|
+
}, description && {
|
|
252
|
+
description: description
|
|
253
|
+
}),
|
|
254
|
+
media: {
|
|
255
|
+
mimeType: finalMimeType,
|
|
256
|
+
body: source.stream
|
|
257
|
+
},
|
|
258
|
+
supportsAllDrives: true,
|
|
259
|
+
fields: 'id,name,mimeType,size,webViewLink,parents'
|
|
260
|
+
})
|
|
261
|
+
];
|
|
262
|
+
case 3:
|
|
263
|
+
response = _state.sent();
|
|
264
|
+
res = response.data;
|
|
265
|
+
id = (_res_id = res.id) !== null && _res_id !== void 0 ? _res_id : '';
|
|
266
|
+
resultName = (_res_name = res.name) !== null && _res_name !== void 0 ? _res_name : finalName;
|
|
267
|
+
resultMimeType = (_res_mimeType = res.mimeType) !== null && _res_mimeType !== void 0 ? _res_mimeType : finalMimeType;
|
|
268
|
+
size = (_res_size = res.size) !== null && _res_size !== void 0 ? _res_size : String((_source_size = source.size) !== null && _source_size !== void 0 ? _source_size : 0);
|
|
269
|
+
webViewLink = (_res_webViewLink = res.webViewLink) !== null && _res_webViewLink !== void 0 ? _res_webViewLink : '';
|
|
270
|
+
parents = res.parents || [];
|
|
271
|
+
if (!(parents.length > 0)) return [
|
|
272
|
+
3,
|
|
273
|
+
8
|
|
274
|
+
];
|
|
275
|
+
actualParentId = parents[0];
|
|
276
|
+
if (!(actualParentId === 'root')) return [
|
|
277
|
+
3,
|
|
278
|
+
4
|
|
279
|
+
];
|
|
280
|
+
parentName = 'My Drive';
|
|
281
|
+
return [
|
|
282
|
+
3,
|
|
283
|
+
8
|
|
284
|
+
];
|
|
285
|
+
case 4:
|
|
286
|
+
if (!actualParentId) return [
|
|
287
|
+
3,
|
|
288
|
+
8
|
|
289
|
+
];
|
|
290
|
+
_state.label = 5;
|
|
291
|
+
case 5:
|
|
292
|
+
_state.trys.push([
|
|
293
|
+
5,
|
|
294
|
+
7,
|
|
295
|
+
,
|
|
296
|
+
8
|
|
297
|
+
]);
|
|
298
|
+
return [
|
|
299
|
+
4,
|
|
300
|
+
drive.files.get({
|
|
301
|
+
fileId: actualParentId,
|
|
302
|
+
fields: 'name'
|
|
303
|
+
})
|
|
304
|
+
];
|
|
305
|
+
case 6:
|
|
306
|
+
parentResponse = _state.sent();
|
|
307
|
+
parentName = parentResponse.data.name || actualParentId;
|
|
308
|
+
return [
|
|
309
|
+
3,
|
|
310
|
+
8
|
|
311
|
+
];
|
|
312
|
+
case 7:
|
|
313
|
+
e = _state.sent();
|
|
314
|
+
logger.info('Failed to fetch parent name', {
|
|
315
|
+
parentId: actualParentId,
|
|
316
|
+
error: e
|
|
317
|
+
});
|
|
318
|
+
parentName = actualParentId; // Fallback to ID
|
|
319
|
+
return [
|
|
320
|
+
3,
|
|
321
|
+
8
|
|
322
|
+
];
|
|
323
|
+
case 8:
|
|
324
|
+
locationSummary = parentName ? ' in "'.concat(parentName, '"') : ' in My Drive';
|
|
325
|
+
logger.info('drive.file.upload success', {
|
|
326
|
+
id: id,
|
|
327
|
+
name: resultName,
|
|
328
|
+
size: size,
|
|
329
|
+
parentId: actualParentId
|
|
330
|
+
});
|
|
331
|
+
// Build result object with operation metadata
|
|
332
|
+
result = _object_spread({
|
|
333
|
+
type: 'success',
|
|
334
|
+
operationSummary: 'Uploaded "'.concat(resultName, '"').concat(locationSummary),
|
|
335
|
+
itemsProcessed: 1,
|
|
336
|
+
itemsChanged: 1,
|
|
337
|
+
completedAt: new Date().toISOString(),
|
|
338
|
+
id: id,
|
|
339
|
+
name: resultName,
|
|
340
|
+
mimeType: resultMimeType,
|
|
341
|
+
size: size,
|
|
342
|
+
webViewLink: webViewLink
|
|
343
|
+
}, actualParentId && {
|
|
344
|
+
parentId: actualParentId
|
|
345
|
+
}, parentName && {
|
|
346
|
+
parentName: parentName
|
|
347
|
+
});
|
|
348
|
+
return [
|
|
349
|
+
2,
|
|
350
|
+
{
|
|
351
|
+
content: [
|
|
352
|
+
{
|
|
353
|
+
type: 'text',
|
|
354
|
+
text: JSON.stringify(result)
|
|
355
|
+
}
|
|
356
|
+
],
|
|
357
|
+
structuredContent: {
|
|
358
|
+
result: result
|
|
359
|
+
}
|
|
360
|
+
}
|
|
361
|
+
];
|
|
362
|
+
case 9:
|
|
363
|
+
error = _state.sent();
|
|
364
|
+
message = _instanceof(error, Error) ? error.message : String(error);
|
|
365
|
+
logger.error('drive.file.upload error', {
|
|
366
|
+
error: message
|
|
367
|
+
});
|
|
368
|
+
// Throw McpError for proper MCP error handling
|
|
369
|
+
throw new _types.McpError(_types.ErrorCode.InternalError, "Error uploading file: ".concat(message), {
|
|
370
|
+
stack: _instanceof(error, Error) ? error.stack : undefined
|
|
371
|
+
});
|
|
372
|
+
case 10:
|
|
373
|
+
return [
|
|
374
|
+
2
|
|
375
|
+
];
|
|
376
|
+
}
|
|
377
|
+
});
|
|
378
|
+
}).apply(this, arguments);
|
|
379
|
+
}
|
|
380
|
+
function createTool() {
|
|
381
|
+
return {
|
|
382
|
+
name: 'file-upload',
|
|
383
|
+
config: config,
|
|
384
|
+
handler: handler
|
|
385
|
+
};
|
|
386
|
+
}
|
|
387
|
+
/* CJS INTEROP */ if (exports.__esModule && exports.default) { try { Object.defineProperty(exports.default, '__esModule', { value: true }); for (var key in exports) { exports.default[key] = exports[key]; } } catch (_) {}; module.exports = exports.default; }
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["/Users/kevin/Dev/OpenSource/ai/mcp-z/mcp-drive/src/mcp/tools/file-upload.ts"],"sourcesContent":["import type { EnrichedExtra } from '@mcp-z/oauth-google';\nimport { schemas } from '@mcp-z/oauth-google';\n\nconst { AuthRequiredBranchSchema } = schemas;\n\nimport type { CallToolResult } from '@modelcontextprotocol/sdk/types.js';\nimport { ErrorCode, McpError } from '@modelcontextprotocol/sdk/types.js';\nimport { google } from 'googleapis';\nimport { z } from 'zod';\nimport { getFileReadStream, guessMimeType } from '../../lib/file-streaming.ts';\n\nconst inputSchema = z.object({\n sourceUri: z.string().trim().min(1).describe('File URI to upload (file://, http://, https://)'),\n name: z.string().trim().min(1).optional().describe('File name in Drive, including extension (defaults to the source file name)'),\n mimeType: z.string().trim().min(1).optional().describe('MIME type, e.g. application/pdf (defaults to the Content-Type header or detection from the file extension)'),\n parentId: z.string().optional().describe('Parent folder ID (omit to upload to My Drive root)'),\n description: z.string().optional().describe('Description to store in the file metadata'),\n});\n\n// Success branch schema\nconst successBranchSchema = z.object({\n type: z.literal('success'),\n operationSummary: z.string().describe('Summary of the file upload operation'),\n itemsProcessed: z.number().describe('Total items attempted (always 1 for single file)'),\n itemsChanged: z.number().describe('Successfully uploaded files (always 1 on success)'),\n completedAt: z.string().describe('ISO datetime when operation completed'),\n id: z.string().describe('ID of the uploaded file'),\n name: z.string().describe('Name of the uploaded file'),\n mimeType: z.string().describe('MIME type of the uploaded file'),\n size: z.string().describe('Size of the uploaded file in bytes'),\n webViewLink: z.string().describe('URL to view the file in Drive'),\n parentId: z.string().optional().describe('ID of the parent folder'),\n parentName: z.string().optional().describe('Name of the parent folder'),\n});\n\n// Output schema with auth_required support\nconst outputSchema = z.discriminatedUnion('type', [successBranchSchema, AuthRequiredBranchSchema]);\n\nconst config = {\n title: 'Upload File',\n description: 'Upload a file to Google Drive from a file:// or http(s):// URI. Content is streamed from the source (no temp files) in a single multipart request. Returns file ID for use in other operations.',\n inputSchema,\n outputSchema: z.object({\n result: outputSchema,\n }),\n} as const;\n\n// Export types for strong typing in tests\nexport type Input = z.infer<typeof inputSchema>;\nexport type Output = z.infer<typeof outputSchema>;\n\nasync function handler({ sourceUri, name, mimeType, parentId, description }: Input, extra: EnrichedExtra): Promise<CallToolResult> {\n const logger = extra.logger;\n logger.info('drive.file.upload called', {\n sourceUri,\n name: name || 'auto',\n parentId: parentId || 'root',\n });\n\n try {\n const drive = google.drive({ version: 'v3', auth: extra.authContext.auth });\n\n // Stream source content directly from URI (no temp files)\n const source = await getFileReadStream(sourceUri);\n const finalName = name || source.fileName;\n const finalMimeType = mimeType || source.contentType || guessMimeType(finalName);\n\n // Create the file with streamed content (multipart upload; the client pipes the\n // stream body through without buffering it into memory)\n const response = await drive.files.create({\n requestBody: {\n name: finalName,\n mimeType: finalMimeType,\n parents: parentId ? [parentId] : null,\n ...(description && { description }),\n },\n media: { mimeType: finalMimeType, body: source.stream },\n supportsAllDrives: true,\n fields: 'id,name,mimeType,size,webViewLink,parents',\n });\n\n const res = response.data;\n const id = res.id ?? '';\n const resultName = res.name ?? finalName;\n const resultMimeType = res.mimeType ?? finalMimeType;\n const size = res.size ?? String(source.size ?? 0);\n const webViewLink = res.webViewLink ?? '';\n const parents = (res.parents as string[] | undefined) || [];\n\n // Fetch parent name if parentId was provided\n let parentName: string | undefined;\n let actualParentId: string | undefined;\n\n if (parents.length > 0) {\n actualParentId = parents[0];\n\n if (actualParentId === 'root') {\n parentName = 'My Drive';\n } else if (actualParentId) {\n try {\n const parentResponse = await drive.files.get({\n fileId: actualParentId,\n fields: 'name',\n });\n parentName = (parentResponse.data.name as string | undefined) || actualParentId;\n } catch (e) {\n logger.info('Failed to fetch parent name', {\n parentId: actualParentId,\n error: e,\n });\n parentName = actualParentId; // Fallback to ID\n }\n }\n }\n\n const locationSummary = parentName ? ` in \"${parentName}\"` : ' in My Drive';\n\n logger.info('drive.file.upload success', {\n id,\n name: resultName,\n size,\n parentId: actualParentId,\n });\n\n // Build result object with operation metadata\n const result: Output = {\n type: 'success' as const,\n operationSummary: `Uploaded \"${resultName}\"${locationSummary}`,\n itemsProcessed: 1,\n itemsChanged: 1,\n completedAt: new Date().toISOString(),\n id,\n name: resultName,\n mimeType: resultMimeType,\n size,\n webViewLink,\n ...(actualParentId && { parentId: actualParentId }),\n ...(parentName && { parentName }),\n };\n\n return {\n content: [\n {\n type: 'text' as const,\n text: JSON.stringify(result),\n },\n ],\n structuredContent: { result },\n };\n } catch (error) {\n const message = error instanceof Error ? error.message : String(error);\n logger.error('drive.file.upload error', { error: message });\n\n // Throw McpError for proper MCP error handling\n throw new McpError(ErrorCode.InternalError, `Error uploading file: ${message}`, {\n stack: error instanceof Error ? error.stack : undefined,\n });\n }\n}\n\nexport default function createTool() {\n return {\n name: 'file-upload' as const,\n config,\n handler,\n };\n}\n"],"names":["createTool","AuthRequiredBranchSchema","schemas","inputSchema","z","object","sourceUri","string","trim","min","describe","name","optional","mimeType","parentId","description","successBranchSchema","type","literal","operationSummary","itemsProcessed","number","itemsChanged","completedAt","id","size","webViewLink","parentName","outputSchema","discriminatedUnion","config","title","result","handler","extra","logger","res","source","drive","finalName","finalMimeType","response","resultName","resultMimeType","parents","actualParentId","parentResponse","e","locationSummary","error","message","info","google","version","auth","authContext","getFileReadStream","fileName","contentType","guessMimeType","files","create","requestBody","media","body","stream","supportsAllDrives","fields","data","String","length","get","fileId","Date","toISOString","content","text","JSON","stringify","structuredContent","Error","McpError","ErrorCode","InternalError","stack","undefined"],"mappings":";;;;+BAgKA;;;eAAwBA;;;2BA/JA;qBAKY;0BACb;mBACL;+BAC+B;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AANjD,IAAM,AAAEC,2BAA6BC,oBAAO,CAApCD;AAQR,IAAME,cAAcC,MAAC,CAACC,MAAM,CAAC;IAC3BC,WAAWF,MAAC,CAACG,MAAM,GAAGC,IAAI,GAAGC,GAAG,CAAC,GAAGC,QAAQ,CAAC;IAC7CC,MAAMP,MAAC,CAACG,MAAM,GAAGC,IAAI,GAAGC,GAAG,CAAC,GAAGG,QAAQ,G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AU+B;oBAAe,GAC7ClB,cAAc;wBAAEA,YAAAA;oBAAW;oBAGjC;;wBAAO;4BACLgD,OAAO;gCACL;oCACE1D,MAAM;oCACN2D,MAAMC,KAAKC,SAAS,CAAC9C;gCACvB;;4BAEF+C,mBAAmB;gCAAE/C,QAAAA;4BAAO;wBAC9B;;;oBACOiB;oBACDC,UAAUD,AAAK,YAALA,OAAiB+B,SAAQ/B,MAAMC,OAAO,GAAGmB,OAAOpB;oBAChEd,OAAOc,KAAK,CAAC,2BAA2B;wBAAEA,OAAOC;oBAAQ;oBAEzD,+CAA+C;oBAC/C,MAAM,IAAI+B,eAAQ,CAACC,gBAAS,CAACC,aAAa,EAAE,AAAC,yBAAgC,OAARjC,UAAW;wBAC9EkC,OAAOnC,AAAK,YAALA,OAAiB+B,SAAQ/B,MAAMmC,KAAK,GAAGC;oBAChD;;;;;;;IAEJ;;AAEe,SAASrF;IACtB,OAAO;QACLW,MAAM;QACNmB,QAAAA;QACAG,SAAAA;IACF;AACF"}
|
|
@@ -23,11 +23,8 @@ function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) {
|
|
|
23
23
|
reject(error);
|
|
24
24
|
return;
|
|
25
25
|
}
|
|
26
|
-
if (info.done)
|
|
27
|
-
|
|
28
|
-
} else {
|
|
29
|
-
Promise.resolve(value).then(_next, _throw);
|
|
30
|
-
}
|
|
26
|
+
if (info.done) resolve(value);
|
|
27
|
+
else Promise.resolve(value).then(_next, _throw);
|
|
31
28
|
}
|
|
32
29
|
function _async_to_generator(fn) {
|
|
33
30
|
return function() {
|
|
@@ -52,17 +49,14 @@ function _define_property(obj, key, value) {
|
|
|
52
49
|
configurable: true,
|
|
53
50
|
writable: true
|
|
54
51
|
});
|
|
55
|
-
} else
|
|
56
|
-
obj[key] = value;
|
|
57
|
-
}
|
|
52
|
+
} else obj[key] = value;
|
|
58
53
|
return obj;
|
|
59
54
|
}
|
|
60
55
|
function _instanceof(left, right) {
|
|
56
|
+
"@swc/helpers - instanceof";
|
|
61
57
|
if (right != null && typeof Symbol !== "undefined" && right[Symbol.hasInstance]) {
|
|
62
58
|
return !!right[Symbol.hasInstance](left);
|
|
63
|
-
} else
|
|
64
|
-
return left instanceof right;
|
|
65
|
-
}
|
|
59
|
+
} else return left instanceof right;
|
|
66
60
|
}
|
|
67
61
|
function _object_spread(target) {
|
|
68
62
|
for(var i = 1; i < arguments.length; i++){
|
|
@@ -94,9 +88,8 @@ function ownKeys(object, enumerableOnly) {
|
|
|
94
88
|
}
|
|
95
89
|
function _object_spread_props(target, source) {
|
|
96
90
|
source = source != null ? source : {};
|
|
97
|
-
if (Object.getOwnPropertyDescriptors)
|
|
98
|
-
|
|
99
|
-
} else {
|
|
91
|
+
if (Object.getOwnPropertyDescriptors) Object.defineProperties(target, Object.getOwnPropertyDescriptors(source));
|
|
92
|
+
else {
|
|
100
93
|
ownKeys(Object(source)).forEach(function(key) {
|
|
101
94
|
Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key));
|
|
102
95
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["/Users/kevin/Dev/Projects/mcp-z/mcp-drive/src/mcp/tools/files-search.ts"],"sourcesContent":["import type { EnrichedExtra } from '@mcp-z/oauth-google';\nimport { schemas } from '@mcp-z/oauth-google';\n\nconst { AuthRequiredBranchSchema } = schemas;\n\nimport { createFieldsSchema, createPaginationSchema, createShapeSchema, filterFields, parseFields, toColumnarFormat } from '@mcp-z/server';\nimport { type CallToolResult, ErrorCode, McpError } from '@modelcontextprotocol/sdk/types.js';\nimport { type drive_v3, google } from 'googleapis';\nimport { z } from 'zod';\nimport { toDriveQuery } from '../../lib/query-builder.ts';\nimport { DRIVE_FILE_COMMON_PATTERNS, DRIVE_FILE_FIELD_DESCRIPTIONS, DRIVE_FILE_FIELDS, type DriveFile, DriveFileSchema, DriveQueryParameterSchema, parseDriveQueryParameter } from '../../schemas/index.ts';\n\nconst inputSchema = z.object({\n query: DriveQueryParameterSchema.describe('Structured Drive query object or JSON string. Use rawDriveQuery for raw Drive syntax.'),\n fields: createFieldsSchema({\n availableFields: DRIVE_FILE_FIELDS,\n fieldDescriptions: DRIVE_FILE_FIELD_DESCRIPTIONS,\n commonPatterns: DRIVE_FILE_COMMON_PATTERNS,\n resourceName: 'Drive file',\n }),\n ...createPaginationSchema({\n defaultPageSize: 50,\n maxPageSize: 1000,\n provider: 'drive',\n }).shape,\n shape: createShapeSchema(),\n});\n\n// Success branch schemas for different shapes\nconst successObjectsBranchSchema = z.object({\n type: z.literal('success'),\n shape: z.literal('objects'),\n items: z.array(DriveFileSchema).describe('Matching Drive files'),\n count: z.number().describe('Number of files in this page'),\n nextPageToken: z.string().optional().describe('Token for fetching next page of results'),\n});\n\nconst successArraysBranchSchema = z.object({\n type: z.literal('success'),\n shape: z.literal('arrays'),\n columns: z.array(z.string()).describe('Column names in canonical order'),\n rows: z.array(z.array(z.unknown())).describe('Row data matching column order'),\n count: z.number().describe('Number of files in this page'),\n nextPageToken: z.string().optional().describe('Token for fetching next page of results'),\n});\n\n// Output schema with auth_required support\n// Using z.union instead of discriminatedUnion since we have two success branches with different shapes\nconst outputSchema = z.union([successObjectsBranchSchema, successArraysBranchSchema, AuthRequiredBranchSchema]);\n\nconst config = {\n title: 'Search Drive Files',\n description: 'Search Google Drive files with flexible field selection for optimal performance.',\n inputSchema: inputSchema,\n outputSchema: z.object({\n result: outputSchema,\n }),\n} as const;\n\nexport type Input = z.infer<typeof inputSchema>;\nexport type Output = z.infer<typeof outputSchema>;\n\n// Type for the raw Google Drive API response\ntype driveFile = drive_v3.Schema$File;\n\ntype driveResponse = drive_v3.Schema$FileList;\n\nasync function handler({ query, pageSize = 50, pageToken, fields, shape = 'arrays' }: Input, extra: EnrichedExtra): Promise<CallToolResult> {\n const logger = extra.logger;\n\n try {\n const parsedQuery = parseDriveQueryParameter(query);\n const requestedFields = parseFields(fields, DRIVE_FILE_FIELDS);\n\n // Validate and clamp pageSize to Google Drive API limits (1-1000)\n const validPageSize = Math.max(1, Math.min(1000, Math.floor(pageSize || 50)));\n\n logger.info('drive.files-search called', {\n query: parsedQuery,\n pageSize: validPageSize,\n pageToken: pageToken ? '[provided]' : undefined,\n fields: fields || 'all',\n });\n\n const drive = google.drive({ version: 'v3', auth: extra.authContext.auth });\n\n // Handle query parameter\n let qStr: string;\n if (parsedQuery && 'rawDriveQuery' in parsedQuery && parsedQuery.rawDriveQuery) {\n // Object with rawDriveQuery field - use it directly\n qStr = parsedQuery.rawDriveQuery;\n } else if (parsedQuery) {\n // Structured query object - convert to Drive query string\n const { q } = toDriveQuery(parsedQuery);\n qStr = q || '';\n } else {\n qStr = '';\n }\n\n const listOptions: {\n q?: string;\n pageSize: number;\n fields: string;\n orderBy: string;\n pageToken?: string;\n } = {\n pageSize: validPageSize,\n fields: 'files(id,name,mimeType,webViewLink,modifiedTime,parents,shared,starred,owners),nextPageToken',\n orderBy: 'modifiedTime desc',\n };\n if (qStr.trim().length > 0) {\n listOptions.q = qStr;\n }\n if (pageToken && pageToken.trim().length > 0) {\n listOptions.pageToken = pageToken;\n }\n\n const response = await drive.files.list(listOptions);\n const res = response.data as driveResponse;\n const files = Array.isArray(res?.files) ? res.files : [];\n\n const parentIds = new Set<string>();\n for (const f of files) {\n if (f?.parents && f.parents.length > 0) {\n for (const parentId of f.parents) {\n if (parentId && parentId !== 'root') {\n parentIds.add(parentId);\n }\n }\n }\n }\n\n const parentNameMap = new Map<string, string>();\n if (parentIds.size > 0) {\n logger.info('Fetching parent names', { count: parentIds.size });\n const parentFetches = Array.from(parentIds).map(async (parentId) => {\n try {\n const parentRes = await drive.files.get({\n fileId: parentId,\n fields: 'id,name',\n });\n const parentName = (parentRes.data.name as string | undefined) || parentId;\n parentNameMap.set(parentId, parentName);\n } catch (e) {\n logger.info('Failed to fetch parent name', { parentId, error: e });\n parentNameMap.set(parentId, parentId); // Fallback to ID\n }\n });\n await Promise.all(parentFetches);\n }\n\n const items: DriveFile[] = files.map((f: driveFile) => {\n const id = f?.id ? String(f.id) : 'unknown';\n const name = f?.name || id;\n const result: DriveFile = { id, name };\n\n // Only include properties that have actual values\n if (f?.mimeType) result.mimeType = f.mimeType;\n if (f?.webViewLink) result.webViewLink = f.webViewLink;\n if (f?.modifiedTime) result.modifiedTime = f.modifiedTime;\n\n if (f?.parents && f.parents.length > 0) {\n result.parents = f.parents.map((parentId) => {\n if (parentId === 'root') {\n return { id: 'root', name: 'My Drive' };\n }\n const parentName = parentNameMap.get(parentId) || parentId;\n return { id: parentId, name: parentName };\n });\n }\n\n if (f?.shared != null) result.shared = f.shared;\n if (f?.starred != null) result.starred = f.starred;\n\n if (f?.owners && f.owners.length > 0) {\n result.owners = f.owners.map((o) => {\n const owner: NonNullable<DriveFile['owners']>[number] = {};\n if (o?.displayName) owner.displayName = o.displayName;\n if (o?.emailAddress) owner.emailAddress = o.emailAddress;\n if (o?.kind) owner.kind = o.kind;\n if (o?.me != null) owner.me = o.me;\n if (o?.permissionId) owner.permissionId = o.permissionId;\n if (o?.photoLink) owner.photoLink = o.photoLink;\n return owner;\n });\n }\n\n return result;\n });\n\n const filteredItems = items.map((item) => filterFields(item, requestedFields));\n\n logger.info('drive.files-search returning', {\n query: parsedQuery,\n pageSize,\n resultCount: filteredItems.length,\n fields: fields || 'all',\n });\n\n const nextPageToken = res.nextPageToken && res.nextPageToken.trim().length > 0 ? res.nextPageToken : undefined;\n\n // Build result based on shape\n const result: Output =\n shape === 'arrays'\n ? {\n type: 'success' as const,\n shape: 'arrays' as const,\n ...toColumnarFormat(filteredItems, requestedFields, DRIVE_FILE_FIELDS),\n count: filteredItems.length,\n ...(nextPageToken && { nextPageToken }),\n }\n : {\n type: 'success' as const,\n shape: 'objects' as const,\n items: filteredItems,\n count: filteredItems.length,\n ...(nextPageToken && { nextPageToken }),\n };\n\n return {\n content: [\n {\n type: 'text' as const,\n text: JSON.stringify(result),\n },\n ],\n structuredContent: { result },\n };\n } catch (error) {\n const message = error instanceof Error ? error.message : String(error);\n logger.error('drive.files-search error', { error: message });\n\n // Throw McpError for all errors so callers can see Drive validation details\n throw new McpError(ErrorCode.InternalError, `Error searching files: ${message}`, {\n stack: error instanceof Error ? error.stack : undefined,\n });\n }\n}\n\nexport default function createTool() {\n return {\n name: 'files-search' as const,\n config,\n handler,\n };\n}\n"],"names":["createTool","AuthRequiredBranchSchema","schemas","inputSchema","z","object","query","DriveQueryParameterSchema","describe","fields","createFieldsSchema","availableFields","DRIVE_FILE_FIELDS","fieldDescriptions","DRIVE_FILE_FIELD_DESCRIPTIONS","commonPatterns","DRIVE_FILE_COMMON_PATTERNS","resourceName","createPaginationSchema","defaultPageSize","maxPageSize","provider","shape","createShapeSchema","successObjectsBranchSchema","type","literal","items","array","DriveFileSchema","count","number","nextPageToken","string","optional","successArraysBranchSchema","columns","rows","unknown","outputSchema","union","config","title","description","result","handler","extra","pageSize","pageToken","logger","parsedQuery","requestedFields","validPageSize","drive","qStr","q","listOptions","response","res","files","parentIds","f","parentId","parentNameMap","parentFetches","filteredItems","error","message","parseDriveQueryParameter","parseFields","Math","max","min","floor","info","undefined","google","version","auth","authContext","rawDriveQuery","toDriveQuery","orderBy","trim","length","list","data","Array","isArray","Set","parents","add","Map","size","from","map","parentRes","parentName","e","get","fileId","name","set","Promise","all","id","String","mimeType","webViewLink","modifiedTime","shared","starred","owners","o","owner","displayName","emailAddress","kind","me","permissionId","photoLink","item","filterFields","resultCount","toColumnarFormat","content","text","JSON","stringify","structuredContent","Error","McpError","ErrorCode","InternalError","stack"],"mappings":";;;;+BA+OA;;;eAAwBA;;;2BA9OA;sBAImG;qBAClE;0BACnB;mBACpB;8BACW;uBACsJ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;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oBAChD;;;;;;;IAEJ;;AAEe,SAAS3E;IACtB,OAAO;QACLqG,MAAM;QACN5D,QAAAA;QACAI,SAAAA;IACF;AACF"}
|
|
1
|
+
{"version":3,"sources":["/Users/kevin/Dev/OpenSource/ai/mcp-z/mcp-drive/src/mcp/tools/files-search.ts"],"sourcesContent":["import type { EnrichedExtra } from '@mcp-z/oauth-google';\nimport { schemas } from '@mcp-z/oauth-google';\n\nconst { AuthRequiredBranchSchema } = schemas;\n\nimport { createFieldsSchema, createPaginationSchema, createShapeSchema, filterFields, parseFields, toColumnarFormat } from '@mcp-z/server';\nimport { type CallToolResult, ErrorCode, McpError } from '@modelcontextprotocol/sdk/types.js';\nimport { type drive_v3, google } from 'googleapis';\nimport { z } from 'zod';\nimport { toDriveQuery } from '../../lib/query-builder.ts';\nimport { DRIVE_FILE_COMMON_PATTERNS, DRIVE_FILE_FIELD_DESCRIPTIONS, DRIVE_FILE_FIELDS, type DriveFile, DriveFileSchema, DriveQueryParameterSchema, parseDriveQueryParameter } from '../../schemas/index.ts';\n\nconst inputSchema = z.object({\n query: DriveQueryParameterSchema.describe('Structured Drive query object or JSON string. Use rawDriveQuery for raw Drive syntax.'),\n fields: createFieldsSchema({\n availableFields: DRIVE_FILE_FIELDS,\n fieldDescriptions: DRIVE_FILE_FIELD_DESCRIPTIONS,\n commonPatterns: DRIVE_FILE_COMMON_PATTERNS,\n resourceName: 'Drive file',\n }),\n ...createPaginationSchema({\n defaultPageSize: 50,\n maxPageSize: 1000,\n provider: 'drive',\n }).shape,\n shape: createShapeSchema(),\n});\n\n// Success branch schemas for different shapes\nconst successObjectsBranchSchema = z.object({\n type: z.literal('success'),\n shape: z.literal('objects'),\n items: z.array(DriveFileSchema).describe('Matching Drive files'),\n count: z.number().describe('Number of files in this page'),\n nextPageToken: z.string().optional().describe('Token for fetching next page of results'),\n});\n\nconst successArraysBranchSchema = z.object({\n type: z.literal('success'),\n shape: z.literal('arrays'),\n columns: z.array(z.string()).describe('Column names in canonical order'),\n rows: z.array(z.array(z.unknown())).describe('Row data matching column order'),\n count: z.number().describe('Number of files in this page'),\n nextPageToken: z.string().optional().describe('Token for fetching next page of results'),\n});\n\n// Output schema with auth_required support\n// Using z.union instead of discriminatedUnion since we have two success branches with different shapes\nconst outputSchema = z.union([successObjectsBranchSchema, successArraysBranchSchema, AuthRequiredBranchSchema]);\n\nconst config = {\n title: 'Search Drive Files',\n description: 'Search Google Drive files with flexible field selection for optimal performance.',\n inputSchema: inputSchema,\n outputSchema: z.object({\n result: outputSchema,\n }),\n} as const;\n\nexport type Input = z.infer<typeof inputSchema>;\nexport type Output = z.infer<typeof outputSchema>;\n\n// Type for the raw Google Drive API response\ntype driveFile = drive_v3.Schema$File;\n\ntype driveResponse = drive_v3.Schema$FileList;\n\nasync function handler({ query, pageSize = 50, pageToken, fields, shape = 'arrays' }: Input, extra: EnrichedExtra): Promise<CallToolResult> {\n const logger = extra.logger;\n\n try {\n const parsedQuery = parseDriveQueryParameter(query);\n const requestedFields = parseFields(fields, DRIVE_FILE_FIELDS);\n\n // Validate and clamp pageSize to Google Drive API limits (1-1000)\n const validPageSize = Math.max(1, Math.min(1000, Math.floor(pageSize || 50)));\n\n logger.info('drive.files-search called', {\n query: parsedQuery,\n pageSize: validPageSize,\n pageToken: pageToken ? '[provided]' : undefined,\n fields: fields || 'all',\n });\n\n const drive = google.drive({ version: 'v3', auth: extra.authContext.auth });\n\n // Handle query parameter\n let qStr: string;\n if (parsedQuery && 'rawDriveQuery' in parsedQuery && parsedQuery.rawDriveQuery) {\n // Object with rawDriveQuery field - use it directly\n qStr = parsedQuery.rawDriveQuery;\n } else if (parsedQuery) {\n // Structured query object - convert to Drive query string\n const { q } = toDriveQuery(parsedQuery);\n qStr = q || '';\n } else {\n qStr = '';\n }\n\n const listOptions: {\n q?: string;\n pageSize: number;\n fields: string;\n orderBy: string;\n pageToken?: string;\n } = {\n pageSize: validPageSize,\n fields: 'files(id,name,mimeType,webViewLink,modifiedTime,parents,shared,starred,owners),nextPageToken',\n orderBy: 'modifiedTime desc',\n };\n if (qStr.trim().length > 0) {\n listOptions.q = qStr;\n }\n if (pageToken && pageToken.trim().length > 0) {\n listOptions.pageToken = pageToken;\n }\n\n const response = await drive.files.list(listOptions);\n const res = response.data as driveResponse;\n const files = Array.isArray(res?.files) ? res.files : [];\n\n const parentIds = new Set<string>();\n for (const f of files) {\n if (f?.parents && f.parents.length > 0) {\n for (const parentId of f.parents) {\n if (parentId && parentId !== 'root') {\n parentIds.add(parentId);\n }\n }\n }\n }\n\n const parentNameMap = new Map<string, string>();\n if (parentIds.size > 0) {\n logger.info('Fetching parent names', { count: parentIds.size });\n const parentFetches = Array.from(parentIds).map(async (parentId) => {\n try {\n const parentRes = await drive.files.get({\n fileId: parentId,\n fields: 'id,name',\n });\n const parentName = (parentRes.data.name as string | undefined) || parentId;\n parentNameMap.set(parentId, parentName);\n } catch (e) {\n logger.info('Failed to fetch parent name', { parentId, error: e });\n parentNameMap.set(parentId, parentId); // Fallback to ID\n }\n });\n await Promise.all(parentFetches);\n }\n\n const items: DriveFile[] = files.map((f: driveFile) => {\n const id = f?.id ? String(f.id) : 'unknown';\n const name = f?.name || id;\n const result: DriveFile = { id, name };\n\n // Only include properties that have actual values\n if (f?.mimeType) result.mimeType = f.mimeType;\n if (f?.webViewLink) result.webViewLink = f.webViewLink;\n if (f?.modifiedTime) result.modifiedTime = f.modifiedTime;\n\n if (f?.parents && f.parents.length > 0) {\n result.parents = f.parents.map((parentId) => {\n if (parentId === 'root') {\n return { id: 'root', name: 'My Drive' };\n }\n const parentName = parentNameMap.get(parentId) || parentId;\n return { id: parentId, name: parentName };\n });\n }\n\n if (f?.shared != null) result.shared = f.shared;\n if (f?.starred != null) result.starred = f.starred;\n\n if (f?.owners && f.owners.length > 0) {\n result.owners = f.owners.map((o) => {\n const owner: NonNullable<DriveFile['owners']>[number] = {};\n if (o?.displayName) owner.displayName = o.displayName;\n if (o?.emailAddress) owner.emailAddress = o.emailAddress;\n if (o?.kind) owner.kind = o.kind;\n if (o?.me != null) owner.me = o.me;\n if (o?.permissionId) owner.permissionId = o.permissionId;\n if (o?.photoLink) owner.photoLink = o.photoLink;\n return owner;\n });\n }\n\n return result;\n });\n\n const filteredItems = items.map((item) => filterFields(item, requestedFields));\n\n logger.info('drive.files-search returning', {\n query: parsedQuery,\n pageSize,\n resultCount: filteredItems.length,\n fields: fields || 'all',\n });\n\n const nextPageToken = res.nextPageToken && res.nextPageToken.trim().length > 0 ? res.nextPageToken : undefined;\n\n // Build result based on shape\n const result: Output =\n shape === 'arrays'\n ? {\n type: 'success' as const,\n shape: 'arrays' as const,\n ...toColumnarFormat(filteredItems, requestedFields, DRIVE_FILE_FIELDS),\n count: filteredItems.length,\n ...(nextPageToken && { nextPageToken }),\n }\n : {\n type: 'success' as const,\n shape: 'objects' as const,\n items: filteredItems,\n count: filteredItems.length,\n ...(nextPageToken && { nextPageToken }),\n };\n\n return {\n content: [\n {\n type: 'text' as const,\n text: JSON.stringify(result),\n },\n ],\n structuredContent: { result },\n };\n } catch (error) {\n const message = error instanceof Error ? error.message : String(error);\n logger.error('drive.files-search error', { error: message });\n\n // Throw McpError for all errors so callers can see Drive validation details\n throw new McpError(ErrorCode.InternalError, `Error searching files: ${message}`, {\n stack: error instanceof Error ? error.stack : undefined,\n });\n }\n}\n\nexport default function createTool() {\n return {\n name: 'files-search' as const,\n config,\n handler,\n };\n}\n"],"names":["createTool","AuthRequiredBranchSchema","schemas","inputSchema","z","object","query","DriveQueryParameterSchema","describe","fields","createFieldsSchema","availableFields","DRIVE_FILE_FIELDS","fieldDescriptions","DRIVE_FILE_FIELD_DESCRIPTIONS","commonPatterns","DRIVE_FILE_COMMON_PATTERNS","resourceName","createPaginationSchema","defaultPageSize","maxPageSize","provider","shape","createShapeSchema","successObjectsBranchSchema","type","literal","items","array","DriveFileSchema","count","number","nextPageToken","string","optional","successArraysBranchSchema","columns","rows","unknown","outputSchema","union","config","title","description","result","handler","extra","pageSize","pageToken","logger","parsedQuery","requestedFields","validPageSize","drive","qStr","q","listOptions","response","res","files","parentIds","f","parentId","parentNameMap","parentFetches","filteredItems","error","message","parseDriveQueryParameter","parseFields","Math","max","min","floor","info","undefined","google","version","auth","authContext","rawDriveQuery","toDriveQuery","orderBy","trim","length","list","data","Array","isArray","Set","parents","add","Map","size","from","map","parentRes","parentName","e","get","fileId","name","set","Promise","all","id","String","mimeType","webViewLink","modifiedTime","shared","starred","owners","o","owner","displayName","emailAddress","kind","me","permissionId","photoLink","item","filterFields","resultCount","toColumnarFormat","content","text","JSON","stringify","structuredContent","Error","McpError","ErrorCode","InternalError","stack"],"mappings":";;;;+BA+OA;;;eAAwBA;;;2BA9OA;sBAImG;qBAClE;0BACnB;mBACpB;8BACW;uBACsJ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAPnL,IAAM,AAAEC,2BAA6BC,oBAAO,CAApCD;AASR,IAAME,cAAcC,MAAC,CAACC,MAAM,CAAC;IAC3BC,OAAOC,kCAAyB,CAACC,QAAQ,CAAC;IAC1CC,QAAQC,IAAAA,0BAAkB,EAAC;QACzBC,iBAAiBC,0BAAiB;QAClCC,mBAAmBC,sCAA6B;QAChDC,gBAAgBC,mCAA0B;QAC1CC,cAAc;IAChB;GACGC,IAAAA,8BAAsB,EAAC;IACxBC,iBAAiB;IACjBC,aAAa;IACbC,UAAU;AACZ,GAAGC,KAAK;IACRA,OAAOC,IAAAA,yBAAiB;;AAG1B,8CAA8C;AAC9C,IAAMC,6BAA6BpB,MAAC,CAACC,MAAM,CAAC;IAC1CoB,MAAMrB,MAAC,CAACsB,OAAO,CAAC;IAChBJ,OAAOlB,MAAC,CAACsB,OAAO,CAAC;IACjBC,OAAOv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iBvC,0BAAiB;wBACrEkB,OAAOmC,cAAcmB,MAAM;wBACvBpD,iBAAiB;wBAAEA,eAAAA;oBAAc,KAEvC;wBACEP,MAAM;wBACNH,OAAO;wBACPK,OAAOsC;wBACPnC,OAAOmC,cAAcmB,MAAM;uBACvBpD,iBAAiB;wBAAEA,eAAAA;oBAAc;oBAG7C;;wBAAO;4BACL6F,OAAO;gCACL;oCACEpG,MAAM;oCACNqG,MAAMC,KAAKC,SAAS,CAACpF;gCACvB;;4BAEFqF,mBAAmB;gCAAErF,QAAAA;4BAAO;wBAC9B;;;oBACOsB;oBACDC,UAAUD,AAAK,YAALA,OAAiBgE,SAAQhE,MAAMC,OAAO,GAAGuC,OAAOxC;oBAChEjB,OAAOiB,KAAK,CAAC,4BAA4B;wBAAEA,OAAOC;oBAAQ;oBAE1D,4EAA4E;oBAC5E,MAAM,IAAIgE,eAAQ,CAACC,gBAAS,CAACC,aAAa,EAAE,AAAC,0BAAiC,OAARlE,UAAW;wBAC/EmE,OAAOpE,AAAK,YAALA,OAAiBgE,SAAQhE,MAAMoE,KAAK,GAAG3D;oBAChD;;;;;;;IAEJ;;AAEe,SAAS3E;IACtB,OAAO;QACLqG,MAAM;QACN5D,QAAAA;QACAI,SAAAA;IACF;AACF"}
|
|
@@ -22,11 +22,8 @@ function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) {
|
|
|
22
22
|
reject(error);
|
|
23
23
|
return;
|
|
24
24
|
}
|
|
25
|
-
if (info.done)
|
|
26
|
-
|
|
27
|
-
} else {
|
|
28
|
-
Promise.resolve(value).then(_next, _throw);
|
|
29
|
-
}
|
|
25
|
+
if (info.done) resolve(value);
|
|
26
|
+
else Promise.resolve(value).then(_next, _throw);
|
|
30
27
|
}
|
|
31
28
|
function _async_to_generator(fn) {
|
|
32
29
|
return function() {
|
|
@@ -51,17 +48,14 @@ function _define_property(obj, key, value) {
|
|
|
51
48
|
configurable: true,
|
|
52
49
|
writable: true
|
|
53
50
|
});
|
|
54
|
-
} else
|
|
55
|
-
obj[key] = value;
|
|
56
|
-
}
|
|
51
|
+
} else obj[key] = value;
|
|
57
52
|
return obj;
|
|
58
53
|
}
|
|
59
54
|
function _instanceof(left, right) {
|
|
55
|
+
"@swc/helpers - instanceof";
|
|
60
56
|
if (right != null && typeof Symbol !== "undefined" && right[Symbol.hasInstance]) {
|
|
61
57
|
return !!right[Symbol.hasInstance](left);
|
|
62
|
-
} else
|
|
63
|
-
return left instanceof right;
|
|
64
|
-
}
|
|
58
|
+
} else return left instanceof right;
|
|
65
59
|
}
|
|
66
60
|
function _object_spread(target) {
|
|
67
61
|
for(var i = 1; i < arguments.length; i++){
|
|
@@ -93,9 +87,8 @@ function ownKeys(object, enumerableOnly) {
|
|
|
93
87
|
}
|
|
94
88
|
function _object_spread_props(target, source) {
|
|
95
89
|
source = source != null ? source : {};
|
|
96
|
-
if (Object.getOwnPropertyDescriptors)
|
|
97
|
-
|
|
98
|
-
} else {
|
|
90
|
+
if (Object.getOwnPropertyDescriptors) Object.defineProperties(target, Object.getOwnPropertyDescriptors(source));
|
|
91
|
+
else {
|
|
99
92
|
ownKeys(Object(source)).forEach(function(key) {
|
|
100
93
|
Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key));
|
|
101
94
|
});
|