@mcp-z/mcp-sheets 2.4.0 → 2.4.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -11,49 +11,9 @@ Object.defineProperty(exports, "default", {
|
|
|
11
11
|
var _oauthgoogle = require("@mcp-z/oauth-google");
|
|
12
12
|
var _server = require("@mcp-z/server");
|
|
13
13
|
var _csvparse = require("csv-parse");
|
|
14
|
+
var _promises = require("stream/promises");
|
|
14
15
|
var _zod = require("zod");
|
|
15
16
|
var _csvstreamingts = require("../../spreadsheet/csv-streaming.js");
|
|
16
|
-
function _async_iterator(iterable) {
|
|
17
|
-
var method, async, sync, retry = 2;
|
|
18
|
-
for("undefined" != typeof Symbol && (async = Symbol.asyncIterator, sync = Symbol.iterator); retry--;){
|
|
19
|
-
if (async && null != (method = iterable[async])) return method.call(iterable);
|
|
20
|
-
if (sync && null != (method = iterable[sync])) return new AsyncFromSyncIterator(method.call(iterable));
|
|
21
|
-
async = "@@asyncIterator", sync = "@@iterator";
|
|
22
|
-
}
|
|
23
|
-
throw new TypeError("Object is not async iterable");
|
|
24
|
-
}
|
|
25
|
-
function AsyncFromSyncIterator(s) {
|
|
26
|
-
function AsyncFromSyncIteratorContinuation(r) {
|
|
27
|
-
if (Object(r) !== r) return Promise.reject(new TypeError(r + " is not an object."));
|
|
28
|
-
var done = r.done;
|
|
29
|
-
return Promise.resolve(r.value).then(function(value) {
|
|
30
|
-
return {
|
|
31
|
-
value: value,
|
|
32
|
-
done: done
|
|
33
|
-
};
|
|
34
|
-
});
|
|
35
|
-
}
|
|
36
|
-
return AsyncFromSyncIterator = function(s) {
|
|
37
|
-
this.s = s, this.n = s.next;
|
|
38
|
-
}, AsyncFromSyncIterator.prototype = {
|
|
39
|
-
s: null,
|
|
40
|
-
n: null,
|
|
41
|
-
next: function() {
|
|
42
|
-
return AsyncFromSyncIteratorContinuation(this.n.apply(this.s, arguments));
|
|
43
|
-
},
|
|
44
|
-
return: function(value) {
|
|
45
|
-
var ret = this.s.return;
|
|
46
|
-
return void 0 === ret ? Promise.resolve({
|
|
47
|
-
value: value,
|
|
48
|
-
done: !0
|
|
49
|
-
}) : AsyncFromSyncIteratorContinuation(ret.apply(this.s, arguments));
|
|
50
|
-
},
|
|
51
|
-
throw: function(value) {
|
|
52
|
-
var thr = this.s.return;
|
|
53
|
-
return void 0 === thr ? Promise.reject(value) : AsyncFromSyncIteratorContinuation(thr.apply(this.s, arguments));
|
|
54
|
-
}
|
|
55
|
-
}, new AsyncFromSyncIterator(s);
|
|
56
|
-
}
|
|
57
17
|
function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) {
|
|
58
18
|
try {
|
|
59
19
|
var info = gen[key](arg);
|
|
@@ -208,7 +168,7 @@ var config = {
|
|
|
208
168
|
};
|
|
209
169
|
function handler(_0, _1) {
|
|
210
170
|
return _async_to_generator(function(param, extra) {
|
|
211
|
-
var sourceUri, _logger_debug, logger, _logger_info,
|
|
171
|
+
var sourceUri, _logger_debug, logger, _logger_info, parser, readStream, firstRowRead, completed, firstRow, rowCount, record, error, pipelineError, columns, isEmpty, result, error1, _logger_error, message;
|
|
212
172
|
return _ts_generator(this, function(_state) {
|
|
213
173
|
switch(_state.label){
|
|
214
174
|
case 0:
|
|
@@ -221,111 +181,71 @@ function handler(_0, _1) {
|
|
|
221
181
|
case 1:
|
|
222
182
|
_state.trys.push([
|
|
223
183
|
1,
|
|
224
|
-
|
|
184
|
+
9,
|
|
225
185
|
,
|
|
226
|
-
|
|
186
|
+
10
|
|
227
187
|
]);
|
|
188
|
+
parser = (0, _csvparse.parse)({
|
|
189
|
+
columns: false,
|
|
190
|
+
skip_empty_lines: true,
|
|
191
|
+
trim: true,
|
|
192
|
+
cast: true,
|
|
193
|
+
relax_column_count: true
|
|
194
|
+
});
|
|
228
195
|
return [
|
|
229
196
|
4,
|
|
230
197
|
(0, _csvstreamingts.getCsvReadStream)(sourceUri)
|
|
231
198
|
];
|
|
232
199
|
case 2:
|
|
233
200
|
readStream = _state.sent();
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
cast: true,
|
|
241
|
-
relax_column_count: true
|
|
242
|
-
}));
|
|
243
|
-
// Read only the first row
|
|
201
|
+
firstRowRead = new Error('First CSV row read');
|
|
202
|
+
completed = (0, _promises.pipeline)(readStream, parser).then(function() {
|
|
203
|
+
return undefined;
|
|
204
|
+
}, function(error) {
|
|
205
|
+
return error;
|
|
206
|
+
});
|
|
244
207
|
firstRow = [];
|
|
245
208
|
rowCount = 0;
|
|
246
|
-
_iteratorAbruptCompletion = false, _didIteratorError = false;
|
|
247
209
|
_state.label = 3;
|
|
248
210
|
case 3:
|
|
249
211
|
_state.trys.push([
|
|
250
212
|
3,
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
213
|
+
5,
|
|
214
|
+
,
|
|
215
|
+
7
|
|
254
216
|
]);
|
|
255
|
-
_iterator = _async_iterator(parser);
|
|
256
|
-
_state.label = 4;
|
|
257
|
-
case 4:
|
|
258
217
|
return [
|
|
259
218
|
4,
|
|
260
|
-
|
|
219
|
+
parser[Symbol.asyncIterator]().next()
|
|
261
220
|
];
|
|
262
|
-
case
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
firstRow = row;
|
|
270
|
-
rowCount++;
|
|
221
|
+
case 4:
|
|
222
|
+
record = _state.sent();
|
|
223
|
+
if (!record.done) {
|
|
224
|
+
firstRow = record.value;
|
|
225
|
+
rowCount = 1;
|
|
226
|
+
parser.destroy(firstRowRead);
|
|
227
|
+
}
|
|
271
228
|
return [
|
|
272
229
|
3,
|
|
273
230
|
7
|
|
274
|
-
]; // Only read first row
|
|
275
|
-
case 6:
|
|
276
|
-
_iteratorAbruptCompletion = false;
|
|
277
|
-
return [
|
|
278
|
-
3,
|
|
279
|
-
4
|
|
280
|
-
];
|
|
281
|
-
case 7:
|
|
282
|
-
return [
|
|
283
|
-
3,
|
|
284
|
-
14
|
|
285
|
-
];
|
|
286
|
-
case 8:
|
|
287
|
-
err = _state.sent();
|
|
288
|
-
_didIteratorError = true;
|
|
289
|
-
_iteratorError = err;
|
|
290
|
-
return [
|
|
291
|
-
3,
|
|
292
|
-
14
|
|
293
|
-
];
|
|
294
|
-
case 9:
|
|
295
|
-
_state.trys.push([
|
|
296
|
-
9,
|
|
297
|
-
,
|
|
298
|
-
12,
|
|
299
|
-
13
|
|
300
|
-
]);
|
|
301
|
-
if (!(_iteratorAbruptCompletion && _iterator.return != null)) return [
|
|
302
|
-
3,
|
|
303
|
-
11
|
|
304
231
|
];
|
|
232
|
+
case 5:
|
|
233
|
+
error = _state.sent();
|
|
305
234
|
return [
|
|
306
235
|
4,
|
|
307
|
-
|
|
236
|
+
completed
|
|
308
237
|
];
|
|
309
|
-
case
|
|
238
|
+
case 6:
|
|
310
239
|
_state.sent();
|
|
311
|
-
|
|
312
|
-
case
|
|
313
|
-
return [
|
|
314
|
-
3,
|
|
315
|
-
13
|
|
316
|
-
];
|
|
317
|
-
case 12:
|
|
318
|
-
if (_didIteratorError) {
|
|
319
|
-
throw _iteratorError;
|
|
320
|
-
}
|
|
321
|
-
return [
|
|
322
|
-
7
|
|
323
|
-
];
|
|
324
|
-
case 13:
|
|
240
|
+
throw error;
|
|
241
|
+
case 7:
|
|
325
242
|
return [
|
|
326
|
-
|
|
243
|
+
4,
|
|
244
|
+
completed
|
|
327
245
|
];
|
|
328
|
-
case
|
|
246
|
+
case 8:
|
|
247
|
+
pipelineError = _state.sent();
|
|
248
|
+
if (pipelineError !== undefined && pipelineError !== firstRowRead) throw pipelineError;
|
|
329
249
|
// Convert first row to strings (column names)
|
|
330
250
|
columns = firstRow.map(function(value) {
|
|
331
251
|
return String(value !== null && value !== void 0 ? value : '');
|
|
@@ -355,16 +275,16 @@ function handler(_0, _1) {
|
|
|
355
275
|
}
|
|
356
276
|
}
|
|
357
277
|
];
|
|
358
|
-
case
|
|
359
|
-
|
|
360
|
-
message = _instanceof(
|
|
278
|
+
case 9:
|
|
279
|
+
error1 = _state.sent();
|
|
280
|
+
message = _instanceof(error1, Error) ? error1.message : String(error1);
|
|
361
281
|
(_logger_error = logger.error) === null || _logger_error === void 0 ? void 0 : _logger_error.call(logger, 'sheets.csv.get-columns error', {
|
|
362
282
|
error: message
|
|
363
283
|
});
|
|
364
284
|
throw new _server.ProtocolError(_server.ProtocolErrorCode.InternalError, "Error getting CSV columns: ".concat(message), {
|
|
365
|
-
stack: _instanceof(
|
|
285
|
+
stack: _instanceof(error1, Error) ? error1.stack : undefined
|
|
366
286
|
});
|
|
367
|
-
case
|
|
287
|
+
case 10:
|
|
368
288
|
return [
|
|
369
289
|
2
|
|
370
290
|
];
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["/Users/kevin/Dev/open-source/ai/mcp-z/mcp-sheets/src/mcp/tools/csv-get-columns.ts"],"sourcesContent":["/** Get column names from CSV file (peek at first row only) */\n\nimport type { EnrichedExtra } from '@mcp-z/oauth-google';\nimport { schemas } from '@mcp-z/oauth-google';\n\nconst { AuthRequiredBranchSchema } = schemas;\n\nimport type { CallToolResult, ToolModule } from '@mcp-z/server';\nimport { ProtocolError, ProtocolErrorCode } from '@mcp-z/server';\nimport { parse } from 'csv-parse';\nimport { z } from 'zod';\nimport { getCsvReadStream } from '../../spreadsheet/csv-streaming.ts';\n\nconst inputSchema = z.object({\n sourceUri: z.string().trim().min(1).describe('CSV file URI (file://, http://, https://)'),\n});\n\n// Success branch schema - uses columns: for consistency with standard vocabulary\nconst successBranchSchema = z.object({\n type: z.literal('success'),\n columns: z.array(z.string()).describe('First row values (column names) or empty if no rows'),\n isEmpty: z.boolean().describe('True if CSV has zero rows'),\n});\n\nconst outputSchema = z.discriminatedUnion('type', [successBranchSchema, AuthRequiredBranchSchema]);\n\nconst config = {\n description: 'Get first row from CSV file (streaming, no memory overhead). Returns columns array and isEmpty flag.',\n inputSchema,\n outputSchema: z.object({\n result: outputSchema,\n }),\n} as const;\n\nexport type Input = z.infer<typeof inputSchema>;\nexport type Output = z.infer<typeof outputSchema>;\n\nasync function handler({ sourceUri }: Input, extra: EnrichedExtra): Promise<CallToolResult> {\n const logger = extra.logger;\n logger.debug?.('sheets.csv.get-columns called', { sourceUri });\n\n try {\n
|
|
1
|
+
{"version":3,"sources":["/Users/kevin/Dev/open-source/ai/mcp-z/mcp-sheets/src/mcp/tools/csv-get-columns.ts"],"sourcesContent":["/** Get column names from CSV file (peek at first row only) */\n\nimport type { EnrichedExtra } from '@mcp-z/oauth-google';\nimport { schemas } from '@mcp-z/oauth-google';\n\nconst { AuthRequiredBranchSchema } = schemas;\n\nimport type { CallToolResult, ToolModule } from '@mcp-z/server';\nimport { ProtocolError, ProtocolErrorCode } from '@mcp-z/server';\nimport { parse } from 'csv-parse';\nimport { pipeline } from 'stream/promises';\nimport { z } from 'zod';\nimport { getCsvReadStream } from '../../spreadsheet/csv-streaming.ts';\n\nconst inputSchema = z.object({\n sourceUri: z.string().trim().min(1).describe('CSV file URI (file://, http://, https://)'),\n});\n\n// Success branch schema - uses columns: for consistency with standard vocabulary\nconst successBranchSchema = z.object({\n type: z.literal('success'),\n columns: z.array(z.string()).describe('First row values (column names) or empty if no rows'),\n isEmpty: z.boolean().describe('True if CSV has zero rows'),\n});\n\nconst outputSchema = z.discriminatedUnion('type', [successBranchSchema, AuthRequiredBranchSchema]);\n\nconst config = {\n description: 'Get first row from CSV file (streaming, no memory overhead). Returns columns array and isEmpty flag.',\n inputSchema,\n outputSchema: z.object({\n result: outputSchema,\n }),\n} as const;\n\nexport type Input = z.infer<typeof inputSchema>;\nexport type Output = z.infer<typeof outputSchema>;\n\nasync function handler({ sourceUri }: Input, extra: EnrichedExtra): Promise<CallToolResult> {\n const logger = extra.logger;\n logger.debug?.('sheets.csv.get-columns called', { sourceUri });\n\n try {\n const parser = parse({\n columns: false,\n skip_empty_lines: true,\n trim: true,\n cast: true,\n relax_column_count: true,\n });\n const readStream = await getCsvReadStream(sourceUri);\n const firstRowRead = new Error('First CSV row read');\n const completed = pipeline(readStream, parser).then(\n () => undefined,\n (error: unknown) => error\n );\n\n let firstRow: unknown[] = [];\n let rowCount = 0;\n try {\n const record = await parser[Symbol.asyncIterator]().next();\n if (!record.done) {\n firstRow = record.value;\n rowCount = 1;\n parser.destroy(firstRowRead);\n }\n } catch (error) {\n await completed;\n throw error;\n }\n\n const pipelineError = await completed;\n if (pipelineError !== undefined && pipelineError !== firstRowRead) throw pipelineError;\n\n // Convert first row to strings (column names)\n const columns = firstRow.map((value) => String(value ?? ''));\n const isEmpty = rowCount === 0;\n\n const result: Output = {\n type: 'success' as const,\n columns,\n isEmpty,\n };\n\n logger.info?.('sheets.csv.get-columns completed', { sourceUri, columnCount: columns.length, isEmpty });\n return {\n content: [{ type: 'text' as const, text: JSON.stringify(result) }],\n structuredContent: { result },\n };\n } catch (error) {\n const message = error instanceof Error ? error.message : String(error);\n logger.error?.('sheets.csv.get-columns error', { error: message });\n throw new ProtocolError(ProtocolErrorCode.InternalError, `Error getting CSV columns: ${message}`, {\n stack: error instanceof Error ? error.stack : undefined,\n });\n }\n}\n\nexport default function createTool() {\n return {\n name: 'csv-get-columns',\n config,\n handler,\n } satisfies ToolModule;\n}\n"],"names":["createTool","AuthRequiredBranchSchema","schemas","inputSchema","z","object","sourceUri","string","trim","min","describe","successBranchSchema","type","literal","columns","array","isEmpty","boolean","outputSchema","discriminatedUnion","config","description","result","handler","extra","logger","parser","readStream","firstRowRead","completed","firstRow","rowCount","record","error","pipelineError","message","debug","parse","skip_empty_lines","cast","relax_column_count","getCsvReadStream","Error","pipeline","then","undefined","Symbol","asyncIterator","next","done","value","destroy","map","String","info","columnCount","length","content","text","JSON","stringify","structuredContent","ProtocolError","ProtocolErrorCode","InternalError","stack","name"],"mappings":"AAAA,4DAA4D;;;;+BAkG5D;;;eAAwBA;;;2BA/FA;sBAKyB;wBAC3B;wBAC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AAM,IAAI2B,qBAAa,CAACC,yBAAiB,CAACC,aAAa,EAAE,AAAC,8BAAqC,OAAR7B,UAAW;wBAChG8B,OAAOhC,AAAK,YAALA,QAAiBS,SAAQT,OAAMgC,KAAK,GAAGpB;oBAChD;;;;;;;IAEJ;;AAEe,SAAS7C;IACtB,OAAO;QACLkE,MAAM;QACN9C,QAAAA;QACAG,SAAAA;IACF;AACF"}
|
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
const { AuthRequiredBranchSchema } = schemas;
|
|
3
3
|
import { ProtocolError, ProtocolErrorCode } from '@mcp-z/server';
|
|
4
4
|
import { parse } from 'csv-parse';
|
|
5
|
+
import { pipeline } from 'stream/promises';
|
|
5
6
|
import { z } from 'zod';
|
|
6
7
|
import { getCsvReadStream } from '../../spreadsheet/csv-streaming.js';
|
|
7
8
|
const inputSchema = z.object({
|
|
@@ -32,25 +33,31 @@ async function handler({ sourceUri }, extra) {
|
|
|
32
33
|
});
|
|
33
34
|
try {
|
|
34
35
|
var _logger_info;
|
|
35
|
-
|
|
36
|
-
const readStream = await getCsvReadStream(sourceUri);
|
|
37
|
-
// Create CSV parser without treating first row as column names
|
|
38
|
-
// We just want to read the raw first row
|
|
39
|
-
const parser = readStream.pipe(parse({
|
|
36
|
+
const parser = parse({
|
|
40
37
|
columns: false,
|
|
41
38
|
skip_empty_lines: true,
|
|
42
39
|
trim: true,
|
|
43
40
|
cast: true,
|
|
44
41
|
relax_column_count: true
|
|
45
|
-
})
|
|
46
|
-
|
|
42
|
+
});
|
|
43
|
+
const readStream = await getCsvReadStream(sourceUri);
|
|
44
|
+
const firstRowRead = new Error('First CSV row read');
|
|
45
|
+
const completed = pipeline(readStream, parser).then(()=>undefined, (error)=>error);
|
|
47
46
|
let firstRow = [];
|
|
48
47
|
let rowCount = 0;
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
48
|
+
try {
|
|
49
|
+
const record = await parser[Symbol.asyncIterator]().next();
|
|
50
|
+
if (!record.done) {
|
|
51
|
+
firstRow = record.value;
|
|
52
|
+
rowCount = 1;
|
|
53
|
+
parser.destroy(firstRowRead);
|
|
54
|
+
}
|
|
55
|
+
} catch (error) {
|
|
56
|
+
await completed;
|
|
57
|
+
throw error;
|
|
53
58
|
}
|
|
59
|
+
const pipelineError = await completed;
|
|
60
|
+
if (pipelineError !== undefined && pipelineError !== firstRowRead) throw pipelineError;
|
|
54
61
|
// Convert first row to strings (column names)
|
|
55
62
|
const columns = firstRow.map((value)=>String(value !== null && value !== void 0 ? value : ''));
|
|
56
63
|
const isEmpty = rowCount === 0;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["/Users/kevin/Dev/open-source/ai/mcp-z/mcp-sheets/src/mcp/tools/csv-get-columns.ts"],"sourcesContent":["/** Get column names from CSV file (peek at first row only) */\n\nimport type { EnrichedExtra } from '@mcp-z/oauth-google';\nimport { schemas } from '@mcp-z/oauth-google';\n\nconst { AuthRequiredBranchSchema } = schemas;\n\nimport type { CallToolResult, ToolModule } from '@mcp-z/server';\nimport { ProtocolError, ProtocolErrorCode } from '@mcp-z/server';\nimport { parse } from 'csv-parse';\nimport { z } from 'zod';\nimport { getCsvReadStream } from '../../spreadsheet/csv-streaming.ts';\n\nconst inputSchema = z.object({\n sourceUri: z.string().trim().min(1).describe('CSV file URI (file://, http://, https://)'),\n});\n\n// Success branch schema - uses columns: for consistency with standard vocabulary\nconst successBranchSchema = z.object({\n type: z.literal('success'),\n columns: z.array(z.string()).describe('First row values (column names) or empty if no rows'),\n isEmpty: z.boolean().describe('True if CSV has zero rows'),\n});\n\nconst outputSchema = z.discriminatedUnion('type', [successBranchSchema, AuthRequiredBranchSchema]);\n\nconst config = {\n description: 'Get first row from CSV file (streaming, no memory overhead). Returns columns array and isEmpty flag.',\n inputSchema,\n outputSchema: z.object({\n result: outputSchema,\n }),\n} as const;\n\nexport type Input = z.infer<typeof inputSchema>;\nexport type Output = z.infer<typeof outputSchema>;\n\nasync function handler({ sourceUri }: Input, extra: EnrichedExtra): Promise<CallToolResult> {\n const logger = extra.logger;\n logger.debug?.('sheets.csv.get-columns called', { sourceUri });\n\n try {\n
|
|
1
|
+
{"version":3,"sources":["/Users/kevin/Dev/open-source/ai/mcp-z/mcp-sheets/src/mcp/tools/csv-get-columns.ts"],"sourcesContent":["/** Get column names from CSV file (peek at first row only) */\n\nimport type { EnrichedExtra } from '@mcp-z/oauth-google';\nimport { schemas } from '@mcp-z/oauth-google';\n\nconst { AuthRequiredBranchSchema } = schemas;\n\nimport type { CallToolResult, ToolModule } from '@mcp-z/server';\nimport { ProtocolError, ProtocolErrorCode } from '@mcp-z/server';\nimport { parse } from 'csv-parse';\nimport { pipeline } from 'stream/promises';\nimport { z } from 'zod';\nimport { getCsvReadStream } from '../../spreadsheet/csv-streaming.ts';\n\nconst inputSchema = z.object({\n sourceUri: z.string().trim().min(1).describe('CSV file URI (file://, http://, https://)'),\n});\n\n// Success branch schema - uses columns: for consistency with standard vocabulary\nconst successBranchSchema = z.object({\n type: z.literal('success'),\n columns: z.array(z.string()).describe('First row values (column names) or empty if no rows'),\n isEmpty: z.boolean().describe('True if CSV has zero rows'),\n});\n\nconst outputSchema = z.discriminatedUnion('type', [successBranchSchema, AuthRequiredBranchSchema]);\n\nconst config = {\n description: 'Get first row from CSV file (streaming, no memory overhead). Returns columns array and isEmpty flag.',\n inputSchema,\n outputSchema: z.object({\n result: outputSchema,\n }),\n} as const;\n\nexport type Input = z.infer<typeof inputSchema>;\nexport type Output = z.infer<typeof outputSchema>;\n\nasync function handler({ sourceUri }: Input, extra: EnrichedExtra): Promise<CallToolResult> {\n const logger = extra.logger;\n logger.debug?.('sheets.csv.get-columns called', { sourceUri });\n\n try {\n const parser = parse({\n columns: false,\n skip_empty_lines: true,\n trim: true,\n cast: true,\n relax_column_count: true,\n });\n const readStream = await getCsvReadStream(sourceUri);\n const firstRowRead = new Error('First CSV row read');\n const completed = pipeline(readStream, parser).then(\n () => undefined,\n (error: unknown) => error\n );\n\n let firstRow: unknown[] = [];\n let rowCount = 0;\n try {\n const record = await parser[Symbol.asyncIterator]().next();\n if (!record.done) {\n firstRow = record.value;\n rowCount = 1;\n parser.destroy(firstRowRead);\n }\n } catch (error) {\n await completed;\n throw error;\n }\n\n const pipelineError = await completed;\n if (pipelineError !== undefined && pipelineError !== firstRowRead) throw pipelineError;\n\n // Convert first row to strings (column names)\n const columns = firstRow.map((value) => String(value ?? ''));\n const isEmpty = rowCount === 0;\n\n const result: Output = {\n type: 'success' as const,\n columns,\n isEmpty,\n };\n\n logger.info?.('sheets.csv.get-columns completed', { sourceUri, columnCount: columns.length, isEmpty });\n return {\n content: [{ type: 'text' as const, text: JSON.stringify(result) }],\n structuredContent: { result },\n };\n } catch (error) {\n const message = error instanceof Error ? error.message : String(error);\n logger.error?.('sheets.csv.get-columns error', { error: message });\n throw new ProtocolError(ProtocolErrorCode.InternalError, `Error getting CSV columns: ${message}`, {\n stack: error instanceof Error ? error.stack : undefined,\n });\n }\n}\n\nexport default function createTool() {\n return {\n name: 'csv-get-columns',\n config,\n handler,\n } satisfies ToolModule;\n}\n"],"names":["schemas","AuthRequiredBranchSchema","ProtocolError","ProtocolErrorCode","parse","pipeline","z","getCsvReadStream","inputSchema","object","sourceUri","string","trim","min","describe","successBranchSchema","type","literal","columns","array","isEmpty","boolean","outputSchema","discriminatedUnion","config","description","result","handler","extra","logger","debug","parser","skip_empty_lines","cast","relax_column_count","readStream","firstRowRead","Error","completed","then","undefined","error","firstRow","rowCount","record","Symbol","asyncIterator","next","done","value","destroy","pipelineError","map","String","info","columnCount","length","content","text","JSON","stringify","structuredContent","message","InternalError","stack","createTool","name"],"mappings":"AAAA,4DAA4D,GAG5D,SAASA,OAAO,QAAQ,sBAAsB;AAE9C,MAAM,EAAEC,wBAAwB,EAAE,GAAGD;AAGrC,SAASE,aAAa,EAAEC,iBAAiB,QAAQ,gBAAgB;AACjE,SAASC,KAAK,QAAQ,YAAY;AAClC,SAASC,QAAQ,QA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CP server for Google Sheets integration with OAuth authentication, spreadsheet management, batch operations, and advanced formatting",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"sheets",
|
|
@@ -61,10 +61,10 @@
|
|
|
61
61
|
"format": "tsds format",
|
|
62
62
|
"prepublish:check": "ncp",
|
|
63
63
|
"prepublishOnly": "node scripts/require-dist-tag.cjs && tsds validate",
|
|
64
|
-
"test": "tsds test:node --
|
|
65
|
-
"test:ci": "tsds test:node --
|
|
66
|
-
"test:ci:engines": "nvu engines tsds test:node --
|
|
67
|
-
"test:engines": "nvu engines tsds test:node --
|
|
64
|
+
"test": "tsds test:node --no-timeouts",
|
|
65
|
+
"test:ci": "tsds test:node --no-timeouts",
|
|
66
|
+
"test:ci:engines": "nvu engines tsds test:node --no-timeouts",
|
|
67
|
+
"test:engines": "nvu engines tsds test:node --no-timeouts",
|
|
68
68
|
"test:setup": "node scripts/setup-test.ts",
|
|
69
69
|
"version": "tsds version"
|
|
70
70
|
},
|
|
@@ -84,7 +84,7 @@
|
|
|
84
84
|
"zod": "^4.2.0"
|
|
85
85
|
},
|
|
86
86
|
"devDependencies": {
|
|
87
|
-
"@mcp-z/client": "^2.
|
|
87
|
+
"@mcp-z/client": "^2.4.0",
|
|
88
88
|
"@modelcontextprotocol/sdk": "^1.0.0",
|
|
89
89
|
"@types/cors": "^2.8.19",
|
|
90
90
|
"@types/express": "^5.0.6",
|