@mcp-z/mcp-sheets 1.2.2 → 2.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (217) hide show
  1. package/README.md +5 -1
  2. package/dist/cjs/index.js.map +1 -1
  3. package/dist/cjs/mcp/prompts/a1-notation.d.cts +2 -3
  4. package/dist/cjs/mcp/prompts/a1-notation.d.ts +2 -3
  5. package/dist/cjs/mcp/prompts/a1-notation.js.map +1 -1
  6. package/dist/cjs/mcp/resources/spreadsheet.js +2 -2
  7. package/dist/cjs/mcp/resources/spreadsheet.js.map +1 -1
  8. package/dist/cjs/mcp/tools/cells-format.d.cts +1 -1
  9. package/dist/cjs/mcp/tools/cells-format.d.ts +1 -1
  10. package/dist/cjs/mcp/tools/cells-format.js +3 -3
  11. package/dist/cjs/mcp/tools/cells-format.js.map +1 -1
  12. package/dist/cjs/mcp/tools/chart-create.d.cts +1 -1
  13. package/dist/cjs/mcp/tools/chart-create.d.ts +1 -1
  14. package/dist/cjs/mcp/tools/chart-create.js +7 -7
  15. package/dist/cjs/mcp/tools/chart-create.js.map +1 -1
  16. package/dist/cjs/mcp/tools/columns-get.d.cts +1 -1
  17. package/dist/cjs/mcp/tools/columns-get.d.ts +1 -1
  18. package/dist/cjs/mcp/tools/columns-get.js +3 -3
  19. package/dist/cjs/mcp/tools/columns-get.js.map +1 -1
  20. package/dist/cjs/mcp/tools/columns-update.d.cts +1 -1
  21. package/dist/cjs/mcp/tools/columns-update.d.ts +1 -1
  22. package/dist/cjs/mcp/tools/columns-update.js +4 -4
  23. package/dist/cjs/mcp/tools/columns-update.js.map +1 -1
  24. package/dist/cjs/mcp/tools/csv-get-columns.d.cts +1 -1
  25. package/dist/cjs/mcp/tools/csv-get-columns.d.ts +1 -1
  26. package/dist/cjs/mcp/tools/csv-get-columns.js +2 -2
  27. package/dist/cjs/mcp/tools/csv-get-columns.js.map +1 -1
  28. package/dist/cjs/mcp/tools/dimensions-batch-update.d.cts +1 -1
  29. package/dist/cjs/mcp/tools/dimensions-batch-update.d.ts +1 -1
  30. package/dist/cjs/mcp/tools/dimensions-batch-update.js +8 -8
  31. package/dist/cjs/mcp/tools/dimensions-batch-update.js.map +1 -1
  32. package/dist/cjs/mcp/tools/dimensions-move.d.cts +1 -1
  33. package/dist/cjs/mcp/tools/dimensions-move.d.ts +1 -1
  34. package/dist/cjs/mcp/tools/dimensions-move.js +6 -6
  35. package/dist/cjs/mcp/tools/dimensions-move.js.map +1 -1
  36. package/dist/cjs/mcp/tools/rows-append.d.cts +1 -1
  37. package/dist/cjs/mcp/tools/rows-append.d.ts +1 -1
  38. package/dist/cjs/mcp/tools/rows-append.js +3 -3
  39. package/dist/cjs/mcp/tools/rows-append.js.map +1 -1
  40. package/dist/cjs/mcp/tools/rows-csv-append.d.cts +1 -1
  41. package/dist/cjs/mcp/tools/rows-csv-append.d.ts +1 -1
  42. package/dist/cjs/mcp/tools/rows-csv-append.js +7 -7
  43. package/dist/cjs/mcp/tools/rows-csv-append.js.map +1 -1
  44. package/dist/cjs/mcp/tools/rows-get.d.cts +1 -1
  45. package/dist/cjs/mcp/tools/rows-get.d.ts +1 -1
  46. package/dist/cjs/mcp/tools/rows-get.js +4 -4
  47. package/dist/cjs/mcp/tools/rows-get.js.map +1 -1
  48. package/dist/cjs/mcp/tools/sheet-copy-to.d.cts +1 -1
  49. package/dist/cjs/mcp/tools/sheet-copy-to.d.ts +1 -1
  50. package/dist/cjs/mcp/tools/sheet-copy-to.js +4 -4
  51. package/dist/cjs/mcp/tools/sheet-copy-to.js.map +1 -1
  52. package/dist/cjs/mcp/tools/sheet-copy.d.cts +1 -1
  53. package/dist/cjs/mcp/tools/sheet-copy.d.ts +1 -1
  54. package/dist/cjs/mcp/tools/sheet-copy.js +4 -4
  55. package/dist/cjs/mcp/tools/sheet-copy.js.map +1 -1
  56. package/dist/cjs/mcp/tools/sheet-create.d.cts +1 -1
  57. package/dist/cjs/mcp/tools/sheet-create.d.ts +1 -1
  58. package/dist/cjs/mcp/tools/sheet-create.js +3 -3
  59. package/dist/cjs/mcp/tools/sheet-create.js.map +1 -1
  60. package/dist/cjs/mcp/tools/sheet-delete.d.cts +1 -1
  61. package/dist/cjs/mcp/tools/sheet-delete.d.ts +1 -1
  62. package/dist/cjs/mcp/tools/sheet-delete.js +2 -2
  63. package/dist/cjs/mcp/tools/sheet-delete.js.map +1 -1
  64. package/dist/cjs/mcp/tools/sheet-find.d.cts +1 -1
  65. package/dist/cjs/mcp/tools/sheet-find.d.ts +1 -1
  66. package/dist/cjs/mcp/tools/sheet-find.js +3 -3
  67. package/dist/cjs/mcp/tools/sheet-find.js.map +1 -1
  68. package/dist/cjs/mcp/tools/sheet-rename.d.cts +1 -1
  69. package/dist/cjs/mcp/tools/sheet-rename.d.ts +1 -1
  70. package/dist/cjs/mcp/tools/sheet-rename.js +4 -4
  71. package/dist/cjs/mcp/tools/sheet-rename.js.map +1 -1
  72. package/dist/cjs/mcp/tools/spreadsheet-copy.d.cts +1 -1
  73. package/dist/cjs/mcp/tools/spreadsheet-copy.d.ts +1 -1
  74. package/dist/cjs/mcp/tools/spreadsheet-copy.js +2 -2
  75. package/dist/cjs/mcp/tools/spreadsheet-copy.js.map +1 -1
  76. package/dist/cjs/mcp/tools/spreadsheet-create.d.cts +1 -1
  77. package/dist/cjs/mcp/tools/spreadsheet-create.d.ts +1 -1
  78. package/dist/cjs/mcp/tools/spreadsheet-create.js +3 -3
  79. package/dist/cjs/mcp/tools/spreadsheet-create.js.map +1 -1
  80. package/dist/cjs/mcp/tools/spreadsheet-find.d.cts +1 -1
  81. package/dist/cjs/mcp/tools/spreadsheet-find.d.ts +1 -1
  82. package/dist/cjs/mcp/tools/spreadsheet-find.js +2 -2
  83. package/dist/cjs/mcp/tools/spreadsheet-find.js.map +1 -1
  84. package/dist/cjs/mcp/tools/spreadsheet-rename.d.cts +1 -1
  85. package/dist/cjs/mcp/tools/spreadsheet-rename.d.ts +1 -1
  86. package/dist/cjs/mcp/tools/spreadsheet-rename.js +2 -2
  87. package/dist/cjs/mcp/tools/spreadsheet-rename.js.map +1 -1
  88. package/dist/cjs/mcp/tools/validation-set.d.cts +1 -1
  89. package/dist/cjs/mcp/tools/validation-set.d.ts +1 -1
  90. package/dist/cjs/mcp/tools/validation-set.js +4 -4
  91. package/dist/cjs/mcp/tools/validation-set.js.map +1 -1
  92. package/dist/cjs/mcp/tools/values-batch-update.d.cts +1 -1
  93. package/dist/cjs/mcp/tools/values-batch-update.d.ts +1 -1
  94. package/dist/cjs/mcp/tools/values-batch-update.js +5 -5
  95. package/dist/cjs/mcp/tools/values-batch-update.js.map +1 -1
  96. package/dist/cjs/mcp/tools/values-clear.d.cts +1 -1
  97. package/dist/cjs/mcp/tools/values-clear.d.ts +1 -1
  98. package/dist/cjs/mcp/tools/values-clear.js +3 -3
  99. package/dist/cjs/mcp/tools/values-clear.js.map +1 -1
  100. package/dist/cjs/mcp/tools/values-csv-update.d.cts +1 -1
  101. package/dist/cjs/mcp/tools/values-csv-update.d.ts +1 -1
  102. package/dist/cjs/mcp/tools/values-csv-update.js +4 -4
  103. package/dist/cjs/mcp/tools/values-csv-update.js.map +1 -1
  104. package/dist/cjs/mcp/tools/values-markdown-update.d.cts +1 -1
  105. package/dist/cjs/mcp/tools/values-markdown-update.d.ts +1 -1
  106. package/dist/cjs/mcp/tools/values-markdown-update.js +5 -5
  107. package/dist/cjs/mcp/tools/values-markdown-update.js.map +1 -1
  108. package/dist/cjs/mcp/tools/values-replace.d.cts +1 -1
  109. package/dist/cjs/mcp/tools/values-replace.d.ts +1 -1
  110. package/dist/cjs/mcp/tools/values-replace.js +5 -5
  111. package/dist/cjs/mcp/tools/values-replace.js.map +1 -1
  112. package/dist/cjs/mcp/tools/values-search.d.cts +1 -1
  113. package/dist/cjs/mcp/tools/values-search.d.ts +1 -1
  114. package/dist/cjs/mcp/tools/values-search.js +3 -3
  115. package/dist/cjs/mcp/tools/values-search.js.map +1 -1
  116. package/dist/cjs/setup/http.d.cts +1 -1
  117. package/dist/cjs/setup/http.d.ts +1 -1
  118. package/dist/cjs/setup/http.js +23 -13
  119. package/dist/cjs/setup/http.js.map +1 -1
  120. package/dist/cjs/setup/stdio.d.cts +1 -1
  121. package/dist/cjs/setup/stdio.d.ts +1 -1
  122. package/dist/cjs/setup/stdio.js +1 -2
  123. package/dist/cjs/setup/stdio.js.map +1 -1
  124. package/dist/esm/index.js +1 -1
  125. package/dist/esm/index.js.map +1 -1
  126. package/dist/esm/mcp/prompts/a1-notation.d.ts +2 -3
  127. package/dist/esm/mcp/prompts/a1-notation.js.map +1 -1
  128. package/dist/esm/mcp/resources/spreadsheet.js +1 -1
  129. package/dist/esm/mcp/resources/spreadsheet.js.map +1 -1
  130. package/dist/esm/mcp/tools/cells-format.d.ts +1 -1
  131. package/dist/esm/mcp/tools/cells-format.js +3 -3
  132. package/dist/esm/mcp/tools/cells-format.js.map +1 -1
  133. package/dist/esm/mcp/tools/chart-create.d.ts +1 -1
  134. package/dist/esm/mcp/tools/chart-create.js +7 -7
  135. package/dist/esm/mcp/tools/chart-create.js.map +1 -1
  136. package/dist/esm/mcp/tools/columns-get.d.ts +1 -1
  137. package/dist/esm/mcp/tools/columns-get.js +3 -3
  138. package/dist/esm/mcp/tools/columns-get.js.map +1 -1
  139. package/dist/esm/mcp/tools/columns-update.d.ts +1 -1
  140. package/dist/esm/mcp/tools/columns-update.js +4 -4
  141. package/dist/esm/mcp/tools/columns-update.js.map +1 -1
  142. package/dist/esm/mcp/tools/csv-get-columns.d.ts +1 -1
  143. package/dist/esm/mcp/tools/csv-get-columns.js +2 -2
  144. package/dist/esm/mcp/tools/csv-get-columns.js.map +1 -1
  145. package/dist/esm/mcp/tools/dimensions-batch-update.d.ts +1 -1
  146. package/dist/esm/mcp/tools/dimensions-batch-update.js +8 -8
  147. package/dist/esm/mcp/tools/dimensions-batch-update.js.map +1 -1
  148. package/dist/esm/mcp/tools/dimensions-move.d.ts +1 -1
  149. package/dist/esm/mcp/tools/dimensions-move.js +6 -6
  150. package/dist/esm/mcp/tools/dimensions-move.js.map +1 -1
  151. package/dist/esm/mcp/tools/rows-append.d.ts +1 -1
  152. package/dist/esm/mcp/tools/rows-append.js +3 -3
  153. package/dist/esm/mcp/tools/rows-append.js.map +1 -1
  154. package/dist/esm/mcp/tools/rows-csv-append.d.ts +1 -1
  155. package/dist/esm/mcp/tools/rows-csv-append.js +7 -7
  156. package/dist/esm/mcp/tools/rows-csv-append.js.map +1 -1
  157. package/dist/esm/mcp/tools/rows-get.d.ts +1 -1
  158. package/dist/esm/mcp/tools/rows-get.js +4 -4
  159. package/dist/esm/mcp/tools/rows-get.js.map +1 -1
  160. package/dist/esm/mcp/tools/sheet-copy-to.d.ts +1 -1
  161. package/dist/esm/mcp/tools/sheet-copy-to.js +4 -4
  162. package/dist/esm/mcp/tools/sheet-copy-to.js.map +1 -1
  163. package/dist/esm/mcp/tools/sheet-copy.d.ts +1 -1
  164. package/dist/esm/mcp/tools/sheet-copy.js +4 -4
  165. package/dist/esm/mcp/tools/sheet-copy.js.map +1 -1
  166. package/dist/esm/mcp/tools/sheet-create.d.ts +1 -1
  167. package/dist/esm/mcp/tools/sheet-create.js +3 -3
  168. package/dist/esm/mcp/tools/sheet-create.js.map +1 -1
  169. package/dist/esm/mcp/tools/sheet-delete.d.ts +1 -1
  170. package/dist/esm/mcp/tools/sheet-delete.js +2 -2
  171. package/dist/esm/mcp/tools/sheet-delete.js.map +1 -1
  172. package/dist/esm/mcp/tools/sheet-find.d.ts +1 -1
  173. package/dist/esm/mcp/tools/sheet-find.js +3 -3
  174. package/dist/esm/mcp/tools/sheet-find.js.map +1 -1
  175. package/dist/esm/mcp/tools/sheet-rename.d.ts +1 -1
  176. package/dist/esm/mcp/tools/sheet-rename.js +4 -4
  177. package/dist/esm/mcp/tools/sheet-rename.js.map +1 -1
  178. package/dist/esm/mcp/tools/spreadsheet-copy.d.ts +1 -1
  179. package/dist/esm/mcp/tools/spreadsheet-copy.js +2 -2
  180. package/dist/esm/mcp/tools/spreadsheet-copy.js.map +1 -1
  181. package/dist/esm/mcp/tools/spreadsheet-create.d.ts +1 -1
  182. package/dist/esm/mcp/tools/spreadsheet-create.js +3 -3
  183. package/dist/esm/mcp/tools/spreadsheet-create.js.map +1 -1
  184. package/dist/esm/mcp/tools/spreadsheet-find.d.ts +1 -1
  185. package/dist/esm/mcp/tools/spreadsheet-find.js +2 -2
  186. package/dist/esm/mcp/tools/spreadsheet-find.js.map +1 -1
  187. package/dist/esm/mcp/tools/spreadsheet-rename.d.ts +1 -1
  188. package/dist/esm/mcp/tools/spreadsheet-rename.js +2 -2
  189. package/dist/esm/mcp/tools/spreadsheet-rename.js.map +1 -1
  190. package/dist/esm/mcp/tools/validation-set.d.ts +1 -1
  191. package/dist/esm/mcp/tools/validation-set.js +4 -4
  192. package/dist/esm/mcp/tools/validation-set.js.map +1 -1
  193. package/dist/esm/mcp/tools/values-batch-update.d.ts +1 -1
  194. package/dist/esm/mcp/tools/values-batch-update.js +5 -5
  195. package/dist/esm/mcp/tools/values-batch-update.js.map +1 -1
  196. package/dist/esm/mcp/tools/values-clear.d.ts +1 -1
  197. package/dist/esm/mcp/tools/values-clear.js +3 -3
  198. package/dist/esm/mcp/tools/values-clear.js.map +1 -1
  199. package/dist/esm/mcp/tools/values-csv-update.d.ts +1 -1
  200. package/dist/esm/mcp/tools/values-csv-update.js +4 -4
  201. package/dist/esm/mcp/tools/values-csv-update.js.map +1 -1
  202. package/dist/esm/mcp/tools/values-markdown-update.d.ts +1 -1
  203. package/dist/esm/mcp/tools/values-markdown-update.js +5 -5
  204. package/dist/esm/mcp/tools/values-markdown-update.js.map +1 -1
  205. package/dist/esm/mcp/tools/values-replace.d.ts +1 -1
  206. package/dist/esm/mcp/tools/values-replace.js +5 -5
  207. package/dist/esm/mcp/tools/values-replace.js.map +1 -1
  208. package/dist/esm/mcp/tools/values-search.d.ts +1 -1
  209. package/dist/esm/mcp/tools/values-search.js +3 -3
  210. package/dist/esm/mcp/tools/values-search.js.map +1 -1
  211. package/dist/esm/setup/http.d.ts +1 -1
  212. package/dist/esm/setup/http.js +21 -11
  213. package/dist/esm/setup/http.js.map +1 -1
  214. package/dist/esm/setup/stdio.d.ts +1 -1
  215. package/dist/esm/setup/stdio.js +1 -2
  216. package/dist/esm/setup/stdio.js.map +1 -1
  217. package/package.json +7 -13
