@mcp-z/mcp-sheets 1.1.0 → 1.1.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/index.js +10 -24
- package/dist/cjs/index.js.map +1 -1
- package/dist/cjs/lib/create-store.js +2 -5
- package/dist/cjs/lib/create-store.js.map +1 -1
- package/dist/cjs/mcp/index.js +8 -19
- package/dist/cjs/mcp/prompts/a1-notation.js +2 -5
- package/dist/cjs/mcp/prompts/a1-notation.js.map +1 -1
- package/dist/cjs/mcp/resources/spreadsheet.js +2 -5
- package/dist/cjs/mcp/resources/spreadsheet.js.map +1 -1
- package/dist/cjs/mcp/tools/cells-format.js +3 -8
- package/dist/cjs/mcp/tools/cells-format.js.map +1 -1
- package/dist/cjs/mcp/tools/chart-create.js +3 -8
- package/dist/cjs/mcp/tools/chart-create.js.map +1 -1
- package/dist/cjs/mcp/tools/columns-get.js +3 -8
- package/dist/cjs/mcp/tools/columns-get.js.map +1 -1
- package/dist/cjs/mcp/tools/columns-update.js +3 -8
- package/dist/cjs/mcp/tools/columns-update.js.map +1 -1
- package/dist/cjs/mcp/tools/csv-get-columns.js +3 -8
- package/dist/cjs/mcp/tools/csv-get-columns.js.map +1 -1
- package/dist/cjs/mcp/tools/dimensions-batch-update.js +3 -8
- package/dist/cjs/mcp/tools/dimensions-batch-update.js.map +1 -1
- package/dist/cjs/mcp/tools/dimensions-move.js +3 -8
- package/dist/cjs/mcp/tools/dimensions-move.js.map +1 -1
- package/dist/cjs/mcp/tools/lib/dimension-operations.js +5 -5
- package/dist/cjs/mcp/tools/rows-append.js +3 -8
- package/dist/cjs/mcp/tools/rows-append.js.map +1 -1
- package/dist/cjs/mcp/tools/rows-csv-append.js +31 -28
- package/dist/cjs/mcp/tools/rows-csv-append.js.map +1 -1
- package/dist/cjs/mcp/tools/rows-get.js +3 -8
- package/dist/cjs/mcp/tools/rows-get.js.map +1 -1
- package/dist/cjs/mcp/tools/sheet-copy-to.js +3 -8
- package/dist/cjs/mcp/tools/sheet-copy-to.js.map +1 -1
- package/dist/cjs/mcp/tools/sheet-copy.js +4 -11
- package/dist/cjs/mcp/tools/sheet-copy.js.map +1 -1
- package/dist/cjs/mcp/tools/sheet-create.js +3 -8
- package/dist/cjs/mcp/tools/sheet-create.js.map +1 -1
- package/dist/cjs/mcp/tools/sheet-delete.js +4 -11
- package/dist/cjs/mcp/tools/sheet-delete.js.map +1 -1
- package/dist/cjs/mcp/tools/sheet-find.js +3 -8
- package/dist/cjs/mcp/tools/sheet-find.js.map +1 -1
- package/dist/cjs/mcp/tools/sheet-rename.js +3 -8
- package/dist/cjs/mcp/tools/sheet-rename.js.map +1 -1
- package/dist/cjs/mcp/tools/spreadsheet-copy.js +4 -11
- package/dist/cjs/mcp/tools/spreadsheet-copy.js.map +1 -1
- package/dist/cjs/mcp/tools/spreadsheet-create.js +3 -8
- package/dist/cjs/mcp/tools/spreadsheet-create.js.map +1 -1
- package/dist/cjs/mcp/tools/spreadsheet-find.js +4 -11
- package/dist/cjs/mcp/tools/spreadsheet-find.js.map +1 -1
- package/dist/cjs/mcp/tools/spreadsheet-rename.js +3 -8
- package/dist/cjs/mcp/tools/spreadsheet-rename.js.map +1 -1
- package/dist/cjs/mcp/tools/validation-set.js +3 -8
- package/dist/cjs/mcp/tools/validation-set.js.map +1 -1
- package/dist/cjs/mcp/tools/values-batch-update.js +3 -8
- package/dist/cjs/mcp/tools/values-batch-update.js.map +1 -1
- package/dist/cjs/mcp/tools/values-clear.js +3 -8
- package/dist/cjs/mcp/tools/values-clear.js.map +1 -1
- package/dist/cjs/mcp/tools/values-csv-update.js +3 -8
- package/dist/cjs/mcp/tools/values-csv-update.js.map +1 -1
- package/dist/cjs/mcp/tools/values-markdown-update.js +3 -8
- package/dist/cjs/mcp/tools/values-markdown-update.js.map +1 -1
- package/dist/cjs/mcp/tools/values-replace.js +4 -11
- package/dist/cjs/mcp/tools/values-replace.js.map +1 -1
- package/dist/cjs/mcp/tools/values-search.js +4 -11
- package/dist/cjs/mcp/tools/values-search.js.map +1 -1
- package/dist/cjs/setup/config.js +11 -25
- package/dist/cjs/setup/config.js.map +1 -1
- package/dist/cjs/setup/http.js +14 -15
- package/dist/cjs/setup/http.js.map +1 -1
- package/dist/cjs/setup/oauth-google.js +6 -14
- package/dist/cjs/setup/oauth-google.js.map +1 -1
- package/dist/cjs/setup/runtime.js +10 -24
- package/dist/cjs/setup/runtime.js.map +1 -1
- package/dist/cjs/setup/stdio.js +14 -15
- package/dist/cjs/setup/stdio.js.map +1 -1
- package/dist/cjs/spreadsheet/csv-streaming.js +2 -5
- package/dist/cjs/spreadsheet/csv-streaming.js.map +1 -1
- package/dist/cjs/spreadsheet/data-operations.js +15 -18
- package/dist/cjs/spreadsheet/data-operations.js.map +1 -1
- package/dist/cjs/spreadsheet/markdown-runs.js +5 -3
- package/dist/cjs/spreadsheet/markdown-runs.js.map +1 -1
- package/dist/cjs/spreadsheet/range-operations.js +1 -1
- package/dist/cjs/spreadsheet/sheet-operations.js +14 -15
- package/dist/cjs/spreadsheet/sheet-operations.js.map +1 -1
- package/dist/cjs/spreadsheet/spreadsheet-management.js +2 -5
- package/dist/cjs/spreadsheet/spreadsheet-management.js.map +1 -1
- package/package.json +12 -8
|
@@ -74,11 +74,8 @@ function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) {
|
|
|
74
74
|
reject(error);
|
|
75
75
|
return;
|
|
76
76
|
}
|
|
77
|
-
if (info.done)
|
|
78
|
-
|
|
79
|
-
} else {
|
|
80
|
-
Promise.resolve(value).then(_next, _throw);
|
|
81
|
-
}
|
|
77
|
+
if (info.done) resolve(value);
|
|
78
|
+
else Promise.resolve(value).then(_next, _throw);
|
|
82
79
|
}
|
|
83
80
|
function _async_to_generator(fn) {
|
|
84
81
|
return function() {
|
|
@@ -99,27 +96,19 @@ function _instanceof(left, right) {
|
|
|
99
96
|
"@swc/helpers - instanceof";
|
|
100
97
|
if (right != null && typeof Symbol !== "undefined" && right[Symbol.hasInstance]) {
|
|
101
98
|
return !!right[Symbol.hasInstance](left);
|
|
102
|
-
} else
|
|
103
|
-
return left instanceof right;
|
|
104
|
-
}
|
|
99
|
+
} else return left instanceof right;
|
|
105
100
|
}
|
|
106
101
|
function _iterable_to_array(iter) {
|
|
107
|
-
if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null)
|
|
102
|
+
if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) {
|
|
103
|
+
return Array.from(iter);
|
|
104
|
+
}
|
|
108
105
|
}
|
|
109
106
|
function _non_iterable_spread() {
|
|
110
|
-
throw new TypeError("Invalid attempt to spread non-iterable instance
|
|
107
|
+
throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
|
|
111
108
|
}
|
|
112
109
|
function _to_consumable_array(arr) {
|
|
113
110
|
return _array_without_holes(arr) || _iterable_to_array(arr) || _unsupported_iterable_to_array(arr) || _non_iterable_spread();
|
|
114
111
|
}
|
|
115
|
-
function _unsupported_iterable_to_array(o, minLen) {
|
|
116
|
-
if (!o) return;
|
|
117
|
-
if (typeof o === "string") return _array_like_to_array(o, minLen);
|
|
118
|
-
var n = Object.prototype.toString.call(o).slice(8, -1);
|
|
119
|
-
if (n === "Object" && o.constructor) n = o.constructor.name;
|
|
120
|
-
if (n === "Map" || n === "Set") return Array.from(n);
|
|
121
|
-
if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _array_like_to_array(o, minLen);
|
|
122
|
-
}
|
|
123
112
|
function _ts_generator(thisArg, body) {
|
|
124
113
|
var f, y, t, _ = {
|
|
125
114
|
label: 0,
|
|
@@ -221,18 +210,32 @@ function _ts_generator(thisArg, body) {
|
|
|
221
210
|
}
|
|
222
211
|
function _ts_values(o) {
|
|
223
212
|
var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
|
|
224
|
-
if (m)
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
213
|
+
if (m) {
|
|
214
|
+
return m.call(o);
|
|
215
|
+
}
|
|
216
|
+
if (o && typeof o.length === "number") {
|
|
217
|
+
return {
|
|
218
|
+
next: function() {
|
|
219
|
+
if (o && i >= o.length) {
|
|
220
|
+
o = void 0;
|
|
221
|
+
}
|
|
222
|
+
return {
|
|
223
|
+
value: o && o[i++],
|
|
224
|
+
done: !o
|
|
225
|
+
};
|
|
226
|
+
}
|
|
227
|
+
};
|
|
228
|
+
}
|
|
234
229
|
throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
|
|
235
230
|
}
|
|
231
|
+
function _unsupported_iterable_to_array(o, minLen) {
|
|
232
|
+
if (!o) return;
|
|
233
|
+
if (typeof o === "string") return _array_like_to_array(o, minLen);
|
|
234
|
+
var n = Object.prototype.toString.call(o).slice(8, -1);
|
|
235
|
+
if (n === "Object" && o.constructor) n = o.constructor.name;
|
|
236
|
+
if (n === "Map" || n === "Set") return Array.from(n);
|
|
237
|
+
if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _array_like_to_array(o, minLen);
|
|
238
|
+
}
|
|
236
239
|
var AuthRequiredBranchSchema = _oauthgoogle.schemas.AuthRequiredBranchSchema;
|
|
237
240
|
// Header mapping schema: source/target can be string (name) or number (0-based index)
|
|
238
241
|
var HeaderMapItemSchema = _zod.z.object({
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["/Users/kevin/Dev/OpenSource/ai/mcp-z/mcp-sheets/src/mcp/tools/rows-csv-append.ts"],"sourcesContent":["/** Import CSV data to Google Sheets with database-style row append and 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 { SheetGidOutput, SheetGidSchema, SpreadsheetIdOutput, SpreadsheetIdSchema } from '../../schemas/index.ts';\nimport { getCsvReadStream } from '../../spreadsheet/csv-streaming.ts';\nimport { buildDeduplicationKey } from '../../spreadsheet/deduplication-utils.ts';\nimport { ensureTabAndHeaders } from '../../spreadsheet/sheet-operations.ts';\n\n// Header mapping schema: source/target can be string (name) or number (0-based index)\nconst HeaderMapItemSchema = z.object({\n source: z.union([z.string(), z.number().int().min(0)]).describe('CSV column: header name (string) or 0-based index (number)'),\n target: z.union([z.string(), z.number().int().min(0)]).describe('Sheet column: header name (string) or 0-based index (number)'),\n});\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 sourceHasHeaders: z.boolean().default(true).describe('Source has header row for column name mapping. Set to false for data-only sources (numeric indices required).'),\n headerMap: z.array(HeaderMapItemSchema).describe('Column mappings from CSV to sheet'),\n deduplicateBy: z\n .array(z.union([z.string(), z.number().int().min(0)]))\n .optional()\n .describe('Sheet columns for deduplication (names or indices)'),\n});\n\nconst successBranchSchema = z.object({\n type: z.literal('success'),\n id: SpreadsheetIdOutput,\n gid: SheetGidOutput,\n sheetTitle: z.string().describe('Sheet tab name'),\n updatedRows: z.number().describe('Number of rows appended'),\n rowsSkipped: z.number().optional().describe('Number of duplicate rows skipped'),\n sheetUrl: z.string().optional().describe('URL to view the sheet'),\n});\n\nconst outputSchema = z.discriminatedUnion('type', [successBranchSchema, AuthRequiredBranchSchema]);\n\nconst config = {\n description: 'Import CSV to Google Sheets with column mapping and optional deduplication. Streams data for large files.',\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/** Batch size for Sheets API calls (1000 rows × 12 cols = 12K cells, well under 40K limit) */\nconst BATCH_SIZE = 1000;\n\n/**\n * Resolve column reference to numeric index\n * @param ref Column reference (string name or number index)\n * @param headers Header row (null when sourceHasHeaders=false)\n * @param sourceHasHeaders Whether headers are present\n * @returns 0-based column index\n */\nfunction resolveColumnReference(ref: string | number, headers: string[] | null, sourceHasHeaders: boolean, context: string): number {\n // If number, use directly as 0-based index\n if (typeof ref === 'number') {\n if (ref < 0) {\n throw new Error(`${context}: Column index must be >= 0, got ${ref}`);\n }\n return ref;\n }\n\n // If string, must be header name\n if (!sourceHasHeaders || !headers) {\n throw new Error(`${context}: String column reference \"${ref}\" requires sourceHasHeaders=true. Use numeric index when sourceHasHeaders=false.`);\n }\n\n const index = headers.indexOf(ref);\n if (index === -1) {\n throw new Error(`${context}: Header \"${ref}\" not found in [${headers.join(', ')}]`);\n }\n\n return index;\n}\n\nasync function handler({ id, gid, sourceUri, sourceHasHeaders, headerMap, deduplicateBy }: Input, extra: EnrichedExtra): Promise<CallToolResult> {\n const logger = extra.logger;\n logger.info('sheets.rows.csv-append called', { id, gid, sourceUri, sourceHasHeaders, headerMap, deduplicateBy });\n\n try {\n if (headerMap.length === 0) {\n throw new McpError(ErrorCode.InvalidParams, 'headerMap cannot be empty');\n }\n\n // Validate: if sourceHasHeaders=false, all references must be numeric\n if (!sourceHasHeaders) {\n for (const { source, target } of headerMap) {\n if (typeof source === 'string') {\n throw new McpError(ErrorCode.InvalidParams, `sourceHasHeaders=false requires numeric indices. Got string source: \"${source}\"`);\n }\n if (typeof target === 'string') {\n throw new McpError(ErrorCode.InvalidParams, `sourceHasHeaders=false requires numeric indices. Got string target: \"${target}\"`);\n }\n }\n if (deduplicateBy) {\n for (const colRef of deduplicateBy) {\n if (typeof colRef === 'string') {\n throw new McpError(ErrorCode.InvalidParams, `sourceHasHeaders=false requires numeric indices in deduplicateBy. Got string: \"${colRef}\"`);\n }\n }\n }\n }\n\n const sheets = google.sheets({ version: 'v4', auth: extra.authContext.auth });\n\n // Get sheet details using the gid\n const spreadsheetResponse = await sheets.spreadsheets.get({\n spreadsheetId: id,\n fields: 'sheets.properties.sheetId,sheets.properties.title',\n });\n\n const sheet = spreadsheetResponse.data.sheets?.find((s) => String(s.properties?.sheetId) === gid);\n\n if (!sheet) {\n throw new McpError(ErrorCode.InvalidParams, 'Sheet not found');\n }\n\n const sheetTitle = sheet?.properties?.title ?? '';\n\n // Determine target headers (for sourceHasHeaders=true) or column count (for sourceHasHeaders=false)\n let sheetHeaders: string[] | null = null;\n let existingKeySet: Set<string> = new Set();\n const keyColumns: (string | number)[] = deduplicateBy || [];\n\n if (sourceHasHeaders) {\n // Extract target header names from headerMap\n const targetHeaderNames = headerMap.map(({ target }) => target).filter((t) => typeof t === 'string') as string[];\n\n // Use ensureTabAndHeaders to setup headers and fetch existing keys\n const headerResult = await ensureTabAndHeaders(sheets, {\n spreadsheetId: id,\n sheetTitle,\n requiredHeader: targetHeaderNames.length > 0 ? targetHeaderNames : null,\n keyColumns: keyColumns.filter((k) => typeof k === 'string') as string[],\n logger,\n });\n\n sheetHeaders = headerResult.header;\n existingKeySet = headerResult.keySet;\n } else {\n // sourceHasHeaders=false: Read existing data for deduplication (if needed)\n if (deduplicateBy && deduplicateBy.length > 0) {\n // Read data in chunks for memory efficiency with large sheets\n const CHUNK_SIZE = 1000;\n let startRow = 1;\n let hasMore = true;\n\n while (hasMore) {\n const endRow = startRow + CHUNK_SIZE - 1;\n const chunkRange = `${sheetTitle}!A${startRow}:ZZZ${endRow}`;\n\n const response = await sheets.spreadsheets.values.get({\n spreadsheetId: id,\n range: chunkRange,\n });\n\n const rows = response.data.values || [];\n\n for (const row of rows) {\n const key = buildDeduplicationKey(row, keyColumns, null, false);\n if (key.replace(/::/g, '') !== '') {\n existingKeySet.add(key);\n }\n }\n\n // Check if there are more rows to read\n if (rows.length < CHUNK_SIZE) {\n hasMore = false;\n } else {\n startRow += CHUNK_SIZE;\n }\n }\n\n logger.info('sheets.rows.csv-append existing keys loaded', { keyCount: existingKeySet.size });\n }\n }\n\n // Streaming CSV processing state\n let sourceHeaders: string[] | null = null;\n let batch: (string | number | boolean | null)[][] = [];\n let totalRows = 0;\n let rowsSkipped = 0;\n\n // Get readable stream from CSV URI (no temp files!)\n const readStream = await getCsvReadStream(sourceUri);\n\n // Create CSV parser\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 // Helper to append batch to Sheets\n const appendBatch = async (rows: (string | number | boolean | null)[][]): Promise<void> => {\n if (rows.length === 0) return;\n\n await sheets.spreadsheets.values.append({\n spreadsheetId: id,\n range: `${sheetTitle}!A:A`,\n valueInputOption: 'USER_ENTERED',\n requestBody: { values: rows, majorDimension: 'ROWS' },\n });\n\n logger.info('sheets.rows.csv-append batch appended', { batchSize: rows.length, totalRows });\n };\n\n // Resolve headerMap to numeric indices (do this after extracting CSV headers)\n let resolvedMap: Array<{ sourceIdx: number; targetIdx: number }> = [];\n\n // Stream and process records\n for await (const record of parser) {\n if (sourceHasHeaders) {\n // Extract source headers from first record\n if (sourceHeaders === null) {\n sourceHeaders = Object.keys(record as Record<string, unknown>);\n logger.info('sheets.rows.csv-append source headers', { sourceHeaders });\n\n // Resolve headerMap now that we have both source and sheet headers\n resolvedMap = headerMap.map(({ source, target }) => ({\n sourceIdx: resolveColumnReference(source, sourceHeaders, sourceHasHeaders, 'headerMap.source'),\n targetIdx: resolveColumnReference(target, sheetHeaders, sourceHasHeaders, 'headerMap.target'),\n }));\n }\n\n // Map source record to sheet row\n const sourceRow = sourceHeaders?.map((h) => (record as Record<string, unknown>)[h] ?? null);\n const maxTargetIdx = Math.max(...resolvedMap.map((m) => m.targetIdx));\n const sheetRow = new Array(maxTargetIdx + 1).fill(null);\n\n for (const { sourceIdx, targetIdx } of resolvedMap) {\n if (sourceRow) {\n sheetRow[targetIdx] = sourceRow[sourceIdx] ?? null;\n }\n }\n\n // Check deduplication\n if (deduplicateBy && deduplicateBy.length > 0) {\n const key = buildDeduplicationKey(sheetRow, keyColumns, sheetHeaders, sourceHasHeaders);\n if (existingKeySet.has(key)) {\n rowsSkipped++;\n continue; // Skip duplicate\n }\n existingKeySet.add(key); // Add to set for future deduplication\n }\n\n // Add to batch\n batch.push(sheetRow);\n totalRows++;\n } else {\n // sourceHasHeaders=false: record is an array (not an object)\n // Resolve map on first row\n if (resolvedMap.length === 0) {\n resolvedMap = headerMap.map(({ source, target }) => ({\n sourceIdx: resolveColumnReference(source, null, sourceHasHeaders, 'headerMap.source'),\n targetIdx: resolveColumnReference(target, null, sourceHasHeaders, 'headerMap.target'),\n }));\n }\n\n const sourceRow = record as unknown[];\n const maxTargetIdx = Math.max(...resolvedMap.map((m) => m.targetIdx));\n const sheetRow = new Array(maxTargetIdx + 1).fill(null);\n\n for (const { sourceIdx, targetIdx } of resolvedMap) {\n if (sourceIdx < sourceRow.length) {\n sheetRow[targetIdx] = sourceRow[sourceIdx] ?? null;\n }\n }\n\n // Check deduplication\n if (deduplicateBy && deduplicateBy.length > 0) {\n const key = buildDeduplicationKey(sheetRow, keyColumns, null, sourceHasHeaders);\n if (existingKeySet.has(key)) {\n rowsSkipped++;\n continue; // Skip duplicate\n }\n existingKeySet.add(key);\n }\n\n // Add to batch\n batch.push(sheetRow);\n totalRows++;\n }\n\n // Append batch when full\n if (batch.length >= BATCH_SIZE) {\n await appendBatch(batch);\n batch = []; // Clear batch\n }\n }\n\n // Flush remaining rows\n if (batch.length > 0) {\n await appendBatch(batch);\n }\n\n logger.info('sheets.rows.csv-append streaming complete', { totalRows, rowsSkipped });\n\n const updatedRows = totalRows;\n\n logger.info('sheets.rows.csv-append completed', { id, gid, updatedRows, rowsSkipped, sourceUri });\n\n const result: Output = {\n type: 'success' as const,\n id,\n gid,\n sheetTitle,\n updatedRows,\n rowsSkipped,\n sheetUrl: `https://docs.google.com/spreadsheets/d/${id}/edit#gid=${gid}`,\n };\n\n return {\n content: [{ type: 'text' as const, text: JSON.stringify(result) }],\n structuredContent: { result },\n };\n } catch (error) {\n const message = error instanceof Error ? error.message : String(error);\n logger.error('sheets.rows.csv-append error', { error: message });\n\n throw new McpError(ErrorCode.InternalError, `Error appending CSV rows: ${message}`, {\n stack: error instanceof Error ? error.stack : undefined,\n });\n }\n}\n\nexport default function createTool() {\n return {\n name: 'rows-csv-append',\n config,\n handler,\n } satisfies ToolModule;\n}\n"],"names":["createTool","AuthRequiredBranchSchema","schemas","HeaderMapItemSchema","z","object","source","union","string","number","int","min","describe","target","inputSchema","id","SpreadsheetIdSchema","gid","SheetGidSchema","sourceUri","trim","sourceHasHeaders","boolean","default","headerMap","array","deduplicateBy","optional","successBranchSchema","type","literal","SpreadsheetIdOutput","SheetGidOutput","sheetTitle","updatedRows","rowsSkipped","sheetUrl","outputSchema","discriminatedUnion","config","description","result","BATCH_SIZE","resolveColumnReference","ref","headers","context","Error","index","indexOf","join","handler","extra","logger","spreadsheetResponse","sheet","colRef","sheets","sheetHeaders","existingKeySet","keyColumns","targetHeaderNames","headerResult","CHUNK_SIZE","startRow","hasMore","endRow","chunkRange","response","rows","row","key","sourceHeaders","batch","totalRows","readStream","parser","appendBatch","resolvedMap","error","message","info","length","McpError","ErrorCode","InvalidParams","google","version","auth","authContext","spreadsheets","get","spreadsheetId","fields","data","find","s","String","properties","sheetId","title","Set","map","filter","t","ensureTabAndHeaders","requiredHeader","k","header","keySet","values","range","buildDeduplicationKey","replace","add","keyCount","size","getCsvReadStream","pipe","parse","columns","skip_empty_lines","cast","relax_column_count","append","valueInputOption","requestBody","majorDimension","batchSize","record","Math","sourceRow","maxTargetIdx","sheetRow","sourceIdx","targetIdx","Object","keys","h","max","m","Array","fill","has","push","content","text","JSON","stringify","structuredContent","InternalError","stack","undefined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Import CSV data to Google Sheets with database-style row append and 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 { SheetGidOutput, SheetGidSchema, SpreadsheetIdOutput, SpreadsheetIdSchema } from '../../schemas/index.ts';\nimport { getCsvReadStream } from '../../spreadsheet/csv-streaming.ts';\nimport { buildDeduplicationKey } from '../../spreadsheet/deduplication-utils.ts';\nimport { ensureTabAndHeaders } from '../../spreadsheet/sheet-operations.ts';\n\n// Header mapping schema: source/target can be string (name) or number (0-based index)\nconst HeaderMapItemSchema = z.object({\n source: z.union([z.string(), z.number().int().min(0)]).describe('CSV column: header name (string) or 0-based index (number)'),\n target: z.union([z.string(), z.number().int().min(0)]).describe('Sheet column: header name (string) or 0-based index (number)'),\n});\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 sourceHasHeaders: z.boolean().default(true).describe('Source has header row for column name mapping. Set to false for data-only sources (numeric indices required).'),\n headerMap: z.array(HeaderMapItemSchema).describe('Column mappings from CSV to sheet'),\n deduplicateBy: z\n .array(z.union([z.string(), z.number().int().min(0)]))\n .optional()\n .describe('Sheet columns for deduplication (names or indices)'),\n});\n\nconst successBranchSchema = z.object({\n type: z.literal('success'),\n id: SpreadsheetIdOutput,\n gid: SheetGidOutput,\n sheetTitle: z.string().describe('Sheet tab name'),\n updatedRows: z.number().describe('Number of rows appended'),\n rowsSkipped: z.number().optional().describe('Number of duplicate rows skipped'),\n sheetUrl: z.string().optional().describe('URL to view the sheet'),\n});\n\nconst outputSchema = z.discriminatedUnion('type', [successBranchSchema, AuthRequiredBranchSchema]);\n\nconst config = {\n description: 'Import CSV to Google Sheets with column mapping and optional deduplication. Streams data for large files.',\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/** Batch size for Sheets API calls (1000 rows × 12 cols = 12K cells, well under 40K limit) */\nconst BATCH_SIZE = 1000;\n\n/**\n * Resolve column reference to numeric index\n * @param ref Column reference (string name or number index)\n * @param headers Header row (null when sourceHasHeaders=false)\n * @param sourceHasHeaders Whether headers are present\n * @returns 0-based column index\n */\nfunction resolveColumnReference(ref: string | number, headers: string[] | null, sourceHasHeaders: boolean, context: string): number {\n // If number, use directly as 0-based index\n if (typeof ref === 'number') {\n if (ref < 0) {\n throw new Error(`${context}: Column index must be >= 0, got ${ref}`);\n }\n return ref;\n }\n\n // If string, must be header name\n if (!sourceHasHeaders || !headers) {\n throw new Error(`${context}: String column reference \"${ref}\" requires sourceHasHeaders=true. Use numeric index when sourceHasHeaders=false.`);\n }\n\n const index = headers.indexOf(ref);\n if (index === -1) {\n throw new Error(`${context}: Header \"${ref}\" not found in [${headers.join(', ')}]`);\n }\n\n return index;\n}\n\nasync function handler({ id, gid, sourceUri, sourceHasHeaders, headerMap, deduplicateBy }: Input, extra: EnrichedExtra): Promise<CallToolResult> {\n const logger = extra.logger;\n logger.info('sheets.rows.csv-append called', { id, gid, sourceUri, sourceHasHeaders, headerMap, deduplicateBy });\n\n try {\n if (headerMap.length === 0) {\n throw new McpError(ErrorCode.InvalidParams, 'headerMap cannot be empty');\n }\n\n // Validate: if sourceHasHeaders=false, all references must be numeric\n if (!sourceHasHeaders) {\n for (const { source, target } of headerMap) {\n if (typeof source === 'string') {\n throw new McpError(ErrorCode.InvalidParams, `sourceHasHeaders=false requires numeric indices. Got string source: \"${source}\"`);\n }\n if (typeof target === 'string') {\n throw new McpError(ErrorCode.InvalidParams, `sourceHasHeaders=false requires numeric indices. Got string target: \"${target}\"`);\n }\n }\n if (deduplicateBy) {\n for (const colRef of deduplicateBy) {\n if (typeof colRef === 'string') {\n throw new McpError(ErrorCode.InvalidParams, `sourceHasHeaders=false requires numeric indices in deduplicateBy. Got string: \"${colRef}\"`);\n }\n }\n }\n }\n\n const sheets = google.sheets({ version: 'v4', auth: extra.authContext.auth });\n\n // Get sheet details using the gid\n const spreadsheetResponse = await sheets.spreadsheets.get({\n spreadsheetId: id,\n fields: 'sheets.properties.sheetId,sheets.properties.title',\n });\n\n const sheet = spreadsheetResponse.data.sheets?.find((s) => String(s.properties?.sheetId) === gid);\n\n if (!sheet) {\n throw new McpError(ErrorCode.InvalidParams, 'Sheet not found');\n }\n\n const sheetTitle = sheet?.properties?.title ?? '';\n\n // Determine target headers (for sourceHasHeaders=true) or column count (for sourceHasHeaders=false)\n let sheetHeaders: string[] | null = null;\n let existingKeySet: Set<string> = new Set();\n const keyColumns: (string | number)[] = deduplicateBy || [];\n\n if (sourceHasHeaders) {\n // Extract target header names from headerMap\n const targetHeaderNames = headerMap.map(({ target }) => target).filter((t) => typeof t === 'string') as string[];\n\n // Use ensureTabAndHeaders to setup headers and fetch existing keys\n const headerResult = await ensureTabAndHeaders(sheets, {\n spreadsheetId: id,\n sheetTitle,\n requiredHeader: targetHeaderNames.length > 0 ? targetHeaderNames : null,\n keyColumns: keyColumns.filter((k) => typeof k === 'string') as string[],\n logger,\n });\n\n sheetHeaders = headerResult.header;\n existingKeySet = headerResult.keySet;\n } else {\n // sourceHasHeaders=false: Read existing data for deduplication (if needed)\n if (deduplicateBy && deduplicateBy.length > 0) {\n // Read data in chunks for memory efficiency with large sheets\n const CHUNK_SIZE = 1000;\n let startRow = 1;\n let hasMore = true;\n\n while (hasMore) {\n const endRow = startRow + CHUNK_SIZE - 1;\n const chunkRange = `${sheetTitle}!A${startRow}:ZZZ${endRow}`;\n\n const response = await sheets.spreadsheets.values.get({\n spreadsheetId: id,\n range: chunkRange,\n });\n\n const rows = response.data.values || [];\n\n for (const row of rows) {\n const key = buildDeduplicationKey(row, keyColumns, null, false);\n if (key.replace(/::/g, '') !== '') {\n existingKeySet.add(key);\n }\n }\n\n // Check if there are more rows to read\n if (rows.length < CHUNK_SIZE) {\n hasMore = false;\n } else {\n startRow += CHUNK_SIZE;\n }\n }\n\n logger.info('sheets.rows.csv-append existing keys loaded', { keyCount: existingKeySet.size });\n }\n }\n\n // Streaming CSV processing state\n let sourceHeaders: string[] | null = null;\n let batch: (string | number | boolean | null)[][] = [];\n let totalRows = 0;\n let rowsSkipped = 0;\n\n // Get readable stream from CSV URI (no temp files!)\n const readStream = await getCsvReadStream(sourceUri);\n\n // Create CSV parser\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 // Helper to append batch to Sheets\n const appendBatch = async (rows: (string | number | boolean | null)[][]): Promise<void> => {\n if (rows.length === 0) return;\n\n await sheets.spreadsheets.values.append({\n spreadsheetId: id,\n range: `${sheetTitle}!A:A`,\n valueInputOption: 'USER_ENTERED',\n requestBody: { values: rows, majorDimension: 'ROWS' },\n });\n\n logger.info('sheets.rows.csv-append batch appended', { batchSize: rows.length, totalRows });\n };\n\n // Resolve headerMap to numeric indices (do this after extracting CSV headers)\n let resolvedMap: Array<{ sourceIdx: number; targetIdx: number }> = [];\n\n // Stream and process records\n for await (const record of parser) {\n if (sourceHasHeaders) {\n // Extract source headers from first record\n if (sourceHeaders === null) {\n sourceHeaders = Object.keys(record as Record<string, unknown>);\n logger.info('sheets.rows.csv-append source headers', { sourceHeaders });\n\n // Resolve headerMap now that we have both source and sheet headers\n resolvedMap = headerMap.map(({ source, target }) => ({\n sourceIdx: resolveColumnReference(source, sourceHeaders, sourceHasHeaders, 'headerMap.source'),\n targetIdx: resolveColumnReference(target, sheetHeaders, sourceHasHeaders, 'headerMap.target'),\n }));\n }\n\n // Map source record to sheet row\n const sourceRow = sourceHeaders?.map((h) => (record as Record<string, unknown>)[h] ?? null);\n const maxTargetIdx = Math.max(...resolvedMap.map((m) => m.targetIdx));\n const sheetRow = new Array(maxTargetIdx + 1).fill(null);\n\n for (const { sourceIdx, targetIdx } of resolvedMap) {\n if (sourceRow) {\n sheetRow[targetIdx] = sourceRow[sourceIdx] ?? null;\n }\n }\n\n // Check deduplication\n if (deduplicateBy && deduplicateBy.length > 0) {\n const key = buildDeduplicationKey(sheetRow, keyColumns, sheetHeaders, sourceHasHeaders);\n if (existingKeySet.has(key)) {\n rowsSkipped++;\n continue; // Skip duplicate\n }\n existingKeySet.add(key); // Add to set for future deduplication\n }\n\n // Add to batch\n batch.push(sheetRow);\n totalRows++;\n } else {\n // sourceHasHeaders=false: record is an array (not an object)\n // Resolve map on first row\n if (resolvedMap.length === 0) {\n resolvedMap = headerMap.map(({ source, target }) => ({\n sourceIdx: resolveColumnReference(source, null, sourceHasHeaders, 'headerMap.source'),\n targetIdx: resolveColumnReference(target, null, sourceHasHeaders, 'headerMap.target'),\n }));\n }\n\n const sourceRow = record as unknown[];\n const maxTargetIdx = Math.max(...resolvedMap.map((m) => m.targetIdx));\n const sheetRow = new Array(maxTargetIdx + 1).fill(null);\n\n for (const { sourceIdx, targetIdx } of resolvedMap) {\n if (sourceIdx < sourceRow.length) {\n sheetRow[targetIdx] = sourceRow[sourceIdx] ?? null;\n }\n }\n\n // Check deduplication\n if (deduplicateBy && deduplicateBy.length > 0) {\n const key = buildDeduplicationKey(sheetRow, keyColumns, null, sourceHasHeaders);\n if (existingKeySet.has(key)) {\n rowsSkipped++;\n continue; // Skip duplicate\n }\n existingKeySet.add(key);\n }\n\n // Add to batch\n batch.push(sheetRow);\n totalRows++;\n }\n\n // Append batch when full\n if (batch.length >= BATCH_SIZE) {\n await appendBatch(batch);\n batch = []; // Clear batch\n }\n }\n\n // Flush remaining rows\n if (batch.length > 0) {\n await appendBatch(batch);\n }\n\n logger.info('sheets.rows.csv-append streaming complete', { totalRows, rowsSkipped });\n\n const updatedRows = totalRows;\n\n logger.info('sheets.rows.csv-append completed', { id, gid, updatedRows, rowsSkipped, sourceUri });\n\n const result: Output = {\n type: 'success' as const,\n id,\n gid,\n sheetTitle,\n updatedRows,\n rowsSkipped,\n sheetUrl: `https://docs.google.com/spreadsheets/d/${id}/edit#gid=${gid}`,\n };\n\n return {\n content: [{ type: 'text' as const, text: JSON.stringify(result) }],\n structuredContent: { result },\n };\n } catch (error) {\n const message = error instanceof Error ? error.message : String(error);\n logger.error('sheets.rows.csv-append error', { error: message });\n\n throw new McpError(ErrorCode.InternalError, `Error appending CSV rows: ${message}`, {\n stack: error instanceof Error ? error.stack : undefined,\n });\n }\n}\n\nexport default function createTool() {\n return {\n name: 'rows-csv-append',\n config,\n handler,\n } satisfies ToolModule;\n}\n"],"names":["createTool","AuthRequiredBranchSchema","schemas","HeaderMapItemSchema","z","object","source","union","string","number","int","min","describe","target","inputSchema","id","SpreadsheetIdSchema","gid","SheetGidSchema","sourceUri","trim","sourceHasHeaders","boolean","default","headerMap","array","deduplicateBy","optional","successBranchSchema","type","literal","SpreadsheetIdOutput","SheetGidOutput","sheetTitle","updatedRows","rowsSkipped","sheetUrl","outputSchema","discriminatedUnion","config","description","result","BATCH_SIZE","resolveColumnReference","ref","headers","context","Error","index","indexOf","join","handler","extra","logger","spreadsheetResponse","sheet","colRef","sheets","sheetHeaders","existingKeySet","keyColumns","targetHeaderNames","headerResult","CHUNK_SIZE","startRow","hasMore","endRow","chunkRange","response","rows","row","key","sourceHeaders","batch","totalRows","readStream","parser","appendBatch","resolvedMap","error","message","info","length","McpError","ErrorCode","InvalidParams","google","version","auth","authContext","spreadsheets","get","spreadsheetId","fields","data","find","s","String","properties","sheetId","title","Set","map","filter","t","ensureTabAndHeaders","requiredHeader","k","header","keySet","values","range","buildDeduplicationKey","replace","add","keyCount","size","getCsvReadStream","pipe","parse","columns","skip_empty_lines","cast","relax_column_count","append","valueInputOption","requestBody","majorDimension","batchSize","record","Math","sourceRow","maxTargetIdx","sheetRow","sourceIdx","targetIdx","Object","keys","h","max","m","Array","fill","has","push","content","text","JSON","stringify","structuredContent","InternalError","stack","undefined","name"],"mappings":"AAAA,sFAAsF;;;;+BA0VtF;;;eAAwBA;;;2BAvVA;qBAMY;wBACd;0BACC;mBACL;uBACuE;8BACxD;oCACK;iCACF;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAXpC,IAAM,AAAEC,2BAA6BC,oBAAO,CAApCD;AAaR,sFAAsF;AACtF,IAAME,sBAAsBC,MAAC,CAACC,MAAM,CAAC;IACnCC,QAAQF,MAAC,CAACG,KAAK,CAAC;QAACH,MAAC,CAACI,MAAM;QAAIJ,MAAC,CAACK,MAAM,GAAGC,GAAG,GAAGC,GAAG,CAAC;KAAG,EAAEC,QAAQ,CAAC;IAChEC,QAAQT,MAAC,CAACG,KAAK,CAAC;QAACH,MAAC,CAACI,MAAM;QAAIJ,MAAC,CAACK,MAAM,GAAGC,GAAG,GAAGC,GAAG,CAAC;KAAG,EAAEC,QAAQ,CAAC;AAClE;AAEA,IAAME,cAAcV,MAAC,CAACC,MAAM,CAAC;IAC3BU,IAAIC,4BAAmB;IACvBC,KAAKC,uBAAc;IACnBC,WAAWf,MAAC,CAACI,MAAM,GAAGY,IAAI,GAAGT,GAAG,CAAC,GAAGC,QAAQ,CAAC;IAC7CS,kBAAkBjB,MAAC,CAACkB,OAAO,GAAGC,OAAO,CAAC,MAAMX,QAAQ,CAAC;IACrDY,WAAWpB,MAAC,CAACqB,KAAK,CAACtB,qBAAqBS,QAAQ,CAAC;IACjDc,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Y,SAAAA;IACF;AACF"}
|
|
@@ -21,11 +21,8 @@ function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) {
|
|
|
21
21
|
reject(error);
|
|
22
22
|
return;
|
|
23
23
|
}
|
|
24
|
-
if (info.done)
|
|
25
|
-
|
|
26
|
-
} else {
|
|
27
|
-
Promise.resolve(value).then(_next, _throw);
|
|
28
|
-
}
|
|
24
|
+
if (info.done) resolve(value);
|
|
25
|
+
else Promise.resolve(value).then(_next, _throw);
|
|
29
26
|
}
|
|
30
27
|
function _async_to_generator(fn) {
|
|
31
28
|
return function() {
|
|
@@ -46,9 +43,7 @@ function _instanceof(left, right) {
|
|
|
46
43
|
"@swc/helpers - instanceof";
|
|
47
44
|
if (right != null && typeof Symbol !== "undefined" && right[Symbol.hasInstance]) {
|
|
48
45
|
return !!right[Symbol.hasInstance](left);
|
|
49
|
-
} else
|
|
50
|
-
return left instanceof right;
|
|
51
|
-
}
|
|
46
|
+
} else return left instanceof right;
|
|
52
47
|
}
|
|
53
48
|
function _ts_generator(thisArg, body) {
|
|
54
49
|
var f, y, t, _ = {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["/Users/kevin/Dev/OpenSource/ai/mcp-z/mcp-sheets/src/mcp/tools/rows-get.ts"],"sourcesContent":["import type { EnrichedExtra } from '@mcp-z/oauth-google';\nimport { schemas } from '@mcp-z/oauth-google';\n\nconst { AuthRequiredBranchSchema } = schemas;\n\nimport type { ToolModule } from '@mcp-z/server';\nimport type { CallToolResult } from '@modelcontextprotocol/sdk/types.js';\nimport { ErrorCode, McpError } from '@modelcontextprotocol/sdk/types.js';\nimport { google } from 'googleapis';\nimport { z } from 'zod';\nimport { SheetCellSchema, SheetGidSchema, SpreadsheetIdSchema } from '../../schemas/index.ts';\n\nconst inputSchema = z.object({\n id: SpreadsheetIdSchema,\n gid: SheetGidSchema,\n range: z.string().min(1).describe('A1 notation range to fetch (e.g., \"B5\", \"A5:D5\", \"B:B\", \"5:5\")'),\n render: z.enum(['FORMATTED_VALUE', 'UNFORMATTED_VALUE', 'FORMULA']).optional().describe('How to render cell values. FORMATTED_VALUE (default): calculated with formatting. UNFORMATTED_VALUE: calculated without formatting. FORMULA: show formula text instead of result.'),\n});\n\n// Success branch schema - uses rows: for consistency with standard vocabulary\nconst successBranchSchema = z.object({\n type: z.literal('success'),\n range: z.string().describe('The A1 notation range that was retrieved'),\n rows: z.array(z.array(SheetCellSchema)).describe('2D array of row data (each inner array is a row)'),\n});\n\n// Output schema with auth_required support\nconst outputSchema = z.discriminatedUnion('type', [successBranchSchema, AuthRequiredBranchSchema]);\n\nconst config = {\n description: 'Fetch row data from a specific range in A1 notation. Best used after values-search to get surrounding context. Use a1-notation prompt for syntax reference.',\n inputSchema,\n outputSchema: z.object({\n result: outputSchema,\n }),\n} as const;\n\nexport type Input = z.infer<typeof inputSchema>;\nexport type Output = z.infer<typeof outputSchema>;\n\nasync function handler({ id, gid, range, render }: Input, extra: EnrichedExtra): Promise<CallToolResult> {\n const logger = extra.logger;\n logger.info('sheets.rows.get called', { id, gid, range, render });\n\n try {\n const sheets = google.sheets({ version: 'v4', auth: extra.authContext.auth });\n\n // Get sheet details using the gid to get sheet title\n const spreadsheetResponse = await sheets.spreadsheets.get({\n spreadsheetId: id,\n fields: 'sheets.properties.sheetId,sheets.properties.title',\n });\n\n const sheet = spreadsheetResponse.data.sheets?.find((s) => String(s.properties?.sheetId) === gid);\n\n if (!sheet) {\n logger.info('sheets.rows.get sheet not found', { id, gid, range });\n throw new McpError(ErrorCode.InvalidParams, `Sheet not found: ${gid}`);\n }\n\n const sheetTitle = sheet.properties?.title ?? '';\n\n // Construct full range with sheet title\n const fullRange = `${sheetTitle}!${range}`;\n\n const response = await sheets.spreadsheets.values.get({\n spreadsheetId: id,\n range: fullRange,\n valueRenderOption: render || 'FORMATTED_VALUE',\n });\n\n const res = response.data;\n const rows = Array.isArray(res.values) ? (res.values as (string | number | boolean | null)[][]) : [];\n\n logger.info('sheets.rows.get success', { id, gid, range, rowCount: rows.length });\n\n const result: Output = {\n type: 'success' as const,\n range: res.range || fullRange,\n rows,\n };\n\n return {\n content: [{ type: 'text' as const, text: JSON.stringify(result) }],\n structuredContent: { result },\n };\n } catch (error) {\n const message = error instanceof Error ? error.message : String(error);\n logger.error('sheets.rows.get error', { error: message });\n\n // Throw McpError for proper MCP error handling\n throw new McpError(ErrorCode.InternalError, `Error getting rows: ${message}`, {\n stack: error instanceof Error ? error.stack : undefined,\n });\n }\n}\n\nexport default function createTool() {\n return {\n name: 'rows-get',\n config,\n handler,\n } satisfies ToolModule;\n}\n"],"names":["createTool","AuthRequiredBranchSchema","schemas","inputSchema","z","object","id","SpreadsheetIdSchema","gid","SheetGidSchema","range","string","min","describe","render","enum","optional","successBranchSchema","type","literal","rows","array","SheetCellSchema","outputSchema","discriminatedUnion","config","description","result","handler","extra","logger","spreadsheetResponse","sheet","sheets","sheetTitle","fullRange","response","res","error","message","info","google","version","auth","authContext","spreadsheets","get","spreadsheetId","fields","data","find","s","String","properties","sheetId","McpError","ErrorCode","InvalidParams","title","values","valueRenderOption","Array","isArray","rowCount","length","content","text","JSON","stringify","structuredContent","Error","InternalError","stack","undefined","name"],"mappings":";;;;+BAiGA;;;eAAwBA;;;2BAhGA;qBAMY;0BACb;mBACL;uBACmD
|
|
1
|
+
{"version":3,"sources":["/Users/kevin/Dev/OpenSource/ai/mcp-z/mcp-sheets/src/mcp/tools/rows-get.ts"],"sourcesContent":["import type { EnrichedExtra } from '@mcp-z/oauth-google';\nimport { schemas } from '@mcp-z/oauth-google';\n\nconst { AuthRequiredBranchSchema } = schemas;\n\nimport type { ToolModule } from '@mcp-z/server';\nimport type { CallToolResult } from '@modelcontextprotocol/sdk/types.js';\nimport { ErrorCode, McpError } from '@modelcontextprotocol/sdk/types.js';\nimport { google } from 'googleapis';\nimport { z } from 'zod';\nimport { SheetCellSchema, SheetGidSchema, SpreadsheetIdSchema } from '../../schemas/index.ts';\n\nconst inputSchema = z.object({\n id: SpreadsheetIdSchema,\n gid: SheetGidSchema,\n range: z.string().min(1).describe('A1 notation range to fetch (e.g., \"B5\", \"A5:D5\", \"B:B\", \"5:5\")'),\n render: z.enum(['FORMATTED_VALUE', 'UNFORMATTED_VALUE', 'FORMULA']).optional().describe('How to render cell values. FORMATTED_VALUE (default): calculated with formatting. UNFORMATTED_VALUE: calculated without formatting. FORMULA: show formula text instead of result.'),\n});\n\n// Success branch schema - uses rows: for consistency with standard vocabulary\nconst successBranchSchema = z.object({\n type: z.literal('success'),\n range: z.string().describe('The A1 notation range that was retrieved'),\n rows: z.array(z.array(SheetCellSchema)).describe('2D array of row data (each inner array is a row)'),\n});\n\n// Output schema with auth_required support\nconst outputSchema = z.discriminatedUnion('type', [successBranchSchema, AuthRequiredBranchSchema]);\n\nconst config = {\n description: 'Fetch row data from a specific range in A1 notation. Best used after values-search to get surrounding context. Use a1-notation prompt for syntax reference.',\n inputSchema,\n outputSchema: z.object({\n result: outputSchema,\n }),\n} as const;\n\nexport type Input = z.infer<typeof inputSchema>;\nexport type Output = z.infer<typeof outputSchema>;\n\nasync function handler({ id, gid, range, render }: Input, extra: EnrichedExtra): Promise<CallToolResult> {\n const logger = extra.logger;\n logger.info('sheets.rows.get called', { id, gid, range, render });\n\n try {\n const sheets = google.sheets({ version: 'v4', auth: extra.authContext.auth });\n\n // Get sheet details using the gid to get sheet title\n const spreadsheetResponse = await sheets.spreadsheets.get({\n spreadsheetId: id,\n fields: 'sheets.properties.sheetId,sheets.properties.title',\n });\n\n const sheet = spreadsheetResponse.data.sheets?.find((s) => String(s.properties?.sheetId) === gid);\n\n if (!sheet) {\n logger.info('sheets.rows.get sheet not found', { id, gid, range });\n throw new McpError(ErrorCode.InvalidParams, `Sheet not found: ${gid}`);\n }\n\n const sheetTitle = sheet.properties?.title ?? '';\n\n // Construct full range with sheet title\n const fullRange = `${sheetTitle}!${range}`;\n\n const response = await sheets.spreadsheets.values.get({\n spreadsheetId: id,\n range: fullRange,\n valueRenderOption: render || 'FORMATTED_VALUE',\n });\n\n const res = response.data;\n const rows = Array.isArray(res.values) ? (res.values as (string | number | boolean | null)[][]) : [];\n\n logger.info('sheets.rows.get success', { id, gid, range, rowCount: rows.length });\n\n const result: Output = {\n type: 'success' as const,\n range: res.range || fullRange,\n rows,\n };\n\n return {\n content: [{ type: 'text' as const, text: JSON.stringify(result) }],\n structuredContent: { result },\n };\n } catch (error) {\n const message = error instanceof Error ? error.message : String(error);\n logger.error('sheets.rows.get error', { error: message });\n\n // Throw McpError for proper MCP error handling\n throw new McpError(ErrorCode.InternalError, `Error getting rows: ${message}`, {\n stack: error instanceof Error ? error.stack : undefined,\n });\n }\n}\n\nexport default function createTool() {\n return {\n name: 'rows-get',\n config,\n handler,\n } satisfies ToolModule;\n}\n"],"names":["createTool","AuthRequiredBranchSchema","schemas","inputSchema","z","object","id","SpreadsheetIdSchema","gid","SheetGidSchema","range","string","min","describe","render","enum","optional","successBranchSchema","type","literal","rows","array","SheetCellSchema","outputSchema","discriminatedUnion","config","description","result","handler","extra","logger","spreadsheetResponse","sheet","sheets","sheetTitle","fullRange","response","res","error","message","info","google","version","auth","authContext","spreadsheets","get","spreadsheetId","fields","data","find","s","String","properties","sheetId","McpError","ErrorCode","InvalidParams","title","values","valueRenderOption","Array","isArray","rowCount","length","content","text","JSON","stringify","structuredContent","Error","InternalError","stack","undefined","name"],"mappings":";;;;+BAiGA;;;eAAwBA;;;2BAhGA;qBAMY;0BACb;mBACL;uBACmD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAPrE,IAAM,AAAEC,2BAA6BC,oBAAO,CAApCD;AASR,IAAME,cAAcC,MAAC,CAACC,MAAM,CAAC;IAC3BC,IAAIC,4BAAmB;IACvBC,KAAKC,uBAAc;IACnBC,OAAON,MAAC,CAACO,M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AMC,OAAO,GAAGa,OAAOd;oBAChER,OAAOQ,KAAK,CAAC,yBAAyB;wBAAEA,OAAOC;oBAAQ;oBAEvD,+CAA+C;oBAC/C,MAAM,IAAIgB,eAAQ,CAACC,gBAAS,CAACe,aAAa,EAAE,AAAC,uBAA8B,OAARhC,UAAW;wBAC5EiC,OAAOlC,AAAK,YAALA,OAAiBgC,SAAQhC,MAAMkC,KAAK,GAAGC;oBAChD;;;;;;;IAEJ;;AAEe,SAASzE;IACtB,OAAO;QACL0E,MAAM;QACNjD,QAAAA;QACAG,SAAAA;IACF;AACF"}
|
|
@@ -21,11 +21,8 @@ function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) {
|
|
|
21
21
|
reject(error);
|
|
22
22
|
return;
|
|
23
23
|
}
|
|
24
|
-
if (info.done)
|
|
25
|
-
|
|
26
|
-
} else {
|
|
27
|
-
Promise.resolve(value).then(_next, _throw);
|
|
28
|
-
}
|
|
24
|
+
if (info.done) resolve(value);
|
|
25
|
+
else Promise.resolve(value).then(_next, _throw);
|
|
29
26
|
}
|
|
30
27
|
function _async_to_generator(fn) {
|
|
31
28
|
return function() {
|
|
@@ -46,9 +43,7 @@ function _instanceof(left, right) {
|
|
|
46
43
|
"@swc/helpers - instanceof";
|
|
47
44
|
if (right != null && typeof Symbol !== "undefined" && right[Symbol.hasInstance]) {
|
|
48
45
|
return !!right[Symbol.hasInstance](left);
|
|
49
|
-
} else
|
|
50
|
-
return left instanceof right;
|
|
51
|
-
}
|
|
46
|
+
} else return left instanceof right;
|
|
52
47
|
}
|
|
53
48
|
function _ts_generator(thisArg, body) {
|
|
54
49
|
var f, y, t, _ = {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["/Users/kevin/Dev/OpenSource/ai/mcp-z/mcp-sheets/src/mcp/tools/sheet-copy-to.ts"],"sourcesContent":["import type { EnrichedExtra } from '@mcp-z/oauth-google';\nimport { schemas } from '@mcp-z/oauth-google';\n\nconst { AuthRequiredBranchSchema } = schemas;\n\nimport type { ToolModule } from '@mcp-z/server';\nimport type { CallToolResult } from '@modelcontextprotocol/sdk/types.js';\nimport { ErrorCode, McpError } from '@modelcontextprotocol/sdk/types.js';\nimport { google } from 'googleapis';\nimport { z } from 'zod';\nimport { SheetGidSchema, SpreadsheetIdSchema } from '../../schemas/index.ts';\n\n// Note: Using contextual descriptions for source/destination IDs since they describe different spreadsheets/sheets\n\nconst inputSchema = z.object({\n sourceId: SpreadsheetIdSchema.describe('Source spreadsheet ID'),\n sourceGid: SheetGidSchema.describe('Source sheet grid ID to copy'),\n destinationId: SpreadsheetIdSchema.describe('Destination spreadsheet ID'),\n newTitle: z.coerce.string().trim().min(1).optional().describe('New name for the copied sheet (optional, will use auto-generated name if not provided)'),\n});\n\n// Success branch schema\nconst successBranchSchema = z.object({\n type: z.literal('success'),\n operationSummary: z.string().describe('Summary of the copy operation'),\n itemsProcessed: z.number().describe('Total items attempted (always 1)'),\n itemsChanged: z.number().describe('Successfully copied (always 1 on success)'),\n completedAt: z.string().describe('ISO datetime when operation completed'),\n sourceId: z.string().describe('Source spreadsheet ID'),\n sourceGid: z.string().describe('Source sheet ID'),\n sourceTitle: z.string().describe('Source sheet title'),\n destinationId: z.string().describe('Destination spreadsheet ID'),\n destinationGid: z.string().describe('Copied sheet ID in destination'),\n destinationTitle: z.string().describe('Title of the copied sheet in destination'),\n sheetUrl: z.string().describe('URL of the copied sheet'),\n renamed: z.boolean().describe('Whether the sheet was renamed after copying'),\n});\n\n// Output schema with auth_required support\nconst outputSchema = z.discriminatedUnion('type', [successBranchSchema, AuthRequiredBranchSchema]);\n\nconst config = {\n description: 'Copy a sheet to another spreadsheet. Copies all data, formatting, and charts.',\n inputSchema,\n outputSchema: z.object({\n result: outputSchema,\n }),\n} as const;\n\nexport type Input = z.infer<typeof inputSchema>;\nexport type Output = z.infer<typeof outputSchema>;\n\nasync function handler({ sourceId, sourceGid, destinationId, newTitle }: Input, extra: EnrichedExtra): Promise<CallToolResult> {\n const logger = extra.logger;\n logger.info('sheets.sheet.copyTo called', { sourceId, sourceGid, destinationId, newTitle });\n\n try {\n const sheets = google.sheets({ version: 'v4', auth: extra.authContext.auth });\n\n // Get source sheet info\n const sourceInfo = await sheets.spreadsheets.get({\n spreadsheetId: sourceId,\n fields: 'sheets.properties.sheetId,sheets.properties.title',\n });\n\n const sourceSheet = sourceInfo.data.sheets?.find((s) => String(s.properties?.sheetId) === sourceGid);\n if (!sourceSheet?.properties) {\n throw new McpError(ErrorCode.InvalidParams, `Source sheet with gid \"${sourceGid}\" not found in spreadsheet`);\n }\n\n const sourceTitle = sourceSheet.properties.title || '';\n\n // Copy the sheet to the destination spreadsheet\n const copyResponse = await sheets.spreadsheets.sheets.copyTo({\n spreadsheetId: sourceId,\n sheetId: Number(sourceGid),\n requestBody: {\n destinationSpreadsheetId: destinationId,\n },\n });\n\n const newSheetId = copyResponse.data.sheetId;\n let destinationTitle = copyResponse.data.title || '';\n\n if (!newSheetId) {\n throw new Error('Failed to retrieve new sheet ID from API response');\n }\n\n // If newTitle is provided, rename the sheet in the destination\n let renamed = false;\n if (newTitle && newTitle !== destinationTitle) {\n await sheets.spreadsheets.batchUpdate({\n spreadsheetId: destinationId,\n requestBody: {\n requests: [\n {\n updateSheetProperties: {\n properties: { sheetId: newSheetId, title: newTitle },\n fields: 'title',\n },\n },\n ],\n },\n });\n destinationTitle = newTitle;\n renamed = true;\n }\n\n logger.info('sheets.sheet.copyTo success', {\n sourceId,\n sourceGid,\n destinationId,\n destinationGid: String(newSheetId),\n renamed,\n });\n\n const result: Output = {\n type: 'success' as const,\n operationSummary: `Copied sheet \"${sourceTitle}\" to destination${renamed ? ` as \"${destinationTitle}\"` : ''}`,\n itemsProcessed: 1,\n itemsChanged: 1,\n completedAt: new Date().toISOString(),\n sourceId,\n sourceGid,\n sourceTitle,\n destinationId,\n destinationGid: String(newSheetId),\n destinationTitle,\n sheetUrl: `https://docs.google.com/spreadsheets/d/${destinationId}/edit#gid=${newSheetId}`,\n renamed,\n };\n\n return {\n content: [\n {\n type: 'text' as const,\n text: JSON.stringify(result),\n },\n ],\n structuredContent: { result },\n };\n } catch (error) {\n if (error instanceof McpError) {\n throw error;\n }\n const message = error instanceof Error ? error.message : String(error);\n logger.error('sheets.sheet.copyTo error', { error: message });\n\n throw new McpError(ErrorCode.InternalError, `Error copying sheet to another spreadsheet: ${message}`, {\n stack: error instanceof Error ? error.stack : undefined,\n });\n }\n}\n\nexport default function createTool() {\n return {\n name: 'sheet-copy-to',\n config,\n handler,\n } satisfies ToolModule;\n}\n"],"names":["createTool","AuthRequiredBranchSchema","schemas","inputSchema","z","object","sourceId","SpreadsheetIdSchema","describe","sourceGid","SheetGidSchema","destinationId","newTitle","coerce","string","trim","min","optional","successBranchSchema","type","literal","operationSummary","itemsProcessed","number","itemsChanged","completedAt","sourceTitle","destinationGid","destinationTitle","sheetUrl","renamed","boolean","outputSchema","discriminatedUnion","config","description","result","handler","extra","logger","sourceInfo","sheets","sourceSheet","copyResponse","newSheetId","error","message","info","google","version","auth","authContext","spreadsheets","get","spreadsheetId","fields","data","find","s","String","properties","sheetId","McpError","ErrorCode","InvalidParams","title","copyTo","Number","requestBody","destinationSpreadsheetId","Error","batchUpdate","requests","updateSheetProperties","Date","toISOString","content","text","JSON","stringify","structuredContent","InternalError","stack","undefined","name"],"mappings":";;;;+BA0JA;;;eAAwBA;;;2BAzJA;qBAMY;0BACb;mBACL;uBACkC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAPpD,IAAM,AAAEC,2BAA6BC,oBAAO,CAApCD;AASR,mHAAmH;AAEnH,IAAME,cAAcC,MAAC,CAACC,MAAM,CAAC;IAC3BC,UAAUC,4BAAmB,CAACC,QAAQ,CAAC;IACvCC,WAAWC,uBAAc,CAACF,QAAQ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,6BAA6B;wBAAEA,OAAOC;oBAAQ;oBAE3D,MAAM,IAAIgB,eAAQ,CAACC,gBAAS,CAACkB,aAAa,EAAE,AAAC,+CAAsD,OAARnC,UAAW;wBACpGoC,OAAOrC,AAAK,YAALA,OAAiByB,SAAQzB,MAAMqC,KAAK,GAAGC;oBAChD;;;;;;;IAEJ;;AAEe,SAASnF;IACtB,OAAO;QACLoF,MAAM;QACNlD,QAAAA;QACAG,SAAAA;IACF;AACF"}
|
|
1
|
+
{"version":3,"sources":["/Users/kevin/Dev/OpenSource/ai/mcp-z/mcp-sheets/src/mcp/tools/sheet-copy-to.ts"],"sourcesContent":["import type { EnrichedExtra } from '@mcp-z/oauth-google';\nimport { schemas } from '@mcp-z/oauth-google';\n\nconst { AuthRequiredBranchSchema } = schemas;\n\nimport type { ToolModule } from '@mcp-z/server';\nimport type { CallToolResult } from '@modelcontextprotocol/sdk/types.js';\nimport { ErrorCode, McpError } from '@modelcontextprotocol/sdk/types.js';\nimport { google } from 'googleapis';\nimport { z } from 'zod';\nimport { SheetGidSchema, SpreadsheetIdSchema } from '../../schemas/index.ts';\n\n// Note: Using contextual descriptions for source/destination IDs since they describe different spreadsheets/sheets\n\nconst inputSchema = z.object({\n sourceId: SpreadsheetIdSchema.describe('Source spreadsheet ID'),\n sourceGid: SheetGidSchema.describe('Source sheet grid ID to copy'),\n destinationId: SpreadsheetIdSchema.describe('Destination spreadsheet ID'),\n newTitle: z.coerce.string().trim().min(1).optional().describe('New name for the copied sheet (optional, will use auto-generated name if not provided)'),\n});\n\n// Success branch schema\nconst successBranchSchema = z.object({\n type: z.literal('success'),\n operationSummary: z.string().describe('Summary of the copy operation'),\n itemsProcessed: z.number().describe('Total items attempted (always 1)'),\n itemsChanged: z.number().describe('Successfully copied (always 1 on success)'),\n completedAt: z.string().describe('ISO datetime when operation completed'),\n sourceId: z.string().describe('Source spreadsheet ID'),\n sourceGid: z.string().describe('Source sheet ID'),\n sourceTitle: z.string().describe('Source sheet title'),\n destinationId: z.string().describe('Destination spreadsheet ID'),\n destinationGid: z.string().describe('Copied sheet ID in destination'),\n destinationTitle: z.string().describe('Title of the copied sheet in destination'),\n sheetUrl: z.string().describe('URL of the copied sheet'),\n renamed: z.boolean().describe('Whether the sheet was renamed after copying'),\n});\n\n// Output schema with auth_required support\nconst outputSchema = z.discriminatedUnion('type', [successBranchSchema, AuthRequiredBranchSchema]);\n\nconst config = {\n description: 'Copy a sheet to another spreadsheet. Copies all data, formatting, and charts.',\n inputSchema,\n outputSchema: z.object({\n result: outputSchema,\n }),\n} as const;\n\nexport type Input = z.infer<typeof inputSchema>;\nexport type Output = z.infer<typeof outputSchema>;\n\nasync function handler({ sourceId, sourceGid, destinationId, newTitle }: Input, extra: EnrichedExtra): Promise<CallToolResult> {\n const logger = extra.logger;\n logger.info('sheets.sheet.copyTo called', { sourceId, sourceGid, destinationId, newTitle });\n\n try {\n const sheets = google.sheets({ version: 'v4', auth: extra.authContext.auth });\n\n // Get source sheet info\n const sourceInfo = await sheets.spreadsheets.get({\n spreadsheetId: sourceId,\n fields: 'sheets.properties.sheetId,sheets.properties.title',\n });\n\n const sourceSheet = sourceInfo.data.sheets?.find((s) => String(s.properties?.sheetId) === sourceGid);\n if (!sourceSheet?.properties) {\n throw new McpError(ErrorCode.InvalidParams, `Source sheet with gid \"${sourceGid}\" not found in spreadsheet`);\n }\n\n const sourceTitle = sourceSheet.properties.title || '';\n\n // Copy the sheet to the destination spreadsheet\n const copyResponse = await sheets.spreadsheets.sheets.copyTo({\n spreadsheetId: sourceId,\n sheetId: Number(sourceGid),\n requestBody: {\n destinationSpreadsheetId: destinationId,\n },\n });\n\n const newSheetId = copyResponse.data.sheetId;\n let destinationTitle = copyResponse.data.title || '';\n\n if (!newSheetId) {\n throw new Error('Failed to retrieve new sheet ID from API response');\n }\n\n // If newTitle is provided, rename the sheet in the destination\n let renamed = false;\n if (newTitle && newTitle !== destinationTitle) {\n await sheets.spreadsheets.batchUpdate({\n spreadsheetId: destinationId,\n requestBody: {\n requests: [\n {\n updateSheetProperties: {\n properties: { sheetId: newSheetId, title: newTitle },\n fields: 'title',\n },\n },\n ],\n },\n });\n destinationTitle = newTitle;\n renamed = true;\n }\n\n logger.info('sheets.sheet.copyTo success', {\n sourceId,\n sourceGid,\n destinationId,\n destinationGid: String(newSheetId),\n renamed,\n });\n\n const result: Output = {\n type: 'success' as const,\n operationSummary: `Copied sheet \"${sourceTitle}\" to destination${renamed ? ` as \"${destinationTitle}\"` : ''}`,\n itemsProcessed: 1,\n itemsChanged: 1,\n completedAt: new Date().toISOString(),\n sourceId,\n sourceGid,\n sourceTitle,\n destinationId,\n destinationGid: String(newSheetId),\n destinationTitle,\n sheetUrl: `https://docs.google.com/spreadsheets/d/${destinationId}/edit#gid=${newSheetId}`,\n renamed,\n };\n\n return {\n content: [\n {\n type: 'text' as const,\n text: JSON.stringify(result),\n },\n ],\n structuredContent: { result },\n };\n } catch (error) {\n if (error instanceof McpError) {\n throw error;\n }\n const message = error instanceof Error ? error.message : String(error);\n logger.error('sheets.sheet.copyTo error', { error: message });\n\n throw new McpError(ErrorCode.InternalError, `Error copying sheet to another spreadsheet: ${message}`, {\n stack: error instanceof Error ? error.stack : undefined,\n });\n }\n}\n\nexport default function createTool() {\n return {\n name: 'sheet-copy-to',\n config,\n handler,\n } satisfies ToolModule;\n}\n"],"names":["createTool","AuthRequiredBranchSchema","schemas","inputSchema","z","object","sourceId","SpreadsheetIdSchema","describe","sourceGid","SheetGidSchema","destinationId","newTitle","coerce","string","trim","min","optional","successBranchSchema","type","literal","operationSummary","itemsProcessed","number","itemsChanged","completedAt","sourceTitle","destinationGid","destinationTitle","sheetUrl","renamed","boolean","outputSchema","discriminatedUnion","config","description","result","handler","extra","logger","sourceInfo","sheets","sourceSheet","copyResponse","newSheetId","error","message","info","google","version","auth","authContext","spreadsheets","get","spreadsheetId","fields","data","find","s","String","properties","sheetId","McpError","ErrorCode","InvalidParams","title","copyTo","Number","requestBody","destinationSpreadsheetId","Error","batchUpdate","requests","updateSheetProperties","Date","toISOString","content","text","JSON","stringify","structuredContent","InternalError","stack","undefined","name"],"mappings":";;;;+BA0JA;;;eAAwBA;;;2BAzJA;qBAMY;0BACb;mBACL;uBACkC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAPpD,IAAM,AAAEC,2BAA6BC,oBAAO,CAApCD;AASR,mHAAmH;AAEnH,IAAME,cAAcC,MAAC,CAACC,MAAM,CAAC;IAC3BC,UAAUC,4BAAmB,CAACC,QAAQ,CAAC;IACvCC,WAAWC,uBAAc,CAACF,QAAQ,CAAC;IACnCG,eAAeJ,4BAAmB,CAACC,QAAQ,CAAC;IAC5CI,UAAUR,MAAC,CAACS,MAAM,CAACC,MAAM,GAAGC,IAAI,GAAGC,GAAG,CAAC,GAAGC,QAAQ,GAAGT,QAAQ,CAAC;AAChE;AAEA,wBAAwB;AACxB,IAAMU,sBAAsBd,MAAC,CAACC,MAAM,CAAC;IACnCc,MAAMf,MAAC,CAACgB,OAAO,CAAC;IAChBC,kBAAkBjB,MAAC,CAACU,MAAM,GAAGN,QAAQ,CAAC;IACtCc,gBAAgBlB,MAAC,CAACmB,MAAM,GAAGf,QAAQ,CAAC;IACpCgB,cAAcpB,MAAC,CAACmB,MAAM,GAAGf,QAAQ,CAAC;IAClCiB,aAAarB,MAAC,CAACU,MAAM,GAAGN,QAAQ,CAAC;IACjCF,UAAUF,MAAC,CAACU,MAAM,GAAGN,QAAQ,CAAC;IAC9BC,WAAWL,MAAC,CAACU,MAAM,GAAGN,QAAQ,CAAC;IAC/BkB,aAAatB,MAAC,CAACU,MAAM,GAAGN,QAAQ,CAAC;IACjCG,eAAeP,MAAC,CAACU,MAAM,GAAGN,QAAQ,CAAC;IACnCmB,gBAAgBvB,MAAC,CAACU,MAAM,GAAGN,Q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AAAA;wBACAf,eAAAA;wBACAgB,gBAAgBgC,OAAOf;wBACvBhB,kBAAAA;wBACAC,UAAU,AAAC,0CAAmEe,OAA1BjC,eAAc,cAAuB,OAAXiC;wBAC9Ed,SAAAA;oBACF;oBAEA;;wBAAO;4BACL8C,OAAO;gCACL;oCACEzD,MAAM;oCACN0D,MAAMC,KAAKC,SAAS,CAAC3C;gCACvB;;4BAEF4C,mBAAmB;gCAAE5C,QAAAA;4BAAO;wBAC9B;;;oBACOS;oBACP,IAAIA,AAAK,YAALA,OAAiBiB,eAAQ,GAAE;wBAC7B,MAAMjB;oBACR;oBACMC,UAAUD,AAAK,YAALA,OAAiByB,SAAQzB,MAAMC,OAAO,GAAGa,OAAOd;oBAChEN,OAAOM,KAAK,CAAC,6BAA6B;wBAAEA,OAAOC;oBAAQ;oBAE3D,MAAM,IAAIgB,eAAQ,CAACC,gBAAS,CAACkB,aAAa,EAAE,AAAC,+CAAsD,OAARnC,UAAW;wBACpGoC,OAAOrC,AAAK,YAALA,OAAiByB,SAAQzB,MAAMqC,KAAK,GAAGC;oBAChD;;;;;;;IAEJ;;AAEe,SAASnF;IACtB,OAAO;QACLoF,MAAM;QACNlD,QAAAA;QACAG,SAAAA;IACF;AACF"}
|
|
@@ -21,11 +21,8 @@ function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) {
|
|
|
21
21
|
reject(error);
|
|
22
22
|
return;
|
|
23
23
|
}
|
|
24
|
-
if (info.done)
|
|
25
|
-
|
|
26
|
-
} else {
|
|
27
|
-
Promise.resolve(value).then(_next, _throw);
|
|
28
|
-
}
|
|
24
|
+
if (info.done) resolve(value);
|
|
25
|
+
else Promise.resolve(value).then(_next, _throw);
|
|
29
26
|
}
|
|
30
27
|
function _async_to_generator(fn) {
|
|
31
28
|
return function() {
|
|
@@ -50,18 +47,14 @@ function _define_property(obj, key, value) {
|
|
|
50
47
|
configurable: true,
|
|
51
48
|
writable: true
|
|
52
49
|
});
|
|
53
|
-
} else
|
|
54
|
-
obj[key] = value;
|
|
55
|
-
}
|
|
50
|
+
} else obj[key] = value;
|
|
56
51
|
return obj;
|
|
57
52
|
}
|
|
58
53
|
function _instanceof(left, right) {
|
|
59
54
|
"@swc/helpers - instanceof";
|
|
60
55
|
if (right != null && typeof Symbol !== "undefined" && right[Symbol.hasInstance]) {
|
|
61
56
|
return !!right[Symbol.hasInstance](left);
|
|
62
|
-
} else
|
|
63
|
-
return left instanceof right;
|
|
64
|
-
}
|
|
57
|
+
} else return left instanceof right;
|
|
65
58
|
}
|
|
66
59
|
function _object_spread(target) {
|
|
67
60
|
for(var i = 1; i < arguments.length; i++){
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["/Users/kevin/Dev/OpenSource/ai/mcp-z/mcp-sheets/src/mcp/tools/sheet-copy.ts"],"sourcesContent":["import type { EnrichedExtra } from '@mcp-z/oauth-google';\nimport { schemas } from '@mcp-z/oauth-google';\n\nconst { AuthRequiredBranchSchema } = schemas;\n\nimport type { ToolModule } from '@mcp-z/server';\nimport type { CallToolResult } from '@modelcontextprotocol/sdk/types.js';\nimport { ErrorCode, McpError } from '@modelcontextprotocol/sdk/types.js';\nimport { google } from 'googleapis';\nimport { z } from 'zod';\nimport { SheetGidOutput, SheetGidSchema, SpreadsheetIdOutput, SpreadsheetIdSchema } from '../../schemas/index.ts';\n\nconst MAX_BATCH_SIZE = 100;\n\nconst copyItemSchema = z.object({\n newTitle: z.coerce.string().trim().min(1).describe('Name for the copied sheet'),\n insertIndex: z.number().int().min(0).optional().describe('Position to insert the new sheet (0-indexed)'),\n});\n\nconst inputSchema = z.object({\n id: SpreadsheetIdSchema,\n gid: SheetGidSchema,\n copies: z.array(copyItemSchema).min(1).max(MAX_BATCH_SIZE).describe('Array of copies to create from the source sheet'),\n});\n\n// Created sheet info\nconst createdSheetSchema = z.object({\n gid: SheetGidOutput,\n title: z.string().describe('Title of the created sheet'),\n sheetUrl: z.string().describe('URL of the created sheet'),\n});\n\n// Success branch schema - uses items: for consistency with standard vocabulary\nconst successBranchSchema = z.object({\n type: z.literal('success'),\n operationSummary: z.string().describe('Summary of the copy operation'),\n itemsProcessed: z.number().describe('Total copies attempted'),\n itemsChanged: z.number().describe('Successfully created copies'),\n completedAt: z.string().describe('ISO datetime when operation completed'),\n id: SpreadsheetIdOutput,\n sourceGid: z.string().describe('Source sheet ID'),\n sourceTitle: z.string().describe('Source sheet title'),\n items: z.array(createdSheetSchema).describe('Information about created sheets'),\n failures: z\n .array(\n z.object({\n title: z.string(),\n error: z.string(),\n })\n )\n .optional()\n .describe('Failed copies with error messages'),\n});\n\n// Output schema with auth_required support\nconst outputSchema = z.discriminatedUnion('type', [successBranchSchema, AuthRequiredBranchSchema]);\n\nconst config = {\n description: 'Copy a sheet/tab within the same spreadsheet. Supports batch copying: create multiple copies from a single source sheet (e.g., create 12 monthly sheets from a template). Copies all data, formatting, charts, and conditional formatting verbatim.',\n inputSchema,\n outputSchema: z.object({\n result: outputSchema,\n }),\n} as const;\n\nexport type Input = z.infer<typeof inputSchema>;\nexport type Output = z.infer<typeof outputSchema>;\n\nasync function handler({ id, gid, copies }: Input, extra: EnrichedExtra): Promise<CallToolResult> {\n const logger = extra.logger;\n logger.info('sheets.sheet.copy called', { id, gid, copyCount: copies.length });\n\n try {\n const sheets = google.sheets({ version: 'v4', auth: extra.authContext.auth });\n\n // First, get the source sheet info\n const spreadsheetInfo = await sheets.spreadsheets.get({\n spreadsheetId: id,\n fields: 'sheets.properties.sheetId,sheets.properties.title',\n });\n\n const sourceSheet = spreadsheetInfo.data.sheets?.find((s) => String(s.properties?.sheetId) === gid);\n if (!sourceSheet?.properties) {\n throw new McpError(ErrorCode.InvalidParams, `Source sheet with gid \"${gid}\" not found in spreadsheet`);\n }\n\n const sourceTitle = sourceSheet.properties.title || '';\n const sourceSheetId = Number(gid);\n\n // Execute copies using Promise.allSettled for partial failure handling\n const results = await Promise.allSettled(\n copies.map(async (copy) => {\n const response = await sheets.spreadsheets.batchUpdate({\n spreadsheetId: id,\n requestBody: {\n requests: [\n {\n duplicateSheet: {\n sourceSheetId,\n newSheetName: copy.newTitle,\n ...(copy.insertIndex !== undefined && { insertSheetIndex: copy.insertIndex }),\n },\n },\n ],\n },\n });\n\n const newSheetId = response.data.replies?.[0]?.duplicateSheet?.properties?.sheetId;\n const newTitle = response.data.replies?.[0]?.duplicateSheet?.properties?.title;\n\n if (!newSheetId || !newTitle) {\n throw new Error('Failed to retrieve new sheet info from API response');\n }\n\n return {\n gid: String(newSheetId),\n title: newTitle,\n sheetUrl: `https://docs.google.com/spreadsheets/d/${id}/edit#gid=${newSheetId}`,\n };\n })\n );\n\n // Separate successes and failures\n const items: Array<{ gid: string; title: string; sheetUrl: string }> = [];\n const failures: Array<{ title: string; error: string }> = [];\n\n results.forEach((result, index) => {\n const copy = copies[index];\n if (!copy) return;\n\n if (result.status === 'fulfilled') {\n items.push(result.value);\n } else {\n const errorMessage = result.reason instanceof Error ? result.reason.message : String(result.reason);\n failures.push({ title: copy.newTitle, error: errorMessage });\n }\n });\n\n const successCount = items.length;\n const failureCount = failures.length;\n const totalCount = copies.length;\n\n const summary = failureCount === 0 ? `Created ${successCount} cop${successCount === 1 ? 'y' : 'ies'} of \"${sourceTitle}\"` : `Created ${successCount} of ${totalCount} cop${totalCount === 1 ? 'y' : 'ies'} (${failureCount} failed)`;\n\n logger.info('sheets.sheet.copy completed', { totalCount, successCount, failureCount });\n\n const result: Output = {\n type: 'success' as const,\n operationSummary: summary,\n itemsProcessed: totalCount,\n itemsChanged: successCount,\n completedAt: new Date().toISOString(),\n id,\n sourceGid: gid,\n sourceTitle,\n items,\n ...(failures.length > 0 && { failures }),\n };\n\n return {\n content: [{ type: 'text' as const, text: JSON.stringify(result) }],\n structuredContent: { result },\n };\n } catch (error) {\n if (error instanceof McpError) {\n throw error;\n }\n const message = error instanceof Error ? error.message : String(error);\n logger.error('sheets.sheet.copy error', { error: message });\n\n throw new McpError(ErrorCode.InternalError, `Error copying sheet: ${message}`, {\n stack: error instanceof Error ? error.stack : undefined,\n });\n }\n}\n\nexport default function createTool() {\n return {\n name: 'sheet-copy',\n config,\n handler,\n } satisfies ToolModule;\n}\n"],"names":["createTool","AuthRequiredBranchSchema","schemas","MAX_BATCH_SIZE","copyItemSchema","z","object","newTitle","coerce","string","trim","min","describe","insertIndex","number","int","optional","inputSchema","id","SpreadsheetIdSchema","gid","SheetGidSchema","copies","array","max","createdSheetSchema","SheetGidOutput","title","sheetUrl","successBranchSchema","type","literal","operationSummary","itemsProcessed","itemsChanged","completedAt","SpreadsheetIdOutput","sourceGid","sourceTitle","items","failures","error","outputSchema","discriminatedUnion","config","description","result","handler","extra","logger","spreadsheetInfo","sheets","sourceSheet","sourceSheetId","results","successCount","failureCount","totalCount","summary","message","info","copyCount","length","google","version","auth","authContext","spreadsheets","get","spreadsheetId","fields","data","find","s","String","properties","sheetId","McpError","ErrorCode","InvalidParams","Number","Promise","allSettled","map","copy","response","newSheetId","batchUpdate","requestBody","requests","duplicateSheet","newSheetName","undefined","insertSheetIndex","replies","Error","forEach","index","status","push","value","errorMessage","reason","Date","toISOString","content","text","JSON","stringify","structuredContent","InternalError","stack","name"],"mappings":";;;;+BAgLA;;;eAAwBA;;;2BA/KA;qBAMY;0BACb;mBACL;uBACuE;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAPzF,IAAM,AAAEC,2BAA6BC,oBAAO,CAApCD;AASR,IAAME,iBAAiB;AAEvB,IAAMC,iBAAiBC,MAAC,CAACC,MAAM,CAAC;IAC9BC,UAAUF,MAAC,CAACG,MAAM,CAACC,MAAM,GAAGC,IAAI,GAAGC,GAAG,CAAC,GAAGC,QAAQ,CAAC;IACnDC,aAAaR,MAAC,CAACS,MAAM,GAA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7B,MAAMpC;oBACR;oBACMkB,UAAUlB,AAAK,YAALA,OAAiBsD,SAAQtD,MAAMkB,OAAO,GAAGe,OAAOjC;oBAChEQ,OAAOR,KAAK,CAAC,2BAA2B;wBAAEA,OAAOkB;oBAAQ;oBAEzD,MAAM,IAAIkB,eAAQ,CAACC,gBAAS,CAACgC,aAAa,EAAE,AAAC,wBAA+B,OAARnD,UAAW;wBAC7EoD,OAAOtE,AAAK,YAALA,OAAiBsD,SAAQtD,MAAMsE,KAAK,GAAGnB;oBAChD;;;;;;;IAEJ;;AAEe,SAAS5F;IACtB,OAAO;QACLgH,MAAM;QACNpE,QAAAA;QACAG,SAAAA;IACF;AACF"}
|
|
1
|
+
{"version":3,"sources":["/Users/kevin/Dev/OpenSource/ai/mcp-z/mcp-sheets/src/mcp/tools/sheet-copy.ts"],"sourcesContent":["import type { EnrichedExtra } from '@mcp-z/oauth-google';\nimport { schemas } from '@mcp-z/oauth-google';\n\nconst { AuthRequiredBranchSchema } = schemas;\n\nimport type { ToolModule } from '@mcp-z/server';\nimport type { CallToolResult } from '@modelcontextprotocol/sdk/types.js';\nimport { ErrorCode, McpError } from '@modelcontextprotocol/sdk/types.js';\nimport { google } from 'googleapis';\nimport { z } from 'zod';\nimport { SheetGidOutput, SheetGidSchema, SpreadsheetIdOutput, SpreadsheetIdSchema } from '../../schemas/index.ts';\n\nconst MAX_BATCH_SIZE = 100;\n\nconst copyItemSchema = z.object({\n newTitle: z.coerce.string().trim().min(1).describe('Name for the copied sheet'),\n insertIndex: z.number().int().min(0).optional().describe('Position to insert the new sheet (0-indexed)'),\n});\n\nconst inputSchema = z.object({\n id: SpreadsheetIdSchema,\n gid: SheetGidSchema,\n copies: z.array(copyItemSchema).min(1).max(MAX_BATCH_SIZE).describe('Array of copies to create from the source sheet'),\n});\n\n// Created sheet info\nconst createdSheetSchema = z.object({\n gid: SheetGidOutput,\n title: z.string().describe('Title of the created sheet'),\n sheetUrl: z.string().describe('URL of the created sheet'),\n});\n\n// Success branch schema - uses items: for consistency with standard vocabulary\nconst successBranchSchema = z.object({\n type: z.literal('success'),\n operationSummary: z.string().describe('Summary of the copy operation'),\n itemsProcessed: z.number().describe('Total copies attempted'),\n itemsChanged: z.number().describe('Successfully created copies'),\n completedAt: z.string().describe('ISO datetime when operation completed'),\n id: SpreadsheetIdOutput,\n sourceGid: z.string().describe('Source sheet ID'),\n sourceTitle: z.string().describe('Source sheet title'),\n items: z.array(createdSheetSchema).describe('Information about created sheets'),\n failures: z\n .array(\n z.object({\n title: z.string(),\n error: z.string(),\n })\n )\n .optional()\n .describe('Failed copies with error messages'),\n});\n\n// Output schema with auth_required support\nconst outputSchema = z.discriminatedUnion('type', [successBranchSchema, AuthRequiredBranchSchema]);\n\nconst config = {\n description: 'Copy a sheet/tab within the same spreadsheet. Supports batch copying: create multiple copies from a single source sheet (e.g., create 12 monthly sheets from a template). Copies all data, formatting, charts, and conditional formatting verbatim.',\n inputSchema,\n outputSchema: z.object({\n result: outputSchema,\n }),\n} as const;\n\nexport type Input = z.infer<typeof inputSchema>;\nexport type Output = z.infer<typeof outputSchema>;\n\nasync function handler({ id, gid, copies }: Input, extra: EnrichedExtra): Promise<CallToolResult> {\n const logger = extra.logger;\n logger.info('sheets.sheet.copy called', { id, gid, copyCount: copies.length });\n\n try {\n const sheets = google.sheets({ version: 'v4', auth: extra.authContext.auth });\n\n // First, get the source sheet info\n const spreadsheetInfo = await sheets.spreadsheets.get({\n spreadsheetId: id,\n fields: 'sheets.properties.sheetId,sheets.properties.title',\n });\n\n const sourceSheet = spreadsheetInfo.data.sheets?.find((s) => String(s.properties?.sheetId) === gid);\n if (!sourceSheet?.properties) {\n throw new McpError(ErrorCode.InvalidParams, `Source sheet with gid \"${gid}\" not found in spreadsheet`);\n }\n\n const sourceTitle = sourceSheet.properties.title || '';\n const sourceSheetId = Number(gid);\n\n // Execute copies using Promise.allSettled for partial failure handling\n const results = await Promise.allSettled(\n copies.map(async (copy) => {\n const response = await sheets.spreadsheets.batchUpdate({\n spreadsheetId: id,\n requestBody: {\n requests: [\n {\n duplicateSheet: {\n sourceSheetId,\n newSheetName: copy.newTitle,\n ...(copy.insertIndex !== undefined && { insertSheetIndex: copy.insertIndex }),\n },\n },\n ],\n },\n });\n\n const newSheetId = response.data.replies?.[0]?.duplicateSheet?.properties?.sheetId;\n const newTitle = response.data.replies?.[0]?.duplicateSheet?.properties?.title;\n\n if (!newSheetId || !newTitle) {\n throw new Error('Failed to retrieve new sheet info from API response');\n }\n\n return {\n gid: String(newSheetId),\n title: newTitle,\n sheetUrl: `https://docs.google.com/spreadsheets/d/${id}/edit#gid=${newSheetId}`,\n };\n })\n );\n\n // Separate successes and failures\n const items: Array<{ gid: string; title: string; sheetUrl: string }> = [];\n const failures: Array<{ title: string; error: string }> = [];\n\n results.forEach((result, index) => {\n const copy = copies[index];\n if (!copy) return;\n\n if (result.status === 'fulfilled') {\n items.push(result.value);\n } else {\n const errorMessage = result.reason instanceof Error ? result.reason.message : String(result.reason);\n failures.push({ title: copy.newTitle, error: errorMessage });\n }\n });\n\n const successCount = items.length;\n const failureCount = failures.length;\n const totalCount = copies.length;\n\n const summary = failureCount === 0 ? `Created ${successCount} cop${successCount === 1 ? 'y' : 'ies'} of \"${sourceTitle}\"` : `Created ${successCount} of ${totalCount} cop${totalCount === 1 ? 'y' : 'ies'} (${failureCount} failed)`;\n\n logger.info('sheets.sheet.copy completed', { totalCount, successCount, failureCount });\n\n const result: Output = {\n type: 'success' as const,\n operationSummary: summary,\n itemsProcessed: totalCount,\n itemsChanged: successCount,\n completedAt: new Date().toISOString(),\n id,\n sourceGid: gid,\n sourceTitle,\n items,\n ...(failures.length > 0 && { failures }),\n };\n\n return {\n content: [{ type: 'text' as const, text: JSON.stringify(result) }],\n structuredContent: { result },\n };\n } catch (error) {\n if (error instanceof McpError) {\n throw error;\n }\n const message = error instanceof Error ? error.message : String(error);\n logger.error('sheets.sheet.copy error', { error: message });\n\n throw new McpError(ErrorCode.InternalError, `Error copying sheet: ${message}`, {\n stack: error instanceof Error ? error.stack : undefined,\n });\n }\n}\n\nexport default function createTool() {\n return {\n name: 'sheet-copy',\n config,\n handler,\n } satisfies ToolModule;\n}\n"],"names":["createTool","AuthRequiredBranchSchema","schemas","MAX_BATCH_SIZE","copyItemSchema","z","object","newTitle","coerce","string","trim","min","describe","insertIndex","number","int","optional","inputSchema","id","SpreadsheetIdSchema","gid","SheetGidSchema","copies","array","max","createdSheetSchema","SheetGidOutput","title","sheetUrl","successBranchSchema","type","literal","operationSummary","itemsProcessed","itemsChanged","completedAt","SpreadsheetIdOutput","sourceGid","sourceTitle","items","failures","error","outputSchema","discriminatedUnion","config","description","result","handler","extra","logger","spreadsheetInfo","sheets","sourceSheet","sourceSheetId","results","successCount","failureCount","totalCount","summary","message","info","copyCount","length","google","version","auth","authContext","spreadsheets","get","spreadsheetId","fields","data","find","s","String","properties","sheetId","McpError","ErrorCode","InvalidParams","Number","Promise","allSettled","map","copy","response","newSheetId","batchUpdate","requestBody","requests","duplicateSheet","newSheetName","undefined","insertSheetIndex","replies","Error","forEach","index","status","push","value","errorMessage","reason","Date","toISOString","content","text","JSON","stringify","structuredContent","InternalError","stack","name"],"mappings":";;;;+BAgLA;;;eAAwBA;;;2BA/KA;qBAMY;0BACb;mBACL;uBACuE;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAPzF,IAAM,AAAEC,2BAA6BC,oBAAO,CAApCD;AASR,IAAME,iBAAiB;AAEvB,IAAMC,iBAAiBC,MAAC,CAACC,MAAM,CAAC;IAC9BC,UAAUF,MAAC,CAACG,MAAM,CAACC,MAAM,GAAGC,IAAI,GAAGC,GAAG,CAAC,GAAGC,QAAQ,CAAC;IACnDC,aAAaR,MAAC,CAACS,MAAM,GAA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7B,MAAMpC;oBACR;oBACMkB,UAAUlB,AAAK,YAALA,OAAiBsD,SAAQtD,MAAMkB,OAAO,GAAGe,OAAOjC;oBAChEQ,OAAOR,KAAK,CAAC,2BAA2B;wBAAEA,OAAOkB;oBAAQ;oBAEzD,MAAM,IAAIkB,eAAQ,CAACC,gBAAS,CAACgC,aAAa,EAAE,AAAC,wBAA+B,OAARnD,UAAW;wBAC7EoD,OAAOtE,AAAK,YAALA,OAAiBsD,SAAQtD,MAAMsE,KAAK,GAAGnB;oBAChD;;;;;;;IAEJ;;AAEe,SAAS5F;IACtB,OAAO;QACLgH,MAAM;QACNpE,QAAAA;QACAG,SAAAA;IACF;AACF"}
|
|
@@ -21,11 +21,8 @@ function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) {
|
|
|
21
21
|
reject(error);
|
|
22
22
|
return;
|
|
23
23
|
}
|
|
24
|
-
if (info.done)
|
|
25
|
-
|
|
26
|
-
} else {
|
|
27
|
-
Promise.resolve(value).then(_next, _throw);
|
|
28
|
-
}
|
|
24
|
+
if (info.done) resolve(value);
|
|
25
|
+
else Promise.resolve(value).then(_next, _throw);
|
|
29
26
|
}
|
|
30
27
|
function _async_to_generator(fn) {
|
|
31
28
|
return function() {
|
|
@@ -46,9 +43,7 @@ function _instanceof(left, right) {
|
|
|
46
43
|
"@swc/helpers - instanceof";
|
|
47
44
|
if (right != null && typeof Symbol !== "undefined" && right[Symbol.hasInstance]) {
|
|
48
45
|
return !!right[Symbol.hasInstance](left);
|
|
49
|
-
} else
|
|
50
|
-
return left instanceof right;
|
|
51
|
-
}
|
|
46
|
+
} else return left instanceof right;
|
|
52
47
|
}
|
|
53
48
|
function _ts_generator(thisArg, body) {
|
|
54
49
|
var f, y, t, _ = {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["/Users/kevin/Dev/OpenSource/ai/mcp-z/mcp-sheets/src/mcp/tools/sheet-create.ts"],"sourcesContent":["import type { EnrichedExtra } from '@mcp-z/oauth-google';\nimport { schemas } from '@mcp-z/oauth-google';\n\nconst { AuthRequiredBranchSchema } = schemas;\n\nimport type { ToolModule } from '@mcp-z/server';\nimport type { CallToolResult } from '@modelcontextprotocol/sdk/types.js';\nimport { ErrorCode, McpError } from '@modelcontextprotocol/sdk/types.js';\nimport { google } from 'googleapis';\nimport { z } from 'zod';\nimport { SheetGidOutput, SpreadsheetIdOutput, SpreadsheetIdSchema } from '../../schemas/index.ts';\n\nconst inputSchema = z.object({\n id: SpreadsheetIdSchema,\n sheetTitle: z.coerce.string().trim().min(1).describe('Name for the new sheet tab'),\n});\n\n// Success branch schema\nconst successBranchSchema = z.object({\n type: z.literal('success'),\n operationSummary: z.string().describe('Summary of the sheet creation operation'),\n itemsProcessed: z.number().describe('Total items attempted (always 1 for single sheet)'),\n itemsChanged: z.number().describe('Successfully created sheets (always 1 on success)'),\n completedAt: z.string().describe('ISO datetime when operation completed'),\n id: SpreadsheetIdOutput,\n gid: SheetGidOutput,\n sheetUrl: z.string().describe('URL of the created sheet'),\n sheetTitle: z.string().describe('Title of the created sheet'),\n});\n\n// Output schema with auth_required support\nconst outputSchema = z.discriminatedUnion('type', [successBranchSchema, AuthRequiredBranchSchema]);\n\nconst config = {\n description: 'Create a new sheet/tab in the spreadsheet/workbook',\n inputSchema,\n outputSchema: z.object({\n result: outputSchema,\n }),\n} as const;\n\nexport type Input = z.infer<typeof inputSchema>;\nexport type Output = z.infer<typeof outputSchema>;\n\nasync function handler({ id, sheetTitle }: Input, extra: EnrichedExtra): Promise<CallToolResult> {\n const logger = extra.logger;\n logger.info('sheets.sheet.create called', { id, sheetTitle });\n\n try {\n const sheets = google.sheets({ version: 'v4', auth: extra.authContext.auth });\n const response = await sheets.spreadsheets.batchUpdate({\n spreadsheetId: id,\n requestBody: {\n requests: [{ addSheet: { properties: { title: sheetTitle } } }],\n },\n });\n const batchResult = response.data;\n const sheetId = batchResult.replies?.[0]?.addSheet?.properties?.sheetId;\n if (!sheetId) {\n throw new Error('Failed to retrieve sheetId from Google Sheets API response');\n }\n logger.info('sheets.sheet.create success', { id, sheetTitle, sheetId });\n\n const result: Output = {\n type: 'success' as const,\n operationSummary: `Created sheet \"${sheetTitle}\"`,\n itemsProcessed: 1,\n itemsChanged: 1,\n completedAt: new Date().toISOString(),\n id,\n gid: String(sheetId),\n sheetUrl: `https://docs.google.com/spreadsheets/d/${id}/edit#gid=${sheetId}`,\n sheetTitle,\n };\n\n return {\n content: [\n {\n type: 'text' as const,\n text: JSON.stringify(result),\n },\n ],\n structuredContent: { result },\n };\n } catch (error) {\n const message = error instanceof Error ? error.message : String(error);\n logger.error('sheets.sheet.create error', { error: message });\n\n // Throw McpError for proper MCP error handling\n throw new McpError(ErrorCode.InternalError, `Error creating sheet: ${message}`, {\n stack: error instanceof Error ? error.stack : undefined,\n });\n }\n}\n\nexport default function createTool() {\n return {\n name: 'sheet-create',\n config,\n handler,\n } satisfies ToolModule;\n}\n"],"names":["createTool","AuthRequiredBranchSchema","schemas","inputSchema","z","object","id","SpreadsheetIdSchema","sheetTitle","coerce","string","trim","min","describe","successBranchSchema","type","literal","operationSummary","itemsProcessed","number","itemsChanged","completedAt","SpreadsheetIdOutput","gid","SheetGidOutput","sheetUrl","outputSchema","discriminatedUnion","config","description","result","handler","extra","logger","batchResult","sheets","response","sheetId","error","message","info","google","version","auth","authContext","spreadsheets","batchUpdate","spreadsheetId","requestBody","requests","addSheet","properties","title","data","replies","Error","Date","toISOString","String","content","text","JSON","stringify","structuredContent","McpError","ErrorCode","InternalError","stack","undefined","name"],"mappings":";;;;+BA+FA;;;eAAwBA;;;2BA9FA;qBAMY;0BACb;mBACL;uBACuD
|
|
1
|
+
{"version":3,"sources":["/Users/kevin/Dev/OpenSource/ai/mcp-z/mcp-sheets/src/mcp/tools/sheet-create.ts"],"sourcesContent":["import type { EnrichedExtra } from '@mcp-z/oauth-google';\nimport { schemas } from '@mcp-z/oauth-google';\n\nconst { AuthRequiredBranchSchema } = schemas;\n\nimport type { ToolModule } from '@mcp-z/server';\nimport type { CallToolResult } from '@modelcontextprotocol/sdk/types.js';\nimport { ErrorCode, McpError } from '@modelcontextprotocol/sdk/types.js';\nimport { google } from 'googleapis';\nimport { z } from 'zod';\nimport { SheetGidOutput, SpreadsheetIdOutput, SpreadsheetIdSchema } from '../../schemas/index.ts';\n\nconst inputSchema = z.object({\n id: SpreadsheetIdSchema,\n sheetTitle: z.coerce.string().trim().min(1).describe('Name for the new sheet tab'),\n});\n\n// Success branch schema\nconst successBranchSchema = z.object({\n type: z.literal('success'),\n operationSummary: z.string().describe('Summary of the sheet creation operation'),\n itemsProcessed: z.number().describe('Total items attempted (always 1 for single sheet)'),\n itemsChanged: z.number().describe('Successfully created sheets (always 1 on success)'),\n completedAt: z.string().describe('ISO datetime when operation completed'),\n id: SpreadsheetIdOutput,\n gid: SheetGidOutput,\n sheetUrl: z.string().describe('URL of the created sheet'),\n sheetTitle: z.string().describe('Title of the created sheet'),\n});\n\n// Output schema with auth_required support\nconst outputSchema = z.discriminatedUnion('type', [successBranchSchema, AuthRequiredBranchSchema]);\n\nconst config = {\n description: 'Create a new sheet/tab in the spreadsheet/workbook',\n inputSchema,\n outputSchema: z.object({\n result: outputSchema,\n }),\n} as const;\n\nexport type Input = z.infer<typeof inputSchema>;\nexport type Output = z.infer<typeof outputSchema>;\n\nasync function handler({ id, sheetTitle }: Input, extra: EnrichedExtra): Promise<CallToolResult> {\n const logger = extra.logger;\n logger.info('sheets.sheet.create called', { id, sheetTitle });\n\n try {\n const sheets = google.sheets({ version: 'v4', auth: extra.authContext.auth });\n const response = await sheets.spreadsheets.batchUpdate({\n spreadsheetId: id,\n requestBody: {\n requests: [{ addSheet: { properties: { title: sheetTitle } } }],\n },\n });\n const batchResult = response.data;\n const sheetId = batchResult.replies?.[0]?.addSheet?.properties?.sheetId;\n if (!sheetId) {\n throw new Error('Failed to retrieve sheetId from Google Sheets API response');\n }\n logger.info('sheets.sheet.create success', { id, sheetTitle, sheetId });\n\n const result: Output = {\n type: 'success' as const,\n operationSummary: `Created sheet \"${sheetTitle}\"`,\n itemsProcessed: 1,\n itemsChanged: 1,\n completedAt: new Date().toISOString(),\n id,\n gid: String(sheetId),\n sheetUrl: `https://docs.google.com/spreadsheets/d/${id}/edit#gid=${sheetId}`,\n sheetTitle,\n };\n\n return {\n content: [\n {\n type: 'text' as const,\n text: JSON.stringify(result),\n },\n ],\n structuredContent: { result },\n };\n } catch (error) {\n const message = error instanceof Error ? error.message : String(error);\n logger.error('sheets.sheet.create error', { error: message });\n\n // Throw McpError for proper MCP error handling\n throw new McpError(ErrorCode.InternalError, `Error creating sheet: ${message}`, {\n stack: error instanceof Error ? error.stack : undefined,\n });\n }\n}\n\nexport default function createTool() {\n return {\n name: 'sheet-create',\n config,\n handler,\n } satisfies ToolModule;\n}\n"],"names":["createTool","AuthRequiredBranchSchema","schemas","inputSchema","z","object","id","SpreadsheetIdSchema","sheetTitle","coerce","string","trim","min","describe","successBranchSchema","type","literal","operationSummary","itemsProcessed","number","itemsChanged","completedAt","SpreadsheetIdOutput","gid","SheetGidOutput","sheetUrl","outputSchema","discriminatedUnion","config","description","result","handler","extra","logger","batchResult","sheets","response","sheetId","error","message","info","google","version","auth","authContext","spreadsheets","batchUpdate","spreadsheetId","requestBody","requests","addSheet","properties","title","data","replies","Error","Date","toISOString","String","content","text","JSON","stringify","structuredContent","McpError","ErrorCode","InternalError","stack","undefined","name"],"mappings":";;;;+BA+FA;;;eAAwBA;;;2BA9FA;qBAMY;0BACb;mBACL;uBACuD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAPzE,IAAM,AAAEC,2BAA6BC,oBAAO,CAApCD;AASR,IAAME,cAAcC,MAAC,CAACC,MAAM,CAAC;IAC3BC,IAAIC,4BAAmB;IACvBC,YAAYJ,MAAC,CAAC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iBiB,SAAQjB,MAAM6B,KAAK,GAAGC;oBAChD;;;;;;;IAEJ;;AAEe,SAASpE;IACtB,OAAO;QACLqE,MAAM;QACNzC,QAAAA;QACAG,SAAAA;IACF;AACF"}
|
|
@@ -21,11 +21,8 @@ function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) {
|
|
|
21
21
|
reject(error);
|
|
22
22
|
return;
|
|
23
23
|
}
|
|
24
|
-
if (info.done)
|
|
25
|
-
|
|
26
|
-
} else {
|
|
27
|
-
Promise.resolve(value).then(_next, _throw);
|
|
28
|
-
}
|
|
24
|
+
if (info.done) resolve(value);
|
|
25
|
+
else Promise.resolve(value).then(_next, _throw);
|
|
29
26
|
}
|
|
30
27
|
function _async_to_generator(fn) {
|
|
31
28
|
return function() {
|
|
@@ -50,18 +47,14 @@ function _define_property(obj, key, value) {
|
|
|
50
47
|
configurable: true,
|
|
51
48
|
writable: true
|
|
52
49
|
});
|
|
53
|
-
} else
|
|
54
|
-
obj[key] = value;
|
|
55
|
-
}
|
|
50
|
+
} else obj[key] = value;
|
|
56
51
|
return obj;
|
|
57
52
|
}
|
|
58
53
|
function _instanceof(left, right) {
|
|
59
54
|
"@swc/helpers - instanceof";
|
|
60
55
|
if (right != null && typeof Symbol !== "undefined" && right[Symbol.hasInstance]) {
|
|
61
56
|
return !!right[Symbol.hasInstance](left);
|
|
62
|
-
} else
|
|
63
|
-
return left instanceof right;
|
|
64
|
-
}
|
|
57
|
+
} else return left instanceof right;
|
|
65
58
|
}
|
|
66
59
|
function _object_spread(target) {
|
|
67
60
|
for(var i = 1; i < arguments.length; i++){
|