Skip to main content
Glama

sheets_copy_to

Copy a specific sheet from one Google Sheets spreadsheet to another by specifying source and destination spreadsheet IDs and the sheet ID to transfer.

Instructions

Copy a sheet to another Google Sheets spreadsheet

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
destinationSpreadsheetIdYesThe ID of the destination spreadsheet
sheetIdYesThe ID of the sheet to copy (use sheets_get_metadata to find sheet IDs)
spreadsheetIdYesThe ID of the source spreadsheet (found in the URL after /d/)

Implementation Reference

  • The main execution logic for the sheets_copy_to tool: validates input, uses Google Sheets API to copy the sheet, formats success response, and handles errors.
    export async function handleCopyTo(input: any) {
      try {
        const validatedInput = validateCopyToInput(input);
        const sheets = await getAuthenticatedClient();
    
        const response = await sheets.spreadsheets.sheets.copyTo({
          spreadsheetId: validatedInput.spreadsheetId,
          sheetId: validatedInput.sheetId,
          requestBody: {
            destinationSpreadsheetId: validatedInput.destinationSpreadsheetId,
          },
        });
    
        return formatSheetOperationResponse('Sheet copied', {
          destinationSheetId: response.data.sheetId,
          title: response.data.title,
        });
      } catch (error) {
        return handleError(error);
      }
    }
  • Input schema and metadata definition for the sheets_copy_to tool.
    export const copyToTool: Tool = {
      name: 'sheets_copy_to',
      description: 'Copy a sheet to another Google Sheets spreadsheet',
      inputSchema: {
        type: 'object',
        properties: {
          spreadsheetId: {
            type: 'string',
            description: 'The ID of the source spreadsheet (found in the URL after /d/)',
          },
          sheetId: {
            type: 'number',
            description: 'The ID of the sheet to copy (use sheets_get_metadata to find sheet IDs)',
          },
          destinationSpreadsheetId: {
            type: 'string',
            description: 'The ID of the destination spreadsheet',
          },
        },
        required: ['spreadsheetId', 'sheetId', 'destinationSpreadsheetId'],
      },
    };
  • src/index.ts:45-45 (registration)
    Maps the tool name 'sheets_copy_to' to its handler function in the central toolHandlers registry.
    ['sheets_copy_to', tools.handleCopyTo],
  • src/index.ts:80-80 (registration)
    Includes the copyToTool in the list of all tools returned by ListTools.
    tools.copyToTool,
  • Re-exports the copyToTool and handleCopyTo from copy-to.ts for use in main index.
    export * from './copy-to.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