sheets_insert_sheet
Add a new sheet to a Google Sheets spreadsheet by specifying its title, position, and dimensions. Requires the spreadsheet ID for integration.
Instructions
Add a new sheet to an existing Google Sheets spreadsheet
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| columnCount | No | Number of columns in the sheet (default: 26) | |
| index | No | The index where the sheet should be inserted (0-based) | |
| rowCount | No | Number of rows in the sheet (default: 1000) | |
| spreadsheetId | Yes | The ID of the spreadsheet (found in the URL after /d/) | |
| title | Yes | The title of the new sheet |
Implementation Reference
- src/tools/insert-sheet.ts:38-74 (handler)The handler function that validates input, authenticates with Google Sheets API, performs batchUpdate to add a new sheet, and formats the response.export async function handleInsertSheet(input: any) { try { const validatedInput = validateInsertSheetInput(input); const sheets = await getAuthenticatedClient(); const response = await sheets.spreadsheets.batchUpdate({ spreadsheetId: validatedInput.spreadsheetId, requestBody: { requests: [ { addSheet: { properties: { title: validatedInput.title, index: validatedInput.index, gridProperties: { rowCount: validatedInput.rowCount, columnCount: validatedInput.columnCount, }, }, }, }, ], }, }); const addedSheet = response.data.replies?.[0]?.addSheet ? response.data.replies[0].addSheet.properties : undefined; return formatSheetOperationResponse('Sheet inserted', { sheetId: addedSheet ? addedSheet.sheetId : undefined, title: addedSheet ? addedSheet.title : undefined, index: addedSheet ? addedSheet.index : undefined, }); } catch (error) { return handleError(error); } }
- src/tools/insert-sheet.ts:7-36 (schema)Tool definition with name, description, and input schema specifying required spreadsheetId and title, optional index, rowCount, columnCount.export const insertSheetTool: Tool = { name: 'sheets_insert_sheet', description: 'Add a new sheet to an existing Google Sheets spreadsheet', inputSchema: { type: 'object', properties: { spreadsheetId: { type: 'string', description: 'The ID of the spreadsheet (found in the URL after /d/)', }, title: { type: 'string', description: 'The title of the new sheet', }, index: { type: 'number', description: 'The index where the sheet should be inserted (0-based)', }, rowCount: { type: 'number', description: 'Number of rows in the sheet (default: 1000)', }, columnCount: { type: 'number', description: 'Number of columns in the sheet (default: 26)', }, }, required: ['spreadsheetId', 'title'], }, };
- src/index.ts:42-42 (registration)Registers the handler for 'sheets_insert_sheet' in the toolHandlers Map used to dispatch CallToolRequests.['sheets_insert_sheet', tools.handleInsertSheet],
- src/index.ts:77-77 (registration)Includes the tool schema in the allTools array for ListToolsRequest response.tools.insertSheetTool,
- src/tools/index.ts:10-10 (registration)Re-exports the tool definition and handler from the insert-sheet module for use in src/index.ts.export * from './insert-sheet.js';