@@ -1 +1 @@
1
- {"version":3,"sources":["/Users/kevin/Dev/OpenSource/ai/mcp-z/mcp-sheets/src/mcp/tools/columns-get.ts"],"sourcesContent":["/** Get column names from Google Sheet (peek at first row only) */\n\nimport type { EnrichedExtra } from '@mcp-z/oauth-google';\nimport { schemas } from '@mcp-z/oauth-google';\n\nconst { AuthRequiredBranchSchema } = schemas;\n\nimport type { ToolModule } from '@mcp-z/server';\nimport type { CallToolResult } from '@modelcontextprotocol/sdk/types.js';\nimport { ErrorCode, McpError } from '@modelcontextprotocol/sdk/types.js';\nimport { google } from 'googleapis';\nimport { z } from 'zod';\nimport { SheetGidSchema, SpreadsheetIdSchema } from '../../schemas/index.ts';\n\nconst inputSchema = z.object({\n id: SpreadsheetIdSchema,\n gid: SheetGidSchema,\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 columns: for consistency with standard vocabulary\nconst successBranchSchema = z.object({\n type: z.literal('success'),\n columns: z.array(z.string()).describe('First row values (column names) or empty if no rows'),\n isEmpty: z.boolean().describe('True if sheet has zero rows'),\n});\n\nconst outputSchema = z.discriminatedUnion('type', [successBranchSchema, AuthRequiredBranchSchema]);\n\nconst config = {\n description: 'Get first row from Google Sheet. Returns columns array and isEmpty flag.',\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, render }: Input, extra: EnrichedExtra): Promise<CallToolResult> {\n const logger = extra.logger;\n logger.debug?.('sheets.columns.get called', { id, gid, render });\n\n try {\n const sheets = google.sheets({ version: 'v4', auth: extra.authContext.auth });\n\n // Get spreadsheet and sheet info in single API call\n const spreadsheetResponse = await sheets.spreadsheets.get({\n spreadsheetId: id,\n fields: 'sheets.properties.sheetId,sheets.properties.title',\n });\n\n // Find sheet by gid\n const sheet = spreadsheetResponse.data.sheets?.find((s) => String(s.properties?.sheetId) === gid);\n if (!sheet?.properties) {\n throw new McpError(ErrorCode.InvalidParams, `Sheet not found: ${gid}`);\n }\n\n const sheetTitle = sheet.properties.title ?? '';\n\n // Read first row only (A1:ZZZ1 should cover most reasonable sheets)\n const range = `'${sheetTitle}'!A1:ZZZ1`;\n const response = await sheets.spreadsheets.values.get({\n spreadsheetId: id,\n range,\n valueRenderOption: render || 'FORMATTED_VALUE',\n });\n\n const rows = response.data.values || [];\n const isEmpty = rows.length === 0;\n\n // Extract first row and convert to strings (column names)\n const firstRow = rows[0] || [];\n const columns = firstRow.map((value) => String(value ?? ''));\n\n const result: Output = {\n type: 'success' as const,\n columns,\n isEmpty,\n };\n\n logger.info?.('sheets.columns.get completed', { id, gid, columnCount: columns.length, isEmpty });\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.columns.get error', { error: message });\n throw new McpError(ErrorCode.InternalError, `Error getting sheet columns: ${message}`, {\n stack: error instanceof Error ? error.stack : undefined,\n });\n }\n}\n\nexport default function createTool() {\n return {\n name: 'columns-get',\n config,\n handler,\n } satisfies ToolModule;\n}\n"],"names":["schemas","AuthRequiredBranchSchema","ErrorCode","McpError","google","z","SheetGidSchema","SpreadsheetIdSchema","inputSchema","object","id","gid","render","enum","optional","describe","successBranchSchema","type","literal","columns","array","string","isEmpty","boolean","outputSchema","discriminatedUnion","config","description","result","handler","extra","logger","debug","sheet","spreadsheetResponse","sheets","version","auth","authContext","spreadsheets","get","spreadsheetId","fields","data","find","s","String","properties","sheetId","InvalidParams","sheetTitle","title","range","response","values","valueRenderOption","rows","length","firstRow","map","value","info","columnCount","content","text","JSON","stringify","structuredContent","error","message","Error","InternalError","stack","undefined","createTool","name"],"mappings":"AAAA,gEAAgE,GAGhE,SAASA,OAAO,QAAQ,sBAAsB;AAE9C,MAAM,EAAEC,wBAAwB,EAAE,GAAGD;AAIrC,SAASE,SAAS,EAAEC,QAAQ,QAAQ,qCAAqC;AACzE,SAASC,MAAM,QAAQ,aAAa;AACpC,SAASC,CAAC,QAAQ,MAAM;AACxB,SAASC,cAAc,EAAEC,mBAAmB,QAAQ,yBAAyB;AAE7E,MAAMC,cAAcH,EAAEI,MAAM,CAAC;IAC3BC,IAAIH;IACJI,KAAKL;IACLM,QAAQP,EAAEQ,IAAI,CAAC;QAAC;QAAmB;QAAqB;KAAU,EAAEC,QAAQ,GAAGC,QAAQ,CAAC;AAC1F;AAEA,iFAAiF;AACjF,MAAMC,sBAAsBX,EAAEI,MAAM,CAAC;IACnCQ,MAAMZ,EAAEa,OAAO,CAAC;IAChBC,SAASd,EAAEe,KAAK,CAACf,EAAEgB,MAAM,IAAIN,QAAQ,CAAC;IACtCO,SAASjB,EAAEkB,OAAO,GAAGR,QAAQ,CAAC;AAChC;AAEA,MAAMS,eAAenB,EAAEoB,kBAAkB,CAAC,QAAQ;IAACT;IAAqBf;CAAyB;AAEjG,MAAMyB,SAAS;IACbC,aAAa;IACbnB;IACAgB,cAAcnB,EAAEI,MAAM,CAAC;QACrBmB,QAAQJ;IACV;AACF;AAKA,eAAeK,QAAQ,EAAEnB,EAAE,EAAEC,GAAG,EAAEC,MAAM,EAAS,EAAEkB,KAAoB;QAErEC;IADA,MAAMA,SAASD,MAAMC,MAAM;KAC3BA,gBAAAA,OAAOC,KAAK,cAAZD,oCAAAA,mBAAAA,QAAe,6BAA6B;QAAErB;QAAIC;QAAKC;IAA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AAc,gCAAgC;YAAErB;YAAIC;YAAKmD,aAAa3C,QAAQsC,MAAM;YAAEnC;QAAQ;QAC9F,OAAO;YACLyC,SAAS;gBAAC;oBAAE9C,MAAM;oBAAiB+C,MAAMC,KAAKC,SAAS,CAACtC;gBAAQ;aAAE;YAClEuC,mBAAmB;gBAAEvC;YAAO;QAC9B;IACF,EAAE,OAAOwC,OAAO;YAEdrC;QADA,MAAMsC,UAAUD,iBAAiBE,QAAQF,MAAMC,OAAO,GAAGvB,OAAOsB;SAChErC,gBAAAA,OAAOqC,KAAK,cAAZrC,oCAAAA,mBAAAA,QAAe,4BAA4B;YAAEqC,OAAOC;QAAQ;QAC5D,MAAM,IAAIlE,SAASD,UAAUqE,aAAa,EAAE,CAAC,6BAA6B,EAAEF,SAAS,EAAE;YACrFG,OAAOJ,iBAAiBE,QAAQF,MAAMI,KAAK,GAAGC;QAChD;IACF;AACF;AAEA,eAAe,SAASC;IACtB,OAAO;QACLC,MAAM;QACNjD;QACAG;IACF;AACF"}
1
+ {"version":3,"sources":["/Users/kevin/Dev/OpenSource/ai/mcp-z/mcp-sheets/src/mcp/tools/columns-get.ts"],"sourcesContent":["/** Get column names from Google Sheet (peek at first row only) */\n\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 { google } from 'googleapis';\nimport { z } from 'zod';\nimport { SheetGidSchema, SpreadsheetIdSchema } from '../../schemas/index.ts';\n\nconst inputSchema = z.object({\n id: SpreadsheetIdSchema,\n gid: SheetGidSchema,\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 columns: for consistency with standard vocabulary\nconst successBranchSchema = z.object({\n type: z.literal('success'),\n columns: z.array(z.string()).describe('First row values (column names) or empty if no rows'),\n isEmpty: z.boolean().describe('True if sheet has zero rows'),\n});\n\nconst outputSchema = z.discriminatedUnion('type', [successBranchSchema, AuthRequiredBranchSchema]);\n\nconst config = {\n description: 'Get first row from Google Sheet. Returns columns array and isEmpty flag.',\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, render }: Input, extra: EnrichedExtra): Promise<CallToolResult> {\n const logger = extra.logger;\n logger.debug?.('sheets.columns.get called', { id, gid, render });\n\n try {\n const sheets = google.sheets({ version: 'v4', auth: extra.authContext.auth });\n\n // Get spreadsheet and sheet info in single API call\n const spreadsheetResponse = await sheets.spreadsheets.get({\n spreadsheetId: id,\n fields: 'sheets.properties.sheetId,sheets.properties.title',\n });\n\n // Find sheet by gid\n const sheet = spreadsheetResponse.data.sheets?.find((s) => String(s.properties?.sheetId) === gid);\n if (!sheet?.properties) {\n throw new ProtocolError(ProtocolErrorCode.InvalidParams, `Sheet not found: ${gid}`);\n }\n\n const sheetTitle = sheet.properties.title ?? '';\n\n // Read first row only (A1:ZZZ1 should cover most reasonable sheets)\n const range = `'${sheetTitle}'!A1:ZZZ1`;\n const response = await sheets.spreadsheets.values.get({\n spreadsheetId: id,\n range,\n valueRenderOption: render || 'FORMATTED_VALUE',\n });\n\n const rows = response.data.values || [];\n const isEmpty = rows.length === 0;\n\n // Extract first row and convert to strings (column names)\n const firstRow = rows[0] || [];\n const columns = firstRow.map((value) => String(value ?? ''));\n\n const result: Output = {\n type: 'success' as const,\n columns,\n isEmpty,\n };\n\n logger.info?.('sheets.columns.get completed', { id, gid, columnCount: columns.length, isEmpty });\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.columns.get error', { error: message });\n throw new ProtocolError(ProtocolErrorCode.InternalError, `Error getting sheet columns: ${message}`, {\n stack: error instanceof Error ? error.stack : undefined,\n });\n }\n}\n\nexport default function createTool() {\n return {\n name: 'columns-get',\n config,\n handler,\n } satisfies ToolModule;\n}\n"],"names":["schemas","AuthRequiredBranchSchema","ProtocolError","ProtocolErrorCode","google","z","SheetGidSchema","SpreadsheetIdSchema","inputSchema","object","id","gid","render","enum","optional","describe","successBranchSchema","type","literal","columns","array","string","isEmpty","boolean","outputSchema","discriminatedUnion","config","description","result","handler","extra","logger","debug","sheet","spreadsheetResponse","sheets","version","auth","authContext","spreadsheets","get","spreadsheetId","fields","data","find","s","String","properties","sheetId","InvalidParams","sheetTitle","title","range","response","values","valueRenderOption","rows","length","firstRow","map","value","info","columnCount","content","text","JSON","stringify","structuredContent","error","message","Error","InternalError","stack","undefined","createTool","name"],"mappings":"AAAA,gEAAgE,GAGhE,SAASA,OAAO,QAAQ,sBAAsB;AAE9C,MAAM,EAAEC,wBAAwB,EAAE,GAAGD;AAGrC,SAASE,aAAa,EAAEC,iBAAiB,QAAQ,gBAAgB;AACjE,SAASC,MAAM,QAAQ,aAAa;AACpC,SAASC,CAAC,QAAQ,MAAM;AACxB,SAASC,cAAc,EAAEC,mBAAmB,QAAQ,yBAAyB;AAE7E,MAAMC,cAAcH,EAAEI,MAAM,CAAC;IAC3BC,IAAIH;IACJI,KAAKL;IACLM,QAAQP,EAAEQ,IAAI,CAAC;QAAC;QAAmB;QAAqB;KAAU,EAAEC,QAAQ,GAAGC,QAAQ,CAAC;AAC1F;AAEA,iFAAiF;AACjF,MAAMC,sBAAsBX,EAAEI,MAAM,CAAC;IACnCQ,MAAMZ,EAAEa,OAAO,CAAC;IAChBC,SAASd,EAAEe,KAAK,CAACf,EAAEgB,MAAM,IAAIN,QAAQ,CAAC;IACtCO,SAASjB,EAAEkB,OAAO,GAAGR,QAAQ,CAAC;AAChC;AAEA,MA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,mBAAmB3C,UAAU;QAC/B;QAEA,MAAM4C,OAAOH,SAASV,IAAI,CAACW,MAAM,IAAI,EAAE;QACvC,MAAMhC,UAAUkC,KAAKC,MAAM,KAAK;QAEhC,0DAA0D;QAC1D,MAAMC,WAAWF,IAAI,CAAC,EAAE,IAAI,EAAE;QAC9B,MAAMrC,UAAUuC,SAASC,GAAG,CAAC,CAACC,QAAUd,OAAOc,kBAAAA,mBAAAA,QAAS;QAExD,MAAMhC,SAAiB;YACrBX,MAAM;YACNE;YACAG;QACF;SAEAS,eAAAA,OAAO8B,IAAI,cAAX9B,mCAAAA,kBAAAA,QAAc,gCAAgC;YAAErB;YAAIC;YAAKmD,aAAa3C,QAAQsC,MAAM;YAAEnC;QAAQ;QAC9F,OAAO;YACLyC,SAAS;gBAAC;oBAAE9C,MAAM;oBAAiB+C,MAAMC,KAAKC,SAAS,CAACtC;gBAAQ;aAAE;YAClEuC,mBAAmB;gBAAEvC;YAAO;QAC9B;IACF,EAAE,OAAOwC,OAAO;YAEdrC;QADA,MAAMsC,UAAUD,iBAAiBE,QAAQF,MAAMC,OAAO,GAAGvB,OAAOsB;SAChErC,gBAAAA,OAAOqC,KAAK,cAAZrC,oCAAAA,mBAAAA,QAAe,4BAA4B;YAAEqC,OAAOC;QAAQ;QAC5D,MAAM,IAAInE,cAAcC,kBAAkBoE,aAAa,EAAE,CAAC,6BAA6B,EAAEF,SAAS,EAAE;YAClGG,OAAOJ,iBAAiBE,QAAQF,MAAMI,KAAK,GAAGC;QAChD;IACF;AACF;AAEA,eAAe,SAASC;IACtB,OAAO;QACLC,MAAM;QACNjD;QACAG;IACF;AACF"}
@@ -1,5 +1,5 @@
1
1
  import type { EnrichedExtra } from '@mcp-z/oauth-google';
2
- import type { CallToolResult } from '@modelcontextprotocol/sdk/types.js';
2
+ import type { CallToolResult } from '@mcp-z/server';
3
3
  import { z } from 'zod';
