@mcp-z/mcp-sheets 1.0.0 → 1.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (150) hide show
  1. package/README.md +32 -3
  2. package/bin/server.js +1 -1
  3. package/dist/cjs/constants.js.map +1 -1
  4. package/dist/cjs/index.js +13 -13
  5. package/dist/cjs/index.js.map +1 -1
  6. package/dist/cjs/lib/create-store.js.map +1 -1
  7. package/dist/cjs/mcp/index.js +6 -6
  8. package/dist/cjs/mcp/index.js.map +1 -1
  9. package/dist/cjs/mcp/prompts/a1-notation.js.map +1 -1
  10. package/dist/cjs/mcp/prompts/index.js +2 -2
  11. package/dist/cjs/mcp/prompts/index.js.map +1 -1
  12. package/dist/cjs/mcp/resources/index.js +2 -2
  13. package/dist/cjs/mcp/resources/index.js.map +1 -1
  14. package/dist/cjs/mcp/resources/spreadsheet.js.map +1 -1
  15. package/dist/cjs/mcp/tools/cells-format.js +8 -8
  16. package/dist/cjs/mcp/tools/cells-format.js.map +1 -1
  17. package/dist/cjs/mcp/tools/chart-create.js +8 -8
  18. package/dist/cjs/mcp/tools/chart-create.js.map +1 -1
  19. package/dist/cjs/mcp/tools/columns-get.js +3 -3
  20. package/dist/cjs/mcp/tools/columns-get.js.map +1 -1
  21. package/dist/cjs/mcp/tools/columns-update.js +10 -10
  22. package/dist/cjs/mcp/tools/columns-update.js.map +1 -1
  23. package/dist/cjs/mcp/tools/csv-get-columns.js +2 -2
  24. package/dist/cjs/mcp/tools/csv-get-columns.js.map +1 -1
  25. package/dist/cjs/mcp/tools/dimensions-batch-update.js +16 -16
  26. package/dist/cjs/mcp/tools/dimensions-batch-update.js.map +1 -1
  27. package/dist/cjs/mcp/tools/dimensions-move.js +5 -5
  28. package/dist/cjs/mcp/tools/dimensions-move.js.map +1 -1
  29. package/dist/cjs/mcp/tools/index.js +52 -52
  30. package/dist/cjs/mcp/tools/index.js.map +1 -1
  31. package/dist/cjs/mcp/tools/lib/dimension-operations.js.map +1 -1
  32. package/dist/cjs/mcp/tools/rows-append.js +10 -10
  33. package/dist/cjs/mcp/tools/rows-append.js.map +1 -1
  34. package/dist/cjs/mcp/tools/rows-csv-append.js +13 -13
  35. package/dist/cjs/mcp/tools/rows-csv-append.js.map +1 -1
  36. package/dist/cjs/mcp/tools/rows-get.js +4 -4
  37. package/dist/cjs/mcp/tools/rows-get.js.map +1 -1
  38. package/dist/cjs/mcp/tools/sheet-copy-to.js +4 -4
  39. package/dist/cjs/mcp/tools/sheet-copy-to.js.map +1 -1
  40. package/dist/cjs/mcp/tools/sheet-copy.js +5 -5
  41. package/dist/cjs/mcp/tools/sheet-copy.js.map +1 -1
  42. package/dist/cjs/mcp/tools/sheet-create.js +4 -4
  43. package/dist/cjs/mcp/tools/sheet-create.js.map +1 -1
  44. package/dist/cjs/mcp/tools/sheet-delete.js +4 -4
  45. package/dist/cjs/mcp/tools/sheet-delete.js.map +1 -1
  46. package/dist/cjs/mcp/tools/sheet-find.js +7 -7
  47. package/dist/cjs/mcp/tools/sheet-find.js.map +1 -1
  48. package/dist/cjs/mcp/tools/sheet-rename.js +5 -5
  49. package/dist/cjs/mcp/tools/sheet-rename.js.map +1 -1
  50. package/dist/cjs/mcp/tools/spreadsheet-copy.js +2 -2
  51. package/dist/cjs/mcp/tools/spreadsheet-copy.js.map +1 -1
  52. package/dist/cjs/mcp/tools/spreadsheet-create.js +2 -2
  53. package/dist/cjs/mcp/tools/spreadsheet-create.js.map +1 -1
  54. package/dist/cjs/mcp/tools/spreadsheet-find.js +6 -6
  55. package/dist/cjs/mcp/tools/spreadsheet-find.js.map +1 -1
  56. package/dist/cjs/mcp/tools/spreadsheet-rename.js +3 -3
  57. package/dist/cjs/mcp/tools/spreadsheet-rename.js.map +1 -1
  58. package/dist/cjs/mcp/tools/validation-set.js +8 -8
  59. package/dist/cjs/mcp/tools/validation-set.js.map +1 -1
  60. package/dist/cjs/mcp/tools/values-batch-update.js +8 -8
  61. package/dist/cjs/mcp/tools/values-batch-update.js.map +1 -1
  62. package/dist/cjs/mcp/tools/values-clear.js +6 -6
  63. package/dist/cjs/mcp/tools/values-clear.js.map +1 -1
  64. package/dist/cjs/mcp/tools/values-csv-update.js +8 -8
  65. package/dist/cjs/mcp/tools/values-csv-update.js.map +1 -1
  66. package/dist/cjs/mcp/tools/values-replace.js +8 -8
  67. package/dist/cjs/mcp/tools/values-replace.js.map +1 -1
  68. package/dist/cjs/mcp/tools/values-search.js +5 -5
  69. package/dist/cjs/mcp/tools/values-search.js.map +1 -1
  70. package/dist/cjs/schemas/index.js.map +1 -1
  71. package/dist/cjs/setup/config.js +11 -1
  72. package/dist/cjs/setup/config.js.map +1 -1
  73. package/dist/cjs/setup/http.js +6 -2
  74. package/dist/cjs/setup/http.js.map +1 -1
  75. package/dist/cjs/setup/index.js +9 -9
  76. package/dist/cjs/setup/index.js.map +1 -1
  77. package/dist/cjs/setup/oauth-google.d.cts +3 -2
  78. package/dist/cjs/setup/oauth-google.d.ts +3 -2
  79. package/dist/cjs/setup/oauth-google.js +15 -12
  80. package/dist/cjs/setup/oauth-google.js.map +1 -1
  81. package/dist/cjs/setup/runtime.js +9 -9
  82. package/dist/cjs/setup/runtime.js.map +1 -1
  83. package/dist/cjs/setup/stdio.js +2 -2
  84. package/dist/cjs/setup/stdio.js.map +1 -1
  85. package/dist/cjs/spreadsheet/column-utilities.js.map +1 -1
  86. package/dist/cjs/spreadsheet/csv-streaming.js.map +1 -1
  87. package/dist/cjs/spreadsheet/data-operations.js +9 -9
  88. package/dist/cjs/spreadsheet/data-operations.js.map +1 -1
  89. package/dist/cjs/spreadsheet/deduplication-utils.js.map +1 -1
  90. package/dist/cjs/spreadsheet/range-operations.js +2 -2
  91. package/dist/cjs/spreadsheet/range-operations.js.map +1 -1
  92. package/dist/cjs/spreadsheet/sheet-operations.js +3 -3
  93. package/dist/cjs/spreadsheet/sheet-operations.js.map +1 -1
  94. package/dist/cjs/spreadsheet/spreadsheet-management.js.map +1 -1
  95. package/dist/esm/constants.js.map +1 -1
  96. package/dist/esm/index.js.map +1 -1
  97. package/dist/esm/lib/create-store.js.map +1 -1
  98. package/dist/esm/mcp/index.js.map +1 -1
  99. package/dist/esm/mcp/prompts/a1-notation.js.map +1 -1
  100. package/dist/esm/mcp/prompts/index.js.map +1 -1
  101. package/dist/esm/mcp/resources/index.js.map +1 -1
  102. package/dist/esm/mcp/resources/spreadsheet.js.map +1 -1
  103. package/dist/esm/mcp/tools/cells-format.js.map +1 -1
  104. package/dist/esm/mcp/tools/chart-create.js.map +1 -1
  105. package/dist/esm/mcp/tools/columns-get.js.map +1 -1
  106. package/dist/esm/mcp/tools/columns-update.js.map +1 -1
  107. package/dist/esm/mcp/tools/csv-get-columns.js.map +1 -1
  108. package/dist/esm/mcp/tools/dimensions-batch-update.js.map +1 -1
  109. package/dist/esm/mcp/tools/dimensions-move.js.map +1 -1
  110. package/dist/esm/mcp/tools/index.js.map +1 -1
  111. package/dist/esm/mcp/tools/lib/dimension-operations.js.map +1 -1
  112. package/dist/esm/mcp/tools/rows-append.js.map +1 -1
  113. package/dist/esm/mcp/tools/rows-csv-append.js.map +1 -1
  114. package/dist/esm/mcp/tools/rows-get.js.map +1 -1
  115. package/dist/esm/mcp/tools/sheet-copy-to.js.map +1 -1
  116. package/dist/esm/mcp/tools/sheet-copy.js.map +1 -1
  117. package/dist/esm/mcp/tools/sheet-create.js.map +1 -1
  118. package/dist/esm/mcp/tools/sheet-delete.js.map +1 -1
  119. package/dist/esm/mcp/tools/sheet-find.js.map +1 -1
  120. package/dist/esm/mcp/tools/sheet-rename.js.map +1 -1
  121. package/dist/esm/mcp/tools/spreadsheet-copy.js.map +1 -1
  122. package/dist/esm/mcp/tools/spreadsheet-create.js.map +1 -1
  123. package/dist/esm/mcp/tools/spreadsheet-find.js.map +1 -1
  124. package/dist/esm/mcp/tools/spreadsheet-rename.js.map +1 -1
  125. package/dist/esm/mcp/tools/validation-set.js.map +1 -1
  126. package/dist/esm/mcp/tools/values-batch-update.js.map +1 -1
  127. package/dist/esm/mcp/tools/values-clear.js.map +1 -1
  128. package/dist/esm/mcp/tools/values-csv-update.js.map +1 -1
  129. package/dist/esm/mcp/tools/values-replace.js.map +1 -1
  130. package/dist/esm/mcp/tools/values-search.js.map +1 -1
  131. package/dist/esm/schemas/index.js.map +1 -1
  132. package/dist/esm/setup/config.js +12 -2
  133. package/dist/esm/setup/config.js.map +1 -1
  134. package/dist/esm/setup/http.js +4 -0
  135. package/dist/esm/setup/http.js.map +1 -1
  136. package/dist/esm/setup/index.js.map +1 -1
  137. package/dist/esm/setup/oauth-google.d.ts +3 -2
  138. package/dist/esm/setup/oauth-google.js +8 -11
  139. package/dist/esm/setup/oauth-google.js.map +1 -1
  140. package/dist/esm/setup/runtime.js.map +1 -1
  141. package/dist/esm/setup/stdio.js.map +1 -1
  142. package/dist/esm/spreadsheet/column-utilities.js.map +1 -1
  143. package/dist/esm/spreadsheet/csv-streaming.js.map +1 -1
  144. package/dist/esm/spreadsheet/data-operations.js.map +1 -1
  145. package/dist/esm/spreadsheet/deduplication-utils.js.map +1 -1
  146. package/dist/esm/spreadsheet/range-operations.js.map +1 -1
  147. package/dist/esm/spreadsheet/sheet-operations.js.map +1 -1
  148. package/dist/esm/spreadsheet/spreadsheet-management.js.map +1 -1
  149. package/dist/esm/types.js.map +1 -1
  150. package/package.json +1 -1
