Skip to main content
Glama

get_user_messages

Retrieve messages from a specific user in a Slack channel to monitor contributions or extract user-specific conversations.

Instructions

Fetch messages by a specific user (given by name) from a Slack channel.

Args:
    channel_id: The Slack channel ID.
    username: The Slack username or real name of the user.
    limit: How many messages to check (optional).

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
channel_idYes
usernameYes
limitNo

Output Schema

TableJSON Schema
NameRequiredDescriptionDefault
resultYes

Implementation Reference

  • main.py:97-143 (handler)
    The @mcp.tool() decorator registers the get_user_messages handler function, which fetches Slack user messages from a channel by username, filters them, and formats for output.
    @mcp.tool()
    async def get_user_messages(channel_id: str, username: str, limit: int = 10) -> str:
        """
        Fetch messages by a specific user (given by name) from a Slack channel.
        
        Args:
            channel_id: The Slack channel ID.
            username: The Slack username or real name of the user.
            limit: How many messages to check (optional).
        """
        # Step 1: Get user list
        users_data = await make_slack_request("users.list")
        if not users_data or not users_data.get("ok"):
            return "❌ Failed to fetch user list."
    
        # Step 2: Create a user_map and find the user ID
        user_map = {}
        user_id = None
        for user in users_data["members"]:
            uid = user.get("id")
            name = user.get("name")
            real_name = user.get("real_name")
    
            user_map[uid] = real_name or name or uid
    
            if name == username or real_name == username:
                user_id = uid
    
        if not user_id:
            return f"❌ No Slack user found with name '{username}'."
    
        # Step 3: Fetch channel messages
        params = {"channel": channel_id, "limit": limit}
        data = await make_slack_request("conversations.history", params)
    
        if not data or not data.get("ok"):
            return "❌ Unable to fetch messages."
    
        # Step 4: Filter messages by user_id
        user_msgs = [msg for msg in data.get("messages", []) if msg.get("user") == user_id]
    
        if not user_msgs:
            return f"No messages found from user '{username}' in the channel."
    
        # ✅ Step 5: Format messages with user_map
        return "\n---\n".join(format_slack_message(msg, user_map) for msg in user_msgs)
  • main.py:34-40 (helper)
    Helper function to format individual Slack messages with timestamp and user name.
    def format_slack_message(msg: dict, user_map: dict[str, str]) -> str:
        """Format Slack message into a readable string with user name."""
        user_id = msg.get("user", "unknown user")
        user_name = user_map.get(user_id, user_id)  # fallback to user ID if name not found
        text = msg.get("text", "")
        ts = msg.get("ts", "")
        return f"[{ts}] {user_name}: {text}"
  • main.py:19-33 (helper)
    Helper function to make authenticated requests to the Slack API.
    async def make_slack_request(method: str, params: dict[str, Any] | None = None) -> dict[str, Any] | None:
        """Make a request to the Slack Web API with proper error handling."""
        headers = {
            "Authorization": f"Bearer {SLACK_TOKEN}",
            "Content-Type": "application/x-www-form-urlencoded"
        }
        async with httpx.AsyncClient() as client:
            try:
                response = await client.post(f"{SLACK_API_BASE}/{method}", data=params, headers=headers, timeout=10.0)
                response.raise_for_status()
                return response.json()
            except Exception as e:
                print(f"Slack API error: {e}")
                return None
  • Input schema and description from the function docstring.
    """
    Fetch messages by a specific user (given by name) from a Slack channel.
    
    Args:
        channel_id: The Slack channel ID.
        username: The Slack username or real name of the user.
        limit: How many messages to check (optional).
    """
Behavior2/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

With no annotations, the description carries full burden but only states basic functionality. It doesn't disclose behavioral traits like permissions needed, rate limits, pagination, error handling, or whether it's read-only (implied by 'Fetch' but not explicit). This is inadequate for a tool with potential Slack API constraints.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness5/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is front-loaded with the core purpose, followed by a concise Args section. Every sentence adds value: the first defines the tool, and the param explanations are necessary. No redundant or verbose content.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness3/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Given 3 parameters, no annotations, and an output schema (which handles return values), the description is minimally adequate. It covers purpose and param semantics but lacks behavioral context (e.g., Slack API nuances). For a tool interacting with external services, more completeness is needed.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters4/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

The description adds meaningful context beyond the schema: it explains 'username' includes 'real name' (not just username), 'limit' checks messages (not fetches exactly that many), and clarifies the purpose of each param. With 0% schema description coverage, this compensates well, though 'channel_id' semantics could be more detailed.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose4/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states the action ('Fetch messages') and target ('by a specific user from a Slack channel'), specifying the resource (messages) and scope (user, channel). It distinguishes from siblings like 'get_recent_slack_messages' (general messages) and 'post_message' (sending), but not explicitly from 'get_user_info' (user metadata).

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines3/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description implies usage when needing messages from a specific user in a channel, but lacks explicit guidance on when to use this vs. 'get_recent_slack_messages' (e.g., for filtering) or 'get_user_info' (for user details). No exclusions or prerequisites are mentioned.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Install Server

Other Tools

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/Abu-BakarYasir/my_slack_mcp'

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