Skip to main content
Glama

discover_spreadsheets_tool

Retrieve spreadsheet names and their sheet names from Google Sheets. Optionally set a maximum number of spreadsheets to analyze.

Instructions

Discover spreadsheets and their sheet names.

Args:
    max_spreadsheets: Maximum number of spreadsheets to analyze (default: 10)

Returns:
    JSON string containing spreadsheet names and their sheet names

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
max_spreadsheetsNoMaximum number of spreadsheets to analyze

Output Schema

TableJSON Schema
NameRequiredDescriptionDefault
resultYes

Implementation Reference

  • Handler function that calls the core discover_spreadsheets logic and returns a compact JSON response.
    def discover_spreadsheets_handler(
        drive_service,
        sheets_service,
        max_spreadsheets: int = 10
    ) -> str:
        """
        Handler for discovering spreadsheets and their sheet names.
        """
        result = discover_spreadsheets(
            drive_service=drive_service,
            sheets_service=sheets_service,
            max_spreadsheets=max_spreadsheets
        )
        return compact_json_response(result)
  • Core logic: queries Google Drive for spreadsheets, then for each spreadsheet gets sheet names via Sheets API, returning structured results.
    def discover_spreadsheets(
        drive_service,
        sheets_service,
        max_spreadsheets: int = 10
    ) -> Dict[str, Any]:
        """
        Discover spreadsheets and their sheet names.
        
        Args:
            drive_service: Google Drive service
            sheets_service: Google Sheets service
            max_spreadsheets: Maximum number of spreadsheets to analyze
        
        Returns:
            Dictionary containing spreadsheet names and their sheet names
        """
        try:
            # Get list of all spreadsheets
            drive_results = drive_service.files().list(
                q="mimeType='application/vnd.google-apps.spreadsheet'",
                pageSize=max_spreadsheets,
                fields="files(id,name)"
            ).execute()
            
            files = drive_results.get("files", [])
            
            result = {
                "total_spreadsheets": len(files),
                "spreadsheets": [],
                "total_sheets": 0
            }
            
            for file in files:
                spreadsheet_name = file["name"]
                spreadsheet_id = file["id"]
                
                spreadsheet_info = {
                    "name": spreadsheet_name,
                    "sheets": []
                }
                
                try:
                    # Get only sheet properties (names)
                    sheets_response = sheets_service.spreadsheets().get(
                        spreadsheetId=spreadsheet_id,
                        fields="sheets.properties"
                    ).execute()
                    
                    sheets = sheets_response.get("sheets", [])
                    
                    for sheet in sheets:
                        props = sheet.get("properties", {})
                        sheet_name = props.get("title", "")
                        
                        if sheet_name:
                            spreadsheet_info["sheets"].append(sheet_name)
                    
                    # Update totals
                    result["total_sheets"] += len(spreadsheet_info["sheets"])
                    
                except Exception as e:
                    spreadsheet_info["error"] = str(e)
                    spreadsheet_info["sheets"] = []
                    print(f"Warning: Could not get sheets for spreadsheet '{spreadsheet_name}': {e}")
                
                result["spreadsheets"].append(spreadsheet_info)
            
            result["message"] = f"Successfully discovered {len(result['spreadsheets'])} spreadsheets with {result['total_sheets']} total sheets"
            
            return result
            
        except Exception as e:
            return {
                "success": False,
                "message": f"Error discovering spreadsheets: {str(e)}"
            }
  • MCP tool registration with @mcp.tool() decorator. Defines the tool with a max_spreadsheets parameter (default 10) and delegates to discover_spreadsheets_handler.
    @mcp.tool()
    def discover_spreadsheets_tool(
        max_spreadsheets: int = Field(default=10, description="Maximum number of spreadsheets to analyze")
    ) -> str:
        """
        Discover spreadsheets and their sheet names.
        
        Args:
            max_spreadsheets: Maximum number of spreadsheets to analyze (default: 10)
        
        Returns:
            JSON string containing spreadsheet names and their sheet names
        """
        sheets_service, drive_service = _get_google_services()
        return discover_spreadsheets_handler(
            drive_service, sheets_service, max_spreadsheets
        )
  • Helper utility that converts the result dictionary to a compact JSON string (no whitespace) used by the handler.
    def compact_json_response(data: Dict[str, Any]) -> str:
        """
        Convert a Python dictionary to a compact JSON string with no newlines or extra spaces.
        
        Args:
            data: Python dictionary to serialize
        
        Returns:
            Compact JSON string with minimal formatting
        """
        return json.dumps(data, separators=(',', ':'))
Behavior2/5

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

No annotations exist, so the description must disclose behavior. It only states the return type (JSON string) but does not mention read-only nature, potential rate limits, or what happens when max_spreadsheets is exceeded.

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 short, with two sentences and a clearly separated Args/Returns section. No redundant information; it is appropriately front-loaded.

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 single parameter and output schema existence, the description is minimally adequate. It mentions the return format but lacks details like the scope of discovery (e.g., all spreadsheets up to max). Could be more specific.

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 coverage is 100%, and the description adds the default value (10). However, it does not explain the impact of different values or any other parameter details beyond what the schema provides.

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

Purpose5/5

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

The description uses a specific verb 'Discover' and resource 'spreadsheets and their sheet names.' It clearly distinguishes from siblings that add, delete, or update sheets. The purpose is immediately understandable.

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?

No guidance on when to use this tool over alternatives like analyze_sheet_structure_tool. The description only provides parameter details without context on prerequisites or situations.

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