sheets_create_spreadsheet
Create a new Google Sheets spreadsheet with customizable titles, sheet configurations, and predefined rows and columns through the mcp-gsheets server.
Instructions
Create a new Google Sheets spreadsheet
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| sheets | No | Array of sheets to create in the spreadsheet | |
| title | Yes | The title of the new spreadsheet |
Implementation Reference
- src/tools/create-spreadsheet.ts:43-74 (handler)The main handler function that executes the tool logic: validates input, gets authenticated Sheets client, builds request body with title and optional sheets config, creates the spreadsheet via API, formats and returns response, handles errors.export async function handleCreateSpreadsheet(input: any) { try { const validatedInput = validateCreateSpreadsheetInput(input); const sheets = await getAuthenticatedClient(); const requestBody: any = { properties: { title: validatedInput.title, }, }; if (validatedInput.sheets && validatedInput.sheets.length > 0) { requestBody.sheets = validatedInput.sheets.map((sheet, index) => ({ properties: { title: sheet.title || `Sheet${index + 1}`, gridProperties: { rowCount: sheet.rowCount || 1000, columnCount: sheet.columnCount || 26, }, }, })); } const response = await sheets.spreadsheets.create({ requestBody, }); return formatSpreadsheetCreatedResponse(response.data); } catch (error) { return handleError(error); } }
- src/tools/create-spreadsheet.ts:7-41 (schema)The Tool definition object with name, description, and detailed inputSchema for validating the tool parameters.export const createSpreadsheetTool: Tool = { name: 'sheets_create_spreadsheet', description: 'Create a new Google Sheets spreadsheet', inputSchema: { type: 'object', properties: { title: { type: 'string', description: 'The title of the new spreadsheet', }, sheets: { type: 'array', items: { type: 'object', properties: { title: { type: 'string', description: 'The title of the sheet', }, rowCount: { type: 'number', description: 'Number of rows in the sheet (default: 1000)', }, columnCount: { type: 'number', description: 'Number of columns in the sheet (default: 26)', }, }, }, description: 'Array of sheets to create in the spreadsheet', }, }, required: ['title'], }, };
- src/index.ts:32-64 (registration)The toolHandlers Map registration that maps the tool name 'sheets_create_spreadsheet' to its handler function tools.handleCreateSpreadsheet for execution dispatch.const toolHandlers = new Map<string, (input: any) => Promise<any>>([ ['sheets_check_access', tools.handleCheckAccess], ['sheets_get_values', tools.handleGetValues], ['sheets_batch_get_values', tools.handleBatchGetValues], ['sheets_get_metadata', tools.handleGetMetadata], ['sheets_update_values', tools.handleUpdateValues], ['sheets_batch_update_values', tools.handleBatchUpdateValues], ['sheets_append_values', tools.handleAppendValues], ['sheets_clear_values', tools.handleClearValues], ['sheets_create_spreadsheet', tools.handleCreateSpreadsheet], ['sheets_insert_sheet', tools.handleInsertSheet], ['sheets_delete_sheet', tools.handleDeleteSheet], ['sheets_duplicate_sheet', tools.handleDuplicateSheet], ['sheets_copy_to', tools.handleCopyTo], ['sheets_update_sheet_properties', tools.handleUpdateSheetProperties], ['sheets_format_cells', tools.formatCellsHandler], ['sheets_update_borders', tools.updateBordersHandler], ['sheets_merge_cells', tools.mergeCellsHandler], ['sheets_unmerge_cells', tools.unmergeCellsHandler], ['sheets_add_conditional_formatting', tools.addConditionalFormattingHandler], // Batch operations ['sheets_batch_delete_sheets', tools.handleBatchDeleteSheets], ['sheets_batch_format_cells', tools.handleBatchFormatCells], // Chart operations ['sheets_create_chart', tools.handleCreateChart], ['sheets_update_chart', tools.handleUpdateChart], ['sheets_delete_chart', tools.handleDeleteChart], // Link and date operations ['sheets_insert_link', tools.handleInsertLink], ['sheets_insert_date', tools.handleInsertDate], // Row operations ['sheets_insert_rows', tools.handleInsertRows], ]);