Skip to main content
Glama

discover_spreadsheets_tool

Find and list Google Sheets spreadsheets with their sheet names to organize and access your data efficiently.

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

  • Core handler logic that discovers spreadsheets using Google Drive API (lists files with spreadsheet MIME type) and retrieves sheet names using Google Sheets API.
    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)}"
            }
  • Registers the 'discover_spreadsheets_tool' with FastMCP using @mcp.tool() decorator and defines the tool's input schema via Pydantic Field. Thin wrapper that initializes services and delegates to 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
        )
  • Pydantic input schema definition for the tool using Field for max_spreadsheets parameter.
    def discover_spreadsheets_tool(
        max_spreadsheets: int = Field(default=10, description="Maximum number of spreadsheets to analyze")
  • Wrapper handler that calls the core discover_spreadsheets function and formats response as compact JSON.
    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)
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 return format ('JSON string') but lacks critical details: what 'discover' entails (e.g., does it list all accessible spreadsheets, search by criteria, require specific permissions?), whether it's read-only or has side effects, or if there are rate limits. For a tool with no annotations, 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 concise, using a clear purpose statement followed by Args and Returns sections. Each sentence serves a purpose, though the parameter repetition from the schema could be considered slightly redundant. It's appropriately sized for a simple tool with one parameter.

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 low complexity (1 parameter, no annotations, but with an output schema), the description is minimally adequate. The output schema likely covers return values, so the description doesn't need to detail them. However, for a 'discover' operation with no annotations, it should better explain what 'discover' means in practice (e.g., scope, permissions) to be fully complete.

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?

The schema description coverage is 100%, with the parameter 'max_spreadsheets' fully documented in the schema. The description repeats the parameter info verbatim ('Maximum number of spreadsheets to analyze (default: 10)'), adding no additional meaning beyond what the schema provides. With high schema coverage, the baseline score of 3 is appropriate as the description doesn't enhance parameter understanding.

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: 'Discover spreadsheets and their sheet names.' It uses a specific verb ('discover') and identifies the resource ('spreadsheets'), but it doesn't explicitly differentiate from sibling tools like 'get_table_metadata_tool' or 'analyze_sheet_structure_tool' that might also retrieve spreadsheet information.

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, access to spreadsheets), nor does it compare to sibling tools like 'get_table_metadata_tool' that might retrieve similar data. The usage context is implied 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

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