@mcp-z/mcp-sheets 2.5.0 → 2.6.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 +1 -1
- package/dist/cjs/constants.d.cts +24 -0
- package/dist/cjs/constants.d.ts +24 -0
- package/dist/cjs/constants.js +56 -0
- package/dist/cjs/constants.js.map +1 -1
- package/dist/cjs/lib/create-store.d.cts +2 -1
- package/dist/cjs/lib/create-store.d.ts +2 -1
- package/dist/cjs/lib/create-store.js +82 -7
- package/dist/cjs/lib/create-store.js.map +1 -1
- package/dist/cjs/mcp/tools/cells-format.d.cts +3 -3
- package/dist/cjs/mcp/tools/cells-format.d.ts +3 -3
- package/dist/cjs/mcp/tools/cells-format.js +3 -2
- package/dist/cjs/mcp/tools/cells-format.js.map +1 -1
- package/dist/cjs/mcp/tools/columns-get.d.cts +2 -2
- package/dist/cjs/mcp/tools/columns-get.d.ts +2 -2
- package/dist/cjs/mcp/tools/columns-get.js +2 -1
- package/dist/cjs/mcp/tools/columns-get.js.map +1 -1
- package/dist/cjs/mcp/tools/columns-update.d.cts +1 -1
- package/dist/cjs/mcp/tools/columns-update.d.ts +1 -1
- package/dist/cjs/mcp/tools/columns-update.js +3 -2
- package/dist/cjs/mcp/tools/columns-update.js.map +1 -1
- package/dist/cjs/mcp/tools/csv-get-columns.js +1 -1
- package/dist/cjs/mcp/tools/lib/dimension-operations.js +1 -1
- package/dist/cjs/mcp/tools/rows-append.d.cts +1 -1
- package/dist/cjs/mcp/tools/rows-append.d.ts +1 -1
- package/dist/cjs/mcp/tools/rows-append.js +2 -1
- package/dist/cjs/mcp/tools/rows-append.js.map +1 -1
- package/dist/cjs/mcp/tools/rows-csv-append.d.cts +1 -1
- package/dist/cjs/mcp/tools/rows-csv-append.d.ts +1 -1
- package/dist/cjs/mcp/tools/rows-csv-append.js +3 -2
- package/dist/cjs/mcp/tools/rows-csv-append.js.map +1 -1
- package/dist/cjs/mcp/tools/rows-get.d.cts +2 -2
- package/dist/cjs/mcp/tools/rows-get.d.ts +2 -2
- package/dist/cjs/mcp/tools/rows-get.js +2 -1
- package/dist/cjs/mcp/tools/rows-get.js.map +1 -1
- package/dist/cjs/mcp/tools/values-batch-update.d.cts +1 -1
- package/dist/cjs/mcp/tools/values-batch-update.d.ts +1 -1
- package/dist/cjs/mcp/tools/values-batch-update.js +3 -2
- package/dist/cjs/mcp/tools/values-batch-update.js.map +1 -1
- package/dist/cjs/mcp/tools/values-csv-update.d.cts +1 -1
- package/dist/cjs/mcp/tools/values-csv-update.d.ts +1 -1
- package/dist/cjs/mcp/tools/values-csv-update.js +3 -2
- package/dist/cjs/mcp/tools/values-csv-update.js.map +1 -1
- package/dist/cjs/mcp/tools/values-search.d.cts +2 -2
- package/dist/cjs/mcp/tools/values-search.d.ts +2 -2
- package/dist/cjs/mcp/tools/values-search.js +2 -1
- package/dist/cjs/mcp/tools/values-search.js.map +1 -1
- package/dist/cjs/setup/http.js +1 -1
- package/dist/cjs/setup/runtime.d.cts +2 -2
- package/dist/cjs/setup/runtime.d.ts +2 -2
- package/dist/cjs/setup/runtime.js +6 -6
- package/dist/cjs/setup/runtime.js.map +1 -1
- package/dist/cjs/setup/stdio.js +1 -1
- package/dist/cjs/spreadsheet/data-operations.js +2 -18
- package/dist/cjs/spreadsheet/data-operations.js.map +1 -1
- package/dist/cjs/spreadsheet/markdown-runs.js +1 -1
- package/dist/cjs/spreadsheet/range-operations.d.cts +1 -5
- package/dist/cjs/spreadsheet/range-operations.d.ts +1 -5
- package/dist/cjs/spreadsheet/range-operations.js +1 -29
- package/dist/cjs/spreadsheet/range-operations.js.map +1 -1
- package/dist/cjs/spreadsheet/sheet-operations.js +25 -75
- package/dist/cjs/spreadsheet/sheet-operations.js.map +1 -1
- package/dist/esm/constants.d.ts +24 -0
- package/dist/esm/constants.js +41 -0
- package/dist/esm/constants.js.map +1 -1
- package/dist/esm/lib/create-store.d.ts +2 -1
- package/dist/esm/lib/create-store.js +22 -4
- package/dist/esm/lib/create-store.js.map +1 -1
- package/dist/esm/mcp/tools/cells-format.d.ts +3 -3
- package/dist/esm/mcp/tools/cells-format.js +3 -2
- package/dist/esm/mcp/tools/cells-format.js.map +1 -1
- package/dist/esm/mcp/tools/columns-get.d.ts +2 -2
- package/dist/esm/mcp/tools/columns-get.js +2 -1
- package/dist/esm/mcp/tools/columns-get.js.map +1 -1
- package/dist/esm/mcp/tools/columns-update.d.ts +1 -1
- package/dist/esm/mcp/tools/columns-update.js +3 -2
- package/dist/esm/mcp/tools/columns-update.js.map +1 -1
- package/dist/esm/mcp/tools/rows-append.d.ts +1 -1
- package/dist/esm/mcp/tools/rows-append.js +2 -1
- package/dist/esm/mcp/tools/rows-append.js.map +1 -1
- package/dist/esm/mcp/tools/rows-csv-append.d.ts +1 -1
- package/dist/esm/mcp/tools/rows-csv-append.js +2 -1
- package/dist/esm/mcp/tools/rows-csv-append.js.map +1 -1
- package/dist/esm/mcp/tools/rows-get.d.ts +2 -2
- package/dist/esm/mcp/tools/rows-get.js +2 -1
- package/dist/esm/mcp/tools/rows-get.js.map +1 -1
- package/dist/esm/mcp/tools/values-batch-update.d.ts +1 -1
- package/dist/esm/mcp/tools/values-batch-update.js +3 -2
- package/dist/esm/mcp/tools/values-batch-update.js.map +1 -1
- package/dist/esm/mcp/tools/values-csv-update.d.ts +1 -1
- package/dist/esm/mcp/tools/values-csv-update.js +3 -2
- package/dist/esm/mcp/tools/values-csv-update.js.map +1 -1
- package/dist/esm/mcp/tools/values-search.d.ts +2 -2
- package/dist/esm/mcp/tools/values-search.js +2 -1
- package/dist/esm/mcp/tools/values-search.js.map +1 -1
- package/dist/esm/setup/runtime.d.ts +2 -2
- package/dist/esm/setup/runtime.js +6 -6
- package/dist/esm/setup/runtime.js.map +1 -1
- package/dist/esm/spreadsheet/data-operations.js +7 -11
- package/dist/esm/spreadsheet/data-operations.js.map +1 -1
- package/dist/esm/spreadsheet/range-operations.d.ts +1 -5
- package/dist/esm/spreadsheet/range-operations.js +0 -27
- package/dist/esm/spreadsheet/range-operations.js.map +1 -1
- package/dist/esm/spreadsheet/sheet-operations.js +19 -36
- package/dist/esm/spreadsheet/sheet-operations.js.map +1 -1
- package/package.json +7 -7
package/README.md
CHANGED
|
@@ -250,7 +250,7 @@ npm install -g @mcp-z/mcp-sheets @keyv/redis
|
|
|
250
250
|
TOKEN_STORE_URI=redis://localhost:6379 mcp-sheets
|
|
251
251
|
```
|
|
252
252
|
|
|
253
|
-
A protocol whose adapter is missing fails at startup naming the package to install.
|
|
253
|
+
A protocol whose adapter is missing fails at startup naming the package to install. This release uses keyv 6, so adapters you install should be keyv 6 releases (`@keyv/redis` 6). Sign-ins saved by earlier versions are moved to the new format on first start.
|
|
254
254
|
|
|
255
255
|
## Documentation
|
|
256
256
|
|
package/dist/cjs/constants.d.cts
CHANGED
|
@@ -7,3 +7,27 @@
|
|
|
7
7
|
export declare const GOOGLE_SCOPE = "openid https://www.googleapis.com/auth/userinfo.profile https://www.googleapis.com/auth/userinfo.email https://www.googleapis.com/auth/spreadsheets https://www.googleapis.com/auth/drive";
|
|
8
8
|
export declare const PASTE_TYPES: readonly ["PASTE_NORMAL", "PASTE_VALUES", "PASTE_FORMAT", "PASTE_NO_BORDERS", "PASTE_FORMULA", "PASTE_DATA_VALIDATION", "PASTE_CONDITIONAL_FORMATTING"];
|
|
9
9
|
export declare const PASTE_ORIENTATIONS: readonly ["NORMAL", "TRANSPOSE"];
|
|
10
|
+
export declare const NATIVE_DATE_POINTER = "Dates: a date-looking string is not necessarily a native date. See values-batch-update for the native-date write, format and read-back steps.";
|
|
11
|
+
export declare const RENDER_DESCRIPTION = "How to render cell values. FORMATTED_VALUE (default): calculated with formatting. UNFORMATTED_VALUE: calculated without formatting; native dates come back as numeric serials (days since 1899-12-30), text dates as strings, so use it to confirm a date is numeric. FORMULA: show formula text instead of result.";
|
|
12
|
+
export declare const NATIVE_DATE_EXAMPLE_WRITE: {
|
|
13
|
+
readonly requests: readonly [{
|
|
14
|
+
readonly range: "B2";
|
|
15
|
+
readonly majorDimension: "ROWS";
|
|
16
|
+
readonly values: readonly [readonly [46334.5]];
|
|
17
|
+
}];
|
|
18
|
+
readonly valueInputOption: "RAW";
|
|
19
|
+
};
|
|
20
|
+
export declare const NATIVE_DATE_EXAMPLE_FORMAT: {
|
|
21
|
+
readonly requests: readonly [{
|
|
22
|
+
readonly range: "B2";
|
|
23
|
+
readonly numberFormat: {
|
|
24
|
+
readonly type: "DATE";
|
|
25
|
+
readonly pattern: "yyyy-mm-dd hh:mm";
|
|
26
|
+
};
|
|
27
|
+
}];
|
|
28
|
+
};
|
|
29
|
+
export declare const NATIVE_DATE_EXAMPLE_READ: {
|
|
30
|
+
readonly range: "B2";
|
|
31
|
+
readonly render: "UNFORMATTED_VALUE";
|
|
32
|
+
};
|
|
33
|
+
export declare const NATIVE_DATE_GUIDANCE: string;
|
package/dist/cjs/constants.d.ts
CHANGED
|
@@ -7,3 +7,27 @@
|
|
|
7
7
|
export declare const GOOGLE_SCOPE = "openid https://www.googleapis.com/auth/userinfo.profile https://www.googleapis.com/auth/userinfo.email https://www.googleapis.com/auth/spreadsheets https://www.googleapis.com/auth/drive";
|
|
8
8
|
export declare const PASTE_TYPES: readonly ["PASTE_NORMAL", "PASTE_VALUES", "PASTE_FORMAT", "PASTE_NO_BORDERS", "PASTE_FORMULA", "PASTE_DATA_VALIDATION", "PASTE_CONDITIONAL_FORMATTING"];
|
|
9
9
|
export declare const PASTE_ORIENTATIONS: readonly ["NORMAL", "TRANSPOSE"];
|
|
10
|
+
export declare const NATIVE_DATE_POINTER = "Dates: a date-looking string is not necessarily a native date. See values-batch-update for the native-date write, format and read-back steps.";
|
|
11
|
+
export declare const RENDER_DESCRIPTION = "How to render cell values. FORMATTED_VALUE (default): calculated with formatting. UNFORMATTED_VALUE: calculated without formatting; native dates come back as numeric serials (days since 1899-12-30), text dates as strings, so use it to confirm a date is numeric. FORMULA: show formula text instead of result.";
|
|
12
|
+
export declare const NATIVE_DATE_EXAMPLE_WRITE: {
|
|
13
|
+
readonly requests: readonly [{
|
|
14
|
+
readonly range: "B2";
|
|
15
|
+
readonly majorDimension: "ROWS";
|
|
16
|
+
readonly values: readonly [readonly [46334.5]];
|
|
17
|
+
}];
|
|
18
|
+
readonly valueInputOption: "RAW";
|
|
19
|
+
};
|
|
20
|
+
export declare const NATIVE_DATE_EXAMPLE_FORMAT: {
|
|
21
|
+
readonly requests: readonly [{
|
|
22
|
+
readonly range: "B2";
|
|
23
|
+
readonly numberFormat: {
|
|
24
|
+
readonly type: "DATE";
|
|
25
|
+
readonly pattern: "yyyy-mm-dd hh:mm";
|
|
26
|
+
};
|
|
27
|
+
}];
|
|
28
|
+
};
|
|
29
|
+
export declare const NATIVE_DATE_EXAMPLE_READ: {
|
|
30
|
+
readonly range: "B2";
|
|
31
|
+
readonly render: "UNFORMATTED_VALUE";
|
|
32
|
+
};
|
|
33
|
+
export declare const NATIVE_DATE_GUIDANCE: string;
|
package/dist/cjs/constants.js
CHANGED
|
@@ -18,11 +18,29 @@ _export(exports, {
|
|
|
18
18
|
get GOOGLE_SCOPE () {
|
|
19
19
|
return GOOGLE_SCOPE;
|
|
20
20
|
},
|
|
21
|
+
get NATIVE_DATE_EXAMPLE_FORMAT () {
|
|
22
|
+
return NATIVE_DATE_EXAMPLE_FORMAT;
|
|
23
|
+
},
|
|
24
|
+
get NATIVE_DATE_EXAMPLE_READ () {
|
|
25
|
+
return NATIVE_DATE_EXAMPLE_READ;
|
|
26
|
+
},
|
|
27
|
+
get NATIVE_DATE_EXAMPLE_WRITE () {
|
|
28
|
+
return NATIVE_DATE_EXAMPLE_WRITE;
|
|
29
|
+
},
|
|
30
|
+
get NATIVE_DATE_GUIDANCE () {
|
|
31
|
+
return NATIVE_DATE_GUIDANCE;
|
|
32
|
+
},
|
|
33
|
+
get NATIVE_DATE_POINTER () {
|
|
34
|
+
return NATIVE_DATE_POINTER;
|
|
35
|
+
},
|
|
21
36
|
get PASTE_ORIENTATIONS () {
|
|
22
37
|
return PASTE_ORIENTATIONS;
|
|
23
38
|
},
|
|
24
39
|
get PASTE_TYPES () {
|
|
25
40
|
return PASTE_TYPES;
|
|
41
|
+
},
|
|
42
|
+
get RENDER_DESCRIPTION () {
|
|
43
|
+
return RENDER_DESCRIPTION;
|
|
26
44
|
}
|
|
27
45
|
});
|
|
28
46
|
var GOOGLE_SCOPE = 'openid https://www.googleapis.com/auth/userinfo.profile https://www.googleapis.com/auth/userinfo.email https://www.googleapis.com/auth/spreadsheets https://www.googleapis.com/auth/drive';
|
|
@@ -39,4 +57,42 @@ var PASTE_ORIENTATIONS = [
|
|
|
39
57
|
'NORMAL',
|
|
40
58
|
'TRANSPOSE'
|
|
41
59
|
];
|
|
60
|
+
var NATIVE_DATE_POINTER = 'Dates: a date-looking string is not necessarily a native date. See values-batch-update for the native-date write, format and read-back steps.';
|
|
61
|
+
var RENDER_DESCRIPTION = 'How to render cell values. FORMATTED_VALUE (default): calculated with formatting. UNFORMATTED_VALUE: calculated without formatting; native dates come back as numeric serials (days since 1899-12-30), text dates as strings, so use it to confirm a date is numeric. FORMULA: show formula text instead of result.';
|
|
62
|
+
var NATIVE_DATE_EXAMPLE_WRITE = {
|
|
63
|
+
requests: [
|
|
64
|
+
{
|
|
65
|
+
range: 'B2',
|
|
66
|
+
majorDimension: 'ROWS',
|
|
67
|
+
values: [
|
|
68
|
+
[
|
|
69
|
+
46334.5
|
|
70
|
+
]
|
|
71
|
+
]
|
|
72
|
+
}
|
|
73
|
+
],
|
|
74
|
+
valueInputOption: 'RAW'
|
|
75
|
+
};
|
|
76
|
+
var NATIVE_DATE_EXAMPLE_FORMAT = {
|
|
77
|
+
requests: [
|
|
78
|
+
{
|
|
79
|
+
range: 'B2',
|
|
80
|
+
numberFormat: {
|
|
81
|
+
type: 'DATE',
|
|
82
|
+
pattern: 'yyyy-mm-dd hh:mm'
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
]
|
|
86
|
+
};
|
|
87
|
+
var NATIVE_DATE_EXAMPLE_READ = {
|
|
88
|
+
range: 'B2',
|
|
89
|
+
render: 'UNFORMATTED_VALUE'
|
|
90
|
+
};
|
|
91
|
+
var NATIVE_DATE_GUIDANCE = [
|
|
92
|
+
"NATIVE DATES: a native Sheets date/time is a serial number plus a date number format. The integer counts days from 1899-12-30; the fraction is the time of day (46334.5 = 2026-11-08 12:00, with a matching format). A serial carries no timezone of its own and is read in the spreadsheet's timezone.",
|
|
93
|
+
'RAW stores values as supplied, so a date-looking string stays text; a numeric serial plus a date format is an explicit native-date write. USER_ENTERED may parse date strings the way the Sheets UI does, using the workbook locale.',
|
|
94
|
+
'Keep the intended wall time/timezone and recorded precision: a date-only record is not an exact midnight event time, and existing timestamps are not reinterpreted.',
|
|
95
|
+
"Example: (1) values-batch-update ".concat(JSON.stringify(NATIVE_DATE_EXAMPLE_WRITE), "; (2) cells-format ").concat(JSON.stringify(NATIVE_DATE_EXAMPLE_FORMAT), "; (3) rows-get (or columns-get / values-search) ").concat(JSON.stringify(NATIVE_DATE_EXAMPLE_READ), ' returns 46334.5 (numeric, so it is not text), while render FORMATTED_VALUE returns "2026-11-08 12:00"; then check dependent chronological formulas.'),
|
|
96
|
+
'Docs: https://developers.google.com/workspace/sheets/api/reference/rest/v4/DateTimeRenderOption and https://developers.google.com/workspace/sheets/api/reference/rest/v4/ValueInputOption'
|
|
97
|
+
].join(' ');
|
|
42
98
|
/* CJS INTEROP */ if (exports.__esModule && exports.default) { try { Object.defineProperty(exports.default, '__esModule', { value: true }); for (var key in exports) { exports.default[key] = exports[key]; } } catch (_) {}; module.exports = exports.default; }
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["/Users/kevin/Dev/open-source/ai/mcp-z/mcp-sheets/src/constants.ts"],"sourcesContent":["/**\n * Sheets MCP Server Constants\n *\n * These scopes are required for Google Sheets and Drive functionality and are hardcoded\n * rather than externally configured since this server knows its own requirements.\n */\n\n// Google OAuth scopes required for Sheets and Drive operations\nexport const GOOGLE_SCOPE = 'openid https://www.googleapis.com/auth/userinfo.profile https://www.googleapis.com/auth/userinfo.email https://www.googleapis.com/auth/spreadsheets https://www.googleapis.com/auth/drive';\n\n// Native paste-special modes of the Sheets API CopyPasteRequest (PasteType / PasteOrientation)\nexport const PASTE_TYPES = ['PASTE_NORMAL', 'PASTE_VALUES', 'PASTE_FORMAT', 'PASTE_NO_BORDERS', 'PASTE_FORMULA', 'PASTE_DATA_VALIDATION', 'PASTE_CONDITIONAL_FORMATTING'] as const;\nexport const PASTE_ORIENTATIONS = ['NORMAL', 'TRANSPOSE'] as const;\n"],"names":["GOOGLE_SCOPE","PASTE_ORIENTATIONS","PASTE_TYPES"],"mappings":"AAAA;;;;;CAKC,GAED,+DAA+D;;;;;;;;;;;;QAClDA;eAAAA;;QAIAC;eAAAA;;QADAC;eAAAA;;;
|
|
1
|
+
{"version":3,"sources":["/Users/kevin/Dev/open-source/ai/mcp-z/mcp-sheets/src/constants.ts"],"sourcesContent":["/**\n * Sheets MCP Server Constants\n *\n * These scopes are required for Google Sheets and Drive functionality and are hardcoded\n * rather than externally configured since this server knows its own requirements.\n */\n\n// Google OAuth scopes required for Sheets and Drive operations\nexport const GOOGLE_SCOPE = 'openid https://www.googleapis.com/auth/userinfo.profile https://www.googleapis.com/auth/userinfo.email https://www.googleapis.com/auth/spreadsheets https://www.googleapis.com/auth/drive';\n\n// Native paste-special modes of the Sheets API CopyPasteRequest (PasteType / PasteOrientation)\nexport const PASTE_TYPES = ['PASTE_NORMAL', 'PASTE_VALUES', 'PASTE_FORMAT', 'PASTE_NO_BORDERS', 'PASTE_FORMULA', 'PASTE_DATA_VALIDATION', 'PASTE_CONDITIONAL_FORMATTING'] as const;\nexport const PASTE_ORIENTATIONS = ['NORMAL', 'TRANSPOSE'] as const;\n\n// Native-date guidance shared by the write, format and read tool descriptions; the example arguments are checked against the tool schemas in test/unit/constants.test.ts.\n// Docs: https://developers.google.com/workspace/sheets/api/reference/rest/v4/DateTimeRenderOption and .../ValueInputOption\nexport const NATIVE_DATE_POINTER = 'Dates: a date-looking string is not necessarily a native date. See values-batch-update for the native-date write, format and read-back steps.';\n\nexport const RENDER_DESCRIPTION =\n 'How to render cell values. FORMATTED_VALUE (default): calculated with formatting. UNFORMATTED_VALUE: calculated without formatting; native dates come back as numeric serials (days since 1899-12-30), text dates as strings, so use it to confirm a date is numeric. FORMULA: show formula text instead of result.';\n\n// Example call arguments (id/gid/includeData omitted), step 1 to 3 of the native-date write, format and read-back.\nexport const NATIVE_DATE_EXAMPLE_WRITE = { requests: [{ range: 'B2', majorDimension: 'ROWS', values: [[46334.5]] }], valueInputOption: 'RAW' } as const;\nexport const NATIVE_DATE_EXAMPLE_FORMAT = { requests: [{ range: 'B2', numberFormat: { type: 'DATE', pattern: 'yyyy-mm-dd hh:mm' } }] } as const;\nexport const NATIVE_DATE_EXAMPLE_READ = { range: 'B2', render: 'UNFORMATTED_VALUE' } as const;\n\nexport const NATIVE_DATE_GUIDANCE = [\n \"NATIVE DATES: a native Sheets date/time is a serial number plus a date number format. The integer counts days from 1899-12-30; the fraction is the time of day (46334.5 = 2026-11-08 12:00, with a matching format). A serial carries no timezone of its own and is read in the spreadsheet's timezone.\",\n 'RAW stores values as supplied, so a date-looking string stays text; a numeric serial plus a date format is an explicit native-date write. USER_ENTERED may parse date strings the way the Sheets UI does, using the workbook locale.',\n 'Keep the intended wall time/timezone and recorded precision: a date-only record is not an exact midnight event time, and existing timestamps are not reinterpreted.',\n `Example: (1) values-batch-update ${JSON.stringify(NATIVE_DATE_EXAMPLE_WRITE)}; (2) cells-format ${JSON.stringify(NATIVE_DATE_EXAMPLE_FORMAT)}; (3) rows-get (or columns-get / values-search) ${JSON.stringify(NATIVE_DATE_EXAMPLE_READ)} returns 46334.5 (numeric, so it is not text), while render FORMATTED_VALUE returns \"2026-11-08 12:00\"; then check dependent chronological formulas.`,\n 'Docs: https://developers.google.com/workspace/sheets/api/reference/rest/v4/DateTimeRenderOption and https://developers.google.com/workspace/sheets/api/reference/rest/v4/ValueInputOption',\n].join(' ');\n"],"names":["GOOGLE_SCOPE","NATIVE_DATE_EXAMPLE_FORMAT","NATIVE_DATE_EXAMPLE_READ","NATIVE_DATE_EXAMPLE_WRITE","NATIVE_DATE_GUIDANCE","NATIVE_DATE_POINTER","PASTE_ORIENTATIONS","PASTE_TYPES","RENDER_DESCRIPTION","requests","range","majorDimension","values","valueInputOption","numberFormat","type","pattern","render","JSON","stringify","join"],"mappings":"AAAA;;;;;CAKC,GAED,+DAA+D;;;;;;;;;;;;QAClDA;eAAAA;;QAeAC;eAAAA;;QACAC;eAAAA;;QAFAC;eAAAA;;QAIAC;eAAAA;;QAVAC;eAAAA;;QAJAC;eAAAA;;QADAC;eAAAA;;QAOAC;eAAAA;;;AAVN,IAAMR,eAAe;AAGrB,IAAMO,cAAc;IAAC;IAAgB;IAAgB;IAAgB;IAAoB;IAAiB;IAAyB;CAA+B;AAClK,IAAMD,qBAAqB;IAAC;IAAU;CAAY;AAIlD,IAAMD,sBAAsB;AAE5B,IAAMG,qBACX;AAGK,IAAML,4BAA4B;IAAEM,UAAU;QAAC;YAAEC,OAAO;YAAMC,gBAAgB;YAAQC,QAAQ;gBAAC;oBAAC;iBAAQ;aAAC;QAAC;KAAE;IAAEC,kBAAkB;AAAM;AACtI,IAAMZ,6BAA6B;IAAEQ,UAAU;QAAC;YAAEC,OAAO;YAAMI,cAAc;gBAAEC,MAAM;gBAAQC,SAAS;YAAmB;QAAE;KAAE;AAAC;AAC9H,IAAMd,2BAA2B;IAAEQ,OAAO;IAAMO,QAAQ;AAAoB;AAE5E,IAAMb,uBAAuB;IAClC;IACA;IACA;IACC,oCAAkGc,OAA/DA,KAAKC,SAAS,CAAChB,4BAA2B,uBAAkHe,OAA7FA,KAAKC,SAAS,CAAClB,6BAA4B,oDAA2F,OAAzCiB,KAAKC,SAAS,CAACjB,2BAA0B;IACzO;CACD,CAACkB,IAAI,CAAC"}
|
|
@@ -10,7 +10,7 @@ Object.defineProperty(exports, // keyv-file is a direct dependency so the defaul
|
|
|
10
10
|
return createStore;
|
|
11
11
|
}
|
|
12
12
|
});
|
|
13
|
-
var _keyvregistry = /*#__PURE__*/
|
|
13
|
+
var _keyvregistry = /*#__PURE__*/ _interop_require_wildcard(require("keyv-registry"));
|
|
14
14
|
function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) {
|
|
15
15
|
try {
|
|
16
16
|
var info = gen[key](arg);
|
|
@@ -37,10 +37,35 @@ function _async_to_generator(fn) {
|
|
|
37
37
|
});
|
|
38
38
|
};
|
|
39
39
|
}
|
|
40
|
-
function
|
|
41
|
-
|
|
40
|
+
function _getRequireWildcardCache(nodeInterop) {
|
|
41
|
+
if (typeof WeakMap !== "function") return null;
|
|
42
|
+
var cacheBabelInterop = new WeakMap();
|
|
43
|
+
var cacheNodeInterop = new WeakMap();
|
|
44
|
+
return (_getRequireWildcardCache = function(nodeInterop) {
|
|
45
|
+
return nodeInterop ? cacheNodeInterop : cacheBabelInterop;
|
|
46
|
+
})(nodeInterop);
|
|
47
|
+
}
|
|
48
|
+
function _interop_require_wildcard(obj, nodeInterop) {
|
|
49
|
+
if (!nodeInterop && obj && obj.__esModule) return obj;
|
|
50
|
+
if (obj === null || typeof obj !== "object" && typeof obj !== "function") return {
|
|
42
51
|
default: obj
|
|
43
52
|
};
|
|
53
|
+
var cache = _getRequireWildcardCache(nodeInterop);
|
|
54
|
+
if (cache && cache.has(obj)) return cache.get(obj);
|
|
55
|
+
var newObj = {
|
|
56
|
+
__proto__: null
|
|
57
|
+
};
|
|
58
|
+
var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor;
|
|
59
|
+
for(var key in obj){
|
|
60
|
+
if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) {
|
|
61
|
+
var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null;
|
|
62
|
+
if (desc && (desc.get || desc.set)) Object.defineProperty(newObj, key, desc);
|
|
63
|
+
else newObj[key] = obj[key];
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
newObj.default = obj;
|
|
67
|
+
if (cache) cache.set(obj, newObj);
|
|
68
|
+
return newObj;
|
|
44
69
|
}
|
|
45
70
|
function _ts_generator(thisArg, body) {
|
|
46
71
|
var f, y, t, _ = {
|
|
@@ -141,19 +166,69 @@ function _ts_generator(thisArg, body) {
|
|
|
141
166
|
};
|
|
142
167
|
}
|
|
143
168
|
}
|
|
144
|
-
function createStore(uri) {
|
|
169
|
+
function createStore(uri, logger) {
|
|
145
170
|
return _async_to_generator(function() {
|
|
146
|
-
var store;
|
|
171
|
+
var protocol, store, cause, _$error, moved, error;
|
|
147
172
|
return _ts_generator(this, function(_state) {
|
|
148
173
|
switch(_state.label){
|
|
149
174
|
case 0:
|
|
175
|
+
// Errors name the protocol only: a redis URI can hold a password.
|
|
176
|
+
protocol = "".concat(uri.split(':')[0], ":");
|
|
177
|
+
_state.label = 1;
|
|
178
|
+
case 1:
|
|
179
|
+
_state.trys.push([
|
|
180
|
+
1,
|
|
181
|
+
3,
|
|
182
|
+
,
|
|
183
|
+
4
|
|
184
|
+
]);
|
|
150
185
|
return [
|
|
151
186
|
4,
|
|
152
187
|
(0, _keyvregistry.default)(uri)
|
|
153
188
|
];
|
|
154
|
-
case
|
|
189
|
+
case 2:
|
|
155
190
|
store = _state.sent();
|
|
156
|
-
|
|
191
|
+
return [
|
|
192
|
+
3,
|
|
193
|
+
4
|
|
194
|
+
];
|
|
195
|
+
case 3:
|
|
196
|
+
cause = _state.sent();
|
|
197
|
+
_$error = new Error("Failed to create store for ".concat(protocol));
|
|
198
|
+
_$error.cause = cause;
|
|
199
|
+
throw _$error;
|
|
200
|
+
case 4:
|
|
201
|
+
if (!store) throw new Error("Failed to create store for ".concat(protocol));
|
|
202
|
+
_state.label = 5;
|
|
203
|
+
case 5:
|
|
204
|
+
_state.trys.push([
|
|
205
|
+
5,
|
|
206
|
+
7,
|
|
207
|
+
,
|
|
208
|
+
9
|
|
209
|
+
]);
|
|
210
|
+
return [
|
|
211
|
+
4,
|
|
212
|
+
(0, _keyvregistry.migrateKeyv5Keys)(store)
|
|
213
|
+
];
|
|
214
|
+
case 6:
|
|
215
|
+
moved = _state.sent();
|
|
216
|
+
if (moved > 0) logger === null || logger === void 0 ? void 0 : logger.info("Moved ".concat(moved, " saved sign-in entries to the keyv 6 format"));
|
|
217
|
+
return [
|
|
218
|
+
3,
|
|
219
|
+
9
|
|
220
|
+
];
|
|
221
|
+
case 7:
|
|
222
|
+
error = _state.sent();
|
|
223
|
+
// Keep the migration error as the one reported, even if closing the store fails too.
|
|
224
|
+
return [
|
|
225
|
+
4,
|
|
226
|
+
store.disconnect().catch(function() {})
|
|
227
|
+
];
|
|
228
|
+
case 8:
|
|
229
|
+
_state.sent();
|
|
230
|
+
throw error;
|
|
231
|
+
case 9:
|
|
157
232
|
return [
|
|
158
233
|
2,
|
|
159
234
|
store
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["/Users/kevin/Dev/open-source/ai/mcp-z/mcp-sheets/src/lib/create-store.ts"],"sourcesContent":["import type Keyv from 'keyv';\nimport keyvRegistry from 'keyv-registry';\n\n// keyv-file is a direct dependency so the default file:// URIs resolve; keyv-registry\n// loads adapters with require() rather than depending on any of them itself.\n\nexport default async function createStore<T>(uri: string): Promise<Keyv<T>> {\n const store = await keyvRegistry<T>(uri);\n if (!store) throw new Error(`Failed to create store for
|
|
1
|
+
{"version":3,"sources":["/Users/kevin/Dev/open-source/ai/mcp-z/mcp-sheets/src/lib/create-store.ts"],"sourcesContent":["import type { Logger } from '@mcp-z/server';\nimport type Keyv from 'keyv';\nimport keyvRegistry, { migrateKeyv5Keys } from 'keyv-registry';\n\n// keyv-file is a direct dependency so the default file:// URIs resolve; keyv-registry\n// loads adapters with require() rather than depending on any of them itself.\n\nexport default async function createStore<T>(uri: string, logger?: Logger): Promise<Keyv<T>> {\n // Errors name the protocol only: a redis URI can hold a password.\n const protocol = `${uri.split(':')[0]}:`;\n let store: Keyv<T> | undefined;\n try {\n store = await keyvRegistry<T>(uri);\n } catch (cause) {\n const error = new Error(`Failed to create store for ${protocol}`);\n (error as Error & { cause?: unknown }).cause = cause;\n throw error;\n }\n if (!store) throw new Error(`Failed to create store for ${protocol}`);\n try {\n // One-time move of sign-ins saved by keyv 5 versions of this server. Removed in the next major.\n const moved = await migrateKeyv5Keys(store as Keyv);\n if (moved > 0) logger?.info(`Moved ${moved} saved sign-in entries to the keyv 6 format`);\n } catch (error) {\n // Keep the migration error as the one reported, even if closing the store fails too.\n await store.disconnect().catch(() => {});\n throw error;\n }\n return store;\n}\n"],"names":["createStore","uri","logger","protocol","store","cause","error","moved","split","keyvRegistry","Error","migrateKeyv5Keys","info","disconnect","catch"],"mappings":";;;;+BAIA,sFAAsF;AACtF,6EAA6E;AAE7E;;;eAA8BA;;;oEALiB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAKhC,SAAeA,YAAeC,GAAW,EAAEC,MAAe;;YAEjEC,UACFC,OAGKC,OACDC,SAOAC,OAECD;;;;oBAfT,kEAAkE;oBAC5DH,WAAW,AAAC,GAAoB,OAAlBF,IAAIO,KAAK,CAAC,IAAI,CAAC,EAAE,EAAC;;;;;;;;;oBAG5B;;wBAAMC,IAAAA,qBAAY,EAAIR;;;oBAA9BG,QAAQ;;;;;;oBACDC;oBACDC,UAAQ,IAAII,MAAM,AAAC,8BAAsC,OAATP;oBACrDG,QAAsCD,KAAK,GAAGA;oBAC/C,MAAMC;;oBAER,IAAI,CAACF,OAAO,MAAM,IAAIM,MAAM,AAAC,8BAAsC,OAATP;;;;;;;;;oBAG1C;;wBAAMQ,IAAAA,8BAAgB,EAACP;;;oBAA/BG,QAAQ;oBACd,IAAIA,QAAQ,GAAGL,mBAAAA,6BAAAA,OAAQU,IAAI,CAAC,AAAC,SAAc,OAANL,OAAM;;;;;;oBACpCD;oBACP,qFAAqF;oBACrF;;wBAAMF,MAAMS,UAAU,GAAGC,KAAK,CAAC,YAAO;;;oBAAtC;oBACA,MAAMR;;oBAER;;wBAAOF;;;;IACT"}
|
|
@@ -25,11 +25,11 @@ declare const inputSchema: z.ZodObject<{
|
|
|
25
25
|
}>>;
|
|
26
26
|
numberFormat: z.ZodOptional<z.ZodObject<{
|
|
27
27
|
type: z.ZodEnum<{
|
|
28
|
+
DATE: "DATE";
|
|
28
29
|
TEXT: "TEXT";
|
|
29
30
|
NUMBER: "NUMBER";
|
|
30
31
|
PERCENT: "PERCENT";
|
|
31
32
|
CURRENCY: "CURRENCY";
|
|
32
|
-
DATE: "DATE";
|
|
33
33
|
TIME: "TIME";
|
|
34
34
|
}>;
|
|
35
35
|
pattern: z.ZodOptional<z.ZodString>;
|
|
@@ -71,7 +71,7 @@ declare function handler({ id, gid, requests }: Input, extra: EnrichedExtra): Pr
|
|
|
71
71
|
export default function createTool(): {
|
|
72
72
|
name: string;
|
|
73
73
|
config: {
|
|
74
|
-
readonly description: "Apply formatting (colors, borders, fonts, alignment, number formats) to cell ranges without modifying data. Supports batch operations for efficiency. Colors use 0-1 RGB format. Best for creating professional, visually organized spreadsheets.";
|
|
74
|
+
readonly description: "Apply formatting (colors, borders, fonts, alignment, number formats) to cell ranges without modifying data. Supports batch operations for efficiency. Colors use 0-1 RGB format. Best for creating professional, visually organized spreadsheets. Date/time cells: numberFormat {type:\"DATE\", pattern:\"yyyy-mm-dd hh:mm\"} only displays a numeric serial as a date; it does not convert text. Dates: a date-looking string is not necessarily a native date. See values-batch-update for the native-date write, format and read-back steps.";
|
|
75
75
|
readonly inputSchema: z.ZodObject<{
|
|
76
76
|
id: z.ZodString;
|
|
77
77
|
gid: z.ZodCoercedString<unknown>;
|
|
@@ -96,11 +96,11 @@ export default function createTool(): {
|
|
|
96
96
|
}>>;
|
|
97
97
|
numberFormat: z.ZodOptional<z.ZodObject<{
|
|
98
98
|
type: z.ZodEnum<{
|
|
99
|
+
DATE: "DATE";
|
|
99
100
|
TEXT: "TEXT";
|
|
100
101
|
NUMBER: "NUMBER";
|
|
101
102
|
PERCENT: "PERCENT";
|
|
102
103
|
CURRENCY: "CURRENCY";
|
|
103
|
-
DATE: "DATE";
|
|
104
104
|
TIME: "TIME";
|
|
105
105
|
}>;
|
|
106
106
|
pattern: z.ZodOptional<z.ZodString>;
|
|
@@ -25,11 +25,11 @@ declare const inputSchema: z.ZodObject<{
|
|
|
25
25
|
}>>;
|
|
26
26
|
numberFormat: z.ZodOptional<z.ZodObject<{
|
|
27
27
|
type: z.ZodEnum<{
|
|
28
|
+
DATE: "DATE";
|
|
28
29
|
TEXT: "TEXT";
|
|
29
30
|
NUMBER: "NUMBER";
|
|
30
31
|
PERCENT: "PERCENT";
|
|
31
32
|
CURRENCY: "CURRENCY";
|
|
32
|
-
DATE: "DATE";
|
|
33
33
|
TIME: "TIME";
|
|
34
34
|
}>;
|
|
35
35
|
pattern: z.ZodOptional<z.ZodString>;
|
|
@@ -71,7 +71,7 @@ declare function handler({ id, gid, requests }: Input, extra: EnrichedExtra): Pr
|
|
|
71
71
|
export default function createTool(): {
|
|
72
72
|
name: string;
|
|
73
73
|
config: {
|
|
74
|
-
readonly description: "Apply formatting (colors, borders, fonts, alignment, number formats) to cell ranges without modifying data. Supports batch operations for efficiency. Colors use 0-1 RGB format. Best for creating professional, visually organized spreadsheets.";
|
|
74
|
+
readonly description: "Apply formatting (colors, borders, fonts, alignment, number formats) to cell ranges without modifying data. Supports batch operations for efficiency. Colors use 0-1 RGB format. Best for creating professional, visually organized spreadsheets. Date/time cells: numberFormat {type:\"DATE\", pattern:\"yyyy-mm-dd hh:mm\"} only displays a numeric serial as a date; it does not convert text. Dates: a date-looking string is not necessarily a native date. See values-batch-update for the native-date write, format and read-back steps.";
|
|
75
75
|
readonly inputSchema: z.ZodObject<{
|
|
76
76
|
id: z.ZodString;
|
|
77
77
|
gid: z.ZodCoercedString<unknown>;
|
|
@@ -96,11 +96,11 @@ export default function createTool(): {
|
|
|
96
96
|
}>>;
|
|
97
97
|
numberFormat: z.ZodOptional<z.ZodObject<{
|
|
98
98
|
type: z.ZodEnum<{
|
|
99
|
+
DATE: "DATE";
|
|
99
100
|
TEXT: "TEXT";
|
|
100
101
|
NUMBER: "NUMBER";
|
|
101
102
|
PERCENT: "PERCENT";
|
|
102
103
|
CURRENCY: "CURRENCY";
|
|
103
|
-
DATE: "DATE";
|
|
104
104
|
TIME: "TIME";
|
|
105
105
|
}>;
|
|
106
106
|
pattern: z.ZodOptional<z.ZodString>;
|
|
@@ -12,6 +12,7 @@ var _sheets = require("@googleapis/sheets");
|
|
|
12
12
|
var _oauthgoogle = require("@mcp-z/oauth-google");
|
|
13
13
|
var _server = require("@mcp-z/server");
|
|
14
14
|
var _zod = require("zod");
|
|
15
|
+
var _constantsts = require("../../constants.js");
|
|
15
16
|
var _googleauthts = require("../../lib/google-auth.js");
|
|
16
17
|
var _indexts = require("../../schemas/index.js");
|
|
17
18
|
var _rangeoperationsts = require("../../spreadsheet/range-operations.js");
|
|
@@ -163,7 +164,7 @@ var NumberFormatSchema = _zod.z.object({
|
|
|
163
164
|
'DATE',
|
|
164
165
|
'TIME'
|
|
165
166
|
]).describe('Number format type'),
|
|
166
|
-
pattern: _zod.z.string().optional().describe('Custom format pattern (e.g., "$#,##0.00" for currency)')
|
|
167
|
+
pattern: _zod.z.string().optional().describe('Custom format pattern (e.g., "$#,##0.00" for currency, "yyyy-mm-dd hh:mm" for a date/time serial)')
|
|
167
168
|
});
|
|
168
169
|
// Border schema
|
|
169
170
|
var BorderSchema = _zod.z.object({
|
|
@@ -211,7 +212,7 @@ var outputSchema = _zod.z.discriminatedUnion('type', [
|
|
|
211
212
|
AuthRequiredBranchSchema
|
|
212
213
|
]);
|
|
213
214
|
var config = {
|
|
214
|
-
description: 'Apply formatting (colors, borders, fonts, alignment, number formats) to cell ranges without modifying data. Supports batch operations for efficiency. Colors use 0-1 RGB format. Best for creating professional, visually organized spreadsheets.',
|
|
215
|
+
description: 'Apply formatting (colors, borders, fonts, alignment, number formats) to cell ranges without modifying data. Supports batch operations for efficiency. Colors use 0-1 RGB format. Best for creating professional, visually organized spreadsheets. Date/time cells: numberFormat {type:"DATE", pattern:"yyyy-mm-dd hh:mm"} only displays a numeric serial as a date; it does not convert text. '.concat(_constantsts.NATIVE_DATE_POINTER),
|
|
215
216
|
inputSchema: inputSchema,
|
|
216
217
|
outputSchema: _zod.z.object({
|
|
217
218
|
result: outputSchema
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["/Users/kevin/Dev/open-source/ai/mcp-z/mcp-sheets/src/mcp/tools/cells-format.ts"],"sourcesContent":["import { type sheets_v4, sheets as sheetsApi } from '@googleapis/sheets';\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 { z } from 'zod';\nimport { googleAuth } from '../../lib/google-auth.ts';\nimport { SheetGidOutput, SheetGidSchema, SpreadsheetIdOutput, SpreadsheetIdSchema } from '../../schemas/index.ts';\nimport { parseA1Notation, rangeReferenceToGridRange } from '../../spreadsheet/range-operations.ts';\n\n// RGB color schema (0-1 range for Google Sheets API)\nconst ColorSchema = z.object({\n red: z.number().min(0).max(1).describe('Red component (0-1)'),\n green: z.number().min(0).max(1).describe('Green component (0-1)'),\n blue: z.number().min(0).max(1).describe('Blue component (0-1)'),\n});\n\n// Number format schema\nconst NumberFormatSchema = z.object({\n type: z.enum(['TEXT', 'NUMBER', 'PERCENT', 'CURRENCY', 'DATE', 'TIME']).describe('Number format type'),\n pattern: z.string().optional().describe('Custom format pattern (e.g., \"$#,##0.00\" for currency)'),\n});\n\n// Border schema\nconst BorderSchema = z.object({\n style: z.enum(['SOLID', 'DASHED', 'DOTTED']).describe('Border line style'),\n color: ColorSchema.describe('Border color'),\n});\n\n// Input schema for format requests\nconst FormatRequestSchema = z.object({\n range: z.string().min(1).describe('A1 notation range to format (e.g., \"A1:D10\", \"B:B\", \"5:5\")'),\n backgroundColor: ColorSchema.optional().describe('Cell background color'),\n textColor: ColorSchema.optional().describe('Text color'),\n bold: z.boolean().optional().describe('Bold text'),\n fontSize: z.number().int().min(6).max(36).optional().describe('Font size in points'),\n horizontalAlignment: z.enum(['LEFT', 'CENTER', 'RIGHT']).optional().describe('Horizontal text alignment'),\n numberFormat: NumberFormatSchema.optional().describe('Number format pattern'),\n borders: BorderSchema.optional().describe('Cell borders'),\n});\n\nconst inputSchema = z.object({\n id: SpreadsheetIdSchema,\n gid: SheetGidSchema,\n requests: z.array(FormatRequestSchema).min(1).max(50).describe('Array of formatting requests. Batch multiple ranges for efficiency.'),\n});\n\nconst successBranchSchema = z.object({\n type: z.literal('success'),\n id: SpreadsheetIdOutput,\n gid: SheetGidOutput,\n sheetTitle: z.string().describe('Title of the formatted sheet'),\n sheetUrl: z.string().describe('URL of the formatted sheet'),\n successCount: z.number().int().nonnegative().describe('Number of format requests successfully applied'),\n failedRanges: z\n .array(\n z.object({\n range: z.string().describe('A1 notation of range that failed'),\n error: z.string().describe('Why formatting failed for this range'),\n })\n )\n .optional()\n .describe('Only populated if some ranges failed to format'),\n});\n\nconst outputSchema = z.discriminatedUnion('type', [successBranchSchema, AuthRequiredBranchSchema]);\n\nconst config = {\n description: 'Apply formatting (colors, borders, fonts, alignment, number formats) to cell ranges without modifying data. Supports batch operations for efficiency. Colors use 0-1 RGB format. Best for creating professional, visually organized spreadsheets.',\n inputSchema,\n outputSchema: z.object({\n result: outputSchema,\n }),\n} as const;\n\nexport type Input = z.infer<typeof inputSchema>;\nexport type Output = z.infer<typeof outputSchema>;\n\nasync function handler({ id, gid, requests }: Input, extra: EnrichedExtra): Promise<CallToolResult> {\n const logger = extra.logger;\n logger.info('sheets.cells.format called', {\n id,\n gid,\n requestCount: requests.length,\n });\n\n try {\n const sheets = sheetsApi({ version: 'v4', auth: googleAuth(extra.authContext.auth) });\n\n // Get spreadsheet and sheet info in single API call\n const spreadsheetResponse = await sheets.spreadsheets.get({\n spreadsheetId: id,\n fields: 'sheets.properties.sheetId,sheets.properties.title',\n });\n\n // Find sheet by gid\n const sheet = spreadsheetResponse.data.sheets?.find((s) => String(s.properties?.sheetId) === gid);\n if (!sheet?.properties) {\n logger.info('Sheet not found for format cells', { id, gid, requestCount: requests.length });\n throw new ProtocolError(ProtocolErrorCode.InvalidParams, `Sheet not found: ${gid}`);\n }\n\n const sheetTitle = sheet.properties.title ?? gid;\n // googleapis types sheetId as `number | null | undefined`; coerce for rangeReferenceToGridRange below (same pattern as values-batch-update.ts's sheetGid).\n const sheetId = sheet.properties.sheetId ?? 0;\n const sheetUrl = `https://docs.google.com/spreadsheets/d/${id}/edit#gid=${sheetId}`;\n\n // Build batch update requests\n const batchRequests: sheets_v4.Schema$Request[] = [];\n const failedRanges: Array<{ range: string; error: string }> = [];\n\n for (const request of requests) {\n try {\n // Parse A1 notation to range reference\n const rangeRef = parseA1Notation(request.range);\n\n // Build grid range from range reference using helper function\n const gridRange = rangeReferenceToGridRange(rangeRef, sheetId);\n\n // Build cell format object\n const cellFormat: {\n backgroundColor?: sheets_v4.Schema$Color;\n textFormat?: sheets_v4.Schema$TextFormat;\n horizontalAlignment?: string;\n numberFormat?: sheets_v4.Schema$NumberFormat;\n } = {};\n const fields: string[] = [];\n\n // Background color\n if (request.backgroundColor) {\n cellFormat.backgroundColor = request.backgroundColor;\n fields.push('backgroundColor');\n }\n\n // Text format\n if (request.textColor || request.bold !== undefined || request.fontSize !== undefined) {\n cellFormat.textFormat = {};\n if (request.textColor) {\n cellFormat.textFormat.foregroundColor = request.textColor;\n fields.push('textFormat.foregroundColor');\n }\n if (request.bold !== undefined) {\n cellFormat.textFormat.bold = request.bold;\n fields.push('textFormat.bold');\n }\n if (request.fontSize !== undefined) {\n cellFormat.textFormat.fontSize = request.fontSize;\n fields.push('textFormat.fontSize');\n }\n }\n\n // Horizontal alignment\n if (request.horizontalAlignment) {\n cellFormat.horizontalAlignment = request.horizontalAlignment;\n fields.push('horizontalAlignment');\n }\n\n // Number format\n if (request.numberFormat) {\n const numberFormat: sheets_v4.Schema$NumberFormat = {\n type: request.numberFormat.type,\n };\n if (request.numberFormat.pattern !== undefined) {\n numberFormat.pattern = request.numberFormat.pattern;\n }\n cellFormat.numberFormat = numberFormat;\n fields.push('numberFormat');\n }\n\n // Add repeatCell request for this range\n if (fields.length > 0) {\n batchRequests.push({\n repeatCell: {\n range: gridRange,\n cell: {\n userEnteredFormat: cellFormat,\n },\n fields: `userEnteredFormat(${fields.join(',')})`,\n },\n });\n }\n\n // Add border formatting if specified\n if (request.borders) {\n batchRequests.push({\n updateBorders: {\n range: gridRange,\n top: {\n style: request.borders.style,\n color: request.borders.color,\n },\n bottom: {\n style: request.borders.style,\n color: request.borders.color,\n },\n left: {\n style: request.borders.style,\n color: request.borders.color,\n },\n right: {\n style: request.borders.style,\n color: request.borders.color,\n },\n },\n });\n }\n } catch (error) {\n const message = error instanceof Error ? error.message : String(error);\n logger.info('Failed to parse range for formatting', {\n range: request.range,\n error: message,\n });\n failedRanges.push({\n range: request.range,\n error: `Failed to parse range: ${message}`,\n });\n }\n }\n\n // Early return if all ranges failed\n if (batchRequests.length === 0) {\n const result: Output = {\n type: 'success' as const,\n id,\n gid: String(sheetId),\n sheetTitle,\n sheetUrl,\n successCount: 0,\n failedRanges: failedRanges.length > 0 ? failedRanges : undefined,\n };\n\n return {\n content: [{ type: 'text' as const, text: JSON.stringify(result) }],\n structuredContent: { result },\n };\n }\n\n logger.info('sheets.cells.format executing batch request', {\n spreadsheetId: id,\n sheetTitle,\n batchRequestsCount: batchRequests.length,\n });\n\n // Execute the batch update\n await sheets.spreadsheets.batchUpdate({\n spreadsheetId: id,\n requestBody: {\n requests: batchRequests,\n },\n });\n\n logger.info('sheets.cells.format completed successfully', {\n successCount: requests.length - failedRanges.length,\n failedCount: failedRanges.length,\n });\n\n const result: Output = {\n type: 'success' as const,\n id,\n gid: String(sheetId),\n sheetTitle,\n sheetUrl,\n successCount: requests.length - failedRanges.length,\n failedRanges: failedRanges.length > 0 ? failedRanges : undefined,\n };\n\n return {\n content: [{ type: 'text' as const, text: JSON.stringify(result) }],\n structuredContent: { result },\n };\n } catch (error) {\n const message = error instanceof Error ? error.message : String(error);\n logger.error('Format cells operation failed', {\n id,\n gid,\n requestCount: requests.length,\n error: message,\n });\n\n throw new ProtocolError(ProtocolErrorCode.InternalError, `Error formatting cells: ${message}`, {\n stack: error instanceof Error ? error.stack : undefined,\n });\n }\n}\n\nexport default function createTool() {\n return {\n name: 'cells-format',\n config,\n handler,\n } satisfies ToolModule;\n}\n"],"names":["createTool","AuthRequiredBranchSchema","schemas","ColorSchema","z","object","red","number","min","max","describe","green","blue","NumberFormatSchema","type","enum","pattern","string","optional","BorderSchema","style","color","FormatRequestSchema","range","backgroundColor","textColor","bold","boolean","fontSize","int","horizontalAlignment","numberFormat","borders","inputSchema","id","SpreadsheetIdSchema","gid","SheetGidSchema","requests","array","successBranchSchema","literal","SpreadsheetIdOutput","SheetGidOutput","sheetTitle","sheetUrl","successCount","nonnegative","failedRanges","error","outputSchema","discriminatedUnion","config","description","result","handler","extra","logger","sheet","spreadsheetResponse","sheets","sheetId","batchRequests","request","rangeRef","gridRange","cellFormat","fields","message","info","requestCount","length","sheetsApi","version","auth","googleAuth","authContext","spreadsheets","get","spreadsheetId","data","find","s","String","properties","ProtocolError","ProtocolErrorCode","InvalidParams","title","parseA1Notation","rangeReferenceToGridRange","push","undefined","textFormat","foregroundColor","repeatCell","cell","userEnteredFormat","join","updateBorders","top","bottom","left","right","Error","content","text","JSON","stringify","structuredContent","batchRequestsCount","batchUpdate","requestBody","failedCount","InternalError","stack","name"],"mappings":";;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L,OAAOY,IAAI,CAAC,8CAA8C;wBACxDvB,cAAcR,SAASiC,MAAM,GAAGvB,aAAauB,MAAM;wBACnD0C,aAAajE,aAAauB,MAAM;oBAClC;oBAEMjB,UAAiB;wBACrBxC,MAAM;wBACNoB,IAAAA;wBACAE,KAAK+C,OAAOtB;wBACZjB,YAAAA;wBACAC,UAAAA;wBACAC,cAAcR,SAASiC,MAAM,GAAGvB,aAAauB,MAAM;wBACnDvB,cAAcA,aAAauB,MAAM,GAAG,IAAIvB,eAAe4C;oBACzD;oBAEA;;wBAAO;4BACLa,OAAO;gCAAG;oCAAE3F,MAAM;oCAAiB4F,MAAMC,KAAKC,SAAS,CAACtD;gCAAQ;;4BAChEuD,mBAAmB;gCAAEvD,QAAAA;4BAAO;wBAC9B;;;oBACOL;oBACDmB,WAAUnB,AAAK,YAALA,OAAiBuD,SAAQvD,MAAMmB,OAAO,GAAGe,OAAOlC;oBAChEQ,OAAOR,KAAK,CAAC,iCAAiC;wBAC5Cf,IAAAA;wBACAE,KAAAA;wBACAkC,cAAchC,SAASiC,MAAM;wBAC7BtB,OAAOmB;oBACT;oBAEA,MAAM,IAAIiB,qBAAa,CAACC,yBAAiB,CAAC4B,aAAa,EAAE,AAAC,2BAAkC,OAAR9C,WAAW;wBAC7F+C,OAAOlE,AAAK,YAALA,OAAiBuD,SAAQvD,MAAMkE,KAAK,GAAGvB;oBAChD;;;;;;;IAEJ;;AAEe,SAAS5F;IACtB,OAAO;QACLoH,MAAM;QACNhE,QAAAA;QACAG,SAAAA;IACF;AACF"}
|
|
1
|
+
{"version":3,"sources":["/Users/kevin/Dev/open-source/ai/mcp-z/mcp-sheets/src/mcp/tools/cells-format.ts"],"sourcesContent":["import { type sheets_v4, sheets as sheetsApi } from '@googleapis/sheets';\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 { z } from 'zod';\nimport { NATIVE_DATE_POINTER } from '../../constants.ts';\nimport { googleAuth } from '../../lib/google-auth.ts';\nimport { SheetGidOutput, SheetGidSchema, SpreadsheetIdOutput, SpreadsheetIdSchema } from '../../schemas/index.ts';\nimport { parseA1Notation, rangeReferenceToGridRange } from '../../spreadsheet/range-operations.ts';\n\n// RGB color schema (0-1 range for Google Sheets API)\nconst ColorSchema = z.object({\n red: z.number().min(0).max(1).describe('Red component (0-1)'),\n green: z.number().min(0).max(1).describe('Green component (0-1)'),\n blue: z.number().min(0).max(1).describe('Blue component (0-1)'),\n});\n\n// Number format schema\nconst NumberFormatSchema = z.object({\n type: z.enum(['TEXT', 'NUMBER', 'PERCENT', 'CURRENCY', 'DATE', 'TIME']).describe('Number format type'),\n pattern: z.string().optional().describe('Custom format pattern (e.g., \"$#,##0.00\" for currency, \"yyyy-mm-dd hh:mm\" for a date/time serial)'),\n});\n\n// Border schema\nconst BorderSchema = z.object({\n style: z.enum(['SOLID', 'DASHED', 'DOTTED']).describe('Border line style'),\n color: ColorSchema.describe('Border color'),\n});\n\n// Input schema for format requests\nconst FormatRequestSchema = z.object({\n range: z.string().min(1).describe('A1 notation range to format (e.g., \"A1:D10\", \"B:B\", \"5:5\")'),\n backgroundColor: ColorSchema.optional().describe('Cell background color'),\n textColor: ColorSchema.optional().describe('Text color'),\n bold: z.boolean().optional().describe('Bold text'),\n fontSize: z.number().int().min(6).max(36).optional().describe('Font size in points'),\n horizontalAlignment: z.enum(['LEFT', 'CENTER', 'RIGHT']).optional().describe('Horizontal text alignment'),\n numberFormat: NumberFormatSchema.optional().describe('Number format pattern'),\n borders: BorderSchema.optional().describe('Cell borders'),\n});\n\nconst inputSchema = z.object({\n id: SpreadsheetIdSchema,\n gid: SheetGidSchema,\n requests: z.array(FormatRequestSchema).min(1).max(50).describe('Array of formatting requests. Batch multiple ranges for efficiency.'),\n});\n\nconst successBranchSchema = z.object({\n type: z.literal('success'),\n id: SpreadsheetIdOutput,\n gid: SheetGidOutput,\n sheetTitle: z.string().describe('Title of the formatted sheet'),\n sheetUrl: z.string().describe('URL of the formatted sheet'),\n successCount: z.number().int().nonnegative().describe('Number of format requests successfully applied'),\n failedRanges: z\n .array(\n z.object({\n range: z.string().describe('A1 notation of range that failed'),\n error: z.string().describe('Why formatting failed for this range'),\n })\n )\n .optional()\n .describe('Only populated if some ranges failed to format'),\n});\n\nconst outputSchema = z.discriminatedUnion('type', [successBranchSchema, AuthRequiredBranchSchema]);\n\nconst config = {\n description: `Apply formatting (colors, borders, fonts, alignment, number formats) to cell ranges without modifying data. Supports batch operations for efficiency. Colors use 0-1 RGB format. Best for creating professional, visually organized spreadsheets. Date/time cells: numberFormat {type:\"DATE\", pattern:\"yyyy-mm-dd hh:mm\"} only displays a numeric serial as a date; it does not convert text. ${NATIVE_DATE_POINTER}`,\n inputSchema,\n outputSchema: z.object({\n result: outputSchema,\n }),\n} as const;\n\nexport type Input = z.infer<typeof inputSchema>;\nexport type Output = z.infer<typeof outputSchema>;\n\nasync function handler({ id, gid, requests }: Input, extra: EnrichedExtra): Promise<CallToolResult> {\n const logger = extra.logger;\n logger.info('sheets.cells.format called', {\n id,\n gid,\n requestCount: requests.length,\n });\n\n try {\n const sheets = sheetsApi({ version: 'v4', auth: googleAuth(extra.authContext.auth) });\n\n // Get spreadsheet and sheet info in single API call\n const spreadsheetResponse = await sheets.spreadsheets.get({\n spreadsheetId: id,\n fields: 'sheets.properties.sheetId,sheets.properties.title',\n });\n\n // Find sheet by gid\n const sheet = spreadsheetResponse.data.sheets?.find((s) => String(s.properties?.sheetId) === gid);\n if (!sheet?.properties) {\n logger.info('Sheet not found for format cells', { id, gid, requestCount: requests.length });\n throw new ProtocolError(ProtocolErrorCode.InvalidParams, `Sheet not found: ${gid}`);\n }\n\n const sheetTitle = sheet.properties.title ?? gid;\n // googleapis types sheetId as `number | null | undefined`; coerce for rangeReferenceToGridRange below (same pattern as values-batch-update.ts's sheetGid).\n const sheetId = sheet.properties.sheetId ?? 0;\n const sheetUrl = `https://docs.google.com/spreadsheets/d/${id}/edit#gid=${sheetId}`;\n\n // Build batch update requests\n const batchRequests: sheets_v4.Schema$Request[] = [];\n const failedRanges: Array<{ range: string; error: string }> = [];\n\n for (const request of requests) {\n try {\n // Parse A1 notation to range reference\n const rangeRef = parseA1Notation(request.range);\n\n // Build grid range from range reference using helper function\n const gridRange = rangeReferenceToGridRange(rangeRef, sheetId);\n\n // Build cell format object\n const cellFormat: {\n backgroundColor?: sheets_v4.Schema$Color;\n textFormat?: sheets_v4.Schema$TextFormat;\n horizontalAlignment?: string;\n numberFormat?: sheets_v4.Schema$NumberFormat;\n } = {};\n const fields: string[] = [];\n\n // Background color\n if (request.backgroundColor) {\n cellFormat.backgroundColor = request.backgroundColor;\n fields.push('backgroundColor');\n }\n\n // Text format\n if (request.textColor || request.bold !== undefined || request.fontSize !== undefined) {\n cellFormat.textFormat = {};\n if (request.textColor) {\n cellFormat.textFormat.foregroundColor = request.textColor;\n fields.push('textFormat.foregroundColor');\n }\n if (request.bold !== undefined) {\n cellFormat.textFormat.bold = request.bold;\n fields.push('textFormat.bold');\n }\n if (request.fontSize !== undefined) {\n cellFormat.textFormat.fontSize = request.fontSize;\n fields.push('textFormat.fontSize');\n }\n }\n\n // Horizontal alignment\n if (request.horizontalAlignment) {\n cellFormat.horizontalAlignment = request.horizontalAlignment;\n fields.push('horizontalAlignment');\n }\n\n // Number format\n if (request.numberFormat) {\n const numberFormat: sheets_v4.Schema$NumberFormat = {\n type: request.numberFormat.type,\n };\n if (request.numberFormat.pattern !== undefined) {\n numberFormat.pattern = request.numberFormat.pattern;\n }\n cellFormat.numberFormat = numberFormat;\n fields.push('numberFormat');\n }\n\n // Add repeatCell request for this range\n if (fields.length > 0) {\n batchRequests.push({\n repeatCell: {\n range: gridRange,\n cell: {\n userEnteredFormat: cellFormat,\n },\n fields: `userEnteredFormat(${fields.join(',')})`,\n },\n });\n }\n\n // Add border formatting if specified\n if (request.borders) {\n batchRequests.push({\n updateBorders: {\n range: gridRange,\n top: {\n style: request.borders.style,\n color: request.borders.color,\n },\n bottom: {\n style: request.borders.style,\n color: request.borders.color,\n },\n left: {\n style: request.borders.style,\n color: request.borders.color,\n },\n right: {\n style: request.borders.style,\n color: request.borders.color,\n },\n },\n });\n }\n } catch (error) {\n const message = error instanceof Error ? error.message : String(error);\n logger.info('Failed to parse range for formatting', {\n range: request.range,\n error: message,\n });\n failedRanges.push({\n range: request.range,\n error: `Failed to parse range: ${message}`,\n });\n }\n }\n\n // Early return if all ranges failed\n if (batchRequests.length === 0) {\n const result: Output = {\n type: 'success' as const,\n id,\n gid: String(sheetId),\n sheetTitle,\n sheetUrl,\n successCount: 0,\n failedRanges: failedRanges.length > 0 ? failedRanges : undefined,\n };\n\n return {\n content: [{ type: 'text' as const, text: JSON.stringify(result) }],\n structuredContent: { result },\n };\n }\n\n logger.info('sheets.cells.format executing batch request', {\n spreadsheetId: id,\n sheetTitle,\n batchRequestsCount: batchRequests.length,\n });\n\n // Execute the batch update\n await sheets.spreadsheets.batchUpdate({\n spreadsheetId: id,\n requestBody: {\n requests: batchRequests,\n },\n });\n\n logger.info('sheets.cells.format completed successfully', {\n successCount: requests.length - failedRanges.length,\n failedCount: failedRanges.length,\n });\n\n const result: Output = {\n type: 'success' as const,\n id,\n gid: String(sheetId),\n sheetTitle,\n sheetUrl,\n successCount: requests.length - failedRanges.length,\n failedRanges: failedRanges.length > 0 ? failedRanges : undefined,\n };\n\n return {\n content: [{ type: 'text' as const, text: JSON.stringify(result) }],\n structuredContent: { result },\n };\n } catch (error) {\n const message = error instanceof Error ? error.message : String(error);\n logger.error('Format cells operation failed', {\n id,\n gid,\n requestCount: requests.length,\n error: message,\n });\n\n throw new ProtocolError(ProtocolErrorCode.InternalError, `Error formatting cells: ${message}`, {\n stack: error instanceof Error ? error.stack : undefined,\n });\n }\n}\n\nexport default function createTool() {\n return {\n name: 'cells-format',\n config,\n handler,\n } satisfies ToolModule;\n}\n"],"names":["createTool","AuthRequiredBranchSchema","schemas","ColorSchema","z","object","red","number","min","max","describe","green","blue","NumberFormatSchema","type","enum","pattern","string","optional","BorderSchema","style","color","FormatRequestSchema","range","backgroundColor","textColor","bold","boolean","fontSize","int","horizontalAlignment","numberFormat","borders","inputSchema","id","SpreadsheetIdSchema","gid","SheetGidSchema","requests","array","successBranchSchema","literal","SpreadsheetIdOutput","SheetGidOutput","sheetTitle","sheetUrl","successCount","nonnegative","failedRanges","error","outputSchema","discriminatedUnion","config","description","NATIVE_DATE_POINTER","result","handler","extra","logger","sheet","spreadsheetResponse","sheets","sheetId","batchRequests","request","rangeRef","gridRange","cellFormat","fields","message","info","requestCount","length","sheetsApi","version","auth","googleAuth","authContext","spreadsheets","get","spreadsheetId","data","find","s","String","properties","ProtocolError","ProtocolErrorCode","InvalidParams","title","parseA1Notation","rangeReferenceToGridRange","push","undefined","textFormat","foregroundColor","repeatCell","cell","userEnteredFormat","join","updateBorders","top","bottom","left","right","Error","content","text","JSON","stringify","structuredContent","batchRequestsCount","batchUpdate","requestBody","failedCount","InternalError","stack","name"],"mappings":";;;;+BAiSA;;;eAAwBA;;;sBAjS4B;2BAE5B;sBAKyB;mBAC/B;2BACkB;4BACT;uBAC8D;iCAC9B;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAR3D,IAAM,AAAEC,2BAA6BC,oBAAO,CAApCD;AAUR,qDAAqD;AACrD,IAAME,cAAcC,MAAC,CAACC,MAAM,CAAC;IAC3BC,KAAKF,MAAC,CAACG,MAAM,GAAGC,GAAG,CAAC,GAAGC,GAAG,CAAC,GAAGC,QAAQ,CAAC;IACvCC,OAAOP,MAAC,CAACG,MAAM,GAAGC,GAAG,CAAC,GAAGC,GAAG,CAAC,G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;oBACON;oBACDoB,WAAUpB,AAAK,YAALA,OAAiBwD,SAAQxD,MAAMoB,OAAO,GAAGe,OAAOnC;oBAChES,OAAOT,KAAK,CAAC,iCAAiC;wBAC5Cf,IAAAA;wBACAE,KAAAA;wBACAmC,cAAcjC,SAASkC,MAAM;wBAC7BvB,OAAOoB;oBACT;oBAEA,MAAM,IAAIiB,qBAAa,CAACC,yBAAiB,CAAC4B,aAAa,EAAE,AAAC,2BAAkC,OAAR9C,WAAW;wBAC7F+C,OAAOnE,AAAK,YAALA,OAAiBwD,SAAQxD,MAAMmE,KAAK,GAAGvB;oBAChD;;;;;;;IAEJ;;AAEe,SAAS7F;IACtB,OAAO;QACLqH,MAAM;QACNjE,QAAAA;QACAI,SAAAA;IACF;AACF"}
|
|
@@ -6,8 +6,8 @@ declare const inputSchema: z.ZodObject<{
|
|
|
6
6
|
id: z.ZodString;
|
|
7
7
|
gid: z.ZodCoercedString<unknown>;
|
|
8
8
|
render: z.ZodOptional<z.ZodEnum<{
|
|
9
|
-
FORMATTED_VALUE: "FORMATTED_VALUE";
|
|
10
9
|
UNFORMATTED_VALUE: "UNFORMATTED_VALUE";
|
|
10
|
+
FORMATTED_VALUE: "FORMATTED_VALUE";
|
|
11
11
|
FORMULA: "FORMULA";
|
|
12
12
|
}>>;
|
|
13
13
|
}, z.core.$strip>;
|
|
@@ -32,8 +32,8 @@ export default function createTool(): {
|
|
|
32
32
|
id: z.ZodString;
|
|
33
33
|
gid: z.ZodCoercedString<unknown>;
|
|
34
34
|
render: z.ZodOptional<z.ZodEnum<{
|
|
35
|
-
FORMATTED_VALUE: "FORMATTED_VALUE";
|
|
36
35
|
UNFORMATTED_VALUE: "UNFORMATTED_VALUE";
|
|
36
|
+
FORMATTED_VALUE: "FORMATTED_VALUE";
|
|
37
37
|
FORMULA: "FORMULA";
|
|
38
38
|
}>>;
|
|
39
39
|
}, z.core.$strip>;
|
|
@@ -6,8 +6,8 @@ declare const inputSchema: z.ZodObject<{
|
|
|
6
6
|
id: z.ZodString;
|
|
7
7
|
gid: z.ZodCoercedString<unknown>;
|
|
8
8
|
render: z.ZodOptional<z.ZodEnum<{
|
|
9
|
-
FORMATTED_VALUE: "FORMATTED_VALUE";
|
|
10
9
|
UNFORMATTED_VALUE: "UNFORMATTED_VALUE";
|
|
10
|
+
FORMATTED_VALUE: "FORMATTED_VALUE";
|
|
11
11
|
FORMULA: "FORMULA";
|
|
12
12
|
}>>;
|
|
13
13
|
}, z.core.$strip>;
|
|
@@ -32,8 +32,8 @@ export default function createTool(): {
|
|
|
32
32
|
id: z.ZodString;
|
|
33
33
|
gid: z.ZodCoercedString<unknown>;
|
|
34
34
|
render: z.ZodOptional<z.ZodEnum<{
|
|
35
|
-
FORMATTED_VALUE: "FORMATTED_VALUE";
|
|
36
35
|
UNFORMATTED_VALUE: "UNFORMATTED_VALUE";
|
|
36
|
+
FORMATTED_VALUE: "FORMATTED_VALUE";
|
|
37
37
|
FORMULA: "FORMULA";
|
|
38
38
|
}>>;
|
|
39
39
|
}, z.core.$strip>;
|
|
@@ -12,6 +12,7 @@ var _sheets = require("@googleapis/sheets");
|
|
|
12
12
|
var _oauthgoogle = require("@mcp-z/oauth-google");
|
|
13
13
|
var _server = require("@mcp-z/server");
|
|
14
14
|
var _zod = require("zod");
|
|
15
|
+
var _constantsts = require("../../constants.js");
|
|
15
16
|
var _googleauthts = require("../../lib/google-auth.js");
|
|
16
17
|
var _indexts = require("../../schemas/index.js");
|
|
17
18
|
function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) {
|
|
@@ -153,7 +154,7 @@ var inputSchema = _zod.z.object({
|
|
|
153
154
|
'FORMATTED_VALUE',
|
|
154
155
|
'UNFORMATTED_VALUE',
|
|
155
156
|
'FORMULA'
|
|
156
|
-
]).optional().describe(
|
|
157
|
+
]).optional().describe(_constantsts.RENDER_DESCRIPTION)
|
|
157
158
|
});
|
|
158
159
|
// Success branch schema - uses columns: for consistency with standard vocabulary
|
|
159
160
|
var successBranchSchema = _zod.z.object({
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["/Users/kevin/Dev/open-source/ai/mcp-z/mcp-sheets/src/mcp/tools/columns-get.ts"],"sourcesContent":["/** Get column names from Google Sheet (peek at first row only) */\n\nimport { sheets as sheetsApi } from '@googleapis/sheets';\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 { z } from 'zod';\nimport { googleAuth } from '../../lib/google-auth.ts';\nimport { SheetGidSchema, SpreadsheetIdSchema } from '../../schemas/index.ts';\n\nconst inputSchema = z.object({\n id: SpreadsheetIdSchema,\n gid: SheetGidSchema,\n render: z.enum(['FORMATTED_VALUE', 'UNFORMATTED_VALUE', 'FORMULA']).optional().describe(
|
|
1
|
+
{"version":3,"sources":["/Users/kevin/Dev/open-source/ai/mcp-z/mcp-sheets/src/mcp/tools/columns-get.ts"],"sourcesContent":["/** Get column names from Google Sheet (peek at first row only) */\n\nimport { sheets as sheetsApi } from '@googleapis/sheets';\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 { z } from 'zod';\nimport { RENDER_DESCRIPTION } from '../../constants.ts';\nimport { googleAuth } from '../../lib/google-auth.ts';\nimport { SheetGidSchema, SpreadsheetIdSchema } from '../../schemas/index.ts';\n\nconst inputSchema = z.object({\n id: SpreadsheetIdSchema,\n gid: SheetGidSchema,\n render: z.enum(['FORMATTED_VALUE', 'UNFORMATTED_VALUE', 'FORMULA']).optional().describe(RENDER_DESCRIPTION),\n});\n\n// Success branch schema - uses columns: for consistency with standard vocabulary\nconst successBranchSchema = z.object({\n type: z.literal('success'),\n columns: z.array(z.string()).describe('First row values (column names) or empty if no rows'),\n isEmpty: z.boolean().describe('True if sheet has zero rows'),\n});\n\nconst outputSchema = z.discriminatedUnion('type', [successBranchSchema, AuthRequiredBranchSchema]);\n\nconst config = {\n description: 'Get first row from Google Sheet. Returns columns array and isEmpty flag.',\n inputSchema,\n outputSchema: z.object({\n result: outputSchema,\n }),\n} as const;\n\nexport type Input = z.infer<typeof inputSchema>;\nexport type Output = z.infer<typeof outputSchema>;\n\nasync function handler({ id, gid, render }: Input, extra: EnrichedExtra): Promise<CallToolResult> {\n const logger = extra.logger;\n logger.debug?.('sheets.columns.get called', { id, gid, render });\n\n try {\n const sheets = sheetsApi({ version: 'v4', auth: googleAuth(extra.authContext.auth) });\n\n // Get spreadsheet and sheet info in single API call\n const spreadsheetResponse = await sheets.spreadsheets.get({\n spreadsheetId: id,\n fields: 'sheets.properties.sheetId,sheets.properties.title',\n });\n\n // Find sheet by gid\n const sheet = spreadsheetResponse.data.sheets?.find((s) => String(s.properties?.sheetId) === gid);\n if (!sheet?.properties) {\n throw new ProtocolError(ProtocolErrorCode.InvalidParams, `Sheet not found: ${gid}`);\n }\n\n const sheetTitle = sheet.properties.title ?? '';\n\n // Read first row only (A1:ZZZ1 should cover most reasonable sheets)\n const range = `'${sheetTitle}'!A1:ZZZ1`;\n const response = await sheets.spreadsheets.values.get({\n spreadsheetId: id,\n range,\n valueRenderOption: render || 'FORMATTED_VALUE',\n });\n\n const rows = response.data.values || [];\n const isEmpty = rows.length === 0;\n\n // Extract first row and convert to strings (column names)\n const firstRow = rows[0] || [];\n const columns = firstRow.map((value) => String(value ?? ''));\n\n const result: Output = {\n type: 'success' as const,\n columns,\n isEmpty,\n };\n\n logger.info?.('sheets.columns.get completed', { id, gid, columnCount: columns.length, isEmpty });\n return {\n content: [{ type: 'text' as const, text: JSON.stringify(result) }],\n structuredContent: { result },\n };\n } catch (error) {\n const message = error instanceof Error ? error.message : String(error);\n logger.error?.('sheets.columns.get error', { error: message });\n throw new ProtocolError(ProtocolErrorCode.InternalError, `Error getting sheet columns: ${message}`, {\n stack: error instanceof Error ? error.stack : undefined,\n });\n }\n}\n\nexport default function createTool() {\n return {\n name: 'columns-get',\n config,\n handler,\n } satisfies ToolModule;\n}\n"],"names":["createTool","AuthRequiredBranchSchema","schemas","inputSchema","z","object","id","SpreadsheetIdSchema","gid","SheetGidSchema","render","enum","optional","describe","RENDER_DESCRIPTION","successBranchSchema","type","literal","columns","array","string","isEmpty","boolean","outputSchema","discriminatedUnion","config","description","result","handler","extra","logger","sheet","spreadsheetResponse","sheets","sheetTitle","range","response","rows","firstRow","error","message","debug","sheetsApi","version","auth","googleAuth","authContext","spreadsheets","get","spreadsheetId","fields","data","find","s","String","properties","sheetId","ProtocolError","ProtocolErrorCode","InvalidParams","title","values","valueRenderOption","length","map","value","info","columnCount","content","text","JSON","stringify","structuredContent","Error","InternalError","stack","undefined","name"],"mappings":"AAAA,gEAAgE;;;;+BAiGhE;;;eAAwBA;;;sBA/FY;2BAEZ;sBAKyB;mBAC/B;2BACiB;4BACR;uBACyB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAPpD,IAAM,AAAEC,2BAA6BC,oBAAO,CAApCD;AASR,IAAME,cAAcC,MAAC,CAACC,MAAM,CAAC;IAC3BC,IAAIC,4BAAmB;IACvBC,KAAKC,uBAAc;IACnBC,QAAQN,MAAC,CAACO,IAAI,CAAC;QAAC;QAAmB;QAAqB;KAAU,EAAEC,QAAQ,GAAGC,QAAQ,CAACC,+BAAkB;AAC5G;AAEA,iFAAiF;AACjF,IAAMC,sBAAsBX,MAAC,CAACC,MAAM,CAAC;IACnCW,MAAMZ,MAAC,CAACa,OAAO,CAAC;IAChBC,SAASd,MAAC,CAACe,KA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ClGmC,OAAOpC,AAAK,YAALA,OAAiBkC,SAAQlC,MAAMoC,KAAK,GAAGC;oBAChD;;;;;;;IAEJ;;AAEe,SAAS5E;IACtB,OAAO;QACL6E,MAAM;QACNpD,QAAAA;QACAG,SAAAA;IACF;AACF"}
|
|
@@ -42,7 +42,7 @@ declare function handler({ id, gid, rows, headers, updateBy, behavior, valueInpu
|
|
|
42
42
|
export default function createTool(): {
|
|
43
43
|
name: string;
|
|
44
44
|
config: {
|
|
45
|
-
readonly description: "Update spreadsheet data by column headers with intelligent upsert logic. Supports adding missing columns, flexible update behaviors, and robust error handling. Uses column names as keys for matching existing rows, enabling context-aware data synchronization workflows.";
|
|
45
|
+
readonly description: "Update spreadsheet data by column headers with intelligent upsert logic. Supports adding missing columns, flexible update behaviors, and robust error handling. Uses column names as keys for matching existing rows, enabling context-aware data synchronization workflows. Dates: a date-looking string is not necessarily a native date. See values-batch-update for the native-date write, format and read-back steps.";
|
|
46
46
|
readonly inputSchema: z.ZodObject<{
|
|
47
47
|
id: z.ZodString;
|
|
48
48
|
gid: z.ZodCoercedString<unknown>;
|