@mcp-z/mcp-sheets 2.4.2 → 2.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 +45 -29
- package/dist/cjs/constants.d.cts +2 -0
- package/dist/cjs/constants.d.ts +2 -0
- package/dist/cjs/constants.js +27 -3
- package/dist/cjs/constants.js.map +1 -1
- package/dist/cjs/mcp/tools/cells-copy.d.cts +165 -0
- package/dist/cjs/mcp/tools/cells-copy.d.ts +165 -0
- package/dist/cjs/mcp/tools/cells-copy.js +388 -0
- package/dist/cjs/mcp/tools/cells-copy.js.map +1 -0
- package/dist/cjs/mcp/tools/index.d.cts +1 -0
- package/dist/cjs/mcp/tools/index.d.ts +1 -0
- package/dist/cjs/mcp/tools/index.js +4 -0
- package/dist/cjs/mcp/tools/index.js.map +1 -1
- package/dist/cjs/schemas/index.d.cts +1 -0
- package/dist/cjs/schemas/index.d.ts +1 -0
- package/dist/cjs/schemas/index.js +16 -0
- package/dist/cjs/schemas/index.js.map +1 -1
- package/dist/cjs/setup/config.js +26 -14
- package/dist/cjs/setup/config.js.map +1 -1
- package/dist/cjs/setup/version-help.js +1 -1
- package/dist/cjs/setup/version-help.js.map +1 -1
- package/dist/cjs/spreadsheet/data-operations.js +59 -164
- package/dist/cjs/spreadsheet/data-operations.js.map +1 -1
- package/dist/cjs/spreadsheet/range-operations.d.cts +26 -0
- package/dist/cjs/spreadsheet/range-operations.d.ts +26 -0
- package/dist/cjs/spreadsheet/range-operations.js +48 -0
- package/dist/cjs/spreadsheet/range-operations.js.map +1 -1
- package/dist/cjs/spreadsheet/sheet-operations.d.cts +6 -0
- package/dist/cjs/spreadsheet/sheet-operations.d.ts +6 -0
- package/dist/cjs/spreadsheet/sheet-operations.js +92 -52
- package/dist/cjs/spreadsheet/sheet-operations.js.map +1 -1
- package/dist/esm/constants.d.ts +2 -0
- package/dist/esm/constants.js +14 -0
- package/dist/esm/constants.js.map +1 -1
- package/dist/esm/mcp/tools/cells-copy.d.ts +165 -0
- package/dist/esm/mcp/tools/cells-copy.js +190 -0
- package/dist/esm/mcp/tools/cells-copy.js.map +1 -0
- package/dist/esm/mcp/tools/index.d.ts +1 -0
- package/dist/esm/mcp/tools/index.js +1 -0
- package/dist/esm/mcp/tools/index.js.map +1 -1
- package/dist/esm/schemas/index.d.ts +1 -0
- package/dist/esm/schemas/index.js +9 -0
- package/dist/esm/schemas/index.js.map +1 -1
- package/dist/esm/setup/config.js +26 -14
- package/dist/esm/setup/config.js.map +1 -1
- package/dist/esm/setup/version-help.js +7 -0
- package/dist/esm/setup/version-help.js.map +1 -1
- package/dist/esm/spreadsheet/data-operations.js +40 -84
- package/dist/esm/spreadsheet/data-operations.js.map +1 -1
- package/dist/esm/spreadsheet/range-operations.d.ts +26 -0
- package/dist/esm/spreadsheet/range-operations.js +50 -0
- package/dist/esm/spreadsheet/range-operations.js.map +1 -1
- package/dist/esm/spreadsheet/sheet-operations.d.ts +6 -0
- package/dist/esm/spreadsheet/sheet-operations.js +69 -43
- package/dist/esm/spreadsheet/sheet-operations.js.map +1 -1
- package/package.json +3 -3
|
@@ -0,0 +1,165 @@
|
|
|
1
|
+
import type { sheets_v4 } from '@googleapis/sheets';
|
|
2
|
+
import type { EnrichedExtra } from '@mcp-z/oauth-google';
|
|
3
|
+
import type { CallToolResult } from '@mcp-z/server';
|
|
4
|
+
import { z } from 'zod';
|
|
5
|
+
declare const inputSchema: z.ZodObject<{
|
|
6
|
+
id: z.ZodString;
|
|
7
|
+
sourceGid: z.ZodPipe<z.ZodUnion<readonly [z.ZodNumber, z.ZodString]>, z.ZodTransform<string, string | number>>;
|
|
8
|
+
sourceRange: z.ZodString;
|
|
9
|
+
destinationGid: z.ZodPipe<z.ZodUnion<readonly [z.ZodNumber, z.ZodString]>, z.ZodTransform<string, string | number>>;
|
|
10
|
+
destinationRange: z.ZodString;
|
|
11
|
+
pasteType: z.ZodDefault<z.ZodEnum<{
|
|
12
|
+
PASTE_NORMAL: "PASTE_NORMAL";
|
|
13
|
+
PASTE_VALUES: "PASTE_VALUES";
|
|
14
|
+
PASTE_FORMAT: "PASTE_FORMAT";
|
|
15
|
+
PASTE_NO_BORDERS: "PASTE_NO_BORDERS";
|
|
16
|
+
PASTE_FORMULA: "PASTE_FORMULA";
|
|
17
|
+
PASTE_DATA_VALIDATION: "PASTE_DATA_VALIDATION";
|
|
18
|
+
PASTE_CONDITIONAL_FORMATTING: "PASTE_CONDITIONAL_FORMATTING";
|
|
19
|
+
}>>;
|
|
20
|
+
pasteOrientation: z.ZodDefault<z.ZodEnum<{
|
|
21
|
+
NORMAL: "NORMAL";
|
|
22
|
+
TRANSPOSE: "TRANSPOSE";
|
|
23
|
+
}>>;
|
|
24
|
+
}, z.core.$strip>;
|
|
25
|
+
declare const successBranchSchema: z.ZodObject<{
|
|
26
|
+
type: z.ZodLiteral<"success">;
|
|
27
|
+
id: z.ZodString;
|
|
28
|
+
spreadsheetTitle: z.ZodString;
|
|
29
|
+
spreadsheetUrl: z.ZodString;
|
|
30
|
+
sourceGid: z.ZodString;
|
|
31
|
+
sourceSheetTitle: z.ZodString;
|
|
32
|
+
sourceRange: z.ZodString;
|
|
33
|
+
destinationGid: z.ZodString;
|
|
34
|
+
destinationSheetTitle: z.ZodString;
|
|
35
|
+
destinationRange: z.ZodString;
|
|
36
|
+
pastedRange: z.ZodString;
|
|
37
|
+
pasteType: z.ZodEnum<{
|
|
38
|
+
PASTE_NORMAL: "PASTE_NORMAL";
|
|
39
|
+
PASTE_VALUES: "PASTE_VALUES";
|
|
40
|
+
PASTE_FORMAT: "PASTE_FORMAT";
|
|
41
|
+
PASTE_NO_BORDERS: "PASTE_NO_BORDERS";
|
|
42
|
+
PASTE_FORMULA: "PASTE_FORMULA";
|
|
43
|
+
PASTE_DATA_VALIDATION: "PASTE_DATA_VALIDATION";
|
|
44
|
+
PASTE_CONDITIONAL_FORMATTING: "PASTE_CONDITIONAL_FORMATTING";
|
|
45
|
+
}>;
|
|
46
|
+
pasteOrientation: z.ZodEnum<{
|
|
47
|
+
NORMAL: "NORMAL";
|
|
48
|
+
TRANSPOSE: "TRANSPOSE";
|
|
49
|
+
}>;
|
|
50
|
+
sheetUrl: z.ZodString;
|
|
51
|
+
}, z.core.$strip>;
|
|
52
|
+
declare const outputSchema: z.ZodDiscriminatedUnion<[z.ZodObject<{
|
|
53
|
+
type: z.ZodLiteral<"success">;
|
|
54
|
+
id: z.ZodString;
|
|
55
|
+
spreadsheetTitle: z.ZodString;
|
|
56
|
+
spreadsheetUrl: z.ZodString;
|
|
57
|
+
sourceGid: z.ZodString;
|
|
58
|
+
sourceSheetTitle: z.ZodString;
|
|
59
|
+
sourceRange: z.ZodString;
|
|
60
|
+
destinationGid: z.ZodString;
|
|
61
|
+
destinationSheetTitle: z.ZodString;
|
|
62
|
+
destinationRange: z.ZodString;
|
|
63
|
+
pastedRange: z.ZodString;
|
|
64
|
+
pasteType: z.ZodEnum<{
|
|
65
|
+
PASTE_NORMAL: "PASTE_NORMAL";
|
|
66
|
+
PASTE_VALUES: "PASTE_VALUES";
|
|
67
|
+
PASTE_FORMAT: "PASTE_FORMAT";
|
|
68
|
+
PASTE_NO_BORDERS: "PASTE_NO_BORDERS";
|
|
69
|
+
PASTE_FORMULA: "PASTE_FORMULA";
|
|
70
|
+
PASTE_DATA_VALIDATION: "PASTE_DATA_VALIDATION";
|
|
71
|
+
PASTE_CONDITIONAL_FORMATTING: "PASTE_CONDITIONAL_FORMATTING";
|
|
72
|
+
}>;
|
|
73
|
+
pasteOrientation: z.ZodEnum<{
|
|
74
|
+
NORMAL: "NORMAL";
|
|
75
|
+
TRANSPOSE: "TRANSPOSE";
|
|
76
|
+
}>;
|
|
77
|
+
sheetUrl: z.ZodString;
|
|
78
|
+
}, z.core.$strip>, z.ZodObject<{
|
|
79
|
+
type: z.ZodLiteral<"auth_required">;
|
|
80
|
+
provider: z.ZodString;
|
|
81
|
+
message: z.ZodString;
|
|
82
|
+
url: z.ZodOptional<z.ZodString>;
|
|
83
|
+
}, z.core.$strip>], "type">;
|
|
84
|
+
export type Input = z.infer<typeof inputSchema>;
|
|
85
|
+
export type Output = z.infer<typeof outputSchema>;
|
|
86
|
+
type SuccessOutput = z.infer<typeof successBranchSchema>;
|
|
87
|
+
/** The slice of the Sheets client this tool uses; tests pass a plain fake. */
|
|
88
|
+
export interface CellsCopySheets {
|
|
89
|
+
spreadsheets: {
|
|
90
|
+
get(params: {
|
|
91
|
+
spreadsheetId: string;
|
|
92
|
+
fields: string;
|
|
93
|
+
}): Promise<{
|
|
94
|
+
data: sheets_v4.Schema$Spreadsheet;
|
|
95
|
+
}>;
|
|
96
|
+
batchUpdate(params: {
|
|
97
|
+
spreadsheetId: string;
|
|
98
|
+
requestBody: sheets_v4.Schema$BatchUpdateSpreadsheetRequest;
|
|
99
|
+
}): Promise<unknown>;
|
|
100
|
+
};
|
|
101
|
+
}
|
|
102
|
+
export declare function copyCells(sheets: CellsCopySheets, { id, sourceGid, sourceRange, destinationGid, destinationRange, pasteType, pasteOrientation }: Input): Promise<SuccessOutput>;
|
|
103
|
+
declare function handler(input: Input, extra: EnrichedExtra): Promise<CallToolResult>;
|
|
104
|
+
export default function createTool(): {
|
|
105
|
+
name: string;
|
|
106
|
+
config: {
|
|
107
|
+
readonly description: "Copy a cell range to another range in the same spreadsheet (same or different tab), like Google Sheets copy and paste-special. Default PASTE_NORMAL copies values, formulas (relative references adjust), formats and merges; pasteType selects one native paste-special mode. Cannot copy between spreadsheets: use sheet-copy-to first. To duplicate a whole tab or workbook use sheet-copy, sheet-copy-to or spreadsheet-copy. Use a1-notation prompt for range syntax.";
|
|
108
|
+
readonly inputSchema: z.ZodObject<{
|
|
109
|
+
id: z.ZodString;
|
|
110
|
+
sourceGid: z.ZodPipe<z.ZodUnion<readonly [z.ZodNumber, z.ZodString]>, z.ZodTransform<string, string | number>>;
|
|
111
|
+
sourceRange: z.ZodString;
|
|
112
|
+
destinationGid: z.ZodPipe<z.ZodUnion<readonly [z.ZodNumber, z.ZodString]>, z.ZodTransform<string, string | number>>;
|
|
113
|
+
destinationRange: z.ZodString;
|
|
114
|
+
pasteType: z.ZodDefault<z.ZodEnum<{
|
|
115
|
+
PASTE_NORMAL: "PASTE_NORMAL";
|
|
116
|
+
PASTE_VALUES: "PASTE_VALUES";
|
|
117
|
+
PASTE_FORMAT: "PASTE_FORMAT";
|
|
118
|
+
PASTE_NO_BORDERS: "PASTE_NO_BORDERS";
|
|
119
|
+
PASTE_FORMULA: "PASTE_FORMULA";
|
|
120
|
+
PASTE_DATA_VALIDATION: "PASTE_DATA_VALIDATION";
|
|
121
|
+
PASTE_CONDITIONAL_FORMATTING: "PASTE_CONDITIONAL_FORMATTING";
|
|
122
|
+
}>>;
|
|
123
|
+
pasteOrientation: z.ZodDefault<z.ZodEnum<{
|
|
124
|
+
NORMAL: "NORMAL";
|
|
125
|
+
TRANSPOSE: "TRANSPOSE";
|
|
126
|
+
}>>;
|
|
127
|
+
}, z.core.$strip>;
|
|
128
|
+
readonly outputSchema: z.ZodObject<{
|
|
129
|
+
result: z.ZodDiscriminatedUnion<[z.ZodObject<{
|
|
130
|
+
type: z.ZodLiteral<"success">;
|
|
131
|
+
id: z.ZodString;
|
|
132
|
+
spreadsheetTitle: z.ZodString;
|
|
133
|
+
spreadsheetUrl: z.ZodString;
|
|
134
|
+
sourceGid: z.ZodString;
|
|
135
|
+
sourceSheetTitle: z.ZodString;
|
|
136
|
+
sourceRange: z.ZodString;
|
|
137
|
+
destinationGid: z.ZodString;
|
|
138
|
+
destinationSheetTitle: z.ZodString;
|
|
139
|
+
destinationRange: z.ZodString;
|
|
140
|
+
pastedRange: z.ZodString;
|
|
141
|
+
pasteType: z.ZodEnum<{
|
|
142
|
+
PASTE_NORMAL: "PASTE_NORMAL";
|
|
143
|
+
PASTE_VALUES: "PASTE_VALUES";
|
|
144
|
+
PASTE_FORMAT: "PASTE_FORMAT";
|
|
145
|
+
PASTE_NO_BORDERS: "PASTE_NO_BORDERS";
|
|
146
|
+
PASTE_FORMULA: "PASTE_FORMULA";
|
|
147
|
+
PASTE_DATA_VALIDATION: "PASTE_DATA_VALIDATION";
|
|
148
|
+
PASTE_CONDITIONAL_FORMATTING: "PASTE_CONDITIONAL_FORMATTING";
|
|
149
|
+
}>;
|
|
150
|
+
pasteOrientation: z.ZodEnum<{
|
|
151
|
+
NORMAL: "NORMAL";
|
|
152
|
+
TRANSPOSE: "TRANSPOSE";
|
|
153
|
+
}>;
|
|
154
|
+
sheetUrl: z.ZodString;
|
|
155
|
+
}, z.core.$strip>, z.ZodObject<{
|
|
156
|
+
type: z.ZodLiteral<"auth_required">;
|
|
157
|
+
provider: z.ZodString;
|
|
158
|
+
message: z.ZodString;
|
|
159
|
+
url: z.ZodOptional<z.ZodString>;
|
|
160
|
+
}, z.core.$strip>], "type">;
|
|
161
|
+
}, z.core.$strip>;
|
|
162
|
+
};
|
|
163
|
+
handler: typeof handler;
|
|
164
|
+
};
|
|
165
|
+
export {};
|
|
@@ -0,0 +1,190 @@
|
|
|
1
|
+
import { sheets as sheetsApi } from '@googleapis/sheets';
|
|
2
|
+
import { schemas } from '@mcp-z/oauth-google';
|
|
3
|
+
const { AuthRequiredBranchSchema } = schemas;
|
|
4
|
+
import { ProtocolError, ProtocolErrorCode } from '@mcp-z/server';
|
|
5
|
+
import { z } from 'zod';
|
|
6
|
+
import { PASTE_ORIENTATIONS, PASTE_TYPES } from '../../constants.js';
|
|
7
|
+
import { googleAuth } from '../../lib/google-auth.js';
|
|
8
|
+
import { A1NotationSchema, SheetGidOutput, SpreadsheetIdOutput, SpreadsheetIdSchema, StrictSheetGidSchema } from '../../schemas/index.js';
|
|
9
|
+
import { calculatePasteRange, cellBlockToA1, parseA1Notation, parseFiniteCellBlock, rangeReferenceToGridRange, validateA1Notation } from '../../spreadsheet/range-operations.js';
|
|
10
|
+
const inputSchema = z.object({
|
|
11
|
+
id: SpreadsheetIdSchema,
|
|
12
|
+
sourceGid: StrictSheetGidSchema.describe('Source sheet ID (from URL gid={gid})'),
|
|
13
|
+
sourceRange: A1NotationSchema.describe('Finite sheet-local A1 range to copy (e.g., "A1:C10"; no sheet prefix, no whole rows/columns)'),
|
|
14
|
+
destinationGid: StrictSheetGidSchema.describe('Destination sheet ID in the same spreadsheet; may equal sourceGid'),
|
|
15
|
+
destinationRange: A1NotationSchema.describe('Top-left cell (e.g., "E1") or a finite range whose height and width are whole multiples of the (oriented) source; a larger range repeats the source to fill it'),
|
|
16
|
+
pasteType: z.enum(PASTE_TYPES).default('PASTE_NORMAL').describe('What to paste. PASTE_NORMAL (default) = values, formulas, formats and merges; PASTE_VALUES = values only, no formats/formulas/merges; PASTE_FORMAT = format only, excluding data validation; PASTE_NO_BORDERS = like PASTE_NORMAL without borders; PASTE_FORMULA = formulas only; PASTE_DATA_VALIDATION = data validation only; PASTE_CONDITIONAL_FORMATTING = conditional formatting rules only'),
|
|
17
|
+
pasteOrientation: z.enum(PASTE_ORIENTATIONS).default('NORMAL').describe('NORMAL, or TRANSPOSE (rows become columns and vice versa)')
|
|
18
|
+
});
|
|
19
|
+
const successBranchSchema = z.object({
|
|
20
|
+
type: z.literal('success'),
|
|
21
|
+
id: SpreadsheetIdOutput,
|
|
22
|
+
spreadsheetTitle: z.string().describe('Title of the spreadsheet'),
|
|
23
|
+
spreadsheetUrl: z.string().describe('URL of the spreadsheet'),
|
|
24
|
+
sourceGid: SheetGidOutput,
|
|
25
|
+
sourceSheetTitle: z.string().describe('Title of the source sheet'),
|
|
26
|
+
sourceRange: z.string().describe('A1 range that was copied'),
|
|
27
|
+
destinationGid: SheetGidOutput,
|
|
28
|
+
destinationSheetTitle: z.string().describe('Title of the destination sheet'),
|
|
29
|
+
destinationRange: z.string().describe('Destination range as requested'),
|
|
30
|
+
pastedRange: z.string().describe('A1 range of cells written in the destination sheet'),
|
|
31
|
+
pasteType: z.enum(PASTE_TYPES).describe('Paste type applied'),
|
|
32
|
+
pasteOrientation: z.enum(PASTE_ORIENTATIONS).describe('Orientation applied'),
|
|
33
|
+
sheetUrl: z.string().describe('URL of the destination sheet')
|
|
34
|
+
});
|
|
35
|
+
const outputSchema = z.discriminatedUnion('type', [
|
|
36
|
+
successBranchSchema,
|
|
37
|
+
AuthRequiredBranchSchema
|
|
38
|
+
]);
|
|
39
|
+
const config = {
|
|
40
|
+
description: 'Copy a cell range to another range in the same spreadsheet (same or different tab), like Google Sheets copy and paste-special. Default PASTE_NORMAL copies values, formulas (relative references adjust), formats and merges; pasteType selects one native paste-special mode. Cannot copy between spreadsheets: use sheet-copy-to first. To duplicate a whole tab or workbook use sheet-copy, sheet-copy-to or spreadsheet-copy. Use a1-notation prompt for range syntax.',
|
|
41
|
+
inputSchema,
|
|
42
|
+
outputSchema: z.object({
|
|
43
|
+
result: outputSchema
|
|
44
|
+
})
|
|
45
|
+
};
|
|
46
|
+
function invalid(message) {
|
|
47
|
+
return new ProtocolError(ProtocolErrorCode.InvalidParams, message);
|
|
48
|
+
}
|
|
49
|
+
/** Validates a finite sheet-local A1 range, converting any failure to InvalidParams. */ function checkRange(label, notation) {
|
|
50
|
+
try {
|
|
51
|
+
validateA1Notation(notation);
|
|
52
|
+
return parseFiniteCellBlock(notation);
|
|
53
|
+
} catch (error) {
|
|
54
|
+
throw invalid(`Invalid ${label}: ${error instanceof Error ? error.message : String(error)}`);
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
export async function copyCells(sheets, { id, sourceGid, sourceRange, destinationGid, destinationRange, pasteType, pasteOrientation }) {
|
|
58
|
+
var _destinationSheet_sheetId, _ref, _spreadsheetData_spreadsheetUrl, _sourceSheet_title, _destinationSheet_title;
|
|
59
|
+
var _spreadsheetData_properties;
|
|
60
|
+
// All range checks happen before any network call
|
|
61
|
+
const source = checkRange('sourceRange', sourceRange);
|
|
62
|
+
checkRange('destinationRange', destinationRange);
|
|
63
|
+
let pasted;
|
|
64
|
+
try {
|
|
65
|
+
pasted = calculatePasteRange(sourceRange, destinationRange, pasteOrientation);
|
|
66
|
+
} catch (error) {
|
|
67
|
+
throw invalid(error instanceof Error ? error.message : String(error));
|
|
68
|
+
}
|
|
69
|
+
const spreadsheetResponse = await sheets.spreadsheets.get({
|
|
70
|
+
spreadsheetId: id,
|
|
71
|
+
fields: 'properties.title,spreadsheetUrl,sheets.properties.sheetId,sheets.properties.title,sheets.properties.gridProperties'
|
|
72
|
+
});
|
|
73
|
+
const spreadsheetData = spreadsheetResponse.data;
|
|
74
|
+
const findSheet = (gid)=>{
|
|
75
|
+
var _spreadsheetData_sheets_find, _spreadsheetData_sheets;
|
|
76
|
+
return (_spreadsheetData_sheets = spreadsheetData.sheets) === null || _spreadsheetData_sheets === void 0 ? void 0 : (_spreadsheetData_sheets_find = _spreadsheetData_sheets.find((s)=>{
|
|
77
|
+
var _s_properties;
|
|
78
|
+
return String((_s_properties = s.properties) === null || _s_properties === void 0 ? void 0 : _s_properties.sheetId) === gid;
|
|
79
|
+
})) === null || _spreadsheetData_sheets_find === void 0 ? void 0 : _spreadsheetData_sheets_find.properties;
|
|
80
|
+
};
|
|
81
|
+
const sourceSheet = findSheet(sourceGid);
|
|
82
|
+
if (!sourceSheet) throw invalid(`Sheet not found: ${sourceGid}`);
|
|
83
|
+
const destinationSheet = findSheet(destinationGid);
|
|
84
|
+
if (!destinationSheet) throw invalid(`Sheet not found: ${destinationGid}`);
|
|
85
|
+
const gridSize = (sheet)=>{
|
|
86
|
+
var _sheet_title;
|
|
87
|
+
var _sheet_gridProperties, _sheet_gridProperties1;
|
|
88
|
+
const rows = (_sheet_gridProperties = sheet.gridProperties) === null || _sheet_gridProperties === void 0 ? void 0 : _sheet_gridProperties.rowCount;
|
|
89
|
+
const columns = (_sheet_gridProperties1 = sheet.gridProperties) === null || _sheet_gridProperties1 === void 0 ? void 0 : _sheet_gridProperties1.columnCount;
|
|
90
|
+
if (typeof rows !== 'number' || typeof columns !== 'number') throw new Error(`Could not read the grid size of sheet "${(_sheet_title = sheet.title) !== null && _sheet_title !== void 0 ? _sheet_title : sheet.sheetId}"`);
|
|
91
|
+
return {
|
|
92
|
+
rows,
|
|
93
|
+
columns
|
|
94
|
+
};
|
|
95
|
+
};
|
|
96
|
+
const sourceGrid = gridSize(sourceSheet);
|
|
97
|
+
const destinationGrid = gridSize(destinationSheet);
|
|
98
|
+
const fits = (grid, endRow, endColumn)=>endRow <= grid.rows && endColumn <= grid.columns;
|
|
99
|
+
if (!fits(sourceGrid, source.endRow, source.endColumn)) {
|
|
100
|
+
throw invalid(`Source range ${sourceRange} is outside the grid of "${sourceSheet.title}" (${sourceGrid.rows} rows x ${sourceGrid.columns} columns)`);
|
|
101
|
+
}
|
|
102
|
+
if (!fits(destinationGrid, pasted.endRow, pasted.endColumn)) {
|
|
103
|
+
throw invalid(`Pasting ${sourceRange} at ${destinationRange} would write ${cellBlockToA1(pasted)}, outside the grid of "${destinationSheet.title}" (${destinationGrid.rows} rows x ${destinationGrid.columns} columns)`);
|
|
104
|
+
}
|
|
105
|
+
// pasteType is always sent explicitly; there is no fallback path
|
|
106
|
+
await sheets.spreadsheets.batchUpdate({
|
|
107
|
+
spreadsheetId: id,
|
|
108
|
+
requestBody: {
|
|
109
|
+
requests: [
|
|
110
|
+
{
|
|
111
|
+
copyPaste: {
|
|
112
|
+
source: rangeReferenceToGridRange(parseA1Notation(sourceRange), Number(sourceGid)),
|
|
113
|
+
destination: rangeReferenceToGridRange(parseA1Notation(destinationRange), Number(destinationGid)),
|
|
114
|
+
pasteType,
|
|
115
|
+
pasteOrientation
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
]
|
|
119
|
+
}
|
|
120
|
+
});
|
|
121
|
+
const destinationSheetId = (_destinationSheet_sheetId = destinationSheet.sheetId) !== null && _destinationSheet_sheetId !== void 0 ? _destinationSheet_sheetId : Number(destinationGid);
|
|
122
|
+
return {
|
|
123
|
+
type: 'success',
|
|
124
|
+
id,
|
|
125
|
+
spreadsheetTitle: (_ref = (_spreadsheetData_properties = spreadsheetData.properties) === null || _spreadsheetData_properties === void 0 ? void 0 : _spreadsheetData_properties.title) !== null && _ref !== void 0 ? _ref : '',
|
|
126
|
+
spreadsheetUrl: (_spreadsheetData_spreadsheetUrl = spreadsheetData.spreadsheetUrl) !== null && _spreadsheetData_spreadsheetUrl !== void 0 ? _spreadsheetData_spreadsheetUrl : '',
|
|
127
|
+
sourceGid,
|
|
128
|
+
sourceSheetTitle: (_sourceSheet_title = sourceSheet.title) !== null && _sourceSheet_title !== void 0 ? _sourceSheet_title : sourceGid,
|
|
129
|
+
sourceRange,
|
|
130
|
+
destinationGid,
|
|
131
|
+
destinationSheetTitle: (_destinationSheet_title = destinationSheet.title) !== null && _destinationSheet_title !== void 0 ? _destinationSheet_title : destinationGid,
|
|
132
|
+
destinationRange,
|
|
133
|
+
pastedRange: cellBlockToA1(pasted),
|
|
134
|
+
pasteType,
|
|
135
|
+
pasteOrientation,
|
|
136
|
+
sheetUrl: `https://docs.google.com/spreadsheets/d/${id}/edit#gid=${destinationSheetId}`
|
|
137
|
+
};
|
|
138
|
+
}
|
|
139
|
+
async function handler(input, extra) {
|
|
140
|
+
const logger = extra.logger;
|
|
141
|
+
const { id, sourceGid, destinationGid, pasteType, pasteOrientation } = input;
|
|
142
|
+
logger.info('sheets.cells.copy called', {
|
|
143
|
+
id,
|
|
144
|
+
sourceGid,
|
|
145
|
+
destinationGid,
|
|
146
|
+
pasteType,
|
|
147
|
+
pasteOrientation
|
|
148
|
+
});
|
|
149
|
+
try {
|
|
150
|
+
const sheets = sheetsApi({
|
|
151
|
+
version: 'v4',
|
|
152
|
+
auth: googleAuth(extra.authContext.auth)
|
|
153
|
+
});
|
|
154
|
+
const result = await copyCells(sheets, input);
|
|
155
|
+
logger.info('sheets.cells.copy completed successfully', {
|
|
156
|
+
id,
|
|
157
|
+
pastedRange: result.type === 'success' ? result.pastedRange : undefined
|
|
158
|
+
});
|
|
159
|
+
return {
|
|
160
|
+
content: [
|
|
161
|
+
{
|
|
162
|
+
type: 'text',
|
|
163
|
+
text: JSON.stringify(result)
|
|
164
|
+
}
|
|
165
|
+
],
|
|
166
|
+
structuredContent: {
|
|
167
|
+
result
|
|
168
|
+
}
|
|
169
|
+
};
|
|
170
|
+
} catch (error) {
|
|
171
|
+
if (error instanceof ProtocolError) throw error;
|
|
172
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
173
|
+
logger.error('Copy cells failed', {
|
|
174
|
+
id,
|
|
175
|
+
sourceGid,
|
|
176
|
+
destinationGid,
|
|
177
|
+
error: message
|
|
178
|
+
});
|
|
179
|
+
throw new ProtocolError(ProtocolErrorCode.InternalError, `Error copying cells: ${message}`, {
|
|
180
|
+
stack: error instanceof Error ? error.stack : undefined
|
|
181
|
+
});
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
export default function createTool() {
|
|
185
|
+
return {
|
|
186
|
+
name: 'cells-copy',
|
|
187
|
+
config,
|
|
188
|
+
handler
|
|
189
|
+
};
|
|
190
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["/Users/kevin/Dev/open-source/ai/mcp-z/mcp-sheets/src/mcp/tools/cells-copy.ts"],"sourcesContent":["import type { sheets_v4 } from '@googleapis/sheets';\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 { PASTE_ORIENTATIONS, PASTE_TYPES } from '../../constants.ts';\nimport { googleAuth } from '../../lib/google-auth.ts';\nimport { A1NotationSchema, SheetGidOutput, SpreadsheetIdOutput, SpreadsheetIdSchema, StrictSheetGidSchema } from '../../schemas/index.ts';\nimport { calculatePasteRange, cellBlockToA1, parseA1Notation, parseFiniteCellBlock, rangeReferenceToGridRange, validateA1Notation } from '../../spreadsheet/range-operations.ts';\n\nconst inputSchema = z.object({\n id: SpreadsheetIdSchema,\n sourceGid: StrictSheetGidSchema.describe('Source sheet ID (from URL gid={gid})'),\n sourceRange: A1NotationSchema.describe('Finite sheet-local A1 range to copy (e.g., \"A1:C10\"; no sheet prefix, no whole rows/columns)'),\n destinationGid: StrictSheetGidSchema.describe('Destination sheet ID in the same spreadsheet; may equal sourceGid'),\n destinationRange: A1NotationSchema.describe('Top-left cell (e.g., \"E1\") or a finite range whose height and width are whole multiples of the (oriented) source; a larger range repeats the source to fill it'),\n pasteType: z\n .enum(PASTE_TYPES)\n .default('PASTE_NORMAL')\n .describe(\n 'What to paste. PASTE_NORMAL (default) = values, formulas, formats and merges; PASTE_VALUES = values only, no formats/formulas/merges; PASTE_FORMAT = format only, excluding data validation; PASTE_NO_BORDERS = like PASTE_NORMAL without borders; PASTE_FORMULA = formulas only; PASTE_DATA_VALIDATION = data validation only; PASTE_CONDITIONAL_FORMATTING = conditional formatting rules only'\n ),\n pasteOrientation: z.enum(PASTE_ORIENTATIONS).default('NORMAL').describe('NORMAL, or TRANSPOSE (rows become columns and vice versa)'),\n});\n\nconst successBranchSchema = z.object({\n type: z.literal('success'),\n id: SpreadsheetIdOutput,\n spreadsheetTitle: z.string().describe('Title of the spreadsheet'),\n spreadsheetUrl: z.string().describe('URL of the spreadsheet'),\n sourceGid: SheetGidOutput,\n sourceSheetTitle: z.string().describe('Title of the source sheet'),\n sourceRange: z.string().describe('A1 range that was copied'),\n destinationGid: SheetGidOutput,\n destinationSheetTitle: z.string().describe('Title of the destination sheet'),\n destinationRange: z.string().describe('Destination range as requested'),\n pastedRange: z.string().describe('A1 range of cells written in the destination sheet'),\n pasteType: z.enum(PASTE_TYPES).describe('Paste type applied'),\n pasteOrientation: z.enum(PASTE_ORIENTATIONS).describe('Orientation applied'),\n sheetUrl: z.string().describe('URL of the destination sheet'),\n});\n\nconst outputSchema = z.discriminatedUnion('type', [successBranchSchema, AuthRequiredBranchSchema]);\n\nconst config = {\n description:\n 'Copy a cell range to another range in the same spreadsheet (same or different tab), like Google Sheets copy and paste-special. Default PASTE_NORMAL copies values, formulas (relative references adjust), formats and merges; pasteType selects one native paste-special mode. Cannot copy between spreadsheets: use sheet-copy-to first. To duplicate a whole tab or workbook use sheet-copy, sheet-copy-to or spreadsheet-copy. Use a1-notation prompt for range syntax.',\n inputSchema,\n outputSchema: z.object({\n result: outputSchema,\n }),\n} as const;\n\nexport type Input = z.infer<typeof inputSchema>;\nexport type Output = z.infer<typeof outputSchema>;\ntype SuccessOutput = z.infer<typeof successBranchSchema>;\n\n/** The slice of the Sheets client this tool uses; tests pass a plain fake. */\nexport interface CellsCopySheets {\n spreadsheets: {\n get(params: { spreadsheetId: string; fields: string }): Promise<{ data: sheets_v4.Schema$Spreadsheet }>;\n batchUpdate(params: { spreadsheetId: string; requestBody: sheets_v4.Schema$BatchUpdateSpreadsheetRequest }): Promise<unknown>;\n };\n}\n\nfunction invalid(message: string): ProtocolError {\n return new ProtocolError(ProtocolErrorCode.InvalidParams, message);\n}\n\n/** Validates a finite sheet-local A1 range, converting any failure to InvalidParams. */\nfunction checkRange(label: string, notation: string) {\n try {\n validateA1Notation(notation);\n return parseFiniteCellBlock(notation);\n } catch (error) {\n throw invalid(`Invalid ${label}: ${error instanceof Error ? error.message : String(error)}`);\n }\n}\n\nexport async function copyCells(sheets: CellsCopySheets, { id, sourceGid, sourceRange, destinationGid, destinationRange, pasteType, pasteOrientation }: Input): Promise<SuccessOutput> {\n // All range checks happen before any network call\n const source = checkRange('sourceRange', sourceRange);\n checkRange('destinationRange', destinationRange);\n let pasted: ReturnType<typeof calculatePasteRange>;\n try {\n pasted = calculatePasteRange(sourceRange, destinationRange, pasteOrientation);\n } catch (error) {\n throw invalid(error instanceof Error ? error.message : String(error));\n }\n\n const spreadsheetResponse = await sheets.spreadsheets.get({\n spreadsheetId: id,\n fields: 'properties.title,spreadsheetUrl,sheets.properties.sheetId,sheets.properties.title,sheets.properties.gridProperties',\n });\n const spreadsheetData = spreadsheetResponse.data;\n const findSheet = (gid: string) => spreadsheetData.sheets?.find((s) => String(s.properties?.sheetId) === gid)?.properties;\n const sourceSheet = findSheet(sourceGid);\n if (!sourceSheet) throw invalid(`Sheet not found: ${sourceGid}`);\n const destinationSheet = findSheet(destinationGid);\n if (!destinationSheet) throw invalid(`Sheet not found: ${destinationGid}`);\n\n const gridSize = (sheet: sheets_v4.Schema$SheetProperties) => {\n const rows = sheet.gridProperties?.rowCount;\n const columns = sheet.gridProperties?.columnCount;\n if (typeof rows !== 'number' || typeof columns !== 'number') throw new Error(`Could not read the grid size of sheet \"${sheet.title ?? sheet.sheetId}\"`);\n return { rows, columns };\n };\n const sourceGrid = gridSize(sourceSheet);\n const destinationGrid = gridSize(destinationSheet);\n const fits = (grid: { rows: number; columns: number }, endRow: number, endColumn: number) => endRow <= grid.rows && endColumn <= grid.columns;\n if (!fits(sourceGrid, source.endRow, source.endColumn)) {\n throw invalid(`Source range ${sourceRange} is outside the grid of \"${sourceSheet.title}\" (${sourceGrid.rows} rows x ${sourceGrid.columns} columns)`);\n }\n if (!fits(destinationGrid, pasted.endRow, pasted.endColumn)) {\n throw invalid(`Pasting ${sourceRange} at ${destinationRange} would write ${cellBlockToA1(pasted)}, outside the grid of \"${destinationSheet.title}\" (${destinationGrid.rows} rows x ${destinationGrid.columns} columns)`);\n }\n\n // pasteType is always sent explicitly; there is no fallback path\n await sheets.spreadsheets.batchUpdate({\n spreadsheetId: id,\n requestBody: {\n requests: [\n {\n copyPaste: {\n source: rangeReferenceToGridRange(parseA1Notation(sourceRange), Number(sourceGid)),\n destination: rangeReferenceToGridRange(parseA1Notation(destinationRange), Number(destinationGid)),\n pasteType,\n pasteOrientation,\n },\n },\n ],\n },\n });\n\n const destinationSheetId = destinationSheet.sheetId ?? Number(destinationGid);\n return {\n type: 'success' as const,\n id,\n spreadsheetTitle: spreadsheetData.properties?.title ?? '',\n spreadsheetUrl: spreadsheetData.spreadsheetUrl ?? '',\n sourceGid,\n sourceSheetTitle: sourceSheet.title ?? sourceGid,\n sourceRange,\n destinationGid,\n destinationSheetTitle: destinationSheet.title ?? destinationGid,\n destinationRange,\n pastedRange: cellBlockToA1(pasted),\n pasteType,\n pasteOrientation,\n sheetUrl: `https://docs.google.com/spreadsheets/d/${id}/edit#gid=${destinationSheetId}`,\n };\n}\n\nasync function handler(input: Input, extra: EnrichedExtra): Promise<CallToolResult> {\n const logger = extra.logger;\n const { id, sourceGid, destinationGid, pasteType, pasteOrientation } = input;\n logger.info('sheets.cells.copy called', { id, sourceGid, destinationGid, pasteType, pasteOrientation });\n\n try {\n const sheets = sheetsApi({ version: 'v4', auth: googleAuth(extra.authContext.auth) });\n const result: Output = await copyCells(sheets as unknown as CellsCopySheets, input);\n logger.info('sheets.cells.copy completed successfully', { id, pastedRange: result.type === 'success' ? result.pastedRange : undefined });\n return {\n content: [{ type: 'text' as const, text: JSON.stringify(result) }],\n structuredContent: { result },\n };\n } catch (error) {\n if (error instanceof ProtocolError) throw error;\n const message = error instanceof Error ? error.message : String(error);\n logger.error('Copy cells failed', { id, sourceGid, destinationGid, error: message });\n throw new ProtocolError(ProtocolErrorCode.InternalError, `Error copying cells: ${message}`, {\n stack: error instanceof Error ? error.stack : undefined,\n });\n }\n}\n\nexport default function createTool() {\n return {\n name: 'cells-copy',\n config,\n handler,\n } satisfies ToolModule;\n}\n"],"names":["sheets","sheetsApi","schemas","AuthRequiredBranchSchema","ProtocolError","ProtocolErrorCode","z","PASTE_ORIENTATIONS","PASTE_TYPES","googleAuth","A1NotationSchema","SheetGidOutput","SpreadsheetIdOutput","SpreadsheetIdSchema","StrictSheetGidSchema","calculatePasteRange","cellBlockToA1","parseA1Notation","parseFiniteCellBlock","rangeReferenceToGridRange","validateA1Notation","inputSchema","object","id","sourceGid","describe","sourceRange","destinationGid","destinationRange","pasteType","enum","default","pasteOrientation","successBranchSchema","type","literal","spreadsheetTitle","string","spreadsheetUrl","sourceSheetTitle","destinationSheetTitle","pastedRange","sheetUrl","outputSchema","discriminatedUnion","config","description","result","invalid","message","InvalidParams","checkRange","label","notation","error","Error","String","copyCells","destinationSheet","spreadsheetData","sourceSheet","source","pasted","spreadsheetResponse","spreadsheets","get","spreadsheetId","fields","data","findSheet","gid","find","s","properties","sheetId","gridSize","sheet","rows","gridProperties","rowCount","columns","columnCount","title","sourceGrid","destinationGrid","fits","grid","endRow","endColumn","batchUpdate","requestBody","requests","copyPaste","Number","destination","destinationSheetId","handler","input","extra","logger","info","version","auth","authContext","undefined","content","text","JSON","stringify","structuredContent","InternalError","stack","createTool","name"],"mappings":"AACA,SAASA,UAAUC,SAAS,QAAQ,qBAAqB;AAEzD,SAASC,OAAO,QAAQ,sBAAsB;AAE9C,MAAM,EAAEC,wBAAwB,EAAE,GAAGD;AAGrC,SAASE,aAAa,EAAEC,iBAAiB,QAAQ,gBAAgB;AACjE,SAASC,CAAC,QAAQ,MAAM;AACxB,SAASC,kBAAkB,EAAEC,WAAW,QAAQ,qBAAqB;AACrE,SAASC,UAAU,QAAQ,2BAA2B;AACtD,SAASC,gBAAgB,EAAEC,cAAc,EAAEC,mBAAmB,EAAEC,mBAAmB,EAAEC,oBAAoB,QAAQ,yBAAyB;AAC1I,SAASC,mBAAmB,EAAEC,aAAa,EAAEC,eAAe,EAAEC,oBAAoB,EAAEC,yBAAyB,EAAEC,kBAAkB,QAAQ,wCAAwC;AAEjL,MAAMC,cAAcf,EAAEgB,MAAM,CAAC;IAC3BC,IAAIV;IACJW,WAAWV,qBAAqBW,QAAQ,CAAC;IACzCC,aAAahB,iBAAiBe,QAAQ,CAAC;IACvCE,gBAAgBb,qBAAqBW,QAAQ,CAAC;IAC9CG,kBAAkBlB,iBAAiBe,QAAQ,CAAC;IAC5CI,WAAWvB,EACRwB,IAAI,CAACtB,aACLuB,OAAO,CAAC,gBACRN,QAAQ,CACP;IAEJO,kBAAkB1B,EAAEwB,IAAI,CAACvB,oBAAoBwB,OAAO,CAAC,UAAUN,QAAQ,CAAC;AAC1E;AAEA,MAAMQ,sBAAsB3B,EAAE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,MAAML,OAAO,GAAGO,OAAOF;QAChE6C,OAAO7C,KAAK,CAAC,qBAAqB;YAAE/B;YAAIC;YAAWG;YAAgB2B,OAAOL;QAAQ;QAClF,MAAM,IAAI7C,cAAcC,kBAAkByG,aAAa,EAAE,CAAC,qBAAqB,EAAE7D,SAAS,EAAE;YAC1F8D,OAAOzD,iBAAiBC,QAAQD,MAAMyD,KAAK,GAAGP;QAChD;IACF;AACF;AAEA,eAAe,SAASQ;IACtB,OAAO;QACLC,MAAM;QACNpE;QACAmD;IACF;AACF"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["/Users/kevin/Dev/open-source/ai/mcp-z/mcp-sheets/src/mcp/tools/index.ts"],"sourcesContent":["export { default as cellsFormat } from './cells-format.ts';\nexport { default as cellsMetadataGet } from './cells-metadata-get.ts';\nexport { default as chartCreate } from './chart-create.ts';\nexport { default as columnsGet } from './columns-get.ts';\nexport { default as columnsUpdate } from './columns-update.ts';\nexport { default as csvGetColumns } from './csv-get-columns.ts';\nexport { default as dimensionsBatchUpdate } from './dimensions-batch-update.ts';\nexport { default as dimensionsMove } from './dimensions-move.ts';\nexport { default as rowsAppend } from './rows-append.ts';\nexport { default as rowsCsvAppend } from './rows-csv-append.ts';\nexport { default as rowsGet } from './rows-get.ts';\nexport { default as sheetCopy } from './sheet-copy.ts';\nexport { default as sheetCopyTo } from './sheet-copy-to.ts';\nexport { default as sheetCreate } from './sheet-create.ts';\nexport { default as sheetDelete } from './sheet-delete.ts';\nexport { default as sheetFind } from './sheet-find.ts';\nexport { default as sheetRename } from './sheet-rename.ts';\nexport { default as spreadsheetCopy } from './spreadsheet-copy.ts';\nexport { default as spreadsheetCreate } from './spreadsheet-create.ts';\nexport { default as spreadsheetFind } from './spreadsheet-find.ts';\nexport { default as spreadsheetMetadataGet } from './spreadsheet-metadata-get.ts';\nexport { default as spreadsheetRename } from './spreadsheet-rename.ts';\nexport { default as validationSet } from './validation-set.ts';\nexport { default as valuesBatchUpdate } from './values-batch-update.ts';\nexport { default as valuesClear } from './values-clear.ts';\nexport { default as valuesCsvUpdate } from './values-csv-update.ts';\nexport { default as valuesMarkdownUpdate } from './values-markdown-update.ts';\nexport { default as valuesReplace } from './values-replace.ts';\nexport { default as valuesSearch } from './values-search.ts';\n"],"names":["default","cellsFormat","cellsMetadataGet","chartCreate","columnsGet","columnsUpdate","csvGetColumns","dimensionsBatchUpdate","dimensionsMove","rowsAppend","rowsCsvAppend","rowsGet","sheetCopy","sheetCopyTo","sheetCreate","sheetDelete","sheetFind","sheetRename","spreadsheetCopy","spreadsheetCreate","spreadsheetFind","spreadsheetMetadataGet","spreadsheetRename","validationSet","valuesBatchUpdate","valuesClear","valuesCsvUpdate","valuesMarkdownUpdate","valuesReplace","valuesSearch"],"mappings":"AAAA,SAASA,WAAWC,WAAW,QAAQ,oBAAoB;AAC3D,
|
|
1
|
+
{"version":3,"sources":["/Users/kevin/Dev/open-source/ai/mcp-z/mcp-sheets/src/mcp/tools/index.ts"],"sourcesContent":["export { default as cellsCopy } from './cells-copy.ts';\nexport { default as cellsFormat } from './cells-format.ts';\nexport { default as cellsMetadataGet } from './cells-metadata-get.ts';\nexport { default as chartCreate } from './chart-create.ts';\nexport { default as columnsGet } from './columns-get.ts';\nexport { default as columnsUpdate } from './columns-update.ts';\nexport { default as csvGetColumns } from './csv-get-columns.ts';\nexport { default as dimensionsBatchUpdate } from './dimensions-batch-update.ts';\nexport { default as dimensionsMove } from './dimensions-move.ts';\nexport { default as rowsAppend } from './rows-append.ts';\nexport { default as rowsCsvAppend } from './rows-csv-append.ts';\nexport { default as rowsGet } from './rows-get.ts';\nexport { default as sheetCopy } from './sheet-copy.ts';\nexport { default as sheetCopyTo } from './sheet-copy-to.ts';\nexport { default as sheetCreate } from './sheet-create.ts';\nexport { default as sheetDelete } from './sheet-delete.ts';\nexport { default as sheetFind } from './sheet-find.ts';\nexport { default as sheetRename } from './sheet-rename.ts';\nexport { default as spreadsheetCopy } from './spreadsheet-copy.ts';\nexport { default as spreadsheetCreate } from './spreadsheet-create.ts';\nexport { default as spreadsheetFind } from './spreadsheet-find.ts';\nexport { default as spreadsheetMetadataGet } from './spreadsheet-metadata-get.ts';\nexport { default as spreadsheetRename } from './spreadsheet-rename.ts';\nexport { default as validationSet } from './validation-set.ts';\nexport { default as valuesBatchUpdate } from './values-batch-update.ts';\nexport { default as valuesClear } from './values-clear.ts';\nexport { default as valuesCsvUpdate } from './values-csv-update.ts';\nexport { default as valuesMarkdownUpdate } from './values-markdown-update.ts';\nexport { default as valuesReplace } from './values-replace.ts';\nexport { default as valuesSearch } from './values-search.ts';\n"],"names":["default","cellsCopy","cellsFormat","cellsMetadataGet","chartCreate","columnsGet","columnsUpdate","csvGetColumns","dimensionsBatchUpdate","dimensionsMove","rowsAppend","rowsCsvAppend","rowsGet","sheetCopy","sheetCopyTo","sheetCreate","sheetDelete","sheetFind","sheetRename","spreadsheetCopy","spreadsheetCreate","spreadsheetFind","spreadsheetMetadataGet","spreadsheetRename","validationSet","valuesBatchUpdate","valuesClear","valuesCsvUpdate","valuesMarkdownUpdate","valuesReplace","valuesSearch"],"mappings":"AAAA,SAASA,WAAWC,SAAS,QAAQ,kBAAkB;AACvD,SAASD,WAAWE,WAAW,QAAQ,oBAAoB;AAC3D,SAASF,WAAWG,gBAAgB,QAAQ,0BAA0B;AACtE,SAASH,WAAWI,WAAW,QAAQ,oBAAoB;AAC3D,SAASJ,WAAWK,UAAU,QAAQ,mBAAmB;AACzD,SAASL,WAAWM,aAAa,QAAQ,sBAAsB;AAC/D,SAASN,WAAWO,aAAa,QAAQ,uBAAuB;AAChE,SAASP,WAAWQ,qBAAqB,QAAQ,+BAA+B;AAChF,SAASR,WAAWS,cAAc,QAAQ,uBAAuB;AACjE,SAAST,WAAWU,UAAU,QAAQ,mBAAmB;AACzD,SAASV,WAAWW,aAAa,QAAQ,uBAAuB;AAChE,SAASX,WAAWY,OAAO,QAAQ,gBAAgB;AACnD,SAASZ,WAAWa,SAAS,QAAQ,kBAAkB;AACvD,SAASb,WAAWc,WAAW,QAAQ,qBAAqB;AAC5D,SAASd,WAAWe,WAAW,QAAQ,oBAAoB;AAC3D,SAASf,WAAWgB,WAAW,QAAQ,oBAAoB;AAC3D,SAAShB,WAAWiB,SAAS,QAAQ,kBAAkB;AACvD,SAASjB,WAAWkB,WAAW,QAAQ,oBAAoB;AAC3D,SAASlB,WAAWmB,eAAe,QAAQ,wBAAwB;AACnE,SAASnB,WAAWoB,iBAAiB,QAAQ,0BAA0B;AACvE,SAASpB,WAAWqB,eAAe,QAAQ,wBAAwB;AACnE,SAASrB,WAAWsB,sBAAsB,QAAQ,gCAAgC;AAClF,SAAStB,WAAWuB,iBAAiB,QAAQ,0BAA0B;AACvE,SAASvB,WAAWwB,aAAa,QAAQ,sBAAsB;AAC/D,SAASxB,WAAWyB,iBAAiB,QAAQ,2BAA2B;AACxE,SAASzB,WAAW0B,WAAW,QAAQ,oBAAoB;AAC3D,SAAS1B,WAAW2B,eAAe,QAAQ,yBAAyB;AACpE,SAAS3B,WAAW4B,oBAAoB,QAAQ,8BAA8B;AAC9E,SAAS5B,WAAW6B,aAAa,QAAQ,sBAAsB;AAC/D,SAAS7B,WAAW8B,YAAY,QAAQ,qBAAqB"}
|
|
@@ -3,6 +3,7 @@ export declare const SpreadsheetRefSchema: z.ZodString;
|
|
|
3
3
|
export declare const SheetRefSchema: z.ZodString;
|
|
4
4
|
export declare const SpreadsheetIdSchema: z.ZodString;
|
|
5
5
|
export declare const SheetGidSchema: z.ZodCoercedString<unknown>;
|
|
6
|
+
export declare const StrictSheetGidSchema: z.ZodPipe<z.ZodUnion<readonly [z.ZodNumber, z.ZodString]>, z.ZodTransform<string, string | number>>;
|
|
6
7
|
export declare const SpreadsheetIdOutput: z.ZodString;
|
|
7
8
|
export declare const SheetGidOutput: z.ZodString;
|
|
8
9
|
export declare const SheetCellSchema: z.ZodUnion<readonly [z.ZodString, z.ZodNumber, z.ZodLiteral<number>, z.ZodLiteral<number>, z.ZodBoolean, z.ZodNull]>;
|
|
@@ -11,6 +11,15 @@ const SHEET_ID_DESC = 'Sheet ID (from URL gid={gid})';
|
|
|
11
11
|
// is the default sheet ID in new spreadsheets.
|
|
12
12
|
export const SpreadsheetIdSchema = z.string().min(1).describe(SPREADSHEET_ID_DESC);
|
|
13
13
|
export const SheetGidSchema = z.coerce.string().min(1).describe(SHEET_ID_DESC);
|
|
14
|
+
// Strict sheet ID: a non-negative integer number or a string of digits (gid 0 and "0" both work).
|
|
15
|
+
// Unlike SheetGidSchema it does not coerce, so null, undefined, booleans, negatives, decimals and
|
|
16
|
+
// non-digit strings are rejected instead of becoming "null", "undefined", "true", etc.
|
|
17
|
+
// Sheet IDs are int32, so values above 2147483647 are rejected (keeps Number(gid) exact).
|
|
18
|
+
const MAX_SHEET_GID = 2147483647;
|
|
19
|
+
export const StrictSheetGidSchema = z.union([
|
|
20
|
+
z.number().int().nonnegative().max(MAX_SHEET_GID),
|
|
21
|
+
z.string().regex(/^\d+$/, 'Sheet ID must be a non-negative integer').refine((value)=>Number(value) <= MAX_SHEET_GID, `Sheet ID must be at most ${MAX_SHEET_GID}`)
|
|
22
|
+
]).transform((value)=>String(typeof value === 'number' ? value : Number(value))).describe(SHEET_ID_DESC);
|
|
14
23
|
// Output schemas (for use in output/response schemas)
|
|
15
24
|
export const SpreadsheetIdOutput = z.string().describe(SPREADSHEET_ID_DESC);
|
|
16
25
|
export const SheetGidOutput = z.string().describe(SHEET_ID_DESC);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["/Users/kevin/Dev/open-source/ai/mcp-z/mcp-sheets/src/schemas/index.ts"],"sourcesContent":["import { z } from 'zod';\n\n// Spreadsheet and sheet reference schemas\nexport const SpreadsheetRefSchema = z.string().min(1).describe('Spreadsheet reference: full URL, exact name, or partial name (not ID - use spreadsheet-find to get ID)');\n\nexport const SheetRefSchema = z.string().min(1).describe('Sheet reference: exact title or partial name match (not ID - use sheet-find to get ID)');\n\n// Shared descriptions for consistency\nconst SPREADSHEET_ID_DESC = 'Spreadsheet ID (from URL d/{id})';\nconst SHEET_ID_DESC = 'Sheet ID (from URL gid={gid})';\n\n// Input schemas (with validation)\n// Note: z.coerce.string() converts numbers to strings, handling cases where MCP clients\n// pass gid: 0 (number) instead of gid: \"0\" (string). This is critical for gid=0 which\n// is the default sheet ID in new spreadsheets.\nexport const SpreadsheetIdSchema = z.string().min(1).describe(SPREADSHEET_ID_DESC);\nexport const SheetGidSchema = z.coerce.string().min(1).describe(SHEET_ID_DESC);\n\n// Output schemas (for use in output/response schemas)\nexport const SpreadsheetIdOutput = z.string().describe(SPREADSHEET_ID_DESC);\nexport const SheetGidOutput = z.string().describe(SHEET_ID_DESC);\n\n// Schema for individual sheet cells (can be string, number, boolean, or null)\n// null represents empty cells - JSON cannot represent undefined, and Google API uses null for empty cells\n// Infinity values are allowed as Google Sheets can contain them, but NaN is still rejected\nexport const SheetCellSchema = z.union([z.string(), z.number(), z.literal(Infinity), z.literal(-Infinity), z.boolean(), z.null()]);\n\n// Schema for a row in a sheet search result\nexport const SheetRowSchema = z.object({\n rowIndex: z.number().int().positive().describe('1-based row number in the sheet'),\n values: z.array(SheetCellSchema).optional().describe('Cell values for this row (included when includeData=true)'),\n range: z.string().optional().describe('A1 notation range for this row (e.g., A5:D5)'),\n});\n\n// A1 notation validation - simplified for zod compatibility\nexport const A1NotationSchema = z.string().min(1).describe('A1 notation for cell range (e.g., A1, A1:B2, A:B, 1:2)');\n"],"names":["z","SpreadsheetRefSchema","string","min","describe","SheetRefSchema","SPREADSHEET_ID_DESC","SHEET_ID_DESC","SpreadsheetIdSchema","SheetGidSchema","coerce","
|
|
1
|
+
{"version":3,"sources":["/Users/kevin/Dev/open-source/ai/mcp-z/mcp-sheets/src/schemas/index.ts"],"sourcesContent":["import { z } from 'zod';\n\n// Spreadsheet and sheet reference schemas\nexport const SpreadsheetRefSchema = z.string().min(1).describe('Spreadsheet reference: full URL, exact name, or partial name (not ID - use spreadsheet-find to get ID)');\n\nexport const SheetRefSchema = z.string().min(1).describe('Sheet reference: exact title or partial name match (not ID - use sheet-find to get ID)');\n\n// Shared descriptions for consistency\nconst SPREADSHEET_ID_DESC = 'Spreadsheet ID (from URL d/{id})';\nconst SHEET_ID_DESC = 'Sheet ID (from URL gid={gid})';\n\n// Input schemas (with validation)\n// Note: z.coerce.string() converts numbers to strings, handling cases where MCP clients\n// pass gid: 0 (number) instead of gid: \"0\" (string). This is critical for gid=0 which\n// is the default sheet ID in new spreadsheets.\nexport const SpreadsheetIdSchema = z.string().min(1).describe(SPREADSHEET_ID_DESC);\nexport const SheetGidSchema = z.coerce.string().min(1).describe(SHEET_ID_DESC);\n\n// Strict sheet ID: a non-negative integer number or a string of digits (gid 0 and \"0\" both work).\n// Unlike SheetGidSchema it does not coerce, so null, undefined, booleans, negatives, decimals and\n// non-digit strings are rejected instead of becoming \"null\", \"undefined\", \"true\", etc.\n// Sheet IDs are int32, so values above 2147483647 are rejected (keeps Number(gid) exact).\nconst MAX_SHEET_GID = 2147483647;\nexport const StrictSheetGidSchema = z\n .union([\n z.number().int().nonnegative().max(MAX_SHEET_GID),\n z\n .string()\n .regex(/^\\d+$/, 'Sheet ID must be a non-negative integer')\n .refine((value) => Number(value) <= MAX_SHEET_GID, `Sheet ID must be at most ${MAX_SHEET_GID}`),\n ])\n .transform((value) => String(typeof value === 'number' ? value : Number(value)))\n .describe(SHEET_ID_DESC);\n\n// Output schemas (for use in output/response schemas)\nexport const SpreadsheetIdOutput = z.string().describe(SPREADSHEET_ID_DESC);\nexport const SheetGidOutput = z.string().describe(SHEET_ID_DESC);\n\n// Schema for individual sheet cells (can be string, number, boolean, or null)\n// null represents empty cells - JSON cannot represent undefined, and Google API uses null for empty cells\n// Infinity values are allowed as Google Sheets can contain them, but NaN is still rejected\nexport const SheetCellSchema = z.union([z.string(), z.number(), z.literal(Infinity), z.literal(-Infinity), z.boolean(), z.null()]);\n\n// Schema for a row in a sheet search result\nexport const SheetRowSchema = z.object({\n rowIndex: z.number().int().positive().describe('1-based row number in the sheet'),\n values: z.array(SheetCellSchema).optional().describe('Cell values for this row (included when includeData=true)'),\n range: z.string().optional().describe('A1 notation range for this row (e.g., A5:D5)'),\n});\n\n// A1 notation validation - simplified for zod compatibility\nexport const A1NotationSchema = z.string().min(1).describe('A1 notation for cell range (e.g., A1, A1:B2, A:B, 1:2)');\n"],"names":["z","SpreadsheetRefSchema","string","min","describe","SheetRefSchema","SPREADSHEET_ID_DESC","SHEET_ID_DESC","SpreadsheetIdSchema","SheetGidSchema","coerce","MAX_SHEET_GID","StrictSheetGidSchema","union","number","int","nonnegative","max","regex","refine","value","Number","transform","String","SpreadsheetIdOutput","SheetGidOutput","SheetCellSchema","literal","Infinity","boolean","null","SheetRowSchema","object","rowIndex","positive","values","array","optional","range","A1NotationSchema"],"mappings":"AAAA,SAASA,CAAC,QAAQ,MAAM;AAExB,0CAA0C;AAC1C,OAAO,MAAMC,uBAAuBD,EAAEE,MAAM,GAAGC,GAAG,CAAC,GAAGC,QAAQ,CAAC,0GAA0G;AAEzK,OAAO,MAAMC,iBAAiBL,EAAEE,MAAM,GAAGC,GAAG,CAAC,GAAGC,QAAQ,CAAC,0FAA0F;AAEnJ,sCAAsC;AACtC,MAAME,sBAAsB;AAC5B,MAAMC,gBAAgB;AAEtB,kCAAkC;AAClC,wFAAwF;AACxF,sFAAsF;AACtF,+CAA+C;AAC/C,OAAO,MAAMC,sBAAsBR,EAAEE,MAAM,GAAGC,GAAG,CAAC,GAAGC,QAAQ,CAACE,qBAAqB;AACnF,OAAO,MAAMG,iBAAiBT,EAAEU,MAAM,CAACR,MAAM,GAAGC,GAAG,CAAC,GAAGC,QAAQ,CAACG,eAAe;AAE/E,kGAAkG;AAClG,kGAAkG;AAClG,uFAAuF;AACvF,0FAA0F;AAC1F,MAAMI,gBAAgB;AACtB,OAAO,MAAMC,uBAAuBZ,EACjCa,KAAK,CAAC;IACLb,EAAEc,MAAM,GAAGC,GAAG,GAAGC,WAAW,GAAGC,GAAG,CAACN;IACnCX,EACGE,MAAM,GACNgB,KAAK,CAAC,SAAS,2CACfC,MAAM,CAAC,CAACC,QAAUC,OAAOD,UAAUT,eAAe,CAAC,yBAAyB,EAAEA,eAAe;CACjG,EACAW,SAAS,CAAC,CAACF,QAAUG,OAAO,OAAOH,UAAU,WAAWA,QAAQC,OAAOD,SACvEhB,QAAQ,CAACG,eAAe;AAE3B,sDAAsD;AACtD,OAAO,MAAMiB,sBAAsBxB,EAAEE,MAAM,GAAGE,QAAQ,CAACE,qBAAqB;AAC5E,OAAO,MAAMmB,iBAAiBzB,EAAEE,MAAM,GAAGE,QAAQ,CAACG,eAAe;AAEjE,8EAA8E;AAC9E,0GAA0G;AAC1G,2FAA2F;AAC3F,OAAO,MAAMmB,kBAAkB1B,EAAEa,KAAK,CAAC;IAACb,EAAEE,MAAM;IAAIF,EAAEc,MAAM;IAAId,EAAE2B,OAAO,CAACC;IAAW5B,EAAE2B,OAAO,CAAC,CAACC;IAAW5B,EAAE6B,OAAO;IAAI7B,EAAE8B,IAAI;CAAG,EAAE;AAEnI,4CAA4C;AAC5C,OAAO,MAAMC,iBAAiB/B,EAAEgC,MAAM,CAAC;IACrCC,UAAUjC,EAAEc,MAAM,GAAGC,GAAG,GAAGmB,QAAQ,GAAG9B,QAAQ,CAAC;IAC/C+B,QAAQnC,EAAEoC,KAAK,CAACV,iBAAiBW,QAAQ,GAAGjC,QAAQ,CAAC;IACrDkC,OAAOtC,EAAEE,MAAM,GAAGmC,QAAQ,GAAGjC,QAAQ,CAAC;AACxC,GAAG;AAEH,4DAA4D;AAC5D,OAAO,MAAMmC,mBAAmBvC,EAAEE,MAAM,GAAGC,GAAG,CAAC,GAAGC,QAAQ,CAAC,0DAA0D"}
|
package/dist/esm/setup/config.js
CHANGED
|
@@ -6,6 +6,7 @@ import { parseArgs } from 'util';
|
|
|
6
6
|
import { GOOGLE_SCOPE } from '../constants.js';
|
|
7
7
|
import { readPkg } from './version-help.js';
|
|
8
8
|
const pkg = readPkg();
|
|
9
|
+
const SERVER_NAME = pkg.name.replace(/^@[^/]+\//, '');
|
|
9
10
|
// @mcp-z/oauth-google and @mcp-z/server are requireable at the >=20 floor; deferred so
|
|
10
11
|
// --version/--help (handled via version-help.ts, never this file) load neither package.
|
|
11
12
|
const _require = typeof require === 'undefined' ? Module.createRequire(import.meta.url) : require;
|
|
@@ -67,22 +68,11 @@ const _require = typeof require === 'undefined' ? Module.createRequire(import.me
|
|
|
67
68
|
strict: false,
|
|
68
69
|
allowPositionals: true
|
|
69
70
|
});
|
|
70
|
-
const name =
|
|
71
|
+
const name = SERVER_NAME;
|
|
71
72
|
// Parse repository URL from package.json, stripping git+ prefix and .git suffix
|
|
72
73
|
const rawRepoUrl = typeof pkg.repository === 'object' ? pkg.repository.url : pkg.repository;
|
|
73
74
|
const repositoryUrl = (_ref = rawRepoUrl === null || rawRepoUrl === void 0 ? void 0 : rawRepoUrl.replace(/^git\+/, '').replace(/\.git$/, '')) !== null && _ref !== void 0 ? _ref : `https://github.com/mcp-z/${name}`;
|
|
74
|
-
|
|
75
|
-
try {
|
|
76
|
-
const configPath = mcpServer.findConfigPath({
|
|
77
|
-
config: '.mcp.json',
|
|
78
|
-
cwd: process.cwd(),
|
|
79
|
-
stopDir: homedir()
|
|
80
|
-
});
|
|
81
|
-
rootDir = path.dirname(configPath);
|
|
82
|
-
} catch {
|
|
83
|
-
rootDir = homedir();
|
|
84
|
-
}
|
|
85
|
-
const baseDir = path.join(rootDir, '.mcp-z');
|
|
75
|
+
const baseDir = resolveBaseDir();
|
|
86
76
|
const cliLogLevel = typeof values['log-level'] === 'string' ? values['log-level'] : undefined;
|
|
87
77
|
const envLogLevel = env.LOG_LEVEL;
|
|
88
78
|
const logLevel = (_ref1 = cliLogLevel !== null && cliLogLevel !== void 0 ? cliLogLevel : envLogLevel) !== null && _ref1 !== void 0 ? _ref1 : 'info';
|
|
@@ -123,9 +113,31 @@ function normalizeResourceStoreUri(resourceStoreUri) {
|
|
|
123
113
|
const expandedPath = resourceStoreUri.startsWith('~') ? resourceStoreUri.replace(/^~/, homedir()) : resourceStoreUri;
|
|
124
114
|
return pathToFileURL(path.resolve(expandedPath)).href;
|
|
125
115
|
}
|
|
116
|
+
/** The server's data directory: `.mcp-z` beside the nearest .mcp.json (searched from cwd up to home), else in the home directory. */ function resolveBaseDir() {
|
|
117
|
+
const mcpServer = _require('@mcp-z/server');
|
|
118
|
+
try {
|
|
119
|
+
const configPath = mcpServer.findConfigPath({
|
|
120
|
+
config: '.mcp.json',
|
|
121
|
+
cwd: process.cwd(),
|
|
122
|
+
stopDir: homedir()
|
|
123
|
+
});
|
|
124
|
+
return path.join(path.dirname(configPath), '.mcp-z');
|
|
125
|
+
} catch {
|
|
126
|
+
return path.join(homedir(), '.mcp-z');
|
|
127
|
+
}
|
|
128
|
+
}
|
|
126
129
|
/**
|
|
127
130
|
* Build production configuration from process globals.
|
|
128
131
|
* Entry point for production server.
|
|
129
132
|
*/ export function createConfig() {
|
|
130
|
-
|
|
133
|
+
const mcpServer = _require('@mcp-z/server');
|
|
134
|
+
const envResult = mcpServer.loadServerEnv({
|
|
135
|
+
name: SERVER_NAME,
|
|
136
|
+
baseDir: resolveBaseDir()
|
|
137
|
+
});
|
|
138
|
+
try {
|
|
139
|
+
return parseConfig(process.argv, process.env);
|
|
140
|
+
} catch (error) {
|
|
141
|
+
throw new Error(`${error.message}\n${mcpServer.formatServerEnvSearch(envResult)}`);
|
|
142
|
+
}
|
|
131
143
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["/Users/kevin/Dev/open-source/ai/mcp-z/mcp-sheets/src/setup/config.ts"],"sourcesContent":["import { fileURLToPath, pathToFileURL } from 'node:url';\nimport type * as OAuthGoogle from '@mcp-z/oauth-google';\nimport type * as McpServer from '@mcp-z/server';\nimport { Module } from 'module';\nimport { homedir } from 'os';\nimport * as path from 'path';\nimport { parseArgs } from 'util';\nimport { GOOGLE_SCOPE } from '../constants.ts';\nimport type { ServerConfig } from '../types.ts';\nimport { readPkg } from './version-help.ts';\n\nconst pkg = readPkg();\n\n// @mcp-z/oauth-google and @mcp-z/server are requireable at the >=20 floor; deferred so\n// --version/--help (handled via version-help.ts, never this file) load neither package.\nconst _require = typeof require === 'undefined' ? Module.createRequire(import.meta.url) : require;\n\n/**\n * Parse Sheets server configuration from CLI arguments and environment.\n *\n * CLI Arguments (all optional):\n * - --auth=<mode> Authentication mode (default: loopback-oauth)\n * Modes: loopback-oauth, service-account, dcr\n * - --headless Disable browser auto-open, return auth URL instead\n * - --redirect-uri=<uri> OAuth redirect URI (default: ephemeral loopback)\n * - --dcr-mode=<mode> DCR mode (self-hosted or external, default: self-hosted)\n * - --dcr-verify-url=<url> External verification endpoint (required for external mode)\n * - --dcr-store-uri=<uri> DCR client storage URI (required for self-hosted mode)\n * - --port=<port> Enable HTTP transport on specified port\n * - --stdio Enable stdio transport (default if no port)\n * - --log-level=<level> Logging level (default: info)\n * - --resource-store-uri=<uri> Resource store URI for CSV file storage (default: file://~/.mcp-z/mcp-sheets/files)\n * - --base-url=<url> Base URL for HTTP file serving (optional)\n *\n * Environment Variables:\n * - GOOGLE_CLIENT_ID OAuth client ID (REQUIRED)\n * - GOOGLE_CLIENT_SECRET OAuth client secret (optional)\n * - AUTH_MODE Default authentication mode (optional)\n * - HEADLESS Disable browser auto-open (optional)\n * - DCR_MODE DCR mode (optional, same format as --dcr-mode)\n * - DCR_VERIFY_URL External verification URL (optional, same as --dcr-verify-url)\n * - DCR_STORE_URI DCR storage URI (optional, same as --dcr-store-uri)\n * - TOKEN_STORE_URI Token storage URI (optional)\n * - PORT Default HTTP port (optional)\n * - LOG_LEVEL Default logging level (optional)\n * - RESOURCE_STORE_URI Resource store URI (optional, file://)\n * - BASE_URL Base URL for HTTP file serving (optional)\n *\n * OAuth Scopes (from constants.ts):\n * 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 */\nexport function parseConfig(args: string[], env: Record<string, string | undefined>): ServerConfig {\n const oauthGoogle = _require('@mcp-z/oauth-google') as typeof OAuthGoogle;\n const mcpServer = _require('@mcp-z/server') as typeof McpServer;\n\n const transportConfig = mcpServer.parseConfig(args, env);\n const oauthConfig = oauthGoogle.parseConfig(args, env);\n\n // Parse DCR configuration if DCR mode is enabled\n const dcrConfig = oauthConfig.auth === 'dcr' ? oauthGoogle.parseDcrConfig(args, env, GOOGLE_SCOPE) : undefined;\n\n // Parse application-level config (LOG_LEVEL, RESOURCE_STORE_URI, BASE_URL)\n const { values } = parseArgs({\n args,\n options: {\n 'log-level': { type: 'string' },\n 'base-url': { type: 'string' },\n 'resource-store-uri': { type: 'string' },\n },\n strict: false, // Allow other arguments\n allowPositionals: true,\n });\n\n const name = pkg.name.replace(/^@[^/]+\\//, '');\n // Parse repository URL from package.json, stripping git+ prefix and .git suffix\n const rawRepoUrl = typeof pkg.repository === 'object' ? pkg.repository.url : pkg.repository;\n const repositoryUrl = rawRepoUrl?.replace(/^git\\+/, '').replace(/\\.git$/, '') ?? `https://github.com/mcp-z/${name}`;\n let rootDir = homedir();\n try {\n const configPath = mcpServer.findConfigPath({ config: '.mcp.json', cwd: process.cwd(), stopDir: homedir() });\n rootDir = path.dirname(configPath);\n } catch {\n rootDir = homedir();\n }\n const baseDir = path.join(rootDir, '.mcp-z');\n const cliLogLevel = typeof values['log-level'] === 'string' ? values['log-level'] : undefined;\n const envLogLevel = env.LOG_LEVEL;\n const logLevel = cliLogLevel ?? envLogLevel ?? 'info';\n\n // Parse storage configuration\n const cliResourceStoreUri = typeof values['resource-store-uri'] === 'string' ? values['resource-store-uri'] : undefined;\n const envResourceStoreUri = env.RESOURCE_STORE_URI;\n const defaultResourceStorePath = path.join(baseDir, name, 'files');\n const resourceStoreUri = normalizeResourceStoreUri(cliResourceStoreUri ?? envResourceStoreUri ?? defaultResourceStorePath);\n\n const cliBaseUrl = typeof values['base-url'] === 'string' ? values['base-url'] : undefined;\n const envBaseUrl = env.BASE_URL;\n const baseUrl = cliBaseUrl ?? envBaseUrl;\n\n // Combine configs\n return {\n ...oauthConfig, // Includes clientId, auth, headless, redirectUri\n transport: transportConfig.transport,\n logLevel,\n baseDir,\n name,\n version: pkg.version,\n repositoryUrl,\n resourceStoreUri,\n ...(baseUrl && { baseUrl }),\n ...(dcrConfig && { dcrConfig }),\n };\n}\n\nfunction normalizeResourceStoreUri(resourceStoreUri: string): string {\n const filePrefix = 'file://';\n if (resourceStoreUri.startsWith(filePrefix)) {\n const rawPath = resourceStoreUri.slice(filePrefix.length);\n const filePath = rawPath.startsWith('~') ? rawPath.replace(/^~/, homedir()) : rawPath.startsWith('/') ? fileURLToPath(resourceStoreUri) : rawPath;\n return pathToFileURL(path.resolve(filePath)).href;\n }\n\n if (resourceStoreUri.includes('://')) return resourceStoreUri;\n\n const expandedPath = resourceStoreUri.startsWith('~') ? resourceStoreUri.replace(/^~/, homedir()) : resourceStoreUri;\n return pathToFileURL(path.resolve(expandedPath)).href;\n}\n\n/**\n * Build production configuration from process globals.\n * Entry point for production server.\n */\nexport function createConfig(): ServerConfig {\n return parseConfig(process.argv, process.env);\n}\n"],"names":["fileURLToPath","pathToFileURL","Module","homedir","path","parseArgs","GOOGLE_SCOPE","readPkg","pkg","_require","require","createRequire","url","parseConfig","args","env","cliLogLevel","cliResourceStoreUri","oauthGoogle","mcpServer","transportConfig","oauthConfig","dcrConfig","auth","parseDcrConfig","undefined","values","options","type","strict","allowPositionals","name","replace","rawRepoUrl","repository","repositoryUrl","rootDir","configPath","findConfigPath","config","cwd","process","stopDir","dirname","baseDir","join","envLogLevel","LOG_LEVEL","logLevel","envResourceStoreUri","RESOURCE_STORE_URI","defaultResourceStorePath","resourceStoreUri","normalizeResourceStoreUri","cliBaseUrl","envBaseUrl","BASE_URL","baseUrl","transport","version","filePrefix","startsWith","rawPath","slice","length","filePath","resolve","href","includes","expandedPath","createConfig","argv"],"mappings":"AAA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wB;IACzD,MAAMQ,aAAa;IACnB,IAAIR,iBAAiBS,UAAU,CAACD,aAAa;QAC3C,MAAME,UAAUV,iBAAiBW,KAAK,CAACH,WAAWI,MAAM;QACxD,MAAMC,WAAWH,QAAQD,UAAU,CAAC,OAAOC,QAAQ9B,OAAO,CAAC,MAAM7B,aAAa2D,QAAQD,UAAU,CAAC,OAAO7D,cAAcoD,oBAAoBU;QAC1I,OAAO7D,cAAcG,KAAK8D,OAAO,CAACD,WAAWE,IAAI;IACnD;IAEA,IAAIf,iBAAiBgB,QAAQ,CAAC,QAAQ,OAAOhB;IAE7C,MAAMiB,eAAejB,iBAAiBS,UAAU,CAAC,OAAOT,iBAAiBpB,OAAO,CAAC,MAAM7B,aAAaiD;IACpG,OAAOnD,cAAcG,KAAK8D,OAAO,CAACG,eAAeF,IAAI;AACvD;AAEA;;;CAGC,GACD,OAAO,SAASG;IACd,OAAOzD,YAAY4B,QAAQ8B,IAAI,EAAE9B,QAAQ1B,GAAG;AAC9C"}
|
|
1
|
+
{"version":3,"sources":["/Users/kevin/Dev/open-source/ai/mcp-z/mcp-sheets/src/setup/config.ts"],"sourcesContent":["import { fileURLToPath, pathToFileURL } from 'node:url';\nimport type * as OAuthGoogle from '@mcp-z/oauth-google';\nimport type * as McpServer from '@mcp-z/server';\nimport { Module } from 'module';\nimport { homedir } from 'os';\nimport * as path from 'path';\nimport { parseArgs } from 'util';\nimport { GOOGLE_SCOPE } from '../constants.ts';\nimport type { ServerConfig } from '../types.ts';\nimport { readPkg } from './version-help.ts';\n\nconst pkg = readPkg();\nconst SERVER_NAME = pkg.name.replace(/^@[^/]+\\//, '');\n\n// @mcp-z/oauth-google and @mcp-z/server are requireable at the >=20 floor; deferred so\n// --version/--help (handled via version-help.ts, never this file) load neither package.\nconst _require = typeof require === 'undefined' ? Module.createRequire(import.meta.url) : require;\n\n/**\n * Parse Sheets server configuration from CLI arguments and environment.\n *\n * CLI Arguments (all optional):\n * - --auth=<mode> Authentication mode (default: loopback-oauth)\n * Modes: loopback-oauth, service-account, dcr\n * - --headless Disable browser auto-open, return auth URL instead\n * - --redirect-uri=<uri> OAuth redirect URI (default: ephemeral loopback)\n * - --dcr-mode=<mode> DCR mode (self-hosted or external, default: self-hosted)\n * - --dcr-verify-url=<url> External verification endpoint (required for external mode)\n * - --dcr-store-uri=<uri> DCR client storage URI (required for self-hosted mode)\n * - --port=<port> Enable HTTP transport on specified port\n * - --stdio Enable stdio transport (default if no port)\n * - --log-level=<level> Logging level (default: info)\n * - --resource-store-uri=<uri> Resource store URI for CSV file storage (default: file://~/.mcp-z/mcp-sheets/files)\n * - --base-url=<url> Base URL for HTTP file serving (optional)\n *\n * Environment Variables:\n * - GOOGLE_CLIENT_ID OAuth client ID (REQUIRED)\n * - GOOGLE_CLIENT_SECRET OAuth client secret (optional)\n * - AUTH_MODE Default authentication mode (optional)\n * - HEADLESS Disable browser auto-open (optional)\n * - DCR_MODE DCR mode (optional, same format as --dcr-mode)\n * - DCR_VERIFY_URL External verification URL (optional, same as --dcr-verify-url)\n * - DCR_STORE_URI DCR storage URI (optional, same as --dcr-store-uri)\n * - TOKEN_STORE_URI Token storage URI (optional)\n * - PORT Default HTTP port (optional)\n * - LOG_LEVEL Default logging level (optional)\n * - RESOURCE_STORE_URI Resource store URI (optional, file://)\n * - BASE_URL Base URL for HTTP file serving (optional)\n *\n * OAuth Scopes (from constants.ts):\n * 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 */\nexport function parseConfig(args: string[], env: Record<string, string | undefined>): ServerConfig {\n const oauthGoogle = _require('@mcp-z/oauth-google') as typeof OAuthGoogle;\n const mcpServer = _require('@mcp-z/server') as typeof McpServer;\n\n const transportConfig = mcpServer.parseConfig(args, env);\n const oauthConfig = oauthGoogle.parseConfig(args, env);\n\n // Parse DCR configuration if DCR mode is enabled\n const dcrConfig = oauthConfig.auth === 'dcr' ? oauthGoogle.parseDcrConfig(args, env, GOOGLE_SCOPE) : undefined;\n\n // Parse application-level config (LOG_LEVEL, RESOURCE_STORE_URI, BASE_URL)\n const { values } = parseArgs({\n args,\n options: {\n 'log-level': { type: 'string' },\n 'base-url': { type: 'string' },\n 'resource-store-uri': { type: 'string' },\n },\n strict: false, // Allow other arguments\n allowPositionals: true,\n });\n\n const name = SERVER_NAME;\n // Parse repository URL from package.json, stripping git+ prefix and .git suffix\n const rawRepoUrl = typeof pkg.repository === 'object' ? pkg.repository.url : pkg.repository;\n const repositoryUrl = rawRepoUrl?.replace(/^git\\+/, '').replace(/\\.git$/, '') ?? `https://github.com/mcp-z/${name}`;\n const baseDir = resolveBaseDir();\n const cliLogLevel = typeof values['log-level'] === 'string' ? values['log-level'] : undefined;\n const envLogLevel = env.LOG_LEVEL;\n const logLevel = cliLogLevel ?? envLogLevel ?? 'info';\n\n // Parse storage configuration\n const cliResourceStoreUri = typeof values['resource-store-uri'] === 'string' ? values['resource-store-uri'] : undefined;\n const envResourceStoreUri = env.RESOURCE_STORE_URI;\n const defaultResourceStorePath = path.join(baseDir, name, 'files');\n const resourceStoreUri = normalizeResourceStoreUri(cliResourceStoreUri ?? envResourceStoreUri ?? defaultResourceStorePath);\n\n const cliBaseUrl = typeof values['base-url'] === 'string' ? values['base-url'] : undefined;\n const envBaseUrl = env.BASE_URL;\n const baseUrl = cliBaseUrl ?? envBaseUrl;\n\n // Combine configs\n return {\n ...oauthConfig, // Includes clientId, auth, headless, redirectUri\n transport: transportConfig.transport,\n logLevel,\n baseDir,\n name,\n version: pkg.version,\n repositoryUrl,\n resourceStoreUri,\n ...(baseUrl && { baseUrl }),\n ...(dcrConfig && { dcrConfig }),\n };\n}\n\nfunction normalizeResourceStoreUri(resourceStoreUri: string): string {\n const filePrefix = 'file://';\n if (resourceStoreUri.startsWith(filePrefix)) {\n const rawPath = resourceStoreUri.slice(filePrefix.length);\n const filePath = rawPath.startsWith('~') ? rawPath.replace(/^~/, homedir()) : rawPath.startsWith('/') ? fileURLToPath(resourceStoreUri) : rawPath;\n return pathToFileURL(path.resolve(filePath)).href;\n }\n\n if (resourceStoreUri.includes('://')) return resourceStoreUri;\n\n const expandedPath = resourceStoreUri.startsWith('~') ? resourceStoreUri.replace(/^~/, homedir()) : resourceStoreUri;\n return pathToFileURL(path.resolve(expandedPath)).href;\n}\n\n/** The server's data directory: `.mcp-z` beside the nearest .mcp.json (searched from cwd up to home), else in the home directory. */\nfunction resolveBaseDir(): string {\n const mcpServer = _require('@mcp-z/server') as typeof McpServer;\n try {\n const configPath = mcpServer.findConfigPath({ config: '.mcp.json', cwd: process.cwd(), stopDir: homedir() });\n return path.join(path.dirname(configPath), '.mcp-z');\n } catch {\n return path.join(homedir(), '.mcp-z');\n }\n}\n\n/**\n * Build production configuration from process globals.\n * Entry point for production server.\n */\nexport function createConfig(): ServerConfig {\n const mcpServer = _require('@mcp-z/server') as typeof McpServer;\n const envResult = mcpServer.loadServerEnv({ name: SERVER_NAME, baseDir: resolveBaseDir() });\n try {\n return parseConfig(process.argv, process.env);\n } catch (error) {\n throw new Error(`${(error as Error).message}\\n${mcpServer.formatServerEnvSearch(envResult)}`);\n }\n}\n"],"names":["fileURLToPath","pathToFileURL","Module","homedir","path","parseArgs","GOOGLE_SCOPE","readPkg","pkg","SERVER_NAME","name","replace","_require","require","createRequire","url","parseConfig","args","env","cliLogLevel","cliResourceStoreUri","oauthGoogle","mcpServer","transportConfig","oauthConfig","dcrConfig","auth","parseDcrConfig","undefined","values","options","type","strict","allowPositionals","rawRepoUrl","repository","repositoryUrl","baseDir","resolveBaseDir","envLogLevel","LOG_LEVEL","logLevel","envResourceStoreUri","RESOURCE_STORE_URI","defaultResourceStorePath","join","resourceStoreUri","normalizeResourceStoreUri","cliBaseUrl","envBaseUrl","BASE_URL","baseUrl","transport","version","filePrefix","startsWith","rawPath","slice","length","filePath","resolve","href","includes","expandedPath","configPath","findConfigPath","config","cwd","process","stopDir","dirname","createConfig","envResult","loadServerEnv","argv","error","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AC,MAAMR,aAAaqD,QAAQD,UAAU,CAAC,OAAOvD,cAAc8C,oBAAoBU;QAC1I,OAAOvD,cAAcG,KAAKwD,OAAO,CAACD,WAAWE,IAAI;IACnD;IAEA,IAAIf,iBAAiBgB,QAAQ,CAAC,QAAQ,OAAOhB;IAE7C,MAAMiB,eAAejB,iBAAiBS,UAAU,CAAC,OAAOT,iBAAiBnC,OAAO,CAAC,MAAMR,aAAa2C;IACpG,OAAO7C,cAAcG,KAAKwD,OAAO,CAACG,eAAeF,IAAI;AACvD;AAEA,mIAAmI,GACnI,SAASvB;IACP,MAAMhB,YAAYV,SAAS;IAC3B,IAAI;QACF,MAAMoD,aAAa1C,UAAU2C,cAAc,CAAC;YAAEC,QAAQ;YAAaC,KAAKC,QAAQD,GAAG;YAAIE,SAASlE;QAAU;QAC1G,OAAOC,KAAKyC,IAAI,CAACzC,KAAKkE,OAAO,CAACN,aAAa;IAC7C,EAAE,OAAM;QACN,OAAO5D,KAAKyC,IAAI,CAAC1C,WAAW;IAC9B;AACF;AAEA;;;CAGC,GACD,OAAO,SAASoE;IACd,MAAMjD,YAAYV,SAAS;IAC3B,MAAM4D,YAAYlD,UAAUmD,aAAa,CAAC;QAAE/D,MAAMD;QAAa4B,SAASC;IAAiB;IACzF,IAAI;QACF,OAAOtB,YAAYoD,QAAQM,IAAI,EAAEN,QAAQlD,GAAG;IAC9C,EAAE,OAAOyD,OAAO;QACd,MAAM,IAAIC,MAAM,GAAG,AAACD,MAAgBE,OAAO,CAAC,EAAE,EAAEvD,UAAUwD,qBAAqB,CAACN,YAAY;IAC9F;AACF"}
|
|
@@ -42,6 +42,13 @@ Environment Variables:
|
|
|
42
42
|
RESOURCE_STORE_URI Resource store URI (optional, file://)
|
|
43
43
|
BASE_URL Base URL for HTTP file serving (optional)
|
|
44
44
|
|
|
45
|
+
Configuration Files:
|
|
46
|
+
Variables may also be set in the first of these files that exists:
|
|
47
|
+
1. .mcp-z/mcp-sheets/.env beside the nearest .mcp.json (else ~/.mcp-z/mcp-sheets/.env)
|
|
48
|
+
2. ~/.config/mcp-z/mcp-sheets/.env (~ is your home directory, on every OS)
|
|
49
|
+
Values already in the environment, including .mcp.json "env", take precedence.
|
|
50
|
+
On macOS and Linux the file must be private (chmod 600), or the server will not start.
|
|
51
|
+
|
|
45
52
|
Storage Backends:
|
|
46
53
|
TOKEN_STORE_URI and DCR_STORE_URI accept any keyv-registry protocol.
|
|
47
54
|
file:// (the default) and memory:// work out of the box. Any other backend
|