sheets_delete_sheet
Remove unwanted sheets from a Google Sheets document by specifying the spreadsheet ID and sheet ID, streamlining document organization and management.
Instructions
Delete a sheet from a Google Sheets spreadsheet
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| sheetId | Yes | The ID of the sheet to delete (use sheets_get_metadata to find sheet IDs) | |
| spreadsheetId | Yes | The ID of the spreadsheet (found in the URL after /d/) |
Implementation Reference
- src/tools/delete-sheet.ts:26-50 (handler)The handler function that validates input, authenticates with Google Sheets API, performs the batchUpdate to delete the specified sheet, formats the response, and handles errors.export async function handleDeleteSheet(input: any) { try { const validatedInput = validateDeleteSheetInput(input); const sheets = await getAuthenticatedClient(); await sheets.spreadsheets.batchUpdate({ spreadsheetId: validatedInput.spreadsheetId, requestBody: { requests: [ { deleteSheet: { sheetId: validatedInput.sheetId, }, }, ], }, }); return formatSheetOperationResponse('Sheet deleted', { sheetId: validatedInput.sheetId, }); } catch (error) { return handleError(error); } }
- src/tools/delete-sheet.ts:7-24 (schema)The tool definition including name, description, and input schema for the sheets_delete_sheet tool.export const deleteSheetTool: Tool = { name: 'sheets_delete_sheet', description: 'Delete a sheet from a Google Sheets spreadsheet', inputSchema: { type: 'object', properties: { spreadsheetId: { type: 'string', description: 'The ID of the spreadsheet (found in the URL after /d/)', }, sheetId: { type: 'number', description: 'The ID of the sheet to delete (use sheets_get_metadata to find sheet IDs)', }, }, required: ['spreadsheetId', 'sheetId'], }, };
- src/index.ts:32-64 (registration)Registration of tool handlers in a Map, including 'sheets_delete_sheet' mapped to tools.handleDeleteSheet for execution handling.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], ]);
- src/index.ts:67-99 (registration)Registration of all tools in an array including deleteSheetTool for listing available tools.const allTools = [ tools.checkAccessTool, tools.getValuesTool, tools.batchGetValuesTool, tools.getMetadataTool, tools.updateValuesTool, tools.batchUpdateValuesTool, tools.appendValuesTool, tools.clearValuesTool, tools.createSpreadsheetTool, tools.insertSheetTool, tools.deleteSheetTool, tools.duplicateSheetTool, tools.copyToTool, tools.updateSheetPropertiesTool, tools.formatCellsTool, tools.updateBordersTool, tools.mergeCellsTool, tools.unmergeCellsTool, tools.addConditionalFormattingTool, // Batch operations tools.batchDeleteSheetsTool, tools.batchFormatCellsTool, // Chart operations tools.createChartTool, tools.updateChartTool, tools.deleteChartTool, // Link and date operations tools.insertLinkTool, tools.insertDateTool, // Row operations tools.insertRowsTool, ];