Skip to main content
Glama

sheets_duplicate_sheet

Duplicate a sheet in Google Sheets by specifying the spreadsheet ID, sheet ID, insertion index, and new name. Streamline worksheet replication for organized data management.

Instructions

Duplicate a sheet within a Google Sheets spreadsheet

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
insertSheetIndexNoThe index where the new sheet should be inserted (0-based)
newSheetNameNoThe name for the duplicated sheet
sheetIdYesThe ID of the sheet to duplicate (use sheets_get_metadata to find sheet IDs)
spreadsheetIdYesThe ID of the spreadsheet (found in the URL after /d/)

Implementation Reference

  • The core handler function that executes the sheet duplication logic using Google Sheets API's batchUpdate with duplicateSheet request. It validates input, calls the API, extracts the new sheet properties, and returns a formatted response.
    export async function handleDuplicateSheet(input: any) { try { const validatedInput = validateDuplicateSheetInput(input); const sheets = await getAuthenticatedClient(); const response = await sheets.spreadsheets.batchUpdate({ spreadsheetId: validatedInput.spreadsheetId, requestBody: { requests: [ { duplicateSheet: { sourceSheetId: validatedInput.sheetId, insertSheetIndex: validatedInput.insertSheetIndex, newSheetName: validatedInput.newSheetName, }, }, ], }, }); const duplicatedSheet = response.data.replies?.[0]?.duplicateSheet ? response.data.replies[0].duplicateSheet.properties : undefined; return formatSheetOperationResponse('Sheet duplicated', { newSheetId: duplicatedSheet ? duplicatedSheet.sheetId : undefined, title: duplicatedSheet ? duplicatedSheet.title : undefined, index: duplicatedSheet ? duplicatedSheet.index : undefined, }); } catch (error) { return handleError(error); } }
  • The Tool schema definition specifying the name, description, and inputSchema (including properties for spreadsheetId, sheetId, insertSheetIndex, newSheetName; required: spreadsheetId, sheetId).
    export const duplicateSheetTool: Tool = { name: 'sheets_duplicate_sheet', description: 'Duplicate a sheet within 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 duplicate (use sheets_get_metadata to find sheet IDs)', }, insertSheetIndex: { type: 'number', description: 'The index where the new sheet should be inserted (0-based)', }, newSheetName: { type: 'string', description: 'The name for the duplicated sheet', }, }, required: ['spreadsheetId', 'sheetId'], }, };
  • src/index.ts:44-44 (registration)
    Registration of the 'sheets_duplicate_sheet' tool with its handler (tools.handleDuplicateSheet) in the central toolHandlers Map used for tool execution.
    ['sheets_duplicate_sheet', tools.handleDuplicateSheet],
  • src/index.ts:79-79 (registration)
    Inclusion of the duplicateSheetTool in the allTools array used for listing available tools via ListToolsRequest.
    tools.duplicateSheetTool,
  • Re-export of the duplicateSheetTool and handleDuplicateSheet from duplicate-sheet.ts, making them available as tools.* in src/index.ts.
    export * from './duplicate-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