4
4
  declare const inputSchema: z.ZodObject<{
5
5
  id: z.ZodString;
@@ -1,6 +1,6 @@
1
1
  import { schemas } from '@mcp-z/oauth-google';
2
2
  const { AuthRequiredBranchSchema } = schemas;
3
- import { ErrorCode, McpError } from '@modelcontextprotocol/sdk/types.js';
3
+ import { ProtocolError, ProtocolErrorCode } from '@mcp-z/server';
4
4
  import { google } from 'googleapis';
5
5
  import { z } from 'zod';
6
6
  import { SheetCellSchema, SheetGidOutput, SheetGidSchema, SpreadsheetIdOutput, SpreadsheetIdSchema } from '../../schemas/index.js';
@@ -118,7 +118,7 @@ async function handler({ id, gid, rows, headers, updateBy, behavior = 'add-or-up
118
118
  (_logger_error = logger.error) === null || _logger_error === void 0 ? void 0 : _logger_error.call(logger, 'sheets.columns.update error', {
119
119
  error: message
120
120
  });
121
- throw new McpError(ErrorCode.InvalidParams, message);
121
+ throw new ProtocolError(ProtocolErrorCode.InvalidParams, message);
122
122
  }
123
123
  // Get spreadsheet and sheet info in single API call
124
124
  const spreadsheetResponse = await sheets.spreadsheets.get({
@@ -140,7 +140,7 @@ async function handler({ id, gid, rows, headers, updateBy, behavior = 'add-or-up
140
140
  gid,
141
141
  rowCount: rows.length
142
142
  });
143
- throw new McpError(ErrorCode.InvalidParams, `Sheet not found: ${gid}`);
143
+ throw new ProtocolError(ProtocolErrorCode.InvalidParams, `Sheet not found: ${gid}`);
144
144
  }
145
145
  const sheetTitle = (_sheet_properties_title = sheet.properties.title) !== null && _sheet_properties_title !== void 0 ? _sheet_properties_title : gid;
146
146
  const sheetGid = (_sheet_properties_sheetId = sheet.properties.sheetId) !== null && _sheet_properties_sheetId !== void 0 ? _sheet_properties_sheetId : 0;
@@ -282,7 +282,7 @@ async function handler({ id, gid, rows, headers, updateBy, behavior = 'add-or-up
282
282
  (_logger_error1 = logger.error) === null || _logger_error1 === void 0 ? void 0 : _logger_error1.call(logger, 'sheets.columns.update error', {
283
283
  error: message
284
284
  });
285
- throw new McpError(ErrorCode.InternalError, `Error updating columns: ${message}`, {
285
+ throw new ProtocolError(ProtocolErrorCode.InternalError, `Error updating columns: ${message}`, {
286
286
  stack: error instanceof Error ? error.stack : undefined
287
287
  });
288
288
  }
@@ -1 +1 @@
1
- {"version":3,"sources":["/Users/kevin/Dev/OpenSource/ai/mcp-z/mcp-sheets/src/mcp/tools/columns-update.ts"],"sourcesContent":["import type { EnrichedExtra } from '@mcp-z/oauth-google';\nimport { schemas } from '@mcp-z/oauth-google';\n\nconst { AuthRequiredBranchSchema } = schemas;\n\nimport type { ToolModule } from '@mcp-z/server';\nimport type { CallToolResult } from '@modelcontextprotocol/sdk/types.js';\nimport { ErrorCode, McpError } from '@modelcontextprotocol/sdk/types.js';\nimport { google } from 'googleapis';\nimport { z } from 'zod';\nimport { SheetCellSchema, SheetGidOutput, SheetGidSchema, SpreadsheetIdOutput, SpreadsheetIdSchema } from '../../schemas/index.ts';\nimport { generateRowKey, type KeyGenerationStrategy, type Row, snapshotHeaderKeysAndPositions, type UpsertOptions, upsertByKey } from '../../spreadsheet/data-operations.ts';\n\n// Input schema for columns update requests with enhanced validation\nconst inputSchema = z\n .object({\n id: SpreadsheetIdSchema,\n gid: SheetGidSchema,\n rows: z.array(z.array(SheetCellSchema)).min(1).max(1000).describe('Array of rows to upsert (max 1000 rows per request). Each row is an array of cell values matching the headers array'),\n headers: z.array(z.string().min(1).max(100)).min(1).max(50).describe('Array of column names/headers (max 50 columns). Must match the length of each row in the rows array'),\n updateBy: z.array(z.string().min(1).max(100)).min(1).max(10).describe('Array of column names to use as unique keys for matching existing rows (max 10 key columns). These columns must exist in the headers array'),\n behavior: z\n .enum(['add-or-update', 'update-only', 'add-only'])\n .default('add-or-update')\n .describe('Update behavior: add-or-update (default) adds new rows and updates existing, update-only skips new rows, add-only skips existing rows. BEST FOR: Bulk upsert operations with key matching in structured database or table contexts.'),\n valueInputOption: z.enum(['RAW', 'USER_ENTERED']).default('USER_ENTERED').describe('How input data should be interpreted (RAW = exact values, USER_ENTERED = parsed like user input with formulas, dates, etc.)'),\n })\n .refine(\n (data) => {\n // Validate that all updateBy columns exist in headers\n const missingColumns = data.updateBy.filter((col) => !data.headers.includes(col));\n return missingColumns.length === 0;\n },\n {\n message: 'All updateBy columns must exist in the headers array',\n path: ['updateBy'],\n }\n )\n .refine(\n (data) => {\n // Validate that all rows have the same length as headers\n const invalidRows = data.rows.findIndex((row) => row.length !== data.headers.length);\n return invalidRows === -1;\n },\n {\n message: 'All rows must have the same length as the headers array',\n path: ['rows'],\n }\n )\n .refine(\n (data) => {\n // Validate that updateBy columns are unique\n const uniqueColumns = new Set(data.updateBy);\n return uniqueColumns.size === data.updateBy.length;\n },\n {\n message: 'updateBy columns must be unique',\n path: ['updateBy'],\n }\n );\n\n// Success branch schema\nconst successBranchSchema = z.object({\n type: z.literal('success'),\n id: SpreadsheetIdOutput,\n gid: SheetGidOutput,\n spreadsheetTitle: z.string().describe('Title of the updated spreadsheet'),\n spreadsheetUrl: z.string().describe('URL of the updated spreadsheet'),\n sheetTitle: z.string().describe('Title of the updated sheet'),\n sheetUrl: z.string().describe('URL of the updated sheet'),\n updatedRows: z.number().int().nonnegative().describe('Number of rows that were successfully updated or inserted'),\n insertedKeys: z.array(z.string()).describe('Keys of rows that were successfully inserted (new rows)'),\n rowsSkipped: z.number().int().nonnegative().describe('Number of rows that were skipped based on the update behavior and existing data'),\n headersAdded: z.array(z.string()).describe('Column headers that were added to the sheet (if any were missing)'),\n errors: z.array(z.string()).optional().describe('Any non-fatal errors encountered during the operation'),\n});\n\nconst outputSchema = z.discriminatedUnion('type', [successBranchSchema, AuthRequiredBranchSchema]);\n\nconst config = {\n description: 'Update spreadsheet data by column headers with intelligent upsert logic. Supports adding missing columns, flexible update behaviors, and robust error handling. Uses column names as keys for matching existing rows, enabling context-aware data synchronization workflows.',\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\n// Helper function to ensure consistent key generation\nfunction generateConsistentRowKey(row: Row, headers: string[], strategy: KeyGenerationStrategy): string {\n return generateRowKey(row, headers, strategy);\n}\n\nasync function handler({ id, gid, rows, headers, updateBy, behavior = 'add-or-update', valueInputOption = 'USER_ENTERED' }: Input, extra: EnrichedExtra): Promise<CallToolResult> {\n const logger = extra.logger;\n logger.debug?.('sheets.columns.update called', {\n id,\n gid,\n rowCount: rows.length,\n headerCount: headers.length,\n updateByColumns: updateBy,\n behavior,\n valueInputOption,\n });\n\n try {\n const sheets = google.sheets({ version: 'v4', auth: extra.authContext.auth });\n\n // Note: Basic input validation is now handled by the enhanced Zod schema\n\n // EARLY VALIDATION: Validate that updateBy columns have non-empty values for all rows\n // This validation happens before finding spreadsheet/sheet to fail fast\n const emptyKeyErrors: string[] = [];\n rows.forEach((row, rowIndex) => {\n const keyValues = updateBy.map((keyCol) => {\n const colIndex = headers.indexOf(keyCol);\n return colIndex >= 0 ? String(row[colIndex] ?? '').trim() : '';\n });\n\n if (keyValues.some((val) => val === '')) {\n emptyKeyErrors.push(`Row ${rowIndex + 1} has empty key values for columns: ${updateBy.join(', ')}`);\n }\n });\n\n if (emptyKeyErrors.length > 0) {\n const message = `Silent data loss prevented - empty key columns detected:\\n${emptyKeyErrors.join('\\n')}`;\n logger.error?.('sheets.columns.update error', { error: message });\n throw new McpError(ErrorCode.InvalidParams, message);\n }\n\n // Get spreadsheet and sheet info in single API call\n const spreadsheetResponse = await sheets.spreadsheets.get({\n spreadsheetId: id,\n fields: 'properties.title,spreadsheetUrl,sheets.properties.sheetId,sheets.properties.title',\n });\n\n const spreadsheetData = spreadsheetResponse.data;\n const spreadsheetTitle = spreadsheetData.properties?.title ?? '';\n const spreadsheetUrl = spreadsheetData.spreadsheetUrl ?? '';\n\n // Find sheet by gid\n const sheet = spreadsheetData.sheets?.find((s) => String(s.properties?.sheetId) === gid);\n if (!sheet?.properties) {\n logger.warn?.('Sheet not found for columns update', { id, gid, rowCount: rows.length });\n throw new McpError(ErrorCode.InvalidParams, `Sheet not found: ${gid}`);\n }\n\n const sheetTitle = sheet.properties.title ?? gid;\n const sheetGid = sheet.properties.sheetId ?? 0;\n const sheetUrl = `https://docs.google.com/spreadsheets/d/${id}/edit#gid=${sheetGid}`;\n\n // Configure upsert options based on behavior\n const upsertOptions: UpsertOptions = {\n keyStrategy: {\n keyColumns: updateBy,\n useProviderIdLogic: false, // Use standard key generation for column-based updates\n separator: '\\\\',\n },\n allowUpdates: behavior === 'add-or-update' || behavior === 'update-only',\n batchSize: 50,\n valueInputOption: valueInputOption,\n };\n\n // Get existing keys to implement behavior filtering\n const { keySet: existingKeys } = await snapshotHeaderKeysAndPositions(sheets, id, sheetTitle, updateBy, upsertOptions.keyStrategy);\n\n // Filter rows based on behavior using consistent key generation\n let processedRows = rows;\n if (behavior === 'add-only') {\n // Only include rows that don't exist yet\n processedRows = rows.filter((row) => {\n // Use the same key generation strategy as the upsert function\n const key = generateConsistentRowKey(row, headers, upsertOptions.keyStrategy);\n return key !== '' && !existingKeys.has(key);\n });\n logger.debug?.('Filtered rows for add-only behavior', {\n originalCount: rows.length,\n filteredCount: processedRows.length,\n });\n } else if (behavior === 'update-only') {\n // Only include rows that already exist\n processedRows = rows.filter((row) => {\n // Use the same key generation strategy as the upsert function\n const key = generateConsistentRowKey(row, headers, upsertOptions.keyStrategy);\n return key !== '' && existingKeys.has(key);\n });\n logger.debug?.('Filtered rows for update-only behavior', {\n originalCount: rows.length,\n filteredCount: processedRows.length,\n });\n }\n\n // Early return if no rows to process after behavior filtering\n if (processedRows.length === 0) {\n logger.info?.('No rows to process after behavior filtering', { behavior, originalCount: rows.length });\n const result: Output = {\n type: 'success' as const,\n id,\n gid: String(sheetGid),\n spreadsheetTitle: spreadsheetTitle || '',\n spreadsheetUrl: spreadsheetUrl || '',\n sheetTitle,\n sheetUrl,\n updatedRows: 0,\n insertedKeys: [],\n rowsSkipped: rows.length,\n headersAdded: [],\n errors: [`No rows matched behavior '${behavior}' - all ${rows.length} rows were skipped`],\n };\n return {\n content: [{ type: 'text' as const, text: JSON.stringify(result) }],\n structuredContent: { result },\n };\n }\n\n logger.debug?.('sheets.columns.update executing upsert operation', {\n spreadsheetId: id,\n sheetTitle,\n canonicalHeaders: headers,\n keyColumns: updateBy,\n behavior,\n processedRowsCount: processedRows.length,\n });\n\n // Execute the upsert operation using the shared function\n const upsertResult = await upsertByKey(sheets, {\n spreadsheetId: id,\n sheetTitle,\n rows: processedRows,\n canonicalHeaders: headers,\n options: upsertOptions,\n logger,\n });\n\n // Track headers that were added (if any)\n // This would require additional logic in upsertByKey to return added headers\n const headersAdded: string[] = [];\n\n // Calculate total rows skipped: behavior filter + upsert duplicates\n const rowsFilteredByBehavior = rows.length - processedRows.length;\n const totalRowsSkipped = upsertResult.rowsSkipped + rowsFilteredByBehavior;\n\n logger.debug?.('sheets.columns.update completed successfully', {\n updatedRows: upsertResult.updatedRows,\n insertedCount: upsertResult.inserted.length,\n rowsSkipped: totalRowsSkipped,\n rowsFilteredByBehavior,\n rowsSkippedByUpsert: upsertResult.rowsSkipped,\n errorsCount: upsertResult.errors?.length || 0,\n });\n\n const result: Output = {\n type: 'success' as const,\n id,\n gid: String(sheetGid),\n spreadsheetTitle: spreadsheetTitle || '',\n spreadsheetUrl: spreadsheetUrl || '',\n sheetTitle,\n sheetUrl,\n updatedRows: upsertResult.updatedRows,\n insertedKeys: upsertResult.inserted,\n rowsSkipped: totalRowsSkipped,\n headersAdded,\n errors: upsertResult.errors,\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.columns.update error', { error: message });\n throw new McpError(ErrorCode.InternalError, `Error updating columns: ${message}`, {\n stack: error instanceof Error ? error.stack : undefined,\n });\n }\n}\n\nexport default function createTool() {\n return {\n name: 'columns-update',\n config,\n handler,\n } satisfies ToolModule;\n}\n"],"names":["schemas","AuthRequiredBranchSchema","ErrorCode","McpError","google","z","SheetCellSchema","SheetGidOutput","SheetGidSchema","SpreadsheetIdOutput","SpreadsheetIdSchema","generateRowKey","snapshotHeaderKeysAndPositions","upsertByKey","inputSchema","object","id","gid","rows","array","min","max","describe","headers","string","updateBy","behavior","enum","default","valueInputOption","refine","data","missingColumns","filter","col","includes","length","message","path","invalidRows","findIndex","row","uniqueColumns","Set","size","successBranchSchema","type","literal","spreadsheetTitle","spreadsheetUrl","sheetTitle","sheetUrl","updatedRows","number","int","nonnegative","insertedKeys","rowsSkipped","headersAdded","errors","optional","outputSchema","discriminatedUnion","config","description","result","generateConsistentRowKey","strategy","handler","extra","logger","debug","rowCount","headerCount","updateByColumns","spreadsheetData","sheet","upsertResult","sheets","version","auth","authContext","emptyKeyErrors","forEach","rowIndex","keyValues","map","keyCol","colIndex","indexOf","String","trim","some","val","push","join","error","InvalidParams","spreadsheetResponse","spreadsheets","get","spreadsheetId","fields","properties","title","find","s","sheetId","warn","sheetGid","upsertOptions","keyStrategy","keyColumns","useProviderIdLogic","separator","allowUpdates","batchSize","keySet","existingKeys","processedRows","key","has","originalCount","filteredCount","info","content","text","JSON","stringify","structuredContent","canonicalHeaders","processedRowsCount","options","rowsFilteredByBehavior","totalRowsSkipped","insertedCount","inserted","rowsSkippedByUpsert","errorsCount","Error","InternalError","stack","undefined","createTool","name"],"mappings":"AACA,SAASA,OAAO,QAAQ,sBAAsB;AAE9C,MAAM,EAAEC,wBAAwB,EAAE,GAAGD;AAIrC,SAASE,SAAS,EAAEC,QAAQ,QAAQ,qCAAqC;AACzE,SAASC,MAAM,QAAQ,aAAa;AACpC,SAASC,CAAC,QAAQ,MAAM;AACxB,SAASC,eAAe,EAAEC,cAAc,EAAEC,cAAc,EAAEC,mBAAmB,EAAEC,mBAAmB,QAAQ,yBAAyB;AACnI,SAASC,cAAc,EAAwCC,8BAA8B,EAAsBC,WAAW,QAAQ,uCAAuC;AAE7K,oEAAoE;AACpE,MAAMC,cAAcT,EACjBU,MAAM,CAAC;IACNC,IAAIN;IACJO,KAAKT;IACLU,MAAMb,EAAEc,KAAK,CAACd,EAAEc,K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Q;YACnC/E,aAAa6E;YACb5E;YACAC,QAAQkB,aAAalB,MAAM;QAC7B;QAEA,OAAO;YACLkE,SAAS;gBAAC;oBAAE/E,MAAM;oBAAiBgF,MAAMC,KAAKC,SAAS,CAAC/D;gBAAQ;aAAE;YAClEgE,mBAAmB;gBAAEhE;YAAO;QAC9B;IACF,EAAE,OAAO+B,OAAO;YAEd1B;QADA,MAAMjC,UAAU2D,iBAAiB2C,QAAQ3C,MAAM3D,OAAO,GAAGqD,OAAOM;SAChE1B,iBAAAA,OAAO0B,KAAK,cAAZ1B,qCAAAA,oBAAAA,QAAe,+BAA+B;YAAE0B,OAAO3D;QAAQ;QAC/D,MAAM,IAAIlC,SAASD,UAAU0I,aAAa,EAAE,CAAC,wBAAwB,EAAEvG,SAAS,EAAE;YAChFwG,OAAO7C,iBAAiB2C,QAAQ3C,MAAM6C,KAAK,GAAGC;QAChD;IACF;AACF;AAEA,eAAe,SAASC;IACtB,OAAO;QACLC,MAAM;QACNjF;QACAK;IACF;AACF"}
1
+ {"version":3,"sources":["/Users/kevin/Dev/OpenSource/ai/mcp-z/mcp-sheets/src/mcp/tools/columns-update.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, SheetGidOutput, SheetGidSchema, SpreadsheetIdOutput, SpreadsheetIdSchema } from '../../schemas/index.ts';\nimport { generateRowKey, type KeyGenerationStrategy, type Row, snapshotHeaderKeysAndPositions, type UpsertOptions, upsertByKey } from '../../spreadsheet/data-operations.ts';\n\n// Input schema for columns update requests with enhanced validation\nconst inputSchema = z\n .object({\n id: SpreadsheetIdSchema,\n gid: SheetGidSchema,\n rows: z.array(z.array(SheetCellSchema)).min(1).max(1000).describe('Array of rows to upsert (max 1000 rows per request). Each row is an array of cell values matching the headers array'),\n headers: z.array(z.string().min(1).max(100)).min(1).max(50).describe('Array of column names/headers (max 50 columns). Must match the length of each row in the rows array'),\n updateBy: z.array(z.string().min(1).max(100)).min(1).max(10).describe('Array of column names to use as unique keys for matching existing rows (max 10 key columns). These columns must exist in the headers array'),\n behavior: z\n .enum(['add-or-update', 'update-only', 'add-only'])\n .default('add-or-update')\n .describe('Update behavior: add-or-update (default) adds new rows and updates existing, update-only skips new rows, add-only skips existing rows. BEST FOR: Bulk upsert operations with key matching in structured database or table contexts.'),\n valueInputOption: z.enum(['RAW', 'USER_ENTERED']).default('USER_ENTERED').describe('How input data should be interpreted (RAW = exact values, USER_ENTERED = parsed like user input with formulas, dates, etc.)'),\n })\n .refine(\n (data) => {\n // Validate that all updateBy columns exist in headers\n const missingColumns = data.updateBy.filter((col) => !data.headers.includes(col));\n return missingColumns.length === 0;\n },\n {\n message: 'All updateBy columns must exist in the headers array',\n path: ['updateBy'],\n }\n )\n .refine(\n (data) => {\n // Validate that all rows have the same length as headers\n const invalidRows = data.rows.findIndex((row) => row.length !== data.headers.length);\n return invalidRows === -1;\n },\n {\n message: 'All rows must have the same length as the headers array',\n path: ['rows'],\n }\n )\n .refine(\n (data) => {\n // Validate that updateBy columns are unique\n const uniqueColumns = new Set(data.updateBy);\n return uniqueColumns.size === data.updateBy.length;\n },\n {\n message: 'updateBy columns must be unique',\n path: ['updateBy'],\n }\n );\n\n// Success branch schema\nconst successBranchSchema = z.object({\n type: z.literal('success'),\n id: SpreadsheetIdOutput,\n gid: SheetGidOutput,\n spreadsheetTitle: z.string().describe('Title of the updated spreadsheet'),\n spreadsheetUrl: z.string().describe('URL of the updated spreadsheet'),\n sheetTitle: z.string().describe('Title of the updated sheet'),\n sheetUrl: z.string().describe('URL of the updated sheet'),\n updatedRows: z.number().int().nonnegative().describe('Number of rows that were successfully updated or inserted'),\n insertedKeys: z.array(z.string()).describe('Keys of rows that were successfully inserted (new rows)'),\n rowsSkipped: z.number().int().nonnegative().describe('Number of rows that were skipped based on the update behavior and existing data'),\n headersAdded: z.array(z.string()).describe('Column headers that were added to the sheet (if any were missing)'),\n errors: z.array(z.string()).optional().describe('Any non-fatal errors encountered during the operation'),\n});\n\nconst outputSchema = z.discriminatedUnion('type', [successBranchSchema, AuthRequiredBranchSchema]);\n\nconst config = {\n description: 'Update spreadsheet data by column headers with intelligent upsert logic. Supports adding missing columns, flexible update behaviors, and robust error handling. Uses column names as keys for matching existing rows, enabling context-aware data synchronization workflows.',\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\n// Helper function to ensure consistent key generation\nfunction generateConsistentRowKey(row: Row, headers: string[], strategy: KeyGenerationStrategy): string {\n return generateRowKey(row, headers, strategy);\n}\n\nasync function handler({ id, gid, rows, headers, updateBy, behavior = 'add-or-update', valueInputOption = 'USER_ENTERED' }: Input, extra: EnrichedExtra): Promise<CallToolResult> {\n const logger = extra.logger;\n logger.debug?.('sheets.columns.update called', {\n id,\n gid,\n rowCount: rows.length,\n headerCount: headers.length,\n updateByColumns: updateBy,\n behavior,\n valueInputOption,\n });\n\n try {\n const sheets = google.sheets({ version: 'v4', auth: extra.authContext.auth });\n\n // Note: Basic input validation is now handled by the enhanced Zod schema\n\n // EARLY VALIDATION: Validate that updateBy columns have non-empty values for all rows\n // This validation happens before finding spreadsheet/sheet to fail fast\n const emptyKeyErrors: string[] = [];\n rows.forEach((row, rowIndex) => {\n const keyValues = updateBy.map((keyCol) => {\n const colIndex = headers.indexOf(keyCol);\n return colIndex >= 0 ? String(row[colIndex] ?? '').trim() : '';\n });\n\n if (keyValues.some((val) => val === '')) {\n emptyKeyErrors.push(`Row ${rowIndex + 1} has empty key values for columns: ${updateBy.join(', ')}`);\n }\n });\n\n if (emptyKeyErrors.length > 0) {\n const message = `Silent data loss prevented - empty key columns detected:\\n${emptyKeyErrors.join('\\n')}`;\n logger.error?.('sheets.columns.update error', { error: message });\n throw new ProtocolError(ProtocolErrorCode.InvalidParams, message);\n }\n\n // Get spreadsheet and sheet info in single API call\n const spreadsheetResponse = await sheets.spreadsheets.get({\n spreadsheetId: id,\n fields: 'properties.title,spreadsheetUrl,sheets.properties.sheetId,sheets.properties.title',\n });\n\n const spreadsheetData = spreadsheetResponse.data;\n const spreadsheetTitle = spreadsheetData.properties?.title ?? '';\n const spreadsheetUrl = spreadsheetData.spreadsheetUrl ?? '';\n\n // Find sheet by gid\n const sheet = spreadsheetData.sheets?.find((s) => String(s.properties?.sheetId) === gid);\n if (!sheet?.properties) {\n logger.warn?.('Sheet not found for columns update', { id, gid, rowCount: rows.length });\n throw new ProtocolError(ProtocolErrorCode.InvalidParams, `Sheet not found: ${gid}`);\n }\n\n const sheetTitle = sheet.properties.title ?? gid;\n const sheetGid = sheet.properties.sheetId ?? 0;\n const sheetUrl = `https://docs.google.com/spreadsheets/d/${id}/edit#gid=${sheetGid}`;\n\n // Configure upsert options based on behavior\n const upsertOptions: UpsertOptions = {\n keyStrategy: {\n keyColumns: updateBy,\n useProviderIdLogic: false, // Use standard key generation for column-based updates\n separator: '\\\\',\n },\n allowUpdates: behavior === 'add-or-update' || behavior === 'update-only',\n batchSize: 50,\n valueInputOption: valueInputOption,\n };\n\n // Get existing keys to implement behavior filtering\n const { keySet: existingKeys } = await snapshotHeaderKeysAndPositions(sheets, id, sheetTitle, updateBy, upsertOptions.keyStrategy);\n\n // Filter rows based on behavior using consistent key generation\n let processedRows = rows;\n if (behavior === 'add-only') {\n // Only include rows that don't exist yet\n processedRows = rows.filter((row) => {\n // Use the same key generation strategy as the upsert function\n const key = generateConsistentRowKey(row, headers, upsertOptions.keyStrategy);\n return key !== '' && !existingKeys.has(key);\n });\n logger.debug?.('Filtered rows for add-only behavior', {\n originalCount: rows.length,\n filteredCount: processedRows.length,\n });\n } else if (behavior === 'update-only') {\n // Only include rows that already exist\n processedRows = rows.filter((row) => {\n // Use the same key generation strategy as the upsert function\n const key = generateConsistentRowKey(row, headers, upsertOptions.keyStrategy);\n return key !== '' && existingKeys.has(key);\n });\n logger.debug?.('Filtered rows for update-only behavior', {\n originalCount: rows.length,\n filteredCount: processedRows.length,\n });\n }\n\n // Early return if no rows to process after behavior filtering\n if (processedRows.length === 0) {\n logger.info?.('No rows to process after behavior filtering', { behavior, originalCount: rows.length });\n const result: Output = {\n type: 'success' as const,\n id,\n gid: String(sheetGid),\n spreadsheetTitle: spreadsheetTitle || '',\n spreadsheetUrl: spreadsheetUrl || '',\n sheetTitle,\n sheetUrl,\n updatedRows: 0,\n insertedKeys: [],\n rowsSkipped: rows.length,\n headersAdded: [],\n errors: [`No rows matched behavior '${behavior}' - all ${rows.length} rows were skipped`],\n };\n return {\n content: [{ type: 'text' as const, text: JSON.stringify(result) }],\n structuredContent: { result },\n };\n }\n\n logger.debug?.('sheets.columns.update executing upsert operation', {\n spreadsheetId: id,\n sheetTitle,\n canonicalHeaders: headers,\n keyColumns: updateBy,\n behavior,\n processedRowsCount: processedRows.length,\n });\n\n // Execute the upsert operation using the shared function\n const upsertResult = await upsertByKey(sheets, {\n spreadsheetId: id,\n sheetTitle,\n rows: processedRows,\n canonicalHeaders: headers,\n options: upsertOptions,\n logger,\n });\n\n // Track headers that were added (if any)\n // This would require additional logic in upsertByKey to return added headers\n const headersAdded: string[] = [];\n\n // Calculate total rows skipped: behavior filter + upsert duplicates\n const rowsFilteredByBehavior = rows.length - processedRows.length;\n const totalRowsSkipped = upsertResult.rowsSkipped + rowsFilteredByBehavior;\n\n logger.debug?.('sheets.columns.update completed successfully', {\n updatedRows: upsertResult.updatedRows,\n insertedCount: upsertResult.inserted.length,\n rowsSkipped: totalRowsSkipped,\n rowsFilteredByBehavior,\n rowsSkippedByUpsert: upsertResult.rowsSkipped,\n errorsCount: upsertResult.errors?.length || 0,\n });\n\n const result: Output = {\n type: 'success' as const,\n id,\n gid: String(sheetGid),\n spreadsheetTitle: spreadsheetTitle || '',\n spreadsheetUrl: spreadsheetUrl || '',\n sheetTitle,\n sheetUrl,\n updatedRows: upsertResult.updatedRows,\n insertedKeys: upsertResult.inserted,\n rowsSkipped: totalRowsSkipped,\n headersAdded,\n errors: upsertResult.errors,\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.columns.update error', { error: message });\n throw new ProtocolError(ProtocolErrorCode.InternalError, `Error updating columns: ${message}`, {\n stack: error instanceof Error ? error.stack : undefined,\n });\n }\n}\n\nexport default function createTool() {\n return {\n name: 'columns-update',\n config,\n handler,\n } satisfies ToolModule;\n}\n"],"names":["schemas","AuthRequiredBranchSchema","ProtocolError","ProtocolErrorCode","google","z","SheetCellSchema","SheetGidOutput","SheetGidSchema","SpreadsheetIdOutput","SpreadsheetIdSchema","generateRowKey","snapshotHeaderKeysAndPositions","upsertByKey","inputSchema","object","id","gid","rows","array","min","max","describe","headers","string","updateBy","behavior","enum","default","valueInputOption","refine","data","missingColumns","filter","col","includes","length","message","path","invalidRows","findIndex","row","uniqueColumns","Set","size","successBranchSchema","type","literal","spreadsheetTitle","spreadsheetUrl","sheetTitle","sheetUrl","updatedRows","number","int","nonnegative","insertedKeys","rowsSkipped","headersAdded","errors","optional","outputSchema","discriminatedUnion","config","description","result","generateConsistentRowKey","strategy","handler","extra","logger","debug","rowCount","headerCount","updateByColumns","spreadsheetData","sheet","upsertResult","sheets","version","auth","authContext","emptyKeyErrors","forEach","rowIndex","keyValues","map","keyCol","colIndex","indexOf","String","trim","some","val","push","join","error","InvalidParams","spreadsheetResponse","spreadsheets","get","spreadsheetId","fields","properties","title","find","s","sheetId","warn","sheetGid","upsertOptions","keyStrategy","keyColumns","useProviderIdLogic","separator","allowUpdates","batchSize","keySet","existingKeys","processedRows","key","has","originalCount","filteredCount","info","content","text","JSON","stringify","structuredContent","canonicalHeaders","processedRowsCount","options","rowsFilteredByBehavior","totalRowsSkipped","insertedCount","inserted","rowsSkippedByUpsert","errorsCount","Error","InternalError","stack","undefined","createTool","name"],"mappings":"AACA,SAASA,OAAO,QAAQ,sBAAsB;AAE9C,MAAM,EAAEC,wBAAwB,EAAE,GAAGD;AAGrC,SAASE,aAAa,EAAEC,iBAAiB,QAAQ,gBAAgB;AACjE,SAASC,MAAM,QAAQ,aAAa;AACpC,SAASC,CAAC,QAAQ,MAAM;AACxB,SAASC,eAAe,EAAEC,cAAc,EAAEC,cAAc,EAAEC,mBAAmB,EAAEC,mBAAmB,QAAQ,yBAAyB;AACnI,SAASC,cAAc,EAAwCC,8BAA8B,EAAsBC,WAAW,QAAQ,uCAAuC;AAE7K,oEAAoE;AACpE,MAAMC,cAAcT,EACjBU,MAAM,CAAC;IACNC,IAAIN;IACJO,KAAKT;IACLU,MAAMb,EAAEc,KAAK,CAACd,EAAEc,KAAK,CAACb,kBAAkBc,GAAG,CAAC,GAAGC,GAAG,CAAC,MAAMC,QAAQ,CAAC;IAClEC,SAASlB,EAAEc,KAAK,CAACd,EAAEmB,MAAM,GAAGJ,GAAG,CAAC,GAAGC,GAAG,CAAC,MAAMD,GAAG,CAAC,GAAGC,GAAG,CAAC,IAAIC,QAAQ,CAAC;IACrEG,UAAUpB,EAAEc,KAAK,CAACd,EAAEmB,MAAM,GAAGJ,GAAG,CAAC,GAAGC,GAAG,CAAC,MAAMD,GAAG,CAAC,GAAGC,GAAG,CAAC,IAAIC,QAAQ,CAAC;IACtEI,UAAUrB,EACPsB,IAAI,CAAC;QAAC;QAAiB;QAAe;KAAW,EACjDC,OAAO,CAAC,iBACRN,QAAQ,CAAC;IACZO,kBAAkBxB,EAAEsB,IAAI,CAAC;QAAC;QAAO;KAAe,EAAEC,OAAO,CAAC,gBAAgBN,QAAQ,CAAC;AACrF,GACCQ,MAAM,CACL,CAACC;IACC,sDAAsD;IACtD,MAAMC,iBAAiBD,KAAKN,QAAQ,CAACQ,MAAM,CAAC,CAAC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Get column names from CSV file (peek at first row only) */
2
2
  import type { EnrichedExtra } from '@mcp-z/oauth-google';
3
- import type { CallToolResult } from '@modelcontextprotocol/sdk/types.js';
3
+ import type { CallToolResult } from '@mcp-z/server';
4
4
  import { z } from 'zod';
5
5
  declare const inputSchema: z.ZodObject<{
6
6
  sourceUri: z.ZodString;
@@ -1,6 +1,6 @@
1
1
  /** Get column names from CSV file (peek at first row only) */ import { schemas } from '@mcp-z/oauth-google';
2
2
  const { AuthRequiredBranchSchema } = schemas;
3
- import { ErrorCode, McpError } from '@modelcontextprotocol/sdk/types.js';
3
+ import { ProtocolError, ProtocolErrorCode } from '@mcp-z/server';
4
4
  import { parse } from 'csv-parse';
5
5
  import { z } from 'zod';
6
6
  import { getCsvReadStream } from '../../spreadsheet/csv-streaming.js';
@@ -81,7 +81,7 @@ async function handler({ sourceUri }, extra) {
81
81
  (_logger_error = logger.error) === null || _logger_error === void 0 ? void 0 : _logger_error.call(logger, 'sheets.csv.get-columns error', {
82
82
  error: message
83
83
  });
84
- throw new McpError(ErrorCode.InternalError, `Error getting CSV columns: ${message}`, {
84
+ throw new ProtocolError(ProtocolErrorCode.InternalError, `Error getting CSV columns: ${message}`, {
85
85
  stack: error instanceof Error ? error.stack : undefined
86
86
  });
87
87
  }
@@ -1 +1 @@
1
- {"version":3,"sources":["/Users/kevin/Dev/OpenSource/ai/mcp-z/mcp-sheets/src/mcp/tools/csv-get-columns.ts"],"sourcesContent":["/** Get column names from CSV file (peek at first row only) */\n\nimport type { EnrichedExtra } from '@mcp-z/oauth-google';\nimport { schemas } from '@mcp-z/oauth-google';\n\nconst { AuthRequiredBranchSchema } = schemas;\n\nimport type { ToolModule } from '@mcp-z/server';\nimport type { CallToolResult } from '@modelcontextprotocol/sdk/types.js';\nimport { ErrorCode, McpError } from '@modelcontextprotocol/sdk/types.js';\nimport { parse } from 'csv-parse';\nimport { z } from 'zod';\nimport { getCsvReadStream } from '../../spreadsheet/csv-streaming.ts';\n\nconst inputSchema = z.object({\n sourceUri: z.string().trim().min(1).describe('CSV file URI (file://, http://, https://)'),\n});\n\n// Success branch schema - uses columns: for consistency with standard vocabulary\nconst successBranchSchema = z.object({\n type: z.literal('success'),\n columns: z.array(z.string()).describe('First row values (column names) or empty if no rows'),\n isEmpty: z.boolean().describe('True if CSV has zero rows'),\n});\n\nconst outputSchema = z.discriminatedUnion('type', [successBranchSchema, AuthRequiredBranchSchema]);\n\nconst config = {\n description: 'Get first row from CSV file (streaming, no memory overhead). Returns columns array and isEmpty flag.',\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({ sourceUri }: Input, extra: EnrichedExtra): Promise<CallToolResult> {\n const logger = extra.logger;\n logger.debug?.('sheets.csv.get-columns called', { sourceUri });\n\n try {\n // Get readable stream from CSV URI (no temp files!)\n const readStream = await getCsvReadStream(sourceUri);\n\n // Create CSV parser without treating first row as column names\n // We just want to read the raw first row\n const parser = readStream.pipe(\n parse({\n columns: false, // Don't treat first row as headers\n skip_empty_lines: true,\n trim: true,\n cast: true, // Auto-convert numbers/booleans\n relax_column_count: true,\n })\n );\n\n // Read only the first row\n let firstRow: unknown[] = [];\n let rowCount = 0;\n\n for await (const row of parser) {\n firstRow = row;\n rowCount++;\n break; // Only read first row\n }\n\n // Convert first row to strings (column names)\n const columns = firstRow.map((value) => String(value ?? ''));\n const isEmpty = rowCount === 0;\n\n const result: Output = {\n type: 'success' as const,\n columns,\n isEmpty,\n };\n\n logger.info?.('sheets.csv.get-columns completed', { sourceUri, columnCount: columns.length, isEmpty });\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.csv.get-columns error', { error: message });\n throw new McpError(ErrorCode.InternalError, `Error getting CSV columns: ${message}`, {\n stack: error instanceof Error ? error.stack : undefined,\n });\n }\n}\n\nexport default function createTool() {\n return {\n name: 'csv-get-columns',\n config,\n handler,\n } satisfies ToolModule;\n}\n"],"names":["schemas","AuthRequiredBranchSchema","ErrorCode","McpError","parse","z","getCsvReadStream","inputSchema","object","sourceUri","string","trim","min","describe","successBranchSchema","type","literal","columns","array","isEmpty","boolean","outputSchema","discriminatedUnion","config","description","result","handler","extra","logger","debug","readStream","parser","pipe","skip_empty_lines","cast","relax_column_count","firstRow","rowCount","row","map","value","String","info","columnCount","length","content","text","JSON","stringify","structuredContent","error","message","Error","InternalError","stack","undefined","createTool","name"],"mappings":"AAAA,4DAA4D,GAG5D,SAASA,OAAO,QAAQ,sBAAsB;AAE9C,MAAM,EAAEC,wBAAwB,EAAE,GAAGD;AAIrC,SAASE,SAAS,EAAEC,QAAQ,QAAQ,qCAAqC;AACzE,SAASC,KAAK,QAAQ,YAAY;AAClC,SAASC,CAAC,QAAQ,MAAM;AACxB,SAASC,gBAAgB,QAAQ,qCAAqC;AAEtE,MAAMC,cAAcF,EAAEG,MAAM,CAAC;IAC3BC,WAAWJ,EAAEK,MAAM,GAAGC,IAAI,GAAGC,GAAG,CAAC,GAAGC,QAAQ,CAAC;AAC/C;AAEA,iFAAiF;AACjF,MAAMC,sBAAsBT,EAAEG,MAAM,CAAC;IACnCO,MAAMV,EAAEW,OAAO,CAAC;IAChBC,SAASZ,EAAEa,KAAK,CAACb,EAAEK,MAAM,IAAIG,QAAQ,CAAC;IACtCM,SAASd,EAAEe,OAAO,GAAGP,QAAQ,CAAC;AAChC;AAEA,MAAMQ,eAAehB,EAAEiB,kBAAkB,CAAC,QAAQ;IAACR;IAAqBb;CAAyB;AAEjG,MAAMsB,SAAS;IACbC,aAAa;IACbjB;IACAc,cAAchB,EAAEG,MAAM,CAAC;QACrBiB,QAAQJ;IACV;AACF;AAKA,eAAeK,QAAQ,EAAEjB,SAAS,EAAS,EAAEkB,KAAoB;QAE/DC;IADA,MAAMA,SAASD,MAAMC,MAAM;KAC3BA,gBAAAA,OAA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Ae,SAASC;IACtB,OAAO;QACLC,MAAM;QACNlC;QACAG;IACF;AACF"}
1
+ {"version":3,"sources":["/Users/kevin/Dev/OpenSource/ai/mcp-z/mcp-sheets/src/mcp/tools/csv-get-columns.ts"],"sourcesContent":["/** Get column names from CSV file (peek at first row only) */\n\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 { parse } from 'csv-parse';\nimport { z } from 'zod';\nimport { getCsvReadStream } from '../../spreadsheet/csv-streaming.ts';\n\nconst inputSchema = z.object({\n sourceUri: z.string().trim().min(1).describe('CSV file URI (file://, http://, https://)'),\n});\n\n// Success branch schema - uses columns: for consistency with standard vocabulary\nconst successBranchSchema = z.object({\n type: z.literal('success'),\n columns: z.array(z.string()).describe('First row values (column names) or empty if no rows'),\n isEmpty: z.boolean().describe('True if CSV has zero rows'),\n});\n\nconst outputSchema = z.discriminatedUnion('type', [successBranchSchema, AuthRequiredBranchSchema]);\n\nconst config = {\n description: 'Get first row from CSV file (streaming, no memory overhead). Returns columns array and isEmpty flag.',\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({ sourceUri }: Input, extra: EnrichedExtra): Promise<CallToolResult> {\n const logger = extra.logger;\n logger.debug?.('sheets.csv.get-columns called', { sourceUri });\n\n try {\n // Get readable stream from CSV URI (no temp files!)\n const readStream = await getCsvReadStream(sourceUri);\n\n // Create CSV parser without treating first row as column names\n // We just want to read the raw first row\n const parser = readStream.pipe(\n parse({\n columns: false, // Don't treat first row as headers\n skip_empty_lines: true,\n trim: true,\n cast: true, // Auto-convert numbers/booleans\n relax_column_count: true,\n })\n );\n\n // Read only the first row\n let firstRow: unknown[] = [];\n let rowCount = 0;\n\n for await (const row of parser) {\n firstRow = row;\n rowCount++;\n break; // Only read first row\n }\n\n // Convert first row to strings (column names)\n const columns = firstRow.map((value) => String(value ?? ''));\n const isEmpty = rowCount === 0;\n\n const result: Output = {\n type: 'success' as const,\n columns,\n isEmpty,\n };\n\n logger.info?.('sheets.csv.get-columns completed', { sourceUri, columnCount: columns.length, isEmpty });\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.csv.get-columns error', { error: message });\n throw new ProtocolError(ProtocolErrorCode.InternalError, `Error getting CSV columns: ${message}`, {\n stack: error instanceof Error ? error.stack : undefined,\n });\n }\n}\n\nexport default function createTool() {\n return {\n name: 'csv-get-columns',\n config,\n handler,\n } satisfies ToolModule;\n}\n"],"names":["schemas","AuthRequiredBranchSchema","ProtocolError","ProtocolErrorCode","parse","z","getCsvReadStream","inputSchema","object","sourceUri","string","trim","min","describe","successBranchSchema","type","literal","columns","array","isEmpty","boolean","outputSchema","discriminatedUnion","config","description","result","handler","extra","logger","debug","readStream","parser","pipe","skip_empty_lines","cast","relax_column_count","firstRow","rowCount","row","map","value","String","info","columnCount","length","content","text","JSON","stringify","structuredContent","error","message","Error","InternalError","stack","undefined","createTool","name"],"mappings":"AAAA,4DAA4D,GAG5D,SAASA,OAAO,QAAQ,sBAAsB;AAE9C,MAAM,EAAEC,wBAAwB,EAAE,GAAGD;AAGrC,SAASE,aAAa,EAAEC,iBAAiB,QAAQ,gBAAgB;AACjE,SAASC,KAAK,QAAQ,YAAY;AAClC,SAASC,CAAC,QAAQ,MAAM;AACxB,SAASC,gBAAgB,QAAQ,qCAAqC;AAEtE,MAAMC,cAAcF,EAAEG,MAAM,CAAC;IAC3BC,WAAWJ,EAAEK,MAAM,GAAGC,IAAI,GAAGC,GAAG,CAAC,GAAGC,QAAQ,CAAC;AAC/C;AAEA,iFAAiF;AACjF,MAAMC,s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,SAAS;gBAAC;oBAAE9B,MAAM;oBAAiB+B,MAAMC,KAAKC,SAAS,CAACvB;gBAAQ;aAAE;YAClEwB,mBAAmB;gBAAExB;YAAO;QAC9B;IACF,EAAE,OAAOyB,OAAO;YAEdtB;QADA,MAAMuB,UAAUD,iBAAiBE,QAAQF,MAAMC,OAAO,GAAGV,OAAOS;SAChEtB,gBAAAA,OAAOsB,KAAK,cAAZtB,oCAAAA,mBAAAA,QAAe,gCAAgC;YAAEsB,OAAOC;QAAQ;QAChE,MAAM,IAAIjD,cAAcC,kBAAkBkD,aAAa,EAAE,CAAC,2BAA2B,EAAEF,SAAS,EAAE;YAChGG,OAAOJ,iBAAiBE,QAAQF,MAAMI,KAAK,GAAGC;QAChD;IACF;AACF;AAEA,eAAe,SAASC;IACtB,OAAO;QACLC,MAAM;QACNlC;QACAG;IACF;AACF"}
@@ -1,5 +1,5 @@
1
1
  import type { EnrichedExtra } from '@mcp-z/oauth-google';
2
- import type { CallToolResult } from '@modelcontextprotocol/sdk/types.js';
2
+ import type { CallToolResult } from '@mcp-z/server';
3
3
  import { z } from 'zod';
4
4
  declare const inputSchema: z.ZodObject<{
5
5
  id: z.ZodString;
@@ -1,6 +1,6 @@
1
1
  import { schemas } from '@mcp-z/oauth-google';
2
2
  const { AuthRequiredBranchSchema } = schemas;
3
- import { ErrorCode, McpError } from '@modelcontextprotocol/sdk/types.js';
3
+ import { ProtocolError, ProtocolErrorCode } from '@mcp-z/server';
4
4
  import { google } from 'googleapis';
5
5
  import { z } from 'zod';
6
6
  import { SheetGidOutput, SheetGidSchema, SpreadsheetIdOutput, SpreadsheetIdSchema } from '../../schemas/index.js';
@@ -106,7 +106,7 @@ async function handler({ id, gid, requests }, extra) {
106
106
  gid,
107
107
  requestCount: requests.length
108
108
  });
109
- throw new McpError(ErrorCode.InvalidParams, `Sheet not found: ${gid}`);
109
+ throw new ProtocolError(ProtocolErrorCode.InvalidParams, `Sheet not found: ${gid}`);
110
110
  }
111
111
  const sheetTitle = (_sheet_properties_title = sheet.properties.title) !== null && _sheet_properties_title !== void 0 ? _sheet_properties_title : gid;
112
112
  const sheetId = sheet.properties.sheetId;
@@ -117,7 +117,7 @@ async function handler({ id, gid, requests }, extra) {
117
117
  gid,
118
118
  sheetTitle
119
119
  });
120
- throw new McpError(ErrorCode.InternalError, `Sheet ID not available for ${gid}. Cannot perform dimension operations without valid sheet ID.`);
120
+ throw new ProtocolError(ProtocolErrorCode.InternalError, `Sheet ID not available for ${gid}. Cannot perform dimension operations without valid sheet ID.`);
121
121
  }
122
122
  const sheetUrl = `https://docs.google.com/spreadsheets/d/${id}/edit#gid=${sheetId}`;
123
123
  // Get current sheet dimensions for response calculation
@@ -167,7 +167,7 @@ async function handler({ id, gid, requests }, extra) {
167
167
  sheetTitle,
168
168
  requestCount: requests.length
169
169
  });
170
- throw new McpError(ErrorCode.InternalError, 'Batch update failed: no response data received from Google Sheets API');
170
+ throw new ProtocolError(ProtocolErrorCode.InternalError, 'Batch update failed: no response data received from Google Sheets API');
171
171
  }
172
172
  const replies = updateResult.replies || [];
173
173
  const expectedCount = requests.length;
@@ -185,7 +185,7 @@ async function handler({ id, gid, requests }, extra) {
185
185
  replyType: Object.keys(reply || {})[0] || 'empty'
186
186
  }))
187
187
  });
188
- throw new McpError(ErrorCode.InternalError, `Batch operation failed: expected ${expectedCount} operations, received ${actualCount} replies. This may indicate a partial failure or Google API issue.`);
188
+ throw new ProtocolError(ProtocolErrorCode.InternalError, `Batch operation failed: expected ${expectedCount} operations, received ${actualCount} replies. This may indicate a partial failure or Google API issue.`);
189
189
  }
190
190
  // Validate each reply exists - Google Sheets API may return empty objects for successful operations
191
191
  for(let i = 0; i < replies.length; i++){
@@ -200,7 +200,7 @@ async function handler({ id, gid, requests }, extra) {
200
200
  spreadsheetId: id,
201
201
  sheetTitle
202
202
  });
203
- throw new McpError(ErrorCode.InternalError, `Operation ${i} failed: missing request data`);
203
+ throw new ProtocolError(ProtocolErrorCode.InternalError, `Operation ${i} failed: missing request data`);
204
204
  }
205
205
  // Note: Google Sheets API often returns empty objects {} for successful dimension operations
206
206
  // This is normal behavior and indicates success, not failure
@@ -213,7 +213,7 @@ async function handler({ id, gid, requests }, extra) {
213
213
  spreadsheetId: id,
214
214
  sheetTitle
215
215
  });
216
- throw new McpError(ErrorCode.InternalError, `Operation ${i} (${request.operation}) failed: null reply from Google Sheets API`);
216
+ throw new ProtocolError(ProtocolErrorCode.InternalError, `Operation ${i} (${request.operation}) failed: null reply from Google Sheets API`);
217
217
  }
218
218
  }
219
219
  // Calculate final dimensions and operation results
@@ -307,7 +307,7 @@ async function handler({ id, gid, requests }, extra) {
307
307
  (_logger_error5 = logger.error) === null || _logger_error5 === void 0 ? void 0 : _logger_error5.call(logger, 'sheets.dimensions.batchUpdate error', {
308
308
  error: message
309
309
  });
310
- throw new McpError(ErrorCode.InternalError, `Error batch updating dimensions: ${message}`, {
310
+ throw new ProtocolError(ProtocolErrorCode.InternalError, `Error batch updating dimensions: ${message}`, {
311
311
  stack: error instanceof Error ? error.stack : undefined
312
312
  });
313
313
  }
@@ -1 +1 @@
1
- {"version":3,"sources":["/Users/kevin/Dev/OpenSource/ai/mcp-z/mcp-sheets/src/mcp/tools/dimensions-batch-update.ts"],"sourcesContent":["import type { EnrichedExtra } from '@mcp-z/oauth-google';\nimport { schemas } from '@mcp-z/oauth-google';\n\nconst { AuthRequiredBranchSchema } = schemas;\n\nimport type { ToolModule } from '@mcp-z/server';\nimport type { CallToolResult } from '@modelcontextprotocol/sdk/types.js';\nimport { ErrorCode, McpError } from '@modelcontextprotocol/sdk/types.js';\nimport { google } from 'googleapis';\nimport { z } from 'zod';\nimport { SheetGidOutput, SheetGidSchema, SpreadsheetIdOutput, SpreadsheetIdSchema } from '../../schemas/index.ts';\nimport { buildDimensionRequest, calculateAffectedCount, DEFAULT_COLUMN_COUNT, DEFAULT_ROW_COUNT, type DimensionRequest, MAX_COLUMN_COUNT, MAX_ROW_COUNT, sortOperations } from './lib/dimension-operations.ts';\n\n// Input schema for dimension batch update requests\nconst DimensionRequestSchema = z.object({\n operation: z.enum(['insertDimension', 'deleteDimension', 'appendDimension']).describe('Type of dimension operation to perform'),\n dimension: z.enum(['ROWS', 'COLUMNS']).describe('Whether to operate on rows or columns'),\n startIndex: z.number().int().nonnegative().describe('Starting index for the operation (0-based)'),\n endIndex: z.number().int().nonnegative().optional().describe('Ending index for the operation (0-based, exclusive). Optional - if omitted, the range is unbounded (extends to the end of the sheet)'),\n inheritFromBefore: z.boolean().optional().describe('For insertDimension: whether new rows/columns inherit properties from the row/column before the insertion point'),\n});\n\nconst inputSchema = z.object({\n id: SpreadsheetIdSchema,\n gid: SheetGidSchema,\n requests: z.array(DimensionRequestSchema).min(1).describe('Array of dimension update requests'),\n});\n\n// Success branch schema\nconst successBranchSchema = z.object({\n type: z.literal('success'),\n id: SpreadsheetIdOutput,\n gid: SheetGidOutput,\n spreadsheetTitle: z.string().describe('Title of the updated spreadsheet'),\n spreadsheetUrl: z.string().describe('URL of the updated spreadsheet'),\n sheetTitle: z.string().describe('Title of the updated sheet'),\n sheetUrl: z.string().describe('URL of the updated sheet'),\n totalOperations: z.number().int().nonnegative().describe('Total number of dimension operations performed'),\n operationResults: z\n .array(\n z.object({\n operation: z.enum(['insertDimension', 'deleteDimension', 'appendDimension']).describe('Type of operation that was performed'),\n dimension: z.enum(['ROWS', 'COLUMNS']).describe('Dimension that was operated on'),\n startIndex: z.number().int().nonnegative().describe('Starting index of the operation'),\n endIndex: z.number().int().nonnegative().optional().describe('Ending index of the operation (for insert/delete)'),\n affectedCount: z.number().int().nonnegative().describe('Number of rows/columns affected by this operation'),\n })\n )\n .describe('Detailed results for each dimension operation'),\n updatedDimensions: z\n .object({\n rows: z.number().int().nonnegative().describe('Total number of rows in the sheet after all operations'),\n columns: z.number().int().nonnegative().describe('Total number of columns in the sheet after all operations'),\n })\n .describe('Final dimensions of the sheet after all operations'),\n});\n\nconst outputSchema = z.discriminatedUnion('type', [successBranchSchema, AuthRequiredBranchSchema]);\n\nconst config = {\n description: 'Batch update sheet dimensions by inserting, deleting, or appending rows/columns. Operations are atomic (all succeed or all fail) and execute in optimal order automatically.',\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, requests }: Input, extra: EnrichedExtra): Promise<CallToolResult> {\n const logger = extra.logger;\n logger.debug?.('sheets.dimensions.batchUpdate called', {\n id,\n gid,\n requestCount: requests.length,\n operations: requests.map((r) => ({ operation: r.operation, dimension: r.dimension, startIndex: r.startIndex, endIndex: r.endIndex })),\n });\n\n try {\n const sheets = google.sheets({ version: 'v4', auth: extra.authContext.auth });\n\n // Get spreadsheet and sheet info in single API call\n const spreadsheetResponse = await sheets.spreadsheets.get({\n spreadsheetId: id,\n fields: 'properties.title,spreadsheetUrl,sheets.properties.sheetId,sheets.properties.title,sheets.properties.gridProperties',\n });\n\n const spreadsheetData = spreadsheetResponse.data;\n const spreadsheetTitle = spreadsheetData.properties?.title ?? '';\n const spreadsheetUrl = spreadsheetData.spreadsheetUrl ?? '';\n\n // Find sheet by gid\n const sheet = spreadsheetData.sheets?.find((s) => String(s.properties?.sheetId) === gid);\n if (!sheet?.properties) {\n logger.warn?.('Sheet not found for dimensions batch update', { id, gid, requestCount: requests.length });\n throw new McpError(ErrorCode.InvalidParams, `Sheet not found: ${gid}`);\n }\n\n const sheetTitle = sheet.properties.title ?? gid;\n const sheetId = sheet.properties.sheetId;\n\n if (sheetId === undefined || sheetId === null) {\n logger.error?.('Sheet ID not available for dimensions batch update', { id, gid, sheetTitle });\n throw new McpError(ErrorCode.InternalError, `Sheet ID not available for ${gid}. Cannot perform dimension operations without valid sheet ID.`);\n }\n\n const sheetUrl = `https://docs.google.com/spreadsheets/d/${id}/edit#gid=${sheetId}`;\n\n // Get current sheet dimensions for response calculation\n // Note: Google Sheets API may not always provide gridProperties for older sheets\n // Fall back to Google's documented defaults for new sheets\n const currentRowCount = sheet.properties.gridProperties?.rowCount ?? DEFAULT_ROW_COUNT;\n const currentColumnCount = sheet.properties.gridProperties?.columnCount ?? DEFAULT_COLUMN_COUNT;\n\n // Sort operations for optimal execution order to prevent index conflicts\n // Delete operations are processed first (high to low index) to avoid shifting issues\n // Insert/append operations are processed after (low to high index)\n const sortedRequests = sortOperations(requests as DimensionRequest[]);\n\n // Build Google Sheets API batch update requests\n const batchRequests = sortedRequests.map((operation) => buildDimensionRequest(operation, sheetId));\n\n logger.debug?.('sheets.dimensions.batchUpdate executing batch request', {\n spreadsheetId: id,\n sheetTitle,\n sheetId,\n totalOperations: batchRequests.length,\n operationTypes: sortedRequests.map((r) => r.operation),\n operationDetails: sortedRequests.map((r, i) => ({\n index: i,\n operation: r.operation,\n dimension: r.dimension,\n startIndex: r.startIndex,\n endIndex: r.endIndex,\n affectedCount: calculateAffectedCount(r),\n })),\n currentDimensions: { rows: currentRowCount, columns: currentColumnCount },\n });\n\n // Execute the atomic batch update\n const batchUpdateResponse = await sheets.spreadsheets.batchUpdate({\n spreadsheetId: id,\n requestBody: {\n requests: batchRequests,\n includeSpreadsheetInResponse: false, // We don't need the full spreadsheet data back\n },\n });\n\n const updateResult = batchUpdateResponse.data;\n\n // Comprehensive validation of batch update results\n if (!updateResult) {\n logger.error?.('Dimensions batch update failed - no response data', {\n spreadsheetId: id,\n sheetTitle,\n requestCount: requests.length,\n });\n throw new McpError(ErrorCode.InternalError, 'Batch update failed: no response data received from Google Sheets API');\n }\n\n const replies = updateResult.replies || [];\n const expectedCount = requests.length;\n const actualCount = replies.length;\n\n // Validate operation count matches expectations\n if (actualCount !== expectedCount) {\n logger.error?.('Dimensions batch update failed - operation count mismatch', {\n expectedOperations: expectedCount,\n actualReplies: actualCount,\n spreadsheetId: id,\n sheetTitle,\n receivedReplies: replies.map((reply, index) => ({\n index,\n replyType: Object.keys(reply || {})[0] || 'empty',\n })),\n });\n\n throw new McpError(ErrorCode.InternalError, `Batch operation failed: expected ${expectedCount} operations, received ${actualCount} replies. This may indicate a partial failure or Google API issue.`);\n }\n\n // Validate each reply exists - Google Sheets API may return empty objects for successful operations\n for (let i = 0; i < replies.length; i++) {\n const reply = replies[i];\n const request = sortedRequests[i];\n\n if (!request) {\n logger.error?.('Dimensions batch update failed - missing request', {\n replyIndex: i,\n hasReply: !!reply,\n hasRequest: !!request,\n spreadsheetId: id,\n sheetTitle,\n });\n throw new McpError(ErrorCode.InternalError, `Operation ${i} failed: missing request data`);\n }\n\n // Note: Google Sheets API often returns empty objects {} for successful dimension operations\n // This is normal behavior and indicates success, not failure\n // We validate that the reply exists (even if empty) rather than checking specific keys\n if (reply === null || reply === undefined) {\n logger.error?.('Dimensions batch update failed - null reply', {\n operationIndex: i,\n expectedOperation: request.operation,\n spreadsheetId: id,\n sheetTitle,\n });\n throw new McpError(ErrorCode.InternalError, `Operation ${i} (${request.operation}) failed: null reply from Google Sheets API`);\n }\n }\n\n // Calculate final dimensions and operation results\n // Note: We calculate based on the operations we performed, but actual dimensions\n // may vary slightly due to Google Sheets internal behavior (e.g., minimum dimensions)\n let finalRowCount = currentRowCount;\n let finalColumnCount = currentColumnCount;\n\n const operationResults = sortedRequests.map((operation, _index) => {\n const affectedCount = calculateAffectedCount(operation);\n\n // Update dimension counts based on operation\n // Operations are applied in sorted order, so this should match actual result\n if (operation.dimension === 'ROWS') {\n if (operation.operation === 'insertDimension') {\n finalRowCount += affectedCount;\n } else if (operation.operation === 'appendDimension') {\n finalRowCount += affectedCount;\n } else if (operation.operation === 'deleteDimension') {\n finalRowCount = Math.max(1, finalRowCount - affectedCount); // Google Sheets minimum 1 row\n }\n } else if (operation.dimension === 'COLUMNS') {\n if (operation.operation === 'insertDimension') {\n finalColumnCount += affectedCount;\n } else if (operation.operation === 'appendDimension') {\n finalColumnCount += affectedCount;\n } else if (operation.operation === 'deleteDimension') {\n finalColumnCount = Math.max(1, finalColumnCount - affectedCount); // Google Sheets minimum 1 column\n }\n }\n\n return {\n operation: operation.operation,\n dimension: operation.dimension,\n startIndex: operation.startIndex,\n endIndex: operation.endIndex,\n affectedCount,\n };\n });\n\n // Validate final dimensions are within Google Sheets limits\n if (finalRowCount > MAX_ROW_COUNT) {\n logger.warn?.('Final row count exceeds Google Sheets maximum', {\n finalRowCount,\n maxRowCount: MAX_ROW_COUNT,\n spreadsheetId: id,\n sheetTitle,\n });\n }\n if (finalColumnCount > MAX_COLUMN_COUNT) {\n logger.warn?.('Final column count exceeds Google Sheets maximum', {\n finalColumnCount,\n maxColumnCount: MAX_COLUMN_COUNT,\n spreadsheetId: id,\n sheetTitle,\n });\n }\n\n logger.debug?.('sheets.dimensions.batchUpdate completed successfully', {\n totalOperations: requests.length,\n finalRowCount,\n finalColumnCount,\n operationResults: operationResults.length,\n });\n\n const result: Output = {\n type: 'success' as const,\n id,\n gid: String(sheetId),\n spreadsheetTitle: spreadsheetTitle || '',\n spreadsheetUrl: spreadsheetUrl || '',\n sheetTitle,\n sheetUrl,\n totalOperations: requests.length,\n operationResults,\n updatedDimensions: {\n rows: finalRowCount,\n columns: finalColumnCount,\n },\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.dimensions.batchUpdate error', { error: message });\n throw new McpError(ErrorCode.InternalError, `Error batch updating dimensions: ${message}`, {\n stack: error instanceof Error ? error.stack : undefined,\n });\n }\n}\n\nexport default function createTool() {\n return {\n name: 'dimensions-batch-update',\n config,\n handler,\n } satisfies ToolModule;\n}\n"],"names":["schemas","AuthRequiredBranchSchema","ErrorCode","McpError","google","z","SheetGidOutput","SheetGidSchema","SpreadsheetIdOutput","SpreadsheetIdSchema","buildDimensionRequest","calculateAffectedCount","DEFAULT_COLUMN_COUNT","DEFAULT_ROW_COUNT","MAX_COLUMN_COUNT","MAX_ROW_COUNT","sortOperations","DimensionRequestSchema","object","operation","enum","describe","dimension","startIndex","number","int","nonnegative","endIndex","optional","inheritFromBefore","boolean","inputSchema","id","gid","requests","array","min","successBranchSchema","type","literal","spreadsheetTitle","string","spreadsheetUrl","sheetTitle","sheetUrl","totalOperations","operationResults","affectedCount","updatedDimensions","rows","columns","outputSchema","discriminatedUnion","config","description","result","handler","extra","logger","debug","requestCount","length","operations","map","r","spreadsheetData","sheet","sheets","version","auth","authContext","spreadsheetResponse","spreadsheets","get","spreadsheetId","fields","data","properties","title","find","s","String","sheetId","warn","InvalidParams","undefined","error","InternalError","currentRowCount","gridProperties","rowCount","currentColumnCount","columnCount","sortedRequests","batchRequests","operationTypes","operationDetails","i","index","currentDimensions","batchUpdateResponse","batchUpdate","requestBody","includeSpreadsheetInResponse","updateResult","replies","expectedCount","actualCount","expectedOperations","actualReplies","receivedReplies","reply","replyType","Object","keys","request","replyIndex","hasReply","hasRequest","operationIndex","expectedOperation","finalRowCount","finalColumnCount","_index","Math","max","maxRowCount","maxColumnCount","content","text","JSON","stringify","structuredContent","message","Error","stack","createTool","name"],"mappings":"AACA,SAASA,OAAO,QAAQ,sBAAsB;AAE9C,MAAM,EAAEC,wBAAwB,EAAE,GAAGD;AAIrC,SAASE,SAAS,EAAEC,QAAQ,QAAQ,qCAAqC;AACzE,SAASC,MAAM,QAAQ,aAAa;AACpC,SAASC,CAAC,QAAQ,MAAM;AACxB,SAASC,cAAc,EAAEC,cAAc,EAAEC,mBAAmB,EAAEC,mBAAmB,QAAQ,yBAAyB;AAClH,SAASC,qBAAqB,EAAEC,sBAAsB,EAAEC,oBAAoB,EAAEC,iBAAiB,EAAyBC,gBAAgB,EAAEC,aAAa,EAAEC,cAAc,QAAQ,gCAAgC;AAE/M,mDAAmD;AACnD,MAAMC,yBAAyBZ,EAAEa,MAAM,CAAC;IACtCC,WAAWd,EAAEe,IAAI,CAAC;QAAC;QAAmB;QAAmB;KAAkB,EAAEC,QAAQ,CAAC;IACtFC,WAAWjB,EAAEe,IAAI,CAAC;QAAC;QAAQ;KAAU,EAAEC,QAAQ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AAEA,eAAe,SAASmD;IACtB,OAAO;QACLC,MAAM;QACNpF;QACAG;IACF;AACF"}
1
+ {"version":3,"sources":["/Users/kevin/Dev/OpenSource/ai/mcp-z/mcp-sheets/src/mcp/tools/dimensions-batch-update.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';\nimport { buildDimensionRequest, calculateAffectedCount, DEFAULT_COLUMN_COUNT, DEFAULT_ROW_COUNT, type DimensionRequest, MAX_COLUMN_COUNT, MAX_ROW_COUNT, sortOperations } from './lib/dimension-operations.ts';\n\n// Input schema for dimension batch update requests\nconst DimensionRequestSchema = z.object({\n operation: z.enum(['insertDimension', 'deleteDimension', 'appendDimension']).describe('Type of dimension operation to perform'),\n dimension: z.enum(['ROWS', 'COLUMNS']).describe('Whether to operate on rows or columns'),\n startIndex: z.number().int().nonnegative().describe('Starting index for the operation (0-based)'),\n endIndex: z.number().int().nonnegative().optional().describe('Ending index for the operation (0-based, exclusive). Optional - if omitted, the range is unbounded (extends to the end of the sheet)'),\n inheritFromBefore: z.boolean().optional().describe('For insertDimension: whether new rows/columns inherit properties from the row/column before the insertion point'),\n});\n\nconst inputSchema = z.object({\n id: SpreadsheetIdSchema,\n gid: SheetGidSchema,\n requests: z.array(DimensionRequestSchema).min(1).describe('Array of dimension update requests'),\n});\n\n// Success branch schema\nconst successBranchSchema = z.object({\n type: z.literal('success'),\n id: SpreadsheetIdOutput,\n gid: SheetGidOutput,\n spreadsheetTitle: z.string().describe('Title of the updated spreadsheet'),\n spreadsheetUrl: z.string().describe('URL of the updated spreadsheet'),\n sheetTitle: z.string().describe('Title of the updated sheet'),\n sheetUrl: z.string().describe('URL of the updated sheet'),\n totalOperations: z.number().int().nonnegative().describe('Total number of dimension operations performed'),\n operationResults: z\n .array(\n z.object({\n operation: z.enum(['insertDimension', 'deleteDimension', 'appendDimension']).describe('Type of operation that was performed'),\n dimension: z.enum(['ROWS', 'COLUMNS']).describe('Dimension that was operated on'),\n startIndex: z.number().int().nonnegative().describe('Starting index of the operation'),\n endIndex: z.number().int().nonnegative().optional().describe('Ending index of the operation (for insert/delete)'),\n affectedCount: z.number().int().nonnegative().describe('Number of rows/columns affected by this operation'),\n })\n )\n .describe('Detailed results for each dimension operation'),\n updatedDimensions: z\n .object({\n rows: z.number().int().nonnegative().describe('Total number of rows in the sheet after all operations'),\n columns: z.number().int().nonnegative().describe('Total number of columns in the sheet after all operations'),\n })\n .describe('Final dimensions of the sheet after all operations'),\n});\n\nconst outputSchema = z.discriminatedUnion('type', [successBranchSchema, AuthRequiredBranchSchema]);\n\nconst config = {\n description: 'Batch update sheet dimensions by inserting, deleting, or appending rows/columns. Operations are atomic (all succeed or all fail) and execute in optimal order automatically.',\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, requests }: Input, extra: EnrichedExtra): Promise<CallToolResult> {\n const logger = extra.logger;\n logger.debug?.('sheets.dimensions.batchUpdate called', {\n id,\n gid,\n requestCount: requests.length,\n operations: requests.map((r) => ({ operation: r.operation, dimension: r.dimension, startIndex: r.startIndex, endIndex: r.endIndex })),\n });\n\n try {\n const sheets = google.sheets({ version: 'v4', auth: extra.authContext.auth });\n\n // Get spreadsheet and sheet info in single API call\n const spreadsheetResponse = await sheets.spreadsheets.get({\n spreadsheetId: id,\n fields: 'properties.title,spreadsheetUrl,sheets.properties.sheetId,sheets.properties.title,sheets.properties.gridProperties',\n });\n\n const spreadsheetData = spreadsheetResponse.data;\n const spreadsheetTitle = spreadsheetData.properties?.title ?? '';\n const spreadsheetUrl = spreadsheetData.spreadsheetUrl ?? '';\n\n // Find sheet by gid\n const sheet = spreadsheetData.sheets?.find((s) => String(s.properties?.sheetId) === gid);\n if (!sheet?.properties) {\n logger.warn?.('Sheet not found for dimensions batch update', { id, gid, requestCount: requests.length });\n throw new ProtocolError(ProtocolErrorCode.InvalidParams, `Sheet not found: ${gid}`);\n }\n\n const sheetTitle = sheet.properties.title ?? gid;\n const sheetId = sheet.properties.sheetId;\n\n if (sheetId === undefined || sheetId === null) {\n logger.error?.('Sheet ID not available for dimensions batch update', { id, gid, sheetTitle });\n throw new ProtocolError(ProtocolErrorCode.InternalError, `Sheet ID not available for ${gid}. Cannot perform dimension operations without valid sheet ID.`);\n }\n\n const sheetUrl = `https://docs.google.com/spreadsheets/d/${id}/edit#gid=${sheetId}`;\n\n // Get current sheet dimensions for response calculation\n // Note: Google Sheets API may not always provide gridProperties for older sheets\n // Fall back to Google's documented defaults for new sheets\n const currentRowCount = sheet.properties.gridProperties?.rowCount ?? DEFAULT_ROW_COUNT;\n const currentColumnCount = sheet.properties.gridProperties?.columnCount ?? DEFAULT_COLUMN_COUNT;\n\n // Sort operations for optimal execution order to prevent index conflicts\n // Delete operations are processed first (high to low index) to avoid shifting issues\n // Insert/append operations are processed after (low to high index)\n const sortedRequests = sortOperations(requests as DimensionRequest[]);\n\n // Build Google Sheets API batch update requests\n const batchRequests = sortedRequests.map((operation) => buildDimensionRequest(operation, sheetId));\n\n logger.debug?.('sheets.dimensions.batchUpdate executing batch request', {\n spreadsheetId: id,\n sheetTitle,\n sheetId,\n totalOperations: batchRequests.length,\n operationTypes: sortedRequests.map((r) => r.operation),\n operationDetails: sortedRequests.map((r, i) => ({\n index: i,\n operation: r.operation,\n dimension: r.dimension,\n startIndex: r.startIndex,\n endIndex: r.endIndex,\n affectedCount: calculateAffectedCount(r),\n })),\n currentDimensions: { rows: currentRowCount, columns: currentColumnCount },\n });\n\n // Execute the atomic batch update\n const batchUpdateResponse = await sheets.spreadsheets.batchUpdate({\n spreadsheetId: id,\n requestBody: {\n requests: batchRequests,\n includeSpreadsheetInResponse: false, // We don't need the full spreadsheet data back\n },\n });\n\n const updateResult = batchUpdateResponse.data;\n\n // Comprehensive validation of batch update results\n if (!updateResult) {\n logger.error?.('Dimensions batch update failed - no response data', {\n spreadsheetId: id,\n sheetTitle,\n requestCount: requests.length,\n });\n throw new ProtocolError(ProtocolErrorCode.InternalError, 'Batch update failed: no response data received from Google Sheets API');\n }\n\n const replies = updateResult.replies || [];\n const expectedCount = requests.length;\n const actualCount = replies.length;\n\n // Validate operation count matches expectations\n if (actualCount !== expectedCount) {\n logger.error?.('Dimensions batch update failed - operation count mismatch', {\n expectedOperations: expectedCount,\n actualReplies: actualCount,\n spreadsheetId: id,\n sheetTitle,\n receivedReplies: replies.map((reply, index) => ({\n index,\n replyType: Object.keys(reply || {})[0] || 'empty',\n })),\n });\n\n throw new ProtocolError(ProtocolErrorCode.InternalError, `Batch operation failed: expected ${expectedCount} operations, received ${actualCount} replies. This may indicate a partial failure or Google API issue.`);\n }\n\n // Validate each reply exists - Google Sheets API may return empty objects for successful operations\n for (let i = 0; i < replies.length; i++) {\n const reply = replies[i];\n const request = sortedRequests[i];\n\n if (!request) {\n logger.error?.('Dimensions batch update failed - missing request', {\n replyIndex: i,\n hasReply: !!reply,\n hasRequest: !!request,\n spreadsheetId: id,\n sheetTitle,\n });\n throw new ProtocolError(ProtocolErrorCode.InternalError, `Operation ${i} failed: missing request data`);\n }\n\n // Note: Google Sheets API often returns empty objects {} for successful dimension operations\n // This is normal behavior and indicates success, not failure\n // We validate that the reply exists (even if empty) rather than checking specific keys\n if (reply === null || reply === undefined) {\n logger.error?.('Dimensions batch update failed - null reply', {\n operationIndex: i,\n expectedOperation: request.operation,\n spreadsheetId: id,\n sheetTitle,\n });\n throw new ProtocolError(ProtocolErrorCode.InternalError, `Operation ${i} (${request.operation}) failed: null reply from Google Sheets API`);\n }\n }\n\n // Calculate final dimensions and operation results\n // Note: We calculate based on the operations we performed, but actual dimensions\n // may vary slightly due to Google Sheets internal behavior (e.g., minimum dimensions)\n let finalRowCount = currentRowCount;\n let finalColumnCount = currentColumnCount;\n\n const operationResults = sortedRequests.map((operation, _index) => {\n const affectedCount = calculateAffectedCount(operation);\n\n // Update dimension counts based on operation\n // Operations are applied in sorted order, so this should match actual result\n if (operation.dimension === 'ROWS') {\n if (operation.operation === 'insertDimension') {\n finalRowCount += affectedCount;\n } else if (operation.operation === 'appendDimension') {\n finalRowCount += affectedCount;\n } else if (operation.operation === 'deleteDimension') {\n finalRowCount = Math.max(1, finalRowCount - affectedCount); // Google Sheets minimum 1 row\n }\n } else if (operation.dimension === 'COLUMNS') {\n if (operation.operation === 'insertDimension') {\n finalColumnCount += affectedCount;\n } else if (operation.operation === 'appendDimension') {\n finalColumnCount += affectedCount;\n } else if (operation.operation === 'deleteDimension') {\n finalColumnCount = Math.max(1, finalColumnCount - affectedCount); // Google Sheets minimum 1 column\n }\n }\n\n return {\n operation: operation.operation,\n dimension: operation.dimension,\n startIndex: operation.startIndex,\n endIndex: operation.endIndex,\n affectedCount,\n };\n });\n\n // Validate final dimensions are within Google Sheets limits\n if (finalRowCount > MAX_ROW_COUNT) {\n logger.warn?.('Final row count exceeds Google Sheets maximum', {\n finalRowCount,\n maxRowCount: MAX_ROW_COUNT,\n spreadsheetId: id,\n sheetTitle,\n });\n }\n if (finalColumnCount > MAX_COLUMN_COUNT) {\n logger.warn?.('Final column count exceeds Google Sheets maximum', {\n finalColumnCount,\n maxColumnCount: MAX_COLUMN_COUNT,\n spreadsheetId: id,\n sheetTitle,\n });\n }\n\n logger.debug?.('sheets.dimensions.batchUpdate completed successfully', {\n totalOperations: requests.length,\n finalRowCount,\n finalColumnCount,\n operationResults: operationResults.length,\n });\n\n const result: Output = {\n type: 'success' as const,\n id,\n gid: String(sheetId),\n spreadsheetTitle: spreadsheetTitle || '',\n spreadsheetUrl: spreadsheetUrl || '',\n sheetTitle,\n sheetUrl,\n totalOperations: requests.length,\n operationResults,\n updatedDimensions: {\n rows: finalRowCount,\n columns: finalColumnCount,\n },\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.dimensions.batchUpdate error', { error: message });\n throw new ProtocolError(ProtocolErrorCode.InternalError, `Error batch updating dimensions: ${message}`, {\n stack: error instanceof Error ? error.stack : undefined,\n });\n }\n}\n\nexport default function createTool() {\n return {\n name: 'dimensions-batch-update',\n config,\n handler,\n } satisfies ToolModule;\n}\n"],"names":["schemas","AuthRequiredBranchSchema","ProtocolError","ProtocolErrorCode","google","z","SheetGidOutput","SheetGidSchema","SpreadsheetIdOutput","SpreadsheetIdSchema","buildDimensionRequest","calculateAffectedCount","DEFAULT_COLUMN_COUNT","DEFAULT_ROW_COUNT","MAX_COLUMN_COUNT","MAX_ROW_COUNT","sortOperations","DimensionRequestSchema","object","operation","enum","describe","dimension","startIndex","number","int","nonnegative","endIndex","optional","inheritFromBefore","boolean","inputSchema","id","gid","requests","array","min","successBranchSchema","type","literal","spreadsheetTitle","string","spreadsheetUrl","sheetTitle","sheetUrl","totalOperations","operationResults","affectedCount","updatedDimensions","rows","columns","outputSchema","discriminatedUnion","config","description","result","handler","extra","logger","debug","requestCount","length","operations","map","r","spreadsheetData","sheet","sheets","version","auth","authContext","spreadsheetResponse","spreadsheets","get","spreadsheetId","fields","data","properties","title","find","s","String","sheetId","warn","InvalidParams","undefined","error","InternalError","currentRowCount","gridProperties","rowCount","currentColumnCount","columnCount","sortedRequests","batchRequests","operationTypes","operationDetails","i","index","currentDimensions","batchUpdateResponse","batchUpdate","requestBody","includeSpreadsheetInResponse","updateResult","replies","expectedCount","actualCount","expectedOperations","actualReplies","receivedReplies","reply","replyType","Object","keys","request","replyIndex","hasReply","hasRequest","operationIndex","expectedOperation","finalRowCount","finalColumnCount","_index","Math","max","maxRowCount","max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AC,KAAKgD,OAAOC;YACZ1C,kBAAkBA,oBAAoB;YACtCE,gBAAgBA,kBAAkB;YAClCC;YACAC;YACAC,iBAAiBX,SAAS2B,MAAM;YAChCf;YACAE,mBAAmB;gBACjBC,MAAMwE;gBACNvE,SAASwE;YACX;QACF;QAEA,OAAO;YACLM,SAAS;gBAAC;oBAAE1F,MAAM;oBAAiB2F,MAAMC,KAAKC,SAAS,CAAC5E;gBAAQ;aAAE;YAClE6E,mBAAmB;gBAAE7E;YAAO;QAC9B;IACF,EAAE,OAAO+B,OAAO;YAEd5B;QADA,MAAM2E,UAAU/C,iBAAiBgD,QAAQhD,MAAM+C,OAAO,GAAGpD,OAAOK;SAChE5B,iBAAAA,OAAO4B,KAAK,cAAZ5B,qCAAAA,oBAAAA,QAAe,uCAAuC;YAAE4B,OAAO+C;QAAQ;QACvE,MAAM,IAAInI,cAAcC,kBAAkBoF,aAAa,EAAE,CAAC,iCAAiC,EAAE8C,SAAS,EAAE;YACtGE,OAAOjD,iBAAiBgD,QAAQhD,MAAMiD,KAAK,GAAGlD;QAChD;IACF;AACF;AAEA,eAAe,SAASmD;IACtB,OAAO;QACLC,MAAM;QACNpF;QACAG;IACF;AACF"}
@@ -1,5 +1,5 @@
1
1
  import type { EnrichedExtra } from '@mcp-z/oauth-google';
2
- import type { CallToolResult } from '@modelcontextprotocol/sdk/types.js';
2
+ import type { CallToolResult } from '@mcp-z/server';
3
3
  import { z } from 'zod';
4
4
  declare const inputSchema: z.ZodObject<{
5
5
  id: z.ZodString;
@@ -1,6 +1,6 @@
1
1
  import { schemas } from '@mcp-z/oauth-google';
2
2
  const { AuthRequiredBranchSchema } = schemas;
3
- import { ErrorCode, McpError } from '@modelcontextprotocol/sdk/types.js';
3
+ import { ProtocolError, ProtocolErrorCode } from '@mcp-z/server';
4
4
  import { google } from 'googleapis';
5
5
  import { z } from 'zod';
6
6
  import { SheetGidOutput, SheetGidSchema, SpreadsheetIdOutput, SpreadsheetIdSchema } from '../../schemas/index.js';
@@ -57,11 +57,11 @@ async function handler({ id, gid, dimension, startIndex, endIndex, destinationIn
57
57
  });
58
58
  // Validate indices
59
59
  if (startIndex >= endIndex) {
60
- throw new McpError(ErrorCode.InvalidParams, `startIndex (${startIndex}) must be less than endIndex (${endIndex})`);
60
+ throw new ProtocolError(ProtocolErrorCode.InvalidParams, `startIndex (${startIndex}) must be less than endIndex (${endIndex})`);
61
61
  }
62
62
  // Check if destination is within source range (invalid move)
63
63
  if (destinationIndex > startIndex && destinationIndex < endIndex) {
64
- throw new McpError(ErrorCode.InvalidParams, `destinationIndex (${destinationIndex}) cannot be within the source range (${startIndex}-${endIndex})`);
64
+ throw new ProtocolError(ProtocolErrorCode.InvalidParams, `destinationIndex (${destinationIndex}) cannot be within the source range (${startIndex}-${endIndex})`);
65
65
  }
66
66
  try {
67
67
  var _ref, _spreadsheetData_spreadsheetUrl, _sheet_properties_title, _sheet_properties_sheetId;
@@ -89,7 +89,7 @@ async function handler({ id, gid, dimension, startIndex, endIndex, destinationIn
89
89
  gid,
90
90
  dimension
91
91
  });
92
- throw new McpError(ErrorCode.InvalidParams, `Sheet not found: ${gid}`);
92
+ throw new ProtocolError(ProtocolErrorCode.InvalidParams, `Sheet not found: ${gid}`);
93
93
  }
94
94
  const sheetTitle = (_sheet_properties_title = sheet.properties.title) !== null && _sheet_properties_title !== void 0 ? _sheet_properties_title : gid;
95
95
  const sheetGid = (_sheet_properties_sheetId = sheet.properties.sheetId) !== null && _sheet_properties_sheetId !== void 0 ? _sheet_properties_sheetId : 0;
@@ -156,7 +156,7 @@ async function handler({ id, gid, dimension, startIndex, endIndex, destinationIn
156
156
  }
157
157
  };
158
158
  } catch (error) {
159
- if (error instanceof McpError) {
159
+ if (error instanceof ProtocolError) {
160
160
  throw error;
161
161
  }
162
162
  const message = error instanceof Error ? error.message : String(error);
@@ -169,7 +169,7 @@ async function handler({ id, gid, dimension, startIndex, endIndex, destinationIn
169
169
  destinationIndex,
170
170
  error: message
171
171
  });
172
- throw new McpError(ErrorCode.InternalError, `Error moving ${dimension.toLowerCase()}: ${message}`, {
172
+ throw new ProtocolError(ProtocolErrorCode.InternalError, `Error moving ${dimension.toLowerCase()}: ${message}`, {
173
173
  stack: error instanceof Error ? error.stack : undefined
174
174
  });
175
175
  }
@@ -1 +1 @@
1
- {"version":3,"sources":["/Users/kevin/Dev/OpenSource/ai/mcp-z/mcp-sheets/src/mcp/tools/dimensions-move.ts"],"sourcesContent":["import type { EnrichedExtra } from '@mcp-z/oauth-google';\nimport { schemas } from '@mcp-z/oauth-google';\n\nconst { AuthRequiredBranchSchema } = schemas;\n\nimport type { ToolModule } from '@mcp-z/server';\nimport type { CallToolResult } from '@modelcontextprotocol/sdk/types.js';\nimport { ErrorCode, McpError } from '@modelcontextprotocol/sdk/types.js';\nimport { google } from 'googleapis';\nimport { z } from 'zod';\nimport { SheetGidOutput, SheetGidSchema, SpreadsheetIdOutput, SpreadsheetIdSchema } from '../../schemas/index.ts';\n\nconst inputSchema = z.object({\n id: SpreadsheetIdSchema,\n gid: SheetGidSchema,\n dimension: z.enum(['ROWS', 'COLUMNS']).describe('Whether to move rows or columns'),\n startIndex: z.number().int().nonnegative().describe('Starting index of the range to move (0-based)'),\n endIndex: z.number().int().positive().describe('Ending index of the range to move (0-based, exclusive)'),\n destinationIndex: z.number().int().nonnegative().describe('Index where the rows/columns will be moved to (0-based)'),\n});\n\nconst successBranchSchema = z.object({\n type: z.literal('success'),\n id: SpreadsheetIdOutput,\n gid: SheetGidOutput,\n spreadsheetTitle: z.string().describe('Title of the spreadsheet'),\n spreadsheetUrl: z.string().describe('URL of the spreadsheet'),\n sheetTitle: z.string().describe('Title of the sheet'),\n sheetUrl: z.string().describe('URL of the sheet'),\n dimension: z.enum(['ROWS', 'COLUMNS']).describe('Dimension that was moved'),\n sourceRange: z.object({\n startIndex: z.number().describe('Starting index of the moved range'),\n endIndex: z.number().describe('Ending index of the moved range'),\n }),\n destinationIndex: z.number().describe('Index where the range was moved to'),\n movedCount: z.number().describe('Number of rows/columns moved'),\n});\n\nconst outputSchema = z.discriminatedUnion('type', [successBranchSchema, AuthRequiredBranchSchema]);\n\nconst config = {\n description: 'Move rows or columns within a sheet to a new position. Use 0-based indices. The destinationIndex is where the rows/columns will be moved TO.',\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, dimension, startIndex, endIndex, destinationIndex }: Input, extra: EnrichedExtra): Promise<CallToolResult> {\n const logger = extra.logger;\n logger.info('sheets.dimensions.move called', { id, gid, dimension, startIndex, endIndex, destinationIndex });\n\n // Validate indices\n if (startIndex >= endIndex) {\n throw new McpError(ErrorCode.InvalidParams, `startIndex (${startIndex}) must be less than endIndex (${endIndex})`);\n }\n\n // Check if destination is within source range (invalid move)\n if (destinationIndex > startIndex && destinationIndex < endIndex) {\n throw new McpError(ErrorCode.InvalidParams, `destinationIndex (${destinationIndex}) cannot be within the source range (${startIndex}-${endIndex})`);\n }\n\n try {\n const sheets = google.sheets({ version: 'v4', auth: extra.authContext.auth });\n\n // Get spreadsheet and sheet info in single API call\n const spreadsheetResponse = await sheets.spreadsheets.get({\n spreadsheetId: id,\n fields: 'properties.title,spreadsheetUrl,sheets.properties.sheetId,sheets.properties.title',\n });\n\n const spreadsheetData = spreadsheetResponse.data;\n const spreadsheetTitle = spreadsheetData.properties?.title ?? '';\n const spreadsheetUrl = spreadsheetData.spreadsheetUrl ?? '';\n\n // Find sheet by gid\n const sheet = spreadsheetData.sheets?.find((s) => String(s.properties?.sheetId) === gid);\n if (!sheet?.properties) {\n logger.info('Sheet not found for move', { id, gid, dimension });\n throw new McpError(ErrorCode.InvalidParams, `Sheet not found: ${gid}`);\n }\n\n const sheetTitle = sheet.properties.title ?? gid;\n const sheetGid = sheet.properties.sheetId ?? 0;\n const sheetUrl = `https://docs.google.com/spreadsheets/d/${id}/edit#gid=${sheetGid}`;\n\n logger.info('sheets.dimensions.move executing', { spreadsheetId: id, sheetTitle, dimension, startIndex, endIndex, destinationIndex });\n\n // Execute the move dimension request\n await sheets.spreadsheets.batchUpdate({\n spreadsheetId: id,\n requestBody: {\n requests: [\n {\n moveDimension: {\n source: {\n sheetId: sheetGid,\n dimension,\n startIndex,\n endIndex,\n },\n destinationIndex,\n },\n },\n ],\n },\n });\n\n const movedCount = endIndex - startIndex;\n\n logger.info('sheets.dimensions.move completed successfully', {\n spreadsheetId: id,\n sheetTitle,\n dimension,\n movedCount,\n });\n\n const result: Output = {\n type: 'success' as const,\n id,\n gid: String(sheetGid),\n spreadsheetTitle: spreadsheetTitle || '',\n spreadsheetUrl: spreadsheetUrl || '',\n sheetTitle,\n sheetUrl,\n dimension,\n sourceRange: {\n startIndex,\n endIndex,\n },\n destinationIndex,\n movedCount,\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 McpError) {\n throw error;\n }\n const message = error instanceof Error ? error.message : String(error);\n logger.error('Move operation failed', { id, gid, dimension, startIndex, endIndex, destinationIndex, error: message });\n\n throw new McpError(ErrorCode.InternalError, `Error moving ${dimension.toLowerCase()}: ${message}`, {\n stack: error instanceof Error ? error.stack : undefined,\n });\n }\n}\n\nexport default function createTool() {\n return {\n name: 'dimensions-move',\n config,\n handler,\n } satisfies ToolModule;\n}\n"],"names":["schemas","AuthRequiredBranchSchema","ErrorCode","McpError","google","z","SheetGidOutput","SheetGidSchema","SpreadsheetIdOutput","SpreadsheetIdSchema","inputSchema","object","id","gid","dimension","enum","describe","startIndex","number","int","nonnegative","endIndex","positive","destinationIndex","successBranchSchema","type","literal","spreadsheetTitle","string","spreadsheetUrl","sheetTitle","sheetUrl","sourceRange","movedCount","outputSchema","discriminatedUnion","config","description","result","handler","extra","logger","info","InvalidParams","spreadsheetData","sheet","sheets","version","auth","authContext","spreadsheetResponse","spreadsheets","get","spreadsheetId","fields","data","properties","title","find","s","String","sheetId","sheetGid","batchUpdate","requestBody","requests","moveDimension","source","content","text","JSON","stringify","structuredContent","error","message","Error","InternalError","toLowerCase","stack","undefined","createTool","name"],"mappings":"AACA,SAASA,OAAO,QAAQ,sBAAsB;AAE9C,MAAM,EAAEC,wBAAwB,EAAE,GAAGD;AAIrC,SAASE,SAAS,EAAEC,QAAQ,QAAQ,qCAAqC;AACzE,SAASC,MAAM,QAAQ,aAAa;AACpC,SAASC,CAAC,QAAQ,MAAM;AACxB,SAASC,cAAc,EAAEC,cAAc,EAAEC,mBAAmB,EAAEC,mBAAmB,QAAQ,yBAAyB;AAElH,MAAMC,cAAcL,EAAEM,MAAM,CAAC;IAC3BC,IAAIH;IACJI,KAAKN;IACLO,WAAWT,EAAEU,IAAI,CAAC;QAAC;QAAQ;KAAU,EAAEC,QAAQ,CAAC;IAChDC,YAAYZ,EAAEa,MAAM,GAAGC,GAAG,GAAGC,WAAW,GAAGJ,QAAQ,CAAC;IACpDK,UAAUhB,EAAEa,MAAM,GAAGC,GAAG,GAAGG,QAAQ,GAAGN,QAAQ,CAAC;IAC/CO,kBAAkBlB,EAAEa,MAAM,GAAGC,GAAG,GAAGC,WAAW,GAAGJ,QAAQ,CAAC;AAC5D;AAEA,MAAMQ,sBAAsBnB,EAAEM,MAAM,CAAC;IACnCc,MAAMpB,EAAEqB,OAAO,CAAC;IAChBd,IAAIJ;IACJK,KAAKP;IACLqB,kBAAkBtB,EAAEuB,MAAM,GAAGZ,QAAQ,CAAC;IACtCa,gBAAgBxB,EAAEuB,MAAM,GAAGZ,QAAQ,CAAC;IACpCc,YAAYzB,EAAEuB,MAAM,GAAGZ,QAAQ,CAAC;IAChCe,UAAU1B,EAAEuB,MAAM,GAAGZ,QAAQ,CAAC;IAC9BF,WAAWT,EAAEU,IAAI,CAAC;QAAC;QAAQ;KAAU,EAAEC,QAAQ,CAAC;IAChDgB,aAAa3B,EAAEM,MAAM,CAAC;QACpBM,YAAYZ,EAAEa,MAAM,GAAGF,QAAQ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F;QAEA,MAAMK,SAAiB;YACrBb,MAAM;YACNb;YACAC,KAAK+C,OAAOE;YACZnC,kBAAkBA,oBAAoB;YACtCE,gBAAgBA,kBAAkB;YAClCC;YACAC;YACAjB;YACAkB,aAAa;gBACXf;gBACAI;YACF;YACAE;YACAU;QACF;QAEA,OAAO;YACLmC,SAAS;gBAAC;oBAAE3C,MAAM;oBAAiB4C,MAAMC,KAAKC,SAAS,CAACjC;gBAAQ;aAAE;YAClEkC,mBAAmB;gBAAElC;YAAO;QAC9B;IACF,EAAE,OAAOmC,OAAO;QACd,IAAIA,iBAAiBtE,UAAU;YAC7B,MAAMsE;QACR;QACA,MAAMC,UAAUD,iBAAiBE,QAAQF,MAAMC,OAAO,GAAGd,OAAOa;QAChEhC,OAAOgC,KAAK,CAAC,yBAAyB;YAAE7D;YAAIC;YAAKC;YAAWG;YAAYI;YAAUE;YAAkBkD,OAAOC;QAAQ;QAEnH,MAAM,IAAIvE,SAASD,UAAU0E,aAAa,EAAE,CAAC,aAAa,EAAE9D,UAAU+D,WAAW,GAAG,EAAE,EAAEH,SAAS,EAAE;YACjGI,OAAOL,iBAAiBE,QAAQF,MAAMK,KAAK,GAAGC;QAChD;IACF;AACF;AAEA,eAAe,SAASC;IACtB,OAAO;QACLC,MAAM;QACN7C;QACAG;IACF;AACF"}
1
+ {"version":3,"sources":["/Users/kevin/Dev/OpenSource/ai/mcp-z/mcp-sheets/src/mcp/tools/dimensions-move.ts"],"sourcesContent":["import type { EnrichedExtra } from '@mcp-z/oauth-google';\nimport { schemas } from '@mcp-z/oauth-google';\n\nconst { AuthRequiredBranchSchema } = schemas;\n\nimport type { CallToolResult, 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 dimension: z.enum(['ROWS', 'COLUMNS']).describe('Whether to move rows or columns'),\n startIndex: z.number().int().nonnegative().describe('Starting index of the range to move (0-based)'),\n endIndex: z.number().int().positive().describe('Ending index of the range to move (0-based, exclusive)'),\n destinationIndex: z.number().int().nonnegative().describe('Index where the rows/columns will be moved to (0-based)'),\n});\n\nconst successBranchSchema = z.object({\n type: z.literal('success'),\n id: SpreadsheetIdOutput,\n gid: SheetGidOutput,\n spreadsheetTitle: z.string().describe('Title of the spreadsheet'),\n spreadsheetUrl: z.string().describe('URL of the spreadsheet'),\n sheetTitle: z.string().describe('Title of the sheet'),\n sheetUrl: z.string().describe('URL of the sheet'),\n dimension: z.enum(['ROWS', 'COLUMNS']).describe('Dimension that was moved'),\n sourceRange: z.object({\n startIndex: z.number().describe('Starting index of the moved range'),\n endIndex: z.number().describe('Ending index of the moved range'),\n }),\n destinationIndex: z.number().describe('Index where the range was moved to'),\n movedCount: z.number().describe('Number of rows/columns moved'),\n});\n\nconst outputSchema = z.discriminatedUnion('type', [successBranchSchema, AuthRequiredBranchSchema]);\n\nconst config = {\n description: 'Move rows or columns within a sheet to a new position. Use 0-based indices. The destinationIndex is where the rows/columns will be moved TO.',\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, dimension, startIndex, endIndex, destinationIndex }: Input, extra: EnrichedExtra): Promise<CallToolResult> {\n const logger = extra.logger;\n logger.info('sheets.dimensions.move called', { id, gid, dimension, startIndex, endIndex, destinationIndex });\n\n // Validate indices\n if (startIndex >= endIndex) {\n throw new ProtocolError(ProtocolErrorCode.InvalidParams, `startIndex (${startIndex}) must be less than endIndex (${endIndex})`);\n }\n\n // Check if destination is within source range (invalid move)\n if (destinationIndex > startIndex && destinationIndex < endIndex) {\n throw new ProtocolError(ProtocolErrorCode.InvalidParams, `destinationIndex (${destinationIndex}) cannot be within the source range (${startIndex}-${endIndex})`);\n }\n\n try {\n const sheets = google.sheets({ version: 'v4', auth: extra.authContext.auth });\n\n // Get spreadsheet and sheet info in single API call\n const spreadsheetResponse = await sheets.spreadsheets.get({\n spreadsheetId: id,\n fields: 'properties.title,spreadsheetUrl,sheets.properties.sheetId,sheets.properties.title',\n });\n\n const spreadsheetData = spreadsheetResponse.data;\n const spreadsheetTitle = spreadsheetData.properties?.title ?? '';\n const spreadsheetUrl = spreadsheetData.spreadsheetUrl ?? '';\n\n // Find sheet by gid\n const sheet = spreadsheetData.sheets?.find((s) => String(s.properties?.sheetId) === gid);\n if (!sheet?.properties) {\n logger.info('Sheet not found for move', { id, gid, dimension });\n throw new ProtocolError(ProtocolErrorCode.InvalidParams, `Sheet not found: ${gid}`);\n }\n\n const sheetTitle = sheet.properties.title ?? gid;\n const sheetGid = sheet.properties.sheetId ?? 0;\n const sheetUrl = `https://docs.google.com/spreadsheets/d/${id}/edit#gid=${sheetGid}`;\n\n logger.info('sheets.dimensions.move executing', { spreadsheetId: id, sheetTitle, dimension, startIndex, endIndex, destinationIndex });\n\n // Execute the move dimension request\n await sheets.spreadsheets.batchUpdate({\n spreadsheetId: id,\n requestBody: {\n requests: [\n {\n moveDimension: {\n source: {\n sheetId: sheetGid,\n dimension,\n startIndex,\n endIndex,\n },\n destinationIndex,\n },\n },\n ],\n },\n });\n\n const movedCount = endIndex - startIndex;\n\n logger.info('sheets.dimensions.move completed successfully', {\n spreadsheetId: id,\n sheetTitle,\n dimension,\n movedCount,\n });\n\n const result: Output = {\n type: 'success' as const,\n id,\n gid: String(sheetGid),\n spreadsheetTitle: spreadsheetTitle || '',\n spreadsheetUrl: spreadsheetUrl || '',\n sheetTitle,\n sheetUrl,\n dimension,\n sourceRange: {\n startIndex,\n endIndex,\n },\n destinationIndex,\n movedCount,\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('Move operation failed', { id, gid, dimension, startIndex, endIndex, destinationIndex, error: message });\n\n throw new ProtocolError(ProtocolErrorCode.InternalError, `Error moving ${dimension.toLowerCase()}: ${message}`, {\n stack: error instanceof Error ? error.stack : undefined,\n });\n }\n}\n\nexport default function createTool() {\n return {\n name: 'dimensions-move',\n config,\n handler,\n } satisfies ToolModule;\n}\n"],"names":["schemas","AuthRequiredBranchSchema","ProtocolError","ProtocolErrorCode","google","z","SheetGidOutput","SheetGidSchema","SpreadsheetIdOutput","SpreadsheetIdSchema","inputSchema","object","id","gid","dimension","enum","describe","startIndex","number","int","nonnegative","endIndex","positive","destinationIndex","successBranchSchema","type","literal","spreadsheetTitle","string","spreadsheetUrl","sheetTitle","sheetUrl","sourceRange","movedCount","outputSchema","discriminatedUnion","config","description","result","handler","extra","logger","info","InvalidParams","spreadsheetData","sheet","sheets","version","auth","authContext","spreadsheetResponse","spreadsheets","get","spreadsheetId","fields","data","properties","title","find","s","String","sheetId","sheetGid","batchUpdate","requestBody","requests","moveDimension","source","content","text","JSON","stringify","structuredContent","error","message","Error","InternalError","toLowerCase","stack","undefined","createTool","name"],"mappings":"AACA,SAASA,OAAO,QAAQ,sBAAsB;AAE9C,MAAM,EAAEC,wBAAwB,EAAE,GAAGD;AAGrC,SAASE,aAAa,EAAEC,iBAAiB,QAAQ,gBAAgB;AACjE,SAASC,MAAM,QAAQ,aAAa;AACpC,SAASC,CAAC,QAAQ,MAAM;AACxB,SAASC,cAAc,EAAEC,cAAc,EAAEC,mBAAmB,EAAEC,mBAAmB,QAAQ,yBAAyB;AAElH,MAAMC,cAAcL,EAAEM,MAAM,CAAC;IAC3BC,IAAIH;IACJI,KAAKN;IACLO,WAAWT,EAAEU,IAAI,CAAC;QAAC;QAAQ;KAAU,EAAEC,QAAQ,CAAC;IAChDC,YAAYZ,EAAEa,MAAM,GAAGC,GAAG,GAAGC,WAAW,GAAGJ,QAAQ,CAA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AIxE,cAAcC,kBAAkByE,aAAa,EAAE,CAAC,aAAa,EAAE9D,UAAU+D,WAAW,GAAG,EAAE,EAAEH,SAAS,EAAE;YAC9GI,OAAOL,iBAAiBE,QAAQF,MAAMK,KAAK,GAAGC;QAChD;IACF;AACF;AAEA,eAAe,SAASC;IACtB,OAAO;QACLC,MAAM;QACN7C;QACAG;IACF;AACF"}
@@ -1,5 +1,5 @@
1
1
  import type { EnrichedExtra } from '@mcp-z/oauth-google';
2
- import type { CallToolResult } from '@modelcontextprotocol/sdk/types.js';
2
+ import type { CallToolResult } from '@mcp-z/server';
3
3
  import { z } from 'zod';
4
4
  declare const inputSchema: z.ZodObject<{
5
5
  id: z.ZodString;