@mcp-z/mcp-drive 1.0.0 → 1.0.2

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.
Files changed (86) hide show
  1. package/README.md +32 -3
  2. package/bin/server.js +1 -1
  3. package/dist/cjs/constants.js.map +1 -1
  4. package/dist/cjs/index.js +13 -13
  5. package/dist/cjs/index.js.map +1 -1
  6. package/dist/cjs/lib/create-store.js.map +1 -1
  7. package/dist/cjs/lib/query-builder.js.map +1 -1
  8. package/dist/cjs/mcp/index.js +6 -6
  9. package/dist/cjs/mcp/index.js.map +1 -1
  10. package/dist/cjs/mcp/prompts/index.js +4 -4
  11. package/dist/cjs/mcp/prompts/index.js.map +1 -1
  12. package/dist/cjs/mcp/prompts/organize-files.js.map +1 -1
  13. package/dist/cjs/mcp/prompts/query-syntax.js.map +1 -1
  14. package/dist/cjs/mcp/resources/file.js.map +1 -1
  15. package/dist/cjs/mcp/resources/index.js +2 -2
  16. package/dist/cjs/mcp/resources/index.js.map +1 -1
  17. package/dist/cjs/mcp/tools/file-move-to-trash.js.map +1 -1
  18. package/dist/cjs/mcp/tools/file-move.js.map +1 -1
  19. package/dist/cjs/mcp/tools/files-search.js +10 -10
  20. package/dist/cjs/mcp/tools/files-search.js.map +1 -1
  21. package/dist/cjs/mcp/tools/folder-contents.js +7 -7
  22. package/dist/cjs/mcp/tools/folder-contents.js.map +1 -1
  23. package/dist/cjs/mcp/tools/folder-create.js.map +1 -1
  24. package/dist/cjs/mcp/tools/folder-path.js.map +1 -1
  25. package/dist/cjs/mcp/tools/folder-search.js +10 -10
  26. package/dist/cjs/mcp/tools/folder-search.js.map +1 -1
  27. package/dist/cjs/mcp/tools/index.js +14 -14
  28. package/dist/cjs/mcp/tools/index.js.map +1 -1
  29. package/dist/cjs/schemas/drive-query-schema.d.cts +1 -2
  30. package/dist/cjs/schemas/drive-query-schema.d.ts +1 -2
  31. package/dist/cjs/schemas/drive-query-schema.js +12 -7
  32. package/dist/cjs/schemas/drive-query-schema.js.map +1 -1
  33. package/dist/cjs/schemas/drive-validation.js.map +1 -1
  34. package/dist/cjs/schemas/index.js.map +1 -1
  35. package/dist/cjs/setup/config.js +11 -1
  36. package/dist/cjs/setup/config.js.map +1 -1
  37. package/dist/cjs/setup/http.js +6 -2
  38. package/dist/cjs/setup/http.js.map +1 -1
  39. package/dist/cjs/setup/index.d.cts +1 -0
  40. package/dist/cjs/setup/index.d.ts +1 -0
  41. package/dist/cjs/setup/index.js +9 -9
  42. package/dist/cjs/setup/index.js.map +1 -1
  43. package/dist/cjs/setup/oauth-google.d.cts +3 -2
  44. package/dist/cjs/setup/oauth-google.d.ts +3 -2
  45. package/dist/cjs/setup/oauth-google.js +15 -12
  46. package/dist/cjs/setup/oauth-google.js.map +1 -1
  47. package/dist/cjs/setup/runtime.js +9 -9
  48. package/dist/cjs/setup/runtime.js.map +1 -1
  49. package/dist/cjs/setup/stdio.js +2 -2
  50. package/dist/cjs/setup/stdio.js.map +1 -1
  51. package/dist/esm/constants.js.map +1 -1
  52. package/dist/esm/index.js.map +1 -1
  53. package/dist/esm/lib/create-store.js.map +1 -1
  54. package/dist/esm/lib/query-builder.js.map +1 -1
  55. package/dist/esm/mcp/index.js.map +1 -1
  56. package/dist/esm/mcp/prompts/index.js.map +1 -1
  57. package/dist/esm/mcp/prompts/organize-files.js.map +1 -1
  58. package/dist/esm/mcp/prompts/query-syntax.js.map +1 -1
  59. package/dist/esm/mcp/resources/file.js.map +1 -1
  60. package/dist/esm/mcp/resources/index.js.map +1 -1
  61. package/dist/esm/mcp/tools/file-move-to-trash.js.map +1 -1
  62. package/dist/esm/mcp/tools/file-move.js.map +1 -1
  63. package/dist/esm/mcp/tools/files-search.js.map +1 -1
  64. package/dist/esm/mcp/tools/folder-contents.js.map +1 -1
  65. package/dist/esm/mcp/tools/folder-create.js.map +1 -1
  66. package/dist/esm/mcp/tools/folder-path.js.map +1 -1
  67. package/dist/esm/mcp/tools/folder-search.js.map +1 -1
  68. package/dist/esm/mcp/tools/index.js.map +1 -1
  69. package/dist/esm/schemas/drive-query-schema.d.ts +1 -2
  70. package/dist/esm/schemas/drive-query-schema.js +1 -1
  71. package/dist/esm/schemas/drive-query-schema.js.map +1 -1
  72. package/dist/esm/schemas/drive-validation.js.map +1 -1
  73. package/dist/esm/schemas/index.js.map +1 -1
  74. package/dist/esm/setup/config.js +12 -2
  75. package/dist/esm/setup/config.js.map +1 -1
  76. package/dist/esm/setup/http.js +4 -0
  77. package/dist/esm/setup/http.js.map +1 -1
  78. package/dist/esm/setup/index.d.ts +1 -0
  79. package/dist/esm/setup/index.js.map +1 -1
  80. package/dist/esm/setup/oauth-google.d.ts +3 -2
  81. package/dist/esm/setup/oauth-google.js +8 -11
  82. package/dist/esm/setup/oauth-google.js.map +1 -1
  83. package/dist/esm/setup/runtime.js.map +1 -1
  84. package/dist/esm/setup/stdio.js.map +1 -1
  85. package/dist/esm/types.js.map +1 -1
  86. package/package.json +2 -2
