Skip to main content
Glama

get_recent_slack_messages

Fetch recent messages from a Slack channel to monitor conversations and stay updated on team discussions.

Instructions

Fetch recent messages from a Slack channel.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
channel_idYes
limitNo

Output Schema

TableJSON Schema
NameRequiredDescriptionDefault
resultYes

Implementation Reference

  • main.py:158-181 (handler)
    The handler function for the 'get_recent_slack_messages' tool. It fetches recent messages from a specified Slack channel using the Slack API, retrieves a user name mapping, formats the messages, and returns them as a string.
    @mcp.tool()
    async def get_recent_slack_messages(channel_id: str, limit: int = 5) -> str:
        """Fetch recent messages from a Slack channel."""
        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 Slack messages."
    
        messages = data.get("messages", [])
        if not messages:
            return "No messages found in the channel."
    
        # 🔁 Get user ID to name map
        user_map = await get_user_name_map()
    
        # Format with name
        formatted = [
            format_slack_message(msg, user_map) for msg in messages
        ]
        return "\n---\n".join(formatted)
  • main.py:45-53 (helper)
    Helper function that fetches and caches user ID to name mappings from Slack users.list API, used by get_recent_slack_messages to display user names.
    async def get_user_name_map() -> dict[str, str]:
        """Fetch and return a mapping of user_id to user name."""
        data = await make_slack_request("users.list")
        if not data or not data.get("ok"):
            return {}
        return {
            user["id"]: user.get("real_name") or user.get("name")
            for user in data["members"]
        }
  • main.py:34-40 (helper)
    Helper function to format individual Slack messages with timestamps and resolved user names, used by get_recent_slack_messages.
    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-32 (helper)
    Core helper for making authenticated requests to the Slack API, used by get_recent_slack_messages and other tools.
    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
Behavior2/5

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

With no annotations provided, the description carries the full burden of behavioral disclosure. It mentions 'fetch' but doesn't specify whether this is a read-only operation, requires authentication, has rate limits, or how it handles errors. This leaves significant gaps in understanding the tool's behavior.

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 a single, clear sentence with no wasted words, making it highly concise and front-loaded. It efficiently communicates the core purpose without unnecessary elaboration.

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 the tool's low complexity (2 parameters, no annotations, but with an output schema), the description is minimally adequate. The output schema likely covers return values, reducing the need for description details, but the description fails to address key behavioral aspects like permissions or error handling, leaving it incomplete for safe use.

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

Parameters2/5

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

Schema description coverage is 0%, so the schema provides no parameter details. The description adds minimal semantics by implying 'channel_id' and 'limit' are used to fetch messages, but it doesn't explain what 'recent' means, the format of 'channel_id', or default behavior for 'limit' (though the schema shows a default of 5). This insufficiently compensates for the lack of schema documentation.

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') and resource ('recent messages from a Slack channel'), making the purpose understandable. However, it doesn't differentiate from sibling tools like 'get_user_messages' which might also retrieve messages, leaving room for ambiguity.

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

Usage Guidelines2/5

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

No guidance is provided on when to use this tool versus alternatives such as 'get_user_messages' or 'post_message'. The description lacks context about prerequisites, constraints, or typical use cases, offering minimal direction.

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