list_spaces
Retrieve a formatted list of Google Chat spaces, including rooms and direct messages, accessible to a specific user for streamlined communication management within Google Workspace.
Instructions
Lists Google Chat spaces (rooms and direct messages) accessible to the user.
Returns:
str: A formatted list of Google Chat spaces accessible to the user.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| page_size | No | ||
| service | Yes | ||
| space_type | No | all | |
| user_google_email | Yes |
Implementation Reference
- gchat/chat_tools.py:19-62 (handler)Implementation of the 'list_spaces' tool handler function, which lists Google Chat spaces using the Chat API. Registered via @server.tool() decorator. Handles filtering by space type (room, dm, all), pagination, and formats the output as a string list.@server.tool() @require_google_service("chat", "chat_read") @handle_http_errors("list_spaces", service_type="chat") async def list_spaces( service, user_google_email: str, page_size: int = 100, space_type: str = "all" # "all", "room", "dm" ) -> str: """ Lists Google Chat spaces (rooms and direct messages) accessible to the user. Returns: str: A formatted list of Google Chat spaces accessible to the user. """ logger.info(f"[list_spaces] Email={user_google_email}, Type={space_type}") # Build filter based on space_type filter_param = None if space_type == "room": filter_param = "spaceType = SPACE" elif space_type == "dm": filter_param = "spaceType = DIRECT_MESSAGE" request_params = {"pageSize": page_size} if filter_param: request_params["filter"] = filter_param response = await asyncio.to_thread( service.spaces().list(**request_params).execute ) spaces = response.get('spaces', []) if not spaces: return f"No Chat spaces found for type '{space_type}'." output = [f"Found {len(spaces)} Chat spaces (type: {space_type}):"] for space in spaces: space_name = space.get('displayName', 'Unnamed Space') space_id = space.get('name', '') space_type_actual = space.get('spaceType', 'UNKNOWN') output.append(f"- {space_name} (ID: {space_id}, Type: {space_type_actual})") return "\n".join(output)
- gchat/chat_tools.py:19-19 (registration)Registration of the 'list_spaces' tool using the @server.tool() decorator.@server.tool()