@@ -1 +1 @@
1
- {"version":3,"sources":["/Users/kevin/Dev/Projects/ai/mcp-z/servers/mcp-sheets/src/mcp/tools/validation-set.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, type sheets_v4 } from 'googleapis';\nimport { z } from 'zod';\nimport { SheetGidOutput, SheetGidSchema, SpreadsheetIdOutput, SpreadsheetIdSchema } from '../../schemas/index.js';\nimport { parseA1Notation, rangeReferenceToGridRange } from '../../spreadsheet/range-operations.js';\n\n// Discriminated union for validation rule types\nconst ValidationRuleSchema = z.discriminatedUnion('conditionType', [\n // Dropdown with hardcoded list\n z.object({\n conditionType: z.literal('ONE_OF_LIST'),\n values: z.array(z.string()).min(1).describe('Hardcoded dropdown options'),\n showDropdown: z.boolean().default(true).describe('Show dropdown UI in cells'),\n strict: z.boolean().default(true).describe('Reject invalid entries'),\n }),\n // Dropdown from range\n z.object({\n conditionType: z.literal('ONE_OF_RANGE'),\n sourceRange: z.string().min(1).describe('A1 notation range containing dropdown options (e.g., \"Options!A1:A10\")'),\n showDropdown: z.boolean().default(true).describe('Show dropdown UI in cells'),\n strict: z.boolean().default(true).describe('Reject invalid entries'),\n }),\n // Numeric constraints\n z.object({\n conditionType: z.enum(['NUMBER_GREATER', 'NUMBER_LESS', 'NUMBER_BETWEEN']),\n values: z.array(z.number()).min(1).max(2).describe('1 value for GREATER/LESS, 2 values for BETWEEN'),\n strict: z.boolean().default(true).describe('Reject invalid entries'),\n }),\n // Text constraints\n z.object({\n conditionType: z.enum(['TEXT_CONTAINS', 'TEXT_IS_EMAIL', 'TEXT_IS_URL']),\n values: z.array(z.string()).optional().describe('Text to match (for TEXT_CONTAINS only)'),\n strict: z.boolean().default(true).describe('Reject invalid entries'),\n }),\n // Date constraints\n z.object({\n conditionType: z.enum(['DATE_AFTER', 'DATE_BEFORE', 'DATE_BETWEEN']),\n values: z.array(z.string()).min(1).max(2).describe('ISO date strings (YYYY-MM-DD)'),\n strict: z.boolean().default(true).describe('Reject invalid entries'),\n }),\n // Custom formula\n z.object({\n conditionType: z.literal('CUSTOM_FORMULA'),\n formula: z.string().min(1).describe('Custom validation formula (e.g., \"=A1>0\")'),\n strict: z.boolean().default(true).describe('Reject invalid entries'),\n }),\n]);\n\n// Input schema for validation requests\nconst ValidationRequestSchema = z.object({\n range: z.string().min(1).describe('A1 notation range for validation (e.g., \"B2:B100\")'),\n rule: ValidationRuleSchema,\n inputMessage: z.string().optional().describe('Help text shown when cell is selected'),\n});\n\nconst inputSchema = z.object({\n id: SpreadsheetIdSchema,\n gid: SheetGidSchema,\n requests: z.array(ValidationRequestSchema).min(1).max(50).describe('Array of validation rules. Batch multiple ranges for efficiency.'),\n});\n\nconst successBranchSchema = z.object({\n type: z.literal('success'),\n id: SpreadsheetIdOutput,\n gid: SheetGidOutput,\n sheetTitle: z.string().describe('Title of the sheet with validation'),\n sheetUrl: z.string().describe('URL of the sheet with validation'),\n successCount: z.number().int().nonnegative().describe('Number of validation rules successfully applied'),\n failedRanges: z\n .array(\n z.object({\n range: z.string().describe('A1 notation of range that failed validation setup'),\n error: z.string().describe('Why validation failed for this range'),\n })\n )\n .optional()\n .describe('Only populated if some validation rules failed'),\n});\n\nconst outputSchema = z.discriminatedUnion('type', [successBranchSchema, AuthRequiredBranchSchema]);\n\nconst config = {\n description: 'Add data validation rules including dropdowns, numeric constraints, text patterns, date ranges, custom formulas. Supports batch operations for efficiency. Use discriminated conditionType to specify rule type. Best for enforcing data integrity and providing user-friendly input controls.',\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// Map condition types to Google Sheets API format\nfunction buildCondition(rule: z.infer<typeof ValidationRuleSchema>) {\n switch (rule.conditionType) {\n case 'ONE_OF_LIST':\n return {\n type: 'ONE_OF_LIST',\n values: rule.values.map((value) => ({ userEnteredValue: value })),\n };\n case 'ONE_OF_RANGE':\n return {\n type: 'ONE_OF_RANGE',\n values: [{ userEnteredValue: `=${rule.sourceRange}` }],\n };\n case 'NUMBER_GREATER':\n return {\n type: 'NUMBER_GREATER',\n values: [{ userEnteredValue: String(rule.values[0]) }],\n };\n case 'NUMBER_LESS':\n return {\n type: 'NUMBER_LESS',\n values: [{ userEnteredValue: String(rule.values[0]) }],\n };\n case 'NUMBER_BETWEEN':\n return {\n type: 'NUMBER_BETWEEN',\n values: [{ userEnteredValue: String(rule.values[0]) }, { userEnteredValue: String(rule.values[1]) }],\n };\n case 'TEXT_CONTAINS':\n return {\n type: 'TEXT_CONTAINS',\n values: rule.values ? [{ userEnteredValue: rule.values[0] }] : [],\n };\n case 'TEXT_IS_EMAIL':\n return {\n type: 'TEXT_IS_EMAIL',\n values: [],\n };\n case 'TEXT_IS_URL':\n return {\n type: 'TEXT_IS_URL',\n values: [],\n };\n case 'DATE_AFTER':\n return {\n type: 'DATE_AFTER',\n values: [{ userEnteredValue: rule.values[0] }],\n };\n case 'DATE_BEFORE':\n return {\n type: 'DATE_BEFORE',\n values: [{ userEnteredValue: rule.values[0] }],\n };\n case 'DATE_BETWEEN':\n return {\n type: 'DATE_BETWEEN',\n values: [{ userEnteredValue: rule.values[0] }, { userEnteredValue: rule.values[1] }],\n };\n case 'CUSTOM_FORMULA':\n return {\n type: 'CUSTOM_FORMULA',\n values: [{ userEnteredValue: rule.formula.startsWith('=') ? rule.formula : `=${rule.formula}` }],\n };\n default:\n // Exhaustive check - all valid conditionType values should be handled above\n throw new Error(`Unknown condition type: ${(rule as { conditionType: string }).conditionType}`);\n }\n}\n\nasync function handler({ id, gid, requests }: Input, extra: EnrichedExtra): Promise<CallToolResult> {\n const logger = extra.logger;\n logger.info('sheets.validation.set called', {\n id,\n gid,\n requestCount: requests.length,\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: '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 logger.info('Sheet not found for validation set', { 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 const sheetUrl = `https://docs.google.com/spreadsheets/d/${id}/edit#gid=${sheetId}`;\n\n // Validate sheetId exists\n if (sheetId === undefined || sheetId === null) {\n logger.error('Sheet ID not available for validation set', { id, gid, sheetTitle });\n throw new McpError(ErrorCode.InternalError, `Sheet ID not available for ${gid}. Cannot perform validation operations without valid sheet ID.`);\n }\n\n // Build batch update requests\n const batchRequests: sheets_v4.Schema$Request[] = [];\n const failedRanges: Array<{ range: string; error: string }> = [];\n\n for (const request of requests) {\n try {\n // Parse A1 notation to range reference\n const rangeRef = parseA1Notation(request.range);\n\n // Build grid range from range reference using helper function\n const gridRange = rangeReferenceToGridRange(rangeRef, sheetId);\n\n // Build validation rule\n const condition = buildCondition(request.rule);\n\n // Build data validation rule - structure matches Schema$DataValidationRule\n const dataValidationRule = {\n condition,\n strict: request.rule.strict,\n showCustomUi: 'showDropdown' in request.rule ? request.rule.showDropdown : undefined,\n inputMessage: request.inputMessage,\n } as sheets_v4.Schema$DataValidationRule;\n\n // Add setDataValidation request\n batchRequests.push({\n setDataValidation: {\n range: gridRange,\n rule: dataValidationRule,\n },\n });\n } catch (error) {\n const message = error instanceof Error ? error.message : String(error);\n logger.info('Failed to build validation rule', {\n range: request.range,\n error: message,\n });\n failedRanges.push({\n range: request.range,\n error: `Failed to build validation rule: ${message}`,\n });\n }\n }\n\n // Early return if all ranges failed\n if (batchRequests.length === 0) {\n const result: Output = {\n type: 'success' as const,\n id,\n gid: String(sheetId),\n sheetTitle,\n sheetUrl,\n successCount: 0,\n failedRanges: failedRanges.length > 0 ? failedRanges : undefined,\n };\n\n return {\n content: [{ type: 'text' as const, text: JSON.stringify(result) }],\n structuredContent: { result },\n };\n }\n\n logger.info('sheets.validation.set executing batch request', {\n spreadsheetId: id,\n sheetTitle,\n batchRequestsCount: batchRequests.length,\n });\n\n // Execute the batch update\n await sheets.spreadsheets.batchUpdate({\n spreadsheetId: id,\n requestBody: {\n requests: batchRequests,\n },\n });\n\n logger.info('sheets.validation.set completed successfully', {\n successCount: requests.length - failedRanges.length,\n failedCount: failedRanges.length,\n });\n\n const result: Output = {\n type: 'success' as const,\n id,\n gid: String(sheetId),\n sheetTitle,\n sheetUrl,\n successCount: requests.length - failedRanges.length,\n failedRanges: failedRanges.length > 0 ? failedRanges : undefined,\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('Validation set operation failed', {\n id,\n gid,\n requestCount: requests.length,\n error: message,\n });\n\n throw new McpError(ErrorCode.InternalError, `Error setting validation: ${message}`, {\n stack: error instanceof Error ? error.stack : undefined,\n });\n }\n}\n\nexport default function createTool() {\n return {\n name: 'validation-set',\n config,\n handler,\n } satisfies ToolModule;\n}\n"],"names":["createTool","AuthRequiredBranchSchema","schemas","ValidationRuleSchema","z","discriminatedUnion","object","conditionType","literal","values","array","string","min","describe","showDropdown","boolean","default","strict","sourceRange","enum","number","max","optional","formula","ValidationRequestSchema","range","rule","inputMessage","inputSchema","id","SpreadsheetIdSchema","gid","SheetGidSchema","requests","successBranchSchema","type","SpreadsheetIdOutput","SheetGidOutput","sheetTitle","sheetUrl","successCount","int","nonnegative","failedRanges","error","outputSchema","config","description","result","buildCondition","map","value","userEnteredValue","String","startsWith","Error","handler","extra","logger","sheet","spreadsheetResponse","sheets","sheetId","batchRequests","request","rangeRef","gridRange","condition","dataValidationRule","message","info","requestCount","length","google","version","auth","authContext","spreadsheets","get","spreadsheetId","fields","data","find","s","properties","McpError","ErrorCode","InvalidParams","title","undefined","InternalError","parseA1Notation","rangeReferenceToGridRange","showCustomUi","push","setDataValidation","content","text","JSON","stringify","structuredContent","batchRequestsCount","batchUpdate","requestBody","failedCount","stack","name"],"mappings":";;;;+BAuTA;;;eAAwBA;;;2BAtTA;qBAMY;0BACG;mBACrB;qBACuE;+BAC9B;;;;;;;;;;;;;;;;;;;;;;;;;;;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O,OAAO;gCAAG;oCAAE7D,MAAM;oCAAiB8D,MAAMC,KAAKC,SAAS,CAACnD;gCAAQ;;4BAChEoD,mBAAmB;gCAAEpD,QAAAA;4BAAO;wBAC9B;;;oBACOJ;oBACDyB,WAAUzB,AAAK,YAALA,OAAiBW,SAAQX,MAAMyB,OAAO,GAAGhB,OAAOT;oBAChEc,OAAOd,KAAK,CAAC,mCAAmC;wBAC9Cf,IAAAA;wBACAE,KAAAA;wBACAwC,cAActC,SAASuC,MAAM;wBAC7B5B,OAAOyB;oBACT;oBAEA,MAAM,IAAIgB,eAAQ,CAACC,gBAAS,CAACI,aAAa,EAAE,AAAC,6BAAoC,OAARrB,WAAW;wBAClFoC,OAAO7D,AAAK,YAALA,OAAiBW,SAAQX,MAAM6D,KAAK,GAAGhB;oBAChD;;;;;;;IAEJ;;AAEe,SAASzF;IACtB,OAAO;QACL0G,MAAM;QACN5D,QAAAA;QACAU,SAAAA;IACF;AACF"}
1
+ {"version":3,"sources":["/Users/kevin/Dev/Projects/mcp-z/mcp-sheets/src/mcp/tools/validation-set.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, type sheets_v4 } from 'googleapis';\nimport { z } from 'zod';\nimport { SheetGidOutput, SheetGidSchema, SpreadsheetIdOutput, SpreadsheetIdSchema } from '../../schemas/index.ts';\nimport { parseA1Notation, rangeReferenceToGridRange } from '../../spreadsheet/range-operations.ts';\n\n// Discriminated union for validation rule types\nconst ValidationRuleSchema = z.discriminatedUnion('conditionType', [\n // Dropdown with hardcoded list\n z.object({\n conditionType: z.literal('ONE_OF_LIST'),\n values: z.array(z.string()).min(1).describe('Hardcoded dropdown options'),\n showDropdown: z.boolean().default(true).describe('Show dropdown UI in cells'),\n strict: z.boolean().default(true).describe('Reject invalid entries'),\n }),\n // Dropdown from range\n z.object({\n conditionType: z.literal('ONE_OF_RANGE'),\n sourceRange: z.string().min(1).describe('A1 notation range containing dropdown options (e.g., \"Options!A1:A10\")'),\n showDropdown: z.boolean().default(true).describe('Show dropdown UI in cells'),\n strict: z.boolean().default(true).describe('Reject invalid entries'),\n }),\n // Numeric constraints\n z.object({\n conditionType: z.enum(['NUMBER_GREATER', 'NUMBER_LESS', 'NUMBER_BETWEEN']),\n values: z.array(z.number()).min(1).max(2).describe('1 value for GREATER/LESS, 2 values for BETWEEN'),\n strict: z.boolean().default(true).describe('Reject invalid entries'),\n }),\n // Text constraints\n z.object({\n conditionType: z.enum(['TEXT_CONTAINS', 'TEXT_IS_EMAIL', 'TEXT_IS_URL']),\n values: z.array(z.string()).optional().describe('Text to match (for TEXT_CONTAINS only)'),\n strict: z.boolean().default(true).describe('Reject invalid entries'),\n }),\n // Date constraints\n z.object({\n conditionType: z.enum(['DATE_AFTER', 'DATE_BEFORE', 'DATE_BETWEEN']),\n values: z.array(z.string()).min(1).max(2).describe('ISO date strings (YYYY-MM-DD)'),\n strict: z.boolean().default(true).describe('Reject invalid entries'),\n }),\n // Custom formula\n z.object({\n conditionType: z.literal('CUSTOM_FORMULA'),\n formula: z.string().min(1).describe('Custom validation formula (e.g., \"=A1>0\")'),\n strict: z.boolean().default(true).describe('Reject invalid entries'),\n }),\n]);\n\n// Input schema for validation requests\nconst ValidationRequestSchema = z.object({\n range: z.string().min(1).describe('A1 notation range for validation (e.g., \"B2:B100\")'),\n rule: ValidationRuleSchema,\n inputMessage: z.string().optional().describe('Help text shown when cell is selected'),\n});\n\nconst inputSchema = z.object({\n id: SpreadsheetIdSchema,\n gid: SheetGidSchema,\n requests: z.array(ValidationRequestSchema).min(1).max(50).describe('Array of validation rules. Batch multiple ranges for efficiency.'),\n});\n\nconst successBranchSchema = z.object({\n type: z.literal('success'),\n id: SpreadsheetIdOutput,\n gid: SheetGidOutput,\n sheetTitle: z.string().describe('Title of the sheet with validation'),\n sheetUrl: z.string().describe('URL of the sheet with validation'),\n successCount: z.number().int().nonnegative().describe('Number of validation rules successfully applied'),\n failedRanges: z\n .array(\n z.object({\n range: z.string().describe('A1 notation of range that failed validation setup'),\n error: z.string().describe('Why validation failed for this range'),\n })\n )\n .optional()\n .describe('Only populated if some validation rules failed'),\n});\n\nconst outputSchema = z.discriminatedUnion('type', [successBranchSchema, AuthRequiredBranchSchema]);\n\nconst config = {\n description: 'Add data validation rules including dropdowns, numeric constraints, text patterns, date ranges, custom formulas. Supports batch operations for efficiency. Use discriminated conditionType to specify rule type. Best for enforcing data integrity and providing user-friendly input controls.',\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// Map condition types to Google Sheets API format\nfunction buildCondition(rule: z.infer<typeof ValidationRuleSchema>) {\n switch (rule.conditionType) {\n case 'ONE_OF_LIST':\n return {\n type: 'ONE_OF_LIST',\n values: rule.values.map((value) => ({ userEnteredValue: value })),\n };\n case 'ONE_OF_RANGE':\n return {\n type: 'ONE_OF_RANGE',\n values: [{ userEnteredValue: `=${rule.sourceRange}` }],\n };\n case 'NUMBER_GREATER':\n return {\n type: 'NUMBER_GREATER',\n values: [{ userEnteredValue: String(rule.values[0]) }],\n };\n case 'NUMBER_LESS':\n return {\n type: 'NUMBER_LESS',\n values: [{ userEnteredValue: String(rule.values[0]) }],\n };\n case 'NUMBER_BETWEEN':\n return {\n type: 'NUMBER_BETWEEN',\n values: [{ userEnteredValue: String(rule.values[0]) }, { userEnteredValue: String(rule.values[1]) }],\n };\n case 'TEXT_CONTAINS':\n return {\n type: 'TEXT_CONTAINS',\n values: rule.values ? [{ userEnteredValue: rule.values[0] }] : [],\n };\n case 'TEXT_IS_EMAIL':\n return {\n type: 'TEXT_IS_EMAIL',\n values: [],\n };\n case 'TEXT_IS_URL':\n return {\n type: 'TEXT_IS_URL',\n values: [],\n };\n case 'DATE_AFTER':\n return {\n type: 'DATE_AFTER',\n values: [{ userEnteredValue: rule.values[0] }],\n };\n case 'DATE_BEFORE':\n return {\n type: 'DATE_BEFORE',\n values: [{ userEnteredValue: rule.values[0] }],\n };\n case 'DATE_BETWEEN':\n return {\n type: 'DATE_BETWEEN',\n values: [{ userEnteredValue: rule.values[0] }, { userEnteredValue: rule.values[1] }],\n };\n case 'CUSTOM_FORMULA':\n return {\n type: 'CUSTOM_FORMULA',\n values: [{ userEnteredValue: rule.formula.startsWith('=') ? rule.formula : `=${rule.formula}` }],\n };\n default:\n // Exhaustive check - all valid conditionType values should be handled above\n throw new Error(`Unknown condition type: ${(rule as { conditionType: string }).conditionType}`);\n }\n}\n\nasync function handler({ id, gid, requests }: Input, extra: EnrichedExtra): Promise<CallToolResult> {\n const logger = extra.logger;\n logger.info('sheets.validation.set called', {\n id,\n gid,\n requestCount: requests.length,\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: '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 logger.info('Sheet not found for validation set', { 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 const sheetUrl = `https://docs.google.com/spreadsheets/d/${id}/edit#gid=${sheetId}`;\n\n // Validate sheetId exists\n if (sheetId === undefined || sheetId === null) {\n logger.error('Sheet ID not available for validation set', { id, gid, sheetTitle });\n throw new McpError(ErrorCode.InternalError, `Sheet ID not available for ${gid}. Cannot perform validation operations without valid sheet ID.`);\n }\n\n // Build batch update requests\n const batchRequests: sheets_v4.Schema$Request[] = [];\n const failedRanges: Array<{ range: string; error: string }> = [];\n\n for (const request of requests) {\n try {\n // Parse A1 notation to range reference\n const rangeRef = parseA1Notation(request.range);\n\n // Build grid range from range reference using helper function\n const gridRange = rangeReferenceToGridRange(rangeRef, sheetId);\n\n // Build validation rule\n const condition = buildCondition(request.rule);\n\n // Build data validation rule - structure matches Schema$DataValidationRule\n const dataValidationRule = {\n condition,\n strict: request.rule.strict,\n showCustomUi: 'showDropdown' in request.rule ? request.rule.showDropdown : undefined,\n inputMessage: request.inputMessage,\n } as sheets_v4.Schema$DataValidationRule;\n\n // Add setDataValidation request\n batchRequests.push({\n setDataValidation: {\n range: gridRange,\n rule: dataValidationRule,\n },\n });\n } catch (error) {\n const message = error instanceof Error ? error.message : String(error);\n logger.info('Failed to build validation rule', {\n range: request.range,\n error: message,\n });\n failedRanges.push({\n range: request.range,\n error: `Failed to build validation rule: ${message}`,\n });\n }\n }\n\n // Early return if all ranges failed\n if (batchRequests.length === 0) {\n const result: Output = {\n type: 'success' as const,\n id,\n gid: String(sheetId),\n sheetTitle,\n sheetUrl,\n successCount: 0,\n failedRanges: failedRanges.length > 0 ? failedRanges : undefined,\n };\n\n return {\n content: [{ type: 'text' as const, text: JSON.stringify(result) }],\n structuredContent: { result },\n };\n }\n\n logger.info('sheets.validation.set executing batch request', {\n spreadsheetId: id,\n sheetTitle,\n batchRequestsCount: batchRequests.length,\n });\n\n // Execute the batch update\n await sheets.spreadsheets.batchUpdate({\n spreadsheetId: id,\n requestBody: {\n requests: batchRequests,\n },\n });\n\n logger.info('sheets.validation.set completed successfully', {\n successCount: requests.length - failedRanges.length,\n failedCount: failedRanges.length,\n });\n\n const result: Output = {\n type: 'success' as const,\n id,\n gid: String(sheetId),\n sheetTitle,\n sheetUrl,\n successCount: requests.length - failedRanges.length,\n failedRanges: failedRanges.length > 0 ? failedRanges : undefined,\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('Validation set operation failed', {\n id,\n gid,\n requestCount: requests.length,\n error: message,\n });\n\n throw new McpError(ErrorCode.InternalError, `Error setting validation: ${message}`, {\n stack: error instanceof Error ? error.stack : undefined,\n });\n }\n}\n\nexport default function createTool() {\n return {\n name: 'validation-set',\n config,\n handler,\n } satisfies ToolModule;\n}\n"],"names":["createTool","AuthRequiredBranchSchema","schemas","ValidationRuleSchema","z","discriminatedUnion","object","conditionType","literal","values","array","string","min","describe","showDropdown","boolean","default","strict","sourceRange","enum","number","max","optional","formula","ValidationRequestSchema","range","rule","inputMessage","inputSchema","id","SpreadsheetIdSchema","gid","SheetGidSchema","requests","successBranchSchema","type","SpreadsheetIdOutput","SheetGidOutput","sheetTitle","sheetUrl","successCount","int","nonnegative","failedRanges","error","outputSchema","config","description","result","buildCondition","map","value","userEnteredValue","String","startsWith","Error","handler","extra","logger","sheet","spreadsheetResponse","sheets","sheetId","batchRequests","request","rangeRef","gridRange","condition","dataValidationRule","message","info","requestCount","length","google","version","auth","authContext","spreadsheets","get","spreadsheetId","fields","data","find","s","properties","McpError","ErrorCode","InvalidParams","title","undefined","InternalError","parseA1Notation","rangeReferenceToGridRange","showCustomUi","push","setDataValidation","content","text","JSON","stringify","structuredContent","batchRequestsCount","batchUpdate","requestBody","failedCount","stack","name"],"mappings":";;;;+BAuTA;;;eAAwBA;;;2BAtTA;qBAMY;0BACG;mBACrB;uBACuE;iCAC9B;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAR3D,IAAM,AAAEC,2BAA6BC,oBAAO,CAApCD;AAUR,gDAAgD;AAChD,IAAME,uBAAuBC,MAAC,CAACC,kBAAkB,CAAC,iBAAiB;IACjE,+BAA+B;IAC/BD,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wBACAE,KAAAA;wBACAwC,cAActC,SAASuC,MAAM;wBAC7B5B,OAAOyB;oBACT;oBAEA,MAAM,IAAIgB,eAAQ,CAACC,gBAAS,CAACI,aAAa,EAAE,AAAC,6BAAoC,OAARrB,WAAW;wBAClFoC,OAAO7D,AAAK,YAALA,OAAiBW,SAAQX,MAAM6D,KAAK,GAAGhB;oBAChD;;;;;;;IAEJ;;AAEe,SAASzF;IACtB,OAAO;QACL0G,MAAM;QACN5D,QAAAA;QACAU,SAAAA;IACF;AACF"}
@@ -12,7 +12,7 @@ var _oauthgoogle = require("@mcp-z/oauth-google");
12
12
  var _types = require("@modelcontextprotocol/sdk/types.js");
