Skip to main content
Glama

get_sheet_cells_by_notation_tool

Retrieve specific cell values from Google Sheets using A1 notation to access spreadsheet data programmatically.

Instructions

Get values from specific cells in a sheet.

This tool retrieves values from multiple cells in a sheet using A1 notation.

Args:
    spreadsheet_name: Name of the spreadsheet
    sheet_name: Name of the sheet to get cells from
    cell_notations: List of cell notations to get values from (e.g., ['A1', 'A6', 'A10', 'E5'])

Returns:
    JSON string with cell values and mapping

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
spreadsheet_nameYesThe name of the Google Spreadsheet
sheet_nameYesThe name of the sheet to get cells from
cell_notationsYesList of cell notations to get values from (e.g., ['A1', 'A6', 'A10', 'E5'])

Output Schema

TableJSON Schema
NameRequiredDescriptionDefault
resultYes

Implementation Reference

  • Core implementation of the get_sheet_cells_by_notation tool. Validates inputs, retrieves spreadsheet and sheet IDs, fetches individual cell values using Google Sheets API spreadsheets.values.get, and returns formatted JSON response.
    def get_sheet_cells_by_notation_handler(
        drive_service,
        sheets_service,
        spreadsheet_name: str,
        sheet_name: str,
        cell_notations: List[str]
    ) -> str:
        """
        Get values from specific cells in a sheet in Google Sheets.
        
        Args:
            drive_service: Google Drive service instance
            sheets_service: Google Sheets service instance
            spreadsheet_name: Name of the spreadsheet
            sheet_name: Name of the sheet to get cells from
            cell_notations: List of cell notations (e.g., ['A1', 'A6', 'A10', 'E5'])
        
        Returns:
            str: Success message with cell values and mapping or error message
        """
        try:
            # Validate inputs
            if not cell_notations or not isinstance(cell_notations, list):
                return compact_json_response({
                    "success": False,
                    "message": "Cell notations are required and must be a list."
                })
            
            if len(cell_notations) == 0:
                return compact_json_response({
                    "success": False,
                    "message": "At least one cell notation is required."
                })
            
            # Validate cell notations
            valid_notations = []
            invalid_notations = []
            
            for notation in cell_notations:
                if not isinstance(notation, str) or not notation.strip():
                    invalid_notations.append({"notation": notation, "error": "Invalid cell notation"})
                    continue
                
                try:
                    # Validate A1 notation format
                    row_idx, col_idx = parse_cell_reference(notation.strip())
                    valid_notations.append(notation.strip())
                except ValueError:
                    invalid_notations.append({"notation": notation, "error": "Invalid A1 notation format"})
            
            if invalid_notations:
                error_messages = [f"'{item['notation']}': {item['error']}" for item in invalid_notations]
                return compact_json_response({
                    "success": False,
                    "message": f"Invalid cell notations: {'; '.join(error_messages)}",
                    "invalid_notations": invalid_notations
                })
            
            if not valid_notations:
                return compact_json_response({
                    "success": False,
                    "message": "No valid cell notations provided."
                })
            
            # Get spreadsheet ID
            spreadsheet_id = get_spreadsheet_id_by_name(drive_service, spreadsheet_name)
            if not spreadsheet_id:
                return compact_json_response({
                    "success": False,
                    "message": f"Spreadsheet '{spreadsheet_name}' not found."
                })
    
            # Get sheet ID
            sheet_ids = get_sheet_ids_by_names(sheets_service, spreadsheet_id, [sheet_name])
            sheet_id = sheet_ids.get(sheet_name)
            if sheet_id is None:
                return compact_json_response({
                    "success": False,
                    "message": f"Sheet '{sheet_name}' not found in spreadsheet '{spreadsheet_name}'."
                })
    
            # Get cell values using sheets.values.get
            cell_values = {}
            cell_data = {}
            
            try:
                # Get values for each cell notation separately
                for notation in valid_notations:
                    range_notation = f"'{sheet_name}'!{notation}"
                    response = sheets_service.spreadsheets().values().get(
                        spreadsheetId=spreadsheet_id,
                        range=range_notation
                    ).execute()
                    
                    values = response.get('values', [])
                    cell_value = values[0][0] if values and values[0] else None
                    
                    cell_values[notation] = cell_value
                    cell_data[notation] = {
                        "value": cell_value,
                        "notation": notation
                    }
                
            except HttpError as e:
                error_details = e.error_details if hasattr(e, 'error_details') else str(e)
                return compact_json_response({
                    "success": False,
                    "message": f"Failed to retrieve cell values: {error_details}",
                    "error_code": e.resp.status if hasattr(e, 'resp') else None
                })
            
            # Prepare response
            response_data = {
                "success": True,
                "message": f"Successfully retrieved {len(cell_values)} cell values from sheet '{sheet_name}'",
                "spreadsheet_name": spreadsheet_name,
                "sheet_name": sheet_name,
                "cell_count": len(cell_values),
                "cell_data": cell_data,
                "summary": {
                    "total_cells": len(cell_values),
                    "non_empty_cells": len([v for v in cell_values.values() if v is not None]),
                    "empty_cells": len([v for v in cell_values.values() if v is None])
                }
            }
            
            return compact_json_response(response_data)
            
        except Exception as e:
            return compact_json_response({
                "success": False,
                "message": f"Unexpected error: {str(e)}",
                "error_type": type(e).__name__
            })
  • MCP tool registration using @mcp.tool() decorator. Defines input parameters with Pydantic Field validation and descriptions, initializes services, and delegates to the handler function.
    @mcp.tool()
    def get_sheet_cells_by_notation_tool(
        spreadsheet_name: str = Field(..., description="The name of the Google Spreadsheet"),
        sheet_name: str = Field(..., description="The name of the sheet to get cells from"),
        cell_notations: List[str] = Field(..., description="List of cell notations to get values from (e.g., ['A1', 'A6', 'A10', 'E5'])")
    ) -> str:
        """
        Get values from specific cells in a sheet.
        
        This tool retrieves values from multiple cells in a sheet using A1 notation.
        
        Args:
            spreadsheet_name: Name of the spreadsheet
            sheet_name: Name of the sheet to get cells from
            cell_notations: List of cell notations to get values from (e.g., ['A1', 'A6', 'A10', 'E5'])
        
        Returns:
            JSON string with cell values and mapping
        """
        sheets_service, drive_service = _get_google_services()
        return get_sheet_cells_by_notation_handler(drive_service, sheets_service, spreadsheet_name, sheet_name, cell_notations)
  • Input schema defined using Pydantic BaseModel Field with required parameters and detailed descriptions for the tool.
    @mcp.tool()
    def get_sheet_cells_by_notation_tool(
        spreadsheet_name: str = Field(..., description="The name of the Google Spreadsheet"),
        sheet_name: str = Field(..., description="The name of the sheet to get cells from"),
        cell_notations: List[str] = Field(..., description="List of cell notations to get values from (e.g., ['A1', 'A6', 'A10', 'E5'])")
    ) -> str:
        """
        Get values from specific cells in a sheet.
        
        This tool retrieves values from multiple cells in a sheet using A1 notation.
        
        Args:
            spreadsheet_name: Name of the spreadsheet
            sheet_name: Name of the sheet to get cells from
            cell_notations: List of cell notations to get values from (e.g., ['A1', 'A6', 'A10', 'E5'])
        
        Returns:
            JSON string with cell values and mapping
        """
        sheets_service, drive_service = _get_google_services()
        return get_sheet_cells_by_notation_handler(drive_service, sheets_service, spreadsheet_name, sheet_name, cell_notations)
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 the tool 'retrieves values' but doesn't cover critical aspects like whether this is a read-only operation, potential rate limits, authentication requirements, error handling, or what happens with invalid cell notations. For a data retrieval tool with zero annotation coverage, this leaves significant gaps in understanding its behavior.

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

