Skip to content

mcp-google-sheets list_sheets() returns only one sheet name due to FastMCP serialization #53

@iqdoctor

Description

@iqdoctor
  • Root cause: The list_sheets MCP tool returned a raw Python list. FastMCP serializes tool results as a single text block, so only the first sheet name survived the conversion and reached the client. That’s why the UI always showed one sheet even though the API was listing them all.
  • Fix: Filter out non‑grid tabs and return a single string with sheet names separated by \n. Example: "catalog\ncatalog (copy)\nx1". Now every tab appears correctly.
  • Next steps: I’m preparing an automated test case plus a PR that covers this serialization bug so we don’t regress.

Let me know if you want the draft issue text or additional logs/screenshots attached.

@mcp.tool()
def list_sheets(spreadsheet_id: str, ctx: Context = None) -> List[str]:
    """
    List all sheets in a Google Spreadsheet.
    
    Args:
        spreadsheet_id: The ID of the spreadsheet (found in the URL)
    
    Returns:
        List of sheet names
    """
    sheets_service = ctx.request_context.lifespan_context.sheets_service
    
    # Get spreadsheet metadata
    spreadsheet = sheets_service.spreadsheets().get(spreadsheetId=spreadsheet_id).execute()
    
    # Extract only grid sheet names (exclude charts / data-source sheets)
    sheet_names = [
        sheet['properties']['title']
        for sheet in spreadsheet['sheets']
        if sheet.get('properties', {}).get('sheetType', 'GRID') == 'GRID'
    ]

    # Return newline-separated sheet names as plain text
    return "\n".join(sheet_names)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions