@mcp-z/mcp-drive 1.1.3 → 2.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/index.js.map +1 -1
- package/dist/cjs/mcp/prompts/query-syntax.d.cts +2 -3
- package/dist/cjs/mcp/prompts/query-syntax.d.ts +2 -3
- package/dist/cjs/mcp/prompts/query-syntax.js.map +1 -1
- package/dist/cjs/mcp/resources/file.d.cts +2 -9
- package/dist/cjs/mcp/resources/file.d.ts +2 -9
- package/dist/cjs/mcp/resources/file.js +2 -2
- package/dist/cjs/mcp/resources/file.js.map +1 -1
- package/dist/cjs/mcp/tools/file-move-to-trash.d.cts +1 -1
- package/dist/cjs/mcp/tools/file-move-to-trash.d.ts +1 -1
- package/dist/cjs/mcp/tools/file-move-to-trash.js +3 -3
- package/dist/cjs/mcp/tools/file-move-to-trash.js.map +1 -1
- package/dist/cjs/mcp/tools/file-move.d.cts +1 -1
- package/dist/cjs/mcp/tools/file-move.d.ts +1 -1
- package/dist/cjs/mcp/tools/file-move.js +3 -3
- package/dist/cjs/mcp/tools/file-move.js.map +1 -1
- package/dist/cjs/mcp/tools/file-upload.d.cts +1 -1
- package/dist/cjs/mcp/tools/file-upload.d.ts +1 -1
- package/dist/cjs/mcp/tools/file-upload.js +3 -3
- package/dist/cjs/mcp/tools/file-upload.js.map +1 -1
- package/dist/cjs/mcp/tools/files-search.d.cts +1 -1
- package/dist/cjs/mcp/tools/files-search.d.ts +1 -1
- package/dist/cjs/mcp/tools/files-search.js +2 -3
- package/dist/cjs/mcp/tools/files-search.js.map +1 -1
- package/dist/cjs/mcp/tools/folder-contents.d.cts +1 -1
- package/dist/cjs/mcp/tools/folder-contents.d.ts +1 -1
- package/dist/cjs/mcp/tools/folder-contents.js +2 -3
- package/dist/cjs/mcp/tools/folder-contents.js.map +1 -1
- package/dist/cjs/mcp/tools/folder-create.d.cts +1 -1
- package/dist/cjs/mcp/tools/folder-create.d.ts +1 -1
- package/dist/cjs/mcp/tools/folder-create.js +3 -3
- package/dist/cjs/mcp/tools/folder-create.js.map +1 -1
- package/dist/cjs/mcp/tools/folder-path.d.cts +1 -1
- package/dist/cjs/mcp/tools/folder-path.d.ts +1 -1
- package/dist/cjs/mcp/tools/folder-path.js +3 -3
- package/dist/cjs/mcp/tools/folder-path.js.map +1 -1
- package/dist/cjs/mcp/tools/folder-search.d.cts +1 -1
- package/dist/cjs/mcp/tools/folder-search.d.ts +1 -1
- package/dist/cjs/mcp/tools/folder-search.js +2 -3
- package/dist/cjs/mcp/tools/folder-search.js.map +1 -1
- package/dist/cjs/setup/http.d.cts +1 -1
- package/dist/cjs/setup/http.d.ts +1 -1
- package/dist/cjs/setup/http.js +1 -2
- package/dist/cjs/setup/http.js.map +1 -1
- package/dist/cjs/setup/stdio.d.cts +1 -1
- package/dist/cjs/setup/stdio.d.ts +1 -1
- package/dist/cjs/setup/stdio.js +1 -2
- package/dist/cjs/setup/stdio.js.map +1 -1
- package/dist/esm/index.js +1 -1
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/mcp/prompts/query-syntax.d.ts +2 -3
- package/dist/esm/mcp/prompts/query-syntax.js.map +1 -1
- package/dist/esm/mcp/resources/file.d.ts +2 -9
- package/dist/esm/mcp/resources/file.js +1 -1
- package/dist/esm/mcp/resources/file.js.map +1 -1
- package/dist/esm/mcp/tools/file-move-to-trash.d.ts +1 -1
- package/dist/esm/mcp/tools/file-move-to-trash.js +3 -3
- package/dist/esm/mcp/tools/file-move-to-trash.js.map +1 -1
- package/dist/esm/mcp/tools/file-move.d.ts +1 -1
- package/dist/esm/mcp/tools/file-move.js +3 -3
- package/dist/esm/mcp/tools/file-move.js.map +1 -1
- package/dist/esm/mcp/tools/file-upload.d.ts +1 -1
- package/dist/esm/mcp/tools/file-upload.js +3 -3
- package/dist/esm/mcp/tools/file-upload.js.map +1 -1
- package/dist/esm/mcp/tools/files-search.d.ts +1 -1
- package/dist/esm/mcp/tools/files-search.js +3 -4
- package/dist/esm/mcp/tools/files-search.js.map +1 -1
- package/dist/esm/mcp/tools/folder-contents.d.ts +1 -1
- package/dist/esm/mcp/tools/folder-contents.js +3 -4
- package/dist/esm/mcp/tools/folder-contents.js.map +1 -1
- package/dist/esm/mcp/tools/folder-create.d.ts +1 -1
- package/dist/esm/mcp/tools/folder-create.js +3 -3
- package/dist/esm/mcp/tools/folder-create.js.map +1 -1
- package/dist/esm/mcp/tools/folder-path.d.ts +1 -1
- package/dist/esm/mcp/tools/folder-path.js +3 -3
- package/dist/esm/mcp/tools/folder-path.js.map +1 -1
- package/dist/esm/mcp/tools/folder-search.d.ts +1 -1
- package/dist/esm/mcp/tools/folder-search.js +3 -4
- package/dist/esm/mcp/tools/folder-search.js.map +1 -1
- package/dist/esm/setup/http.d.ts +1 -1
- package/dist/esm/setup/http.js +1 -2
- package/dist/esm/setup/http.js.map +1 -1
- package/dist/esm/setup/stdio.d.ts +1 -1
- package/dist/esm/setup/stdio.js +1 -2
- package/dist/esm/setup/stdio.js.map +1 -1
- package/package.json +7 -7
package/dist/cjs/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["/Users/kevin/Dev/OpenSource/ai/mcp-z/mcp-drive/src/index.ts"],"sourcesContent":["import { handleVersionHelp } from './setup/version-help.ts';\nimport type { ServerConfig } from './types.ts';\n\nexport { GOOGLE_SCOPE } from './constants.ts';\nexport * as mcp from './mcp/index.ts';\nexport * as schemas from './schemas/index.ts';\nexport * as setup from './setup/index.ts';\nexport * from './types.ts';\n\nexport async function startServer(config: ServerConfig): Promise<void> {\n // createHTTPServer/createStdioServer pull in @
|
|
1
|
+
{"version":3,"sources":["/Users/kevin/Dev/OpenSource/ai/mcp-z/mcp-drive/src/index.ts"],"sourcesContent":["import { handleVersionHelp } from './setup/version-help.ts';\nimport type { ServerConfig } from './types.ts';\n\nexport { GOOGLE_SCOPE } from './constants.ts';\nexport * as mcp from './mcp/index.ts';\nexport * as schemas from './schemas/index.ts';\nexport * as setup from './setup/index.ts';\nexport * from './types.ts';\n\nexport async function startServer(config: ServerConfig): Promise<void> {\n // createHTTPServer/createStdioServer pull in @mcp-z/server and every mcp/tools/*.ts\n // (googleapis included); deferred so a --version/--help run never reaches them.\n const { createHTTPServer } = await import('./setup/http.ts');\n const { createStdioServer } = await import('./setup/stdio.ts');\n const { logger, close } = config.transport.type === 'stdio' ? await createStdioServer(config) : await createHTTPServer(config);\n\n process.on('SIGINT', async () => {\n await close();\n process.exit(0);\n });\n\n logger.info(`Server started with ${config.transport.type} transport`);\n await new Promise(() => {});\n}\n\nexport default async function main(): Promise<void> {\n // Check for help/version flags FIRST, before config parsing\n const versionHelpResult = handleVersionHelp(process.argv);\n if (versionHelpResult.handled) {\n console.log(versionHelpResult.output);\n process.exit(0);\n }\n\n // Only parse config if no help/version flags. config.ts's own heavy imports (@mcp-z/oauth-google,\n // @mcp-z/server) are deferred internally, so this static-looking call stays cheap until here.\n const { createConfig } = await import('./setup/config.ts');\n const config = createConfig();\n await startServer(config);\n}\n\nif (process.argv[1] === new URL(import.meta.url).pathname) {\n main();\n}\n"],"names":["GOOGLE_SCOPE","main","mcp","schemas","setup","startServer","config","createHTTPServer","createStdioServer","logger","close","transport","type","process","on","exit","info","Promise","versionHelpResult","createConfig","handleVersionHelp","argv","handled","console","log","output","URL","pathname"],"mappings":";;;;;;;;;;;QAGSA;eAAAA,yBAAY;;QAsBrB;eAA8BC;;QArBlBC;;;QACAC;;;QACAC;;;QAGUC;eAAAA;;;6BATY;2BAGL;+DACR;gEACI;gEACF;qBACT;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAEP,SAAeA,YAAYC,MAAoB;;YAG5CC,kBACAC,mBACkBF,MAAlBG,QAAQC;;;;oBAFa;;wBAAM;2EAAA,QAAO;;;;oBAAlCH,mBAAqB,cAArBA;oBACsB;;wBAAM;2EAAA,QAAO;;;;oBAAnCC,oBAAsB,cAAtBA;yBACkBF,CAAAA,OAAOK,SAAS,CAACC,IAAI,KAAK,OAAM,GAAhCN;;;;oBAAoC;;wBAAME,kBAAkBF;;;2BAAxB;;;;;;oBAAkC;;wBAAMC,iBAAiBD;;;2BAAvB;;;oBAAtEA,aAAlBG,SAAkBH,KAAlBG,QAAQC,QAAUJ,KAAVI;oBAEhBG,QAAQC,EAAE,CAAC,UAAU;;;;;wCACnB;;4CAAMJ;;;wCAAN;wCACAG,QAAQE,IAAI,CAAC;;;;;;wBACf;;oBAEAN,OAAOO,IAAI,CAAC,AAAC,uBAA4C,OAAtBV,OAAOK,SAAS,CAACC,IAAI,EAAC;oBACzD;;wBAAM,IAAIK,QAAQ,YAAO;;;oBAAzB;;;;;;IACF;;AAEe,SAAehB;;YAEtBiB,mBAQEC,cACFb;;;;oBAVN,4DAA4D;oBACtDY,oBAAoBE,IAAAA,gCAAiB,EAACP,QAAQQ,IAAI;oBACxD,IAAIH,kBAAkBI,OAAO,EAAE;wBAC7BC,QAAQC,GAAG,CAACN,kBAAkBO,MAAM;wBACpCZ,QAAQE,IAAI,CAAC;oBACf;oBAIyB;;wBAAM;2EAAA,QAAO;;;;oBAA9BI,eAAiB,cAAjBA;oBACFb,SAASa;oBACf;;wBAAMd,YAAYC;;;oBAAlB;;;;;;IACF;;AAEA,IAAIO,QAAQQ,IAAI,CAAC,EAAE,KAAK,IAAIK,IAAI,qDAAiBC,QAAQ,EAAE;IACzD1B;AACF"}
|
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
import type { ServerNotification, ServerRequest } from '@modelcontextprotocol/sdk/types.js';
|
|
1
|
+
import type { ServerContext } from '@mcp-z/server';
|
|
3
2
|
export default function createPrompt(): {
|
|
4
3
|
name: string;
|
|
5
4
|
config: {
|
|
@@ -7,7 +6,7 @@ export default function createPrompt(): {
|
|
|
7
6
|
};
|
|
8
7
|
handler: (_args: {
|
|
9
8
|
[x: string]: unknown;
|
|
10
|
-
}, _extra:
|
|
9
|
+
}, _extra: ServerContext) => Promise<{
|
|
11
10
|
messages: {
|
|
12
11
|
role: "user";
|
|
13
12
|
content: {
|
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
import type { ServerNotification, ServerRequest } from '@modelcontextprotocol/sdk/types.js';
|
|
1
|
+
import type { ServerContext } from '@mcp-z/server';
|
|
3
2
|
export default function createPrompt(): {
|
|
4
3
|
name: string;
|
|
5
4
|
config: {
|
|
@@ -7,7 +6,7 @@ export default function createPrompt(): {
|
|
|
7
6
|
};
|
|
8
7
|
handler: (_args: {
|
|
9
8
|
[x: string]: unknown;
|
|
10
|
-
}, _extra:
|
|
9
|
+
}, _extra: ServerContext) => Promise<{
|
|
11
10
|
messages: {
|
|
12
11
|
role: "user";
|
|
13
12
|
content: {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["/Users/kevin/Dev/OpenSource/ai/mcp-z/mcp-drive/src/mcp/prompts/query-syntax.ts"],"sourcesContent":["import type { PromptModule } from '@mcp-z/server';\
|
|
1
|
+
{"version":3,"sources":["/Users/kevin/Dev/OpenSource/ai/mcp-z/mcp-drive/src/mcp/prompts/query-syntax.ts"],"sourcesContent":["import type { PromptModule, ServerContext } from '@mcp-z/server';\n\nexport default function createPrompt() {\n const config = {\n description: 'Reference guide for Google Drive query syntax',\n };\n\n const handler = async (_args: { [x: string]: unknown }, _extra: ServerContext) => {\n return {\n messages: [\n {\n role: 'user' as const,\n content: {\n type: 'text' as const,\n text: `# Google Drive Query Syntax Reference\n\n## Logical Operators\n- \\`$and\\`: Array of conditions that ALL must match\n- \\`$or\\`: Array of conditions where ANY must match\n- \\`$not\\`: Condition that must NOT match\n\n## File/Folder Fields\n- \\`name\\`: Search by name (partial match, case-insensitive)\n- \\`mimeType\\`: Filter by MIME type\n- \\`fullText\\`: Search file content and metadata\n- \\`parentId\\`: Search within folder (use \"root\" for My Drive)\n- \\`owner\\`: Filter by owner email\n\n## Boolean Flags\n- \\`starred\\`: true/false\n- \\`sharedWithMe\\`: true/false\n- \\`trashed\\`: true/false\n\n## Date Range\n\\`\\`\\`json\n{ \"modifiedTime\": { \"$gte\": \"2024-01-01\", \"$lt\": \"2024-12-31\" } }\n\\`\\`\\`\n\n## Common MIME Types\n- \\`application/vnd.google-apps.folder\\`: Folders\n- \\`application/vnd.google-apps.document\\`: Google Docs\n- \\`application/vnd.google-apps.spreadsheet\\`: Google Sheets\n- \\`application/vnd.google-apps.presentation\\`: Google Slides\n- \\`application/pdf\\`: PDF files\n- \\`image/jpeg\\`, \\`image/png\\`: Images\n\n## Field Operators (for multi-value fields)\n- \\`$any\\`: OR - matches if ANY value matches\n- \\`$all\\`: AND - matches if ALL values match\n- \\`$none\\`: NOT - matches if NONE match\n\n## Escape Hatch\n- \\`rawDriveQuery\\`: Raw Google Drive query syntax\n\n## Example Queries\n\\`\\`\\`json\n// PDFs modified this year\n{ \"mimeType\": \"application/pdf\", \"modifiedTime\": { \"$gte\": \"2024-01-01\" } }\n\n// Starred spreadsheets\n{ \"mimeType\": \"application/vnd.google-apps.spreadsheet\", \"starred\": true }\n\n// Files in specific folder\n{ \"parentId\": \"1abc123xyz\" }\n\n// Search by name\n{ \"name\": \"budget\" }\n\n// Complex: shared PDFs or Docs\n{ \"$or\": [\n { \"mimeType\": \"application/pdf\", \"sharedWithMe\": true },\n { \"mimeType\": \"application/vnd.google-apps.document\", \"sharedWithMe\": true }\n]}\n\\`\\`\\``,\n },\n },\n ],\n };\n };\n\n return {\n name: 'query-syntax',\n config,\n handler,\n } satisfies PromptModule;\n}\n"],"names":["createPrompt","config","description","handler","_args","_extra","messages","role","content","type","text","name"],"mappings":";;;;+BAEA;;;eAAwBA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAT,SAASA;IACtB,IAAMC,SAAS;QACbC,aAAa;IACf;IAEA,IAAMC,UAAU,iBAAOC,OAAiCC;;;gBACtD;;oBAAO;wBACLC,QAAQ;4BACN;gCACEC,MAAM;gCACNC,SAAS;oCACPC,MAAM;oCACNC,MAAM;gCA4DR;4BACF;;oBAEJ;;;QACF;;IAEA,OAAO;QACLC,MAAM;QACNV,QAAAA;QACAE,SAAAA;IACF;AACF"}
|
|
@@ -1,9 +1,2 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
import type { ReadResourceResult, ServerNotification, ServerRequest } from '@modelcontextprotocol/sdk/types.js';
|
|
4
|
-
export default function createResource(): {
|
|
5
|
-
name: string;
|
|
6
|
-
template: ResourceTemplate;
|
|
7
|
-
config: import("@modelcontextprotocol/sdk/server/mcp.js").ResourceMetadata;
|
|
8
|
-
handler: (uri: URL, variables: Record<string, string | string[]>, extra: RequestHandlerExtra<ServerRequest, ServerNotification>) => Promise<ReadResourceResult>;
|
|
9
|
-
};
|
|
1
|
+
import type { ResourceModule } from '@mcp-z/server';
|
|
2
|
+
export default function createResource(): ResourceModule;
|
|
@@ -1,9 +1,2 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
import type { ReadResourceResult, ServerNotification, ServerRequest } from '@modelcontextprotocol/sdk/types.js';
|
|
4
|
-
export default function createResource(): {
|
|
5
|
-
name: string;
|
|
6
|
-
template: ResourceTemplate;
|
|
7
|
-
config: import("@modelcontextprotocol/sdk/server/mcp.js").ResourceMetadata;
|
|
8
|
-
handler: (uri: URL, variables: Record<string, string | string[]>, extra: RequestHandlerExtra<ServerRequest, ServerNotification>) => Promise<ReadResourceResult>;
|
|
9
|
-
};
|
|
1
|
+
import type { ResourceModule } from '@mcp-z/server';
|
|
2
|
+
export default function createResource(): ResourceModule;
|
|
@@ -8,7 +8,7 @@ Object.defineProperty(exports, "default", {
|
|
|
8
8
|
return createResource;
|
|
9
9
|
}
|
|
10
10
|
});
|
|
11
|
-
var
|
|
11
|
+
var _server = require("@mcp-z/server");
|
|
12
12
|
var _googleapis = require("googleapis");
|
|
13
13
|
function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) {
|
|
14
14
|
try {
|
|
@@ -136,7 +136,7 @@ function _ts_generator(thisArg, body) {
|
|
|
136
136
|
}
|
|
137
137
|
}
|
|
138
138
|
function createResource() {
|
|
139
|
-
var template = new
|
|
139
|
+
var template = new _server.ResourceTemplate('drive://files/{fileId}', {
|
|
140
140
|
list: undefined
|
|
141
141
|
});
|
|
142
142
|
var config = {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["/Users/kevin/Dev/OpenSource/ai/mcp-z/mcp-drive/src/mcp/resources/file.ts"],"sourcesContent":["import type { EnrichedExtra } from '@mcp-z/oauth-google';\nimport type { ResourceConfig, ResourceModule } from '@mcp-z/server';\nimport { ResourceTemplate } from '@
|
|
1
|
+
{"version":3,"sources":["/Users/kevin/Dev/OpenSource/ai/mcp-z/mcp-drive/src/mcp/resources/file.ts"],"sourcesContent":["import type { EnrichedExtra } from '@mcp-z/oauth-google';\nimport type { ReadResourceResult, ResourceConfig, ResourceModule, ServerContext } from '@mcp-z/server';\nimport { ResourceTemplate } from '@mcp-z/server';\nimport { google } from 'googleapis';\n\nexport default function createResource(): ResourceModule {\n const template = new ResourceTemplate('drive://files/{fileId}', {\n list: undefined,\n });\n const config: ResourceConfig = {\n description: 'Drive file resource',\n mimeType: 'application/json',\n };\n\n const handler = async (uri: URL, variables: Record<string, string | string[]>, extra: ServerContext): Promise<ReadResourceResult> => {\n // Extract fileId and handle both string and string[] cases\n const fileId = Array.isArray(variables.fileId) ? variables.fileId[0] : variables.fileId;\n\n try {\n // Validate fileId exists and is a string\n if (!fileId || typeof fileId !== 'string') {\n return {\n contents: [\n {\n uri: uri.href,\n mimeType: 'application/json',\n text: JSON.stringify({\n error: 'Missing or invalid fileId in resource URI',\n }),\n },\n ],\n };\n }\n\n // Safe type guard to access middleware-enriched extra\n const { logger, authContext } = extra as unknown as EnrichedExtra;\n const drive = google.drive({ version: 'v3', auth: authContext.auth });\n const resp = await drive.files.get({\n fileId,\n fields: 'id,name,mimeType,size,modifiedTime,owners,webViewLink',\n });\n const data = resp.data;\n logger.debug?.({ fileId, fileName: data?.name }, 'drive-file resource fetch success');\n return {\n contents: [\n {\n uri: uri.href,\n mimeType: 'application/json',\n text: JSON.stringify(data || {}),\n },\n ],\n };\n } catch (error) {\n const { logger } = extra as unknown as EnrichedExtra;\n logger.debug?.(error as Record<string, unknown>, 'drive resource fetch failed');\n return {\n contents: [\n {\n uri: uri.href,\n mimeType: 'application/json',\n text: JSON.stringify({ error: (error as Error).message }),\n },\n ],\n };\n }\n };\n\n return {\n name: 'file',\n template,\n config,\n handler,\n } satisfies ResourceModule;\n}\n"],"names":["createResource","template","ResourceTemplate","list","undefined","config","description","mimeType","handler","uri","variables","extra","fileId","logger","authContext","drive","resp","data","error","Array","isArray","contents","href","text","JSON","stringify","google","version","auth","files","get","fields","debug","fileName","name","message"],"mappings":";;;;+BAKA;;;eAAwBA;;;sBAHS;0BACV;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAER,SAASA;IACtB,IAAMC,WAAW,IAAIC,wBAAgB,CAAC,0BAA0B;QAC9DC,MAAMC;IACR;IACA,IAAMC,SAAyB;QAC7BC,aAAa;QACbC,UAAU;IACZ;IAEA,IAAMC,UAAU,iBAAOC,KAAUC,WAA8CC;;gBAEvEC,QA0BJC,eAPQA,QAAQC,aACVC,OACAC,MAIAC,MAWCC,OAEPL,gBADQA;;;;wBAtCV,2DAA2D;wBACrDD,SAASO,MAAMC,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,SAAAA;IACF;AACF"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { EnrichedExtra } from '@mcp-z/oauth-google';
|
|
2
|
-
import { type CallToolResult } from '@
|
|
2
|
+
import { type CallToolResult } from '@mcp-z/server';
|
|
3
3
|
import { z } from 'zod';
|
|
4
4
|
declare const inputSchema: z.ZodObject<{
|
|
5
5
|
ids: z.ZodArray<z.ZodString>;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { EnrichedExtra } from '@mcp-z/oauth-google';
|
|
2
|
-
import { type CallToolResult } from '@
|
|
2
|
+
import { type CallToolResult } from '@mcp-z/server';
|
|
3
3
|
import { z } from 'zod';
|
|
4
4
|
declare const inputSchema: z.ZodObject<{
|
|
5
5
|
ids: z.ZodArray<z.ZodString>;
|
|
@@ -9,7 +9,7 @@ Object.defineProperty(exports, "default", {
|
|
|
9
9
|
}
|
|
10
10
|
});
|
|
11
11
|
var _oauthgoogle = require("@mcp-z/oauth-google");
|
|
12
|
-
var
|
|
12
|
+
var _server = require("@mcp-z/server");
|
|
13
13
|
var _googleapis = require("googleapis");
|
|
14
14
|
var _zod = require("zod");
|
|
15
15
|
function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) {
|
|
@@ -306,8 +306,8 @@ function handler(_0, _1) {
|
|
|
306
306
|
logger.error('drive.file.moveToTrash error', {
|
|
307
307
|
error: message
|
|
308
308
|
});
|
|
309
|
-
// Throw
|
|
310
|
-
throw new
|
|
309
|
+
// Throw ProtocolError
|
|
310
|
+
throw new _server.ProtocolError(_server.ProtocolErrorCode.InternalError, "Error moving files to trash: ".concat(message), {
|
|
311
311
|
stack: _instanceof(error, Error) ? error.stack : undefined
|
|
312
312
|
});
|
|
313
313
|
case 4:
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["/Users/kevin/Dev/OpenSource/ai/mcp-z/mcp-drive/src/mcp/tools/file-move-to-trash.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,
|
|
1
|
+
{"version":3,"sources":["/Users/kevin/Dev/OpenSource/ai/mcp-z/mcp-drive/src/mcp/tools/file-move-to-trash.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, ProtocolError, ProtocolErrorCode } from '@mcp-z/server';\nimport { google } from 'googleapis';\nimport { z } from 'zod';\n\nconst MAX_BATCH_SIZE = 1000;\n\nconst inputSchema = z.object({\n ids: z.array(z.string().min(1)).min(1).max(MAX_BATCH_SIZE).describe('File IDs to soft delete (move to trash)'),\n});\n\n// Success branch schema\nconst successBranchSchema = z.object({\n type: z.literal('success'),\n operationSummary: z.string().describe('Human-readable summary of the operation'),\n totalCount: z.number().describe('Total number of files requested to trash'),\n successCount: z.number().describe('Number of files successfully moved to trash'),\n failureCount: z.number().describe('Number of files that failed to move'),\n recoverable: z.boolean().describe('Whether trashed files can be restored'),\n recoverableDays: z.number().describe('Days until permanent deletion'),\n failures: z\n .array(\n z.object({\n id: z.string().describe('ID of the file that failed'),\n error: z.string().describe('Error message explaining the failure'),\n })\n )\n .optional()\n .describe('Details of any files that failed to trash'),\n});\n\n// Output schema with auth_required support\nconst outputSchema = z.discriminatedUnion('type', [successBranchSchema, AuthRequiredBranchSchema]);\n\nconst config = {\n title: 'Move Files to Trash',\n description: 'Move files to trash (recoverable for 30 days).',\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\nasync function handler({ ids }: Input, extra: EnrichedExtra): Promise<CallToolResult> {\n const logger = extra.logger;\n logger.info('drive.file.moveToTrash called', { count: ids.length });\n\n try {\n const drive = google.drive({ version: 'v3', auth: extra.authContext.auth });\n\n const results = await Promise.allSettled(\n ids.map(async (id) => {\n await drive.files.update({\n fileId: id,\n requestBody: { trashed: true },\n });\n return id;\n })\n );\n\n // Separate successes and failures\n const failures: Array<{ id: string; error: string }> = [];\n\n results.forEach((result, index) => {\n const id = ids[index];\n if (!id) return;\n\n if (result.status === 'rejected') {\n const errorMessage = result.reason instanceof Error ? result.reason.message : String(result.reason);\n failures.push({ id, error: errorMessage });\n }\n });\n\n const successCount = ids.length - failures.length;\n const failureCount = failures.length;\n const totalCount = ids.length;\n\n logger.info('drive.file.moveToTrash completed', {\n totalCount,\n successCount,\n failureCount,\n });\n\n const operationSummary = failureCount === 0 ? `Moved ${successCount} file${successCount === 1 ? '' : 's'} to trash (recoverable for 30 days)` : `Moved ${successCount} of ${totalCount} file${totalCount === 1 ? '' : 's'} to trash (${failureCount} failed, recoverable for 30 days)`;\n\n const result: Output = {\n type: 'success' as const,\n operationSummary,\n totalCount,\n successCount,\n failureCount,\n recoverable: true,\n recoverableDays: 30,\n ...(failures.length > 0 && { failures }),\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.moveToTrash error', { error: message });\n\n // Throw ProtocolError\n throw new ProtocolError(ProtocolErrorCode.InternalError, `Error moving files to trash: ${message}`, {\n stack: error instanceof Error ? error.stack : undefined,\n });\n }\n}\n\nexport default function createTool() {\n return {\n name: 'file-move-to-trash' as const,\n config,\n handler,\n };\n}\n"],"names":["createTool","AuthRequiredBranchSchema","schemas","MAX_BATCH_SIZE","inputSchema","z","object","ids","array","string","min","max","describe","successBranchSchema","type","literal","operationSummary","totalCount","number","successCount","failureCount","recoverable","boolean","recoverableDays","failures","id","error","optional","outputSchema","discriminatedUnion","config","title","description","result","handler","extra","logger","drive","results","message","info","count","length","google","version","auth","authContext","Promise","allSettled","map","files","update","fileId","requestBody","trashed","forEach","index","status","errorMessage","reason","Error","String","push","content","text","JSON","stringify","structuredContent","ProtocolError","ProtocolErrorCode","InternalError","stack","undefined","name"],"mappings":";;;;+BA2HA;;;eAAwBA;;;2BA1HA;sBAI8C;0BAC/C;mBACL;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAJlB,IAAM,AAAEC,2BAA6BC,oBAAO,CAApCD;AAMR,IAAME,iBAAiB;AAEvB,IAAMC,cAAcC,MAAC,CAACC,MAAM,CAAC;IAC3BC,KAAKF,MAAC,CAACG,KAAK,CAACH,MAAC,CAACI,MAAM,GAAGC,GAAG,CAAC,IAAIA,GAAG,CAAC,GAAGC,GAAG,CAACR,gBAAgBS,QAAQ,CAAC;AACtE;AAEA,wBAAwB;AACxB,IAAMC,sBAAsBR,MAAC,CAACC,MAAM,CAAC;IACnCQ,MAAMT,MAAC,CAACU,OAAO,CAAC;IAChBC,kBAAkBX,MAAC,CAACI,MAAM,GAAGG,QAAQ,CAAC;IACtCK,YAAYZ,MAAC,CAACa,MAAM,GAAGN,QAAQ,CAAC;IAChCO,cAAcd,MAAC,CAACa,MAAM,GAAGN,QAAQ,CAAC;IAClCQ,cAAcf,MAAC,CAACa,MAAM,GAAGN,QAAQ,CAAC;IAClCS,aAAahB,MAAC,CAACiB,OAAO,GAAGV,QAAQ,CAAC;IAClCW,iBAAiBlB,MAAC,CAACa,MAAM,GAAGN,QAAQ,CAAC;IACrCY,UAAUnB,MAAC,CACRG,KAAK,CACJH,MAAC,CAACC,MAAM,CAAC;QACPmB,IAAIpB,MAAC,CAACI,MAAM,GAAGG,QAAQ,CAAC;QACxBc,OAAOrB,MAAC,CAACI,MAAM,GAAGG,QAAQ,CAAC;IAC7B,IAEDe,QAAQ,GACRf,QAAQ,CAAC;AACd;AAEA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-google';
|
|
2
|
-
import { type CallToolResult } from '@
|
|
2
|
+
import { type CallToolResult } from '@mcp-z/server';
|
|
3
3
|
import { z } from 'zod';
|
|
4
4
|
declare const inputSchema: z.ZodObject<{
|
|
5
5
|
fileIds: z.ZodUnion<readonly [z.ZodString, z.ZodArray<z.ZodString>]>;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { EnrichedExtra } from '@mcp-z/oauth-google';
|
|
2
|
-
import { type CallToolResult } from '@
|
|
2
|
+
import { type CallToolResult } from '@mcp-z/server';
|
|
3
3
|
import { z } from 'zod';
|
|
4
4
|
declare const inputSchema: z.ZodObject<{
|
|
5
5
|
fileIds: z.ZodUnion<readonly [z.ZodString, z.ZodArray<z.ZodString>]>;
|
|
@@ -9,7 +9,7 @@ Object.defineProperty(exports, "default", {
|
|
|
9
9
|
}
|
|
10
10
|
});
|
|
11
11
|
var _oauthgoogle = require("@mcp-z/oauth-google");
|
|
12
|
-
var
|
|
12
|
+
var _server = require("@mcp-z/server");
|
|
13
13
|
var _googleapis = require("googleapis");
|
|
14
14
|
var _zod = require("zod");
|
|
15
15
|
function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) {
|
|
@@ -584,8 +584,8 @@ function handler(_0, _1) {
|
|
|
584
584
|
logger.error('drive.file.move error', {
|
|
585
585
|
error: message
|
|
586
586
|
});
|
|
587
|
-
// Throw
|
|
588
|
-
throw new
|
|
587
|
+
// Throw ProtocolError
|
|
588
|
+
throw new _server.ProtocolError(_server.ProtocolErrorCode.InternalError, "Error moving files: ".concat(message), {
|
|
589
589
|
stack: _instanceof(error, Error) ? error.stack : undefined
|
|
590
590
|
});
|
|
591
591
|
case 7:
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["/Users/kevin/Dev/OpenSource/ai/mcp-z/mcp-drive/src/mcp/tools/file-move.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, ErrorCode, McpError } from '@modelcontextprotocol/sdk/types.js';\nimport type { drive_v3 } from 'googleapis';\nimport { google } from 'googleapis';\nimport { z } from 'zod';\nimport type { Logger } from '../../types.ts';\n\n// Type guard for Google Drive API errors\ninterface DriveApiError {\n message?: string;\n code?: number | string;\n}\n\nfunction isDriveApiError(error: unknown): error is DriveApiError {\n return typeof error === 'object' && error !== null && ('message' in error || 'code' in error);\n}\n\n// Types for results\ninterface MoveResult {\n fileId: string;\n fileName: string;\n oldParents: string[];\n newParent: string;\n webViewLink?: string;\n}\n\ninterface FailedMove {\n fileId: string;\n error: string;\n code?: string;\n}\n\nconst inputSchema = z.object({\n fileIds: z.union([z.string().min(1), z.array(z.string().min(1)).min(1).max(100)]).describe('File or folder ID(s) to move. Single ID or array (max 100 for batch)'),\n destinationFolderId: z.string().min(1).describe('Destination folder ID (use \"root\" for My Drive root)'),\n returnOldParents: z.boolean().optional().describe('Include old parent IDs in response for manual undo (recommended: true)'),\n});\n\n// Success branch schema\nconst successBranchSchema = z.object({\n type: z.literal('success'),\n moved: z\n .array(\n z.object({\n fileId: z.string().describe('ID of the moved file'),\n fileName: z.string().describe('Name of the moved file'),\n oldParents: z.array(z.string()).describe('Previous parent folder IDs (for undo)'),\n newParent: z.string().describe('New parent folder ID'),\n webViewLink: z.string().optional().describe('URL to view the file'),\n })\n )\n .describe('Successfully moved files'),\n failed: z\n .array(\n z.object({\n fileId: z.string().describe('ID of the file that failed to move'),\n error: z.string().describe('Error message explaining the failure'),\n code: z.string().optional().describe('API error code if available'),\n })\n )\n .optional()\n .describe('Files that failed to move'),\n totalRequested: z.number().describe('Total number of files requested to move'),\n totalMoved: z.number().describe('Number of files successfully moved'),\n totalFailed: z.number().describe('Number of files that failed to move'),\n});\n\n// Output schema with auth_required support\nconst outputSchema = z.discriminatedUnion('type', [successBranchSchema, AuthRequiredBranchSchema]);\n\nconst config = {\n title: 'Move Files',\n description: 'Move files/folders to destination folder. Returns oldParents for undo. Use \"root\" for My Drive root.',\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/**\n * Move a single file to a new parent folder\n */\nasync function moveSingleFile(\n drive: drive_v3.Drive,\n fileId: string,\n destinationFolderId: string,\n returnOldParents: boolean,\n logger: Logger\n): Promise<{\n success: boolean;\n result?: MoveResult;\n error?: FailedMove;\n}> {\n try {\n // Get current file metadata to get old parents\n const fileMetadata = await drive.files.get({\n fileId: fileId,\n fields: 'id,name,parents,webViewLink',\n });\n\n const oldParents = (fileMetadata.data.parents as string[] | undefined) || [];\n const fileName = (fileMetadata.data.name as string | undefined) || fileId;\n const webViewLink = fileMetadata.data.webViewLink as string | undefined;\n\n // Move file using addParents and removeParents\n await drive.files.update({\n fileId: fileId,\n addParents: destinationFolderId,\n removeParents: oldParents.join(','),\n fields: 'id,name,parents,webViewLink',\n });\n\n const result: MoveResult = {\n fileId: fileId,\n fileName: fileName,\n oldParents: returnOldParents ? oldParents : [],\n newParent: destinationFolderId,\n ...(webViewLink && { webViewLink }),\n };\n\n return { success: true, result };\n } catch (e: unknown) {\n const errorMessage = isDriveApiError(e) && e.message ? e.message : 'Unknown error';\n const errorCode = isDriveApiError(e) && e.code ? String(e.code) : undefined;\n logger.info('Failed to move file', { fileId, error: errorMessage });\n return {\n success: false,\n error: {\n fileId: fileId,\n error: errorMessage,\n ...(errorCode && { code: errorCode }),\n },\n };\n }\n}\n\n/**\n * Move multiple files using batch requests\n */\nasync function moveBatchFiles(\n drive: drive_v3.Drive,\n fileIds: string[],\n destinationFolderId: string,\n returnOldParents: boolean,\n _logger: Logger\n): Promise<{\n moved: MoveResult[];\n failed: FailedMove[];\n}> {\n const moved: MoveResult[] = [];\n const failed: FailedMove[] = [];\n\n // First, fetch metadata for all files in batch\n const metadataResults = await Promise.allSettled(\n fileIds.map(async (fileId) => {\n try {\n const response = await drive.files.get({\n fileId: fileId,\n fields: 'id,name,parents,webViewLink',\n });\n const webViewLink = response.data.webViewLink as string | undefined;\n return {\n fileId: fileId,\n name: (response.data.name as string | undefined) || fileId,\n parents: (response.data.parents as string[] | undefined) || [],\n ...(webViewLink && { webViewLink }),\n };\n } catch (e: unknown) {\n const message = isDriveApiError(e) && e.message ? e.message : String(e);\n throw new Error(`Failed to fetch metadata: ${message}`);\n }\n })\n );\n\n // Process metadata results\n const filesToMove: Array<{\n fileId: string;\n name: string;\n parents: string[];\n webViewLink?: string;\n }> = [];\n for (let i = 0; i < metadataResults.length; i++) {\n const result = metadataResults[i];\n if (result && result.status === 'fulfilled') {\n filesToMove.push(result.value);\n } else if (result && result.status === 'rejected') {\n const fileId = fileIds[i];\n if (fileId) {\n const errorCode = result.reason?.code ? String(result.reason.code) : undefined;\n failed.push({\n fileId: fileId,\n error: result.reason?.message || 'Failed to fetch file metadata',\n ...(errorCode && { code: errorCode }),\n });\n }\n }\n }\n\n // Now move files in batch\n const moveResults = await Promise.allSettled(\n filesToMove.map(async (file) => {\n try {\n await drive.files.update({\n fileId: file.fileId,\n addParents: destinationFolderId,\n removeParents: file.parents.join(','),\n fields: 'id',\n });\n return {\n fileId: file.fileId,\n fileName: file.name,\n oldParents: returnOldParents ? file.parents : [],\n newParent: destinationFolderId,\n ...(file.webViewLink && { webViewLink: file.webViewLink }),\n };\n } catch (e: unknown) {\n const message = isDriveApiError(e) && e.message ? e.message : String(e);\n throw new Error(`Failed to move: ${message}`);\n }\n })\n );\n\n // Process move results\n for (let i = 0; i < moveResults.length; i++) {\n const result = moveResults[i];\n if (result && result.status === 'fulfilled') {\n moved.push(result.value);\n } else if (result && result.status === 'rejected') {\n const file = filesToMove[i];\n if (file) {\n const errorCode = result.reason?.code ? String(result.reason.code) : undefined;\n failed.push({\n fileId: file.fileId,\n error: result.reason?.message || 'Failed to move file',\n ...(errorCode && { code: errorCode }),\n });\n }\n }\n }\n\n return { moved, failed };\n}\n\nasync function handler({ fileIds, destinationFolderId, returnOldParents = true }: Input, extra: EnrichedExtra): Promise<CallToolResult> {\n const logger = extra.logger;\n const isBatch = Array.isArray(fileIds);\n const fileIdArray = Array.isArray(fileIds) ? fileIds : [fileIds];\n\n logger.info('drive.file.move called', {\n fileCount: fileIdArray.length,\n isBatch,\n destinationFolderId,\n returnOldParents,\n });\n\n try {\n const drive = google.drive({ version: 'v3', auth: extra.authContext.auth });\n\n let moved: MoveResult[] = [];\n let failed: FailedMove[] = [];\n\n if (isBatch && fileIdArray.length > 1) {\n // Use batch API for multiple files\n const batchResult = await moveBatchFiles(drive, fileIdArray, destinationFolderId, returnOldParents, logger);\n moved = batchResult.moved;\n failed = batchResult.failed;\n } else {\n // Single file operation\n const fileId = fileIdArray[0];\n if (fileId) {\n const singleResult = await moveSingleFile(drive, fileId, destinationFolderId, returnOldParents, logger);\n if (singleResult.success && singleResult.result) {\n moved.push(singleResult.result);\n } else if (singleResult.error) {\n failed.push(singleResult.error);\n }\n }\n }\n\n logger.info('drive.file.move returning', {\n totalRequested: fileIdArray.length,\n totalMoved: moved.length,\n totalFailed: failed.length,\n });\n\n const result: Output = {\n type: 'success' as const,\n moved,\n ...(failed.length > 0 && { failed }),\n totalRequested: fileIdArray.length,\n totalMoved: moved.length,\n totalFailed: failed.length,\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.move error', { error: message });\n\n // Throw McpError\n throw new McpError(ErrorCode.InternalError, `Error moving files: ${message}`, {\n stack: error instanceof Error ? error.stack : undefined,\n });\n }\n}\n\nexport default function createTool() {\n return {\n name: 'file-move' as const,\n config,\n handler,\n };\n}\n"],"names":["createTool","AuthRequiredBranchSchema","schemas","isDriveApiError","error","inputSchema","z","object","fileIds","union","string","min","array","max","describe","destinationFolderId","returnOldParents","boolean","optional","successBranchSchema","type","literal","moved","fileId","fileName","oldParents","newParent","webViewLink","failed","code","totalRequested","number","totalMoved","totalFailed","outputSchema","discriminatedUnion","config","title","description","result","moveSingleFile","drive","logger","fileMetadata","e","errorMessage","errorCode","files","get","fields","data","parents","name","update","addParents","removeParents","join","success","message","String","undefined","info","moveBatchFiles","_logger","metadataResults","filesToMove","i","moveResults","file","Promise","allSettled","map","response","Error","length","status","push","value","reason","handler","extra","isBatch","fileIdArray","batchResult","singleResult","Array","isArray","fileCount","google","version","auth","authContext","content","text","JSON","stringify","structuredContent","McpError","ErrorCode","InternalError","stack"],"mappings":";;;;+BAiUA;;;eAAwBA;;;2BAhUA;qBAIiC;0BAElC;mBACL;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AALlB,IAAM,AAAEC,2BAA6BC,oBAAO,CAApCD;AAcR,SAASE,gBAAgBC,KAAc;IACrC,OAAO,CAAA,OAAOA,sCAAP,SAAOA,MAAI,MAAM,YAAYA,UAAU,QAAS,CAAA,aAAaA,SAAS,UAAUA,KAAI;AAC7F;AAiBA,IAAMC,cAAcC,MAAC,CAACC,MAAM,CAAC;IAC3BC,SAASF,MAAC,CAACG,KAAK,CAAC;QAACH,MAAC,CAACI,MAAM,GAAGC,GAAG,CAAC;QAAIL,MAAC,CAACM,KAAK,CAACN,MAAC,CAACI,MAAM,GAAGC,GAAG,CAAC,IAAIA,GAAG,CAAC,GAAGE,GAAG,CAAC;KAAK,EAAEC,QAAQ,CAAC;IAC3FC,qBAAqBT,MAAC,CAACI,MAAM,GAAGC,GAAG,CAAC,GAAGG,QAAQ,CAAC;IAChDE,kBAAkBV,MAAC,CAACW,OAAO,GAAGC,QAAQ,GAAGJ,QAAQ,CAAC;AACpD;AAEA,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
+
{"version":3,"sources":["/Users/kevin/Dev/OpenSource/ai/mcp-z/mcp-drive/src/mcp/tools/file-move.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, ProtocolError, ProtocolErrorCode } from '@mcp-z/server';\nimport type { drive_v3 } from 'googleapis';\nimport { google } from 'googleapis';\nimport { z } from 'zod';\nimport type { Logger } from '../../types.ts';\n\n// Type guard for Google Drive API errors\ninterface DriveApiError {\n message?: string;\n code?: number | string;\n}\n\nfunction isDriveApiError(error: unknown): error is DriveApiError {\n return typeof error === 'object' && error !== null && ('message' in error || 'code' in error);\n}\n\n// Types for results\ninterface MoveResult {\n fileId: string;\n fileName: string;\n oldParents: string[];\n newParent: string;\n webViewLink?: string;\n}\n\ninterface FailedMove {\n fileId: string;\n error: string;\n code?: string;\n}\n\nconst inputSchema = z.object({\n fileIds: z.union([z.string().min(1), z.array(z.string().min(1)).min(1).max(100)]).describe('File or folder ID(s) to move. Single ID or array (max 100 for batch)'),\n destinationFolderId: z.string().min(1).describe('Destination folder ID (use \"root\" for My Drive root)'),\n returnOldParents: z.boolean().optional().describe('Include old parent IDs in response for manual undo (recommended: true)'),\n});\n\n// Success branch schema\nconst successBranchSchema = z.object({\n type: z.literal('success'),\n moved: z\n .array(\n z.object({\n fileId: z.string().describe('ID of the moved file'),\n fileName: z.string().describe('Name of the moved file'),\n oldParents: z.array(z.string()).describe('Previous parent folder IDs (for undo)'),\n newParent: z.string().describe('New parent folder ID'),\n webViewLink: z.string().optional().describe('URL to view the file'),\n })\n )\n .describe('Successfully moved files'),\n failed: z\n .array(\n z.object({\n fileId: z.string().describe('ID of the file that failed to move'),\n error: z.string().describe('Error message explaining the failure'),\n code: z.string().optional().describe('API error code if available'),\n })\n )\n .optional()\n .describe('Files that failed to move'),\n totalRequested: z.number().describe('Total number of files requested to move'),\n totalMoved: z.number().describe('Number of files successfully moved'),\n totalFailed: z.number().describe('Number of files that failed to move'),\n});\n\n// Output schema with auth_required support\nconst outputSchema = z.discriminatedUnion('type', [successBranchSchema, AuthRequiredBranchSchema]);\n\nconst config = {\n title: 'Move Files',\n description: 'Move files/folders to destination folder. Returns oldParents for undo. Use \"root\" for My Drive root.',\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/**\n * Move a single file to a new parent folder\n */\nasync function moveSingleFile(\n drive: drive_v3.Drive,\n fileId: string,\n destinationFolderId: string,\n returnOldParents: boolean,\n logger: Logger\n): Promise<{\n success: boolean;\n result?: MoveResult;\n error?: FailedMove;\n}> {\n try {\n // Get current file metadata to get old parents\n const fileMetadata = await drive.files.get({\n fileId: fileId,\n fields: 'id,name,parents,webViewLink',\n });\n\n const oldParents = (fileMetadata.data.parents as string[] | undefined) || [];\n const fileName = (fileMetadata.data.name as string | undefined) || fileId;\n const webViewLink = fileMetadata.data.webViewLink as string | undefined;\n\n // Move file using addParents and removeParents\n await drive.files.update({\n fileId: fileId,\n addParents: destinationFolderId,\n removeParents: oldParents.join(','),\n fields: 'id,name,parents,webViewLink',\n });\n\n const result: MoveResult = {\n fileId: fileId,\n fileName: fileName,\n oldParents: returnOldParents ? oldParents : [],\n newParent: destinationFolderId,\n ...(webViewLink && { webViewLink }),\n };\n\n return { success: true, result };\n } catch (e: unknown) {\n const errorMessage = isDriveApiError(e) && e.message ? e.message : 'Unknown error';\n const errorCode = isDriveApiError(e) && e.code ? String(e.code) : undefined;\n logger.info('Failed to move file', { fileId, error: errorMessage });\n return {\n success: false,\n error: {\n fileId: fileId,\n error: errorMessage,\n ...(errorCode && { code: errorCode }),\n },\n };\n }\n}\n\n/**\n * Move multiple files using batch requests\n */\nasync function moveBatchFiles(\n drive: drive_v3.Drive,\n fileIds: string[],\n destinationFolderId: string,\n returnOldParents: boolean,\n _logger: Logger\n): Promise<{\n moved: MoveResult[];\n failed: FailedMove[];\n}> {\n const moved: MoveResult[] = [];\n const failed: FailedMove[] = [];\n\n // First, fetch metadata for all files in batch\n const metadataResults = await Promise.allSettled(\n fileIds.map(async (fileId) => {\n try {\n const response = await drive.files.get({\n fileId: fileId,\n fields: 'id,name,parents,webViewLink',\n });\n const webViewLink = response.data.webViewLink as string | undefined;\n return {\n fileId: fileId,\n name: (response.data.name as string | undefined) || fileId,\n parents: (response.data.parents as string[] | undefined) || [],\n ...(webViewLink && { webViewLink }),\n };\n } catch (e: unknown) {\n const message = isDriveApiError(e) && e.message ? e.message : String(e);\n throw new Error(`Failed to fetch metadata: ${message}`);\n }\n })\n );\n\n // Process metadata results\n const filesToMove: Array<{\n fileId: string;\n name: string;\n parents: string[];\n webViewLink?: string;\n }> = [];\n for (let i = 0; i < metadataResults.length; i++) {\n const result = metadataResults[i];\n if (result && result.status === 'fulfilled') {\n filesToMove.push(result.value);\n } else if (result && result.status === 'rejected') {\n const fileId = fileIds[i];\n if (fileId) {\n const errorCode = result.reason?.code ? String(result.reason.code) : undefined;\n failed.push({\n fileId: fileId,\n error: result.reason?.message || 'Failed to fetch file metadata',\n ...(errorCode && { code: errorCode }),\n });\n }\n }\n }\n\n // Now move files in batch\n const moveResults = await Promise.allSettled(\n filesToMove.map(async (file) => {\n try {\n await drive.files.update({\n fileId: file.fileId,\n addParents: destinationFolderId,\n removeParents: file.parents.join(','),\n fields: 'id',\n });\n return {\n fileId: file.fileId,\n fileName: file.name,\n oldParents: returnOldParents ? file.parents : [],\n newParent: destinationFolderId,\n ...(file.webViewLink && { webViewLink: file.webViewLink }),\n };\n } catch (e: unknown) {\n const message = isDriveApiError(e) && e.message ? e.message : String(e);\n throw new Error(`Failed to move: ${message}`);\n }\n })\n );\n\n // Process move results\n for (let i = 0; i < moveResults.length; i++) {\n const result = moveResults[i];\n if (result && result.status === 'fulfilled') {\n moved.push(result.value);\n } else if (result && result.status === 'rejected') {\n const file = filesToMove[i];\n if (file) {\n const errorCode = result.reason?.code ? String(result.reason.code) : undefined;\n failed.push({\n fileId: file.fileId,\n error: result.reason?.message || 'Failed to move file',\n ...(errorCode && { code: errorCode }),\n });\n }\n }\n }\n\n return { moved, failed };\n}\n\nasync function handler({ fileIds, destinationFolderId, returnOldParents = true }: Input, extra: EnrichedExtra): Promise<CallToolResult> {\n const logger = extra.logger;\n const isBatch = Array.isArray(fileIds);\n const fileIdArray = Array.isArray(fileIds) ? fileIds : [fileIds];\n\n logger.info('drive.file.move called', {\n fileCount: fileIdArray.length,\n isBatch,\n destinationFolderId,\n returnOldParents,\n });\n\n try {\n const drive = google.drive({ version: 'v3', auth: extra.authContext.auth });\n\n let moved: MoveResult[] = [];\n let failed: FailedMove[] = [];\n\n if (isBatch && fileIdArray.length > 1) {\n // Use batch API for multiple files\n const batchResult = await moveBatchFiles(drive, fileIdArray, destinationFolderId, returnOldParents, logger);\n moved = batchResult.moved;\n failed = batchResult.failed;\n } else {\n // Single file operation\n const fileId = fileIdArray[0];\n if (fileId) {\n const singleResult = await moveSingleFile(drive, fileId, destinationFolderId, returnOldParents, logger);\n if (singleResult.success && singleResult.result) {\n moved.push(singleResult.result);\n } else if (singleResult.error) {\n failed.push(singleResult.error);\n }\n }\n }\n\n logger.info('drive.file.move returning', {\n totalRequested: fileIdArray.length,\n totalMoved: moved.length,\n totalFailed: failed.length,\n });\n\n const result: Output = {\n type: 'success' as const,\n moved,\n ...(failed.length > 0 && { failed }),\n totalRequested: fileIdArray.length,\n totalMoved: moved.length,\n totalFailed: failed.length,\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.move error', { error: message });\n\n // Throw ProtocolError\n throw new ProtocolError(ProtocolErrorCode.InternalError, `Error moving files: ${message}`, {\n stack: error instanceof Error ? error.stack : undefined,\n });\n }\n}\n\nexport default function createTool() {\n return {\n name: 'file-move' as const,\n config,\n handler,\n };\n}\n"],"names":["createTool","AuthRequiredBranchSchema","schemas","isDriveApiError","error","inputSchema","z","object","fileIds","union","string","min","array","max","describe","destinationFolderId","returnOldParents","boolean","optional","successBranchSchema","type","literal","moved","fileId","fileName","oldParents","newParent","webViewLink","failed","code","totalRequested","number","totalMoved","totalFailed","outputSchema","discriminatedUnion","config","title","description","result","moveSingleFile","drive","logger","fileMetadata","e","errorMessage","errorCode","files","get","fields","data","parents","name","update","addParents","removeParents","join","success","message","String","undefined","info","moveBatchFiles","_logger","metadataResults","filesToMove","i","moveResults","file","Promise","allSettled","map","response","Error","length","status","push","value","reason","handler","extra","isBatch","fileIdArray","batchResult","singleResult","Array","isArray","fileCount","google","version","auth","authContext","content","text","JSON","stringify","structuredContent","ProtocolError","ProtocolErrorCode","InternalError","stack"],"mappings":";;;;+BAiUA;;;eAAwBA;;;2BAhUA;sBAI8C;0BAE/C;mBACL;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AALlB,IAAM,AAAEC,2BAA6BC,oBAAO,CAApCD;AAcR,SAASE,gBAAgBC,KAAc;IACrC,OAAO,CAAA,OAAOA,sCAAP,SAAOA,MAAI,MAAM,YAAYA,UAAU,QAAS,CAAA,aAAaA,SAAS,UAAUA,KAAI;AAC7F;AAiBA,IAAMC,cAAcC,MAAC,CAACC,MAAM,CAAC;IAC3BC,SAASF,MAAC,CAACG,KAAK,CAAC;QAACH,MAAC,CAACI,MAAM,GAAGC,GAAG,CAAC;QAAIL,MAAC,CAACM,KAAK,CAACN,MAAC,CAACI,MAAM,GAAGC,GAAG,CAAC,IAAIA,GAAG,CAAC,GAAGE,GAAG,CAAC;KAAK,EAA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C,OAAOhG,AAAK,YAALA,OAAiBqE,SAAQrE,MAAMgG,KAAK,GAAGxC;oBAChD;;;;;;;IAEJ;;AAEe,SAAS5D;IACtB,OAAO;QACLoD,MAAM;QACNhB,QAAAA;QACA2C,SAAAA;IACF;AACF"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { EnrichedExtra } from '@mcp-z/oauth-google';
|
|
2
|
-
import type { CallToolResult } from '@
|
|
2
|
+
import type { CallToolResult } from '@mcp-z/server';
|
|
3
3
|
import { z } from 'zod';
|
|
4
4
|
declare const inputSchema: z.ZodObject<{
|
|
5
5
|
sourceUri: z.ZodString;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { EnrichedExtra } from '@mcp-z/oauth-google';
|
|
2
|
-
import type { CallToolResult } from '@
|
|
2
|
+
import type { CallToolResult } from '@mcp-z/server';
|
|
3
3
|
import { z } from 'zod';
|
|
4
4
|
declare const inputSchema: z.ZodObject<{
|
|
5
5
|
sourceUri: z.ZodString;
|
|
@@ -9,7 +9,7 @@ Object.defineProperty(exports, "default", {
|
|
|
9
9
|
}
|
|
10
10
|
});
|
|
11
11
|
var _oauthgoogle = require("@mcp-z/oauth-google");
|
|
12
|
-
var
|
|
12
|
+
var _server = require("@mcp-z/server");
|
|
13
13
|
var _googleapis = require("googleapis");
|
|
14
14
|
var _zod = require("zod");
|
|
15
15
|
var _filestreamingts = require("../../lib/file-streaming.js");
|
|
@@ -365,8 +365,8 @@ function handler(_0, _1) {
|
|
|
365
365
|
logger.error('drive.file.upload error', {
|
|
366
366
|
error: message
|
|
367
367
|
});
|
|
368
|
-
// Throw
|
|
369
|
-
throw new
|
|
368
|
+
// Throw ProtocolError for proper MCP error handling
|
|
369
|
+
throw new _server.ProtocolError(_server.ProtocolErrorCode.InternalError, "Error uploading file: ".concat(message), {
|
|
370
370
|
stack: _instanceof(error, Error) ? error.stack : undefined
|
|
371
371
|
});
|
|
372
372
|
case 10:
|
|
@@ -1 +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,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B,OAAdN,YAAW,KAAmB,OAAhBM;wBAC7C5B,gBAAgB;wBAChBE,cAAc;wBACdC,aAAa,IAAIkD,OAAOC,WAAW;wBACnClD,IAAAA;wBACAb,MAAM+B;wBACN7B,UAAU8B;wBACVlB,MAAAA;wBACAC,aAAAA;uBACImB,kBAAkB;wBAAE/B,UAAU+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"}
|
|
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 '@mcp-z/server';\nimport { ProtocolError, ProtocolErrorCode } from '@mcp-z/server';\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 ProtocolError for proper MCP error handling\n throw new ProtocolError(ProtocolErrorCode.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","ProtocolError","ProtocolErrorCode","InternalError","stack","undefined"],"mappings":";;;;+BAgKA;;;eAAwBA;;;2BA/JA;sBAKyB;0BAC1B;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,GAAGF,QAAQ,CAAC;IACnDG,UAAUT,MAAC,CAACG,MAAM,GAAGC,IAAI,GAAGC,GAAG,CAAC,GAAGG,QAAQ,GAAGF,QAAQ,CAAC;IACvDI,UAAUV,MAAC,CAACG,MAAM,GAAGK,QAAQ,GAAGF,QAAQ,CAA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4BAAO;wBAC9B;;;oBACOiB;oBACDC,UAAUD,AAAK,YAALA,OAAiB+B,SAAQ/B,MAAMC,OAAO,GAAGmB,OAAOpB;oBAChEd,OAAOc,KAAK,CAAC,2BAA2B;wBAAEA,OAAOC;oBAAQ;oBAEzD,oDAAoD;oBACpD,MAAM,IAAI+B,qBAAa,CAACC,yBAAiB,CAACC,aAAa,EAAE,AAAC,yBAAgC,OAARjC,UAAW;wBAC3FkC,OAAOnC,AAAK,YAALA,OAAiB+B,SAAQ/B,MAAMmC,KAAK,GAAGC;oBAChD;;;;;;;IAEJ;;AAEe,SAASrF;IACtB,OAAO;QACLW,MAAM;QACNmB,QAAAA;QACAG,SAAAA;IACF;AACF"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { EnrichedExtra } from '@mcp-z/oauth-google';
|
|
2
|
-
import { type CallToolResult } from '@
|
|
2
|
+
import { type CallToolResult } from '@mcp-z/server';
|
|
3
3
|
import { z } from 'zod';
|
|
4
4
|
declare const inputSchema: z.ZodObject<{
|
|
5
5
|
shape: z.ZodDefault<z.ZodOptional<z.ZodEnum<{
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { EnrichedExtra } from '@mcp-z/oauth-google';
|
|
2
|
-
import { type CallToolResult } from '@
|
|
2
|
+
import { type CallToolResult } from '@mcp-z/server';
|
|
3
3
|
import { z } from 'zod';
|
|
4
4
|
declare const inputSchema: z.ZodObject<{
|
|
5
5
|
shape: z.ZodDefault<z.ZodOptional<z.ZodEnum<{
|
|
@@ -10,7 +10,6 @@ Object.defineProperty(exports, "default", {
|
|
|
10
10
|
});
|
|
11
11
|
var _oauthgoogle = require("@mcp-z/oauth-google");
|
|
12
12
|
var _server = require("@mcp-z/server");
|
|
13
|
-
var _types = require("@modelcontextprotocol/sdk/types.js");
|
|
14
13
|
var _googleapis = require("googleapis");
|
|
15
14
|
var _zod = require("zod");
|
|
16
15
|
var _querybuilderts = require("../../lib/query-builder.js");
|
|
@@ -495,8 +494,8 @@ function handler(_0, _1) {
|
|
|
495
494
|
logger.error('drive.files-search error', {
|
|
496
495
|
error: message
|
|
497
496
|
});
|
|
498
|
-
// Throw
|
|
499
|
-
throw new
|
|
497
|
+
// Throw ProtocolError for all errors so callers can see Drive validation details
|
|
498
|
+
throw new _server.ProtocolError(_server.ProtocolErrorCode.InternalError, "Error searching files: ".concat(message), {
|
|
500
499
|
stack: _instanceof(error, Error) ? error.stack : undefined
|
|
501
500
|
});
|
|
502
501
|
case 6:
|