Skip to main content
Glama

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
NameRequiredDescriptionDefault
columnCountNoNumber of columns in the sheet (default: 26)
indexNoThe index where the sheet should be inserted (0-based)
rowCountNoNumber of rows in the sheet (default: 1000)
spreadsheetIdYesThe ID of the spreadsheet (found in the URL after /d/)
titleYesThe title of the new sheet

Implementation Reference

  • 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); } }
  • 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,
  • Re-exports the tool definition and handler from the insert-sheet module for use in src/index.ts.
    export * from './insert-sheet.js';

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/freema/mcp-gsheets'

If you have feedback or need assistance with the MCP directory API, please join our Discord server