Skip to main content
Glama

create_sheets_tool

Add new sheets to an existing Google Spreadsheet by specifying sheet names, enabling organized data management within spreadsheets.

Instructions

Create new sheets in a Google Spreadsheet.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
spreadsheet_nameYesThe name of the Google Spreadsheet
sheet_namesYesList of sheet names to create as new sheets

Output Schema

TableJSON Schema
NameRequiredDescriptionDefault
resultYes

Implementation Reference

  • Core handler implementing sheet creation logic: validates inputs, retrieves spreadsheet ID, checks duplicates, calls API to create sheets, handles errors, returns JSON response.
    def create_sheets_handler(
        drive_service,
        sheets_service,
        spreadsheet_name: str,
        sheet_names: List[str]
    ) -> str:
        """
        Handler to create new sheets in a Google Spreadsheet.
        
        Args:
            drive_service: Google Drive service
            sheets_service: Google Sheets service
            spreadsheet_name: Name of the spreadsheet
            sheet_names: List of sheet names to create
        
        Returns:
            JSON string with success status and created sheets info
        """
        try:
            # Validate inputs
            if not sheet_names or not isinstance(sheet_names, list):
                return compact_json_response({
                    "success": False,
                    "message": "Sheet names are required and must be a list."
                })
            
            if len(sheet_names) == 0:
                return compact_json_response({
                    "success": False,
                    "message": "At least one sheet name is required."
                })
            
            # Validate each sheet name
            valid_names = []
            invalid_names = []
            
            for name in sheet_names:
                validation = validate_sheet_name(name)
                if validation["valid"]:
                    valid_names.append(validation["cleaned_name"])
                else:
                    invalid_names.append({"name": name, "error": validation["error"]})
            
            if invalid_names:
                error_messages = [f"'{item['name']}': {item['error']}" for item in invalid_names]
                return compact_json_response({
                    "success": False,
                    "message": f"Invalid sheet names: {'; '.join(error_messages)}",
                    "invalid_names": invalid_names
                })
            
            if not valid_names:
                return compact_json_response({
                    "success": False,
                    "message": "No valid sheet names 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."
                })
            
            # Check for duplicate names
            duplicate_check = check_duplicate_sheet_names(sheets_service, spreadsheet_id, valid_names)
            if duplicate_check["has_duplicates"]:
                return compact_json_response({
                    "success": False,
                    "message": duplicate_check["error"]
                })
            
            # Create sheets
            try:
                created_sheets = create_sheets(sheets_service, spreadsheet_id, valid_names)
                
                # Prepare response
                response_data = {
                    "success": True,
                    "spreadsheet_name": spreadsheet_name,
                    "created_sheets": valid_names,
                    "sheets_created": len(created_sheets),
                    "message": f"Successfully created {len(created_sheets)} sheet(s) in '{spreadsheet_name}'",
                    "sheet_details": [
                        {
                            "sheet_id": sheet.sheet_id,
                            "title": sheet.title,
                            "index": sheet.index
                        }
                        for sheet in created_sheets
                    ]
                }
                
                return compact_json_response(response_data)
                
            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 create sheets: {error_details}",
                    "error_code": e.resp.status if hasattr(e, 'resp') else None
                })
            
        except Exception as e:
            return compact_json_response({
                "success": False,
                "message": f"Unexpected error: {str(e)}",
                "error_type": type(e).__name__
            })
  • MCP tool registration for 'create_sheets_tool' including input schema via Field annotations and docstring, thin wrapper initializing services and delegating to handler.
    @mcp.tool()
    def create_sheets_tool(
        spreadsheet_name: str = Field(..., description="The name of the Google Spreadsheet"),
        sheet_names: List[str] = Field(..., description="List of sheet names to create as new sheets")
    ) -> str:
        """
        Create new sheets in a Google Spreadsheet.
        """
        sheets_service, drive_service = _get_google_services()
        return create_sheets_handler(drive_service, sheets_service, spreadsheet_name, sheet_names)
  • Input schema defined by Pydantic Field parameters with descriptions for spreadsheet_name and sheet_names.
    @mcp.tool()
    def create_sheets_tool(
        spreadsheet_name: str = Field(..., description="The name of the Google Spreadsheet"),
        sheet_names: List[str] = Field(..., description="List of sheet names to create as new sheets")
    ) -> str:
        """
        Create new sheets in a Google Spreadsheet.
        """
        sheets_service, drive_service = _get_google_services()
        return create_sheets_handler(drive_service, sheets_service, spreadsheet_name, sheet_names)
Behavior2/5

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

With no annotations provided, the description carries full burden for behavioral disclosure. It states the action ('Create') but doesn't cover permissions needed, rate limits, whether sheets are appended or replace existing ones, error conditions, or what the output contains. This is inadequate for a mutation tool with zero annotation coverage.

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, clear sentence with no wasted words. It's front-loaded with the core action and resource, making it immediately understandable without unnecessary elaboration.

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 has an output schema (which handles return values) and 100% schema coverage for parameters, the description is minimally complete. However, as a mutation tool with no annotations, it should provide more behavioral context about permissions, side effects, or error handling to be fully adequate.

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%, so the schema fully documents both parameters. The description adds no additional parameter semantics beyond implying the tool operates on a spreadsheet and creates sheets. This meets the baseline for high schema coverage.

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 ('Create') and resource ('new sheets in a Google Spreadsheet'), making the purpose immediately understandable. However, it doesn't differentiate from sibling tools like 'create_duplicate_sheet_tool' or 'create_table_tool', which also create sheet-related resources.

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., spreadsheet must exist), exclusions, or compare to siblings like 'create_duplicate_sheet_tool' for copying existing sheets.

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