Conciseness4/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, provides usage context in the second sentence, and includes separate sections for Args and Returns. Every sentence adds value, though the Args section largely duplicates schema information. The structure helps with readability.

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 moderate complexity (3 parameters, data retrieval function) and the presence of both input schema (100% coverage) and output schema, the description is minimally adequate. However, with no annotations and multiple sibling tools for similar purposes, it should provide more contextual guidance about when to use this specific method versus alternatives. The output schema existence means the description doesn't need to detail return values.

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

Parameters3/5

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

Schema description coverage is 100%, with each parameter clearly documented in the input schema. The description adds minimal value beyond the schema: it repeats the example for 'cell_notations' and mentions 'A1 notation' (implied in the schema's example). Since the schema already provides comprehensive parameter documentation, the baseline score of 3 is appropriate.

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: 'Get values from specific cells in a sheet' and 'retrieves values from multiple cells in a sheet using A1 notation.' This specifies the verb (get/retrieve), resource (cells in a sheet), and method (A1 notation). However, it doesn't explicitly distinguish it from sibling tools like 'get_sheet_cells_by_range_tool' or 'get_table_data_tool', which appear to serve similar data retrieval purposes.

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 mentions 'A1 notation' but doesn't explain when this is preferable over range-based retrieval (e.g., 'get_sheet_cells_by_range_tool') or table-based methods (e.g., 'get_table_data_tool'). There are no prerequisites, exclusions, or comparative context provided.

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

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/henilcalagiya/google-sheets-mcp'

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