Skip to main content
Glama
taylorwilsdon

Google Workspace MCP Server - Control Gmail, Calendar, Docs, Sheets, Slides, Chat, Forms & Drive

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
NameRequiredDescriptionDefault
order_byNocreateTime desc
page_sizeNo
serviceYes
space_idYes
user_google_emailYes

Implementation Reference

  • 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)
  • Registers the 'get_messages' tool with the MCP server using the @server.tool() decorator.
    @server.tool()
  • 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")

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/taylorwilsdon/google_workspace_mcp'

If you have feedback or need assistance with the MCP directory API, please join our Discord server