@mindstone/mcp-server-google-workspace 0.4.2 → 0.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +43 -5
- package/dist/modules/docs/service.d.ts +76 -6
- package/dist/modules/docs/service.js +791 -103
- package/dist/modules/docs/tabCopy.d.ts +266 -0
- package/dist/modules/docs/tabCopy.js +794 -0
- package/dist/modules/docs/tabs.d.ts +161 -0
- package/dist/modules/docs/tabs.js +416 -0
- package/dist/modules/docs/types.d.ts +141 -1
- package/dist/modules/drive/service.d.ts +15 -0
- package/dist/modules/drive/service.js +77 -2
- package/dist/modules/drive/types.d.ts +1 -1
- package/dist/modules/sheets/a1Utils.d.ts +13 -0
- package/dist/modules/sheets/a1Utils.js +33 -7
- package/dist/modules/sheets/formatters.d.ts +33 -2
- package/dist/modules/sheets/formatters.js +84 -5
- package/dist/modules/sheets/service.d.ts +26 -1
- package/dist/modules/sheets/service.js +264 -8
- package/dist/modules/sheets/types.d.ts +71 -0
- package/dist/modules/sheets/types.js +12 -1
- package/dist/modules/sheets/writeGuards.js +2 -2
- package/dist/tools/definitions/destructive-overrides.json +8 -0
- package/dist/tools/definitions/docs.js +395 -9
- package/dist/tools/definitions/drive.js +9 -4
- package/dist/tools/definitions/open-world-overrides.json +8 -0
- package/dist/tools/definitions/sheets.js +177 -1
- package/dist/tools/docs-handlers.d.ts +125 -0
- package/dist/tools/docs-handlers.js +397 -15
- package/dist/tools/param-normalizer.js +16 -0
- package/dist/tools/server.js +35 -3
- package/dist/tools/sheets-handlers.d.ts +54 -1
- package/dist/tools/sheets-handlers.js +107 -13
- package/dist/tools/type-guards.d.ts +89 -0
- package/dist/tools/type-guards.js +190 -6
- package/dist/tools/types.d.ts +1 -1
- package/dist/utils/apiError.d.ts +6 -0
- package/dist/utils/apiError.js +12 -0
- package/dist/utils/tabPosition.d.ts +20 -0
- package/dist/utils/tabPosition.js +19 -0
- package/package.json +1 -1
|
@@ -1,16 +1,20 @@
|
|
|
1
1
|
import { google } from 'googleapis';
|
|
2
2
|
import { BaseGoogleService } from '../../services/base/BaseGoogleService.js';
|
|
3
|
-
import { isAuthHandoffError } from '../../utils/apiError.js';
|
|
3
|
+
import { describeApiErrorUntrusted, isAuthHandoffError } from '../../utils/apiError.js';
|
|
4
|
+
import { computeMoveApiIndex } from '../../utils/tabPosition.js';
|
|
5
|
+
import { SheetsInputError, } from './types.js';
|
|
4
6
|
import { SHEETS_SCOPES } from './scopes.js';
|
|
5
7
|
import { buildAnchorEnvelope, buildShapedReadResponse, ContinuationTokenError, mergeFormulaAndValue, parseContinuationToken, } from './cellShape.js';
|
|
6
8
|
import { rewriteSheetsApiError } from './errorRewriter.js';
|
|
7
|
-
import { parseA1Range,
|
|
9
|
+
import { parseA1Range, quoteSheetTitle, rowCountFromA1 } from './a1Utils.js';
|
|
8
10
|
import { detectFormulaOverwrite, detectRawFormulaLiterals, detectSuspiciousWrites, } from './writeGuards.js';
|
|
9
11
|
import logger from '../../utils/logger.js';
|
|
10
12
|
const DEFAULT_MAX_ROWS = 1000;
|
|
11
13
|
const DEFAULT_MAX_COLS = 26; // A-Z
|
|
12
14
|
const ANCHOR_FIRST_ROWS = 50;
|
|
13
15
|
const ANCHOR_LAST_ROWS = 10;
|
|
16
|
+
/** Most rows/columns insert_workspace_spreadsheet_dimension adds in one call. */
|
|
17
|
+
export const MAX_INSERT_DIMENSION_COUNT = 100;
|
|
14
18
|
export class SheetsService extends BaseGoogleService {
|
|
15
19
|
initialized = false;
|
|
16
20
|
constructor() {
|
|
@@ -169,7 +173,7 @@ export class SheetsService extends BaseGoogleService {
|
|
|
169
173
|
return activeStartRow;
|
|
170
174
|
}
|
|
171
175
|
buildA1WindowRange(sheetTitle, startCol, endCol, startRow, endRow) {
|
|
172
|
-
const normalizedSheetName =
|
|
176
|
+
const normalizedSheetName = quoteSheetTitle(sheetTitle);
|
|
173
177
|
return {
|
|
174
178
|
a1: `${normalizedSheetName}!${startCol}${startRow}:${endCol}${endRow}`,
|
|
175
179
|
startRow,
|
|
@@ -309,7 +313,7 @@ export class SheetsService extends BaseGoogleService {
|
|
|
309
313
|
continuationPayloadToRange(payload) {
|
|
310
314
|
const startCol = payload.startCol ?? 'A';
|
|
311
315
|
const endCol = payload.endCol ?? startCol;
|
|
312
|
-
const sheet = payload.sheet ?
|
|
316
|
+
const sheet = payload.sheet ? quoteSheetTitle(payload.sheet) : undefined;
|
|
313
317
|
const rowRange = `${startCol}${payload.startRow}:${endCol}${payload.endRow}`;
|
|
314
318
|
return sheet ? `${sheet}!${rowRange}` : rowRange;
|
|
315
319
|
}
|
|
@@ -340,7 +344,7 @@ export class SheetsService extends BaseGoogleService {
|
|
|
340
344
|
}
|
|
341
345
|
const sheetTitle = targetSheet?.properties?.title ?? payload.sheet;
|
|
342
346
|
const continuationRange = sheetTitle
|
|
343
|
-
? `${
|
|
347
|
+
? `${quoteSheetTitle(sheetTitle)}!${payload.startCol ?? 'A'}${payload.startRow}:${payload.endCol ?? (payload.startCol ?? 'A')}${payload.endRow}`
|
|
344
348
|
: this.continuationPayloadToRange(payload);
|
|
345
349
|
if (options.valueView === 'shaped') {
|
|
346
350
|
const [formattedResult, formulaResult] = await Promise.allSettled([
|
|
@@ -393,6 +397,7 @@ export class SheetsService extends BaseGoogleService {
|
|
|
393
397
|
spreadsheetId,
|
|
394
398
|
spreadsheetUrl: this.constructSpreadsheetUrl(spreadsheetId),
|
|
395
399
|
values: this.toCellMatrix(response.data.values),
|
|
400
|
+
valuesRange: response.data.range || continuationRange,
|
|
396
401
|
},
|
|
397
402
|
};
|
|
398
403
|
}
|
|
@@ -416,6 +421,7 @@ export class SheetsService extends BaseGoogleService {
|
|
|
416
421
|
let values;
|
|
417
422
|
let shapedValues;
|
|
418
423
|
let anchorValues;
|
|
424
|
+
let valuesRange;
|
|
419
425
|
let truncated = false;
|
|
420
426
|
if (options.range) {
|
|
421
427
|
if (options.valueView === 'shaped') {
|
|
@@ -456,6 +462,7 @@ export class SheetsService extends BaseGoogleService {
|
|
|
456
462
|
else {
|
|
457
463
|
const valueRange = valuesResult.data;
|
|
458
464
|
values = this.toCellMatrix(valueRange.values);
|
|
465
|
+
valuesRange = valueRange.range || options.range;
|
|
459
466
|
// Apply truncation if needed
|
|
460
467
|
const maxRows = options.maxRows ?? DEFAULT_MAX_ROWS;
|
|
461
468
|
const maxCols = options.maxCols ?? DEFAULT_MAX_COLS;
|
|
@@ -485,6 +492,8 @@ export class SheetsService extends BaseGoogleService {
|
|
|
485
492
|
truncated,
|
|
486
493
|
shapedValues,
|
|
487
494
|
anchorValues,
|
|
495
|
+
// Text output only: the JSON shape stays as it was.
|
|
496
|
+
...(valuesRange !== undefined && !options.returnJson ? { valuesRange } : {}),
|
|
488
497
|
};
|
|
489
498
|
const preserveLegacySpreadsheetJsonShape = options.returnJson
|
|
490
499
|
&& options.valueView === undefined
|
|
@@ -548,6 +557,7 @@ export class SheetsService extends BaseGoogleService {
|
|
|
548
557
|
spreadsheetId,
|
|
549
558
|
spreadsheetUrl: this.constructSpreadsheetUrl(spreadsheetId),
|
|
550
559
|
values,
|
|
560
|
+
valuesRange: response.data.range || options.range,
|
|
551
561
|
};
|
|
552
562
|
return {
|
|
553
563
|
success: true,
|
|
@@ -757,7 +767,7 @@ export class SheetsService extends BaseGoogleService {
|
|
|
757
767
|
}
|
|
758
768
|
const endRow = parsed.startRow - 1;
|
|
759
769
|
const startRow = Math.max(1, endRow - 199);
|
|
760
|
-
const sheetPrefix = parsed.sheetName ? `${
|
|
770
|
+
const sheetPrefix = parsed.sheetName ? `${quoteSheetTitle(parsed.sheetName)}!` : '';
|
|
761
771
|
const contextRange = `${sheetPrefix}${parsed.startCol}${startRow}:${parsed.startCol}${endRow}`;
|
|
762
772
|
try {
|
|
763
773
|
const response = await client.spreadsheets.values.get({
|
|
@@ -816,7 +826,7 @@ export class SheetsService extends BaseGoogleService {
|
|
|
816
826
|
column: columnLetter,
|
|
817
827
|
rows: Array.from({ length: values.length }, (_, index) => appendedStartRow + index),
|
|
818
828
|
suggestedFormula: formula,
|
|
819
|
-
detail: `Possible formula opportunity: column ${columnLetter} appears to use a fill-down formula in ${
|
|
829
|
+
detail: `Possible formula opportunity: column ${columnLetter} appears to use a fill-down formula in ${quoteSheetTitle(sheetTitle)}!${columnLetter}${lastFormulaRowIndex + 1}. New row(s) ${appendedStartRow}-${endRow} will break the pattern. Consider extending the formula range or copying the formula.`,
|
|
820
830
|
});
|
|
821
831
|
}
|
|
822
832
|
return warnings;
|
|
@@ -849,7 +859,7 @@ export class SheetsService extends BaseGoogleService {
|
|
|
849
859
|
const startColLetter = this.columnIndexToLetter(startColIndex + 1);
|
|
850
860
|
const endColLetter = this.columnIndexToLetter(endColIndex + 1);
|
|
851
861
|
const readStartRow = Math.max(1, rowCount - 4);
|
|
852
|
-
const sheetName =
|
|
862
|
+
const sheetName = quoteSheetTitle(targetSheet.properties.title);
|
|
853
863
|
const formulaReadRange = `${sheetName}!${startColLetter}${readStartRow}:${endColLetter}${rowCount}`;
|
|
854
864
|
const formulaRead = await client.spreadsheets.get({
|
|
855
865
|
spreadsheetId,
|
|
@@ -1230,6 +1240,208 @@ export class SheetsService extends BaseGoogleService {
|
|
|
1230
1240
|
};
|
|
1231
1241
|
}
|
|
1232
1242
|
}
|
|
1243
|
+
/**
|
|
1244
|
+
* Duplicate a sheet (tab) inside the same spreadsheet. Google copies values,
|
|
1245
|
+
* formulas, formatting, merges and validation. `position` is the 0-based
|
|
1246
|
+
* position of the copy; it defaults to right after the source.
|
|
1247
|
+
*/
|
|
1248
|
+
async duplicateSheet(email, options) {
|
|
1249
|
+
try {
|
|
1250
|
+
const newTitle = options.title !== undefined ? requireSheetTitle(options.title) : undefined;
|
|
1251
|
+
const client = await this.getWriteClient(email);
|
|
1252
|
+
const sheets = await this.readSheetList(client, options.spreadsheetId);
|
|
1253
|
+
const source = findSheet(sheets, { sheetId: options.sheetId, sheetTitle: options.sheetTitle });
|
|
1254
|
+
// Inserting a new sheet: no before-removal adjustment, any index 0..count.
|
|
1255
|
+
assertSheetPosition(options.position, sheets.length);
|
|
1256
|
+
const position = options.position ?? source.index + 1;
|
|
1257
|
+
const duplicateSheet = {
|
|
1258
|
+
sourceSheetId: source.sheetId,
|
|
1259
|
+
insertSheetIndex: position,
|
|
1260
|
+
};
|
|
1261
|
+
if (newTitle !== undefined)
|
|
1262
|
+
duplicateSheet.newSheetName = newTitle;
|
|
1263
|
+
const response = await client.spreadsheets.batchUpdate({
|
|
1264
|
+
spreadsheetId: options.spreadsheetId,
|
|
1265
|
+
requestBody: { requests: [{ duplicateSheet }] },
|
|
1266
|
+
});
|
|
1267
|
+
const properties = response.data.replies?.[0]?.duplicateSheet?.properties;
|
|
1268
|
+
if (!properties || typeof properties.sheetId !== 'number') {
|
|
1269
|
+
throw new Error('Duplicate sheet returned no sheet properties; check list_workspace_spreadsheet_sheets before retrying');
|
|
1270
|
+
}
|
|
1271
|
+
return {
|
|
1272
|
+
success: true,
|
|
1273
|
+
data: {
|
|
1274
|
+
spreadsheetId: options.spreadsheetId,
|
|
1275
|
+
sourceSheetId: source.sheetId,
|
|
1276
|
+
sheet: this.extractSheetInfo({ properties }),
|
|
1277
|
+
requestedPosition: position,
|
|
1278
|
+
},
|
|
1279
|
+
};
|
|
1280
|
+
}
|
|
1281
|
+
catch (error) {
|
|
1282
|
+
return toSheetTabFailure(error);
|
|
1283
|
+
}
|
|
1284
|
+
}
|
|
1285
|
+
/**
|
|
1286
|
+
* Rename and/or reorder a sheet. `position` is the 0-based position the sheet
|
|
1287
|
+
* should end up at; the API's before-removal index is computed here. A call
|
|
1288
|
+
* that changes nothing makes no write. Reports the actual title and position
|
|
1289
|
+
* after the write.
|
|
1290
|
+
*/
|
|
1291
|
+
async updateSheet(email, options) {
|
|
1292
|
+
try {
|
|
1293
|
+
if (options.title === undefined && options.position === undefined) {
|
|
1294
|
+
throw new SheetsInputError('Pass at least one of title or position.');
|
|
1295
|
+
}
|
|
1296
|
+
const newTitle = options.title !== undefined ? requireSheetTitle(options.title) : undefined;
|
|
1297
|
+
const client = await this.getWriteClient(email);
|
|
1298
|
+
const sheets = await this.readSheetList(client, options.spreadsheetId);
|
|
1299
|
+
const current = findSheet(sheets, { sheetId: options.sheetId, sheetTitle: options.sheetTitle });
|
|
1300
|
+
// Final position among all sheets, the moved sheet included.
|
|
1301
|
+
assertSheetPosition(options.position, sheets.length - 1);
|
|
1302
|
+
const targetPosition = options.position ?? current.index;
|
|
1303
|
+
const titleChanged = newTitle !== undefined && newTitle !== current.title;
|
|
1304
|
+
const positionChanged = targetPosition !== current.index;
|
|
1305
|
+
if (!titleChanged && !positionChanged) {
|
|
1306
|
+
return {
|
|
1307
|
+
success: true,
|
|
1308
|
+
data: {
|
|
1309
|
+
spreadsheetId: options.spreadsheetId,
|
|
1310
|
+
sheet: current,
|
|
1311
|
+
changed: false,
|
|
1312
|
+
requestedPosition: targetPosition,
|
|
1313
|
+
},
|
|
1314
|
+
};
|
|
1315
|
+
}
|
|
1316
|
+
const properties = { sheetId: current.sheetId };
|
|
1317
|
+
const fields = [];
|
|
1318
|
+
if (titleChanged) {
|
|
1319
|
+
properties.title = newTitle;
|
|
1320
|
+
fields.push('title');
|
|
1321
|
+
}
|
|
1322
|
+
if (positionChanged) {
|
|
1323
|
+
properties.index = computeMoveApiIndex({
|
|
1324
|
+
sameParent: true,
|
|
1325
|
+
currentIndex: current.index,
|
|
1326
|
+
targetPosition,
|
|
1327
|
+
});
|
|
1328
|
+
fields.push('index');
|
|
1329
|
+
}
|
|
1330
|
+
await client.spreadsheets.batchUpdate({
|
|
1331
|
+
spreadsheetId: options.spreadsheetId,
|
|
1332
|
+
requestBody: {
|
|
1333
|
+
requests: [{ updateSheetProperties: { properties, fields: fields.join(',') } }],
|
|
1334
|
+
},
|
|
1335
|
+
});
|
|
1336
|
+
const after = await this.readSheetList(client, options.spreadsheetId);
|
|
1337
|
+
const updated = after.find((sheet) => sheet.sheetId === current.sheetId);
|
|
1338
|
+
if (!updated) {
|
|
1339
|
+
throw new Error(`Updated sheet ${current.sheetId} is missing from the spreadsheet's sheet list`);
|
|
1340
|
+
}
|
|
1341
|
+
return {
|
|
1342
|
+
success: true,
|
|
1343
|
+
data: {
|
|
1344
|
+
spreadsheetId: options.spreadsheetId,
|
|
1345
|
+
sheet: updated,
|
|
1346
|
+
changed: true,
|
|
1347
|
+
requestedPosition: targetPosition,
|
|
1348
|
+
},
|
|
1349
|
+
};
|
|
1350
|
+
}
|
|
1351
|
+
catch (error) {
|
|
1352
|
+
return toSheetTabFailure(error);
|
|
1353
|
+
}
|
|
1354
|
+
}
|
|
1355
|
+
/**
|
|
1356
|
+
* Insert empty rows or columns into a sheet. Cells at and after `startIndex`
|
|
1357
|
+
* move down (rows) or right (columns); Google adjusts formulas that refer to
|
|
1358
|
+
* them. The new rows/columns copy the formatting of the row/column before
|
|
1359
|
+
* them (default) or after them.
|
|
1360
|
+
*/
|
|
1361
|
+
async insertDimension(email, options) {
|
|
1362
|
+
try {
|
|
1363
|
+
const count = options.count ?? 1;
|
|
1364
|
+
if (!Number.isInteger(count) || count < 1 || count > MAX_INSERT_DIMENSION_COUNT) {
|
|
1365
|
+
throw new SheetsInputError(`count must be a whole number from 1 to ${MAX_INSERT_DIMENSION_COUNT}.`);
|
|
1366
|
+
}
|
|
1367
|
+
if (!Number.isInteger(options.startIndex) || options.startIndex < 0) {
|
|
1368
|
+
throw new SheetsInputError('start_index must be a whole number, 0 or more (0 = first row or column).');
|
|
1369
|
+
}
|
|
1370
|
+
const client = await this.getWriteClient(email);
|
|
1371
|
+
const sheets = await this.readSheetList(client, options.spreadsheetId);
|
|
1372
|
+
const sheet = findSheet(sheets, { sheetId: options.sheetId, sheetTitle: options.sheetTitle });
|
|
1373
|
+
const isRows = options.dimension === 'ROWS';
|
|
1374
|
+
const unit = isRows ? 'row' : 'column';
|
|
1375
|
+
const size = isRows ? sheet.rowCount : sheet.columnCount;
|
|
1376
|
+
if (size !== undefined && options.startIndex > size) {
|
|
1377
|
+
throw new SheetsInputError(`start_index ${options.startIndex} is past the end of the sheet, which has ${size} ${unit}s; use ${size} to add after the last ${unit}.`);
|
|
1378
|
+
}
|
|
1379
|
+
// There is nothing to copy formatting from before the first row/column,
|
|
1380
|
+
// or after the last one; the default picks the side that exists.
|
|
1381
|
+
const atStart = options.startIndex === 0;
|
|
1382
|
+
const atEnd = size !== undefined && options.startIndex === size;
|
|
1383
|
+
if (options.inheritFrom === 'before' && atStart) {
|
|
1384
|
+
throw new SheetsInputError(`inherit_from "before" needs start_index 1 or more: there is no ${unit} before ${unit} 0. Use inherit_from "after".`);
|
|
1385
|
+
}
|
|
1386
|
+
if (options.inheritFrom === 'after' && atEnd) {
|
|
1387
|
+
throw new SheetsInputError(`inherit_from "after" can't be used at the end of the sheet: there is no ${unit} after it. Use inherit_from "before".`);
|
|
1388
|
+
}
|
|
1389
|
+
const inheritFromBefore = options.inheritFrom !== undefined ? options.inheritFrom === 'before' : !atStart;
|
|
1390
|
+
const endIndex = options.startIndex + count;
|
|
1391
|
+
await client.spreadsheets.batchUpdate({
|
|
1392
|
+
spreadsheetId: options.spreadsheetId,
|
|
1393
|
+
requestBody: {
|
|
1394
|
+
requests: [
|
|
1395
|
+
{
|
|
1396
|
+
insertDimension: {
|
|
1397
|
+
range: {
|
|
1398
|
+
sheetId: sheet.sheetId,
|
|
1399
|
+
dimension: options.dimension,
|
|
1400
|
+
startIndex: options.startIndex,
|
|
1401
|
+
endIndex,
|
|
1402
|
+
},
|
|
1403
|
+
inheritFromBefore,
|
|
1404
|
+
},
|
|
1405
|
+
},
|
|
1406
|
+
],
|
|
1407
|
+
},
|
|
1408
|
+
});
|
|
1409
|
+
const a1Bounds = isRows
|
|
1410
|
+
? `${options.startIndex + 1}:${endIndex}`
|
|
1411
|
+
: `${this.columnIndexToLetter(options.startIndex + 1)}:${this.columnIndexToLetter(endIndex)}`;
|
|
1412
|
+
return {
|
|
1413
|
+
success: true,
|
|
1414
|
+
data: {
|
|
1415
|
+
spreadsheetId: options.spreadsheetId,
|
|
1416
|
+
sheet,
|
|
1417
|
+
dimension: options.dimension,
|
|
1418
|
+
startIndex: options.startIndex,
|
|
1419
|
+
count,
|
|
1420
|
+
inheritFromBefore,
|
|
1421
|
+
a1Range: `${quoteSheetTitle(sheet.title)}!${a1Bounds}`,
|
|
1422
|
+
},
|
|
1423
|
+
};
|
|
1424
|
+
}
|
|
1425
|
+
catch (error) {
|
|
1426
|
+
return toSheetTabFailure(error);
|
|
1427
|
+
}
|
|
1428
|
+
}
|
|
1429
|
+
async getWriteClient(email) {
|
|
1430
|
+
await this.ensureInitialized();
|
|
1431
|
+
this.checkInitialized();
|
|
1432
|
+
await this.validateScopes(email, [SHEETS_SCOPES.FULL]);
|
|
1433
|
+
return this.getAuthenticatedClient(email, (auth) => google.sheets({ version: 'v4', auth }));
|
|
1434
|
+
}
|
|
1435
|
+
/** Every sheet's properties, in tab order. */
|
|
1436
|
+
async readSheetList(client, spreadsheetId) {
|
|
1437
|
+
const response = await client.spreadsheets.get({
|
|
1438
|
+
spreadsheetId,
|
|
1439
|
+
fields: 'sheets.properties',
|
|
1440
|
+
});
|
|
1441
|
+
return (response.data.sheets ?? [])
|
|
1442
|
+
.map((sheet) => this.extractSheetInfo(sheet))
|
|
1443
|
+
.sort((a, b) => a.index - b.index);
|
|
1444
|
+
}
|
|
1233
1445
|
/**
|
|
1234
1446
|
* Batch read values from multiple ranges in a single API call
|
|
1235
1447
|
*/
|
|
@@ -1696,4 +1908,48 @@ export class SheetsService extends BaseGoogleService {
|
|
|
1696
1908
|
}
|
|
1697
1909
|
}
|
|
1698
1910
|
}
|
|
1911
|
+
/**
|
|
1912
|
+
* Shared catch for the sheet-management methods: auth handoffs and input
|
|
1913
|
+
* errors propagate; API failures become `{ success: false }` with the HTTP
|
|
1914
|
+
* status kept.
|
|
1915
|
+
*/
|
|
1916
|
+
function toSheetTabFailure(error) {
|
|
1917
|
+
// An expired/revoked grant must keep its reconnect signal.
|
|
1918
|
+
if (isAuthHandoffError(error))
|
|
1919
|
+
throw error;
|
|
1920
|
+
if (error instanceof SheetsInputError)
|
|
1921
|
+
throw error;
|
|
1922
|
+
return { success: false, error: describeApiErrorUntrusted(error, 'google-workspace:sheets:api-error') };
|
|
1923
|
+
}
|
|
1924
|
+
function requireSheetTitle(title) {
|
|
1925
|
+
const trimmed = title.trim();
|
|
1926
|
+
if (trimmed.length === 0) {
|
|
1927
|
+
throw new SheetsInputError('title must not be empty.');
|
|
1928
|
+
}
|
|
1929
|
+
return trimmed;
|
|
1930
|
+
}
|
|
1931
|
+
/** `max` is the largest allowed 0-based position. */
|
|
1932
|
+
function assertSheetPosition(position, max) {
|
|
1933
|
+
if (position === undefined)
|
|
1934
|
+
return;
|
|
1935
|
+
if (!Number.isInteger(position) || position < 0 || position > max) {
|
|
1936
|
+
throw new SheetsInputError(`position must be a whole number from 0 to ${max} (0 = first; list_workspace_spreadsheet_sheets numbers sheets from 1).`);
|
|
1937
|
+
}
|
|
1938
|
+
}
|
|
1939
|
+
/** Find a sheet by numeric id or by exact title. */
|
|
1940
|
+
function findSheet(sheets, ref) {
|
|
1941
|
+
if (ref.sheetId !== undefined) {
|
|
1942
|
+
const found = sheets.find((sheet) => sheet.sheetId === ref.sheetId);
|
|
1943
|
+
if (found)
|
|
1944
|
+
return found;
|
|
1945
|
+
throw new SheetsInputError(`No sheet with sheetId ${ref.sheetId} in this spreadsheet. Call list_workspace_spreadsheet_sheets to see each sheet's sheetId.`);
|
|
1946
|
+
}
|
|
1947
|
+
if (ref.sheetTitle !== undefined) {
|
|
1948
|
+
const found = sheets.find((sheet) => sheet.title === ref.sheetTitle);
|
|
1949
|
+
if (found)
|
|
1950
|
+
return found;
|
|
1951
|
+
throw new SheetsInputError(`No sheet titled "${ref.sheetTitle}" in this spreadsheet (titles must match exactly). Call list_workspace_spreadsheet_sheets to see the sheets.`);
|
|
1952
|
+
}
|
|
1953
|
+
throw new SheetsInputError('Pass sheet_id or sheet_title.');
|
|
1954
|
+
}
|
|
1699
1955
|
//# sourceMappingURL=service.js.map
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { sheets_v4 } from 'googleapis';
|
|
2
|
+
import { McpError } from '@modelcontextprotocol/sdk/types.js';
|
|
2
3
|
import type { FormulaCellRef, SuspiciousWriteWarning } from './writeGuards.js';
|
|
3
4
|
export type { FormulaCellRef, SuspiciousWriteWarning } from './writeGuards.js';
|
|
4
5
|
export type Spreadsheet = sheets_v4.Schema$Spreadsheet;
|
|
@@ -126,12 +127,82 @@ export interface SheetInfo {
|
|
|
126
127
|
rowCount?: number;
|
|
127
128
|
columnCount?: number;
|
|
128
129
|
}
|
|
130
|
+
/**
|
|
131
|
+
* Input error raised by the sheet-management methods (unknown sheet, position
|
|
132
|
+
* out of range, …). Service catches rethrow it so the caller sees InvalidParams
|
|
133
|
+
* instead of a generic API failure.
|
|
134
|
+
*/
|
|
135
|
+
export declare class SheetsInputError extends McpError {
|
|
136
|
+
constructor(message: string);
|
|
137
|
+
}
|
|
138
|
+
export interface DuplicateSheetOptions {
|
|
139
|
+
spreadsheetId: string;
|
|
140
|
+
/** Exactly one of sheetId / sheetTitle (the sheet to copy). */
|
|
141
|
+
sheetId?: number;
|
|
142
|
+
sheetTitle?: string;
|
|
143
|
+
/** Name for the copy; Google names it "Copy of …" when omitted. */
|
|
144
|
+
title?: string;
|
|
145
|
+
/** 0-based position for the copy; defaults to right after the source. */
|
|
146
|
+
position?: number;
|
|
147
|
+
}
|
|
148
|
+
export interface UpdateSheetOptions {
|
|
149
|
+
spreadsheetId: string;
|
|
150
|
+
/** Exactly one of sheetId / sheetTitle (the sheet's current title). */
|
|
151
|
+
sheetId?: number;
|
|
152
|
+
sheetTitle?: string;
|
|
153
|
+
title?: string;
|
|
154
|
+
/** 0-based final position among all sheets. */
|
|
155
|
+
position?: number;
|
|
156
|
+
}
|
|
157
|
+
export type SheetDimension = 'ROWS' | 'COLUMNS';
|
|
158
|
+
export interface InsertDimensionOptions {
|
|
159
|
+
spreadsheetId: string;
|
|
160
|
+
/** Exactly one of sheetId / sheetTitle. */
|
|
161
|
+
sheetId?: number;
|
|
162
|
+
sheetTitle?: string;
|
|
163
|
+
dimension: SheetDimension;
|
|
164
|
+
/** 0-based index the first new row/column gets. */
|
|
165
|
+
startIndex: number;
|
|
166
|
+
count?: number;
|
|
167
|
+
/** Copy formatting from the row/column before the insert (default) or after it. */
|
|
168
|
+
inheritFrom?: 'before' | 'after';
|
|
169
|
+
}
|
|
170
|
+
export interface SheetDuplicateResponse {
|
|
171
|
+
spreadsheetId: string;
|
|
172
|
+
sourceSheetId: number;
|
|
173
|
+
sheet: SheetInfo;
|
|
174
|
+
requestedPosition: number;
|
|
175
|
+
}
|
|
176
|
+
export interface SheetUpdateResponse {
|
|
177
|
+
spreadsheetId: string;
|
|
178
|
+
sheet: SheetInfo;
|
|
179
|
+
/** False when the sheet already had that title and position (no write was made). */
|
|
180
|
+
changed: boolean;
|
|
181
|
+
requestedPosition: number;
|
|
182
|
+
}
|
|
183
|
+
export interface DimensionInsertResponse {
|
|
184
|
+
spreadsheetId: string;
|
|
185
|
+
sheet: SheetInfo;
|
|
186
|
+
dimension: SheetDimension;
|
|
187
|
+
startIndex: number;
|
|
188
|
+
count: number;
|
|
189
|
+
inheritFromBefore: boolean;
|
|
190
|
+
/** The inserted rows/columns in A1 notation, e.g. `'Q2 Data'!F:F` or `Sheet1!6:7`. */
|
|
191
|
+
a1Range: string;
|
|
192
|
+
}
|
|
193
|
+
export interface SheetTabOperationResult<T> {
|
|
194
|
+
success: boolean;
|
|
195
|
+
data?: T;
|
|
196
|
+
error?: string;
|
|
197
|
+
}
|
|
129
198
|
export interface SpreadsheetResponse {
|
|
130
199
|
title: string;
|
|
131
200
|
spreadsheetId: string;
|
|
132
201
|
spreadsheetUrl: string;
|
|
133
202
|
sheets?: SheetInfo[];
|
|
134
203
|
values?: CellValue[][];
|
|
204
|
+
/** A1 range `values` came from, used to number rows in text output (not set in JSON results). */
|
|
205
|
+
valuesRange?: string;
|
|
135
206
|
truncated?: boolean;
|
|
136
207
|
shapedValues?: ShapedReadResponse;
|
|
137
208
|
anchorValues?: AnchorReadResponse;
|
|
@@ -1,2 +1,13 @@
|
|
|
1
|
-
|
|
1
|
+
import { McpError, ErrorCode } from '@modelcontextprotocol/sdk/types.js';
|
|
2
|
+
/**
|
|
3
|
+
* Input error raised by the sheet-management methods (unknown sheet, position
|
|
4
|
+
* out of range, …). Service catches rethrow it so the caller sees InvalidParams
|
|
5
|
+
* instead of a generic API failure.
|
|
6
|
+
*/
|
|
7
|
+
export class SheetsInputError extends McpError {
|
|
8
|
+
constructor(message) {
|
|
9
|
+
super(ErrorCode.InvalidParams, message);
|
|
10
|
+
this.name = 'SheetsInputError';
|
|
11
|
+
}
|
|
12
|
+
}
|
|
2
13
|
//# sourceMappingURL=types.js.map
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { parseA1Range,
|
|
1
|
+
import { parseA1Range, quoteSheetTitle } from './a1Utils.js';
|
|
2
2
|
function columnLetterToIndex(columnLetter) {
|
|
3
3
|
const normalized = columnLetter.trim().toUpperCase();
|
|
4
4
|
let index = 0;
|
|
@@ -49,7 +49,7 @@ function formatCellA1(sheetName, rowIndex, columnIndex) {
|
|
|
49
49
|
if (!sheetName) {
|
|
50
50
|
return cell;
|
|
51
51
|
}
|
|
52
|
-
return `${
|
|
52
|
+
return `${quoteSheetTitle(sheetName)}!${cell}`;
|
|
53
53
|
}
|
|
54
54
|
function toNumeric(value) {
|
|
55
55
|
if (typeof value === 'number' && Number.isFinite(value)) {
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
{
|
|
2
|
+
"add_workspace_document_tab": true,
|
|
2
3
|
"add_workspace_spreadsheet_sheet": true,
|
|
3
4
|
"append_to_workspace_document": true,
|
|
4
5
|
"append_to_workspace_spreadsheet": true,
|
|
@@ -12,6 +13,7 @@
|
|
|
12
13
|
"complete_task": true,
|
|
13
14
|
"compose_workspace_email": false,
|
|
14
15
|
"copy_drive_file": true,
|
|
16
|
+
"copy_workspace_document_tab": true,
|
|
15
17
|
"create_drive_folder": true,
|
|
16
18
|
"create_task": true,
|
|
17
19
|
"create_workspace_calendar_event": true,
|
|
@@ -28,6 +30,7 @@
|
|
|
28
30
|
"delete_workspace_attachment": true,
|
|
29
31
|
"delete_workspace_calendar_event": true,
|
|
30
32
|
"delete_workspace_comment": true,
|
|
33
|
+
"delete_workspace_document_tab": true,
|
|
31
34
|
"delete_workspace_draft": true,
|
|
32
35
|
"delete_workspace_label": true,
|
|
33
36
|
"delete_workspace_label_filter": true,
|
|
@@ -35,6 +38,7 @@
|
|
|
35
38
|
"download_drive_file": false,
|
|
36
39
|
"download_file_revision": false,
|
|
37
40
|
"download_workspace_attachment": false,
|
|
41
|
+
"duplicate_workspace_spreadsheet_sheet": true,
|
|
38
42
|
"extract_workspace_document_id": false,
|
|
39
43
|
"extract_workspace_presentation_id": false,
|
|
40
44
|
"extract_workspace_spreadsheet_id": false,
|
|
@@ -54,6 +58,8 @@
|
|
|
54
58
|
"get_workspace_label": false,
|
|
55
59
|
"get_workspace_slide": false,
|
|
56
60
|
"get_workspace_slide_thumbnail": false,
|
|
61
|
+
"insert_workspace_document_text": true,
|
|
62
|
+
"insert_workspace_spreadsheet_dimension": true,
|
|
57
63
|
"list_chat_messages": false,
|
|
58
64
|
"list_chat_spaces": false,
|
|
59
65
|
"list_drive_files": false,
|
|
@@ -108,9 +114,11 @@
|
|
|
108
114
|
"update_drive_permissions": true,
|
|
109
115
|
"update_task": true,
|
|
110
116
|
"update_workspace_contact": true,
|
|
117
|
+
"update_workspace_document_tab": true,
|
|
111
118
|
"update_workspace_draft": true,
|
|
112
119
|
"update_workspace_label": true,
|
|
113
120
|
"update_workspace_label_filter": true,
|
|
121
|
+
"update_workspace_spreadsheet_sheet": true,
|
|
114
122
|
"update_workspace_spreadsheet_values": true,
|
|
115
123
|
"update_workspace_vacation_responder": true,
|
|
116
124
|
"upload_drive_file": true,
|