@@ -1 +1 @@
1
- {"version":3,"sources":["/Users/kevin/Dev/Projects/ai/mcp-z/servers/mcp-drive/src/mcp/tools/folder-contents.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 { google } from 'googleapis';\nimport { z } from 'zod';\nimport { DRIVE_FILE_COMMON_PATTERNS, DRIVE_FILE_FIELD_DESCRIPTIONS, DRIVE_FILE_FIELDS, type DriveFile, DriveFileSchema } from '../../schemas/index.js';\n\nconst inputSchema = z.object({\n folderId: z.string().min(1).describe('Folder ID to list contents (use \"root\" for Drive root)'),\n fields: createFieldsSchema({\n availableFields: DRIVE_FILE_FIELDS,\n fieldDescriptions: DRIVE_FILE_FIELD_DESCRIPTIONS,\n commonPatterns: DRIVE_FILE_COMMON_PATTERNS,\n resourceName: 'Drive item',\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('Files and folders in the specified folder'),\n count: z.number().describe('Number of items in this page'),\n folderId: z.string().describe('ID of the folder that was listed'),\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 items in this page'),\n folderId: z.string().describe('ID of the folder that was listed'),\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: 'List Folder Contents',\n description: 'List files and folders in a specific folder with field selection.',\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 DriveItem = {\n id?: string;\n name?: string;\n mimeType?: string;\n webViewLink?: string;\n modifiedTime?: string;\n parents?: string[];\n shared?: boolean;\n starred?: boolean;\n owners?: Array<{\n displayName?: string;\n emailAddress?: string;\n kind?: string;\n me?: boolean;\n permissionId?: string;\n photoLink?: string;\n }>;\n};\n\ntype DriveResponse = {\n files?: DriveItem[];\n nextPageToken?: string;\n};\n\nasync function handler({ folderId, pageSize = 50, pageToken, fields, shape = 'arrays' }: Input, extra: EnrichedExtra): Promise<CallToolResult> {\n const logger = extra.logger;\n\n const requestedFields = parseFields(fields, DRIVE_FILE_FIELDS);\n\n logger.info('drive.folder.contents called', {\n folderId,\n pageSize,\n pageToken: pageToken ? '[provided]' : undefined,\n fields: fields || 'all',\n });\n\n try {\n const drive = google.drive({ version: 'v3', auth: extra.authContext.auth });\n\n const qStr = `'${folderId}' in parents and trashed = false`;\n\n const listOptions: {\n q: string;\n pageSize: number;\n fields: string;\n orderBy: string;\n pageToken?: string;\n } = {\n q: qStr,\n pageSize: Math.min(1000, pageSize),\n fields: 'files(id,name,mimeType,webViewLink,modifiedTime,parents,shared,starred,owners),nextPageToken',\n orderBy: 'folder,name', // Folders first, then by name\n };\n if (pageToken && pageToken.trim().length > 0) {\n listOptions.pageToken = pageToken;\n }\n\n const response = await drive.files.list(listOptions);\n\n const res = response.data as DriveResponse;\n const items = Array.isArray(res?.files) ? res.files : [];\n\n const parentIds = new Set<string>();\n for (const f of items) {\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 driveFiles: DriveFile[] = items.map((f: DriveItem) => {\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 // Build parent objects with names\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 !== undefined) result.shared = f.shared;\n if (f?.starred !== undefined) 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 !== undefined) 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 = driveFiles.map((item) => filterFields(item, requestedFields));\n\n logger.info('drive.folder.contents returning', {\n folderId,\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 folderId,\n ...(nextPageToken && { nextPageToken }),\n }\n : {\n type: 'success' as const,\n shape: 'objects' as const,\n items: filteredItems,\n count: filteredItems.length,\n folderId,\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.folder.contents error', { error: message });\n\n // Throw McpError\n throw new McpError(ErrorCode.InternalError, `Error listing folder contents: ${message}`, {\n stack: error instanceof Error ? error.stack : undefined,\n });\n }\n}\n\nexport default function createTool() {\n return {\n name: 'folder-contents' as const,\n config,\n handler,\n };\n}\n"],"names":["schemas","AuthRequiredBranchSchema","createFieldsSchema","createPaginationSchema","createShapeSchema","filterFields","parseFields","toColumnarFormat","ErrorCode","McpError","google","z","DRIVE_FILE_COMMON_PATTERNS","DRIVE_FILE_FIELD_DESCRIPTIONS","DRIVE_FILE_FIELDS","DriveFileSchema","inputSchema","object","folderId","string","min","describe","fields","availableFields","fieldDescriptions","commonPatterns","resourceName","defaultPageSize","maxPageSize","provider","shape","successObjectsBranchSchema","type","literal","items","array","count","number","nextPageToken","optional","successArraysBranchSchema","columns","rows","unknown","outputSchema","union","config","title","description","result","handler","pageSize","pageToken","extra","logger","requestedFields","info","undefined","drive","version","auth","authContext","qStr","listOptions","q","Math","orderBy","trim","length","response","files","list","res","data","Array","isArray","parentIds","Set","f","parents","parentId","add","parentNameMap","Map","size","parentFetches","from","map","parentRes","get","fileId","parentName","name","set","e","error","Promise","all","driveFiles","id","String","mimeType","webViewLink","modifiedTime","shared","starred","owners","o","owner","displayName","emailAddress","kind","me","permissionId","photoLink","filteredItems","item","resultCount","content","text","JSON","stringify","structuredContent","message","Error","InternalError","stack","createTool"],"mappings":"AACA,SAASA,OAAO,QAAQ,sBAAsB;AAE9C,MAAM,EAAEC,wBAAwB,EAAE,GAAGD;AAErC,SAASE,kBAAkB,EAAEC,sBAAsB,EAAEC,iBAAiB,EAAEC,YAAY,EAAEC,WAAW,EAAEC,gBAAgB,QAAQ,gBAAgB;AAC3I,SAA8BC,SAAS,EAAEC,QAAQ,QAAQ,qCAAqC;AAC9F,SAASC,MAAM,QAAQ,aAAa;AACpC,SAASC,CAAC,QAAQ,MAAM;AACxB,SAASC,0BAA0B,EAAEC,6BAA6B,EAAEC,iBAAiB,EAAkBC,eAAe,QAAQ,yBAAyB;AAEvJ,MAAMC,cAAcL,EAAEM,MAAM,CAAC;IAC3BC,UAAUP,EAAEQ,MAAM,GAAGC,GAAG,CAAC,GAAGC,QAAQ,CAAC;IACrCC,QAAQpB,mBAAmB;QACzBqB,iBAAiBT;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"],"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 { google } from 'googleapis';\nimport { z } from 'zod';\nimport { DRIVE_FILE_COMMON_PATTERNS, DRIVE_FILE_FIELD_DESCRIPTIONS, DRIVE_FILE_FIELDS, type DriveFile, DriveFileSchema } from '../../schemas/index.ts';\n\nconst inputSchema = z.object({\n folderId: z.string().min(1).describe('Folder ID to list contents (use \"root\" for Drive root)'),\n fields: createFieldsSchema({\n availableFields: DRIVE_FILE_FIELDS,\n fieldDescriptions: DRIVE_FILE_FIELD_DESCRIPTIONS,\n commonPatterns: DRIVE_FILE_COMMON_PATTERNS,\n resourceName: 'Drive item',\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('Files and folders in the specified folder'),\n count: z.number().describe('Number of items in this page'),\n folderId: z.string().describe('ID of the folder that was listed'),\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 items in this page'),\n folderId: z.string().describe('ID of the folder that was listed'),\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: 'List Folder Contents',\n description: 'List files and folders in a specific folder with field selection.',\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 DriveItem = {\n id?: string;\n name?: string;\n mimeType?: string;\n webViewLink?: string;\n modifiedTime?: string;\n parents?: string[];\n shared?: boolean;\n starred?: boolean;\n owners?: Array<{\n displayName?: string;\n emailAddress?: string;\n kind?: string;\n me?: boolean;\n permissionId?: string;\n photoLink?: string;\n }>;\n};\n\ntype DriveResponse = {\n files?: DriveItem[];\n nextPageToken?: string;\n};\n\nasync function handler({ folderId, pageSize = 50, pageToken, fields, shape = 'arrays' }: Input, extra: EnrichedExtra): Promise<CallToolResult> {\n const logger = extra.logger;\n\n const requestedFields = parseFields(fields, DRIVE_FILE_FIELDS);\n\n logger.info('drive.folder.contents called', {\n folderId,\n pageSize,\n pageToken: pageToken ? '[provided]' : undefined,\n fields: fields || 'all',\n });\n\n try {\n const drive = google.drive({ version: 'v3', auth: extra.authContext.auth });\n\n const qStr = `'${folderId}' in parents and trashed = false`;\n\n const listOptions: {\n q: string;\n pageSize: number;\n fields: string;\n orderBy: string;\n pageToken?: string;\n } = {\n q: qStr,\n pageSize: Math.min(1000, pageSize),\n fields: 'files(id,name,mimeType,webViewLink,modifiedTime,parents,shared,starred,owners),nextPageToken',\n orderBy: 'folder,name', // Folders first, then by name\n };\n if (pageToken && pageToken.trim().length > 0) {\n listOptions.pageToken = pageToken;\n }\n\n const response = await drive.files.list(listOptions);\n\n const res = response.data as DriveResponse;\n const items = Array.isArray(res?.files) ? res.files : [];\n\n const parentIds = new Set<string>();\n for (const f of items) {\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 driveFiles: DriveFile[] = items.map((f: DriveItem) => {\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 // Build parent objects with names\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 !== undefined) result.shared = f.shared;\n if (f?.starred !== undefined) 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 !== undefined) 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 = driveFiles.map((item) => filterFields(item, requestedFields));\n\n logger.info('drive.folder.contents returning', {\n folderId,\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 folderId,\n ...(nextPageToken && { nextPageToken }),\n }\n : {\n type: 'success' as const,\n shape: 'objects' as const,\n items: filteredItems,\n count: filteredItems.length,\n folderId,\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.folder.contents error', { error: message });\n\n // Throw McpError\n throw new McpError(ErrorCode.InternalError, `Error listing folder contents: ${message}`, {\n stack: error instanceof Error ? error.stack : undefined,\n });\n }\n}\n\nexport default function createTool() {\n return {\n name: 'folder-contents' as const,\n config,\n handler,\n };\n}\n"],"names":["schemas","AuthRequiredBranchSchema","createFieldsSchema","createPaginationSchema","createShapeSchema","filterFields","parseFields","toColumnarFormat","ErrorCode","McpError","google","z","DRIVE_FILE_COMMON_PATTERNS","DRIVE_FILE_FIELD_DESCRIPTIONS","DRIVE_FILE_FIELDS","DriveFileSchema","inputSchema","object","folderId","string","min","describe","fields","availableFields","fieldDescriptions","commonPatterns","resourceName","defaultPageSize","maxPageSize","provider","shape","successObjectsBranchSchema","type","literal","items","array","count","number","nextPageToken","optional","successArraysBranchSchema","columns","rows","unknown","outputSchema","union","config","title","description","result","handler","pageSize","pageToken","extra","logger","requestedFields","info","undefined","drive","version","auth","authContext","qStr","listOptions","q","Math","orderBy","trim","length","response","files","list","res","data","Array","isArray","parentIds","Set","f","parents","parentId","add","parentNameMap","Map","size","parentFetches","from","map","parentRes","get","fileId","parentName","name","set","e","error","Promise","all","driveFiles","id","String","mimeType","webViewLink","modifiedTime","shared","starred","owners","o","owner","displayName","emailAddress","kind","me","permissionId","photoLink","filteredItems","item","resultCount","content","text","JSON","stringify","structuredContent","message","Error","InternalError","stack","createTool"],"mappings":"A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AAS,CAACxE;gBACvB;aACD;YACDyE,mBAAmB;gBAAEzE;YAAO;QAC9B;IACF,EAAE,OAAO8C,OAAO;QACd,MAAM4B,UAAU5B,iBAAiB6B,QAAQ7B,MAAM4B,OAAO,GAAGvB,OAAOL;QAChEzC,OAAOyC,KAAK,CAAC,+BAA+B;YAAEA,OAAO4B;QAAQ;QAE7D,iBAAiB;QACjB,MAAM,IAAIlH,SAASD,UAAUqH,aAAa,EAAE,CAAC,+BAA+B,EAAEF,SAAS,EAAE;YACvFG,OAAO/B,iBAAiB6B,QAAQ7B,MAAM+B,KAAK,GAAGrE;QAChD;IACF;AACF;AAEA,eAAe,SAASsE;IACtB,OAAO;QACLnC,MAAM;QACN9C;QACAI;IACF;AACF"}
@@ -1 +1 @@
1
- {"version":3,"sources":["/Users/kevin/Dev/Projects/ai/mcp-z/servers/mcp-drive/src/mcp/tools/folder-create.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';\n\nconst inputSchema = z.object({\n name: z.string().trim().min(1).describe('Name for the new folder'),\n parentId: z.string().optional().describe('Parent folder ID (omit to create in My Drive root)'),\n});\n\n// Success branch schema\nconst successBranchSchema = z.object({\n type: z.literal('success'),\n operationSummary: z.string().describe('Summary of the folder creation operation'),\n itemsProcessed: z.number().describe('Total items attempted (always 1 for single folder)'),\n itemsChanged: z.number().describe('Successfully created folders (always 1 on success)'),\n completedAt: z.string().describe('ISO datetime when operation completed'),\n id: z.string().describe('ID of the created folder'),\n name: z.string().describe('Name of the created folder'),\n webViewLink: z.string().describe('URL to view the folder 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: 'Create Folder',\n description: 'Create a new folder in Google Drive. Returns folder 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({ name: folderName, parentId }: Input, extra: EnrichedExtra): Promise<CallToolResult> {\n const logger = extra.logger;\n logger.info('drive.folder.create called', {\n name: folderName,\n parentId: parentId || 'root',\n });\n\n try {\n const drive = google.drive({ version: 'v3', auth: extra.authContext.auth });\n\n // Folder MIME type constant (consistent with folder-search.ts)\n const folderMimeType = 'application/vnd.google-apps.folder';\n\n // Create the folder\n const response = await drive.files.create({\n requestBody: {\n name: folderName,\n mimeType: folderMimeType,\n parents: parentId ? [parentId] : null,\n },\n fields: 'id,name,webViewLink,parents',\n });\n\n const res = response.data;\n const id = res.id ?? '';\n const name = res.name ?? folderName;\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.folder.create success', {\n id,\n name,\n parentId: actualParentId,\n });\n\n // Build result object with operation metadata\n const result: Output = {\n type: 'success' as const,\n operationSummary: `Created folder \"${name}\"${locationSummary}`,\n itemsProcessed: 1,\n itemsChanged: 1,\n completedAt: new Date().toISOString(),\n id,\n name,\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.folder.create error', { error: message });\n\n // Throw McpError for proper MCP error handling\n throw new McpError(ErrorCode.InternalError, `Error creating folder: ${message}`, {\n stack: error instanceof Error ? error.stack : undefined,\n });\n }\n}\n\nexport default function createTool() {\n return {\n name: 'folder-create' as const,\n config,\n handler,\n };\n}\n"],"names":["schemas","AuthRequiredBranchSchema","ErrorCode","McpError","google","z","inputSchema","object","name","string","trim","min","describe","parentId","optional","successBranchSchema","type","literal","operationSummary","itemsProcessed","number","itemsChanged","completedAt","id","webViewLink","parentName","outputSchema","discriminatedUnion","config","title","description","result","handler","folderName","extra","logger","info","res","drive","version","auth","authContext","folderMimeType","response","files","create","requestBody","mimeType","parents","fields","data","actualParentId","length","parentResponse","get","fileId","e","error","locationSummary","Date","toISOString","content","text","JSON","stringify","structuredContent","message","Error","String","InternalError","stack","undefined","createTool"],"mappings":"AACA,SAASA,OAAO,QAAQ,sBAAsB;AAE9C,MAAM,EAAEC,wBAAwB,EAAE,GAAGD;AAGrC,SAASE,SAAS,EAAEC,QAAQ,QAAQ,qCAAqC;AACzE,SAASC,MAAM,QAAQ,aAAa;AACpC,SAASC,CAAC,QAAQ,MAAM;AAExB,MAAMC,cAAcD,EAAEE,MAAM,CAAC;IAC3BC,MAAMH,EAAEI,MAAM,GAAGC,IAAI,GAAGC,GAAG,CAAC,GAAGC,QAAQ,CAAC;IACxCC,UAAUR,EAAEI,MAAM,GAAGK,QAAQ,GAAGF,QAAQ,CAAC;AAC3C;AAEA,wBAAwB;AACxB,MAAMG,sBAAsBV,EAAEE,MAAM,CAAC;IACnCS,MAAMX,EAAEY,OAAO,CAAC;IAChBC,kBAAkBb,EAAEI,MAA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SAAS;gBACP;oBACE7C,MAAM;oBACN8C,MAAMC,KAAKC,SAAS,CAACjC;gBACvB;aACD;YACDkC,mBAAmB;gBAAElC;YAAO;QAC9B;IACF,EAAE,OAAO0B,OAAO;QACd,MAAMS,UAAUT,iBAAiBU,QAAQV,MAAMS,OAAO,GAAGE,OAAOX;QAChEtB,OAAOsB,KAAK,CAAC,6BAA6B;YAAEA,OAAOS;QAAQ;QAE3D,+CAA+C;QAC/C,MAAM,IAAI/D,SAASD,UAAUmE,aAAa,EAAE,CAAC,uBAAuB,EAAEH,SAAS,EAAE;YAC/EI,OAAOb,iBAAiBU,QAAQV,MAAMa,KAAK,GAAGC;QAChD;IACF;AACF;AAEA,eAAe,SAASC;IACtB,OAAO;QACLhE,MAAM;QACNoB;QACAI;IACF;AACF"}
1
+ {"version":3,"sources":["/Users/kevin/Dev/Projects/mcp-z/mcp-drive/src/mcp/tools/folder-create.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';\n\nconst inputSchema = z.object({\n name: z.string().trim().min(1).describe('Name for the new folder'),\n parentId: z.string().optional().describe('Parent folder ID (omit to create in My Drive root)'),\n});\n\n// Success branch schema\nconst successBranchSchema = z.object({\n type: z.literal('success'),\n operationSummary: z.string().describe('Summary of the folder creation operation'),\n itemsProcessed: z.number().describe('Total items attempted (always 1 for single folder)'),\n itemsChanged: z.number().describe('Successfully created folders (always 1 on success)'),\n completedAt: z.string().describe('ISO datetime when operation completed'),\n id: z.string().describe('ID of the created folder'),\n name: z.string().describe('Name of the created folder'),\n webViewLink: z.string().describe('URL to view the folder 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: 'Create Folder',\n description: 'Create a new folder in Google Drive. Returns folder 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({ name: folderName, parentId }: Input, extra: EnrichedExtra): Promise<CallToolResult> {\n const logger = extra.logger;\n logger.info('drive.folder.create called', {\n name: folderName,\n parentId: parentId || 'root',\n });\n\n try {\n const drive = google.drive({ version: 'v3', auth: extra.authContext.auth });\n\n // Folder MIME type constant (consistent with folder-search.ts)\n const folderMimeType = 'application/vnd.google-apps.folder';\n\n // Create the folder\n const response = await drive.files.create({\n requestBody: {\n name: folderName,\n mimeType: folderMimeType,\n parents: parentId ? [parentId] : null,\n },\n fields: 'id,name,webViewLink,parents',\n });\n\n const res = response.data;\n const id = res.id ?? '';\n const name = res.name ?? folderName;\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.folder.create success', {\n id,\n name,\n parentId: actualParentId,\n });\n\n // Build result object with operation metadata\n const result: Output = {\n type: 'success' as const,\n operationSummary: `Created folder \"${name}\"${locationSummary}`,\n itemsProcessed: 1,\n itemsChanged: 1,\n completedAt: new Date().toISOString(),\n id,\n name,\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.folder.create error', { error: message });\n\n // Throw McpError for proper MCP error handling\n throw new McpError(ErrorCode.InternalError, `Error creating folder: ${message}`, {\n stack: error instanceof Error ? error.stack : undefined,\n });\n }\n}\n\nexport default function createTool() {\n return {\n name: 'folder-create' as const,\n config,\n handler,\n };\n}\n"],"names":["schemas","AuthRequiredBranchSchema","ErrorCode","McpError","google","z","inputSchema","object","name","string","trim","min","describe","parentId","optional","successBranchSchema","type","literal","operationSummary","itemsProcessed","number","itemsChanged","completedAt","id","webViewLink","parentName","outputSchema","discriminatedUnion","config","title","description","result","handler","folderName","extra","logger","info","res","drive","version","auth","authContext","folderMimeType","response","files","create","requestBody","mimeType","parents","fields","data","actualParentId","length","parentResponse","get","fileId","e","error","locationSummary","Date","toISOString","content","text","JSON","stringify","structuredContent","message","Error","String","InternalError","stack","undefined","createTool"],"mappings":"AACA,SAASA,OAAO,QAAQ,sBAAsB;AAE9C,MAAM,EAAEC,wBAAwB,EAAE,GAAGD;AAGrC,SAASE,SAAS,EAAEC,QAAQ,QAAQ,qCAAqC;AACzE,SAASC,MAAM,QAAQ,aAAa;AACpC,SAASC,CAAC,QAAQ,MAAM;AAExB,MAAMC,cAAcD,EAAEE,MAAM,CAAC;IAC3BC,MAAMH,EAAEI,MAAM,GAAGC,IAAI,GAAGC,GAAG,CAAC,GAAGC,QAAQ,CAAC;IACxCC,UAAUR,EAAEI,MAAM,GAAGK,QAAQ,GAAGF,QAAQ,CAAC;AAC3C;AAEA,wBAAwB;AACxB,MAAMG,sBAAsBV,EAAEE,MAAM,CAAC;IACnCS,MAAMX,EAAEY,OAAO,CAAC;IAChBC,kBAAkB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OAAO;YACLoC,SAAS;gBACP;oBACE7C,MAAM;oBACN8C,MAAMC,KAAKC,SAAS,CAACjC;gBACvB;aACD;YACDkC,mBAAmB;gBAAElC;YAAO;QAC9B;IACF,EAAE,OAAO0B,OAAO;QACd,MAAMS,UAAUT,iBAAiBU,QAAQV,MAAMS,OAAO,GAAGE,OAAOX;QAChEtB,OAAOsB,KAAK,CAAC,6BAA6B;YAAEA,OAAOS;QAAQ;QAE3D,+CAA+C;QAC/C,MAAM,IAAI/D,SAASD,UAAUmE,aAAa,EAAE,CAAC,uBAAuB,EAAEH,SAAS,EAAE;YAC/EI,OAAOb,iBAAiBU,QAAQV,MAAMa,KAAK,GAAGC;QAChD;IACF;AACF;AAEA,eAAe,SAASC;IACtB,OAAO;QACLhE,MAAM;QACNoB;QACAI;IACF;AACF"}
@@ -1 +1 @@
1
- {"version":3,"sources":["/Users/kevin/Dev/Projects/ai/mcp-z/servers/mcp-drive/src/mcp/tools/folder-path.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.js';\n\nconst inputSchema = z.object({\n folderId: z.string().min(1).describe('Folder ID to get path for (or \"root\")'),\n});\n\n// Success branch schema - uses items: for consistency with standard vocabulary\nconst successBranchSchema = z.object({\n type: z.literal('success'),\n path: z.string().describe('Full path from root (e.g., /Work/Projects/2024)'),\n items: z\n .array(\n z.object({\n id: z.string().describe('Folder ID'),\n name: z.string().describe('Folder name'),\n })\n )\n .describe('Path items from root to target folder'),\n});\n\n// Output schema with auth_required support\nconst outputSchema = z.discriminatedUnion('type', [successBranchSchema, AuthRequiredBranchSchema]);\n\nconst config = {\n title: 'Get Folder Path',\n description: 'Get full path from folder to root. Returns human-readable path and items with IDs.',\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 * Resolves the full path for a folder by walking up the parent chain.\n * Returns both the path string and structured segments with IDs and names.\n */\nasync function resolveFolderPath(drive: drive_v3.Drive, folderId: string, logger: Logger): Promise<{ path: string; segments: Array<{ id: string; name: string }> }> {\n // Handle root specially\n if (folderId === 'root') {\n return {\n path: '/',\n segments: [{ id: 'root', name: 'My Drive' }],\n };\n }\n\n const segments: Array<{ id: string; name: string }> = [];\n let currentId = folderId;\n const visited = new Set<string>();\n\n // Walk up the parent chain\n while (currentId && currentId !== 'root') {\n // Prevent infinite loops\n if (visited.has(currentId)) {\n logger.info('Circular folder reference detected', {\n folderId: currentId,\n });\n break;\n }\n visited.add(currentId);\n\n // Fetch folder metadata\n try {\n const response = await drive.files.get({\n fileId: currentId,\n fields: 'id,name,parents',\n });\n\n const id = response.data.id as string;\n const name = (response.data.name as string) || id;\n const parents = response.data.parents as string[] | undefined;\n\n // Add to segments at beginning (we're walking from child to root)\n segments.unshift({ id, name });\n\n // Move to parent\n currentId = (parents && parents.length > 0 ? parents[0] : '') || '';\n } catch (e) {\n logger.info('Failed to resolve folder path', {\n folderId: currentId,\n error: e,\n });\n break;\n }\n }\n\n // Add root if we reached it\n if (currentId === 'root') {\n segments.unshift({ id: 'root', name: 'My Drive' });\n }\n\n // Build path string\n const pathParts = segments.slice(1).map((seg) => seg.name); // Skip root\n const path = pathParts.length > 0 ? `/${pathParts.join('/')}` : '/';\n\n return { path, segments };\n}\n\nasync function handler({ folderId }: Input, extra: EnrichedExtra): Promise<CallToolResult> {\n const logger = extra.logger;\n logger.info('drive.folder.path called', { folderId });\n\n try {\n const drive = google.drive({ version: 'v3', auth: extra.authContext.auth });\n\n const pathResult = await resolveFolderPath(drive, folderId, logger);\n\n logger.info('drive.folder.path returning', {\n path: pathResult.path,\n segmentCount: pathResult.segments.length,\n });\n\n const result: Output = {\n type: 'success' as const,\n path: pathResult.path,\n items: pathResult.segments,\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.folder.path error', { error: message });\n\n // Throw McpError\n throw new McpError(ErrorCode.InternalError, `Error getting folder path: ${message}`, {\n stack: error instanceof Error ? error.stack : undefined,\n });\n }\n}\n\nexport default function createTool() {\n return {\n name: 'folder-path' as const,\n config,\n handler,\n };\n}\n"],"names":["schemas","AuthRequiredBranchSchema","ErrorCode","McpError","google","z","inputSchema","object","folderId","string","min","describe","successBranchSchema","type","literal","path","items","array","id","name","outputSchema","discriminatedUnion","config","title","description","result","resolveFolderPath","drive","logger","segments","currentId","visited","Set","has","info","add","response","files","get","fileId","fields","data","parents","unshift","length","e","error","pathParts","slice","map","seg","join","handler","extra","version","auth","authContext","pathResult","segmentCount","content","text","JSON","stringify","structuredContent","message","Error","String","InternalError","stack","undefined","createTool"],"mappings":"AACA,SAASA,OAAO,QAAQ,sBAAsB;AAE9C,MAAM,EAAEC,wBAAwB,EAAE,GAAGD;AAErC,SAA8BE,SAAS,EAAEC,QAAQ,QAAQ,qCAAqC;AAE9F,SAASC,MAAM,QAAQ,aAAa;AACpC,SAASC,CAAC,QAAQ,MAAM;AAGxB,MAAMC,cAAcD,EAAEE,MAAM,CAAC;IAC3BC,UAAUH,EAAEI,MAAM,GAAGC,GAAG,CAAC,GAAGC,QAAQ,CAAC;AACvC;AAEA,+EAA+E;AAC/E,MAAMC,sBAAsBP,EAAEE,MAAM,CAAC;IACnCM,MAAMR,EAAES,OAAO,CAAC;IAChBC,MAAMV,EAAEI,MAAM,GAAGE,QAAQ,CAAC;IAC1BK,OAAOX,EACJY,KAAK,CACJZ,EAAEE,MAAM,CAAC;QACPW,IAAIb,EAAEI,MAAM,GAAGE,QAAQ,CAAC;QACxBQ,MAA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AOkB,KAAK,CAAC,2BAA2B;YAAEA,OAAOkB;QAAQ;QAEzD,iBAAiB;QACjB,MAAM,IAAI7D,SAASD,UAAUiE,aAAa,EAAE,CAAC,2BAA2B,EAAEH,SAAS,EAAE;YACnFI,OAAOtB,iBAAiBmB,QAAQnB,MAAMsB,KAAK,GAAGC;QAChD;IACF;AACF;AAEA,eAAe,SAASC;IACtB,OAAO;QACLnD,MAAM;QACNG;QACA8B;IACF;AACF"}
1
+ {"version":3,"sources":["/Users/kevin/Dev/Projects/mcp-z/mcp-drive/src/mcp/tools/folder-path.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\nconst inputSchema = z.object({\n folderId: z.string().min(1).describe('Folder ID to get path for (or \"root\")'),\n});\n\n// Success branch schema - uses items: for consistency with standard vocabulary\nconst successBranchSchema = z.object({\n type: z.literal('success'),\n path: z.string().describe('Full path from root (e.g., /Work/Projects/2024)'),\n items: z\n .array(\n z.object({\n id: z.string().describe('Folder ID'),\n name: z.string().describe('Folder name'),\n })\n )\n .describe('Path items from root to target folder'),\n});\n\n// Output schema with auth_required support\nconst outputSchema = z.discriminatedUnion('type', [successBranchSchema, AuthRequiredBranchSchema]);\n\nconst config = {\n title: 'Get Folder Path',\n description: 'Get full path from folder to root. Returns human-readable path and items with IDs.',\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 * Resolves the full path for a folder by walking up the parent chain.\n * Returns both the path string and structured segments with IDs and names.\n */\nasync function resolveFolderPath(drive: drive_v3.Drive, folderId: string, logger: Logger): Promise<{ path: string; segments: Array<{ id: string; name: string }> }> {\n // Handle root specially\n if (folderId === 'root') {\n return {\n path: '/',\n segments: [{ id: 'root', name: 'My Drive' }],\n };\n }\n\n const segments: Array<{ id: string; name: string }> = [];\n let currentId = folderId;\n const visited = new Set<string>();\n\n // Walk up the parent chain\n while (currentId && currentId !== 'root') {\n // Prevent infinite loops\n if (visited.has(currentId)) {\n logger.info('Circular folder reference detected', {\n folderId: currentId,\n });\n break;\n }\n visited.add(currentId);\n\n // Fetch folder metadata\n try {\n const response = await drive.files.get({\n fileId: currentId,\n fields: 'id,name,parents',\n });\n\n const id = response.data.id as string;\n const name = (response.data.name as string) || id;\n const parents = response.data.parents as string[] | undefined;\n\n // Add to segments at beginning (we're walking from child to root)\n segments.unshift({ id, name });\n\n // Move to parent\n currentId = (parents && parents.length > 0 ? parents[0] : '') || '';\n } catch (e) {\n logger.info('Failed to resolve folder path', {\n folderId: currentId,\n error: e,\n });\n break;\n }\n }\n\n // Add root if we reached it\n if (currentId === 'root') {\n segments.unshift({ id: 'root', name: 'My Drive' });\n }\n\n // Build path string\n const pathParts = segments.slice(1).map((seg) => seg.name); // Skip root\n const path = pathParts.length > 0 ? `/${pathParts.join('/')}` : '/';\n\n return { path, segments };\n}\n\nasync function handler({ folderId }: Input, extra: EnrichedExtra): Promise<CallToolResult> {\n const logger = extra.logger;\n logger.info('drive.folder.path called', { folderId });\n\n try {\n const drive = google.drive({ version: 'v3', auth: extra.authContext.auth });\n\n const pathResult = await resolveFolderPath(drive, folderId, logger);\n\n logger.info('drive.folder.path returning', {\n path: pathResult.path,\n segmentCount: pathResult.segments.length,\n });\n\n const result: Output = {\n type: 'success' as const,\n path: pathResult.path,\n items: pathResult.segments,\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.folder.path error', { error: message });\n\n // Throw McpError\n throw new McpError(ErrorCode.InternalError, `Error getting folder path: ${message}`, {\n stack: error instanceof Error ? error.stack : undefined,\n });\n }\n}\n\nexport default function createTool() {\n return {\n name: 'folder-path' as const,\n config,\n handler,\n };\n}\n"],"names":["schemas","AuthRequiredBranchSchema","ErrorCode","McpError","google","z","inputSchema","object","folderId","string","min","describe","successBranchSchema","type","literal","path","items","array","id","name","outputSchema","discriminatedUnion","config","title","description","result","resolveFolderPath","drive","logger","segments","currentId","visited","Set","has","info","add","response","files","get","fileId","fields","data","parents","unshift","length","e","error","pathParts","slice","map","seg","join","handler","extra","version","auth","authContext","pathResult","segmentCount","content","text","JSON","stringify","structuredContent","message","Error","String","InternalError","stack","undefined","createTool"],"mappings":"AACA,SAASA,OAAO,QAAQ,sBAAsB;AAE9C,MAAM,EAAEC,wBAAwB,EAAE,GAAGD;AAErC,SAA8BE,SAAS,EAAEC,QAAQ,QAAQ,qCAAqC;AAE9F,SAASC,MAAM,QAAQ,aAAa;AACpC,SAASC,CAAC,QAAQ,MAAM;AAGxB,MAAMC,cAAcD,EAAEE,MAAM,CAAC;IAC3BC,UAAUH,EAAEI,MAAM,GAAGC,GAAG,CAAC,GAAGC,QAAQ,CAAC;AACvC;AAEA,+EAA+E;AAC/E,MAAMC,sBAAsBP,EAAEE,MAAM,CAAC;IACnCM,MAAMR,EAAES,OAAO,CAAC;IAChBC,MAAMV,EAAEI,MAAM,GAAGE,QAAQ,CAAC;IAC1BK,OAAOX,EACJY,KAAK,CACJZ,EAAEE,MAAM,CAAC;QACPW,IAAIb,EAAEI,MAAM,GAAGE,QAAQ,CAAC;QACxBQ,MAAMd,EAAEI,MAAM,GAAGE,QAAQ,CAAC;IAC5B,IAEDA,QAAQ,CAAC;AACd;AAEA,2CAA2C;AAC3C,MAAMS,eAAef,EAAEgB,kBAAkB,CAAC,QAAQ;IAACT;IAAqBX;CAAyB;AAEjG,MAAMqB,SAAS;IACbC,OAAO;IACPC,aAAa;IACblB,aAAaA;IACbc,cAAcf,EAAEE,MAAM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,OAAO;QACLnD,MAAM;QACNG;QACA8B;IACF;AACF"}
@@ -1 +1 @@
1
- {"version":3,"sources":["/Users/kevin/Dev/Projects/ai/mcp-z/servers/mcp-drive/src/mcp/tools/folder-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 } from 'googleapis';\nimport { google } from 'googleapis';\nimport { z } from 'zod';\nimport { toDriveQuery } from '../../lib/query-builder.js';\nimport { DRIVE_FILE_COMMON_PATTERNS, DRIVE_FILE_FIELD_DESCRIPTIONS, DRIVE_FILE_FIELDS, type DriveFile, DriveFileSchema, DriveQuerySchema } from '../../schemas/index.js';\nimport type { Logger } from '../../types.js';\n\nconst inputSchema = z.object({\n query: DriveQuerySchema.optional().describe('Drive query object with structured search fields. See DriveQuerySchema for detailed query syntax and examples.'),\n fields: createFieldsSchema({\n availableFields: [...DRIVE_FILE_FIELDS, 'path'] as const,\n fieldDescriptions: {\n ...DRIVE_FILE_FIELD_DESCRIPTIONS,\n path: 'Full folder path like /Work/Projects (requires resolvePaths=true)',\n },\n commonPatterns: DRIVE_FILE_COMMON_PATTERNS,\n resourceName: 'Drive folder',\n }),\n resolvePaths: z.boolean().optional().describe('Resolve full folder paths like /Work/Projects/2024 (requires additional API calls per result)'),\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.extend({ path: z.string().optional().describe('Full folder path (if resolvePaths=true)') })).describe('Matching Drive folders'),\n count: z.number().describe('Number of folders 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 folders 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 Folders',\n description: 'Search Google Drive folders with flexible field selection and optional path resolution.',\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 DriveFolder = {\n id?: string;\n name?: string;\n mimeType?: string;\n webViewLink?: string;\n modifiedTime?: string;\n parents?: string[];\n shared?: boolean;\n starred?: boolean;\n owners?: Array<{\n displayName?: string;\n emailAddress?: string;\n kind?: string;\n me?: boolean;\n permissionId?: string;\n photoLink?: string;\n }>;\n};\n\ntype DriveFolderResponse = {\n files?: DriveFolder[];\n nextPageToken?: string;\n};\n\n/**\n * Resolves the full path for a folder by walking up the parent chain\n * Caches folder names to reduce redundant API calls\n */\nasync function resolveFolderPath(drive: drive_v3.Drive, folderId: string, folderCache: Map<string, string>, logger: Logger): Promise<string> {\n if (folderId === 'root') return '/';\n\n const pathParts: string[] = [];\n let currentId = folderId;\n const visited = new Set<string>();\n\n while (currentId && currentId !== 'root') {\n // Prevent infinite loops\n if (visited.has(currentId)) {\n logger.info('Circular folder reference detected', {\n folderId: currentId,\n });\n break;\n }\n visited.add(currentId);\n\n // Check cache first\n if (folderCache.has(currentId)) {\n const cachedName = folderCache.get(currentId);\n if (cachedName) {\n pathParts.unshift(cachedName);\n }\n\n // Get parent of cached folder\n try {\n const response = await drive.files.get({\n fileId: currentId,\n fields: 'parents',\n });\n const parents = response.data.parents as string[] | undefined;\n currentId = (parents && parents.length > 0 ? parents[0] : '') || '';\n } catch (_e) {\n logger.info('Failed to get parent for cached folder', {\n folderId: currentId,\n });\n break;\n }\n } else {\n // Fetch folder metadata\n try {\n const response = await drive.files.get({\n fileId: currentId,\n fields: 'name,parents',\n });\n const folderName = response.data.name as string | undefined;\n const parents = response.data.parents as string[] | undefined;\n\n if (folderName) {\n folderCache.set(currentId, folderName);\n pathParts.unshift(folderName);\n }\n\n currentId = (parents && parents.length > 0 ? parents[0] : '') || '';\n } catch (e) {\n logger.info('Failed to resolve folder path', {\n folderId: currentId,\n error: e,\n });\n break;\n }\n }\n }\n\n return `/${pathParts.join('/')}`;\n}\n\nasync function handler({ query, resolvePaths = false, pageSize = 50, pageToken, fields, shape = 'arrays' }: Input, extra: EnrichedExtra): Promise<CallToolResult> {\n const logger = extra.logger;\n\n const requestedFields = parseFields(fields, [...DRIVE_FILE_FIELDS, 'path'] as const);\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.folder.search called', {\n query,\n resolvePaths,\n pageSize: validPageSize,\n pageToken: pageToken ? '[provided]' : undefined,\n fields: fields || 'all',\n });\n\n try {\n const drive = google.drive({ version: 'v3', auth: extra.authContext.auth });\n\n const folderMimeType = 'application/vnd.google-apps.folder';\n let qStr: string;\n\n if (typeof query === 'string') {\n // String query - treat as raw Drive query\n qStr = `(${query}) and mimeType='${folderMimeType}' and trashed = false`;\n } else if (query && typeof query === 'object' && 'rawDriveQuery' in query && query.rawDriveQuery) {\n // Object with rawDriveQuery field - use it directly\n qStr = `(${query.rawDriveQuery}) and mimeType='${folderMimeType}' and trashed = false`;\n } else if (query) {\n // Structured query object - convert to Drive query string\n const { q } = toDriveQuery(query);\n qStr = q ? `(${q}) and mimeType='${folderMimeType}' and trashed = false` : `mimeType='${folderMimeType}' and trashed = false`;\n } else {\n // No query - return all folders\n qStr = `mimeType='${folderMimeType}' and trashed = false`;\n }\n\n const listOptions: {\n q: string;\n pageSize: number;\n fields: string;\n orderBy: string;\n pageToken?: string;\n } = {\n q: qStr,\n pageSize: validPageSize,\n fields: 'files(id,name,mimeType,webViewLink,modifiedTime,parents,shared,starred,owners),nextPageToken',\n orderBy: 'modifiedTime desc',\n };\n if (pageToken && pageToken.trim().length > 0) {\n listOptions.pageToken = pageToken;\n }\n\n const response = await drive.files.list(listOptions);\n\n const res = response.data as DriveFolderResponse;\n const folders = Array.isArray(res?.files) ? res.files : [];\n\n const parentIds = new Set<string>();\n for (const f of folders) {\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 // Cache for folder names to reduce API calls during path resolution\n const folderCache = new Map<string, string>();\n\n const items: (DriveFile & { path?: string })[] = await Promise.all(\n folders.map(async (f: DriveFolder) => {\n const id = f?.id ? String(f.id) : 'unknown';\n const name = f?.name || id;\n const result: DriveFile & { path?: string } = { 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 // Build parent objects with names\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 !== undefined) result.shared = f.shared;\n if (f?.starred !== undefined) 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 !== undefined) 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 // Resolve path if requested\n if (resolvePaths && id !== 'unknown') {\n result.path = await resolveFolderPath(drive, id, folderCache, logger);\n }\n\n return result;\n })\n );\n\n const filteredItems = items.map((item) => filterFields(item, requestedFields));\n\n logger.info('drive.folder.search returning', {\n query,\n pageSize,\n resultCount: filteredItems.length,\n resolvePaths,\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, 'path'] as const),\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.folder.search error', { error: message });\n\n // Check if this is a Drive API validation error (invalid query, invalid pageToken, etc.)\n // These should return empty results rather than throw\n const isDriveValidationError = message.includes('Invalid Value') || message.includes('Invalid value') || message.includes('File not found') || message.includes('Bad Request');\n\n if (isDriveValidationError) {\n // Return empty result set for validation errors\n const result: Output =\n shape === 'arrays'\n ? {\n type: 'success' as const,\n shape: 'arrays' as const,\n columns: [],\n rows: [],\n count: 0,\n }\n : {\n type: 'success' as const,\n shape: 'objects' as const,\n items: [],\n count: 0,\n };\n\n return {\n content: [\n {\n type: 'text' as const,\n text: JSON.stringify(result),\n },\n ],\n structuredContent: { result },\n };\n }\n\n // Throw McpError for other errors\n throw new McpError(ErrorCode.InternalError, `Error searching folders: ${message}`, {\n stack: error instanceof Error ? error.stack : undefined,\n });\n }\n}\n\nexport default function createTool() {\n return {\n name: 'folder-search' as const,\n config,\n handler,\n };\n}\n"],"names":["schemas","AuthRequiredBranchSchema","createFieldsSchema","createPaginationSchema","createShapeSchema","filterFields","parseFields","toColumnarFormat","ErrorCode","McpError","google","z","toDriveQuery","DRIVE_FILE_COMMON_PATTERNS","DRIVE_FILE_FIELD_DESCRIPTIONS","DRIVE_FILE_FIELDS","DriveFileSchema","DriveQuerySchema","inputSchema","object","query","optional","describe","fields","availableFields","fieldDescriptions","path","commonPatterns","resourceName","resolvePaths","boolean","defaultPageSize","maxPageSize","provider","shape","successObjectsBranchSchema","type","literal","items","array","extend","string","count","number","nextPageToken","successArraysBranchSchema","columns","rows","unknown","outputSchema","union","config","title","description","result","resolveFolderPath","drive","folderId","folderCache","logger","pathParts","currentId","visited","Set","has","info","add","cachedName","get","unshift","response","files","fileId","parents","data","length","_e","folderName","name","set","e","error","join","handler","pageSize","pageToken","extra","requestedFields","validPageSize","Math","max","min","floor","undefined","version","auth","authContext","folderMimeType","qStr","rawDriveQuery","q","listOptions","orderBy","trim","list","res","folders","Array","isArray","parentIds","f","parentId","parentNameMap","Map","size","parentFetches","from","map","parentRes","parentName","Promise","all","id","String","mimeType","webViewLink","modifiedTime","shared","starred","owners","o","owner","displayName","emailAddress","kind","me","permissionId","photoLink","filteredItems","item","resultCount","content","text","JSON","stringify","structuredContent","message","Error","isDriveValidationError","includes","Internal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mcp/tools/folder-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 } from 'googleapis';\nimport { 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, DriveQuerySchema } from '../../schemas/index.ts';\nimport type { Logger } from '../../types.ts';\n\nconst inputSchema = z.object({\n query: DriveQuerySchema.optional().describe('Drive query object with structured search fields. See DriveQuerySchema for detailed query syntax and examples.'),\n fields: createFieldsSchema({\n availableFields: [...DRIVE_FILE_FIELDS, 'path'] as const,\n fieldDescriptions: {\n ...DRIVE_FILE_FIELD_DESCRIPTIONS,\n path: 'Full folder path like /Work/Projects (requires resolvePaths=true)',\n },\n commonPatterns: DRIVE_FILE_COMMON_PATTERNS,\n resourceName: 'Drive folder',\n }),\n resolvePaths: z.boolean().optional().describe('Resolve full folder paths like /Work/Projects/2024 (requires additional API calls per result)'),\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.extend({ path: z.string().optional().describe('Full folder path (if resolvePaths=true)') })).describe('Matching Drive folders'),\n count: z.number().describe('Number of folders 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 folders 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 Folders',\n description: 'Search Google Drive folders with flexible field selection and optional path resolution.',\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 DriveFolder = {\n id?: string;\n name?: string;\n mimeType?: string;\n webViewLink?: string;\n modifiedTime?: string;\n parents?: string[];\n shared?: boolean;\n starred?: boolean;\n owners?: Array<{\n displayName?: string;\n emailAddress?: string;\n kind?: string;\n me?: boolean;\n permissionId?: string;\n photoLink?: string;\n }>;\n};\n\ntype DriveFolderResponse = {\n files?: DriveFolder[];\n nextPageToken?: string;\n};\n\n/**\n * Resolves the full path for a folder by walking up the parent chain\n * Caches folder names to reduce redundant API calls\n */\nasync function resolveFolderPath(drive: drive_v3.Drive, folderId: string, folderCache: Map<string, string>, logger: Logger): Promise<string> {\n if (folderId === 'root') return '/';\n\n const pathParts: string[] = [];\n let currentId = folderId;\n const visited = new Set<string>();\n\n while (currentId && currentId !== 'root') {\n // Prevent infinite loops\n if (visited.has(currentId)) {\n logger.info('Circular folder reference detected', {\n folderId: currentId,\n });\n break;\n }\n visited.add(currentId);\n\n // Check cache first\n if (folderCache.has(currentId)) {\n const cachedName = folderCache.get(currentId);\n if (cachedName) {\n pathParts.unshift(cachedName);\n }\n\n // Get parent of cached folder\n try {\n const response = await drive.files.get({\n fileId: currentId,\n fields: 'parents',\n });\n const parents = response.data.parents as string[] | undefined;\n currentId = (parents && parents.length > 0 ? parents[0] : '') || '';\n } catch (_e) {\n logger.info('Failed to get parent for cached folder', {\n folderId: currentId,\n });\n break;\n }\n } else {\n // Fetch folder metadata\n try {\n const response = await drive.files.get({\n fileId: currentId,\n fields: 'name,parents',\n });\n const folderName = response.data.name as string | undefined;\n const parents = response.data.parents as string[] | undefined;\n\n if (folderName) {\n folderCache.set(currentId, folderName);\n pathParts.unshift(folderName);\n }\n\n currentId = (parents && parents.length > 0 ? parents[0] : '') || '';\n } catch (e) {\n logger.info('Failed to resolve folder path', {\n folderId: currentId,\n error: e,\n });\n break;\n }\n }\n }\n\n return `/${pathParts.join('/')}`;\n}\n\nasync function handler({ query, resolvePaths = false, pageSize = 50, pageToken, fields, shape = 'arrays' }: Input, extra: EnrichedExtra): Promise<CallToolResult> {\n const logger = extra.logger;\n\n const requestedFields = parseFields(fields, [...DRIVE_FILE_FIELDS, 'path'] as const);\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.folder.search called', {\n query,\n resolvePaths,\n pageSize: validPageSize,\n pageToken: pageToken ? '[provided]' : undefined,\n fields: fields || 'all',\n });\n\n try {\n const drive = google.drive({ version: 'v3', auth: extra.authContext.auth });\n\n const folderMimeType = 'application/vnd.google-apps.folder';\n let qStr: string;\n\n if (typeof query === 'string') {\n // String query - treat as raw Drive query\n qStr = `(${query}) and mimeType='${folderMimeType}' and trashed = false`;\n } else if (query && typeof query === 'object' && 'rawDriveQuery' in query && query.rawDriveQuery) {\n // Object with rawDriveQuery field - use it directly\n qStr = `(${query.rawDriveQuery}) and mimeType='${folderMimeType}' and trashed = false`;\n } else if (query) {\n // Structured query object - convert to Drive query string\n const { q } = toDriveQuery(query);\n qStr = q ? `(${q}) and mimeType='${folderMimeType}' and trashed = false` : `mimeType='${folderMimeType}' and trashed = false`;\n } else {\n // No query - return all folders\n qStr = `mimeType='${folderMimeType}' and trashed = false`;\n }\n\n const listOptions: {\n q: string;\n pageSize: number;\n fields: string;\n orderBy: string;\n pageToken?: string;\n } = {\n q: qStr,\n pageSize: validPageSize,\n fields: 'files(id,name,mimeType,webViewLink,modifiedTime,parents,shared,starred,owners),nextPageToken',\n orderBy: 'modifiedTime desc',\n };\n if (pageToken && pageToken.trim().length > 0) {\n listOptions.pageToken = pageToken;\n }\n\n const response = await drive.files.list(listOptions);\n\n const res = response.data as DriveFolderResponse;\n const folders = Array.isArray(res?.files) ? res.files : [];\n\n const parentIds = new Set<string>();\n for (const f of folders) {\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 // Cache for folder names to reduce API calls during path resolution\n const folderCache = new Map<string, string>();\n\n const items: (DriveFile & { path?: string })[] = await Promise.all(\n folders.map(async (f: DriveFolder) => {\n const id = f?.id ? String(f.id) : 'unknown';\n const name = f?.name || id;\n const result: DriveFile & { path?: string } = { 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 // Build parent objects with names\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 !== undefined) result.shared = f.shared;\n if (f?.starred !== undefined) 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 !== undefined) 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 // Resolve path if requested\n if (resolvePaths && id !== 'unknown') {\n result.path = await resolveFolderPath(drive, id, folderCache, logger);\n }\n\n return result;\n })\n );\n\n const filteredItems = items.map((item) => filterFields(item, requestedFields));\n\n logger.info('drive.folder.search returning', {\n query,\n pageSize,\n resultCount: filteredItems.length,\n resolvePaths,\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, 'path'] as const),\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.folder.search error', { error: message });\n\n // Check if this is a Drive API validation error (invalid query, invalid pageToken, etc.)\n // These should return empty results rather than throw\n const isDriveValidationError = message.includes('Invalid Value') || message.includes('Invalid value') || message.includes('File not found') || message.includes('Bad Request');\n\n if (isDriveValidationError) {\n // Return empty result set for validation errors\n const result: Output =\n shape === 'arrays'\n ? {\n type: 'success' as const,\n shape: 'arrays' as const,\n columns: [],\n rows: [],\n count: 0,\n }\n : {\n type: 'success' as const,\n shape: 'objects' as const,\n items: [],\n count: 0,\n };\n\n return {\n content: [\n {\n type: 'text' as const,\n text: JSON.stringify(result),\n },\n ],\n structuredContent: { result },\n };\n }\n\n // Throw McpError for other errors\n throw new McpError(ErrorCode.InternalError, `Error searching folders: ${message}`, {\n stack: error instanceof Error ? error.stack : undefined,\n });\n }\n}\n\nexport default function createTool() {\n return {\n name: 'folder-search' as const,\n config,\n handler,\n };\n}\n"],"names":["schemas","AuthRequiredBranchSchema","createFieldsSchema","createPaginationSchema","createShapeSchema","filterFields","parseFields","toColumnarFormat","ErrorCode","McpError","google","z","toDriveQuery","DRIVE_FILE_COMMON_PATTERNS","DRIVE_FILE_FIELD_DESCRIPTIONS","DRIVE_FILE_FIELDS","DriveFileSchema","DriveQuerySchema","inputSchema","object","query","optional","describe","fields","availableFields","fieldDescriptions","path","commonPatterns","resourceName","resolvePaths","boolean","defaultPageSize","maxPageSize","provider","shape","successObjectsBranchSchema","type","literal","items","array","extend","string","count","number","nextPageToken","successArraysBranchSchema","columns","rows","unknown","outputSchema","union","config","title","description","result","resolveFolderPath","drive","folderId","folderCache","logger","pathParts","currentId","visited","Set","has","info","add","cachedName","get","unshift","response","files","fileId","parents","data","length","_e","folderName","name","set","e","error","join","handler","pageSize","pageToken","extra","requestedFields","validPageSize","Math","max","min","floor","undefined","version","auth","authContext","folderMimeType","qStr","rawDriveQuery","q","listOptions","orderBy","trim","list","res","folders","Array","isArray","parentIds","f","parentId","parentNameMap","Map","size","parentFetches","from","map","parentRes","parentName","Promise","all","id","String","mimeType","webViewLink","modifiedTime","shared","starred","owners","o","owner","displayName","emailAddress","kind","me","permissionId","photoLink","filteredItems","item","resultCount","content","text","JSON","stringify","structuredContent","message","Error","isDriveValidationError","includes","InternalError","stack","createTool"],"mappings":"AACA,SAASA,OAAO,QAAQ,sBAAsB;AAE9C,MAAM,EAAEC,wBAAwB,EAAE,GAAGD;AAErC,SAASE,kBAAkB,EAA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AEN,OAAO;YACLiG,SAAS;gBACP;oBACEzG,MAAM;oBACN0G,MAAMC,KAAKC,SAAS,CAAC1F;gBACvB;aACD;YACD2F,mBAAmB;gBAAE3F;YAAO;QAC9B;IACF,EAAE,OAAO2B,OAAO;QACd,MAAMiE,UAAUjE,iBAAiBkE,QAAQlE,MAAMiE,OAAO,GAAGvB,OAAO1C;QAChEtB,OAAOsB,KAAK,CAAC,6BAA6B;YAAEA,OAAOiE;QAAQ;QAE3D,yFAAyF;QACzF,sDAAsD;QACtD,MAAME,yBAAyBF,QAAQG,QAAQ,CAAC,oBAAoBH,QAAQG,QAAQ,CAAC,oBAAoBH,QAAQG,QAAQ,CAAC,qBAAqBH,QAAQG,QAAQ,CAAC;QAEhK,IAAID,wBAAwB;YAC1B,gDAAgD;YAChD,MAAM9F,SACJpB,UAAU,WACN;gBACEE,MAAM;gBACNF,OAAO;gBACPY,SAAS,EAAE;gBACXC,MAAM,EAAE;gBACRL,OAAO;YACT,IACA;gBACEN,MAAM;gBACNF,OAAO;gBACPI,OAAO,EAAE;gBACTI,OAAO;YACT;YAEN,OAAO;gBACLmG,SAAS;oBACP;wBACEzG,MAAM;wBACN0G,MAAMC,KAAKC,SAAS,CAAC1F;oBACvB;iBACD;gBACD2F,mBAAmB;oBAAE3F;gBAAO;YAC9B;QACF;QAEA,kCAAkC;QAClC,MAAM,IAAI7C,SAASD,UAAU8I,aAAa,EAAE,CAAC,yBAAyB,EAAEJ,SAAS,EAAE;YACjFK,OAAOtE,iBAAiBkE,QAAQlE,MAAMsE,KAAK,GAAG1D;QAChD;IACF;AACF;AAEA,eAAe,SAAS2D;IACtB,OAAO;QACL1E,MAAM;QACN3B;QACAgC;IACF;AACF"}
@@ -1 +1 @@
1
- {"version":3,"sources":["/Users/kevin/Dev/Projects/ai/mcp-z/servers/mcp-drive/src/mcp/tools/index.ts"],"sourcesContent":["export { default as fileMove } from './file-move.js';\nexport { default as fileMoveToTrash } from './file-move-to-trash.js';\nexport { default as filesSearch } from './files-search.js';\nexport { default as folderContents } from './folder-contents.js';\nexport { default as folderCreate } from './folder-create.js';\nexport { default as folderPath } from './folder-path.js';\nexport { default as folderSearch } from './folder-search.js';\n"],"names":["default","fileMove","fileMoveToTrash","filesSearch","folderContents","folderCreate","folderPath","folderSearch"],"mappings":"AAAA,SAASA,WAAWC,QAAQ,QAAQ,iBAAiB;AACrD,SAASD,WAAWE,eAAe,QAAQ,0BAA0B;AACrE,SAASF,WAAWG,WAAW,QAAQ,oBAAoB;AAC3D,SAASH,WAAWI,cAAc,QAAQ,uBAAuB;AACjE,SAASJ,WAAWK,YAAY,QAAQ,qBAAqB;AAC7D,SAASL,WAAWM,UAAU,QAAQ,mBAAmB;AACzD,SAASN,WAAWO,YAAY,QAAQ,qBAAqB"}
1
+ {"version":3,"sources":["/Users/kevin/Dev/Projects/mcp-z/mcp-drive/src/mcp/tools/index.ts"],"sourcesContent":["export { default as fileMove } from './file-move.ts';\nexport { default as fileMoveToTrash } from './file-move-to-trash.ts';\nexport { default as filesSearch } from './files-search.ts';\nexport { default as folderContents } from './folder-contents.ts';\nexport { default as folderCreate } from './folder-create.ts';\nexport { default as folderPath } from './folder-path.ts';\nexport { default as folderSearch } from './folder-search.ts';\n"],"names":["default","fileMove","fileMoveToTrash","filesSearch","folderContents","folderCreate","folderPath","folderSearch"],"mappings":"AAAA,SAASA,WAAWC,QAAQ,QAAQ,iBAAiB;AACrD,SAASD,WAAWE,eAAe,QAAQ,0BAA0B;AACrE,SAASF,WAAWG,WAAW,QAAQ,oBAAoB;AAC3D,SAASH,WAAWI,cAAc,QAAQ,uBAAuB;AACjE,SAASJ,WAAWK,YAAY,QAAQ,qBAAqB;AAC7D,SAASL,WAAWM,UAAU,QAAQ,mBAAmB;AACzD,SAASN,WAAWO,YAAY,QAAQ,qBAAqB"}
@@ -3,7 +3,7 @@ import { z } from 'zod';
3
3
  * Field operator schema for Drive query fields that support multiple values
