@mcp-z/mcp-sheets 2.0.0 → 2.1.1

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 (137) hide show
  1. package/dist/cjs/lib/google-auth.d.cts +9 -0
  2. package/dist/cjs/lib/google-auth.d.ts +9 -0
  3. package/dist/cjs/lib/google-auth.js +16 -0
  4. package/dist/cjs/lib/google-auth.js.map +1 -0
  5. package/dist/cjs/mcp/resources/spreadsheet.js +4 -3
  6. package/dist/cjs/mcp/resources/spreadsheet.js.map +1 -1
  7. package/dist/cjs/mcp/tools/cells-format.js +4 -3
  8. package/dist/cjs/mcp/tools/cells-format.js.map +1 -1
  9. package/dist/cjs/mcp/tools/chart-create.js +4 -3
  10. package/dist/cjs/mcp/tools/chart-create.js.map +1 -1
  11. package/dist/cjs/mcp/tools/columns-get.js +4 -3
  12. package/dist/cjs/mcp/tools/columns-get.js.map +1 -1
  13. package/dist/cjs/mcp/tools/columns-update.js +4 -3
  14. package/dist/cjs/mcp/tools/columns-update.js.map +1 -1
  15. package/dist/cjs/mcp/tools/dimensions-batch-update.js +4 -3
  16. package/dist/cjs/mcp/tools/dimensions-batch-update.js.map +1 -1
  17. package/dist/cjs/mcp/tools/dimensions-move.js +4 -3
  18. package/dist/cjs/mcp/tools/dimensions-move.js.map +1 -1
  19. package/dist/cjs/mcp/tools/rows-append.js +4 -3
  20. package/dist/cjs/mcp/tools/rows-append.js.map +1 -1
  21. package/dist/cjs/mcp/tools/rows-csv-append.js +4 -3
  22. package/dist/cjs/mcp/tools/rows-csv-append.js.map +1 -1
  23. package/dist/cjs/mcp/tools/rows-get.js +4 -3
  24. package/dist/cjs/mcp/tools/rows-get.js.map +1 -1
  25. package/dist/cjs/mcp/tools/sheet-copy-to.js +4 -3
  26. package/dist/cjs/mcp/tools/sheet-copy-to.js.map +1 -1
  27. package/dist/cjs/mcp/tools/sheet-copy.js +4 -3
  28. package/dist/cjs/mcp/tools/sheet-copy.js.map +1 -1
  29. package/dist/cjs/mcp/tools/sheet-create.js +4 -3
  30. package/dist/cjs/mcp/tools/sheet-create.js.map +1 -1
  31. package/dist/cjs/mcp/tools/sheet-delete.js +4 -3
  32. package/dist/cjs/mcp/tools/sheet-delete.js.map +1 -1
  33. package/dist/cjs/mcp/tools/sheet-find.js +4 -3
  34. package/dist/cjs/mcp/tools/sheet-find.js.map +1 -1
  35. package/dist/cjs/mcp/tools/sheet-rename.js +4 -3
  36. package/dist/cjs/mcp/tools/sheet-rename.js.map +1 -1
  37. package/dist/cjs/mcp/tools/spreadsheet-copy.js +7 -5
  38. package/dist/cjs/mcp/tools/spreadsheet-copy.js.map +1 -1
  39. package/dist/cjs/mcp/tools/spreadsheet-create.js +4 -3
  40. package/dist/cjs/mcp/tools/spreadsheet-create.js.map +1 -1
  41. package/dist/cjs/mcp/tools/spreadsheet-find.js +7 -5
  42. package/dist/cjs/mcp/tools/spreadsheet-find.js.map +1 -1
  43. package/dist/cjs/mcp/tools/spreadsheet-rename.js +4 -3
  44. package/dist/cjs/mcp/tools/spreadsheet-rename.js.map +1 -1
  45. package/dist/cjs/mcp/tools/validation-set.js +4 -3
  46. package/dist/cjs/mcp/tools/validation-set.js.map +1 -1
  47. package/dist/cjs/mcp/tools/values-batch-update.js +4 -3
  48. package/dist/cjs/mcp/tools/values-batch-update.js.map +1 -1
  49. package/dist/cjs/mcp/tools/values-clear.js +4 -3
  50. package/dist/cjs/mcp/tools/values-clear.js.map +1 -1
  51. package/dist/cjs/mcp/tools/values-csv-update.js +4 -3
  52. package/dist/cjs/mcp/tools/values-csv-update.js.map +1 -1
  53. package/dist/cjs/mcp/tools/values-markdown-update.js +4 -3
  54. package/dist/cjs/mcp/tools/values-markdown-update.js.map +1 -1
  55. package/dist/cjs/mcp/tools/values-replace.js +4 -3
  56. package/dist/cjs/mcp/tools/values-replace.js.map +1 -1
  57. package/dist/cjs/mcp/tools/values-search.js +4 -3
  58. package/dist/cjs/mcp/tools/values-search.js.map +1 -1
  59. package/dist/cjs/spreadsheet/data-operations.d.cts +1 -1
  60. package/dist/cjs/spreadsheet/data-operations.d.ts +1 -1
  61. package/dist/cjs/spreadsheet/data-operations.js.map +1 -1
  62. package/dist/cjs/spreadsheet/markdown-runs.d.cts +1 -31
  63. package/dist/cjs/spreadsheet/markdown-runs.d.ts +1 -31
  64. package/dist/cjs/spreadsheet/markdown-runs.js +31 -31
  65. package/dist/cjs/spreadsheet/markdown-runs.js.map +1 -1
  66. package/dist/cjs/spreadsheet/sheet-operations.d.cts +1 -1
  67. package/dist/cjs/spreadsheet/sheet-operations.d.ts +1 -1
  68. package/dist/cjs/spreadsheet/sheet-operations.js.map +1 -1
  69. package/dist/cjs/spreadsheet/spreadsheet-management.d.cts +2 -1
  70. package/dist/cjs/spreadsheet/spreadsheet-management.d.ts +2 -1
  71. package/dist/cjs/spreadsheet/spreadsheet-management.js.map +1 -1
  72. package/dist/esm/lib/google-auth.d.ts +9 -0
  73. package/dist/esm/lib/google-auth.js +11 -0
  74. package/dist/esm/lib/google-auth.js.map +1 -0
  75. package/dist/esm/mcp/resources/spreadsheet.js +4 -3
  76. package/dist/esm/mcp/resources/spreadsheet.js.map +1 -1
  77. package/dist/esm/mcp/tools/cells-format.js +4 -3
  78. package/dist/esm/mcp/tools/cells-format.js.map +1 -1
  79. package/dist/esm/mcp/tools/chart-create.js +4 -3
  80. package/dist/esm/mcp/tools/chart-create.js.map +1 -1
  81. package/dist/esm/mcp/tools/columns-get.js +5 -4
  82. package/dist/esm/mcp/tools/columns-get.js.map +1 -1
  83. package/dist/esm/mcp/tools/columns-update.js +4 -3
  84. package/dist/esm/mcp/tools/columns-update.js.map +1 -1
  85. package/dist/esm/mcp/tools/dimensions-batch-update.js +4 -3
  86. package/dist/esm/mcp/tools/dimensions-batch-update.js.map +1 -1
  87. package/dist/esm/mcp/tools/dimensions-move.js +4 -3
  88. package/dist/esm/mcp/tools/dimensions-move.js.map +1 -1
  89. package/dist/esm/mcp/tools/rows-append.js +4 -3
  90. package/dist/esm/mcp/tools/rows-append.js.map +1 -1
  91. package/dist/esm/mcp/tools/rows-csv-append.js +5 -4
  92. package/dist/esm/mcp/tools/rows-csv-append.js.map +1 -1
  93. package/dist/esm/mcp/tools/rows-get.js +4 -3
  94. package/dist/esm/mcp/tools/rows-get.js.map +1 -1
  95. package/dist/esm/mcp/tools/sheet-copy-to.js +4 -3
  96. package/dist/esm/mcp/tools/sheet-copy-to.js.map +1 -1
  97. package/dist/esm/mcp/tools/sheet-copy.js +4 -3
  98. package/dist/esm/mcp/tools/sheet-copy.js.map +1 -1
  99. package/dist/esm/mcp/tools/sheet-create.js +4 -3
  100. package/dist/esm/mcp/tools/sheet-create.js.map +1 -1
  101. package/dist/esm/mcp/tools/sheet-delete.js +4 -3
  102. package/dist/esm/mcp/tools/sheet-delete.js.map +1 -1
  103. package/dist/esm/mcp/tools/sheet-find.js +4 -3
  104. package/dist/esm/mcp/tools/sheet-find.js.map +1 -1
  105. package/dist/esm/mcp/tools/sheet-rename.js +4 -3
  106. package/dist/esm/mcp/tools/sheet-rename.js.map +1 -1
  107. package/dist/esm/mcp/tools/spreadsheet-copy.js +7 -5
  108. package/dist/esm/mcp/tools/spreadsheet-copy.js.map +1 -1
  109. package/dist/esm/mcp/tools/spreadsheet-create.js +4 -3
  110. package/dist/esm/mcp/tools/spreadsheet-create.js.map +1 -1
  111. package/dist/esm/mcp/tools/spreadsheet-find.js +7 -5
  112. package/dist/esm/mcp/tools/spreadsheet-find.js.map +1 -1
  113. package/dist/esm/mcp/tools/spreadsheet-rename.js +4 -3
  114. package/dist/esm/mcp/tools/spreadsheet-rename.js.map +1 -1
  115. package/dist/esm/mcp/tools/validation-set.js +4 -3
  116. package/dist/esm/mcp/tools/validation-set.js.map +1 -1
  117. package/dist/esm/mcp/tools/values-batch-update.js +4 -3
  118. package/dist/esm/mcp/tools/values-batch-update.js.map +1 -1
  119. package/dist/esm/mcp/tools/values-clear.js +4 -3
  120. package/dist/esm/mcp/tools/values-clear.js.map +1 -1
  121. package/dist/esm/mcp/tools/values-csv-update.js +5 -4
  122. package/dist/esm/mcp/tools/values-csv-update.js.map +1 -1
  123. package/dist/esm/mcp/tools/values-markdown-update.js +4 -3
  124. package/dist/esm/mcp/tools/values-markdown-update.js.map +1 -1
  125. package/dist/esm/mcp/tools/values-replace.js +4 -3
  126. package/dist/esm/mcp/tools/values-replace.js.map +1 -1
  127. package/dist/esm/mcp/tools/values-search.js +4 -3
  128. package/dist/esm/mcp/tools/values-search.js.map +1 -1
  129. package/dist/esm/spreadsheet/data-operations.d.ts +1 -1
  130. package/dist/esm/spreadsheet/data-operations.js.map +1 -1
  131. package/dist/esm/spreadsheet/markdown-runs.d.ts +1 -31
  132. package/dist/esm/spreadsheet/markdown-runs.js.map +1 -1
  133. package/dist/esm/spreadsheet/sheet-operations.d.ts +1 -1
  134. package/dist/esm/spreadsheet/sheet-operations.js.map +1 -1
  135. package/dist/esm/spreadsheet/spreadsheet-management.d.ts +2 -1
  136. package/dist/esm/spreadsheet/spreadsheet-management.js.map +1 -1
  137. package/package.json +5 -5
@@ -8,10 +8,11 @@ Object.defineProperty(exports, "default", {
8
8
  return createTool;
9
9
  }
10
10
  });
11
+ var _sheets = require("@googleapis/sheets");
11
12
  var _oauthgoogle = require("@mcp-z/oauth-google");
12
13
  var _server = require("@mcp-z/server");
13
- var _googleapis = require("googleapis");
14
14
  var _zod = require("zod");
15
+ var _googleauthts = require("../../lib/google-auth.js");
15
16
  var _indexts = require("../../schemas/index.js");
