get_messages
Retrieve and format messages from a Google Chat space using service details, user email, and space ID to access organized communication data.
Instructions
Retrieves messages from a Google Chat space.
Returns:
str: Formatted messages from the specified space.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| order_by | No | createTime desc | |
| page_size | No | ||
| service | Yes | ||
| space_id | Yes | ||
| user_google_email | Yes |
Implementation Reference
- gchat/chat_tools.py:67-112 (handler)The core handler function that retrieves messages from a specified Google Chat space. It fetches space information, lists recent messages using the Google Chat API, formats them with sender, time, content, and message ID, and returns a formatted string.async def get_messages( service, user_google_email: str, space_id: str, page_size: int = 50, order_by: str = "createTime desc" ) -> str: """ Retrieves messages from a Google Chat space. Returns: str: Formatted messages from the specified space. """ logger.info(f"[get_messages] Space ID: '{space_id}' for user '{user_google_email}'") # Get space info first space_info = await asyncio.to_thread( service.spaces().get(name=space_id).execute ) space_name = space_info.get('displayName', 'Unknown Space') # Get messages response = await asyncio.to_thread( service.spaces().messages().list( parent=space_id, pageSize=page_size, orderBy=order_by ).execute ) messages = response.get('messages', []) if not messages: return f"No messages found in space '{space_name}' (ID: {space_id})." output = [f"Messages from '{space_name}' (ID: {space_id}):\n"] for msg in messages: sender = msg.get('sender', {}).get('displayName', 'Unknown Sender') create_time = msg.get('createTime', 'Unknown Time') text_content = msg.get('text', 'No text content') msg_name = msg.get('name', '') output.append(f"[{create_time}] {sender}:") output.append(f" {text_content}") output.append(f" (Message ID: {msg_name})\n") return "\n".join(output)
- gchat/chat_tools.py:64-64 (registration)Registers the 'get_messages' tool with the MCP server using the @server.tool() decorator.@server.tool()
- gchat/chat_tools.py:64-66 (registration)Decorator stack that registers the tool, requires Google Chat read permissions, and handles HTTP errors specifically for 'get_messages'.@server.tool() @require_google_service("chat", "chat_read") @handle_http_errors("get_messages", service_type="chat")