Skip to main content
Glama
taylorwilsdon

Google Workspace MCP Server - Control Gmail, Calendar, Docs, Sheets, Slides, Chat, Forms & Drive

modify_sheet_values

Update, write, or clear values in a specified range of Google Sheets. Requires user email, spreadsheet ID, and range details. Supports "RAW" or "USER_ENTERED" input options.

Instructions

Modifies values in a specific range of a Google Sheet - can write, update, or clear values.

Args:
    user_google_email (str): The user's Google email address. Required.
    spreadsheet_id (str): The ID of the spreadsheet. Required.
    range_name (str): The range to modify (e.g., "Sheet1!A1:D10", "A1:D10"). Required.
    values (Optional[List[List[str]]]): 2D array of values to write/update. Required unless clear_values=True.
    value_input_option (str): How to interpret input values ("RAW" or "USER_ENTERED"). Defaults to "USER_ENTERED".
    clear_values (bool): If True, clears the range instead of writing values. Defaults to False.

Returns:
    str: Confirmation message of the successful modification operation.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
clear_valuesNo
range_nameYes
serviceYes
spreadsheet_idYes
user_google_emailYes
value_input_optionNoUSER_ENTERED
valuesNo

Implementation Reference

  • The core handler function for the 'modify_sheet_values' tool. It handles writing, updating, or clearing values in a Google Sheet range using the Sheets API. Includes JSON parsing for MCP parameters, API calls for update or clear, and logging.
    @server.tool()
    @handle_http_errors("modify_sheet_values", service_type="sheets")
    @require_google_service("sheets", "sheets_write")
    async def modify_sheet_values(
        service,
        user_google_email: str,
        spreadsheet_id: str,
        range_name: str,
        values: Optional[Union[str, List[List[str]]]] = None,
        value_input_option: str = "USER_ENTERED",
        clear_values: bool = False,
    ) -> str:
        """
        Modifies values in a specific range of a Google Sheet - can write, update, or clear values.
    
        Args:
            user_google_email (str): The user's Google email address. Required.
            spreadsheet_id (str): The ID of the spreadsheet. Required.
            range_name (str): The range to modify (e.g., "Sheet1!A1:D10", "A1:D10"). Required.
            values (Optional[Union[str, List[List[str]]]]): 2D array of values to write/update. Can be a JSON string or Python list. Required unless clear_values=True.
            value_input_option (str): How to interpret input values ("RAW" or "USER_ENTERED"). Defaults to "USER_ENTERED".
            clear_values (bool): If True, clears the range instead of writing values. Defaults to False.
    
        Returns:
            str: Confirmation message of the successful modification operation.
        """
        operation = "clear" if clear_values else "write"
        logger.info(f"[modify_sheet_values] Invoked. Operation: {operation}, Email: '{user_google_email}', Spreadsheet: {spreadsheet_id}, Range: {range_name}")
    
        # Parse values if it's a JSON string (MCP passes parameters as JSON strings)
        if values is not None and isinstance(values, str):
            try:
                parsed_values = json.loads(values)
                if not isinstance(parsed_values, list):
                    raise ValueError(f"Values must be a list, got {type(parsed_values).__name__}")
                # Validate it's a list of lists
                for i, row in enumerate(parsed_values):
                    if not isinstance(row, list):
                        raise ValueError(f"Row {i} must be a list, got {type(row).__name__}")
                values = parsed_values
                logger.info(f"[modify_sheet_values] Parsed JSON string to Python list with {len(values)} rows")
            except json.JSONDecodeError as e:
                raise Exception(f"Invalid JSON format for values: {e}")
            except ValueError as e:
                raise Exception(f"Invalid values structure: {e}")
    
        if not clear_values and not values:
            raise Exception("Either 'values' must be provided or 'clear_values' must be True.")
    
        if clear_values:
            result = await asyncio.to_thread(
                service.spreadsheets()
                .values()
                .clear(spreadsheetId=spreadsheet_id, range=range_name)
                .execute
            )
    
            cleared_range = result.get("clearedRange", range_name)
            text_output = f"Successfully cleared range '{cleared_range}' in spreadsheet {spreadsheet_id} for {user_google_email}."
            logger.info(f"Successfully cleared range '{cleared_range}' for {user_google_email}.")
        else:
            body = {"values": values}
    
            result = await asyncio.to_thread(
                service.spreadsheets()
                .values()
                .update(
                    spreadsheetId=spreadsheet_id,
                    range=range_name,
                    valueInputOption=value_input_option,
                    body=body,
                )
                .execute
            )
    
            updated_cells = result.get("updatedCells", 0)
            updated_rows = result.get("updatedRows", 0)
            updated_columns = result.get("updatedColumns", 0)
    
            text_output = (
                f"Successfully updated range '{range_name}' in spreadsheet {spreadsheet_id} for {user_google_email}. "
                f"Updated: {updated_cells} cells, {updated_rows} rows, {updated_columns} columns."
            )
            logger.info(f"Successfully updated {updated_cells} cells for {user_google_email}.")
    
        return text_output
  • Module __init__.py imports and lists 'modify_sheet_values' in __all__, registering it as part of the gsheets module tools.
    from .sheets_tools import (
        list_spreadsheets,
        get_spreadsheet_info,
        read_sheet_values,
        modify_sheet_values,
        create_spreadsheet,
        create_sheet,
    )
    
    __all__ = [
        "list_spreadsheets",
        "get_spreadsheet_info", 
        "read_sheet_values",
        "modify_sheet_values",
        "create_spreadsheet",
        "create_sheet",
    ]
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 mentions the tool can 'write, update, or clear values' and returns a 'confirmation message,' but lacks details on permissions required, rate limits, error handling, or what constitutes a successful modification. For a mutation tool with zero annotation coverage, this is insufficient.

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 well-structured and appropriately sized. It starts with a clear purpose statement, followed by a bulleted list of parameters with concise explanations, and ends with return information. Every sentence adds value without redundancy, making it easy to parse.

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

Completeness3/5

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

Given the tool's complexity (7 parameters, mutation operation) and lack of annotations or output schema, the description is partially complete. It covers parameters well but misses behavioral context like authentication, error cases, or output details. It's adequate for basic use but has gaps for robust agent invocation.

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

Parameters5/5

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

The description adds significant value beyond the input schema, which has 0% schema description coverage. It explains each parameter's purpose, required status, defaults, and interactions (e.g., 'values' is required unless 'clear_values=True'). This compensates fully for the schema's lack of descriptions, making parameter usage clear.

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 tool's purpose: 'Modifies values in a specific range of a Google Sheet - can write, update, or clear values.' It specifies the verb (modify), resource (Google Sheet values), and scope (specific range). However, it doesn't explicitly differentiate from sibling tools like 'read_sheet_values' or 'create_spreadsheet', though the distinction is implied through the action.

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. It doesn't mention prerequisites (e.g., authentication needs), compare it to sibling tools like 'read_sheet_values' for reading or 'create_spreadsheet' for creation, or specify scenarios where it's appropriate. Usage is implied by the action but not explicitly stated.

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/taylorwilsdon/google_workspace_mcp'

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