create_sheet
Add a new sheet to a Google spreadsheet by specifying the user email, spreadsheet ID, and sheet name. Confirm successful creation with a message.
Instructions
Creates a new sheet within an existing spreadsheet.
Args: user_google_email (str): The user's Google email address. Required. spreadsheet_id (str): The ID of the spreadsheet. Required. sheet_name (str): The name of the new sheet. Required.
Returns: str: Confirmation message of the successful sheet creation.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| sheet_name | Yes | ||
| spreadsheet_id | Yes | ||
| user_google_email | Yes |
Implementation Reference
- gsheets/sheets_tools.py:308-355 (handler)The core handler function for the 'create_sheet' MCP tool. It uses the Google Sheets API to add a new sheet to an existing spreadsheet via batchUpdate request. Includes logging, error handling, and authentication decorators.@server.tool() @handle_http_errors("create_sheet", service_type="sheets") @require_google_service("sheets", "sheets_write") async def create_sheet( service, user_google_email: str, spreadsheet_id: str, sheet_name: str, ) -> str: """ Creates a new sheet within an existing spreadsheet. Args: user_google_email (str): The user's Google email address. Required. spreadsheet_id (str): The ID of the spreadsheet. Required. sheet_name (str): The name of the new sheet. Required. Returns: str: Confirmation message of the successful sheet creation. """ logger.info(f"[create_sheet] Invoked. Email: '{user_google_email}', Spreadsheet: {spreadsheet_id}, Sheet: {sheet_name}") request_body = { "requests": [ { "addSheet": { "properties": { "title": sheet_name } } } ] } response = await asyncio.to_thread( service.spreadsheets() .batchUpdate(spreadsheetId=spreadsheet_id, body=request_body) .execute ) sheet_id = response["replies"][0]["addSheet"]["properties"]["sheetId"] text_output = ( f"Successfully created sheet '{sheet_name}' (ID: {sheet_id}) in spreadsheet {spreadsheet_id} for {user_google_email}." ) logger.info(f"Successfully created sheet for {user_google_email}. Sheet ID: {sheet_id}") return text_output
- gsheets/__init__.py:7-23 (registration)Registers and exposes the 'create_sheet' tool by importing it from sheets_tools.py and including it in __all__, making it available when the gsheets package is imported.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", ]