get_recent_slack_messages
Retrieve recent messages from a Slack channel to monitor conversations, track updates, and stay informed about team discussions.
Instructions
Fetch recent messages from a Slack channel.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| channel_id | Yes | ||
| limit | No |
Implementation Reference
- main.py:158-181 (handler)The handler function for the get_recent_slack_messages tool. It fetches the recent messages from the specified Slack channel using the Slack conversations.history API, retrieves a user name mapping, formats each message with timestamp, user name, and text, and returns them separated by ---.@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)