Skip to main content
Glama

sheets_update_borders

Modify cell borders in Google Sheets by specifying the spreadsheet ID, range, and border styles. Streamline formatting tasks programmatically with structured input.

Instructions

Update borders of cells in a Google Sheet

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
bordersYes
rangeYes
spreadsheetIdYes

Implementation Reference

  • The main handler function that validates input, parses the range, builds the UpdateBordersRequest for the Google Sheets API batchUpdate, converts border properties, and executes the update.
    export async function updateBordersHandler(input: any): Promise<ToolResponse> {
      try {
        // Handle case where borders comes as JSON string
        input.borders = parseJsonInput(input.borders, 'borders');
    
        const validatedInput = updateBordersInputSchema.parse(input) as UpdateBordersInput;
        const sheets = await getAuthenticatedClient();
    
        // Extract sheet name and get sheet ID
        const { sheetName, range: cleanRange } = extractSheetName(validatedInput.range);
        const sheetId = await getSheetId(sheets, validatedInput.spreadsheetId, sheetName);
    
        // Parse range to GridRange
        const gridRange = parseRange(cleanRange, sheetId);
    
        // Build the border update request
        const updateBordersRequest: sheets_v4.Schema$UpdateBordersRequest = {
          range: gridRange,
        };
    
        // Helper function to convert our border format to Google's format
        const convertBorder = (border?: any): sheets_v4.Schema$Border | undefined => {
          if (!border) {
            return undefined;
          }
          return {
            style: border.style,
            color: border.color,
            width: border.width,
          };
        };
    
        const topBorder = convertBorder(validatedInput.borders.top);
        if (topBorder) {
          updateBordersRequest.top = topBorder;
        }
    
        const bottomBorder = convertBorder(validatedInput.borders.bottom);
        if (bottomBorder) {
          updateBordersRequest.bottom = bottomBorder;
        }
    
        const leftBorder = convertBorder(validatedInput.borders.left);
        if (leftBorder) {
          updateBordersRequest.left = leftBorder;
        }
    
        const rightBorder = convertBorder(validatedInput.borders.right);
        if (rightBorder) {
          updateBordersRequest.right = rightBorder;
        }
    
        const innerHorizontalBorder = convertBorder(validatedInput.borders.innerHorizontal);
        if (innerHorizontalBorder) {
          updateBordersRequest.innerHorizontal = innerHorizontalBorder;
        }
    
        const innerVerticalBorder = convertBorder(validatedInput.borders.innerVertical);
        if (innerVerticalBorder) {
          updateBordersRequest.innerVertical = innerVerticalBorder;
        }
    
        // Execute the border update
        const response = await sheets.spreadsheets.batchUpdate({
          spreadsheetId: validatedInput.spreadsheetId,
          requestBody: {
            requests: [
              {
                updateBorders: updateBordersRequest,
              },
            ],
          },
        });
    
        return formatToolResponse(`Successfully updated borders for range ${validatedInput.range}`, {
          spreadsheetId: response.data.spreadsheetId,
        });
      } catch (error) {
        return handleError(error);
      }
    }
  • Zod schemas for color, border, borders objects, and the main input schema. Also the Tool object definition with name, description, and inputSchema for MCP.
    // Schema definitions
    const colorSchema = z
      .object({
        red: z.number().min(0).max(1).optional(),
        green: z.number().min(0).max(1).optional(),
        blue: z.number().min(0).max(1).optional(),
        alpha: z.number().min(0).max(1).optional(),
      })
      .optional();
    
    const borderSchema = z
      .object({
        style: z.enum(['NONE', 'SOLID', 'DASHED', 'DOTTED', 'SOLID_MEDIUM', 'SOLID_THICK', 'DOUBLE']),
        color: colorSchema,
        width: z.number().positive().optional(),
      })
      .optional();
    
    const bordersSchema = z.object({
      top: borderSchema,
      bottom: borderSchema,
      left: borderSchema,
      right: borderSchema,
      innerHorizontal: borderSchema,
      innerVertical: borderSchema,
    });
    
    const updateBordersInputSchema = z.object({
      spreadsheetId: z.string(),
      range: z.string(),
      borders: bordersSchema,
    });
    
    export const updateBordersTool: Tool = {
      name: 'sheets_update_borders',
      description: 'Update borders of cells in a Google Sheet',
      inputSchema: {
        type: 'object',
        properties: updateBordersInputSchema.shape,
        required: ['spreadsheetId', 'range', 'borders'],
      },
    };
  • src/index.ts:32-64 (registration)
    Registration of the updateBordersHandler in the toolHandlers Map used by the MCP server to dispatch tool calls.
    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)
    Inclusion of the updateBordersTool in the allTools array returned by ListToolsRequestHandler.
    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,
    ];
  • Re-export of updateBordersTool and updateBordersHandler from the individual tool file to make them available for import in src/index.ts.
    export * from './update-borders.js';
Behavior2/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

No annotations are provided, so the description carries the full burden of behavioral disclosure. It states 'Update' which implies a mutation, but doesn't mention permissions required, whether changes are reversible, rate limits, or what happens to existing borders. For a mutation tool with zero annotation coverage, this is a significant gap in transparency.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness5/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is a single, efficient sentence that gets straight to the point with no wasted words. It's appropriately sized for a tool with a straightforward name and purpose, making it easy to parse quickly.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness2/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

For a mutation tool with 3 undocumented parameters, 0% schema coverage, and no output schema, the description is inadequate. It doesn't explain what the tool returns, how borders are specified, or provide any context about the mutation's effects. The description should do much more to compensate for the lack of structured documentation.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters1/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Schema description coverage is 0%, meaning none of the three parameters (spreadsheetId, range, borders) are documented in the schema. The description adds no information about what these parameters mean, their expected formats, or examples of usage. It fails to compensate for the complete lack of schema documentation.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose4/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states the verb ('Update') and resource ('borders of cells in a Google Sheet'), making the purpose immediately understandable. However, it doesn't distinguish this tool from similar formatting tools like 'sheets_format_cells' or 'sheets_update_sheet_properties', which could also involve border modifications, so it lacks sibling differentiation.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines2/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description provides no guidance on when to use this tool versus alternatives. With siblings like 'sheets_format_cells' that might handle borders, there's no indication of whether this is the primary border tool, when to choose it over others, or any prerequisites for usage.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Install Server

Other Tools

Related Tools

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