13
13
  var _googleapis = require("googleapis");
14
14
  var _zod = require("zod");
15
- var _index = require("../../schemas/index.js");
15
+ var _indexts = require("../../schemas/index.js");
16
16
  function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) {
17
17
  try {
18
18
  var info = gen[key](arg);
@@ -151,16 +151,16 @@ function _ts_generator(thisArg, body) {
151
151
  var AuthRequiredBranchSchema = _oauthgoogle.schemas.AuthRequiredBranchSchema;
152
152
  // Input schema for values batch update requests
153
153
  var ValuesBatchUpdateRequestSchema = _zod.z.object({
154
- range: _index.A1NotationSchema.describe('A1 notation range defining the bounded target area. Data dimensions must match range dimensions. Example: D1:D100 requires exactly 100 rows of data. Use open-ended ranges like D1:D to write any number of rows.'),
155
- values: _zod.z.array(_zod.z.array(_index.SheetCellSchema)).min(1).describe('2D array of values. Row count must match range height, column count must match range width. Use null to skip a cell (preserve existing value), empty string "" to clear it.'),
154
+ range: _indexts.A1NotationSchema.describe('A1 notation range defining the bounded target area. Data dimensions must match range dimensions. Example: D1:D100 requires exactly 100 rows of data. Use open-ended ranges like D1:D to write any number of rows.'),
155
+ values: _zod.z.array(_zod.z.array(_indexts.SheetCellSchema)).min(1).describe('2D array of values. Row count must match range height, column count must match range width. Use null to skip a cell (preserve existing value), empty string "" to clear it.'),
156
156
  majorDimension: _zod.z.enum([
157
157
  'ROWS',
158
158
  'COLUMNS'
159
159
  ]).describe('Whether values represent rows or columns')
160
160
  });
161
161
  var inputSchema = _zod.z.object({
162
- id: _index.SpreadsheetIdSchema,
163
- gid: _index.SheetGidSchema,
162
+ id: _indexts.SpreadsheetIdSchema,
163
+ gid: _indexts.SheetGidSchema,
164
164
  requests: _zod.z.array(ValuesBatchUpdateRequestSchema).min(1).describe('Array of value update requests'),
165
165
  valueInputOption: _zod.z.enum([
166
166
  'RAW',
@@ -170,8 +170,8 @@ var inputSchema = _zod.z.object({
170
170
  });
171
171
  var successBranchSchema = _zod.z.object({
172
172
  type: _zod.z.literal('success'),
173
- id: _index.SpreadsheetIdOutput,
174
- gid: _index.SheetGidOutput,
173
+ id: _indexts.SpreadsheetIdOutput,
174
+ gid: _indexts.SheetGidOutput,
175
175
  spreadsheetTitle: _zod.z.string().describe('Title of the updated spreadsheet'),
176
176
  spreadsheetUrl: _zod.z.string().describe('URL of the updated spreadsheet'),
177
177
  sheetTitle: _zod.z.string().describe('Title of the updated sheet'),
@@ -186,7 +186,7 @@ var successBranchSchema = _zod.z.object({
186
186
  'ROWS',
187
187
  'COLUMNS'
188
188
  ]).describe('Dimension of the updated data'),
189
- values: _zod.z.array(_zod.z.array(_index.SheetCellSchema)).optional().describe('Updated values (if includeData was true)')
189
+ values: _zod.z.array(_zod.z.array(_indexts.SheetCellSchema)).optional().describe('Updated values (if includeData was true)')
190
190
  })).optional().describe('Detailed information about updated data (if includeData was true)')
191
191
  });
192
192
  var outputSchema = _zod.z.discriminatedUnion('type', [
@@ -1 +1 @@
1
- {"version":3,"sources":["/Users/kevin/Dev/Projects/ai/mcp-z/servers/mcp-sheets/src/mcp/tools/values-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 { A1NotationSchema, SheetCellSchema, SheetGidOutput, SheetGidSchema, SpreadsheetIdOutput, SpreadsheetIdSchema } from '../../schemas/index.js';\n\n// Types for updated data response\ninterface UpdatedDataItem {\n range: string;\n majorDimension: 'ROWS' | 'COLUMNS';\n values?: (string | number | boolean | null)[][];\n}\n\n// Input schema for values batch update requests\nconst ValuesBatchUpdateRequestSchema = z.object({\n range: A1NotationSchema.describe('A1 notation range defining the bounded target area. Data dimensions must match range dimensions. Example: D1:D100 requires exactly 100 rows of data. Use open-ended ranges like D1:D to write any number of rows.'),\n values: z.array(z.array(SheetCellSchema)).min(1).describe('2D array of values. Row count must match range height, column count must match range width. Use null to skip a cell (preserve existing value), empty string \"\" to clear it.'),\n majorDimension: z.enum(['ROWS', 'COLUMNS']).describe('Whether values represent rows or columns'),\n});\n\nconst inputSchema = z.object({\n id: SpreadsheetIdSchema,\n gid: SheetGidSchema,\n requests: z.array(ValuesBatchUpdateRequestSchema).min(1).describe('Array of value update requests'),\n valueInputOption: z.enum(['RAW', 'USER_ENTERED']).describe('How input data should be interpreted (RAW = exact values, USER_ENTERED = parsed like user input)'),\n includeData: z.boolean().describe('Whether to include updated cell values in the response'),\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 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 totalUpdatedRows: z.number().int().nonnegative().describe('Total number of rows updated across all requests'),\n totalUpdatedColumns: z.number().int().nonnegative().describe('Total number of columns updated across all requests'),\n totalUpdatedCells: z.number().int().nonnegative().describe('Total number of cells updated across all requests'),\n updatedRanges: z.array(z.string()).describe('A1 notation ranges that were updated'),\n updatedData: z\n .array(\n z.object({\n range: z.string().describe('A1 notation range that was updated'),\n majorDimension: z.enum(['ROWS', 'COLUMNS']).describe('Dimension of the updated data'),\n values: z.array(z.array(SheetCellSchema)).optional().describe('Updated values (if includeData was true)'),\n })\n )\n .optional()\n .describe('Detailed information about updated data (if includeData was true)'),\n});\n\nconst outputSchema = z.discriminatedUnion('type', [successBranchSchema, AuthRequiredBranchSchema]);\n\nconst config = {\n description: 'Batch update multiple cell ranges. RAW=exact values, USER_ENTERED=parsed like user input. Use a1-notation prompt for range syntax.',\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, valueInputOption = 'USER_ENTERED', includeData = false }: Input, extra: EnrichedExtra): Promise<CallToolResult> {\n const logger = extra.logger;\n logger.info('sheets.values.batchUpdate called', {\n id,\n gid,\n requestCount: requests.length,\n valueInputOption,\n includeData,\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 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 sheetGid = sheet.properties.sheetId ?? 0;\n const sheetUrl = `https://docs.google.com/spreadsheets/d/${id}/edit#gid=${sheetGid}`;\n\n // Build batch update request with prefixed ranges\n const batchUpdateData = requests.map((req) => ({\n range: `${sheetTitle}!${req.range}`,\n values: req.values,\n majorDimension: req.majorDimension || 'ROWS',\n }));\n\n logger.info('sheets.values.batchUpdate executing batch request', {\n spreadsheetId: id,\n sheetTitle,\n batchUpdateDataCount: batchUpdateData.length,\n });\n\n // Execute the batch update\n const batchUpdateResponse = await sheets.spreadsheets.values.batchUpdate({\n spreadsheetId: id,\n requestBody: {\n valueInputOption,\n data: batchUpdateData,\n includeValuesInResponse: includeData,\n responseDateTimeRenderOption: 'FORMATTED_STRING',\n responseValueRenderOption: 'FORMATTED_VALUE',\n },\n });\n\n const updateResult = batchUpdateResponse.data;\n\n // Validate batch operation results and detect partial failures\n const responses = updateResult.responses || [];\n const expectedCount = requests.length;\n const actualCount = responses.length;\n\n if (actualCount !== expectedCount) {\n logger.error('Partial batch failure detected', {\n expectedOperations: expectedCount,\n completedOperations: actualCount,\n spreadsheetId: id,\n sheetTitle,\n });\n\n throw new McpError(ErrorCode.InternalError, `Batch operation partially failed: ${actualCount}/${expectedCount} operations completed`);\n }\n\n // Check for any failed operations (empty or null responses)\n const failedOperations = responses.filter((response, index) => {\n if (!response || !response.updatedRange) {\n logger.error('Failed operation detected', {\n operationIndex: index,\n requestedRange: requests[index]?.range,\n spreadsheetId: id,\n sheetTitle,\n });\n return true;\n }\n return false;\n });\n\n if (failedOperations.length > 0) {\n throw new McpError(ErrorCode.InternalError, `${failedOperations.length} operations failed to update ranges`);\n }\n\n // Extract updated ranges and calculate totals\n const updatedRanges = responses.map((response) => response.updatedRange || '').filter((range) => range);\n const totalUpdatedRows = updateResult.totalUpdatedRows || 0;\n const totalUpdatedColumns = updateResult.totalUpdatedColumns || 0;\n const totalUpdatedCells = updateResult.totalUpdatedCells || 0;\n\n // Build updated data response if requested\n let updatedData: UpdatedDataItem[] | undefined;\n if (includeData && updateResult.responses) {\n updatedData = updateResult.responses\n .filter((response) => response.updatedData)\n .map((response) => {\n const item: UpdatedDataItem = {\n range: response.updatedRange || '',\n majorDimension: (response.updatedData?.majorDimension as 'ROWS' | 'COLUMNS' | undefined) || 'ROWS',\n };\n const values = response.updatedData?.values as (string | number | boolean | null | undefined)[][] | undefined;\n if (values !== undefined) {\n // Map undefined values to null for JSON Schema compatibility\n item.values = values.map((row) => row.map((cell) => (cell === undefined ? null : cell)));\n }\n return item;\n });\n }\n\n logger.info('sheets.values.batchUpdate completed successfully', {\n totalUpdatedRows,\n totalUpdatedColumns,\n totalUpdatedCells,\n updatedRangesCount: updatedRanges.length,\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 totalUpdatedRows,\n totalUpdatedColumns,\n totalUpdatedCells,\n updatedRanges,\n updatedData,\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('Batch update operation failed', {\n id,\n gid,\n requestCount: requests.length,\n valueInputOption,\n error: message,\n });\n\n throw new McpError(ErrorCode.InternalError, `Error batch updating values: ${message}`, {\n stack: error instanceof Error ? error.stack : undefined,\n });\n }\n}\n\nexport default function createTool() {\n return {\n name: 'values-batch-update',\n config,\n handler,\n } satisfies ToolModule;\n}\n"],"names":["createTool","AuthRequiredBranchSchema","schemas","ValuesBatchUpdateRequestSchema","z","object","range","A1NotationSchema","describe","values","array","SheetCellSchema","min","majorDimension","enum","inputSchema","id","SpreadsheetIdSchema","gid","SheetGidSchema","requests","valueInputOption","includeData","boolean","successBranchSchema","type","literal","SpreadsheetIdOutput","SheetGidOutput","spreadsheetTitle","string","spreadsheetUrl","sheetTitle","sheetUrl","totalUpdatedRows","number","int","nonnegative","totalUpdatedColumns","totalUpdatedCells","updatedRanges","updatedData","optional","outputSchema","discriminatedUnion","config","description","result","handler","extra","logger","spreadsheetData","sheet","sheets","spreadsheetResponse","sheetGid","batchUpdateData","batchUpdateResponse","updateResult","responses","expectedCount","actualCount","failedOperations","error","message","info","requestCount","length","google","version","auth","authContext","spreadsheets","get","spreadsheetId","fields","data","properties","title","find","s","String","sheetId","McpError","ErrorCode","InvalidParams","map","req","batchUpdateDataCount","batchUpdate","requestBody","includeValuesInResponse","responseDateTimeRenderOption","responseValueRenderOption","expectedOperations","completedOperations","InternalError","filter","response","index","updatedRange","operationIndex","requestedRange","item","undefined","row","cell","updatedRangesCount","content","text","JSON","stringify","structuredContent","Error","stack","name"],"mappings":";;;;+BAyOA;;;eAAwBA;;;2BAxOA;qBAMY;0BACb;mBACL;qBAC0G;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAP5H,IAAM,AAAEC,2BAA6BC,oBAAO,CAApCD;AAgBR,gDAAgD;AAChD,IAAME,iCAAiCC,MAAC,CAACC,MAAM,CAAC;IAC9CC,OAAOC,uBAAgB,CAACC,QAAQ,CAAC;IACjCC,QAAQL,MAAC,CAACM,KAAK,CAACN,MAAC,CAACM,KAAK,CAACC,sBAAe,GAAGC,GAAG,CAAC,GAAGJ,QAAQ,CAAC;IAC1DK,gBAAgBT,MAAC,CAACU,IAAI,CAAC;QAAC;QAAQ;KAAU,EAAEN,QAAQ,CAAC;AACvD;AAEA,IAAMO,cAAcX,MAAC,CAACC,MAAM,CAAC;IAC3BW,IAAIC,0BAAmB;IACvBC,KAAKC,qBAAc;IACnBC,UAAUhB,MAAC,CAACM,KAAK,CAACP,gCAAgCS,GAAG,CAAC,GAAGJ,QAAQ,CAAC;IAClEa,kBAAkBjB,MAAC,CAACU,IAAI,CAAC;QAAC;QAAO;KAAe,EAAEN,QAAQ,CAAC;IAC3Dc,aAAalB,MAAC,CAACmB,OAAO,GAAGf,QAAQ,CAAC;AACpC;AAEA,IAAMgB,sBAAs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D,SAAQlD,MAAMmD,KAAK,GAAGV;oBAChD;;;;;;;IAEJ;;AAEe,SAASxG;IACtB,OAAO;QACLmH,MAAM;QACNtE,QAAAA;QACAG,SAAAA;IACF;AACF"}
1
+ {"version":3,"sources":["/Users/kevin/Dev/Projects/mcp-z/mcp-sheets/src/mcp/tools/values-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 { A1NotationSchema, SheetCellSchema, SheetGidOutput, SheetGidSchema, SpreadsheetIdOutput, SpreadsheetIdSchema } from '../../schemas/index.ts';\n\n// Types for updated data response\ninterface UpdatedDataItem {\n range: string;\n majorDimension: 'ROWS' | 'COLUMNS';\n values?: (string | number | boolean | null)[][];\n}\n\n// Input schema for values batch update requests\nconst ValuesBatchUpdateRequestSchema = z.object({\n range: A1NotationSchema.describe('A1 notation range defining the bounded target area. Data dimensions must match range dimensions. Example: D1:D100 requires exactly 100 rows of data. Use open-ended ranges like D1:D to write any number of rows.'),\n values: z.array(z.array(SheetCellSchema)).min(1).describe('2D array of values. Row count must match range height, column count must match range width. Use null to skip a cell (preserve existing value), empty string \"\" to clear it.'),\n majorDimension: z.enum(['ROWS', 'COLUMNS']).describe('Whether values represent rows or columns'),\n});\n\nconst inputSchema = z.object({\n id: SpreadsheetIdSchema,\n gid: SheetGidSchema,\n requests: z.array(ValuesBatchUpdateRequestSchema).min(1).describe('Array of value update requests'),\n valueInputOption: z.enum(['RAW', 'USER_ENTERED']).describe('How input data should be interpreted (RAW = exact values, USER_ENTERED = parsed like user input)'),\n includeData: z.boolean().describe('Whether to include updated cell values in the response'),\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 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 totalUpdatedRows: z.number().int().nonnegative().describe('Total number of rows updated across all requests'),\n totalUpdatedColumns: z.number().int().nonnegative().describe('Total number of columns updated across all requests'),\n totalUpdatedCells: z.number().int().nonnegative().describe('Total number of cells updated across all requests'),\n updatedRanges: z.array(z.string()).describe('A1 notation ranges that were updated'),\n updatedData: z\n .array(\n z.object({\n range: z.string().describe('A1 notation range that was updated'),\n majorDimension: z.enum(['ROWS', 'COLUMNS']).describe('Dimension of the updated data'),\n values: z.array(z.array(SheetCellSchema)).optional().describe('Updated values (if includeData was true)'),\n })\n )\n .optional()\n .describe('Detailed information about updated data (if includeData was true)'),\n});\n\nconst outputSchema = z.discriminatedUnion('type', [successBranchSchema, AuthRequiredBranchSchema]);\n\nconst config = {\n description: 'Batch update multiple cell ranges. RAW=exact values, USER_ENTERED=parsed like user input. Use a1-notation prompt for range syntax.',\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, valueInputOption = 'USER_ENTERED', includeData = false }: Input, extra: EnrichedExtra): Promise<CallToolResult> {\n const logger = extra.logger;\n logger.info('sheets.values.batchUpdate called', {\n id,\n gid,\n requestCount: requests.length,\n valueInputOption,\n includeData,\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 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 sheetGid = sheet.properties.sheetId ?? 0;\n const sheetUrl = `https://docs.google.com/spreadsheets/d/${id}/edit#gid=${sheetGid}`;\n\n // Build batch update request with prefixed ranges\n const batchUpdateData = requests.map((req) => ({\n range: `${sheetTitle}!${req.range}`,\n values: req.values,\n majorDimension: req.majorDimension || 'ROWS',\n }));\n\n logger.info('sheets.values.batchUpdate executing batch request', {\n spreadsheetId: id,\n sheetTitle,\n batchUpdateDataCount: batchUpdateData.length,\n });\n\n // Execute the batch update\n const batchUpdateResponse = await sheets.spreadsheets.values.batchUpdate({\n spreadsheetId: id,\n requestBody: {\n valueInputOption,\n data: batchUpdateData,\n includeValuesInResponse: includeData,\n responseDateTimeRenderOption: 'FORMATTED_STRING',\n responseValueRenderOption: 'FORMATTED_VALUE',\n },\n });\n\n const updateResult = batchUpdateResponse.data;\n\n // Validate batch operation results and detect partial failures\n const responses = updateResult.responses || [];\n const expectedCount = requests.length;\n const actualCount = responses.length;\n\n if (actualCount !== expectedCount) {\n logger.error('Partial batch failure detected', {\n expectedOperations: expectedCount,\n completedOperations: actualCount,\n spreadsheetId: id,\n sheetTitle,\n });\n\n throw new McpError(ErrorCode.InternalError, `Batch operation partially failed: ${actualCount}/${expectedCount} operations completed`);\n }\n\n // Check for any failed operations (empty or null responses)\n const failedOperations = responses.filter((response, index) => {\n if (!response || !response.updatedRange) {\n logger.error('Failed operation detected', {\n operationIndex: index,\n requestedRange: requests[index]?.range,\n spreadsheetId: id,\n sheetTitle,\n });\n return true;\n }\n return false;\n });\n\n if (failedOperations.length > 0) {\n throw new McpError(ErrorCode.InternalError, `${failedOperations.length} operations failed to update ranges`);\n }\n\n // Extract updated ranges and calculate totals\n const updatedRanges = responses.map((response) => response.updatedRange || '').filter((range) => range);\n const totalUpdatedRows = updateResult.totalUpdatedRows || 0;\n const totalUpdatedColumns = updateResult.totalUpdatedColumns || 0;\n const totalUpdatedCells = updateResult.totalUpdatedCells || 0;\n\n // Build updated data response if requested\n let updatedData: UpdatedDataItem[] | undefined;\n if (includeData && updateResult.responses) {\n updatedData = updateResult.responses\n .filter((response) => response.updatedData)\n .map((response) => {\n const item: UpdatedDataItem = {\n range: response.updatedRange || '',\n majorDimension: (response.updatedData?.majorDimension as 'ROWS' | 'COLUMNS' | undefined) || 'ROWS',\n };\n const values = response.updatedData?.values as (string | number | boolean | null | undefined)[][] | undefined;\n if (values !== undefined) {\n // Map undefined values to null for JSON Schema compatibility\n item.values = values.map((row) => row.map((cell) => (cell === undefined ? null : cell)));\n }\n return item;\n });\n }\n\n logger.info('sheets.values.batchUpdate completed successfully', {\n totalUpdatedRows,\n totalUpdatedColumns,\n totalUpdatedCells,\n updatedRangesCount: updatedRanges.length,\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 totalUpdatedRows,\n totalUpdatedColumns,\n totalUpdatedCells,\n updatedRanges,\n updatedData,\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('Batch update operation failed', {\n id,\n gid,\n requestCount: requests.length,\n valueInputOption,\n error: message,\n });\n\n throw new McpError(ErrorCode.InternalError, `Error batch updating values: ${message}`, {\n stack: error instanceof Error ? error.stack : undefined,\n });\n }\n}\n\nexport default function createTool() {\n return {\n name: 'values-batch-update',\n config,\n handler,\n } satisfies ToolModule;\n}\n"],"names":["createTool","AuthRequiredBranchSchema","schemas","ValuesBatchUpdateRequestSchema","z","object","range","A1NotationSchema","describe","values","array","SheetCellSchema","min","majorDimension","enum","inputSchema","id","SpreadsheetIdSchema","gid","SheetGidSchema","requests","valueInputOption","includeData","boolean","successBranchSchema","type","literal","SpreadsheetIdOutput","SheetGidOutput","spreadsheetTitle","string","spreadsheetUrl","sheetTitle","sheetUrl","totalUpdatedRows","number","int","nonnegative","totalUpdatedColumns","totalUpdatedCells","updatedRanges","updatedData","optional","outputSchema","discriminatedUnion","config","description","result","handler","extra","logger","spreadsheetData","sheet","sheets","spreadsheetResponse","sheetGid","batchUpdateData","batchUpdateResponse","updateResult","responses","expectedCount","actualCount","failedOperations","error","message","info","requestCount","length","google","version","auth","authContext","spreadsheets","get","spreadsheetId","fields","data","properties","title","find","s","String","sheetId","McpError","ErrorCode","InvalidParams","map","req","batchUpdateDataCount","batchUpdate","requestBody","includeValuesInResponse","responseDateTimeRenderOption","responseValueRenderOption","expectedOperations","completedOperations","InternalError","filter","response","index","updatedRange","operationIndex","requestedRange","item","undefined","row","cell","updatedRangesCount","content","text","JSON","stringify","structuredContent","Error","stack","name"],"mappings":";;;;+BAyOA;;;eAAwBA;;;2BAxOA;qBAMY;0BACb;mBACL;uBAC0G;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAP5H,IAAM,AAAEC,2BAA6BC,oBAAO,CAApCD;AAgBR,gDAAgD;AAChD,IAAME,iCAAiCC,MAAC,CAACC,MAAM,CAAC;IAC9CC,OAAOC,yBAAgB,CAACC,QAAQ,CAAC;IACjCC,QAAQL,MAAC,CAACM,KAAK,CAACN,MAAC,CAACM,KAAK,CAACC,wBAAe,GAAGC,GAAG,CAAC,GAAGJ,QAAQ,CAAC;IAC1DK,gBAAgBT,MAAC,CAACU,IAAI,CAAC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;gCAAEjE,QAAAA;4BAAO;wBAC9B;;;oBACOgB;oBACDC,UAAUD,AAAK,YAALA,OAAiBkD,SAAQlD,MAAMC,OAAO,GAAGiB,OAAOlB;oBAChEb,OAAOa,KAAK,CAAC,iCAAiC;wBAC5C/C,IAAAA;wBACAE,KAAAA;wBACAgD,cAAc9C,SAAS+C,MAAM;wBAC7B9C,kBAAAA;wBACA0C,OAAOC;oBACT;oBAEA,MAAM,IAAImB,eAAQ,CAACC,gBAAS,CAACY,aAAa,EAAE,AAAC,gCAAuC,OAARhC,UAAW;wBACrFkD,OAAOnD,AAAK,YAALA,OAAiBkD,SAAQlD,MAAMmD,KAAK,GAAGV;oBAChD;;;;;;;IAEJ;;AAEe,SAASxG;IACtB,OAAO;QACLmH,MAAM;QACNtE,QAAAA;QACAG,SAAAA;IACF;AACF"}
@@ -12,7 +12,7 @@ var _oauthgoogle = require("@mcp-z/oauth-google");
12
12
  var _types = require("@modelcontextprotocol/sdk/types.js");
13
13
  var _googleapis = require("googleapis");
14
14
  var _zod = require("zod");
15
- var _index = require("../../schemas/index.js");
15
+ var _indexts = require("../../schemas/index.js");
16
16
  function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) {
17
17
  try {
18
18
  var info = gen[key](arg);
@@ -150,14 +150,14 @@ function _ts_generator(thisArg, body) {
150
150
  }
151
151
  var AuthRequiredBranchSchema = _oauthgoogle.schemas.AuthRequiredBranchSchema;
152
152
  var inputSchema = _zod.z.object({
153
- id: _index.SpreadsheetIdSchema,
154
- gid: _index.SheetGidSchema,
155
- ranges: _zod.z.array(_index.A1NotationSchema).min(1).describe('A1 notation ranges to clear (e.g., ["A1:B5", "D3:D10"]). Clears values only, preserves formatting.')
153
+ id: _indexts.SpreadsheetIdSchema,
154
+ gid: _indexts.SheetGidSchema,
155
+ ranges: _zod.z.array(_indexts.A1NotationSchema).min(1).describe('A1 notation ranges to clear (e.g., ["A1:B5", "D3:D10"]). Clears values only, preserves formatting.')
156
156
  });
157
157
  var successBranchSchema = _zod.z.object({
158
158
  type: _zod.z.literal('success'),
159
- id: _index.SpreadsheetIdOutput,
160
- gid: _index.SheetGidOutput,
159
+ id: _indexts.SpreadsheetIdOutput,
160
+ gid: _indexts.SheetGidOutput,
161
161
  spreadsheetTitle: _zod.z.string().describe('Title of the spreadsheet'),
162
162
  spreadsheetUrl: _zod.z.string().describe('URL of the spreadsheet'),
163
163
  sheetTitle: _zod.z.string().describe('Title of the sheet'),
@@ -1 +1 @@
1
- {"version":3,"sources":["/Users/kevin/Dev/Projects/ai/mcp-z/servers/mcp-sheets/src/mcp/tools/values-clear.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 { A1NotationSchema, SheetGidOutput, SheetGidSchema, SpreadsheetIdOutput, SpreadsheetIdSchema } from '../../schemas/index.js';\n\nconst inputSchema = z.object({\n id: SpreadsheetIdSchema,\n gid: SheetGidSchema,\n ranges: z.array(A1NotationSchema).min(1).describe('A1 notation ranges to clear (e.g., [\"A1:B5\", \"D3:D10\"]). Clears values only, preserves formatting.'),\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 clearedRanges: z.array(z.string()).describe('A1 notation ranges that were cleared'),\n});\n\nconst outputSchema = z.discriminatedUnion('type', [successBranchSchema, AuthRequiredBranchSchema]);\n\nconst config = {\n description: 'Clear cell values from one or more ranges. Clears values only - preserves formatting, validation, and other cell properties. Use a1-notation prompt for range syntax.',\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, ranges }: Input, extra: EnrichedExtra): Promise<CallToolResult> {\n const logger = extra.logger;\n logger.info('sheets.values.clear called', { id, gid, rangeCount: ranges.length });\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 clear', { id, gid, rangeCount: ranges.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 // Prefix ranges with sheet title\n const prefixedRanges = ranges.map((range) => `${sheetTitle}!${range}`);\n\n logger.info('sheets.values.clear executing', { spreadsheetId: id, sheetTitle, prefixedRanges });\n\n // Use batchClear for efficiency (works for single or multiple ranges)\n const clearResponse = await sheets.spreadsheets.values.batchClear({\n spreadsheetId: id,\n requestBody: {\n ranges: prefixedRanges,\n },\n });\n\n const clearedRanges = clearResponse.data.clearedRanges || [];\n\n logger.info('sheets.values.clear completed successfully', {\n spreadsheetId: id,\n sheetTitle,\n clearedRangesCount: clearedRanges.length,\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 clearedRanges,\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('Clear operation failed', { id, gid, rangeCount: ranges.length, error: message });\n\n throw new McpError(ErrorCode.InternalError, `Error clearing values: ${message}`, {\n stack: error instanceof Error ? error.stack : undefined,\n });\n }\n}\n\nexport default function createTool() {\n return {\n name: 'values-clear',\n config,\n handler,\n } satisfies ToolModule;\n}\n"],"names":["createTool","AuthRequiredBranchSchema","schemas","inputSchema","z","object","id","SpreadsheetIdSchema","gid","SheetGidSchema","ranges","array","A1NotationSchema","min","describe","successBranchSchema","type","literal","SpreadsheetIdOutput","SheetGidOutput","spreadsheetTitle","string","spreadsheetUrl","sheetTitle","sheetUrl","clearedRanges","outputSchema","discriminatedUnion","config","description","result","handler","extra","logger","spreadsheetData","sheet","sheets","spreadsheetResponse","sheetGid","prefixedRanges","clearResponse","error","message","info","rangeCount","length","google","version","auth","authContext","spreadsheets","get","spreadsheetId","fields","data","properties","title","find","s","String","sheetId","McpError","ErrorCode","InvalidParams","map","range","values","batchClear","requestBody","clearedRangesCount","content","text","JSON","stringify","structuredContent","Error","InternalError","stack","undefined","name"],"mappings":";;;;+BAoHA;;;eAAwBA;;;2BAnHA;qBAMY;0BACb;mBACL;qBACyF;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAP3G,IAAM,AAAEC,2BAA6BC,oBAAO,CAApCD;AASR,IAAME,cAAcC,MAAC,CAACC,MAAM,CAAC;IAC3BC,IAAIC,0BAAmB;IACvBC,KAAKC,qBAAc;IACnBC,QAAQN,MAAC,C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B,MAAM,CAACC,UAAU,CAAC;4BAChEf,eAAe9C;4BACf8D,aAAa;gCACX1D,QAAQ6B;4BACV;wBACF;;;oBALMC,gBAAgB;oBAOhBf,gBAAgBe,cAAcc,IAAI,CAAC7B,aAAa;oBAEtDQ,OAAOU,IAAI,CAAC,8CAA8C;wBACxDS,eAAe9C;wBACfiB,YAAAA;wBACA8C,oBAAoB5C,cAAcoB,MAAM;oBAC1C;oBAEMf,SAAiB;wBACrBd,MAAM;wBACNV,IAAAA;wBACAE,KAAKmD,OAAOrB;wBACZlB,kBAAkBA,oBAAoB;wBACtCE,gBAAgBA,kBAAkB;wBAClCC,YAAAA;wBACAC,UAAAA;wBACAC,eAAAA;oBACF;oBAEA;;wBAAO;4BACL6C,OAAO;gCAAG;oCAAEtD,MAAM;oCAAiBuD,MAAMC,KAAKC,SAAS,CAAC3C;gCAAQ;;4BAChE4C,mBAAmB;gCAAE5C,QAAAA;4BAAO;wBAC9B;;;oBACOW;oBACDC,UAAUD,AAAK,YAALA,OAAiBkC,SAAQlC,MAAMC,OAAO,GAAGiB,OAAOlB;oBAChER,OAAOQ,KAAK,CAAC,0BAA0B;wBAAEnC,IAAAA;wBAAIE,KAAAA;wBAAKoC,YAAYlC,OAAOmC,MAAM;wBAAEJ,OAAOC;oBAAQ;oBAE5F,MAAM,IAAImB,eAAQ,CAACC,gBAAS,CAACc,aAAa,EAAE,AAAC,0BAAiC,OAARlC,UAAW;wBAC/EmC,OAAOpC,AAAK,YAALA,OAAiBkC,SAAQlC,MAAMoC,KAAK,GAAGC;oBAChD;;;;;;;IAEJ;;AAEe,SAAS9E;IACtB,OAAO;QACL+E,MAAM;QACNnD,QAAAA;QACAG,SAAAA;IACF;AACF"}
1
+ {"version":3,"sources":["/Users/kevin/Dev/Projects/mcp-z/mcp-sheets/src/mcp/tools/values-clear.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 { A1NotationSchema, SheetGidOutput, SheetGidSchema, SpreadsheetIdOutput, SpreadsheetIdSchema } from '../../schemas/index.ts';\n\nconst inputSchema = z.object({\n id: SpreadsheetIdSchema,\n gid: SheetGidSchema,\n ranges: z.array(A1NotationSchema).min(1).describe('A1 notation ranges to clear (e.g., [\"A1:B5\", \"D3:D10\"]). Clears values only, preserves formatting.'),\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 clearedRanges: z.array(z.string()).describe('A1 notation ranges that were cleared'),\n});\n\nconst outputSchema = z.discriminatedUnion('type', [successBranchSchema, AuthRequiredBranchSchema]);\n\nconst config = {\n description: 'Clear cell values from one or more ranges. Clears values only - preserves formatting, validation, and other cell properties. Use a1-notation prompt for range syntax.',\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, ranges }: Input, extra: EnrichedExtra): Promise<CallToolResult> {\n const logger = extra.logger;\n logger.info('sheets.values.clear called', { id, gid, rangeCount: ranges.length });\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 clear', { id, gid, rangeCount: ranges.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 // Prefix ranges with sheet title\n const prefixedRanges = ranges.map((range) => `${sheetTitle}!${range}`);\n\n logger.info('sheets.values.clear executing', { spreadsheetId: id, sheetTitle, prefixedRanges });\n\n // Use batchClear for efficiency (works for single or multiple ranges)\n const clearResponse = await sheets.spreadsheets.values.batchClear({\n spreadsheetId: id,\n requestBody: {\n ranges: prefixedRanges,\n },\n });\n\n const clearedRanges = clearResponse.data.clearedRanges || [];\n\n logger.info('sheets.values.clear completed successfully', {\n spreadsheetId: id,\n sheetTitle,\n clearedRangesCount: clearedRanges.length,\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 clearedRanges,\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('Clear operation failed', { id, gid, rangeCount: ranges.length, error: message });\n\n throw new McpError(ErrorCode.InternalError, `Error clearing values: ${message}`, {\n stack: error instanceof Error ? error.stack : undefined,\n });\n }\n}\n\nexport default function createTool() {\n return {\n name: 'values-clear',\n config,\n handler,\n } satisfies ToolModule;\n}\n"],"names":["createTool","AuthRequiredBranchSchema","schemas","inputSchema","z","object","id","SpreadsheetIdSchema","gid","SheetGidSchema","ranges","array","A1NotationSchema","min","describe","successBranchSchema","type","literal","SpreadsheetIdOutput","SheetGidOutput","spreadsheetTitle","string","spreadsheetUrl","sheetTitle","sheetUrl","clearedRanges","outputSchema","discriminatedUnion","config","description","result","handler","extra","logger","spreadsheetData","sheet","sheets","spreadsheetResponse","sheetGid","prefixedRanges","clearResponse","error","message","info","rangeCount","length","google","version","auth","authContext","spreadsheets","get","spreadsheetId","fields","data","properties","title","find","s","String","sheetId","McpError","ErrorCode","InvalidParams","map","range","values","batchClear","requestBody","clearedRangesCount","content","text","JSON","stringify","structuredContent","Error","InternalError","stack","undefined","name"],"mappings":";;;;+BAoHA;;;eAAwBA;;;2BAnHA;qBAMY;0BACb;mBACL;uBACyF;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAP3G,IAAM,AAAEC,2BAA6BC,oBAAO,CAApCD;AASR,IAAME,cAAcC,MAAC,CAACC,MAAM,CAAC;IAC3BC,IAAIC,4BAAmB;IACvBC,KAAKC,uBAAc;IACnBC,QAAQN,MAAC,CAACO,KAAK,CAACC,yBAAgB,EAAEC,GAAG,CAAC,GAAGC,QAAQ,CAAC;AACpD;AAEA,IAAMC,sBAAsBX,MAAC,CAACC,MAAM,CAAC;IACnCW,MAAMZ,MAAC,CAACa,OAAO,CAAC;IAChBX,IAAIY,4BAAmB;IACvBV,KAAKW,uBAAc;IACnBC,kBAAkBhB,MAAC,CAACiB,MAAM,GAAGP,QAAQ,CAAC;IACtCQ,gBAAgBlB,MAAC,CAACiB,MAAM,GAAGP,QAAQ,CAAC;IACpCS,YAAYnB,MAAC,CAACiB,MAAM,GAAGP,QAAQ,CAAC;IAChCU,UAAUpB,MAAC,CAACiB,MAAM,GAAGP,QAAQ,CAAC;IAC9BW,eAAerB,MAAC,CAACO,KAAK,CAACP,MAAC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;oCAAEtD,MAAM;oCAAiBuD,MAAMC,KAAKC,SAAS,CAAC3C;gCAAQ;;4BAChE4C,mBAAmB;gCAAE5C,QAAAA;4BAAO;wBAC9B;;;oBACOW;oBACDC,UAAUD,AAAK,YAALA,OAAiBkC,SAAQlC,MAAMC,OAAO,GAAGiB,OAAOlB;oBAChER,OAAOQ,KAAK,CAAC,0BAA0B;wBAAEnC,IAAAA;wBAAIE,KAAAA;wBAAKoC,YAAYlC,OAAOmC,MAAM;wBAAEJ,OAAOC;oBAAQ;oBAE5F,MAAM,IAAImB,eAAQ,CAACC,gBAAS,CAACc,aAAa,EAAE,AAAC,0BAAiC,OAARlC,UAAW;wBAC/EmC,OAAOpC,AAAK,YAALA,OAAiBkC,SAAQlC,MAAMoC,KAAK,GAAGC;oBAChD;;;;;;;IAEJ;;AAEe,SAAS9E;IACtB,OAAO;QACL+E,MAAM;QACNnD,QAAAA;QACAG,SAAAA;IACF;AACF"}
@@ -13,8 +13,8 @@ var _types = require("@modelcontextprotocol/sdk/types.js");
13
13
  var _csvparse = require("csv-parse");
14
14
  var _googleapis = require("googleapis");
15
15
  var _zod = require("zod");
16
- var _index = require("../../schemas/index.js");
17
- var _csvstreaming = require("../../spreadsheet/csv-streaming.js");
16
+ var _indexts = require("../../schemas/index.js");
17
+ var _csvstreamingts = require("../../spreadsheet/csv-streaming.js");
18
18
  function _async_iterator(iterable) {
19
19
  var method, async, sync, retry = 2;
20
20
  for("undefined" != typeof Symbol && (async = Symbol.asyncIterator, sync = Symbol.iterator); retry--;){
@@ -194,10 +194,10 @@ function _ts_generator(thisArg, body) {
194
194
  var AuthRequiredBranchSchema = _oauthgoogle.schemas.AuthRequiredBranchSchema;
195
195
  /** Batch size for Sheets API calls (1000 rows × avg 10 cols = 10K cells, well under 40K limit) */ var BATCH_SIZE = 1000;
196
196
  var inputSchema = _zod.z.object({
197
- id: _index.SpreadsheetIdSchema,
198
- gid: _index.SheetGidSchema,
197
+ id: _indexts.SpreadsheetIdSchema,
198
+ gid: _indexts.SheetGidSchema,
199
199
  sourceUri: _zod.z.string().trim().min(1).describe('CSV file URI (file://, http://, https://)'),
200
- startRange: _index.A1NotationSchema.default('A1').describe('Top-left cell where CSV data starts (default: A1)'),
200
+ startRange: _indexts.A1NotationSchema.default('A1').describe('Top-left cell where CSV data starts (default: A1)'),
201
201
  valueInputOption: _zod.z.enum([
202
202
  'RAW',
203
203
  'USER_ENTERED'
@@ -206,8 +206,8 @@ var inputSchema = _zod.z.object({
206
206
  });
207
207
  var successBranchSchema = _zod.z.object({
208
208
  type: _zod.z.literal('success'),
209
- id: _index.SpreadsheetIdOutput,
210
- gid: _index.SheetGidOutput,
209
+ id: _indexts.SpreadsheetIdOutput,
210
+ gid: _indexts.SheetGidOutput,
211
211
  spreadsheetTitle: _zod.z.string().describe('Spreadsheet title'),
212
212
  spreadsheetUrl: _zod.z.string().describe('Spreadsheet URL'),
213
213
  sheetTitle: _zod.z.string().describe('Sheet title'),
@@ -281,7 +281,7 @@ function handler(_0, _1) {
281
281
  totalCols = 0;
282
282
  return [
283
283
  4,
284
- (0, _csvstreaming.getCsvReadStream)(sourceUri)
284
+ (0, _csvstreamingts.getCsvReadStream)(sourceUri)
285
285
  ];
286
286
  case 3:
287
287
  readStream = _state.sent();
@@ -1 +1 @@
1
- {"version":3,"sources":["/Users/kevin/Dev/Projects/ai/mcp-z/servers/mcp-sheets/src/mcp/tools/values-csv-update.ts"],"sourcesContent":["/** Import CSV data to Google Sheets with range-based update (no deduplication) */\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 { google } from 'googleapis';\nimport { z } from 'zod';\nimport { A1NotationSchema, SheetGidOutput, SheetGidSchema, SpreadsheetIdOutput, SpreadsheetIdSchema } from '../../schemas/index.js';\nimport { getCsvReadStream } from '../../spreadsheet/csv-streaming.js';\n\n/** Batch size for Sheets API calls (1000 rows × avg 10 cols = 10K cells, well under 40K limit) */\nconst BATCH_SIZE = 1000;\n\nconst inputSchema = z.object({\n id: SpreadsheetIdSchema,\n gid: SheetGidSchema,\n sourceUri: z.string().trim().min(1).describe('CSV file URI (file://, http://, https://)'),\n startRange: A1NotationSchema.default('A1').describe('Top-left cell where CSV data starts (default: A1)'),\n valueInputOption: z.enum(['RAW', 'USER_ENTERED']).default('USER_ENTERED').describe('How to interpret values (RAW = exact, USER_ENTERED = parse formulas/dates)'),\n sourceHasHeaders: z.boolean().default(true).describe('First row is headers (metadata) - exclude from data range. Set to false to include first row as data.'),\n});\n\nconst successBranchSchema = z.object({\n type: z.literal('success'),\n id: SpreadsheetIdOutput,\n gid: SheetGidOutput,\n spreadsheetTitle: z.string().describe('Spreadsheet title'),\n spreadsheetUrl: z.string().describe('Spreadsheet URL'),\n sheetTitle: z.string().describe('Sheet title'),\n sheetUrl: z.string().describe('Sheet URL'),\n updatedRange: z.string().describe('A1 notation range that was updated'),\n updatedRows: z.number().describe('Number of rows updated'),\n updatedColumns: z.number().describe('Number of columns updated'),\n updatedCells: z.number().describe('Number of cells updated'),\n});\n\nconst outputSchema = z.discriminatedUnion('type', [successBranchSchema, AuthRequiredBranchSchema]);\n\nconst config = {\n description: 'Import CSV to sheet range. Overwrites existing data at startRange. Use rows-csv-append for database-style appends with deduplication.',\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, sourceUri, startRange, valueInputOption = 'USER_ENTERED', sourceHasHeaders }: Input, extra: EnrichedExtra): Promise<CallToolResult> {\n const logger = extra.logger;\n logger.info('sheets.values.csv-update called', { id, gid, sourceUri, startRange, valueInputOption, sourceHasHeaders });\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\n // Find the sheet by gid\n const sheet = spreadsheetData.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 // Streaming CSV processing state\n let sourceHeaders: string[] = [];\n const allRows: (string | number | boolean | null)[][] = [];\n let totalCols = 0;\n\n // Get readable stream from CSV URI (no temp files!)\n const readStream = await getCsvReadStream(sourceUri);\n\n // Create CSV parser with native streaming\n const parser = readStream.pipe(\n parse({\n columns: !!sourceHasHeaders, // Parse first row as column names if source has 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 // Stream and collect all rows (with batching for very large files)\n for await (const record of parser) {\n if (sourceHasHeaders) {\n // Extract source headers from first record\n if (sourceHeaders.length === 0) {\n sourceHeaders = Object.keys(record as Record<string, unknown>);\n totalCols = sourceHeaders.length;\n logger.info('sheets.values.csv-update source headers', { sourceHeaders, totalCols });\n }\n\n // Convert record to row array (exclude source headers from data range)\n // CSV values are strings/numbers/booleans/nulls from the parser\n const row = sourceHeaders.map((header) => (record as Record<string, string | number | boolean | null>)[header] ?? null);\n allRows.push(row);\n } else {\n // sourceHasHeaders=false: record is an array, include all rows (including first row)\n const row = record as (string | number | boolean | null)[];\n allRows.push(row);\n\n if (totalCols === 0) {\n totalCols = row.length;\n }\n }\n }\n\n if (allRows.length === 0) {\n throw new McpError(ErrorCode.InvalidParams, 'CSV file is empty');\n }\n\n // Prepare data for update (all rows)\n const dataToWrite: (string | number | boolean | null)[][] = allRows;\n\n // For large datasets, use batchUpdate to write in chunks\n // This respects the 40K cell limit per request\n const batchRequests = [];\n const currentRow = startRange.match(/[A-Z]+(\\d+)/)?.[1] || '1';\n let currentRowNum = Number.parseInt(currentRow, 10);\n\n for (let i = 0; i < dataToWrite.length; i += BATCH_SIZE) {\n const batchData = dataToWrite.slice(i, i + BATCH_SIZE);\n const batchRange = `${sheetTitle}!${startRange.match(/[A-Z]+/)?.[0]}${currentRowNum}`;\n\n batchRequests.push({\n range: batchRange,\n values: batchData,\n });\n\n currentRowNum += batchData.length;\n }\n\n logger.info('sheets.values.csv-update batching', { totalBatches: batchRequests.length, batchSize: BATCH_SIZE });\n\n // Execute batch update\n const batchUpdateResponse = await sheets.spreadsheets.values.batchUpdate({\n spreadsheetId: id,\n requestBody: {\n valueInputOption,\n data: batchRequests,\n },\n });\n\n const totalUpdatedCells = batchUpdateResponse.data.totalUpdatedCells || 0;\n const totalUpdatedRows = batchUpdateResponse.data.totalUpdatedRows || 0;\n const totalUpdatedColumns = batchUpdateResponse.data.totalUpdatedColumns || 0;\n const firstUpdatedRange = batchUpdateResponse.data.responses?.[0]?.updatedRange || `${sheetTitle}!${startRange}`;\n\n logger.info('sheets.values.csv-update completed', { id, gid: sheet.properties.sheetId, updatedRange: firstUpdatedRange, updatedRows: totalUpdatedRows, sourceUri });\n\n const result: Output = {\n type: 'success' as const,\n id,\n gid: String(sheet.properties.sheetId ?? ''),\n spreadsheetTitle: spreadsheetData.properties?.title ?? '',\n spreadsheetUrl: spreadsheetData.spreadsheetUrl ?? `https://docs.google.com/spreadsheets/d/${id}`,\n sheetTitle,\n sheetUrl: `https://docs.google.com/spreadsheets/d/${id}/edit#gid=${sheet.properties.sheetId}`,\n updatedRange: firstUpdatedRange,\n updatedRows: totalUpdatedRows,\n updatedColumns: totalUpdatedColumns,\n updatedCells: totalUpdatedCells,\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.values.csv-update error', { error: message });\n\n throw new McpError(ErrorCode.InternalError, `Error updating values from CSV: ${message}`, {\n stack: error instanceof Error ? error.stack : undefined,\n });\n }\n}\n\nexport default function createTool() {\n return {\n name: 'values-csv-update',\n config,\n handler,\n } satisfies ToolModule;\n}\n"],"names":["createTool","AuthRequiredBranchSchema","schemas","BATCH_SIZE","inputSchema","z","object","id","SpreadsheetIdSchema","gid","SheetGidSchema","sourceUri","string","trim","min","describe","startRange","A1NotationSchema","default","valueInputOption","enum","sourceHasHeaders","boolean","successBranchSchema","type","literal","SpreadsheetIdOutput","SheetGidOutput","spreadsheetTitle","spreadsheetUrl","sheetTitle","sheetUrl","updatedRange","updatedRows","number","updatedColumns","updatedCells","outputSchema","discriminatedUnion","config","description","result","handler","extra","logger","sheet","spreadsheetData","batchUpdateResponse","sheets","spreadsheetResponse","sourceHeaders","allRows","totalCols","readStream","parser","dataToWrite","batchRequests","currentRow","currentRowNum","i","batchData","batchRange","totalUpdatedCells","totalUpdatedRows","totalUpdatedColumns","firstUpdatedRange","error","message","info","google","version","auth","authContext","spreadsheets","get","spreadsheetId","fields","data","find","s","String","properties","sheetId","McpError","ErrorCode","InvalidParams","title","getCsvReadStream","pipe","parse","columns","skip_empty_lines","cast","relax_column_count","record","length","Object","keys","row","map","header","push","match","Number","parseInt","slice","range","values","totalBatches","batchSize","batchUpdate","requestBody","responses","content","text","JSON","stringify","structuredContent","Error","InternalError","stack","undefined","name"],"mappings":"AAAA,gFAAgF;;;;+BAiMhF;;;eAAwBA;;;2BA9LA;qBAMY;wBACd;0BACC;mBACL;qBACyF;4BAC1E;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AATjC,IAAM,AA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AM;QACNnF,QAAAA;QACAG,SAAAA;IACF;AACF"}
1
+ {"version":3,"sources":["/Users/kevin/Dev/Projects/mcp-z/mcp-sheets/src/mcp/tools/values-csv-update.ts"],"sourcesContent":["/** Import CSV data to Google Sheets with range-based update (no deduplication) */\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 { google } from 'googleapis';\nimport { z } from 'zod';\nimport { A1NotationSchema, SheetGidOutput, SheetGidSchema, SpreadsheetIdOutput, SpreadsheetIdSchema } from '../../schemas/index.ts';\nimport { getCsvReadStream } from '../../spreadsheet/csv-streaming.ts';\n\n/** Batch size for Sheets API calls (1000 rows × avg 10 cols = 10K cells, well under 40K limit) */\nconst BATCH_SIZE = 1000;\n\nconst inputSchema = z.object({\n id: SpreadsheetIdSchema,\n gid: SheetGidSchema,\n sourceUri: z.string().trim().min(1).describe('CSV file URI (file://, http://, https://)'),\n startRange: A1NotationSchema.default('A1').describe('Top-left cell where CSV data starts (default: A1)'),\n valueInputOption: z.enum(['RAW', 'USER_ENTERED']).default('USER_ENTERED').describe('How to interpret values (RAW = exact, USER_ENTERED = parse formulas/dates)'),\n sourceHasHeaders: z.boolean().default(true).describe('First row is headers (metadata) - exclude from data range. Set to false to include first row as data.'),\n});\n\nconst successBranchSchema = z.object({\n type: z.literal('success'),\n id: SpreadsheetIdOutput,\n gid: SheetGidOutput,\n spreadsheetTitle: z.string().describe('Spreadsheet title'),\n spreadsheetUrl: z.string().describe('Spreadsheet URL'),\n sheetTitle: z.string().describe('Sheet title'),\n sheetUrl: z.string().describe('Sheet URL'),\n updatedRange: z.string().describe('A1 notation range that was updated'),\n updatedRows: z.number().describe('Number of rows updated'),\n updatedColumns: z.number().describe('Number of columns updated'),\n updatedCells: z.number().describe('Number of cells updated'),\n});\n\nconst outputSchema = z.discriminatedUnion('type', [successBranchSchema, AuthRequiredBranchSchema]);\n\nconst config = {\n description: 'Import CSV to sheet range. Overwrites existing data at startRange. Use rows-csv-append for database-style appends with deduplication.',\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, sourceUri, startRange, valueInputOption = 'USER_ENTERED', sourceHasHeaders }: Input, extra: EnrichedExtra): Promise<CallToolResult> {\n const logger = extra.logger;\n logger.info('sheets.values.csv-update called', { id, gid, sourceUri, startRange, valueInputOption, sourceHasHeaders });\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\n // Find the sheet by gid\n const sheet = spreadsheetData.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 // Streaming CSV processing state\n let sourceHeaders: string[] = [];\n const allRows: (string | number | boolean | null)[][] = [];\n let totalCols = 0;\n\n // Get readable stream from CSV URI (no temp files!)\n const readStream = await getCsvReadStream(sourceUri);\n\n // Create CSV parser with native streaming\n const parser = readStream.pipe(\n parse({\n columns: !!sourceHasHeaders, // Parse first row as column names if source has 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 // Stream and collect all rows (with batching for very large files)\n for await (const record of parser) {\n if (sourceHasHeaders) {\n // Extract source headers from first record\n if (sourceHeaders.length === 0) {\n sourceHeaders = Object.keys(record as Record<string, unknown>);\n totalCols = sourceHeaders.length;\n logger.info('sheets.values.csv-update source headers', { sourceHeaders, totalCols });\n }\n\n // Convert record to row array (exclude source headers from data range)\n // CSV values are strings/numbers/booleans/nulls from the parser\n const row = sourceHeaders.map((header) => (record as Record<string, string | number | boolean | null>)[header] ?? null);\n allRows.push(row);\n } else {\n // sourceHasHeaders=false: record is an array, include all rows (including first row)\n const row = record as (string | number | boolean | null)[];\n allRows.push(row);\n\n if (totalCols === 0) {\n totalCols = row.length;\n }\n }\n }\n\n if (allRows.length === 0) {\n throw new McpError(ErrorCode.InvalidParams, 'CSV file is empty');\n }\n\n // Prepare data for update (all rows)\n const dataToWrite: (string | number | boolean | null)[][] = allRows;\n\n // For large datasets, use batchUpdate to write in chunks\n // This respects the 40K cell limit per request\n const batchRequests = [];\n const currentRow = startRange.match(/[A-Z]+(\\d+)/)?.[1] || '1';\n let currentRowNum = Number.parseInt(currentRow, 10);\n\n for (let i = 0; i < dataToWrite.length; i += BATCH_SIZE) {\n const batchData = dataToWrite.slice(i, i + BATCH_SIZE);\n const batchRange = `${sheetTitle}!${startRange.match(/[A-Z]+/)?.[0]}${currentRowNum}`;\n\n batchRequests.push({\n range: batchRange,\n values: batchData,\n });\n\n currentRowNum += batchData.length;\n }\n\n logger.info('sheets.values.csv-update batching', { totalBatches: batchRequests.length, batchSize: BATCH_SIZE });\n\n // Execute batch update\n const batchUpdateResponse = await sheets.spreadsheets.values.batchUpdate({\n spreadsheetId: id,\n requestBody: {\n valueInputOption,\n data: batchRequests,\n },\n });\n\n const totalUpdatedCells = batchUpdateResponse.data.totalUpdatedCells || 0;\n const totalUpdatedRows = batchUpdateResponse.data.totalUpdatedRows || 0;\n const totalUpdatedColumns = batchUpdateResponse.data.totalUpdatedColumns || 0;\n const firstUpdatedRange = batchUpdateResponse.data.responses?.[0]?.updatedRange || `${sheetTitle}!${startRange}`;\n\n logger.info('sheets.values.csv-update completed', { id, gid: sheet.properties.sheetId, updatedRange: firstUpdatedRange, updatedRows: totalUpdatedRows, sourceUri });\n\n const result: Output = {\n type: 'success' as const,\n id,\n gid: String(sheet.properties.sheetId ?? ''),\n spreadsheetTitle: spreadsheetData.properties?.title ?? '',\n spreadsheetUrl: spreadsheetData.spreadsheetUrl ?? `https://docs.google.com/spreadsheets/d/${id}`,\n sheetTitle,\n sheetUrl: `https://docs.google.com/spreadsheets/d/${id}/edit#gid=${sheet.properties.sheetId}`,\n updatedRange: firstUpdatedRange,\n updatedRows: totalUpdatedRows,\n updatedColumns: totalUpdatedColumns,\n updatedCells: totalUpdatedCells,\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.values.csv-update error', { error: message });\n\n throw new McpError(ErrorCode.InternalError, `Error updating values from CSV: ${message}`, {\n stack: error instanceof Error ? error.stack : undefined,\n });\n }\n}\n\nexport default function createTool() {\n return {\n name: 'values-csv-update',\n config,\n handler,\n } satisfies ToolModule;\n}\n"],"names":["createTool","AuthRequiredBranchSchema","schemas","BATCH_SIZE","inputSchema","z","object","id","SpreadsheetIdSchema","gid","SheetGidSchema","sourceUri","string","trim","min","describe","startRange","A1NotationSchema","default","valueInputOption","enum","sourceHasHeaders","boolean","successBranchSchema","type","literal","SpreadsheetIdOutput","SheetGidOutput","spreadsheetTitle","spreadsheetUrl","sheetTitle","sheetUrl","updatedRange","updatedRows","number","updatedColumns","updatedCells","outputSchema","discriminatedUnion","config","description","result","handler","extra","logger","sheet","spreadsheetData","batchUpdateResponse","sheets","spreadsheetResponse","sourceHeaders","allRows","totalCols","readStream","parser","dataToWrite","batchRequests","currentRow","currentRowNum","i","batchData","batchRange","totalUpdatedCells","totalUpdatedRows","totalUpdatedColumns","firstUpdatedRange","error","message","info","google","version","auth","authContext","spreadsheets","get","spreadsheetId","fields","data","find","s","String","properties","sheetId","McpError","ErrorCode","InvalidParams","title","getCsvReadStream","pipe","parse","columns","skip_empty_lines","cast","relax_column_count","record","length","Object","keys","row","map","header","push","match","Number","parseInt","slice","range","values","totalBatches","batchSize","batchUpdate","requestBody","responses","content","text","JSON","stringify","structuredContent","Error","InternalError","stack","undefined","name"],"mappings":"AAAA,gFAAgF;;;;+BAiMhF;;;eAAwBA;;;2BA9LA;qBAMY;wBACd;0BACC;mBACL;uBACyF;8BAC1E;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AATjC,IAAM,AAAEC,2BAA6BC,oBAAO,CAApCD;AAWR,gGAAgG,GAChG,IAAME,aAAa;AAEnB,IAAMC,cAAcC,MAAC,CAACC,MAAM,CAAC;IAC3BC,IAAIC,4BAAmB;IACvBC,KAAKC,uBAAc;IACnBC,WAAWN,MAAC,CAACO,MAAM,GAAGC,IAAI,GAAGC,GAAG,CAAC,GAAGC,QAAQ,CAAC;IAC7CC,YAAYC,yBAAgB,CAACC,OAAO,CAAC,MAAMH,QAAQ,CAAC;IACpDI,kBAAkBd,MAAC,CAACe,IAAI,CAAC;QAAC;QAAO;KAAe,EAAEF,OAAO,CAAC,gBAAgBH,QAAQ,CAAC;IACnFM,kBAAkBhB,MAAC,CAACiB,OAAO,GAAGJ,OAAO,CAAC,MAAMH,QAAQ,CAAC;AACvD;AAEA,IAAMQ,sBAAsBlB,MAAC,CAACC,MAAM,CAAC;IACnCkB,MAAMnB,MAAC,CAACoB,OAAO,CAAC;IAChBlB,IAAImB,4BAAmB;IACvBjB,KAAKkB,uBAAc;IACnBC,kBAAkBvB,MAAC,CAACO,MAAM,GAAGG,QAAQ,CAAC;IACtCc,gBAAgBxB,MAAC,CAACO,MAAM,GAAGG,QAAQ,CAAC;IACpCe,YAAYzB,MAAC,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F,MAAM;oCAAiB0F,MAAMC,KAAKC,SAAS,CAAC3E;gCAAQ;;4BAChE4E,mBAAmB;gCAAE5E,QAAAA;4BAAO;wBAC9B;;;oBACOyB;oBACDC,UAAUD,AAAK,YAALA,OAAiBoD,SAAQpD,MAAMC,OAAO,GAAGa,OAAOd;oBAChEtB,OAAOsB,KAAK,CAAC,kCAAkC;wBAAEA,OAAOC;oBAAQ;oBAEhE,MAAM,IAAIgB,eAAQ,CAACC,gBAAS,CAACmC,aAAa,EAAE,AAAC,mCAA0C,OAARpD,UAAW;wBACxFqD,OAAOtD,AAAK,YAALA,OAAiBoD,SAAQpD,MAAMsD,KAAK,GAAGC;oBAChD;;;;;;;IAEJ;;AAEe,SAASzH;IACtB,OAAO;QACL0H,MAAM;QACNnF,QAAAA;QACAG,SAAAA;IACF;AACF"}
@@ -12,8 +12,8 @@ var _oauthgoogle = require("@mcp-z/oauth-google");
12
12
  var _types = require("@modelcontextprotocol/sdk/types.js");
13
13
  var _googleapis = require("googleapis");
14
14
  var _zod = require("zod");
15
- var _index = require("../../schemas/index.js");
16
- var _rangeoperations = require("../../spreadsheet/range-operations.js");
15
+ var _indexts = require("../../schemas/index.js");
16
+ var _rangeoperationsts = require("../../spreadsheet/range-operations.js");
17
17
  function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) {
18
18
  try {
19
19
  var info = gen[key](arg);
@@ -179,12 +179,12 @@ function _ts_generator(thisArg, body) {
179
179
  }
180
180
  var AuthRequiredBranchSchema = _oauthgoogle.schemas.AuthRequiredBranchSchema;
181
181
  var inputSchema = _zod.z.object({
182
- id: _index.SpreadsheetIdSchema,
182
+ id: _indexts.SpreadsheetIdSchema,
183
183
  find: _zod.z.string().min(1).describe('Text or regex pattern to find'),
184
184
  replacement: _zod.z.string().describe('Replacement text. Use $1, $2 for regex capture groups. Empty string deletes matches.'),
185
185
  // Scope - defaults to all sheets if neither specified
186
- gid: _index.SheetGidSchema.optional().describe('Limit to specific sheet. If omitted, searches all sheets.'),
187
- range: _index.A1NotationSchema.optional().describe('Limit to specific A1 range within the sheet (requires gid)'),
186
+ gid: _indexts.SheetGidSchema.optional().describe('Limit to specific sheet. If omitted, searches all sheets.'),
187
+ range: _indexts.A1NotationSchema.optional().describe('Limit to specific A1 range within the sheet (requires gid)'),
188
188
  // Match options
189
189
  matchCase: _zod.z.boolean().optional().describe('Case-sensitive matching'),
190
190
  matchEntireCell: _zod.z.boolean().optional().describe('Only match entire cell content'),
@@ -197,7 +197,7 @@ var inputSchema = _zod.z.object({
197
197
  });
198
198
  var successBranchSchema = _zod.z.object({
199
199
  type: _zod.z.literal('success'),
200
- id: _index.SpreadsheetIdOutput,
200
+ id: _indexts.SpreadsheetIdOutput,
201
201
  spreadsheetUrl: _zod.z.string().describe('URL of the spreadsheet'),
202
202
  occurrencesChanged: _zod.z.number().int().nonnegative().describe('Total replacements made'),
203
203
  valuesChanged: _zod.z.number().int().nonnegative().describe('Number of non-formula cells changed'),
@@ -293,8 +293,8 @@ function handler(_0, _1) {
293
293
  findReplaceRequest.sheetId = sheetId;
294
294
  } else {
295
295
  // gid + range = search specific range
296
- rangeRef = (0, _rangeoperations.parseA1Notation)(range);
297
- findReplaceRequest.range = (0, _rangeoperations.rangeReferenceToGridRange)(rangeRef, sheetId);
296
+ rangeRef = (0, _rangeoperationsts.parseA1Notation)(range);
297
+ findReplaceRequest.range = (0, _rangeoperationsts.rangeReferenceToGridRange)(rangeRef, sheetId);
298
298
  }
299
299
  _state.label = 4;
300
300
  case 4:
@@ -1 +1 @@
1
- {"version":3,"sources":["/Users/kevin/Dev/Projects/ai/mcp-z/servers/mcp-sheets/src/mcp/tools/values-replace.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, type sheets_v4 } from 'googleapis';\nimport { z } from 'zod';\nimport { A1NotationSchema, SheetGidSchema, SpreadsheetIdOutput, SpreadsheetIdSchema } from '../../schemas/index.js';\nimport { parseA1Notation, rangeReferenceToGridRange } from '../../spreadsheet/range-operations.js';\n\nconst inputSchema = z\n .object({\n id: SpreadsheetIdSchema,\n find: z.string().min(1).describe('Text or regex pattern to find'),\n replacement: z.string().describe('Replacement text. Use $1, $2 for regex capture groups. Empty string deletes matches.'),\n\n // Scope - defaults to all sheets if neither specified\n gid: SheetGidSchema.optional().describe('Limit to specific sheet. If omitted, searches all sheets.'),\n range: A1NotationSchema.optional().describe('Limit to specific A1 range within the sheet (requires gid)'),\n\n // Match options\n matchCase: z.boolean().optional().describe('Case-sensitive matching'),\n matchEntireCell: z.boolean().optional().describe('Only match entire cell content'),\n searchByRegex: z.boolean().optional().describe('Treat find as RE2 regex'),\n includeFormulas: z.boolean().optional().describe('Search within formula text'),\n })\n .refine((data) => !(data.range && !data.gid), { message: 'range requires gid' });\n\nconst successBranchSchema = z.object({\n type: z.literal('success'),\n id: SpreadsheetIdOutput,\n spreadsheetUrl: z.string().describe('URL of the spreadsheet'),\n occurrencesChanged: z.number().int().nonnegative().describe('Total replacements made'),\n valuesChanged: z.number().int().nonnegative().describe('Number of non-formula cells changed'),\n formulasChanged: z.number().int().nonnegative().describe('Number of formula cells changed'),\n rowsChanged: z.number().int().nonnegative().describe('Number of rows with replacements'),\n sheetsChanged: z.number().int().nonnegative().describe('Number of sheets with replacements'),\n});\n\nconst outputSchema = z.discriminatedUnion('type', [successBranchSchema, AuthRequiredBranchSchema]);\n\nconst config = {\n description: 'Find and replace text across a spreadsheet. Searches all sheets by default, or limit with gid/range. Supports regex with capture groups ($1, $2).',\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, find, replacement, gid, range, matchCase, matchEntireCell, searchByRegex, includeFormulas }: Input, extra: EnrichedExtra): Promise<CallToolResult> {\n const logger = extra.logger;\n logger.info('sheets.values-replace called', { id, find, replacement, gid, range });\n\n try {\n const sheets = google.sheets({ version: 'v4', auth: extra.authContext.auth });\n\n // Build FindReplaceRequest - only include defined options\n const findReplaceRequest: sheets_v4.Schema$FindReplaceRequest = {\n find,\n replacement,\n ...(matchCase !== undefined && { matchCase }),\n ...(matchEntireCell !== undefined && { matchEntireCell }),\n ...(searchByRegex !== undefined && { searchByRegex }),\n ...(includeFormulas !== undefined && { includeFormulas }),\n };\n\n // Set scope based on gid/range\n if (!gid) {\n // No gid = search all sheets\n findReplaceRequest.allSheets = true;\n } else {\n // Need to resolve sheet to get numeric sheetId\n const spreadsheetResponse = await sheets.spreadsheets.get({\n spreadsheetId: id,\n fields: 'sheets.properties.sheetId,sheets.properties.title',\n });\n\n const sheet = spreadsheetResponse.data.sheets?.find((s) => String(s.properties?.sheetId) === gid);\n if (!sheet) {\n throw new McpError(ErrorCode.InvalidParams, `Sheet not found: ${gid}`);\n }\n\n // Note: sheetId can be 0 which is falsy, so check explicitly for undefined/null\n const sheetId = sheet.properties?.sheetId;\n if (sheetId === undefined || sheetId === null) {\n throw new McpError(ErrorCode.InternalError, 'Sheet properties not available');\n }\n\n if (!range) {\n // gid but no range = search specific sheet\n findReplaceRequest.sheetId = sheetId;\n } else {\n // gid + range = search specific range\n const rangeRef = parseA1Notation(range);\n findReplaceRequest.range = rangeReferenceToGridRange(rangeRef, sheetId);\n }\n }\n\n // Execute batchUpdate\n const response = await sheets.spreadsheets.batchUpdate({\n spreadsheetId: id,\n requestBody: {\n requests: [{ findReplace: findReplaceRequest }],\n },\n });\n\n const findReplaceResponse = response.data.replies?.[0]?.findReplace;\n const spreadsheetUrl = `https://docs.google.com/spreadsheets/d/${id}/edit`;\n\n logger.info('sheets.values-replace completed', {\n occurrencesChanged: findReplaceResponse?.occurrencesChanged ?? 0,\n sheetsChanged: findReplaceResponse?.sheetsChanged ?? 0,\n });\n\n const result: Output = {\n type: 'success' as const,\n id,\n spreadsheetUrl,\n occurrencesChanged: findReplaceResponse?.occurrencesChanged ?? 0,\n valuesChanged: findReplaceResponse?.valuesChanged ?? 0,\n formulasChanged: findReplaceResponse?.formulasChanged ?? 0,\n rowsChanged: findReplaceResponse?.rowsChanged ?? 0,\n sheetsChanged: findReplaceResponse?.sheetsChanged ?? 0,\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('Replace operation failed', {\n id,\n find,\n replacement,\n gid,\n range,\n error: message,\n });\n\n throw new McpError(ErrorCode.InternalError, `Error replacing values: ${message}`, {\n stack: error instanceof Error ? error.stack : undefined,\n });\n }\n}\n\nexport default function createTool() {\n return {\n name: 'values-replace',\n config,\n handler,\n } satisfies ToolModule;\n}\n"],"names":["createTool","AuthRequiredBranchSchema","schemas","inputSchema","z","object","id","SpreadsheetIdSchema","find","string","min","describe","replacement","gid","SheetGidSchema","optional","range","A1NotationSchema","matchCase","boolean","matchEntireCell","searchByRegex","includeFormulas","refine","data","message","successBranchSchema","type","literal","SpreadsheetIdOutput","spreadsheetUrl","occurrencesChanged","number","int","nonnegative","valuesChanged","formulasChanged","rowsChanged","sheetsChanged","outputSchema","discriminatedUnion","config","description","result","handler","extra","logger","response","sheets","findReplaceRequest","spreadsheetResponse","sheet","sheetId","rangeRef","findReplaceResponse","error","info","google","version","auth","authContext","undefined","allSheets","spreadsheets","get","spreadsheetId","fields","s","String","properties","McpError","ErrorCode","InvalidParams","InternalError","parseA1Notation","rangeReferenceToGridRange","batchUpdate","requestBody","requests","findReplace","replies","content","text","JSON","stringify","structuredContent","Error","stack","name"],"mappings":";;;;+BA2JA;;;eAAwBA;;;2BA1JA;qBAMY;0BACG;mBACrB;qBACyE;+BAChC;;;;;;;;;;;;;;;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AA4B;wBACvCjD,IAAAA;wBACAE,MAAAA;wBACAI,aAAAA;wBACAC,KAAAA;wBACAG,OAAAA;wBACAuC,OAAO9B;oBACT;oBAEA,MAAM,IAAI6C,eAAQ,CAACC,gBAAS,CAACE,aAAa,EAAE,AAAC,2BAAkC,OAARhD,UAAW;wBAChF8D,OAAOhC,AAAK,YAALA,OAAiB+B,SAAQ/B,MAAMgC,KAAK,GAAG1B;oBAChD;;;;;;;IAEJ;;AAEe,SAAS7D;IACtB,OAAO;QACLwF,MAAM;QACN/C,QAAAA;QACAG,SAAAA;IACF;AACF"}
1
+ {"version":3,"sources":["/Users/kevin/Dev/Projects/mcp-z/mcp-sheets/src/mcp/tools/values-replace.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, type sheets_v4 } from 'googleapis';\nimport { z } from 'zod';\nimport { A1NotationSchema, SheetGidSchema, SpreadsheetIdOutput, SpreadsheetIdSchema } from '../../schemas/index.ts';\nimport { parseA1Notation, rangeReferenceToGridRange } from '../../spreadsheet/range-operations.ts';\n\nconst inputSchema = z\n .object({\n id: SpreadsheetIdSchema,\n find: z.string().min(1).describe('Text or regex pattern to find'),\n replacement: z.string().describe('Replacement text. Use $1, $2 for regex capture groups. Empty string deletes matches.'),\n\n // Scope - defaults to all sheets if neither specified\n gid: SheetGidSchema.optional().describe('Limit to specific sheet. If omitted, searches all sheets.'),\n range: A1NotationSchema.optional().describe('Limit to specific A1 range within the sheet (requires gid)'),\n\n // Match options\n matchCase: z.boolean().optional().describe('Case-sensitive matching'),\n matchEntireCell: z.boolean().optional().describe('Only match entire cell content'),\n searchByRegex: z.boolean().optional().describe('Treat find as RE2 regex'),\n includeFormulas: z.boolean().optional().describe('Search within formula text'),\n })\n .refine((data) => !(data.range && !data.gid), { message: 'range requires gid' });\n\nconst successBranchSchema = z.object({\n type: z.literal('success'),\n id: SpreadsheetIdOutput,\n spreadsheetUrl: z.string().describe('URL of the spreadsheet'),\n occurrencesChanged: z.number().int().nonnegative().describe('Total replacements made'),\n valuesChanged: z.number().int().nonnegative().describe('Number of non-formula cells changed'),\n formulasChanged: z.number().int().nonnegative().describe('Number of formula cells changed'),\n rowsChanged: z.number().int().nonnegative().describe('Number of rows with replacements'),\n sheetsChanged: z.number().int().nonnegative().describe('Number of sheets with replacements'),\n});\n\nconst outputSchema = z.discriminatedUnion('type', [successBranchSchema, AuthRequiredBranchSchema]);\n\nconst config = {\n description: 'Find and replace text across a spreadsheet. Searches all sheets by default, or limit with gid/range. Supports regex with capture groups ($1, $2).',\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, find, replacement, gid, range, matchCase, matchEntireCell, searchByRegex, includeFormulas }: Input, extra: EnrichedExtra): Promise<CallToolResult> {\n const logger = extra.logger;\n logger.info('sheets.values-replace called', { id, find, replacement, gid, range });\n\n try {\n const sheets = google.sheets({ version: 'v4', auth: extra.authContext.auth });\n\n // Build FindReplaceRequest - only include defined options\n const findReplaceRequest: sheets_v4.Schema$FindReplaceRequest = {\n find,\n replacement,\n ...(matchCase !== undefined && { matchCase }),\n ...(matchEntireCell !== undefined && { matchEntireCell }),\n ...(searchByRegex !== undefined && { searchByRegex }),\n ...(includeFormulas !== undefined && { includeFormulas }),\n };\n\n // Set scope based on gid/range\n if (!gid) {\n // No gid = search all sheets\n findReplaceRequest.allSheets = true;\n } else {\n // Need to resolve sheet to get numeric sheetId\n const spreadsheetResponse = await sheets.spreadsheets.get({\n spreadsheetId: id,\n fields: 'sheets.properties.sheetId,sheets.properties.title',\n });\n\n const sheet = spreadsheetResponse.data.sheets?.find((s) => String(s.properties?.sheetId) === gid);\n if (!sheet) {\n throw new McpError(ErrorCode.InvalidParams, `Sheet not found: ${gid}`);\n }\n\n // Note: sheetId can be 0 which is falsy, so check explicitly for undefined/null\n const sheetId = sheet.properties?.sheetId;\n if (sheetId === undefined || sheetId === null) {\n throw new McpError(ErrorCode.InternalError, 'Sheet properties not available');\n }\n\n if (!range) {\n // gid but no range = search specific sheet\n findReplaceRequest.sheetId = sheetId;\n } else {\n // gid + range = search specific range\n const rangeRef = parseA1Notation(range);\n findReplaceRequest.range = rangeReferenceToGridRange(rangeRef, sheetId);\n }\n }\n\n // Execute batchUpdate\n const response = await sheets.spreadsheets.batchUpdate({\n spreadsheetId: id,\n requestBody: {\n requests: [{ findReplace: findReplaceRequest }],\n },\n });\n\n const findReplaceResponse = response.data.replies?.[0]?.findReplace;\n const spreadsheetUrl = `https://docs.google.com/spreadsheets/d/${id}/edit`;\n\n logger.info('sheets.values-replace completed', {\n occurrencesChanged: findReplaceResponse?.occurrencesChanged ?? 0,\n sheetsChanged: findReplaceResponse?.sheetsChanged ?? 0,\n });\n\n const result: Output = {\n type: 'success' as const,\n id,\n spreadsheetUrl,\n occurrencesChanged: findReplaceResponse?.occurrencesChanged ?? 0,\n valuesChanged: findReplaceResponse?.valuesChanged ?? 0,\n formulasChanged: findReplaceResponse?.formulasChanged ?? 0,\n rowsChanged: findReplaceResponse?.rowsChanged ?? 0,\n sheetsChanged: findReplaceResponse?.sheetsChanged ?? 0,\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('Replace operation failed', {\n id,\n find,\n replacement,\n gid,\n range,\n error: message,\n });\n\n throw new McpError(ErrorCode.InternalError, `Error replacing values: ${message}`, {\n stack: error instanceof Error ? error.stack : undefined,\n });\n }\n}\n\nexport default function createTool() {\n return {\n name: 'values-replace',\n config,\n handler,\n } satisfies ToolModule;\n}\n"],"names":["createTool","AuthRequiredBranchSchema","schemas","inputSchema","z","object","id","SpreadsheetIdSchema","find","string","min","describe","replacement","gid","SheetGidSchema","optional","range","A1NotationSchema","matchCase","boolean","matchEntireCell","searchByRegex","includeFormulas","refine","data","message","successBranchSchema","type","literal","SpreadsheetIdOutput","spreadsheetUrl","occurrencesChanged","number","int","nonnegative","valuesChanged","formulasChanged","rowsChanged","sheetsChanged","outputSchema","discriminatedUnion","config","description","result","handler","extra","logger","response","sheets","findReplaceRequest","spreadsheetResponse","sheet","sheetId","rangeRef","findReplaceResponse","error","info","google","version","auth","authContext","undefined","allSheets","spreadsheets","get","spreadsheetId","fields","s","String","properties","McpError","ErrorCode","InvalidParams","InternalError","parseA1Notation","rangeReferenceToGridRange","batchUpdate","requestBody","requests","findReplace","replies","content","text","JSON","stringify","structuredContent","Error","stack","name"],"mappings":";;;;+BA2JA;;;eAAwBA;;;2BA1JA;qBAMY;0BACG;mBACrB;uBACyE;iCAChC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAR3D,IAAM,AAAEC,2BAA6BC,oBAAO,CAApCD;AAUR,IAAME,cAAcC,MAAC,CAClBC,MAAM,CAAC;IACNC,IAAIC,4BAAmB;IACvBC,MAAMJ,MAAC,CAACK,MAAM,GAAGC,GAAG,CAAC,GAAGC,QAAQ,CAAC;IACjCC,aAAaR,MAAC,CAACK,MAAM,GAAGE,QAAQ,CAAC;IAEjC,sDAAsD;IACtDE,KAAKC,uBAAc,CAACC,QAAQ,GAAGJ,QAAQ,CAAC;IACxCK,OAAOC,yBAAgB,CAACF,QAAQ,GAAGJ,QAAQ,CAAC;IAE5C,gBAAgB;IAChBO,WAAWd,MAAC,CAACe,O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