4
4
  * Supports OR ($any), AND ($all), and NOT ($none) operations
5
5
  */
6
- declare const FieldOperatorSchema: z.ZodObject<{
6
+ export declare const FieldOperatorSchema: z.ZodObject<{
7
7
  $any: z.ZodOptional<z.ZodArray<z.ZodString>>;
8
8
  $all: z.ZodOptional<z.ZodArray<z.ZodString>>;
9
9
  $none: z.ZodOptional<z.ZodArray<z.ZodString>>;
@@ -37,4 +37,3 @@ export type DriveQueryObject = {
37
37
  */
38
38
  export declare const DriveQuerySchema: z.ZodUnion<readonly [z.ZodString, z.ZodType<DriveQueryObject, unknown, z.core.$ZodTypeInternals<DriveQueryObject, unknown>>]>;
39
39
  export type DriveQuery = string | DriveQueryObject;
40
- export {};
@@ -2,7 +2,7 @@ import { z } from 'zod';
2
2
  /**
3
3
  * Field operator schema for Drive query fields that support multiple values
4
4
  * Supports OR ($any), AND ($all), and NOT ($none) operations
5
- */ const FieldOperatorSchema = z.object({
5
+ */ export const FieldOperatorSchema = z.object({
6
6
  $any: z.array(z.string()).optional().describe('OR within field - matches if ANY value matches'),
7
7
  $all: z.array(z.string()).optional().describe('AND within field - matches if ALL values match'),
8
8
  $none: z.array(z.string()).optional().describe('NOT within field - matches if NONE match')
@@ -1 +1 @@
1
- {"version":3,"sources":["/Users/kevin/Dev/Projects/ai/mcp-z/servers/mcp-drive/src/schemas/drive-query-schema.ts"],"sourcesContent":["import { z } from 'zod';\n\n/**\n * Field operator schema for Drive query fields that support multiple values\n * Supports OR ($any), AND ($all), and NOT ($none) operations\n */\nconst FieldOperatorSchema = z\n .object({\n $any: z.array(z.string()).optional().describe('OR within field - matches if ANY value matches'),\n $all: z.array(z.string()).optional().describe('AND within field - matches if ALL values match'),\n $none: z.array(z.string()).optional().describe('NOT within field - matches if NONE match'),\n })\n .strict();\n\nexport type FieldOperator = z.infer<typeof FieldOperatorSchema>;\n\n/**\n * Drive query object schema with recursive operators and Drive features.\n *\n * Includes Drive-specific features:\n * - name: Search by file/folder name (supports string or field operators)\n * - mimeType: Filter by MIME type (e.g., \"application/pdf\", \"application/vnd.google-apps.folder\")\n * - fullText: Search file content and metadata\n * - parentId: Search within specific folder (supports string or field operators)\n * - starred: Filter by starred status\n * - shared: Filter by shared status\n * - modifiedTime: Date range filtering with $gte and $lt\n * - owner: Filter by owner email (supports string or field operators)\n * - rawDriveQuery: Escape hatch for advanced Drive query syntax\n *\n * Logical operators:\n * - $and: Array of conditions that must ALL match (recursive)\n * - $or: Array of conditions where ANY must match (recursive)\n * - $not: Nested condition that must NOT match (recursive)\n *\n * Note: Cast through unknown to work around Zod's lazy schema type inference issue\n * with exactOptionalPropertyTypes. The runtime schema is correct; this cast ensures\n * TypeScript sees the strict DriveQueryObject type everywhere the schema is used.\n */\nconst DriveQueryObjectSchema = z.lazy(() =>\n z\n .object({\n // Logical operators for combining conditions (recursive)\n $and: z.array(DriveQueryObjectSchema).optional().describe('Array of conditions that must ALL match'),\n $or: z.array(DriveQueryObjectSchema).optional().describe('Array of conditions where ANY must match'),\n $not: DriveQueryObjectSchema.optional().describe('Nested condition that must NOT match'),\n\n // File/folder name search\n name: z\n .union([z.string().min(1), FieldOperatorSchema])\n .optional()\n .describe('Search by file or folder name (partial match, case-insensitive)'),\n\n // MIME type filtering\n mimeType: z\n .union([z.string().min(1), FieldOperatorSchema])\n .optional()\n .describe('Filter by MIME type (e.g., \"application/pdf\", \"application/vnd.google-apps.folder\", \"image/jpeg\")'),\n\n // Full-text search across content and metadata\n fullText: z\n .union([z.string().min(1), FieldOperatorSchema])\n .optional()\n .describe('Search file content and metadata (full-text search)'),\n\n // Parent folder filtering\n parentId: z\n .union([z.string().min(1), FieldOperatorSchema])\n .optional()\n .describe('Search within specific folder by folder ID (use \"root\" for My Drive root)'),\n\n // Boolean flags\n starred: z.boolean().optional().describe('Filter by starred status (true = starred, false = not starred)'),\n sharedWithMe: z.boolean().optional().describe('Filter by \"shared with me\" collection (true = in shared collection, false = not shared)'),\n trashed: z.boolean().optional().describe('Filter by trash status (true = in trash, false = not in trash). Note: Drive tools automatically filter out trashed files unless explicitly requested.'),\n\n // Date range filtering\n modifiedTime: z\n .object({\n $gte: z\n .string()\n .regex(/^\\d{4}-\\d{2}-\\d{2}(T\\d{2}:\\d{2}:\\d{2}(\\.\\d{3})?Z)?$/)\n .optional()\n .describe('Files modified on or after this date (ISO 8601: YYYY-MM-DD or YYYY-MM-DDTHH:mm:ss.sssZ)'),\n $lt: z\n .string()\n .regex(/^\\d{4}-\\d{2}-\\d{2}(T\\d{2}:\\d{2}:\\d{2}(\\.\\d{3})?Z)?$/)\n .optional()\n .describe('Files modified before this date (ISO 8601: YYYY-MM-DD or YYYY-MM-DDTHH:mm:ss.sssZ)'),\n })\n .optional()\n .describe('Filter by modification date range'),\n\n // Owner filtering\n owner: z\n .union([z.string().min(1), FieldOperatorSchema])\n .optional()\n .describe('Filter by owner email address (partial match)'),\n\n // Raw Drive query string - escape hatch for advanced syntax\n rawDriveQuery: z.string().min(1).optional().describe(\"Raw Google Drive query syntax for advanced use cases. Bypasses schema validation - use sparingly. Example: \\\"name contains 'budget' and mimeType = 'application/pdf'\\\"\"),\n })\n .strict()\n) as unknown as z.ZodType<DriveQueryObject>;\n\nexport type DriveQueryObject = {\n $and?: DriveQueryObject[];\n $or?: DriveQueryObject[];\n $not?: DriveQueryObject;\n name?: string | FieldOperator;\n mimeType?: string | FieldOperator;\n fullText?: string | FieldOperator;\n parentId?: string | FieldOperator;\n starred?: boolean;\n sharedWithMe?: boolean;\n trashed?: boolean;\n modifiedTime?: {\n $gte?: string;\n $lt?: string;\n };\n owner?: string | FieldOperator;\n rawDriveQuery?: string;\n};\n\n/**\n * Drive query schema that accepts either:\n * - A structured DriveQueryObject with typed fields\n * - A raw Drive query string for advanced use cases\n *\n * This provides type safety for common queries while allowing\n * direct Google Drive query syntax when needed.\n */\nexport const DriveQuerySchema = z.union([z.string().min(1), DriveQueryObjectSchema]);\n\nexport type DriveQuery = string | DriveQueryObject;\n"],"names":["z","FieldOperatorSchema","object","$any","array","string","optional","describe","$all","$none","strict","DriveQueryObjectSchema","lazy","$and","$or","$not","name","union","min","mimeType","fullText","parentId","starred","boolean","sharedWithMe","trashed","modifiedTime","$gte","regex","$lt","owner","rawDriveQuery","DriveQuerySchema"],"mappings":"AAAA,SAASA,CAAC,QAAQ,MAAM;AAExB;;;CAGC,GACD,MAAMC,sBAAsBD,EACzBE,MAAM,CAAC;IACNC,MAAMH,EAAEI,KAAK,CAACJ,EAAEK,MAAM,IAAIC,QAAQ,GAAGC,QAAQ,CAAC;IAC9CC,MAAMR,EAAEI,KAAK,CAACJ,EAAEK,MAAM,IAAIC,QAAQ,GAAGC,QAAQ,CAAC;IAC9CE,OAAOT,EAAEI,KAAK,CAACJ,EAAEK,MAAM,IAAIC,QAAQ,GAAGC,QAAQ,CAAC;AACjD,GACCG,MAAM;AAIT;;;;;;;;;;;;;;;;;;;;;;CAsBC,GACD,MAAMC,yBAAyBX,EAAEY,IAAI,CAAC,IACpCZ,EACGE,MAAM,CAAC;QACN,yDAAyD;QACzDW,MAAMb,EAAEI,KAAK,CAACO,wBAAwBL,QAAQ,GAAGC,QAAQ,CAAC;QAC1DO,KAAKd,EAAEI,KAAK,CAACO,wBAAwBL,QAAQ,GAAGC,QAAQ,CAAC;QACzDQ,MAAMJ,uBAAuBL,QAAQ,GAAGC,QAAQ,CAAC;QAEjD,0BAA0B;QAC1BS,MAAMhB,EACHiB,KAAK,CAAC;YAACjB,EAAEK,MAAM,GAAGa,GAAG,CAAC;YAAIjB;SAAoB,EAC9CK,QAAQ,GACRC,QAAQ,CAAC;QAEZ,sBAAsB;QACtBY,UAAUnB,EACPiB,KAAK,CAAC;YAACjB,EAAEK,MAAM,GAAGa,GAAG,CAAC;YAAIjB;SAAoB,EAC9CK,QAAQ,GACRC,QAAQ,CAAC;QAEZ,+CAA+C;QAC/Ca,UAAUpB,EACPiB,KAAK,CAAC;YAACjB,EAAEK,MAAM,GAAGa,GAAG,CAAC;YAAIjB;SAAoB,EAC9CK,QAAQ,GACRC,QAAQ,CAAC;QAEZ,0BAA0B;QAC1Bc,UAAUrB,EACPiB,KAAK,CAAC;YAACjB,EAAEK,MAAM,GAAGa,GAAG,CAAC;YAAIjB;SAAoB,EAC9CK,QAAQ,GACRC,QAAQ,CAAC;QAEZ,gBAAgB;QAChBe,SAAStB,EAAEuB,OAAO,GAAGjB,QAAQ,GAAGC,QAAQ,CAAC;QACzCiB,cAAcxB,EAAEuB,OAAO,GAAGjB,QAAQ,GAAGC,QAAQ,CAAC;QAC9CkB,SAASzB,EAAEuB,OAAO,GAAGjB,QAAQ,GAAGC,QAAQ,CAAC;QAEzC,uBAAuB;QACvBmB,cAAc1B,EACXE,MAAM,CAAC;YACNyB,MAAM3B,EACHK,MAAM,GACNuB,KAAK,CAAC,uDACNtB,QAAQ,GACRC,QAAQ,CAAC;YACZsB,KAAK7B,EACFK,MAAM,GACNuB,KAAK,CAAC,uDACNtB,QAAQ,GACRC,QAAQ,CAAC;QACd,GACCD,QAAQ,GACRC,QAAQ,CAAC;QAEZ,kBAAkB;QAClBuB,OAAO9B,EACJiB,KAAK,CAAC;YAACjB,EAAEK,MAAM,GAAGa,GAAG,CAAC;YAAIjB;SAAoB,EAC9CK,QAAQ,GACRC,QAAQ,CAAC;QAEZ,4DAA4D;QAC5DwB,eAAe/B,EAAEK,MAAM,GAAGa,GAAG,CAAC,GAAGZ,QAAQ,GAAGC,QAAQ,CAAC;IACvD,GACCG,MAAM;AAsBX;;;;;;;CAOC,GACD,OAAO,MAAMsB,mBAAmBhC,EAAEiB,KAAK,CAAC;IAACjB,EAAEK,MAAM,GAAGa,GAAG,CAAC;IAAIP;CAAuB,EAAE"}
1
+ {"version":3,"sources":["/Users/kevin/Dev/Projects/mcp-z/mcp-drive/src/schemas/drive-query-schema.ts"],"sourcesContent":["import { z } from 'zod';\n\n/**\n * Field operator schema for Drive query fields that support multiple values\n * Supports OR ($any), AND ($all), and NOT ($none) operations\n */\nexport const FieldOperatorSchema = z\n .object({\n $any: z.array(z.string()).optional().describe('OR within field - matches if ANY value matches'),\n $all: z.array(z.string()).optional().describe('AND within field - matches if ALL values match'),\n $none: z.array(z.string()).optional().describe('NOT within field - matches if NONE match'),\n })\n .strict();\n\nexport type FieldOperator = z.infer<typeof FieldOperatorSchema>;\n\n/**\n * Drive query object schema with recursive operators and Drive features.\n *\n * Includes Drive-specific features:\n * - name: Search by file/folder name (supports string or field operators)\n * - mimeType: Filter by MIME type (e.g., \"application/pdf\", \"application/vnd.google-apps.folder\")\n * - fullText: Search file content and metadata\n * - parentId: Search within specific folder (supports string or field operators)\n * - starred: Filter by starred status\n * - shared: Filter by shared status\n * - modifiedTime: Date range filtering with $gte and $lt\n * - owner: Filter by owner email (supports string or field operators)\n * - rawDriveQuery: Escape hatch for advanced Drive query syntax\n *\n * Logical operators:\n * - $and: Array of conditions that must ALL match (recursive)\n * - $or: Array of conditions where ANY must match (recursive)\n * - $not: Nested condition that must NOT match (recursive)\n *\n * Note: Cast through unknown to work around Zod's lazy schema type inference issue\n * with exactOptionalPropertyTypes. The runtime schema is correct; this cast ensures\n * TypeScript sees the strict DriveQueryObject type everywhere the schema is used.\n */\nconst DriveQueryObjectSchema = z.lazy(() =>\n z\n .object({\n // Logical operators for combining conditions (recursive)\n $and: z.array(DriveQueryObjectSchema).optional().describe('Array of conditions that must ALL match'),\n $or: z.array(DriveQueryObjectSchema).optional().describe('Array of conditions where ANY must match'),\n $not: DriveQueryObjectSchema.optional().describe('Nested condition that must NOT match'),\n\n // File/folder name search\n name: z\n .union([z.string().min(1), FieldOperatorSchema])\n .optional()\n .describe('Search by file or folder name (partial match, case-insensitive)'),\n\n // MIME type filtering\n mimeType: z\n .union([z.string().min(1), FieldOperatorSchema])\n .optional()\n .describe('Filter by MIME type (e.g., \"application/pdf\", \"application/vnd.google-apps.folder\", \"image/jpeg\")'),\n\n // Full-text search across content and metadata\n fullText: z\n .union([z.string().min(1), FieldOperatorSchema])\n .optional()\n .describe('Search file content and metadata (full-text search)'),\n\n // Parent folder filtering\n parentId: z\n .union([z.string().min(1), FieldOperatorSchema])\n .optional()\n .describe('Search within specific folder by folder ID (use \"root\" for My Drive root)'),\n\n // Boolean flags\n starred: z.boolean().optional().describe('Filter by starred status (true = starred, false = not starred)'),\n sharedWithMe: z.boolean().optional().describe('Filter by \"shared with me\" collection (true = in shared collection, false = not shared)'),\n trashed: z.boolean().optional().describe('Filter by trash status (true = in trash, false = not in trash). Note: Drive tools automatically filter out trashed files unless explicitly requested.'),\n\n // Date range filtering\n modifiedTime: z\n .object({\n $gte: z\n .string()\n .regex(/^\\d{4}-\\d{2}-\\d{2}(T\\d{2}:\\d{2}:\\d{2}(\\.\\d{3})?Z)?$/)\n .optional()\n .describe('Files modified on or after this date (ISO 8601: YYYY-MM-DD or YYYY-MM-DDTHH:mm:ss.sssZ)'),\n $lt: z\n .string()\n .regex(/^\\d{4}-\\d{2}-\\d{2}(T\\d{2}:\\d{2}:\\d{2}(\\.\\d{3})?Z)?$/)\n .optional()\n .describe('Files modified before this date (ISO 8601: YYYY-MM-DD or YYYY-MM-DDTHH:mm:ss.sssZ)'),\n })\n .optional()\n .describe('Filter by modification date range'),\n\n // Owner filtering\n owner: z\n .union([z.string().min(1), FieldOperatorSchema])\n .optional()\n .describe('Filter by owner email address (partial match)'),\n\n // Raw Drive query string - escape hatch for advanced syntax\n rawDriveQuery: z.string().min(1).optional().describe(\"Raw Google Drive query syntax for advanced use cases. Bypasses schema validation - use sparingly. Example: \\\"name contains 'budget' and mimeType = 'application/pdf'\\\"\"),\n })\n .strict()\n) as unknown as z.ZodType<DriveQueryObject>;\n\nexport type DriveQueryObject = {\n $and?: DriveQueryObject[];\n $or?: DriveQueryObject[];\n $not?: DriveQueryObject;\n name?: string | FieldOperator;\n mimeType?: string | FieldOperator;\n fullText?: string | FieldOperator;\n parentId?: string | FieldOperator;\n starred?: boolean;\n sharedWithMe?: boolean;\n trashed?: boolean;\n modifiedTime?: {\n $gte?: string;\n $lt?: string;\n };\n owner?: string | FieldOperator;\n rawDriveQuery?: string;\n};\n\n/**\n * Drive query schema that accepts either:\n * - A structured DriveQueryObject with typed fields\n * - A raw Drive query string for advanced use cases\n *\n * This provides type safety for common queries while allowing\n * direct Google Drive query syntax when needed.\n */\nexport const DriveQuerySchema = z.union([z.string().min(1), DriveQueryObjectSchema]);\n\nexport type DriveQuery = string | DriveQueryObject;\n"],"names":["z","FieldOperatorSchema","object","$any","array","string","optional","describe","$all","$none","strict","DriveQueryObjectSchema","lazy","$and","$or","$not","name","union","min","mimeType","fullText","parentId","starred","boolean","sharedWithMe","trashed","modifiedTime","$gte","regex","$lt","owner","rawDriveQuery","DriveQuerySchema"],"mappings":"AAAA,SAASA,CAAC,QAAQ,MAAM;AAExB;;;CAGC,GACD,OAAO,MAAMC,sBAAsBD,EAChCE,MAAM,CAAC;IACNC,MAAMH,EAAEI,KAAK,CAACJ,EAAEK,MAAM,IAAIC,QAAQ,GAAGC,QAAQ,CAAC;IAC9CC,MAAMR,EAAEI,KAAK,CAACJ,EAAEK,MAAM,IAAIC,QAAQ,GAAGC,QAAQ,CAAC;IAC9CE,OAAOT,EAAEI,KAAK,CAACJ,EAAEK,MAAM,IAAIC,QAAQ,GAAGC,QAAQ,CAAC;AACjD,GACCG,MAAM,GAAG;AAIZ;;;;;;;;;;;;;;;;;;;;;;CAsBC,GACD,MAAMC,yBAAyBX,EAAEY,IAAI,CAAC,IACpCZ,EACGE,MAAM,CAAC;QACN,yDAAyD;QACzDW,MAAMb,EAAEI,KAAK,CAACO,wBAAwBL,QAAQ,GAAGC,QAAQ,CAAC;QAC1DO,KAAKd,EAAEI,KAAK,CAACO,wBAAwBL,QAAQ,GAAGC,QAAQ,CAAC;QACzDQ,MAAMJ,uBAAuBL,QAAQ,GAAGC,QAAQ,CAAC;QAEjD,0BAA0B;QAC1BS,MAAMhB,EACHiB,KAAK,CAAC;YAACjB,EAAEK,MAAM,GAAGa,GAAG,CAAC;YAAIjB;SAAoB,EAC9CK,QAAQ,GACRC,QAAQ,CAAC;QAEZ,sBAAsB;QACtBY,UAAUnB,EACPiB,KAAK,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AuB,EAAE"}
@@ -1 +1 @@
1
- {"version":3,"sources":["/Users/kevin/Dev/Projects/ai/mcp-z/servers/mcp-drive/src/schemas/drive-validation.ts"],"sourcesContent":["import { z } from 'zod';\n\n// Drive file schema\nexport const DriveFileSchema = z.object({\n id: z.string().optional(),\n name: z.string().optional(),\n mimeType: z.string().optional().describe('MIME type of the file (e.g., application/pdf, image/png)'),\n webViewLink: z.string().optional().describe('URL to view the file in Google Drive'),\n webContentLink: z.string().optional().describe('Direct download link for the file'),\n modifiedTime: z.string().optional().describe('ISO datetime when file was last modified'),\n createdTime: z.string().optional().describe('ISO datetime when file was created'),\n size: z.string().optional().describe('File size in bytes as string'),\n version: z.string().optional().describe('Version number of the file'),\n shared: z.boolean().optional().describe('Whether the file is shared with others'),\n starred: z.boolean().optional().describe('Whether the file is starred by the user'),\n trashed: z.boolean().optional().describe('Whether the file is in trash'),\n parents: z\n .array(\n z.object({\n id: z.string().describe('Parent folder ID'),\n name: z.string().describe('Parent folder name'),\n })\n )\n .optional()\n .describe('Parent folders with ID and name'),\n owners: z\n .array(\n z.object({\n displayName: z.string().optional(),\n emailAddress: z.string().optional(),\n kind: z.string().optional().describe('Resource type identifier (e.g., \"drive#user\")'),\n me: z.boolean().optional().describe('Whether this owner is the current user'),\n permissionId: z.string().optional().describe('Permission ID for this user'),\n photoLink: z.string().optional().describe('URL to user profile photo'),\n })\n )\n .optional(),\n permissions: z\n .object({\n canEdit: z.boolean().optional(),\n canComment: z.boolean().optional(),\n canShare: z.boolean().optional(),\n })\n .optional()\n .describe(\"Current user's permissions on this file\"),\n});\n\nexport type DriveFile = z.infer<typeof DriveFileSchema>;\n\n// Drive file field definitions for field selection\nexport const DRIVE_FILE_FIELDS = ['id', 'name', 'mimeType', 'webViewLink', 'modifiedTime', 'parents', 'shared', 'starred', 'owners'] as const;\n\nexport const DRIVE_FILE_FIELD_DESCRIPTIONS: Record<(typeof DRIVE_FILE_FIELDS)[number], string> = {\n id: 'Unique file/folder identifier',\n name: 'File or folder name',\n mimeType: 'MIME type (e.g., application/pdf, application/vnd.google-apps.folder)',\n webViewLink: 'URL to view the file in Google Drive',\n modifiedTime: 'Last modification timestamp',\n parents: 'Parent folder IDs',\n shared: 'Whether the file is shared',\n starred: 'Whether the file is starred',\n owners: 'File owner information (displayName, emailAddress, etc.)',\n};\n\nexport const DRIVE_FILE_COMMON_PATTERNS = [\n {\n name: 'Bulk operations (delete/move)',\n fields: 'id,name',\n tokens: '~20 tokens/file',\n },\n {\n name: 'Browsing/filtering',\n fields: 'id,name,mimeType,modifiedTime',\n tokens: '~40 tokens/file',\n },\n {\n name: 'Full metadata',\n fields: 'id,name,mimeType,webViewLink,modifiedTime,owners',\n tokens: '~80 tokens/file',\n },\n] as const;\n"],"names":["z","DriveFileSchema","object","id","string","optional","name","mimeType","describe","webViewLink","webContentLink","modifiedTime","createdTime","size","version","shared","boolean","starred","trashed","parents","array","owners","displayName","emailAddress","kind","me","permissionId","photoLink","permissions","canEdit","canComment","canShare","DRIVE_FILE_FIELDS","DRIVE_FILE_FIELD_DESCRIPTIONS","DRIVE_FILE_COMMON_PATTERNS","fields","tokens"],"mappings":"AAAA,SAASA,CAAC,QAAQ,MAAM;AAExB,oBAAoB;AACpB,OAAO,MAAMC,kBAAkBD,EAAEE,MAAM,CAAC;IACtCC,IAAIH,EAAEI,MAAM,GAAGC,QAAQ;IACvBC,MAAMN,EAAEI,MAAM,GAAGC,QAAQ;IACzBE,UAAUP,EAAEI,MAAM,GAAGC,QAAQ,GAAGG,QAAQ,CAAC;IACzCC,aAAaT,EAAEI,MAAM,GAAGC,QAAQ,GAAGG,QAAQ,CAAC;IAC5CE,gBAAgBV,EAAEI,MAAM,GAAGC,QAAQ,GAAGG,QAAQ,CAAC;IAC/CG,cAAcX,EAAEI,MAAM,GAAGC,QAAQ,GAAGG,QAAQ,CAAC;IAC7CI,aAAaZ,EAAEI,MAAM,GAAGC,QAAQ,GAAGG,QAAQ,CAAC;IAC5CK,MAAMb,EAAEI,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S,CAAU;AAE9I,OAAO,MAAMC,gCAAoF;IAC/F9B,IAAI;IACJG,MAAM;IACNC,UAAU;IACVE,aAAa;IACbE,cAAc;IACdQ,SAAS;IACTJ,QAAQ;IACRE,SAAS;IACTI,QAAQ;AACV,EAAE;AAEF,OAAO,MAAMa,6BAA6B;IACxC;QACE5B,MAAM;QACN6B,QAAQ;QACRC,QAAQ;IACV;IACA;QACE9B,MAAM;QACN6B,QAAQ;QACRC,QAAQ;IACV;IACA;QACE9B,MAAM;QACN6B,QAAQ;QACRC,QAAQ;IACV;CACD,CAAU"}
1
+ {"version":3,"sources":["/Users/kevin/Dev/Projects/mcp-z/mcp-drive/src/schemas/drive-validation.ts"],"sourcesContent":["import { z } from 'zod';\n\n// Drive file schema\nexport const DriveFileSchema = z.object({\n id: z.string().optional(),\n name: z.string().optional(),\n mimeType: z.string().optional().describe('MIME type of the file (e.g., application/pdf, image/png)'),\n webViewLink: z.string().optional().describe('URL to view the file in Google Drive'),\n webContentLink: z.string().optional().describe('Direct download link for the file'),\n modifiedTime: z.string().optional().describe('ISO datetime when file was last modified'),\n createdTime: z.string().optional().describe('ISO datetime when file was created'),\n size: z.string().optional().describe('File size in bytes as string'),\n version: z.string().optional().describe('Version number of the file'),\n shared: z.boolean().optional().describe('Whether the file is shared with others'),\n starred: z.boolean().optional().describe('Whether the file is starred by the user'),\n trashed: z.boolean().optional().describe('Whether the file is in trash'),\n parents: z\n .array(\n z.object({\n id: z.string().describe('Parent folder ID'),\n name: z.string().describe('Parent folder name'),\n })\n )\n .optional()\n .describe('Parent folders with ID and name'),\n owners: z\n .array(\n z.object({\n displayName: z.string().optional(),\n emailAddress: z.string().optional(),\n kind: z.string().optional().describe('Resource type identifier (e.g., \"drive#user\")'),\n me: z.boolean().optional().describe('Whether this owner is the current user'),\n permissionId: z.string().optional().describe('Permission ID for this user'),\n photoLink: z.string().optional().describe('URL to user profile photo'),\n })\n )\n .optional(),\n permissions: z\n .object({\n canEdit: z.boolean().optional(),\n canComment: z.boolean().optional(),\n canShare: z.boolean().optional(),\n })\n .optional()\n .describe(\"Current user's permissions on this file\"),\n});\n\nexport type DriveFile = z.infer<typeof DriveFileSchema>;\n\n// Drive file field definitions for field selection\nexport const DRIVE_FILE_FIELDS = ['id', 'name', 'mimeType', 'webViewLink', 'modifiedTime', 'parents', 'shared', 'starred', 'owners'] as const;\n\nexport const DRIVE_FILE_FIELD_DESCRIPTIONS: Record<(typeof DRIVE_FILE_FIELDS)[number], string> = {\n id: 'Unique file/folder identifier',\n name: 'File or folder name',\n mimeType: 'MIME type (e.g., application/pdf, application/vnd.google-apps.folder)',\n webViewLink: 'URL to view the file in Google Drive',\n modifiedTime: 'Last modification timestamp',\n parents: 'Parent folder IDs',\n shared: 'Whether the file is shared',\n starred: 'Whether the file is starred',\n owners: 'File owner information (displayName, emailAddress, etc.)',\n};\n\nexport const DRIVE_FILE_COMMON_PATTERNS = [\n {\n name: 'Bulk operations (delete/move)',\n fields: 'id,name',\n tokens: '~20 tokens/file',\n },\n {\n name: 'Browsing/filtering',\n fields: 'id,name,mimeType,modifiedTime',\n tokens: '~40 tokens/file',\n },\n {\n name: 'Full metadata',\n fields: 'id,name,mimeType,webViewLink,modifiedTime,owners',\n tokens: '~80 tokens/file',\n },\n] as const;\n"],"names":["z","DriveFileSchema","object","id","string","optional","name","mimeType","describe","webViewLink","webContentLink","modifiedTime","createdTime","size","version","shared","boolean","starred","trashed","parents","array","owners","displayName","emailAddress","kind","me","permissionId","photoLink","permissions","canEdit","canComment","canShare","DRIVE_FILE_FIELDS","DRIVE_FILE_FIELD_DESCRIPTIONS","DRIVE_FILE_COMMON_PATTERNS","fields","tokens"],"mappings":"AAAA,SAASA,CAAC,QAAQ,MAAM;AAExB,oBAAoB;AACpB,OAAO,MAAMC,kBAAkBD,EAAEE,MAAM,CAAC;IACtCC,IAAIH,EAAEI,MAAM,GAAGC,QAAQ;IACvBC,MAAMN,EAAEI,MAAM,GAAGC,QAAQ;IACzBE,UAAUP,EAA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;IACXuB,aAAa5B,EACVE,MAAM,CAAC;QACN2B,SAAS7B,EAAEgB,OAAO,GAAGX,QAAQ;QAC7ByB,YAAY9B,EAAEgB,OAAO,GAAGX,QAAQ;QAChC0B,UAAU/B,EAAEgB,OAAO,GAAGX,QAAQ;IAChC,GACCA,QAAQ,GACRG,QAAQ,CAAC;AACd,GAAG;AAIH,mDAAmD;AACnD,OAAO,MAAMwB,oBAAoB;IAAC;IAAM;IAAQ;IAAY;IAAe;IAAgB;IAAW;IAAU;IAAW;CAAS,CAAU;AAE9I,OAAO,MAAMC,gCAAoF;IAC/F9B,IAAI;IACJG,MAAM;IACNC,UAAU;IACVE,aAAa;IACbE,cAAc;IACdQ,SAAS;IACTJ,QAAQ;IACRE,SAAS;IACTI,QAAQ;AACV,EAAE;AAEF,OAAO,MAAMa,6BAA6B;IACxC;QACE5B,MAAM;QACN6B,QAAQ;QACRC,QAAQ;IACV;IACA;QACE9B,MAAM;QACN6B,QAAQ;QACRC,QAAQ;IACV;IACA;QACE9B,MAAM;QACN6B,QAAQ;QACRC,QAAQ;IACV;CACD,CAAU"}
@@ -1 +1 @@
1
- {"version":3,"sources":["/Users/kevin/Dev/Projects/ai/mcp-z/servers/mcp-drive/src/schemas/index.ts"],"sourcesContent":["export * from './drive-query-schema.js';\nexport * from './drive-validation.js';\n"],"names":[],"mappings":"AAAA,cAAc,0BAA0B;AACxC,cAAc,wBAAwB"}
1
+ {"version":3,"sources":["/Users/kevin/Dev/Projects/mcp-z/mcp-drive/src/schemas/index.ts"],"sourcesContent":["export * from './drive-query-schema.ts';\nexport * from './drive-validation.ts';\n"],"names":[],"mappings":"AAAA,cAAc,0BAA0B;AACxC,cAAc,wBAAwB"}
@@ -1,5 +1,5 @@
1
1
  import { parseDcrConfig, parseConfig as parseOAuthConfig } from '@mcp-z/oauth-google';
2
- import { parseConfig as parseTransportConfig } from '@mcp-z/server';
2
+ import { findConfigPath, parseConfig as parseTransportConfig } from '@mcp-z/server';
3
3
  import * as fs from 'fs';
4
4
  import moduleRoot from 'module-root-sync';
5
5
  import { homedir } from 'os';
@@ -124,7 +124,17 @@ Examples:
124
124
  // Parse repository URL from package.json, stripping git+ prefix and .git suffix
125
125
  const rawRepoUrl = typeof pkg.repository === 'object' ? pkg.repository.url : pkg.repository;
126
126
  const repositoryUrl = (_ref = rawRepoUrl === null || rawRepoUrl === void 0 ? void 0 : rawRepoUrl.replace(/^git\+/, '').replace(/\.git$/, '')) !== null && _ref !== void 0 ? _ref : `https://github.com/mcp-z/${name}`;
127
- const rootDir = process.cwd() === '/' ? homedir() : process.cwd();
127
+ let rootDir = homedir();
128
+ try {
129
+ const configPath = findConfigPath({
130
+ config: '.mcp.json',
131
+ cwd: process.cwd(),
132
+ stopDir: homedir()
133
+ });
134
+ rootDir = path.dirname(configPath);
135
+ } catch {
136
+ rootDir = homedir();
137
+ }
128
138
  const baseDir = path.join(rootDir, '.mcp-z');
129
139
  const cliLogLevel = typeof values['log-level'] === 'string' ? values['log-level'] : undefined;
130
140
  const envLogLevel = env.LOG_LEVEL;
@@ -1 +1 @@
1
- {"version":3,"sources":["/Users/kevin/Dev/Projects/ai/mcp-z/servers/mcp-drive/src/setup/config.ts"],"sourcesContent":["import { parseDcrConfig, parseConfig as parseOAuthConfig } from '@mcp-z/oauth-google';\nimport { parseConfig as parseTransportConfig } from '@mcp-z/server';\nimport * as fs from 'fs';\nimport moduleRoot from 'module-root-sync';\nimport { homedir } from 'os';\nimport * as path from 'path';\nimport * as url from 'url';\nimport { parseArgs } from 'util';\nimport { GOOGLE_SCOPE } from '../constants.ts';\nimport type { ServerConfig } from '../types.js';\n\nconst pkg = JSON.parse(fs.readFileSync(path.join(moduleRoot(url.fileURLToPath(import.meta.url)), 'package.json'), 'utf-8'));\n\nconst HELP_TEXT = `\nUsage: mcp-drive [options]\n\nMCP server for Google Drive file management with OAuth authentication.\n\nOptions:\n --version Show version number\n --help Show this help message\n --auth=<mode> Authentication mode (default: loopback-oauth)\n Modes: loopback-oauth, service-account, dcr\n --headless Disable browser auto-open, return auth URL instead\n --redirect-uri=<uri> OAuth redirect URI (default: ephemeral loopback)\n --dcr-mode=<mode> DCR mode (self-hosted or external, default: self-hosted)\n --dcr-verify-url=<url> External verification endpoint (required for external mode)\n --dcr-store-uri=<uri> DCR client storage URI (required for self-hosted mode)\n --port=<port> Enable HTTP transport on specified port\n --stdio Enable stdio transport (default if no port)\n --log-level=<level> Logging level (default: info)\n\nEnvironment Variables:\n GOOGLE_CLIENT_ID OAuth client ID (REQUIRED)\n GOOGLE_CLIENT_SECRET OAuth client secret (optional)\n AUTH_MODE Default authentication mode (optional)\n HEADLESS Disable browser auto-open (optional)\n DCR_MODE DCR mode (optional, same format as --dcr-mode)\n DCR_VERIFY_URL External verification URL (optional, same as --dcr-verify-url)\n DCR_STORE_URI DCR storage URI (optional, same as --dcr-store-uri)\n PORT Default HTTP port (optional)\n LOG_LEVEL Default logging level (optional)\n\nOAuth Scopes:\n openid https://www.googleapis.com/auth/userinfo.profile https://www.googleapis.com/auth/userinfo.email https://www.googleapis.com/auth/drive\n\nExamples:\n mcp-drive # Use default settings\n mcp-drive --auth=service-account # Use service account auth\n mcp-drive --port=3000 # HTTP transport on port 3000\n GOOGLE_CLIENT_ID=xxx mcp-drive # Set client ID via env var\n`.trim();\n\n/**\n * Handle --version and --help flags before config parsing.\n * These should work without requiring any configuration.\n */\nexport function handleVersionHelp(args: string[]): { handled: boolean; output?: string } {\n const { values } = parseArgs({\n args,\n options: {\n version: { type: 'boolean' },\n help: { type: 'boolean' },\n },\n strict: false,\n });\n\n if (values.version) return { handled: true, output: pkg.version };\n if (values.help) return { handled: true, output: HELP_TEXT };\n return { handled: false };\n}\n\n/**\n * Parse Drive server configuration from CLI arguments and environment.\n *\n * CLI Arguments (all optional):\n * - --auth=<mode> Authentication mode (default: loopback-oauth)\n * Modes: loopback-oauth, service-account, dcr\n * - --headless Disable browser auto-open, return auth URL instead\n * - --redirect-uri=<uri> OAuth redirect URI (default: ephemeral loopback)\n * - --dcr-mode=<mode> DCR mode (self-hosted or external, default: self-hosted)\n * - --dcr-verify-url=<url> External verification endpoint (required for external mode)\n * - --dcr-store-uri=<uri> DCR client storage URI (required for self-hosted mode)\n * - --port=<port> Enable HTTP transport on specified port\n * - --stdio Enable stdio transport (default if no port)\n * - --log-level=<level> Logging level (default: info)\n *\n * Environment Variables:\n * - GOOGLE_CLIENT_ID OAuth client ID (REQUIRED)\n * - GOOGLE_CLIENT_SECRET OAuth client secret (optional)\n * - AUTH_MODE Default authentication mode (optional)\n * - HEADLESS Disable browser auto-open (optional)\n * - DCR_MODE DCR mode (optional, same format as --dcr-mode)\n * - DCR_VERIFY_URL External verification URL (optional, same as --dcr-verify-url)\n * - DCR_STORE_URI DCR storage URI (optional, same as --dcr-store-uri)\n * - PORT Default HTTP port (optional)\n * - LOG_LEVEL Default logging level (optional)\n *\n * OAuth Scopes (from constants.ts):\n * openid https://www.googleapis.com/auth/userinfo.profile https://www.googleapis.com/auth/userinfo.email https://www.googleapis.com/auth/drive\n */\nexport function parseConfig(args: string[], env: Record<string, string | undefined>): ServerConfig {\n const transportConfig = parseTransportConfig(args, env);\n const oauthConfig = parseOAuthConfig(args, env);\n\n // Parse DCR configuration if DCR mode is enabled\n const dcrConfig = oauthConfig.auth === 'dcr' ? parseDcrConfig(args, env, GOOGLE_SCOPE) : undefined;\n\n // Parse application-level config (LOG_LEVEL)\n const { values } = parseArgs({\n args,\n options: {\n 'log-level': { type: 'string' },\n },\n strict: false, // Allow other arguments\n allowPositionals: true,\n });\n\n const name = pkg.name.replace(/^@[^/]+\\//, '');\n // Parse repository URL from package.json, stripping git+ prefix and .git suffix\n const rawRepoUrl = typeof pkg.repository === 'object' ? pkg.repository.url : pkg.repository;\n const repositoryUrl = rawRepoUrl?.replace(/^git\\+/, '').replace(/\\.git$/, '') ?? `https://github.com/mcp-z/${name}`;\n const rootDir = process.cwd() === '/' ? homedir() : process.cwd();\n const baseDir = path.join(rootDir, '.mcp-z');\n const cliLogLevel = typeof values['log-level'] === 'string' ? values['log-level'] : undefined;\n const envLogLevel = env.LOG_LEVEL;\n const logLevel = cliLogLevel ?? envLogLevel ?? 'info';\n\n // Combine configs\n return {\n ...oauthConfig, // Includes clientId, auth, headless, redirectUri\n transport: transportConfig.transport,\n logLevel,\n baseDir,\n name,\n version: pkg.version,\n repositoryUrl,\n ...(dcrConfig && { dcrConfig }),\n };\n}\n\n/**\n * Build production configuration from process globals.\n * Entry point for production server.\n */\nexport function createConfig(): ServerConfig {\n return parseConfig(process.argv, process.env);\n}\n"],"names":["parseDcrConfig","parseConfig","parseOAuthConfig","parseTransportConfig","fs","moduleRoot","homedir","path","url","parseArgs","GOOGLE_SCOPE","pkg","JSON","parse","readFileSync","join","fileURLToPath","HELP_TEXT","trim","handleVersionHelp","args","values","options","version","type","help","strict","handled","output","env","cliLogLevel","transportConfig","oauthConfig","dcrConfig","auth","undefined","allowPositionals","name","replace","rawRepoUrl","repository","repositoryUrl","rootDir","process","cwd","baseDir","envLogLevel","LOG_LEVEL","logLevel","transport","createConfig","argv"],"mappings":"AAAA,SAASA,cAAc,EAAEC,eAAeC,gBAAgB,QAAQ,sBAAsB;AACtF,SAASD,eAAeE,oBAAoB,QAAQ,gBAAgB;AACpE,YAAYC,QAAQ,KAAK;AACzB,OAAOC,gBAAgB,mBAAmB;AAC1C,SAASC,OAAO,QAAQ,KAAK;AAC7B,YAAYC,UAAU,OAAO;AAC7B,YAAYC,SAAS,MAAM;AAC3B,SAASC,SAAS,QAAQ,OAAO;AACjC,SAASC,YAAY,QAAQ,kBAAkB;AAG/C,MAAMC,MAAMC,KAAKC,KAAK,CAACT,GAAGU,YAAY,CAACP,KAAKQ,IAAI,CAACV,WAAWG,IAAIQ,aAAa,CAAC,YAAYR,GAAG,IAAI,iBAAiB;AAElH,MAAMS,YAAY,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAsCnB,CAAC,CAACC,IAAI;AAEN;;;CAGC,GACD,OAAO,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AAC2B,SAAS;IACnC,MAAMZ,cAAc,OAAOT,MAAM,CAAC,YAAY,KAAK,WAAWA,MAAM,CAAC,YAAY,GAAGc;IACpF,MAAMW,cAAcjB,IAAIkB,SAAS;IACjC,MAAMC,YAAWlB,QAAAA,wBAAAA,yBAAAA,cAAegB,yBAAfhB,mBAAAA,QAA8B;IAE/C,kBAAkB;IAClB,OAAO;QACL,GAAGE,WAAW;QACdiB,WAAWlB,gBAAgBkB,SAAS;QACpCD;QACAH;QACAR;QACAd,SAASZ,IAAIY,OAAO;QACpBkB;QACA,GAAIR,aAAa;YAAEA;QAAU,CAAC;IAChC;AACF;AAEA;;;CAGC,GACD,OAAO,SAASiB;IACd,OAAOjD,YAAY0C,QAAQQ,IAAI,EAAER,QAAQd,GAAG;AAC9C"}
1
+ {"version":3,"sources":["/Users/kevin/Dev/Projects/mcp-z/mcp-drive/src/setup/config.ts"],"sourcesContent":["import { parseDcrConfig, parseConfig as parseOAuthConfig } from '@mcp-z/oauth-google';\nimport { findConfigPath, parseConfig as parseTransportConfig } from '@mcp-z/server';\nimport * as fs from 'fs';\nimport moduleRoot from 'module-root-sync';\nimport { homedir } from 'os';\nimport * as path from 'path';\nimport * as url from 'url';\nimport { parseArgs } from 'util';\nimport { GOOGLE_SCOPE } from '../constants.ts';\nimport type { ServerConfig } from '../types.ts';\n\nconst pkg = JSON.parse(fs.readFileSync(path.join(moduleRoot(url.fileURLToPath(import.meta.url)), 'package.json'), 'utf-8'));\n\nconst HELP_TEXT = `\nUsage: mcp-drive [options]\n\nMCP server for Google Drive file management with OAuth authentication.\n\nOptions:\n --version Show version number\n --help Show this help message\n --auth=<mode> Authentication mode (default: loopback-oauth)\n Modes: loopback-oauth, service-account, dcr\n --headless Disable browser auto-open, return auth URL instead\n --redirect-uri=<uri> OAuth redirect URI (default: ephemeral loopback)\n --dcr-mode=<mode> DCR mode (self-hosted or external, default: self-hosted)\n --dcr-verify-url=<url> External verification endpoint (required for external mode)\n --dcr-store-uri=<uri> DCR client storage URI (required for self-hosted mode)\n --port=<port> Enable HTTP transport on specified port\n --stdio Enable stdio transport (default if no port)\n --log-level=<level> Logging level (default: info)\n\nEnvironment Variables:\n GOOGLE_CLIENT_ID OAuth client ID (REQUIRED)\n GOOGLE_CLIENT_SECRET OAuth client secret (optional)\n AUTH_MODE Default authentication mode (optional)\n HEADLESS Disable browser auto-open (optional)\n DCR_MODE DCR mode (optional, same format as --dcr-mode)\n DCR_VERIFY_URL External verification URL (optional, same as --dcr-verify-url)\n DCR_STORE_URI DCR storage URI (optional, same as --dcr-store-uri)\n PORT Default HTTP port (optional)\n LOG_LEVEL Default logging level (optional)\n\nOAuth Scopes:\n openid https://www.googleapis.com/auth/userinfo.profile https://www.googleapis.com/auth/userinfo.email https://www.googleapis.com/auth/drive\n\nExamples:\n mcp-drive # Use default settings\n mcp-drive --auth=service-account # Use service account auth\n mcp-drive --port=3000 # HTTP transport on port 3000\n GOOGLE_CLIENT_ID=xxx mcp-drive # Set client ID via env var\n`.trim();\n\n/**\n * Handle --version and --help flags before config parsing.\n * These should work without requiring any configuration.\n */\nexport function handleVersionHelp(args: string[]): { handled: boolean; output?: string } {\n const { values } = parseArgs({\n args,\n options: {\n version: { type: 'boolean' },\n help: { type: 'boolean' },\n },\n strict: false,\n });\n\n if (values.version) return { handled: true, output: pkg.version };\n if (values.help) return { handled: true, output: HELP_TEXT };\n return { handled: false };\n}\n\n/**\n * Parse Drive server configuration from CLI arguments and environment.\n *\n * CLI Arguments (all optional):\n * - --auth=<mode> Authentication mode (default: loopback-oauth)\n * Modes: loopback-oauth, service-account, dcr\n * - --headless Disable browser auto-open, return auth URL instead\n * - --redirect-uri=<uri> OAuth redirect URI (default: ephemeral loopback)\n * - --dcr-mode=<mode> DCR mode (self-hosted or external, default: self-hosted)\n * - --dcr-verify-url=<url> External verification endpoint (required for external mode)\n * - --dcr-store-uri=<uri> DCR client storage URI (required for self-hosted mode)\n * - --port=<port> Enable HTTP transport on specified port\n * - --stdio Enable stdio transport (default if no port)\n * - --log-level=<level> Logging level (default: info)\n *\n * Environment Variables:\n * - GOOGLE_CLIENT_ID OAuth client ID (REQUIRED)\n * - GOOGLE_CLIENT_SECRET OAuth client secret (optional)\n * - AUTH_MODE Default authentication mode (optional)\n * - HEADLESS Disable browser auto-open (optional)\n * - DCR_MODE DCR mode (optional, same format as --dcr-mode)\n * - DCR_VERIFY_URL External verification URL (optional, same as --dcr-verify-url)\n * - DCR_STORE_URI DCR storage URI (optional, same as --dcr-store-uri)\n * - PORT Default HTTP port (optional)\n * - LOG_LEVEL Default logging level (optional)\n *\n * OAuth Scopes (from constants.ts):\n * openid https://www.googleapis.com/auth/userinfo.profile https://www.googleapis.com/auth/userinfo.email https://www.googleapis.com/auth/drive\n */\nexport function parseConfig(args: string[], env: Record<string, string | undefined>): ServerConfig {\n const transportConfig = parseTransportConfig(args, env);\n const oauthConfig = parseOAuthConfig(args, env);\n\n // Parse DCR configuration if DCR mode is enabled\n const dcrConfig = oauthConfig.auth === 'dcr' ? parseDcrConfig(args, env, GOOGLE_SCOPE) : undefined;\n\n // Parse application-level config (LOG_LEVEL)\n const { values } = parseArgs({\n args,\n options: {\n 'log-level': { type: 'string' },\n },\n strict: false, // Allow other arguments\n allowPositionals: true,\n });\n\n const name = pkg.name.replace(/^@[^/]+\\//, '');\n // Parse repository URL from package.json, stripping git+ prefix and .git suffix\n const rawRepoUrl = typeof pkg.repository === 'object' ? pkg.repository.url : pkg.repository;\n const repositoryUrl = rawRepoUrl?.replace(/^git\\+/, '').replace(/\\.git$/, '') ?? `https://github.com/mcp-z/${name}`;\n let rootDir = homedir();\n try {\n const configPath = findConfigPath({ config: '.mcp.json', cwd: process.cwd(), stopDir: homedir() });\n rootDir = path.dirname(configPath);\n } catch {\n rootDir = homedir();\n }\n const baseDir = path.join(rootDir, '.mcp-z');\n const cliLogLevel = typeof values['log-level'] === 'string' ? values['log-level'] : undefined;\n const envLogLevel = env.LOG_LEVEL;\n const logLevel = cliLogLevel ?? envLogLevel ?? 'info';\n\n // Combine configs\n return {\n ...oauthConfig, // Includes clientId, auth, headless, redirectUri\n transport: transportConfig.transport,\n logLevel,\n baseDir,\n name,\n version: pkg.version,\n repositoryUrl,\n ...(dcrConfig && { dcrConfig }),\n };\n}\n\n/**\n * Build production configuration from process globals.\n * Entry point for production server.\n */\nexport function createConfig(): ServerConfig {\n return parseConfig(process.argv, process.env);\n}\n"],"names":["parseDcrConfig","parseConfig","parseOAuthConfig","findConfigPath","parseTransportConfig","fs","moduleRoot","homedir","path","url","parseArgs","GOOGLE_SCOPE","pkg","JSON","parse","readFileSync","join","fileURLToPath","HELP_TEXT","trim","handleVersionHelp","args","values","options","version","type","help","strict","handled","output","env","cliLogLevel","transportConfig","oauthConfig","dcrConfig","auth","undefined","allowPositionals","name","replace","rawRepoUrl","repository","repositoryUrl","rootDir","configPath","config","cwd","process","stopDir","dirname","baseDir","envLogLevel","LOG_LEVEL","logLevel","transport","createConfig","argv"],"mappings":"AAAA,SAASA,cAAc,EAAEC,eAAeC,gBAAgB,QAAQ,sBAAsB;AACtF,SAASC,cAAc,EAAEF,eAAeG,oBAAoB,QAAQ,gBAAgB;AACpF,YAAYC,QAAQ,KAAK;AACzB,OAAOC,gBAAgB,mBAAmB;AAC1C,SAASC,OAAO,QAAQ,KAAK;AAC7B,YAAYC,UAAU,OAAO;AAC7B,YAAYC,SAAS,MAAM;AAC3B,SAASC,SAAS,QAAQ,OAAO;AACjC,SAASC,YAAY,QAAQ,kBAAkB;AAG/C,MAAMC,MAAMC,KAAKC,KAAK,CAACT,GAAGU,YAAY,CAACP,KAAKQ,IAAI,CAACV,WAAWG,IAAIQ,aAAa,CAAC,YAAYR,GAAG,IAAI,iBAAiB;AAElH,MAAMS,YAAY,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAsCnB,CAAC,CAACC,IAAI;AAEN;;;CAGC,GACD,OAAO,SAASC,kBAAkBC,IAAc;IAC9C,MAAM,EAAEC,MAAM,EAA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IACzB,EAAE,OAAM;QACND,UAAUpC;IACZ;IACA,MAAM2C,UAAU1C,KAAKQ,IAAI,CAAC2B,SAAS;IACnC,MAAMZ,cAAc,OAAOT,MAAM,CAAC,YAAY,KAAK,WAAWA,MAAM,CAAC,YAAY,GAAGc;IACpF,MAAMe,cAAcrB,IAAIsB,SAAS;IACjC,MAAMC,YAAWtB,QAAAA,wBAAAA,yBAAAA,cAAeoB,yBAAfpB,mBAAAA,QAA8B;IAE/C,kBAAkB;IAClB,OAAO;QACL,GAAGE,WAAW;QACdqB,WAAWtB,gBAAgBsB,SAAS;QACpCD;QACAH;QACAZ;QACAd,SAASZ,IAAIY,OAAO;QACpBkB;QACA,GAAIR,aAAa;YAAEA;QAAU,CAAC;IAChC;AACF;AAEA;;;CAGC,GACD,OAAO,SAASqB;IACd,OAAOtD,YAAY8C,QAAQS,IAAI,EAAET,QAAQjB,GAAG;AAC9C"}
@@ -31,6 +31,10 @@ export async function createHTTPServer(config, overrides) {
31
31
  app.use(express.json({
32
32
  limit: '10mb'
33
33
  }));
34
+ if (runtime.deps.oauthAdapters.loopbackRouter) {
35
+ app.use('/', runtime.deps.oauthAdapters.loopbackRouter);
36
+ logger.info('Mounted loopback OAuth callback router');
37
+ }
34
38
  if (runtime.deps.oauthAdapters.dcrRouter) {
35
39
  app.use('/', runtime.deps.oauthAdapters.dcrRouter);
36
40
  logger.info('Mounted DCR router with OAuth endpoints');
@@ -1 +1 @@
1
- {"version":3,"sources":["/Users/kevin/Dev/Projects/ai/mcp-z/servers/mcp-drive/src/setup/http.ts"],"sourcesContent":["import { composeMiddleware, connectHttp, registerPrompts, registerResources, registerTools } from '@mcp-z/server';\nimport { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js';\nimport cors from 'cors';\nimport express from 'express';\nimport type { RuntimeOverrides, ServerConfig } from '../types.js';\nimport { createDefaultRuntime } from './runtime.js';\n\nexport async function createHTTPServer(config: ServerConfig, overrides?: RuntimeOverrides) {\n const runtime = await createDefaultRuntime(config, overrides);\n const modules = runtime.createDomainModules();\n const layers = runtime.middlewareFactories.map((factory) => factory(runtime.deps));\n const composed = composeMiddleware(modules, layers);\n const logger = runtime.deps.logger;\n const port = config.transport.port;\n if (!port) throw new Error('Port is required for HTTP transport');\n\n const tools = [...composed.tools, ...runtime.deps.oauthAdapters.accountTools];\n const prompts = [...composed.prompts, ...runtime.deps.oauthAdapters.accountPrompts];\n\n const mcpServer = new McpServer({ name: config.name, version: config.version });\n registerTools(mcpServer, tools);\n registerResources(mcpServer, composed.resources);\n registerPrompts(mcpServer, prompts);\n\n const app = express();\n app.use(cors());\n app.use(express.json({ limit: '10mb' }));\n\n if (runtime.deps.oauthAdapters.dcrRouter) {\n app.use('/', runtime.deps.oauthAdapters.dcrRouter);\n logger.info('Mounted DCR router with OAuth endpoints');\n }\n\n logger.info(`Starting ${config.name} MCP server (http)`);\n const { close, httpServer } = await connectHttp(mcpServer, { logger, app, port });\n logger.info('http transport ready');\n\n return {\n httpServer,\n mcpServer,\n logger,\n close: async () => {\n await close();\n await runtime.close();\n },\n };\n}\n"],"names":["composeMiddleware","connectHttp","registerPrompts","registerResources","registerTools","McpServer","cors","express","createDefaultRuntime","createHTTPServer","config","overrides","runtime","modules","createDomainModules","layers","middlewareFactories","map","factory","deps","composed","logger","port","transport","Error","tools","oauthAdapters","accountTools","prompts","accountPrompts","mcpServer","name","version","resources","app","use","json","limit","dcrRouter","info","close","httpServer"],"mappings":"AAAA,SAASA,iBAAiB,EAAEC,WAAW,EAAEC,eAAe,EAAEC,iBAAiB,EAAEC,aAAa,QAAQ,gBAAgB;AAClH,SAASC,SAAS,QAAQ,0CAA0C;AACpE,OAAOC,UAAU,OAAO;AACxB,OAAOC,aAAa,UAAU;AAE9B,SAASC,oBAAoB,QAAQ,eAAe;AAEpD,OAAO,eAAeC,iBAAiBC,MAAoB,EAAEC,SAA4B;IACvF,MAAMC,UAAU,MAAMJ,qBAAqBE,QAAQC;IACnD,MAAME,UAAUD,QAAQE,mBAA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;IACF;AACF"}
1
+ {"version":3,"sources":["/Users/kevin/Dev/Projects/mcp-z/mcp-drive/src/setup/http.ts"],"sourcesContent":["import { composeMiddleware, connectHttp, registerPrompts, registerResources, registerTools } from '@mcp-z/server';\nimport { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js';\nimport cors from 'cors';\nimport express from 'express';\nimport type { RuntimeOverrides, ServerConfig } from '../types.ts';\nimport { createDefaultRuntime } from './runtime.ts';\n\nexport async function createHTTPServer(config: ServerConfig, overrides?: RuntimeOverrides) {\n const runtime = await createDefaultRuntime(config, overrides);\n const modules = runtime.createDomainModules();\n const layers = runtime.middlewareFactories.map((factory) => factory(runtime.deps));\n const composed = composeMiddleware(modules, layers);\n const logger = runtime.deps.logger;\n const port = config.transport.port;\n if (!port) throw new Error('Port is required for HTTP transport');\n\n const tools = [...composed.tools, ...runtime.deps.oauthAdapters.accountTools];\n const prompts = [...composed.prompts, ...runtime.deps.oauthAdapters.accountPrompts];\n\n const mcpServer = new McpServer({ name: config.name, version: config.version });\n registerTools(mcpServer, tools);\n registerResources(mcpServer, composed.resources);\n registerPrompts(mcpServer, prompts);\n\n const app = express();\n app.use(cors());\n app.use(express.json({ limit: '10mb' }));\n\n if (runtime.deps.oauthAdapters.loopbackRouter) {\n app.use('/', runtime.deps.oauthAdapters.loopbackRouter);\n logger.info('Mounted loopback OAuth callback router');\n }\n\n if (runtime.deps.oauthAdapters.dcrRouter) {\n app.use('/', runtime.deps.oauthAdapters.dcrRouter);\n logger.info('Mounted DCR router with OAuth endpoints');\n }\n\n logger.info(`Starting ${config.name} MCP server (http)`);\n const { close, httpServer } = await connectHttp(mcpServer, { logger, app, port });\n logger.info('http transport ready');\n\n return {\n httpServer,\n mcpServer,\n logger,\n close: async () => {\n await close();\n await runtime.close();\n },\n };\n}\n"],"names":["composeMiddleware","connectHttp","registerPrompts","registerResources","registerTools","McpServer","cors","express","createDefaultRuntime","createHTTPServer","config","overrides","runtime","modules","createDomainModules","layers","middlewareFactories","map","factory","deps","composed","logger","port","transport","Error","tools","oauthAdapters","accountTools","prompts","accountPrompts","mcpServer","name","version","resources","app","use","json","limit","loopbackRouter","info","dcrRouter","close","httpServer"],"mappings":"AAAA,SAASA,iBAAiB,EAAEC,WAAW,EAAEC,eAAe,EAAEC,iBAAiB,EAAEC,aAAa,QAAQ,gBAAgB;AAClH,SAASC,SAAS,QAAQ,0CAA0C;AACpE,OAAOC,UAAU,OAAO;AACxB,OAAOC,aAAa,UAAU;AAE9B,SAASC,oBAAoB,QAAQ,eAAe;AAEpD,OAAO,eAAeC,iBAAiBC,MAAoB,EAAEC,SAA4B;IACvF,MAAMC,UAAU,MAAMJ,qBAAqBE,QAAQC;IACnD,MAAME,UAAUD,QAAQE,mBAAmB;IAC3C,MAAMC,SAASH,QAAQI,mBAAmB,CAACC,GAAG,CAAC,CAACC,UAAYA,QAAQN,QAAQO,IAAI;IAChF,MAAMC,WAAWpB,kBAAkBa,SAASE;IAC5C,MAAMM,SAAST,QAAQO,IAAI,CAACE,MAAM;IAClC,MAAMC,OAAOZ,OAAOa,SAAS,CAACD,IAAI;IAClC,IAAI,CAACA,MAAM,MAAM,IAAIE,MAAM;IAE3B,MAAMC,QAAQ;WAAIL,SAASK,KAAK;WAAKb,QAAQO,IAAI,CAACO,aAAa,CAACC,YAAY;KAAC;IAC7E,MAAMC,UAAU;WAAIR,SAASQ,OAAO;WAAKhB,QAAQO,IAAI,CAACO,aAAa,CAACG,cAAc;KAAC;IAEnF,MAAMC,YAAY,IAAIzB,UAAU;QAAE0B,MAAMrB,OAAOqB,IAAI;QAAEC,SAAStB,OAAOsB,OAAO;IAAC;IAC7E5B,cAAc0B,WAAWL;IACzBtB,kBAAkB2B,WAAWV,SAASa,SAAS;IAC/C/B,gBAAgB4B,WAAWF;IAE3B,MAAMM,MAAM3B;IACZ2B,IAAIC,GAAG,CAAC7B;IACR4B,IAAIC,GAAG,CAAC5B,QAAQ6B,IAAI,CAAC;QAAEC,OAAO;IAAO;IAErC,IAAIzB,QAAQO,IAAI,CAACO,aAAa,CAACY,cAAc,EAAE;QAC7CJ,IAAIC,GAAG,CAAC,KAAKvB,QAAQO,IAAI,CAACO,aAAa,CAACY,cAAc;QACtDjB,OAAOkB,IAAI,CAAC;IACd;IAEA,IAAI3B,QAAQO,IAAI,CAACO,aAAa,CAACc,SAAS,EAAE;QACxCN,IAAIC,GAAG,CAAC,KAAKvB,QAAQO,IAAI,CAACO,aAAa,CAACc,SAAS;QACjDnB,OAAOkB,IAAI,CAAC;IACd;IAEAlB,OAAOkB,IAAI,CAAC,CAAC,SAAS,EAAE7B,OAAOqB,IAAI,CAAC,kBAAkB,CAAC;IACvD,MAAM,EAAEU,KAAK,EAAEC,UAAU,EAAE,GAAG,MAAMzC,YAAY6B,WAAW;QAAET;QAAQa;QAAKZ;IAAK;IAC/ED,OAAOkB,IAAI,CAAC;IAEZ,OAAO;QACLG;QACAZ;QACAT;QACAoB,OAAO;YACL,MAAMA;YACN,MAAM7B,QAAQ6B,KAAK;QACrB;IACF;AACF"}
@@ -1,5 +1,6 @@
1
1
  export { createConfig, parseConfig } from './config.js';
2
2
  export { createHTTPServer } from './http.js';
3
+ export type { AuthMiddleware, OAuthAdapters, OAuthRuntimeDeps } from './oauth-google.js';
3
4
  export { createOAuthAdapters } from './oauth-google.js';
4
5
  export * from './runtime.js';
5
6
  export { createStdioServer } from './stdio.js';
@@ -1 +1 @@
1
- {"version":3,"sources":["/Users/kevin/Dev/Projects/ai/mcp-z/servers/mcp-drive/src/setup/index.ts"],"sourcesContent":["export { createConfig, parseConfig } from './config.js';\nexport { createHTTPServer } from './http.js';\nexport { createOAuthAdapters } from './oauth-google.js';\nexport * from './runtime.js';\nexport { createStdioServer } from './stdio.js';\n"],"names":["createConfig","parseConfig","createHTTPServer","createOAuthAdapters","createStdioServer"],"mappings":"AAAA,SAASA,YAAY,EAAEC,WAAW,QAAQ,cAAc;AACxD,SAASC,gBAAgB,QAAQ,YAAY;AAC7C,SAASC,mBAAmB,QAAQ,oBAAoB;AACxD,cAAc,eAAe;AAC7B,SAASC,iBAAiB,QAAQ,aAAa"}
1
+ {"version":3,"sources":["/Users/kevin/Dev/Projects/mcp-z/mcp-drive/src/setup/index.ts"],"sourcesContent":["export { createConfig, parseConfig } from './config.ts';\nexport { createHTTPServer } from './http.ts';\nexport type { AuthMiddleware, OAuthAdapters, OAuthRuntimeDeps } from './oauth-google.ts';\nexport { createOAuthAdapters } from './oauth-google.ts';\nexport * from './runtime.ts';\nexport { createStdioServer } from './stdio.ts';\n"],"names":["createConfig","parseConfig","createHTTPServer","createOAuthAdapters","createStdioServer"],"mappings":"AAAA,SAASA,YAAY,EAAEC,WAAW,QAAQ,cAAc;AACxD,SAASC,gBAAgB,QAAQ,YAAY;AAE7C,SAASC,mBAAmB,QAAQ,oBAAoB;AACxD,cAAc,eAAe;AAC7B,SAASC,iBAAiB,QAAQ,aAAa"}
@@ -1,4 +1,4 @@
1
- import { type AuthEmailProvider } from '@mcp-z/oauth';
1
+ import { type AccountAuthProvider } from '@mcp-z/oauth';
2
2
  import type { CachedToken } from '@mcp-z/oauth-google';
3
3
  import { DcrOAuthProvider, LoopbackOAuthProvider, ServiceAccountProvider } from '@mcp-z/oauth-google';
4
4
  import type { Logger, PromptModule, ToolModule } from '@mcp-z/server';
@@ -41,10 +41,11 @@ export interface AuthMiddleware {
41
41
  export interface OAuthAdapters {
42
42
  primary: LoopbackOAuthProvider | ServiceAccountProvider | DcrOAuthProvider;
43
43
  middleware: AuthMiddleware;
44
- authAdapter: AuthEmailProvider;
44
+ authAdapter: AccountAuthProvider;
45
45
  accountTools: ToolModule[];
46
46
  accountPrompts: PromptModule[];
47
47
  dcrRouter?: Router;
48
+ loopbackRouter?: Router;
48
49
  }
49
50
  /**
50
51
  * Create Drive OAuth adapters based on transport configuration