16
17
  function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) {
17
18
  try {
@@ -195,9 +196,9 @@ function handler(_0, _1) {
195
196
  ,
196
197
  5
197
198
  ]);
198
- sheets = _googleapis.google.sheets({
199
+ sheets = (0, _sheets.sheets)({
199
200
  version: 'v4',
200
- auth: extra.authContext.auth
201
+ auth: (0, _googleauthts.googleAuth)(extra.authContext.auth)
201
202
  });
202
203
  return [
203
204
  4,
@@ -1 +1 @@
1
- {"version":3,"sources":["/Users/kevin/Dev/OpenSource/ai/mcp-z/mcp-sheets/src/mcp/tools/rows-get.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, ToolModule } from '@mcp-z/server';\nimport { ProtocolError, ProtocolErrorCode } from '@mcp-z/server';\nimport { google } from 'googleapis';\nimport { z } from 'zod';\nimport { SheetCellSchema, SheetGidSchema, SpreadsheetIdSchema } from '../../schemas/index.ts';\n\nconst inputSchema = z.object({\n id: SpreadsheetIdSchema,\n gid: SheetGidSchema,\n range: z.string().min(1).describe('A1 notation range to fetch (e.g., \"B5\", \"A5:D5\", \"B:B\", \"5:5\")'),\n render: z.enum(['FORMATTED_VALUE', 'UNFORMATTED_VALUE', 'FORMULA']).optional().describe('How to render cell values. FORMATTED_VALUE (default): calculated with formatting. UNFORMATTED_VALUE: calculated without formatting. FORMULA: show formula text instead of result.'),\n});\n\n// Success branch schema - uses rows: for consistency with standard vocabulary\nconst successBranchSchema = z.object({\n type: z.literal('success'),\n range: z.string().describe('The A1 notation range that was retrieved'),\n rows: z.array(z.array(SheetCellSchema)).describe('2D array of row data (each inner array is a row)'),\n});\n\n// Output schema with auth_required support\nconst outputSchema = z.discriminatedUnion('type', [successBranchSchema, AuthRequiredBranchSchema]);\n\nconst config = {\n description: 'Fetch row data from a specific range in A1 notation. Best used after values-search to get surrounding context. Use a1-notation prompt for syntax reference.',\n inputSchema,\n outputSchema: z.object({\n result: outputSchema,\n }),\n} as const;\n\nexport type Input = z.infer<typeof inputSchema>;\nexport type Output = z.infer<typeof outputSchema>;\n\nasync function handler({ id, gid, range, render }: Input, extra: EnrichedExtra): Promise<CallToolResult> {\n const logger = extra.logger;\n logger.info('sheets.rows.get called', { id, gid, range, render });\n\n try {\n const sheets = google.sheets({ version: 'v4', auth: extra.authContext.auth });\n\n // Get sheet details using the gid to get sheet title\n const spreadsheetResponse = await sheets.spreadsheets.get({\n spreadsheetId: id,\n fields: 'sheets.properties.sheetId,sheets.properties.title',\n });\n\n const sheet = spreadsheetResponse.data.sheets?.find((s) => String(s.properties?.sheetId) === gid);\n\n if (!sheet) {\n logger.info('sheets.rows.get sheet not found', { id, gid, range });\n throw new ProtocolError(ProtocolErrorCode.InvalidParams, `Sheet not found: ${gid}`);\n }\n\n const sheetTitle = sheet.properties?.title ?? '';\n\n // Construct full range with sheet title\n const fullRange = `${sheetTitle}!${range}`;\n\n const response = await sheets.spreadsheets.values.get({\n spreadsheetId: id,\n range: fullRange,\n valueRenderOption: render || 'FORMATTED_VALUE',\n });\n\n const res = response.data;\n const rows = Array.isArray(res.values) ? (res.values as (string | number | boolean | null)[][]) : [];\n\n logger.info('sheets.rows.get success', { id, gid, range, rowCount: rows.length });\n\n const result: Output = {\n type: 'success' as const,\n range: res.range || fullRange,\n rows,\n };\n\n return {\n content: [{ type: 'text' as const, text: JSON.stringify(result) }],\n structuredContent: { result },\n };\n } catch (error) {\n const message = error instanceof Error ? error.message : String(error);\n logger.error('sheets.rows.get error', { error: message });\n\n // Throw ProtocolError for proper MCP error handling\n throw new ProtocolError(ProtocolErrorCode.InternalError, `Error getting rows: ${message}`, {\n stack: error instanceof Error ? error.stack : undefined,\n });\n }\n}\n\nexport default function createTool() {\n return {\n name: 'rows-get',\n config,\n handler,\n } satisfies ToolModule;\n}\n"],"names":["createTool","AuthRequiredBranchSchema","schemas","inputSchema","z","object","id","SpreadsheetIdSchema","gid","SheetGidSchema","range","string","min","describe","render","enum","optional","successBranchSchema","type","literal","rows","array","SheetCellSchema","outputSchema","discriminatedUnion","config","description","result","handler","extra","logger","spreadsheetResponse","sheet","sheets","sheetTitle","fullRange","response","res","error","message","info","google","version","auth","authContext","spreadsheets","get","spreadsheetId","fields","data","find","s","String","properties","sheetId","ProtocolError","ProtocolErrorCode","InvalidParams","title","values","valueRenderOption","Array","isArray","rowCount","length","content","text","JSON","stringify","structuredContent","Error","Internal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AI,CAAC,2BAA2B;wBAAElC,IAAAA;wBAAIE,KAAAA;wBAAKE,OAAAA;wBAAOqD,UAAU3C,KAAK4C,MAAM;oBAAC;oBAEzErC,SAAiB;wBACrBT,MAAM;wBACNR,OAAO2B,IAAI3B,KAAK,IAAIyB;wBACpBf,MAAAA;oBACF;oBAEA;;wBAAO;4BACL6C,OAAO;gCAAG;oCAAE/C,MAAM;oCAAiBgD,MAAMC,KAAKC,SAAS,CAACzC;gCAAQ;;4BAChE0C,mBAAmB;gCAAE1C,QAAAA;4BAAO;wBAC9B;;;oBACOW;oBACDC,UAAUD,AAAK,YAALA,OAAiBgC,SAAQhC,MAAMC,OAAO,GAAGa,OAAOd;oBAChER,OAAOQ,KAAK,CAAC,yBAAyB;wBAAEA,OAAOC;oBAAQ;oBAEvD,oDAAoD;oBACpD,MAAM,IAAIgB,qBAAa,CAACC,yBAAiB,CAACe,aAAa,EAAE,AAAC,uBAA8B,OAARhC,UAAW;wBACzFiC,OAAOlC,AAAK,YAALA,OAAiBgC,SAAQhC,MAAMkC,KAAK,GAAGC;oBAChD;;;;;;;IAEJ;;AAEe,SAASzE;IACtB,OAAO;QACL0E,MAAM;QACNjD,QAAAA;QACAG,SAAAA;IACF;AACF"}
1
+ {"version":3,"sources":["/Users/kevin/Dev/OpenSource/ai/mcp-z/mcp-sheets/src/mcp/tools/rows-get.ts"],"sourcesContent":["import { sheets as sheetsApi } from '@googleapis/sheets';\nimport type { EnrichedExtra } from '@mcp-z/oauth-google';\nimport { schemas } from '@mcp-z/oauth-google';\n\nconst { AuthRequiredBranchSchema } = schemas;\n\nimport type { CallToolResult, ToolModule } from '@mcp-z/server';\nimport { ProtocolError, ProtocolErrorCode } from '@mcp-z/server';\nimport { z } from 'zod';\nimport { googleAuth } from '../../lib/google-auth.ts';\nimport { SheetCellSchema, SheetGidSchema, SpreadsheetIdSchema } from '../../schemas/index.ts';\n\nconst inputSchema = z.object({\n id: SpreadsheetIdSchema,\n gid: SheetGidSchema,\n range: z.string().min(1).describe('A1 notation range to fetch (e.g., \"B5\", \"A5:D5\", \"B:B\", \"5:5\")'),\n render: z.enum(['FORMATTED_VALUE', 'UNFORMATTED_VALUE', 'FORMULA']).optional().describe('How to render cell values. FORMATTED_VALUE (default): calculated with formatting. UNFORMATTED_VALUE: calculated without formatting. FORMULA: show formula text instead of result.'),\n});\n\n// Success branch schema - uses rows: for consistency with standard vocabulary\nconst successBranchSchema = z.object({\n type: z.literal('success'),\n range: z.string().describe('The A1 notation range that was retrieved'),\n rows: z.array(z.array(SheetCellSchema)).describe('2D array of row data (each inner array is a row)'),\n});\n\n// Output schema with auth_required support\nconst outputSchema = z.discriminatedUnion('type', [successBranchSchema, AuthRequiredBranchSchema]);\n\nconst config = {\n description: 'Fetch row data from a specific range in A1 notation. Best used after values-search to get surrounding context. Use a1-notation prompt for syntax reference.',\n inputSchema,\n outputSchema: z.object({\n result: outputSchema,\n }),\n} as const;\n\nexport type Input = z.infer<typeof inputSchema>;\nexport type Output = z.infer<typeof outputSchema>;\n\nasync function handler({ id, gid, range, render }: Input, extra: EnrichedExtra): Promise<CallToolResult> {\n const logger = extra.logger;\n logger.info('sheets.rows.get called', { id, gid, range, render });\n\n try {\n const sheets = sheetsApi({ version: 'v4', auth: googleAuth(extra.authContext.auth) });\n\n // Get sheet details using the gid to get sheet title\n const spreadsheetResponse = await sheets.spreadsheets.get({\n spreadsheetId: id,\n fields: 'sheets.properties.sheetId,sheets.properties.title',\n });\n\n const sheet = spreadsheetResponse.data.sheets?.find((s) => String(s.properties?.sheetId) === gid);\n\n if (!sheet) {\n logger.info('sheets.rows.get sheet not found', { id, gid, range });\n throw new ProtocolError(ProtocolErrorCode.InvalidParams, `Sheet not found: ${gid}`);\n }\n\n const sheetTitle = sheet.properties?.title ?? '';\n\n // Construct full range with sheet title\n const fullRange = `${sheetTitle}!${range}`;\n\n const response = await sheets.spreadsheets.values.get({\n spreadsheetId: id,\n range: fullRange,\n valueRenderOption: render || 'FORMATTED_VALUE',\n });\n\n const res = response.data;\n const rows = Array.isArray(res.values) ? (res.values as (string | number | boolean | null)[][]) : [];\n\n logger.info('sheets.rows.get success', { id, gid, range, rowCount: rows.length });\n\n const result: Output = {\n type: 'success' as const,\n range: res.range || fullRange,\n rows,\n };\n\n return {\n content: [{ type: 'text' as const, text: JSON.stringify(result) }],\n structuredContent: { result },\n };\n } catch (error) {\n const message = error instanceof Error ? error.message : String(error);\n logger.error('sheets.rows.get error', { error: message });\n\n // Throw ProtocolError for proper MCP error handling\n throw new ProtocolError(ProtocolErrorCode.InternalError, `Error getting rows: ${message}`, {\n stack: error instanceof Error ? error.stack : undefined,\n });\n }\n}\n\nexport default function createTool() {\n return {\n name: 'rows-get',\n config,\n handler,\n } satisfies ToolModule;\n}\n"],"names":["createTool","AuthRequiredBranchSchema","schemas","inputSchema","z","object","id","SpreadsheetIdSchema","gid","SheetGidSchema","range","string","min","describe","render","enum","optional","successBranchSchema","type","literal","rows","array","SheetCellSchema","outputSchema","discriminatedUnion","config","description","result","handler","extra","logger","spreadsheetResponse","sheet","sheets","sheetTitle","fullRange","response","res","error","message","info","sheetsApi","version","auth","googleAuth","authContext","spreadsheets","get","spreadsheetId","fields","data","find","s","String","properties","sheetId","ProtocolError","ProtocolErrorCode","InvalidParams","title","values","valueRenderOption","Array","isArray","rowCount","length","content","text","JSON","stringify","structuredContent","Error","InternalError","stack","undefined","name"],"mappings":";;;;+BAiGA;;;eAAwBA;;;sBAjGY;2BAEZ;sBAKyB;mBAC/B;4BACS;uBAC0C;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AANrE,IAAM,AAAEC,2BAA6BC,oBAAO,CAApCD;AAQR,IAAME,cAAcC,MAAC,CAACC,MAAM,CAAC;IAC3BC,IAAIC,4BAAmB;IACvBC,KAAKC,uBAAc;I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OW;oBACDC,UAAUD,AAAK,YAALA,OAAiBiC,SAAQjC,MAAMC,OAAO,GAAGc,OAAOf;oBAChER,OAAOQ,KAAK,CAAC,yBAAyB;wBAAEA,OAAOC;oBAAQ;oBAEvD,oDAAoD;oBACpD,MAAM,IAAIiB,qBAAa,CAACC,yBAAiB,CAACe,aAAa,EAAE,AAAC,uBAA8B,OAARjC,UAAW;wBACzFkC,OAAOnC,AAAK,YAALA,OAAiBiC,SAAQjC,MAAMmC,KAAK,GAAGC;oBAChD;;;;;;;IAEJ;;AAEe,SAAS1E;IACtB,OAAO;QACL2E,MAAM;QACNlD,QAAAA;QACAG,SAAAA;IACF;AACF"}
@@ -8,10 +8,11 @@ Object.defineProperty(exports, "default", {
8
8
  return createTool;
9
9
  }
10
10
  });
11
+ var _sheets = require("@googleapis/sheets");
11
12
  var _oauthgoogle = require("@mcp-z/oauth-google");
12
13
  var _server = require("@mcp-z/server");
13
- var _googleapis = require("googleapis");
14
14
  var _zod = require("zod");
15
+ var _googleauthts = require("../../lib/google-auth.js");
15
16
  var _indexts = require("../../schemas/index.js");
16
17
  function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) {
17
18
  try {
@@ -202,9 +203,9 @@ function handler(_0, _1) {
202
203
  ,
203
204
  7
204
205
  ]);
205
- sheets = _googleapis.google.sheets({
206
+ sheets = (0, _sheets.sheets)({
206
207
  version: 'v4',
207
- auth: extra.authContext.auth
208
+ auth: (0, _googleauthts.googleAuth)(extra.authContext.auth)
208
209
  });
209
210
  return [
210
211
  4,
@@ -1 +1 @@
1
- {"version":3,"sources":["/Users/kevin/Dev/OpenSource/ai/mcp-z/mcp-sheets/src/mcp/tools/sheet-copy-to.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, ToolModule } from '@mcp-z/server';\nimport { ProtocolError, ProtocolErrorCode } from '@mcp-z/server';\nimport { google } from 'googleapis';\nimport { z } from 'zod';\nimport { SheetGidSchema, SpreadsheetIdSchema } from '../../schemas/index.ts';\n\n// Note: Using contextual descriptions for source/destination IDs since they describe different spreadsheets/sheets\n\nconst inputSchema = z.object({\n sourceId: SpreadsheetIdSchema.describe('Source spreadsheet ID'),\n sourceGid: SheetGidSchema.describe('Source sheet grid ID to copy'),\n destinationId: SpreadsheetIdSchema.describe('Destination spreadsheet ID'),\n newTitle: z.coerce.string().trim().min(1).optional().describe('New name for the copied sheet (optional, will use auto-generated name if not provided)'),\n});\n\n// Success branch schema\nconst successBranchSchema = z.object({\n type: z.literal('success'),\n operationSummary: z.string().describe('Summary of the copy operation'),\n itemsProcessed: z.number().describe('Total items attempted (always 1)'),\n itemsChanged: z.number().describe('Successfully copied (always 1 on success)'),\n completedAt: z.string().describe('ISO datetime when operation completed'),\n sourceId: z.string().describe('Source spreadsheet ID'),\n sourceGid: z.string().describe('Source sheet ID'),\n sourceTitle: z.string().describe('Source sheet title'),\n destinationId: z.string().describe('Destination spreadsheet ID'),\n destinationGid: z.string().describe('Copied sheet ID in destination'),\n destinationTitle: z.string().describe('Title of the copied sheet in destination'),\n sheetUrl: z.string().describe('URL of the copied sheet'),\n renamed: z.boolean().describe('Whether the sheet was renamed after copying'),\n});\n\n// Output schema with auth_required support\nconst outputSchema = z.discriminatedUnion('type', [successBranchSchema, AuthRequiredBranchSchema]);\n\nconst config = {\n description: 'Copy a sheet to another spreadsheet. Copies all data, formatting, and charts.',\n inputSchema,\n outputSchema: z.object({\n result: outputSchema,\n }),\n} as const;\n\nexport type Input = z.infer<typeof inputSchema>;\nexport type Output = z.infer<typeof outputSchema>;\n\nasync function handler({ sourceId, sourceGid, destinationId, newTitle }: Input, extra: EnrichedExtra): Promise<CallToolResult> {\n const logger = extra.logger;\n logger.info('sheets.sheet.copyTo called', { sourceId, sourceGid, destinationId, newTitle });\n\n try {\n const sheets = google.sheets({ version: 'v4', auth: extra.authContext.auth });\n\n // Get source sheet info\n const sourceInfo = await sheets.spreadsheets.get({\n spreadsheetId: sourceId,\n fields: 'sheets.properties.sheetId,sheets.properties.title',\n });\n\n const sourceSheet = sourceInfo.data.sheets?.find((s) => String(s.properties?.sheetId) === sourceGid);\n if (!sourceSheet?.properties) {\n throw new ProtocolError(ProtocolErrorCode.InvalidParams, `Source sheet with gid \"${sourceGid}\" not found in spreadsheet`);\n }\n\n const sourceTitle = sourceSheet.properties.title || '';\n\n // Copy the sheet to the destination spreadsheet\n const copyResponse = await sheets.spreadsheets.sheets.copyTo({\n spreadsheetId: sourceId,\n sheetId: Number(sourceGid),\n requestBody: {\n destinationSpreadsheetId: destinationId,\n },\n });\n\n const newSheetId = copyResponse.data.sheetId;\n let destinationTitle = copyResponse.data.title || '';\n\n if (!newSheetId) {\n throw new Error('Failed to retrieve new sheet ID from API response');\n }\n\n // If newTitle is provided, rename the sheet in the destination\n let renamed = false;\n if (newTitle && newTitle !== destinationTitle) {\n await sheets.spreadsheets.batchUpdate({\n spreadsheetId: destinationId,\n requestBody: {\n requests: [\n {\n updateSheetProperties: {\n properties: { sheetId: newSheetId, title: newTitle },\n fields: 'title',\n },\n },\n ],\n },\n });\n destinationTitle = newTitle;\n renamed = true;\n }\n\n logger.info('sheets.sheet.copyTo success', {\n sourceId,\n sourceGid,\n destinationId,\n destinationGid: String(newSheetId),\n renamed,\n });\n\n const result: Output = {\n type: 'success' as const,\n operationSummary: `Copied sheet \"${sourceTitle}\" to destination${renamed ? ` as \"${destinationTitle}\"` : ''}`,\n itemsProcessed: 1,\n itemsChanged: 1,\n completedAt: new Date().toISOString(),\n sourceId,\n sourceGid,\n sourceTitle,\n destinationId,\n destinationGid: String(newSheetId),\n destinationTitle,\n sheetUrl: `https://docs.google.com/spreadsheets/d/${destinationId}/edit#gid=${newSheetId}`,\n renamed,\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 if (error instanceof ProtocolError) {\n throw error;\n }\n const message = error instanceof Error ? error.message : String(error);\n logger.error('sheets.sheet.copyTo error', { error: message });\n\n throw new ProtocolError(ProtocolErrorCode.InternalError, `Error copying sheet to another spreadsheet: ${message}`, {\n stack: error instanceof Error ? error.stack : undefined,\n });\n }\n}\n\nexport default function createTool() {\n return {\n name: 'sheet-copy-to',\n config,\n handler,\n } satisfies ToolModule;\n}\n"],"names":["createTool","AuthRequiredBranchSchema","schemas","inputSchema","z","object","sourceId","SpreadsheetIdSchema","describe","sourceGid","SheetGidSchema","destinationId","newTitle","coerce","string","trim","min","optional","successBranchSchema","type","literal","operationSummary","itemsProcessed","number","itemsChanged","completedAt","sourceTitle","destinationGid","destinationTitle","sheetUrl","renamed","boolean","outputSchema","discriminatedUnion","config","description","result","handler","extra","logger","sourceInfo","sheets","sourceSheet","copyResponse","newSheetId","error","message","info","google","version","auth","authContext","spreadsheets","get","spreadsheetId","fields","data","find","s","String","properties","sheetId","ProtocolError","ProtocolErrorCode","InvalidParams","title","copyTo","Number","requestBody","destinationSpreadsheetId","Error","batchUpdate","requests","updateSheetProperties","Date","toISOString","content","text","JSON","stringify","structuredContent","InternalError","stack","undefined","name"],"mappings":";;;;+BAyJA;;;eAAwBA;;;2BAxJA;sBAKyB;0BAC1B;mBACL;uBACkC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AANpD,IAAM,AAAEC,2BAA6BC,oBAAO,CAApCD;AAQR,mHAAmH;AAEnH,IAAME,cAAcC,MAAC,CAACC,MAAM,CAAC;IAC3BC,UAAUC,4BAAmB,CAACC,QAAQ,CAAC;IACvCC,WAAWC,uBAAc,CAACF,QAAQ,CAAC;IACnCG,eAAeJ,4BAAmB,CAACC,QAAQ,CAAC;IAC5CI,UAAUR,MAAC,CAACS,MAAM,CAACC,MAAM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E,AAAC,+CAAsD,OAARnC,UAAW;wBACjHoC,OAAOrC,AAAK,YAALA,OAAiByB,SAAQzB,MAAMqC,KAAK,GAAGC;oBAChD;;;;;;;IAEJ;;AAEe,SAASnF;IACtB,OAAO;QACLoF,MAAM;QACNlD,QAAAA;QACAG,SAAAA;IACF;AACF"}
1
+ {"version":3,"sources":["/Users/kevin/Dev/OpenSource/ai/mcp-z/mcp-sheets/src/mcp/tools/sheet-copy-to.ts"],"sourcesContent":["import { sheets as sheetsApi } from '@googleapis/sheets';\nimport type { EnrichedExtra } from '@mcp-z/oauth-google';\nimport { schemas } from '@mcp-z/oauth-google';\n\nconst { AuthRequiredBranchSchema } = schemas;\n\nimport type { CallToolResult, ToolModule } from '@mcp-z/server';\nimport { ProtocolError, ProtocolErrorCode } from '@mcp-z/server';\nimport { z } from 'zod';\nimport { googleAuth } from '../../lib/google-auth.ts';\nimport { SheetGidSchema, SpreadsheetIdSchema } from '../../schemas/index.ts';\n\n// Note: Using contextual descriptions for source/destination IDs since they describe different spreadsheets/sheets\n\nconst inputSchema = z.object({\n sourceId: SpreadsheetIdSchema.describe('Source spreadsheet ID'),\n sourceGid: SheetGidSchema.describe('Source sheet grid ID to copy'),\n destinationId: SpreadsheetIdSchema.describe('Destination spreadsheet ID'),\n newTitle: z.coerce.string().trim().min(1).optional().describe('New name for the copied sheet (optional, will use auto-generated name if not provided)'),\n});\n\n// Success branch schema\nconst successBranchSchema = z.object({\n type: z.literal('success'),\n operationSummary: z.string().describe('Summary of the copy operation'),\n itemsProcessed: z.number().describe('Total items attempted (always 1)'),\n itemsChanged: z.number().describe('Successfully copied (always 1 on success)'),\n completedAt: z.string().describe('ISO datetime when operation completed'),\n sourceId: z.string().describe('Source spreadsheet ID'),\n sourceGid: z.string().describe('Source sheet ID'),\n sourceTitle: z.string().describe('Source sheet title'),\n destinationId: z.string().describe('Destination spreadsheet ID'),\n destinationGid: z.string().describe('Copied sheet ID in destination'),\n destinationTitle: z.string().describe('Title of the copied sheet in destination'),\n sheetUrl: z.string().describe('URL of the copied sheet'),\n renamed: z.boolean().describe('Whether the sheet was renamed after copying'),\n});\n\n// Output schema with auth_required support\nconst outputSchema = z.discriminatedUnion('type', [successBranchSchema, AuthRequiredBranchSchema]);\n\nconst config = {\n description: 'Copy a sheet to another spreadsheet. Copies all data, formatting, and charts.',\n inputSchema,\n outputSchema: z.object({\n result: outputSchema,\n }),\n} as const;\n\nexport type Input = z.infer<typeof inputSchema>;\nexport type Output = z.infer<typeof outputSchema>;\n\nasync function handler({ sourceId, sourceGid, destinationId, newTitle }: Input, extra: EnrichedExtra): Promise<CallToolResult> {\n const logger = extra.logger;\n logger.info('sheets.sheet.copyTo called', { sourceId, sourceGid, destinationId, newTitle });\n\n try {\n const sheets = sheetsApi({ version: 'v4', auth: googleAuth(extra.authContext.auth) });\n\n // Get source sheet info\n const sourceInfo = await sheets.spreadsheets.get({\n spreadsheetId: sourceId,\n fields: 'sheets.properties.sheetId,sheets.properties.title',\n });\n\n const sourceSheet = sourceInfo.data.sheets?.find((s) => String(s.properties?.sheetId) === sourceGid);\n if (!sourceSheet?.properties) {\n throw new ProtocolError(ProtocolErrorCode.InvalidParams, `Source sheet with gid \"${sourceGid}\" not found in spreadsheet`);\n }\n\n const sourceTitle = sourceSheet.properties.title || '';\n\n // Copy the sheet to the destination spreadsheet\n const copyResponse = await sheets.spreadsheets.sheets.copyTo({\n spreadsheetId: sourceId,\n sheetId: Number(sourceGid),\n requestBody: {\n destinationSpreadsheetId: destinationId,\n },\n });\n\n const newSheetId = copyResponse.data.sheetId;\n let destinationTitle = copyResponse.data.title || '';\n\n if (!newSheetId) {\n throw new Error('Failed to retrieve new sheet ID from API response');\n }\n\n // If newTitle is provided, rename the sheet in the destination\n let renamed = false;\n if (newTitle && newTitle !== destinationTitle) {\n await sheets.spreadsheets.batchUpdate({\n spreadsheetId: destinationId,\n requestBody: {\n requests: [\n {\n updateSheetProperties: {\n properties: { sheetId: newSheetId, title: newTitle },\n fields: 'title',\n },\n },\n ],\n },\n });\n destinationTitle = newTitle;\n renamed = true;\n }\n\n logger.info('sheets.sheet.copyTo success', {\n sourceId,\n sourceGid,\n destinationId,\n destinationGid: String(newSheetId),\n renamed,\n });\n\n const result: Output = {\n type: 'success' as const,\n operationSummary: `Copied sheet \"${sourceTitle}\" to destination${renamed ? ` as \"${destinationTitle}\"` : ''}`,\n itemsProcessed: 1,\n itemsChanged: 1,\n completedAt: new Date().toISOString(),\n sourceId,\n sourceGid,\n sourceTitle,\n destinationId,\n destinationGid: String(newSheetId),\n destinationTitle,\n sheetUrl: `https://docs.google.com/spreadsheets/d/${destinationId}/edit#gid=${newSheetId}`,\n renamed,\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 if (error instanceof ProtocolError) {\n throw error;\n }\n const message = error instanceof Error ? error.message : String(error);\n logger.error('sheets.sheet.copyTo error', { error: message });\n\n throw new ProtocolError(ProtocolErrorCode.InternalError, `Error copying sheet to another spreadsheet: ${message}`, {\n stack: error instanceof Error ? error.stack : undefined,\n });\n }\n}\n\nexport default function createTool() {\n return {\n name: 'sheet-copy-to',\n config,\n handler,\n } satisfies ToolModule;\n}\n"],"names":["createTool","AuthRequiredBranchSchema","schemas","inputSchema","z","object","sourceId","SpreadsheetIdSchema","describe","sourceGid","SheetGidSchema","destinationId","newTitle","coerce","string","trim","min","optional","successBranchSchema","type","literal","operationSummary","itemsProcessed","number","itemsChanged","completedAt","sourceTitle","destinationGid","destinationTitle","sheetUrl","renamed","boolean","outputSchema","discriminatedUnion","config","description","result","handler","extra","logger","sourceInfo","sheets","sourceSheet","copyResponse","newSheetId","error","message","info","sheetsApi","version","auth","googleAuth","authContext","spreadsheets","get","spreadsheetId","fields","data","find","s","String","properties","sheetId","ProtocolError","ProtocolErrorCode","InvalidParams","title","copyTo","Number","requestBody","destinationSpreadsheetId","Error","batchUpdate","requests","updateSheetProperties","Date","toISOString","content","text","JS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Af,eAAAA;wBACAgB,gBAAgBiC,OAAOhB;wBACvBhB,kBAAAA;wBACAC,UAAU,AAAC,0CAAmEe,OAA1BjC,eAAc,cAAuB,OAAXiC;wBAC9Ed,SAAAA;oBACF;oBAEA;;wBAAO;4BACL+C,OAAO;gCACL;oCACE1D,MAAM;oCACN2D,MAAMC,KAAKC,SAAS,CAAC5C;gCACvB;;4BAEF6C,mBAAmB;gCAAE7C,QAAAA;4BAAO;wBAC9B;;;oBACOS;oBACP,IAAIA,AAAK,YAALA,OAAiBkB,qBAAa,GAAE;wBAClC,MAAMlB;oBACR;oBACMC,UAAUD,AAAK,YAALA,OAAiB0B,SAAQ1B,MAAMC,OAAO,GAAGc,OAAOf;oBAChEN,OAAOM,KAAK,CAAC,6BAA6B;wBAAEA,OAAOC;oBAAQ;oBAE3D,MAAM,IAAIiB,qBAAa,CAACC,yBAAiB,CAACkB,aAAa,EAAE,AAAC,+CAAsD,OAARpC,UAAW;wBACjHqC,OAAOtC,AAAK,YAALA,OAAiB0B,SAAQ1B,MAAMsC,KAAK,GAAGC;oBAChD;;;;;;;IAEJ;;AAEe,SAASpF;IACtB,OAAO;QACLqF,MAAM;QACNnD,QAAAA;QACAG,SAAAA;IACF;AACF"}
@@ -8,10 +8,11 @@ Object.defineProperty(exports, "default", {
8
8
  return createTool;
9
9
  }
10
10
  });
11
+ var _sheets = require("@googleapis/sheets");
11
12
  var _oauthgoogle = require("@mcp-z/oauth-google");
12
13
  var _server = require("@mcp-z/server");
13
- var _googleapis = require("googleapis");
14
14
  var _zod = require("zod");
15
+ var _googleauthts = require("../../lib/google-auth.js");
15
16
  var _indexts = require("../../schemas/index.js");
16
17
  function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) {
17
18
  try {
@@ -236,9 +237,9 @@ function handler(_0, _1) {
236
237
  ,
237
238
  5
238
239
  ]);
239
- sheets = _googleapis.google.sheets({
240
+ sheets = (0, _sheets.sheets)({
240
241
  version: 'v4',
241
- auth: extra.authContext.auth
242
+ auth: (0, _googleauthts.googleAuth)(extra.authContext.auth)
242
243
  });
243
244
  return [
244
245
  4,
@@ -1 +1 @@
1
- {"version":3,"sources":["/Users/kevin/Dev/OpenSource/ai/mcp-z/mcp-sheets/src/mcp/tools/sheet-copy.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, ToolModule } from '@mcp-z/server';\nimport { ProtocolError, ProtocolErrorCode } from '@mcp-z/server';\nimport { google } from 'googleapis';\nimport { z } from 'zod';\nimport { SheetGidOutput, SheetGidSchema, SpreadsheetIdOutput, SpreadsheetIdSchema } from '../../schemas/index.ts';\n\nconst MAX_BATCH_SIZE = 100;\n\nconst copyItemSchema = z.object({\n newTitle: z.coerce.string().trim().min(1).describe('Name for the copied sheet'),\n insertIndex: z.number().int().min(0).optional().describe('Position to insert the new sheet (0-indexed)'),\n});\n\nconst inputSchema = z.object({\n id: SpreadsheetIdSchema,\n gid: SheetGidSchema,\n copies: z.array(copyItemSchema).min(1).max(MAX_BATCH_SIZE).describe('Array of copies to create from the source sheet'),\n});\n\n// Created sheet info\nconst createdSheetSchema = z.object({\n gid: SheetGidOutput,\n title: z.string().describe('Title of the created sheet'),\n sheetUrl: z.string().describe('URL of the created sheet'),\n});\n\n// Success branch schema - uses items: for consistency with standard vocabulary\nconst successBranchSchema = z.object({\n type: z.literal('success'),\n operationSummary: z.string().describe('Summary of the copy operation'),\n itemsProcessed: z.number().describe('Total copies attempted'),\n itemsChanged: z.number().describe('Successfully created copies'),\n completedAt: z.string().describe('ISO datetime when operation completed'),\n id: SpreadsheetIdOutput,\n sourceGid: z.string().describe('Source sheet ID'),\n sourceTitle: z.string().describe('Source sheet title'),\n items: z.array(createdSheetSchema).describe('Information about created sheets'),\n failures: z\n .array(\n z.object({\n title: z.string(),\n error: z.string(),\n })\n )\n .optional()\n .describe('Failed copies with error messages'),\n});\n\n// Output schema with auth_required support\nconst outputSchema = z.discriminatedUnion('type', [successBranchSchema, AuthRequiredBranchSchema]);\n\nconst config = {\n description: 'Copy a sheet/tab within the same spreadsheet. Supports batch copying: create multiple copies from a single source sheet (e.g., create 12 monthly sheets from a template). Copies all data, formatting, charts, and conditional formatting verbatim.',\n inputSchema,\n outputSchema: z.object({\n result: outputSchema,\n }),\n} as const;\n\nexport type Input = z.infer<typeof inputSchema>;\nexport type Output = z.infer<typeof outputSchema>;\n\nasync function handler({ id, gid, copies }: Input, extra: EnrichedExtra): Promise<CallToolResult> {\n const logger = extra.logger;\n logger.info('sheets.sheet.copy called', { id, gid, copyCount: copies.length });\n\n try {\n const sheets = google.sheets({ version: 'v4', auth: extra.authContext.auth });\n\n // First, get the source sheet info\n const spreadsheetInfo = await sheets.spreadsheets.get({\n spreadsheetId: id,\n fields: 'sheets.properties.sheetId,sheets.properties.title',\n });\n\n const sourceSheet = spreadsheetInfo.data.sheets?.find((s) => String(s.properties?.sheetId) === gid);\n if (!sourceSheet?.properties) {\n throw new ProtocolError(ProtocolErrorCode.InvalidParams, `Source sheet with gid \"${gid}\" not found in spreadsheet`);\n }\n\n const sourceTitle = sourceSheet.properties.title || '';\n const sourceSheetId = Number(gid);\n\n // Execute copies using Promise.allSettled for partial failure handling\n const results = await Promise.allSettled(\n copies.map(async (copy) => {\n const response = await sheets.spreadsheets.batchUpdate({\n spreadsheetId: id,\n requestBody: {\n requests: [\n {\n duplicateSheet: {\n sourceSheetId,\n newSheetName: copy.newTitle,\n ...(copy.insertIndex !== undefined && { insertSheetIndex: copy.insertIndex }),\n },\n },\n ],\n },\n });\n\n const newSheetId = response.data.replies?.[0]?.duplicateSheet?.properties?.sheetId;\n const newTitle = response.data.replies?.[0]?.duplicateSheet?.properties?.title;\n\n if (!newSheetId || !newTitle) {\n throw new Error('Failed to retrieve new sheet info from API response');\n }\n\n return {\n gid: String(newSheetId),\n title: newTitle,\n sheetUrl: `https://docs.google.com/spreadsheets/d/${id}/edit#gid=${newSheetId}`,\n };\n })\n );\n\n // Separate successes and failures\n const items: Array<{ gid: string; title: string; sheetUrl: string }> = [];\n const failures: Array<{ title: string; error: string }> = [];\n\n results.forEach((result, index) => {\n const copy = copies[index];\n if (!copy) return;\n\n if (result.status === 'fulfilled') {\n items.push(result.value);\n } else {\n const errorMessage = result.reason instanceof Error ? result.reason.message : String(result.reason);\n failures.push({ title: copy.newTitle, error: errorMessage });\n }\n });\n\n const successCount = items.length;\n const failureCount = failures.length;\n const totalCount = copies.length;\n\n const summary = failureCount === 0 ? `Created ${successCount} cop${successCount === 1 ? 'y' : 'ies'} of \"${sourceTitle}\"` : `Created ${successCount} of ${totalCount} cop${totalCount === 1 ? 'y' : 'ies'} (${failureCount} failed)`;\n\n logger.info('sheets.sheet.copy completed', { totalCount, successCount, failureCount });\n\n const result: Output = {\n type: 'success' as const,\n operationSummary: summary,\n itemsProcessed: totalCount,\n itemsChanged: successCount,\n completedAt: new Date().toISOString(),\n id,\n sourceGid: gid,\n sourceTitle,\n items,\n ...(failures.length > 0 && { failures }),\n };\n\n return {\n content: [{ type: 'text' as const, text: JSON.stringify(result) }],\n structuredContent: { result },\n };\n } catch (error) {\n if (error instanceof ProtocolError) {\n throw error;\n }\n const message = error instanceof Error ? error.message : String(error);\n logger.error('sheets.sheet.copy error', { error: message });\n\n throw new ProtocolError(ProtocolErrorCode.InternalError, `Error copying sheet: ${message}`, {\n stack: error instanceof Error ? error.stack : undefined,\n });\n }\n}\n\nexport default function createTool() {\n return {\n name: 'sheet-copy',\n config,\n handler,\n } satisfies ToolModule;\n}\n"],"names":["createTool","AuthRequiredBranchSchema","schemas","MAX_BATCH_SIZE","copyItemSchema","z","object","newTitle","coerce","string","trim","min","describe","insertIndex","number","int","optional","inputSchema","id","SpreadsheetIdSchema","gid","SheetGidSchema","copies","array","max","createdSheetSchema","SheetGidOutput","title","sheetUrl","successBranchSchema","type","literal","operationSummary","itemsProcessed","itemsChanged","completedAt","SpreadsheetIdOutput","sourceGid","sourceTitle","items","failures","error","outputSchema","discriminatedUnion","config","description","result","handler","extra","logger","spreadsheetInfo","sheets","sourceSheet","sourceSheetId","results","successCount","failureCount","totalCount","summary","message","info","copyCount","length","google","version","auth","authContext","spreadsheets","get","spreadsheetId","fields","data","find","s","String","properties","sheetId","ProtocolError","ProtocolErrorCode","InvalidParams","Number","Promise","allSettled","map","copy","response","newSheetId","batchUpdate","requestBody","requests","duplicateSheet","newSheetName","undefined","insertSheetIndex","replies","Error","forEach","index","status","push","value","errorMessage","reason","Date","toISOString","content","text","JSON","stringify","structuredContent","InternalError","stack","name"],"mappings":";;;;+BA+KA;;;eAAwBA;;;2BA9KA;sBAKyB;0BAC1B;mBACL;uBACuE;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AANzF,IAAM,AAAEC,2BAA6BC,oBAAO,CAApCD;AAQR,IAAME,iBAAiB;AAEvB,IAAMC,iBAAiBC,MAAC,CAACC,MAAM,CAAC;IAC9BC,UAAUF,MAAC,CAACG,MAAM,CAACC,MAAM,GAAGC,IAAI,GAAGC,GAAG,CAAC,GAAGC,QAAQ,CAAC;IACnDC,aAAaR,MAAC,CAACS,MAAM,GAAGC,GAAG,GAAGJ,GAAG,CAAC,GAAGK,QAAQ,GAAGJ,QAAQ,CAAC;AAC3D;AAEA,IAAMK,cAAcZ,MAAC,CAACC,MAAM,CAAC;IAC3BY,IAAIC,4BAAmB;IACvBC,KAAKC,uBAAc;IACnBC,QAAQjB,MAAC,CAACkB,KAAK,CAACnB,gBAAgBO,GAAG,CAAC,GAAGa,GAAG,CAACrB,gBAAgBS,QAAQ,CAAC;AACtE;AAEA,qBAAqB;AACrB,IAAMa,qBAAqBpB,MAAC,CAACC,MAAM,CAAC;IAClCc,K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SAAS5F;IACtB,OAAO;QACLgH,MAAM;QACNpE,QAAAA;QACAG,SAAAA;IACF;AACF"}
1
+ {"version":3,"sources":["/Users/kevin/Dev/OpenSource/ai/mcp-z/mcp-sheets/src/mcp/tools/sheet-copy.ts"],"sourcesContent":["import { sheets as sheetsApi } from '@googleapis/sheets';\nimport type { EnrichedExtra } from '@mcp-z/oauth-google';\nimport { schemas } from '@mcp-z/oauth-google';\n\nconst { AuthRequiredBranchSchema } = schemas;\n\nimport type { CallToolResult, ToolModule } from '@mcp-z/server';\nimport { ProtocolError, ProtocolErrorCode } from '@mcp-z/server';\nimport { z } from 'zod';\nimport { googleAuth } from '../../lib/google-auth.ts';\nimport { SheetGidOutput, SheetGidSchema, SpreadsheetIdOutput, SpreadsheetIdSchema } from '../../schemas/index.ts';\n\nconst MAX_BATCH_SIZE = 100;\n\nconst copyItemSchema = z.object({\n newTitle: z.coerce.string().trim().min(1).describe('Name for the copied sheet'),\n insertIndex: z.number().int().min(0).optional().describe('Position to insert the new sheet (0-indexed)'),\n});\n\nconst inputSchema = z.object({\n id: SpreadsheetIdSchema,\n gid: SheetGidSchema,\n copies: z.array(copyItemSchema).min(1).max(MAX_BATCH_SIZE).describe('Array of copies to create from the source sheet'),\n});\n\n// Created sheet info\nconst createdSheetSchema = z.object({\n gid: SheetGidOutput,\n title: z.string().describe('Title of the created sheet'),\n sheetUrl: z.string().describe('URL of the created sheet'),\n});\n\n// Success branch schema - uses items: for consistency with standard vocabulary\nconst successBranchSchema = z.object({\n type: z.literal('success'),\n operationSummary: z.string().describe('Summary of the copy operation'),\n itemsProcessed: z.number().describe('Total copies attempted'),\n itemsChanged: z.number().describe('Successfully created copies'),\n completedAt: z.string().describe('ISO datetime when operation completed'),\n id: SpreadsheetIdOutput,\n sourceGid: z.string().describe('Source sheet ID'),\n sourceTitle: z.string().describe('Source sheet title'),\n items: z.array(createdSheetSchema).describe('Information about created sheets'),\n failures: z\n .array(\n z.object({\n title: z.string(),\n error: z.string(),\n })\n )\n .optional()\n .describe('Failed copies with error messages'),\n});\n\n// Output schema with auth_required support\nconst outputSchema = z.discriminatedUnion('type', [successBranchSchema, AuthRequiredBranchSchema]);\n\nconst config = {\n description: 'Copy a sheet/tab within the same spreadsheet. Supports batch copying: create multiple copies from a single source sheet (e.g., create 12 monthly sheets from a template). Copies all data, formatting, charts, and conditional formatting verbatim.',\n inputSchema,\n outputSchema: z.object({\n result: outputSchema,\n }),\n} as const;\n\nexport type Input = z.infer<typeof inputSchema>;\nexport type Output = z.infer<typeof outputSchema>;\n\nasync function handler({ id, gid, copies }: Input, extra: EnrichedExtra): Promise<CallToolResult> {\n const logger = extra.logger;\n logger.info('sheets.sheet.copy called', { id, gid, copyCount: copies.length });\n\n try {\n const sheets = sheetsApi({ version: 'v4', auth: googleAuth(extra.authContext.auth) });\n\n // First, get the source sheet info\n const spreadsheetInfo = await sheets.spreadsheets.get({\n spreadsheetId: id,\n fields: 'sheets.properties.sheetId,sheets.properties.title',\n });\n\n const sourceSheet = spreadsheetInfo.data.sheets?.find((s) => String(s.properties?.sheetId) === gid);\n if (!sourceSheet?.properties) {\n throw new ProtocolError(ProtocolErrorCode.InvalidParams, `Source sheet with gid \"${gid}\" not found in spreadsheet`);\n }\n\n const sourceTitle = sourceSheet.properties.title || '';\n const sourceSheetId = Number(gid);\n\n // Execute copies using Promise.allSettled for partial failure handling\n const results = await Promise.allSettled(\n copies.map(async (copy) => {\n const response = await sheets.spreadsheets.batchUpdate({\n spreadsheetId: id,\n requestBody: {\n requests: [\n {\n duplicateSheet: {\n sourceSheetId,\n newSheetName: copy.newTitle,\n ...(copy.insertIndex !== undefined && { insertSheetIndex: copy.insertIndex }),\n },\n },\n ],\n },\n });\n\n const newSheetId = response.data.replies?.[0]?.duplicateSheet?.properties?.sheetId;\n const newTitle = response.data.replies?.[0]?.duplicateSheet?.properties?.title;\n\n if (!newSheetId || !newTitle) {\n throw new Error('Failed to retrieve new sheet info from API response');\n }\n\n return {\n gid: String(newSheetId),\n title: newTitle,\n sheetUrl: `https://docs.google.com/spreadsheets/d/${id}/edit#gid=${newSheetId}`,\n };\n })\n );\n\n // Separate successes and failures\n const items: Array<{ gid: string; title: string; sheetUrl: string }> = [];\n const failures: Array<{ title: string; error: string }> = [];\n\n results.forEach((result, index) => {\n const copy = copies[index];\n if (!copy) return;\n\n if (result.status === 'fulfilled') {\n items.push(result.value);\n } else {\n const errorMessage = result.reason instanceof Error ? result.reason.message : String(result.reason);\n failures.push({ title: copy.newTitle, error: errorMessage });\n }\n });\n\n const successCount = items.length;\n const failureCount = failures.length;\n const totalCount = copies.length;\n\n const summary = failureCount === 0 ? `Created ${successCount} cop${successCount === 1 ? 'y' : 'ies'} of \"${sourceTitle}\"` : `Created ${successCount} of ${totalCount} cop${totalCount === 1 ? 'y' : 'ies'} (${failureCount} failed)`;\n\n logger.info('sheets.sheet.copy completed', { totalCount, successCount, failureCount });\n\n const result: Output = {\n type: 'success' as const,\n operationSummary: summary,\n itemsProcessed: totalCount,\n itemsChanged: successCount,\n completedAt: new Date().toISOString(),\n id,\n sourceGid: gid,\n sourceTitle,\n items,\n ...(failures.length > 0 && { failures }),\n };\n\n return {\n content: [{ type: 'text' as const, text: JSON.stringify(result) }],\n structuredContent: { result },\n };\n } catch (error) {\n if (error instanceof ProtocolError) {\n throw error;\n }\n const message = error instanceof Error ? error.message : String(error);\n logger.error('sheets.sheet.copy error', { error: message });\n\n throw new ProtocolError(ProtocolErrorCode.InternalError, `Error copying sheet: ${message}`, {\n stack: error instanceof Error ? error.stack : undefined,\n });\n }\n}\n\nexport default function createTool() {\n return {\n name: 'sheet-copy',\n config,\n handler,\n } satisfies ToolModule;\n}\n"],"names":["createTool","AuthRequiredBranchSchema","schemas","MAX_BATCH_SIZE","copyItemSchema","z","object","newTitle","coerce","string","trim","min","describe","insertIndex","number","int","optional","inputSchema","id","SpreadsheetIdSchema","gid","SheetGidSchema","copies","array","max","createdSheetSchema","SheetGidOutput","title","sheetUrl","successBranchSchema","type","literal","operationSummary","itemsProcessed","itemsChanged","completedAt","SpreadsheetIdOutput","sourceGid","sourceTitle","items","failures","error","outputSchema","discriminatedUnion","config","description","result","handler","extra","logger","spreadsheetInfo","sheets","sourceSheet","sourceSheetId","results","successCount","failureCount","totalCount","summary","message","info","copyCount","length","sheetsApi","version","auth","googleAuth","authContext","spreadsheets","get","spreadsheetId","fields","data","find","s","String","properties","sheetId","ProtocolError","ProtocolErrorCode","InvalidParams","Number","Promise","allSettled","map","copy","response","newSheetId","batchUpdate","requestBody","requests","duplicateSheet","newSheetName","undefined","insertSheetIndex","replies","Error","forEach","index","status","push","value","errorMessage","reason","Date","toISOString","content","text","JSON","stringify","structuredContent","InternalError","stack","name"],"mappings":";;;;+BAgLA;;;eAAwBA;;;sBAhLY;2BAEZ;sBAKyB;mBAC/B;4BACS;uBAC8D;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AANzF,IAAM,AAAEC,2BAA6BC,oBAAO,CAApCD;AAQR,IAAME,iBAAiB;AAEvB,IAAMC,iBAAiBC,MAAC,CAACC,MAAM,CAAC;IAC9BC,UAAUF,MAAC,CAACG,MAAM,CAACC,MAAM,GAAGC,IAAI,GAAGC,GAAG,CAAC,GAAGC,QAAQ,CAAC;IACnDC,aAAaR,MAAC,CAACS,MAAM,GAAGC,GAAG,GAAGJ,GAAG,CAAC,GAAGK,QAAQ,GAAGJ,QAAQ,CAAC;AAC3D;AAEA,IAAMK,cAAcZ,MAAC,CAACC,MAAM,CAAC;IAC3BY,IAAIC,4BAAmB;IACvBC,KAAKC,uBAAc;IACnBC,QAAQjB,MAAC,CAACkB,KAAK,CAACnB,gBAAgBO,GAAG,CAAC,GAAGa,GAAG,CAACrB,gBAAgBS,QAAQ,CAAC;AACtE;AA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E,AAAK,YAALA,OAAiBuD,SAAQvD,MAAMuE,KAAK,GAAGnB;oBAChD;;;;;;;IAEJ;;AAEe,SAAS7F;IACtB,OAAO;QACLiH,MAAM;QACNrE,QAAAA;QACAG,SAAAA;IACF;AACF"}
@@ -8,10 +8,11 @@ Object.defineProperty(exports, "default", {
8
8
  return createTool;
9
9
  }
10
10
  });
11
+ var _sheets = require("@googleapis/sheets");
11
12
  var _oauthgoogle = require("@mcp-z/oauth-google");
12
13
  var _server = require("@mcp-z/server");
13
- var _googleapis = require("googleapis");
14
14
  var _zod = require("zod");
15
+ var _googleauthts = require("../../lib/google-auth.js");
15
16
  var _indexts = require("../../schemas/index.js");
16
17
  function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) {
17
18
  try {
@@ -193,9 +194,9 @@ function handler(_0, _1) {
193
194
  ,
194
195
  4
195
196
  ]);
196
- sheets = _googleapis.google.sheets({
197
+ sheets = (0, _sheets.sheets)({
197
198
  version: 'v4',
198
- auth: extra.authContext.auth
199
+ auth: (0, _googleauthts.googleAuth)(extra.authContext.auth)
199
200
  });
200
201
  return [
201
202
  4,
@@ -1 +1 @@
1
- {"version":3,"sources":["/Users/kevin/Dev/OpenSource/ai/mcp-z/mcp-sheets/src/mcp/tools/sheet-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, ToolModule } from '@mcp-z/server';\nimport { ProtocolError, ProtocolErrorCode } from '@mcp-z/server';\nimport { google } from 'googleapis';\nimport { z } from 'zod';\nimport { SheetGidOutput, SpreadsheetIdOutput, SpreadsheetIdSchema } from '../../schemas/index.ts';\n\nconst inputSchema = z.object({\n id: SpreadsheetIdSchema,\n sheetTitle: z.coerce.string().trim().min(1).describe('Name for the new sheet tab'),\n});\n\n// Success branch schema\nconst successBranchSchema = z.object({\n type: z.literal('success'),\n operationSummary: z.string().describe('Summary of the sheet creation operation'),\n itemsProcessed: z.number().describe('Total items attempted (always 1 for single sheet)'),\n itemsChanged: z.number().describe('Successfully created sheets (always 1 on success)'),\n completedAt: z.string().describe('ISO datetime when operation completed'),\n id: SpreadsheetIdOutput,\n gid: SheetGidOutput,\n sheetUrl: z.string().describe('URL of the created sheet'),\n sheetTitle: z.string().describe('Title of the created sheet'),\n});\n\n// Output schema with auth_required support\nconst outputSchema = z.discriminatedUnion('type', [successBranchSchema, AuthRequiredBranchSchema]);\n\nconst config = {\n description: 'Create a new sheet/tab in the spreadsheet/workbook',\n inputSchema,\n outputSchema: z.object({\n result: outputSchema,\n }),\n} as const;\n\nexport type Input = z.infer<typeof inputSchema>;\nexport type Output = z.infer<typeof outputSchema>;\n\nasync function handler({ id, sheetTitle }: Input, extra: EnrichedExtra): Promise<CallToolResult> {\n const logger = extra.logger;\n logger.info('sheets.sheet.create called', { id, sheetTitle });\n\n try {\n const sheets = google.sheets({ version: 'v4', auth: extra.authContext.auth });\n const response = await sheets.spreadsheets.batchUpdate({\n spreadsheetId: id,\n requestBody: {\n requests: [{ addSheet: { properties: { title: sheetTitle } } }],\n },\n });\n const batchResult = response.data;\n const sheetId = batchResult.replies?.[0]?.addSheet?.properties?.sheetId;\n if (!sheetId) {\n throw new Error('Failed to retrieve sheetId from Google Sheets API response');\n }\n logger.info('sheets.sheet.create success', { id, sheetTitle, sheetId });\n\n const result: Output = {\n type: 'success' as const,\n operationSummary: `Created sheet \"${sheetTitle}\"`,\n itemsProcessed: 1,\n itemsChanged: 1,\n completedAt: new Date().toISOString(),\n id,\n gid: String(sheetId),\n sheetUrl: `https://docs.google.com/spreadsheets/d/${id}/edit#gid=${sheetId}`,\n sheetTitle,\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('sheets.sheet.create error', { error: message });\n\n // Throw ProtocolError for proper MCP error handling\n throw new ProtocolError(ProtocolErrorCode.InternalError, `Error creating sheet: ${message}`, {\n stack: error instanceof Error ? error.stack : undefined,\n });\n }\n}\n\nexport default function createTool() {\n return {\n name: 'sheet-create',\n config,\n handler,\n } satisfies ToolModule;\n}\n"],"names":["createTool","AuthRequiredBranchSchema","schemas","inputSchema","z","object","id","SpreadsheetIdSchema","sheetTitle","coerce","string","trim","min","describe","successBranchSchema","type","literal","operationSummary","itemsProcessed","number","itemsChanged","completedAt","SpreadsheetIdOutput","gid","SheetGidOutput","sheetUrl","outputSchema","discriminatedUnion","config","description","result","handler","extra","logger","batchResult","sheets","response","sheetId","error","message","info","google","version","auth","authContext","spreadsheets","batchUpdate","spreadsheetId","requestBody","requests","addSheet","properties","title","data","replies","Error","Date","toISOString","String","content","text","JSON","stringify","structuredContent","ProtocolError","ProtocolErrorCode","InternalError","stack","undefined","name"],"mappings":";;;;+BA8FA;;;eAAwBA;;;2BA7FA;sBAKyB;0BAC1B;mBACL;uBACuD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AANzE,IAAM,AAAEC,2BAA6BC,oBAAO,CAApCD;AAQR,IAAME,cAAcC,MAAC,CAACC,MAAM,CAAC;IAC3BC,IAAIC,4BAAmB;IACvBC,YAAYJ,MAAC,CAACK,MAAM,CAACC,MAAM,GAAGC,IAAI,GAAGC,GAAG,CAAC,GAAGC,QAAQ,CAAC;AACvD;AAEA,wBAAwB;AACxB,IAAMC,sBAAsBV,MAAC,CAACC,MAAM,CAAC;IACnCU,MAAMX,MAAC,CAACY,OAAO,CAAC;IAChBC,kBAAkBb,MAAC,CAACM,MAAM,GAAGG,QAAQ,CAAC;IACtCK,gBAAgBd,MAAC,CAACe,MAAM,GAAGN,QAAQ,CAAC;IACpCO,cAAchB,MAAC,CAACe,MAAM,GAAGN,Q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BAAoCiB,UAAU,cAA9CjB,gEAAAA,0CAAgDG,OAAO;oBACvE,IAAI,CAACA,SAAS;wBACZ,MAAM,IAAIkB,MAAM;oBAClB;oBACAtB,OAAOO,IAAI,CAAC,+BAA+B;wBAAElC,IAAAA;wBAAIE,YAAAA;wBAAY6B,SAAAA;oBAAQ;oBAE/DP,SAAiB;wBACrBf,MAAM;wBACNE,kBAAkB,AAAC,kBAA4B,OAAXT,YAAW;wBAC/CU,gBAAgB;wBAChBE,cAAc;wBACdC,aAAa,IAAImC,OAAOC,WAAW;wBACnCnD,IAAAA;wBACAiB,KAAKmC,OAAOrB;wBACZZ,UAAU,AAAC,0CAAwDY,OAAf/B,IAAG,cAAoB,OAAR+B;wBACnE7B,YAAAA;oBACF;oBAEA;;wBAAO;4BACLmD,OAAO;gCACL;oCACE5C,MAAM;oCACN6C,MAAMC,KAAKC,SAAS,CAAChC;gCACvB;;4BAEFiC,mBAAmB;gCAAEjC,QAAAA;4BAAO;wBAC9B;;;oBACOQ;oBACDC,UAAUD,AAAK,YAALA,OAAiBiB,SAAQjB,MAAMC,OAAO,GAAGmB,OAAOpB;oBAChEL,OAAOK,KAAK,CAAC,6BAA6B;wBAAEA,OAAOC;oBAAQ;oBAE3D,oDAAoD;oBACpD,MAAM,IAAIyB,qBAAa,CAACC,yBAAiB,CAACC,aAAa,EAAE,AAAC,yBAAgC,OAAR3B,UAAW;wBAC3F4B,OAAO7B,AAAK,YAALA,OAAiBiB,SAAQjB,MAAM6B,KAAK,GAAGC;oBAChD;;;;;;;IAEJ;;AAEe,SAASpE;IACtB,OAAO;QACLqE,MAAM;QACNzC,QAAAA;QACAG,SAAAA;IACF;AACF"}
1
+ {"version":3,"sources":["/Users/kevin/Dev/OpenSource/ai/mcp-z/mcp-sheets/src/mcp/tools/sheet-create.ts"],"sourcesContent":["import { sheets as sheetsApi } from '@googleapis/sheets';\nimport type { EnrichedExtra } from '@mcp-z/oauth-google';\nimport { schemas } from '@mcp-z/oauth-google';\n\nconst { AuthRequiredBranchSchema } = schemas;\n\nimport type { CallToolResult, ToolModule } from '@mcp-z/server';\nimport { ProtocolError, ProtocolErrorCode } from '@mcp-z/server';\nimport { z } from 'zod';\nimport { googleAuth } from '../../lib/google-auth.ts';\nimport { SheetGidOutput, SpreadsheetIdOutput, SpreadsheetIdSchema } from '../../schemas/index.ts';\n\nconst inputSchema = z.object({\n id: SpreadsheetIdSchema,\n sheetTitle: z.coerce.string().trim().min(1).describe('Name for the new sheet tab'),\n});\n\n// Success branch schema\nconst successBranchSchema = z.object({\n type: z.literal('success'),\n operationSummary: z.string().describe('Summary of the sheet creation operation'),\n itemsProcessed: z.number().describe('Total items attempted (always 1 for single sheet)'),\n itemsChanged: z.number().describe('Successfully created sheets (always 1 on success)'),\n completedAt: z.string().describe('ISO datetime when operation completed'),\n id: SpreadsheetIdOutput,\n gid: SheetGidOutput,\n sheetUrl: z.string().describe('URL of the created sheet'),\n sheetTitle: z.string().describe('Title of the created sheet'),\n});\n\n// Output schema with auth_required support\nconst outputSchema = z.discriminatedUnion('type', [successBranchSchema, AuthRequiredBranchSchema]);\n\nconst config = {\n description: 'Create a new sheet/tab in the spreadsheet/workbook',\n inputSchema,\n outputSchema: z.object({\n result: outputSchema,\n }),\n} as const;\n\nexport type Input = z.infer<typeof inputSchema>;\nexport type Output = z.infer<typeof outputSchema>;\n\nasync function handler({ id, sheetTitle }: Input, extra: EnrichedExtra): Promise<CallToolResult> {\n const logger = extra.logger;\n logger.info('sheets.sheet.create called', { id, sheetTitle });\n\n try {\n const sheets = sheetsApi({ version: 'v4', auth: googleAuth(extra.authContext.auth) });\n const response = await sheets.spreadsheets.batchUpdate({\n spreadsheetId: id,\n requestBody: {\n requests: [{ addSheet: { properties: { title: sheetTitle } } }],\n },\n });\n const batchResult = response.data;\n const sheetId = batchResult.replies?.[0]?.addSheet?.properties?.sheetId;\n if (!sheetId) {\n throw new Error('Failed to retrieve sheetId from Google Sheets API response');\n }\n logger.info('sheets.sheet.create success', { id, sheetTitle, sheetId });\n\n const result: Output = {\n type: 'success' as const,\n operationSummary: `Created sheet \"${sheetTitle}\"`,\n itemsProcessed: 1,\n itemsChanged: 1,\n completedAt: new Date().toISOString(),\n id,\n gid: String(sheetId),\n sheetUrl: `https://docs.google.com/spreadsheets/d/${id}/edit#gid=${sheetId}`,\n sheetTitle,\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('sheets.sheet.create error', { error: message });\n\n // Throw ProtocolError for proper MCP error handling\n throw new ProtocolError(ProtocolErrorCode.InternalError, `Error creating sheet: ${message}`, {\n stack: error instanceof Error ? error.stack : undefined,\n });\n }\n}\n\nexport default function createTool() {\n return {\n name: 'sheet-create',\n config,\n handler,\n } satisfies ToolModule;\n}\n"],"names":["createTool","AuthRequiredBranchSchema","schemas","inputSchema","z","object","id","SpreadsheetIdSchema","sheetTitle","coerce","string","trim","min","describe","successBranchSchema","type","literal","operationSummary","itemsProcessed","number","itemsChanged","completedAt","SpreadsheetIdOutput","gid","SheetGidOutput","sheetUrl","outputSchema","discriminatedUnion","config","description","result","handler","extra","logger","batchResult","sheets","response","sheetId","error","message","info","sheetsApi","version","auth","googleAuth","authContext","spreadsheets","batchUpdate","spreadsheetId","requestBody","requests","addSheet","properties","title","data","replies","Error","Date","toISOString","String","content","text","JSON","stringify","structuredContent","ProtocolError","ProtocolErrorCode","InternalError","stack","undefined","name"],"mappings":";;;;+BA+FA;;;eAAwBA;;;sBA/FY;2BAEZ;sBAKyB;mBAC/B;4BACS;uBAC8C;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AANzE,IAAM,AAAEC,2BAA6BC,oBAAO,CAApCD;AAQR,IAAME,cAA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C,yBAAiB,CAACC,aAAa,EAAE,AAAC,yBAAgC,OAAR5B,UAAW;wBAC3F6B,OAAO9B,AAAK,YAALA,OAAiBkB,SAAQlB,MAAM8B,KAAK,GAAGC;oBAChD;;;;;;;IAEJ;;AAEe,SAASrE;IACtB,OAAO;QACLsE,MAAM;QACN1C,QAAAA;QACAG,SAAAA;IACF;AACF"}
@@ -8,10 +8,11 @@ Object.defineProperty(exports, "default", {
8
8
  return createTool;
9
9
  }
10
10
  });
11
+ var _sheets = require("@googleapis/sheets");
11
12
  var _oauthgoogle = require("@mcp-z/oauth-google");
12
13
  var _server = require("@mcp-z/server");
13
- var _googleapis = require("googleapis");
14
14
  var _zod = require("zod");
15
+ var _googleauthts = require("../../lib/google-auth.js");
15
16
  var _indexts = require("../../schemas/index.js");
16
17
  function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) {
17
18
  try {
@@ -221,9 +222,9 @@ function handler(_0, _1) {
221
222
  ,
222
223
  4
223
224
  ]);
224
- sheets = _googleapis.google.sheets({
225
+ sheets = (0, _sheets.sheets)({
225
226
  version: 'v4',
226
- auth: extra.authContext.auth
227
+ auth: (0, _googleauthts.googleAuth)(extra.authContext.auth)
227
228
  });
228
229
  return [
229
230
  4,
@@ -1 +1 @@
1
- {"version":3,"sources":["/Users/kevin/Dev/OpenSource/ai/mcp-z/mcp-sheets/src/mcp/tools/sheet-delete.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, ToolModule } from '@mcp-z/server';\nimport { ProtocolError, ProtocolErrorCode } from '@mcp-z/server';\nimport { google } from 'googleapis';\nimport { z } from 'zod';\nimport { SheetGidSchema, SpreadsheetIdOutput, SpreadsheetIdSchema } from '../../schemas/index.ts';\n\nconst MAX_BATCH_SIZE = 1000;\n\nconst inputSchema = z.object({\n id: SpreadsheetIdSchema,\n gids: z.array(SheetGidSchema).min(1).max(MAX_BATCH_SIZE).describe('Sheet grid IDs to permanently delete'),\n});\n\nconst successBranchSchema = z.object({\n type: z.literal('success'),\n operationSummary: z.string().describe('Human-readable summary of the operation'),\n itemsProcessed: z.number().describe('Total sheets attempted to delete'),\n itemsChanged: z.number().describe('Number of sheets successfully deleted'),\n completedAt: z.string().describe('ISO timestamp when operation completed'),\n recoverable: z.literal(false).describe('Whether deletion can be undone (always false)'),\n id: SpreadsheetIdOutput,\n spreadsheetUrl: z.string().optional().describe('URL to view the spreadsheet'),\n failures: z\n .array(\n z.object({\n gid: z.string().describe('Grid ID of sheet that failed to delete'),\n error: z.string().describe('Error message explaining the failure'),\n })\n )\n .optional()\n .describe('Details of any sheets that failed to delete'),\n});\n\nconst outputSchema = z.discriminatedUnion('type', [successBranchSchema, AuthRequiredBranchSchema]);\n\nconst config = {\n description: 'Permanently delete sheets from a spreadsheet. Cannot delete the last remaining sheet.',\n inputSchema,\n outputSchema: z.object({\n result: outputSchema,\n }),\n} as const;\n\nexport type Input = z.infer<typeof inputSchema>;\nexport type Output = z.infer<typeof outputSchema>;\n\nasync function handler({ id, gids }: Input, extra: EnrichedExtra): Promise<CallToolResult> {\n const logger = extra.logger;\n logger.info('sheets.sheet.delete called', { id, count: gids.length });\n\n try {\n const sheets = google.sheets({ version: 'v4', auth: extra.authContext.auth });\n\n const results = await Promise.allSettled(\n gids.map(async (gid) => {\n await sheets.spreadsheets.batchUpdate({\n spreadsheetId: id,\n requestBody: {\n requests: [{ deleteSheet: { sheetId: Number(gid) } }],\n },\n });\n return gid;\n })\n );\n\n // Separate successes and failures\n const failures: Array<{ gid: string; error: string }> = [];\n\n results.forEach((result, index) => {\n const gid = gids[index];\n if (!gid) return;\n\n if (result.status === 'rejected') {\n const errorMessage = result.reason instanceof Error ? result.reason.message : String(result.reason);\n failures.push({ gid, error: errorMessage });\n }\n });\n\n const successCount = gids.length - failures.length;\n const failureCount = failures.length;\n const totalCount = gids.length;\n\n const summary = failureCount === 0 ? `Permanently deleted ${successCount} sheet${successCount === 1 ? '' : 's'}` : `Deleted ${successCount} of ${totalCount} sheet${totalCount === 1 ? '' : 's'} (${failureCount} failed)`;\n\n logger.info('sheets.sheet.delete completed', {\n totalCount,\n successCount,\n failureCount,\n });\n\n const result: Output = {\n type: 'success' as const,\n operationSummary: summary,\n itemsProcessed: totalCount,\n itemsChanged: successCount,\n completedAt: new Date().toISOString(),\n recoverable: false as const,\n id,\n spreadsheetUrl: `https://docs.google.com/spreadsheets/d/${id}`,\n ...(failures.length > 0 && { failures }),\n };\n\n return {\n content: [{ type: 'text' as const, text: JSON.stringify(result) }],\n structuredContent: { result },\n };\n } catch (error) {\n const message = error instanceof Error ? error.message : String(error);\n logger.error('sheets.sheet.delete error', { error: message });\n\n throw new ProtocolError(ProtocolErrorCode.InternalError, `Error deleting sheet: ${message}`, {\n stack: error instanceof Error ? error.stack : undefined,\n });\n }\n}\n\nexport default function createTool() {\n return {\n name: 'sheet-delete',\n config,\n handler,\n } satisfies ToolModule;\n}\n"],"names":["createTool","AuthRequiredBranchSchema","schemas","MAX_BATCH_SIZE","inputSchema","z","object","id","SpreadsheetIdSchema","gids","array","SheetGidSchema","min","max","describe","successBranchSchema","type","literal","operationSummary","string","itemsProcessed","number","itemsChanged","completedAt","recoverable","SpreadsheetIdOutput","spreadsheetUrl","optional","failures","gid","error","outputSchema","discriminatedUnion","config","description","result","handler","extra","logger","sheets","results","successCount","failureCount","totalCount","summary","message","info","count","length","google","version","auth","authContext","Promise","allSettled","map","spreadsheets","batchUpdate","spreadsheetId","requestBody","requests","deleteSheet","sheetId","Number","forEach","index","status","errorMessage","reason","Error","String","push","Date","toISOString","content","text","JSON","stringify","structuredContent","ProtocolError","ProtocolErrorCode","InternalError","stack","undefined","name"],"mappings":";;;;+BAyHA;;;eAAwBA;;;2BAxHA;sBAKyB;0BAC1B;mBACL;uBACuD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;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sheetsApi } from '@googleapis/sheets';\nimport type { EnrichedExtra } from '@mcp-z/oauth-google';\nimport { schemas } from '@mcp-z/oauth-google';\n\nconst { AuthRequiredBranchSchema } = schemas;\n\nimport type { CallToolResult, ToolModule } from '@mcp-z/server';\nimport { ProtocolError, ProtocolErrorCode } from '@mcp-z/server';\nimport { z } from 'zod';\nimport { googleAuth } from '../../lib/google-auth.ts';\nimport { SheetGidSchema, SpreadsheetIdOutput, SpreadsheetIdSchema } from '../../schemas/index.ts';\n\nconst MAX_BATCH_SIZE = 1000;\n\nconst inputSchema = z.object({\n id: SpreadsheetIdSchema,\n gids: z.array(SheetGidSchema).min(1).max(MAX_BATCH_SIZE).describe('Sheet grid IDs to permanently delete'),\n});\n\nconst successBranchSchema = z.object({\n type: z.literal('success'),\n operationSummary: z.string().describe('Human-readable summary of the operation'),\n itemsProcessed: z.number().describe('Total sheets attempted to delete'),\n itemsChanged: z.number().describe('Number of sheets successfully deleted'),\n completedAt: z.string().describe('ISO timestamp when operation completed'),\n recoverable: z.literal(false).describe('Whether deletion can be undone (always false)'),\n id: SpreadsheetIdOutput,\n spreadsheetUrl: z.string().optional().describe('URL to view the spreadsheet'),\n failures: z\n .array(\n z.object({\n gid: z.string().describe('Grid ID of sheet that failed to delete'),\n error: z.string().describe('Error message explaining the failure'),\n })\n )\n .optional()\n .describe('Details of any sheets that failed to delete'),\n});\n\nconst outputSchema = z.discriminatedUnion('type', [successBranchSchema, AuthRequiredBranchSchema]);\n\nconst config = {\n description: 'Permanently delete sheets from a spreadsheet. Cannot delete the last remaining sheet.',\n inputSchema,\n outputSchema: z.object({\n result: outputSchema,\n }),\n} as const;\n\nexport type Input = z.infer<typeof inputSchema>;\nexport type Output = z.infer<typeof outputSchema>;\n\nasync function handler({ id, gids }: Input, extra: EnrichedExtra): Promise<CallToolResult> {\n const logger = extra.logger;\n logger.info('sheets.sheet.delete called', { id, count: gids.length });\n\n try {\n const sheets = sheetsApi({ version: 'v4', auth: googleAuth(extra.authContext.auth) });\n\n const results = await Promise.allSettled(\n gids.map(async (gid) => {\n await sheets.spreadsheets.batchUpdate({\n spreadsheetId: id,\n requestBody: {\n requests: [{ deleteSheet: { sheetId: Number(gid) } }],\n },\n });\n return gid;\n })\n );\n\n // Separate successes and failures\n const failures: Array<{ gid: string; error: string }> = [];\n\n results.forEach((result, index) => {\n const gid = gids[index];\n if (!gid) return;\n\n if (result.status === 'rejected') {\n const errorMessage = result.reason instanceof Error ? result.reason.message : String(result.reason);\n failures.push({ gid, error: errorMessage });\n }\n });\n\n const successCount = gids.length - failures.length;\n const failureCount = failures.length;\n const totalCount = gids.length;\n\n const summary = failureCount === 0 ? `Permanently deleted ${successCount} sheet${successCount === 1 ? '' : 's'}` : `Deleted ${successCount} of ${totalCount} sheet${totalCount === 1 ? '' : 's'} (${failureCount} failed)`;\n\n logger.info('sheets.sheet.delete completed', {\n totalCount,\n successCount,\n failureCount,\n });\n\n const result: Output = {\n type: 'success' as const,\n operationSummary: summary,\n itemsProcessed: totalCount,\n itemsChanged: successCount,\n completedAt: new Date().toISOString(),\n recoverable: false as const,\n id,\n spreadsheetUrl: `https://docs.google.com/spreadsheets/d/${id}`,\n ...(failures.length > 0 && { failures }),\n };\n\n return {\n content: [{ type: 'text' as const, text: JSON.stringify(result) }],\n structuredContent: { result },\n };\n } catch (error) {\n const message = error instanceof Error ? error.message : String(error);\n logger.error('sheets.sheet.delete error', { error: message });\n\n throw new ProtocolError(ProtocolErrorCode.InternalError, `Error deleting sheet: ${message}`, {\n stack: error instanceof Error ? error.stack : undefined,\n });\n }\n}\n\nexport default function createTool() {\n return {\n name: 'sheet-delete',\n config,\n handler,\n } satisfies ToolModule;\n}\n"],"names":["createTool","AuthRequiredBranchSchema","schemas","MAX_BATCH_SIZE","inputSchema","z","object","id","SpreadsheetIdSchema","gids","array","SheetGidSchema","min","max","describe","successBranchSchema","type","literal","operationSummary","string","itemsProcessed","number","itemsChanged","completedAt","recoverable","SpreadsheetIdOutput","spreadsheetUrl","optional","failures","gid","error","outputSchema","discriminatedUnion","config","description","result","handler","extra","logger","sheets","results","successCount","failureCount","totalCount","summary","message","info","count","length","sheetsApi","version","auth","googleAuth","authContext","Promise","allSettled","map","spreadsheets","batchUpdate","spreadsheetId","requestBody","requests","deleteSheet","sheetId","Number","forEach","index","status","errorMessage","reason","Error","String","push","Date","toISOString","content","text","JSON","stringify","structuredContent","ProtocolError","ProtocolErrorCode","InternalError","stack","undefined","name"],"mappings":";;;;+BA0HA;;;eAAwBA;;;sBA1HY;2BAEZ;sBAKyB;mBAC/B;4BACS;uBAC8C;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AANzE,IAAM,AAAEC,2BAA6BC,oBAAO,CAApCD;AAQR,IAAME,iBAAiB;AAEvB,IAAMC,cAAcC,MAAC,CAACC,MAAM,CAAC;IAC3BC,IAAIC,4BAAmB;IACvBC,MAAMJ,MAAC,CAACK,KAAK,CAACC,uBAAc,EAAEC,GAAG,CAAC,GAAGC,GAAG,CAACV,gBAAgBW,QAAQ,CAAC;AACpE;AAEA,IAAMC,sBAAsBV,MAAC,CAACC,MAAM,CAAC;IACnCU,MAAMX,MAAC,CAACY,OAAO,CAAC;IAChBC,kBAAkBb,MAAC,CAACc,MAAM,GAAGL,QAAQ,CAAC;IACtCM,gBAAgBf,MAAC,CAACgB,MAAM,GAAGP,QAAQ,CAAC;IACpCQ,cAAcjB,MAAC,CAACgB,MAAM,GAAGP,QAAQ,CAAC;IAClCS,aAAalB,MAAC,CAACc,MAAM,GAAGL,QAAQ,CAAC;IACjCU,aAAanB,MAAC,CAACY,OAAO,CAAC,OAAOH,QAAQ,CAAC;IACvCP,IAAIkB,4BAAmB;IACvBC,gBAAgBrB,MAAC,CAACc,MAAM,GAAGQ,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GAAG0B,OAAOzC;oBAChEQ,OAAOR,KAAK,CAAC,6BAA6B;wBAAEA,OAAOe;oBAAQ;oBAE3D,MAAM,IAAImC,qBAAa,CAACC,yBAAiB,CAACC,aAAa,EAAE,AAAC,yBAAgC,OAARrC,UAAW;wBAC3FsC,OAAOrD,AAAK,YAALA,OAAiBwC,SAAQxC,MAAMqD,KAAK,GAAGC;oBAChD;;;;;;;IAEJ;;AAEe,SAASpF;IACtB,OAAO;QACLqF,MAAM;QACNpD,QAAAA;QACAG,SAAAA;IACF;AACF"}
@@ -8,10 +8,11 @@ Object.defineProperty(exports, "default", {
8
8
  return createTool;
9
9
  }
10
10
  });
11
+ var _sheets = require("@googleapis/sheets");
11
12
  var _oauthgoogle = require("@mcp-z/oauth-google");
12
13
  var _server = require("@mcp-z/server");
13
- var _googleapis = require("googleapis");
14
14
  var _zod = require("zod");
15
+ var _googleauthts = require("../../lib/google-auth.js");
15
16
  var _indexts = require("../../schemas/index.js");
16
17
  var _sheetoperationsts = require("../../spreadsheet/sheet-operations.js");
17
18
  function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) {
@@ -188,9 +189,9 @@ function handler(_0, _1) {
188
189
  ,
189
190
  4
190
191
  ]);
191
- sheets = _googleapis.google.sheets({
192
+ sheets = (0, _sheets.sheets)({
192
193
  version: 'v4',
193
- auth: extra.authContext.auth
194
+ auth: (0, _googleauthts.googleAuth)(extra.authContext.auth)
194
195
  });
195
196
  return [
196
197
  4,
@@ -1 +1 @@
1
- {"version":3,"sources":["/Users/kevin/Dev/OpenSource/ai/mcp-z/mcp-sheets/src/mcp/tools/sheet-find.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, ToolModule } from '@mcp-z/server';\nimport { ProtocolError, ProtocolErrorCode } from '@mcp-z/server';\nimport { google } from 'googleapis';\nimport { z } from 'zod';\nimport { SheetGidOutput, SheetRefSchema, SpreadsheetIdOutput, SpreadsheetIdSchema } from '../../schemas/index.ts';\nimport { findSheetByRef } from '../../spreadsheet/sheet-operations.ts';\n\nconst inputSchema = z.object({\n id: SpreadsheetIdSchema,\n sheetRef: SheetRefSchema,\n});\n\nconst successBranchSchema = z.object({\n type: z.literal('success'),\n id: SpreadsheetIdOutput,\n gid: SheetGidOutput,\n title: z.string().describe('Sheet tab name'),\n sheetUrl: z.string().optional().describe('URL to view the sheet'),\n});\n\nconst outputSchema = z.discriminatedUnion('type', [successBranchSchema, AuthRequiredBranchSchema]);\n\nconst config = {\n description: 'Find an existing sheet/tab within a known spreadsheet by title or GUID',\n inputSchema,\n outputSchema: z.object({\n result: outputSchema,\n }),\n} as const;\n\nexport type Input = z.infer<typeof inputSchema>;\nexport type Output = z.infer<typeof outputSchema>;\n\nasync function handler({ id, sheetRef }: Input, extra: EnrichedExtra): Promise<CallToolResult> {\n const logger = extra.logger;\n logger.info('sheets.sheet.find called', { id, sheetRef });\n\n try {\n const sheets = google.sheets({ version: 'v4', auth: extra.authContext.auth });\n\n // Find sheet within the known spreadsheet\n const sheet = await findSheetByRef(sheets, id, sheetRef, logger);\n if (!sheet) {\n throw new ProtocolError(ProtocolErrorCode.InvalidParams, 'Sheet not found');\n }\n\n const title = sheet?.properties?.title ?? String(sheetRef);\n const gid = sheet?.properties?.sheetId != null ? String(sheet.properties.sheetId) : '';\n const sheetUrl = gid ? `https://docs.google.com/spreadsheets/d/${id}/edit#gid=${gid}` : `https://docs.google.com/spreadsheets/d/${id}`;\n\n logger.info('sheets.sheet.find success', { id, gid, title });\n\n const result: Output = {\n type: 'success' as const,\n id,\n gid,\n title,\n sheetUrl,\n };\n\n return {\n content: [{ type: 'text' as const, text: JSON.stringify(result) }],\n structuredContent: { result },\n };\n } catch (error) {\n const message = error instanceof Error ? error.message : String(error);\n logger.error('sheets.sheet.find error', { error: message });\n\n throw new ProtocolError(ProtocolErrorCode.InternalError, `Error finding sheet: ${message}`, {\n stack: error instanceof Error ? error.stack : undefined,\n });\n }\n}\n\nexport default function createTool() {\n return {\n name: 'sheet-find',\n config,\n handler,\n } satisfies ToolModule;\n}\n"],"names":["createTool","AuthRequiredBranchSchema","schemas","inputSchema","z","object","id","SpreadsheetIdSchema","sheetRef","SheetRefSchema","successBranchSchema","type","literal","SpreadsheetIdOutput","gid","SheetGidOutput","title","string","describe","sheetUrl","optional","outputSchema","discriminatedUnion","config","description","result","handler","extra","logger","sheet","sheets","error","message","info","google","version","auth","authContext","findSheetByRef","ProtocolError","ProtocolErrorCode","InvalidParams","properties","String","sheetId","content","text","JSON","stringify","structuredContent","Error","InternalError","stack","undefined","name"],"mappings":";;;;+BA+EA;;;eAAwBA;;;2BA9EA;sBAKyB;0BAC1B;mBACL;uBACuE;iCAC1D;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAP/B,IAAM,AAAEC,2BAA6BC,oBAAO,CAApCD;AASR,IAAME,cAAcC,MAAC,CAACC,MAAM,CAAC;IAC3BC,IAAIC,4BAAmB;IACvBC,UAAUC,uBAAc;AAC1B;AAEA,IAAMC,sBAAsBN,MAAC,CAACC,MAAM,CAAC;IACnCM,MAAMP,MAAC,CAACQ,OAAO,CAAC;IAChBN,IAAIO,4BAAmB;IACvBC,KAAKC,uBAAc;IACnBC,OAAOZ,MAAC,CAACa,MAAM,GAAGC,QAAQ,CAAC;IAC3BC,UAAUf,MAAC,CAACa,MAAM,GAAGG,QAAQ,GAAGF,QAAQ,CAAC;AAC3C;AAEA,IAAMG,eAAejB,MAAC,CAACkB,kBAAkB,CAAC,QAAQ;IAACZ;IAAqBT;CAAyB;AAEjG,IAAMsB,SAAS;IACbC,aAAa;IACbrB,aAAAA;IACAkB,cAAcjB,MAAC,CAACC,MAAM,CAAC;QACrBo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CAAQ;;4BAChEwB,mBAAmB;gCAAExB,QAAAA;4BAAO;wBAC9B;;;oBACOM;oBACDC,UAAUD,AAAK,YAALA,OAAiBmB,SAAQnB,MAAMC,OAAO,GAAGW,OAAOZ;oBAChEH,OAAOG,KAAK,CAAC,2BAA2B;wBAAEA,OAAOC;oBAAQ;oBAEzD,MAAM,IAAIO,qBAAa,CAACC,yBAAiB,CAACW,aAAa,EAAE,AAAC,wBAA+B,OAARnB,UAAW;wBAC1FoB,OAAOrB,AAAK,YAALA,OAAiBmB,SAAQnB,MAAMqB,KAAK,GAAGC;oBAChD;;;;;;;IAEJ;;AAEe,SAASrD;IACtB,OAAO;QACLsD,MAAM;QACN/B,QAAAA;QACAG,SAAAA;IACF;AACF"}
1
+ {"version":3,"sources":["/Users/kevin/Dev/OpenSource/ai/mcp-z/mcp-sheets/src/mcp/tools/sheet-find.ts"],"sourcesContent":["import { sheets as sheetsApi } from '@googleapis/sheets';\nimport type { EnrichedExtra } from '@mcp-z/oauth-google';\nimport { schemas } from '@mcp-z/oauth-google';\n\nconst { AuthRequiredBranchSchema } = schemas;\n\nimport type { CallToolResult, ToolModule } from '@mcp-z/server';\nimport { ProtocolError, ProtocolErrorCode } from '@mcp-z/server';\nimport { z } from 'zod';\nimport { googleAuth } from '../../lib/google-auth.ts';\nimport { SheetGidOutput, SheetRefSchema, SpreadsheetIdOutput, SpreadsheetIdSchema } from '../../schemas/index.ts';\nimport { findSheetByRef } from '../../spreadsheet/sheet-operations.ts';\n\nconst inputSchema = z.object({\n id: SpreadsheetIdSchema,\n sheetRef: SheetRefSchema,\n});\n\nconst successBranchSchema = z.object({\n type: z.literal('success'),\n id: SpreadsheetIdOutput,\n gid: SheetGidOutput,\n title: z.string().describe('Sheet tab name'),\n sheetUrl: z.string().optional().describe('URL to view the sheet'),\n});\n\nconst outputSchema = z.discriminatedUnion('type', [successBranchSchema, AuthRequiredBranchSchema]);\n\nconst config = {\n description: 'Find an existing sheet/tab within a known spreadsheet by title or GUID',\n inputSchema,\n outputSchema: z.object({\n result: outputSchema,\n }),\n} as const;\n\nexport type Input = z.infer<typeof inputSchema>;\nexport type Output = z.infer<typeof outputSchema>;\n\nasync function handler({ id, sheetRef }: Input, extra: EnrichedExtra): Promise<CallToolResult> {\n const logger = extra.logger;\n logger.info('sheets.sheet.find called', { id, sheetRef });\n\n try {\n const sheets = sheetsApi({ version: 'v4', auth: googleAuth(extra.authContext.auth) });\n\n // Find sheet within the known spreadsheet\n const sheet = await findSheetByRef(sheets, id, sheetRef, logger);\n if (!sheet) {\n throw new ProtocolError(ProtocolErrorCode.InvalidParams, 'Sheet not found');\n }\n\n const title = sheet?.properties?.title ?? String(sheetRef);\n const gid = sheet?.properties?.sheetId != null ? String(sheet.properties.sheetId) : '';\n const sheetUrl = gid ? `https://docs.google.com/spreadsheets/d/${id}/edit#gid=${gid}` : `https://docs.google.com/spreadsheets/d/${id}`;\n\n logger.info('sheets.sheet.find success', { id, gid, title });\n\n const result: Output = {\n type: 'success' as const,\n id,\n gid,\n title,\n sheetUrl,\n };\n\n return {\n content: [{ type: 'text' as const, text: JSON.stringify(result) }],\n structuredContent: { result },\n };\n } catch (error) {\n const message = error instanceof Error ? error.message : String(error);\n logger.error('sheets.sheet.find error', { error: message });\n\n throw new ProtocolError(ProtocolErrorCode.InternalError, `Error finding sheet: ${message}`, {\n stack: error instanceof Error ? error.stack : undefined,\n });\n }\n}\n\nexport default function createTool() {\n return {\n name: 'sheet-find',\n config,\n handler,\n } satisfies ToolModule;\n}\n"],"names":["createTool","AuthRequiredBranchSchema","schemas","inputSchema","z","object","id","SpreadsheetIdSchema","sheetRef","SheetRefSchema","successBranchSchema","type","literal","SpreadsheetIdOutput","gid","SheetGidOutput","title","string","describe","sheetUrl","optional","outputSchema","discriminatedUnion","config","description","result","handler","extra","logger","sheet","sheets","error","message","info","sheetsApi","version","auth","googleAuth","authContext","findSheetByRef","ProtocolError","ProtocolErrorCode","InvalidParams","properties","String","sheetId","content","text","JSON","stringify","struct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;;;;;;;IAEJ;;AAEe,SAAStD;IACtB,OAAO;QACLuD,MAAM;QACNhC,QAAAA;QACAG,SAAAA;IACF;AACF"}
@@ -8,10 +8,11 @@ Object.defineProperty(exports, "default", {
8
8
  return createTool;
9
9
  }
10
10
  });
11
+ var _sheets = require("@googleapis/sheets");
11
12
  var _oauthgoogle = require("@mcp-z/oauth-google");
12
13
  var _server = require("@mcp-z/server");
13
- var _googleapis = require("googleapis");
14
14
  var _zod = require("zod");
15
+ var _googleauthts = require("../../lib/google-auth.js");
15
16
  var _indexts = require("../../schemas/index.js");
16
17
  function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) {
17
18
  try {
@@ -196,9 +197,9 @@ function handler(_0, _1) {
196
197
  ,
197
198
  5
198
199
  ]);
199
- sheets = _googleapis.google.sheets({
200
+ sheets = (0, _sheets.sheets)({
200
201
  version: 'v4',
201
- auth: extra.authContext.auth
202
+ auth: (0, _googleauthts.googleAuth)(extra.authContext.auth)
202
203
  });
203
204
  return [
204
205
  4,
@@ -1 +1 @@
1
- {"version":3,"sources":["/Users/kevin/Dev/OpenSource/ai/mcp-z/mcp-sheets/src/mcp/tools/sheet-rename.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, ToolModule } from '@mcp-z/server';\nimport { ProtocolError, ProtocolErrorCode } from '@mcp-z/server';\nimport { google } from 'googleapis';\nimport { z } from 'zod';\nimport { SheetGidOutput, SheetGidSchema, SpreadsheetIdOutput, SpreadsheetIdSchema } from '../../schemas/index.ts';\n\nconst inputSchema = z.object({\n id: SpreadsheetIdSchema,\n gid: SheetGidSchema,\n newTitle: z.coerce.string().trim().min(1).describe('New name for the sheet tab'),\n});\n\n// Success branch schema\nconst successBranchSchema = z.object({\n type: z.literal('success'),\n operationSummary: z.string().describe('Summary of the rename operation'),\n itemsProcessed: z.number().describe('Total items attempted (always 1 for single sheet)'),\n itemsChanged: z.number().describe('Successfully renamed sheets (always 1 on success)'),\n completedAt: z.string().describe('ISO datetime when operation completed'),\n id: SpreadsheetIdOutput,\n gid: SheetGidOutput,\n sheetUrl: z.string().describe('URL of the renamed sheet'),\n oldTitle: z.string().describe('Previous title of the sheet'),\n newTitle: z.string().describe('New title of the sheet'),\n});\n\n// Output schema with auth_required support\nconst outputSchema = z.discriminatedUnion('type', [successBranchSchema, AuthRequiredBranchSchema]);\n\nconst config = {\n description: 'Rename a sheet within a spreadsheet.',\n inputSchema,\n outputSchema: z.object({\n result: outputSchema,\n }),\n} as const;\n\nexport type Input = z.infer<typeof inputSchema>;\nexport type Output = z.infer<typeof outputSchema>;\n\nasync function handler({ id, gid, newTitle }: Input, extra: EnrichedExtra): Promise<CallToolResult> {\n const logger = extra.logger;\n logger.info('sheets.sheet.rename called', { id, gid, newTitle });\n\n try {\n const sheets = google.sheets({ version: 'v4', auth: extra.authContext.auth });\n\n // First, get the current sheet title\n const spreadsheetInfo = await sheets.spreadsheets.get({\n spreadsheetId: id,\n fields: 'sheets.properties.sheetId,sheets.properties.title',\n });\n\n const sheetInfo = spreadsheetInfo.data.sheets?.find((s) => String(s.properties?.sheetId) === gid);\n if (!sheetInfo?.properties) {\n throw new ProtocolError(ProtocolErrorCode.InvalidParams, `Sheet with gid \"${gid}\" not found in spreadsheet`);\n }\n\n const oldTitle = sheetInfo.properties.title || '';\n\n // Rename the sheet\n await sheets.spreadsheets.batchUpdate({\n spreadsheetId: id,\n requestBody: {\n requests: [\n {\n updateSheetProperties: {\n properties: { sheetId: Number(gid), title: newTitle },\n fields: 'title',\n },\n },\n ],\n },\n });\n\n logger.info('sheets.sheet.rename success', { id, gid, oldTitle, newTitle });\n\n const result: Output = {\n type: 'success' as const,\n operationSummary: `Renamed sheet \"${oldTitle}\" to \"${newTitle}\"`,\n itemsProcessed: 1,\n itemsChanged: 1,\n completedAt: new Date().toISOString(),\n id,\n gid,\n sheetUrl: `https://docs.google.com/spreadsheets/d/${id}/edit#gid=${gid}`,\n oldTitle,\n newTitle,\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 if (error instanceof ProtocolError) {\n throw error;\n }\n const message = error instanceof Error ? error.message : String(error);\n logger.error('sheets.sheet.rename error', { error: message });\n\n throw new ProtocolError(ProtocolErrorCode.InternalError, `Error renaming sheet: ${message}`, {\n stack: error instanceof Error ? error.stack : undefined,\n });\n }\n}\n\nexport default function createTool() {\n return {\n name: 'sheet-rename',\n config,\n handler,\n } satisfies ToolModule;\n}\n"],"names":["createTool","AuthRequiredBranchSchema","schemas","inputSchema","z","object","id","SpreadsheetIdSchema","gid","SheetGidSchema","newTitle","coerce","string","trim","min","describe","successBranchSchema","type","literal","operationSummary","itemsProcessed","number","itemsChanged","completedAt","SpreadsheetIdOutput","SheetGidOutput","sheetUrl","oldTitle","outputSchema","discriminatedUnion","config","description","result","handler","extra","logger","spreadsheetInfo","sheets","sheetInfo","error","message","info","google","version","auth","authContext","spreadsheets","get","spreadsheetId","fields","data","find","s","String","properties","sheetId","ProtocolError","ProtocolErrorCode","InvalidParams","title","batchUpdate","requestBody","requests","updateSheetProperties","Number","Date","toISOString","content","text","JSON","stringify","structuredContent","Error","InternalError","stack","undefined","name"],"mappings":";;;;+BAqHA;;;eAAwBA;;;2BApHA;sBAKyB;0BAC1B;mBACL;uBACuE;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AANzF,IAAM,AAAEC,2BAA6BC,oBAAO,CAApCD;AAQR,IAAME,cAAcC,MAAC,CAACC,MAAM,CAAC;IAC3BC,IAAIC,4BAAmB;IACvBC,KAAKC,uBAAc;IACnBC,UAAUN,MAAC,CAACO,MAAM,CAACC,MAAM,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,MAAMC,KAAKC,SAAS,CAACtC;gCACvB;;4BAEFuC,mBAAmB;gCAAEvC,QAAAA;4BAAO;wBAC9B;;;oBACOO;oBACP,IAAIA,AAAK,YAALA,OAAiBiB,qBAAa,GAAE;wBAClC,MAAMjB;oBACR;oBACMC,UAAUD,AAAK,YAALA,OAAiBiC,SAAQjC,MAAMC,OAAO,GAAGa,OAAOd;oBAChEJ,OAAOI,KAAK,CAAC,6BAA6B;wBAAEA,OAAOC;oBAAQ;oBAE3D,MAAM,IAAIgB,qBAAa,CAACC,yBAAiB,CAACgB,aAAa,EAAE,AAAC,yBAAgC,OAARjC,UAAW;wBAC3FkC,OAAOnC,AAAK,YAALA,OAAiBiC,SAAQjC,MAAMmC,KAAK,GAAGC;oBAChD;;;;;;;IAEJ;;AAEe,SAAS3E;IACtB,OAAO;QACL4E,MAAM;QACN9C,QAAAA;QACAG,SAAAA;IACF;AACF"}
1
+ {"version":3,"sources":["/Users/kevin/Dev/OpenSource/ai/mcp-z/mcp-sheets/src/mcp/tools/sheet-rename.ts"],"sourcesContent":["import { sheets as sheetsApi } from '@googleapis/sheets';\nimport type { EnrichedExtra } from '@mcp-z/oauth-google';\nimport { schemas } from '@mcp-z/oauth-google';\n\nconst { AuthRequiredBranchSchema } = schemas;\n\nimport type { CallToolResult, ToolModule } from '@mcp-z/server';\nimport { ProtocolError, ProtocolErrorCode } from '@mcp-z/server';\nimport { z } from 'zod';\nimport { googleAuth } from '../../lib/google-auth.ts';\nimport { SheetGidOutput, SheetGidSchema, SpreadsheetIdOutput, SpreadsheetIdSchema } from '../../schemas/index.ts';\n\nconst inputSchema = z.object({\n id: SpreadsheetIdSchema,\n gid: SheetGidSchema,\n newTitle: z.coerce.string().trim().min(1).describe('New name for the sheet tab'),\n});\n\n// Success branch schema\nconst successBranchSchema = z.object({\n type: z.literal('success'),\n operationSummary: z.string().describe('Summary of the rename operation'),\n itemsProcessed: z.number().describe('Total items attempted (always 1 for single sheet)'),\n itemsChanged: z.number().describe('Successfully renamed sheets (always 1 on success)'),\n completedAt: z.string().describe('ISO datetime when operation completed'),\n id: SpreadsheetIdOutput,\n gid: SheetGidOutput,\n sheetUrl: z.string().describe('URL of the renamed sheet'),\n oldTitle: z.string().describe('Previous title of the sheet'),\n newTitle: z.string().describe('New title of the sheet'),\n});\n\n// Output schema with auth_required support\nconst outputSchema = z.discriminatedUnion('type', [successBranchSchema, AuthRequiredBranchSchema]);\n\nconst config = {\n description: 'Rename a sheet within a spreadsheet.',\n inputSchema,\n outputSchema: z.object({\n result: outputSchema,\n }),\n} as const;\n\nexport type Input = z.infer<typeof inputSchema>;\nexport type Output = z.infer<typeof outputSchema>;\n\nasync function handler({ id, gid, newTitle }: Input, extra: EnrichedExtra): Promise<CallToolResult> {\n const logger = extra.logger;\n logger.info('sheets.sheet.rename called', { id, gid, newTitle });\n\n try {\n const sheets = sheetsApi({ version: 'v4', auth: googleAuth(extra.authContext.auth) });\n\n // First, get the current sheet title\n const spreadsheetInfo = await sheets.spreadsheets.get({\n spreadsheetId: id,\n fields: 'sheets.properties.sheetId,sheets.properties.title',\n });\n\n const sheetInfo = spreadsheetInfo.data.sheets?.find((s) => String(s.properties?.sheetId) === gid);\n if (!sheetInfo?.properties) {\n throw new ProtocolError(ProtocolErrorCode.InvalidParams, `Sheet with gid \"${gid}\" not found in spreadsheet`);\n }\n\n const oldTitle = sheetInfo.properties.title || '';\n\n // Rename the sheet\n await sheets.spreadsheets.batchUpdate({\n spreadsheetId: id,\n requestBody: {\n requests: [\n {\n updateSheetProperties: {\n properties: { sheetId: Number(gid), title: newTitle },\n fields: 'title',\n },\n },\n ],\n },\n });\n\n logger.info('sheets.sheet.rename success', { id, gid, oldTitle, newTitle });\n\n const result: Output = {\n type: 'success' as const,\n operationSummary: `Renamed sheet \"${oldTitle}\" to \"${newTitle}\"`,\n itemsProcessed: 1,\n itemsChanged: 1,\n completedAt: new Date().toISOString(),\n id,\n gid,\n sheetUrl: `https://docs.google.com/spreadsheets/d/${id}/edit#gid=${gid}`,\n oldTitle,\n newTitle,\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 if (error instanceof ProtocolError) {\n throw error;\n }\n const message = error instanceof Error ? error.message : String(error);\n logger.error('sheets.sheet.rename error', { error: message });\n\n throw new ProtocolError(ProtocolErrorCode.InternalError, `Error renaming sheet: ${message}`, {\n stack: error instanceof Error ? error.stack : undefined,\n });\n }\n}\n\nexport default function createTool() {\n return {\n name: 'sheet-rename',\n config,\n handler,\n } satisfies ToolModule;\n}\n"],"names":["createTool","AuthRequiredBranchSchema","schemas","inputSchema","z","object","id","SpreadsheetIdSchema","gid","SheetGidSchema","newTitle","coerce","string","trim","min","describe","successBranchSchema","type","literal","operationSummary","itemsProcessed","number","itemsChanged","completedAt","SpreadsheetIdOutput","SheetGidOutput","sheetUrl","oldTitle","outputSchema","discriminatedUnion","config","description","result","handler","extra","logger","spreadsheetInfo","sheets","sheetInfo","error","message","info","sheetsApi","version","auth","googleAuth","authContext","spreadsheets","get","spreadsheetId","fields","data","find","s","String","properties","sheetId","ProtocolError","ProtocolErrorCode","InvalidParams","title","batchUpdate","requestBody","requests","updateSheetProperties","Number","Date","toISOString","content","text","JSON","stringify","structuredContent","Error","InternalError","stack","undefined","name"],"mappings":";;;;+BAsHA;;;eAAwBA;;;sBAtHY;2BAEZ;sBAKyB;mBAC/B;4BACS;uBAC8D;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AANzF,IAAM,AAAEC,2BAA6BC,oBAAO,CAApCD;AAQR,IAAME,cAAcC,MAAC,CAACC,MAAM,CAAC;IAC3BC,IAAIC,4BAAmB;IACvBC,KAAKC,uBAAc;IACnBC,UAAUN,MAAC,CAACO,MAAM,CAACC,MAAM,G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D,MAAM;oCACNoD,MAAMC,KAAKC,SAAS,CAACvC;gCACvB;;4BAEFwC,mBAAmB;gCAAExC,QAAAA;4BAAO;wBAC9B;;;oBACOO;oBACP,IAAIA,AAAK,YAALA,OAAiBkB,qBAAa,GAAE;wBAClC,MAAMlB;oBACR;oBACMC,UAAUD,AAAK,YAALA,OAAiBkC,SAAQlC,MAAMC,OAAO,GAAGc,OAAOf;oBAChEJ,OAAOI,KAAK,CAAC,6BAA6B;wBAAEA,OAAOC;oBAAQ;oBAE3D,MAAM,IAAIiB,qBAAa,CAACC,yBAAiB,CAACgB,aAAa,EAAE,AAAC,yBAAgC,OAARlC,UAAW;wBAC3FmC,OAAOpC,AAAK,YAALA,OAAiBkC,SAAQlC,MAAMoC,KAAK,GAAGC;oBAChD;;;;;;;IAEJ;;AAEe,SAAS5E;IACtB,OAAO;QACL6E,MAAM;QACN/C,QAAAA;QACAG,SAAAA;IACF;AACF"}
@@ -8,10 +8,12 @@ Object.defineProperty(exports, "default", {
8
8
  return createTool;
9
9
  }
10
10
  });
11
+ var _drive = require("@googleapis/drive");
12
+ var _sheets = require("@googleapis/sheets");
11
13
  var _oauthgoogle = require("@mcp-z/oauth-google");
12
14
  var _server = require("@mcp-z/server");
13
- var _googleapis = require("googleapis");
14
15
  var _zod = require("zod");
16
+ var _googleauthts = require("../../lib/google-auth.js");
15
17
  var _indexts = require("../../schemas/index.js");
16
18
  function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) {
17
19
  try {
@@ -221,13 +223,13 @@ function handler(_0, _1) {
221
223
  ,
222
224
  5
223
225
  ]);
224
- drive = _googleapis.google.drive({
226
+ drive = (0, _drive.drive)({
225
227
  version: 'v3',
226
- auth: extra.authContext.auth
228
+ auth: (0, _googleauthts.googleAuth)(extra.authContext.auth)
227
229
  });
228
- sheets = _googleapis.google.sheets({
230
+ sheets = (0, _sheets.sheets)({
229
231
  version: 'v4',
230
- auth: extra.authContext.auth
232
+ auth: (0, _googleauthts.googleAuth)(extra.authContext.auth)
231
233
  });
232
234
  return [
233
235
  4,