search_messages
Find specific messages in your Slack workspace by entering search queries, with options to sort results by relevance or date and control the number of returned items.
Instructions
Search for messages across the Slack workspace.
Args: query: Search query sort: Sort by 'score' or 'timestamp' sort_dir: Sort direction 'asc' or 'desc' count: Number of results to return
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| query | Yes | ||
| sort | No | timestamp | |
| sort_dir | No | desc | |
| count | No |
Implementation Reference
- slack_mcp/server.py:368-384 (handler)The primary MCP tool handler for 'search_messages', decorated with @mcp.tool() which also handles registration. It creates a SlackClient instance and calls its search_messages method, returning JSON results.@mcp.tool() async def search_messages(query: str, sort: str = "timestamp", sort_dir: str = "desc", count: int = 20) -> str: """ Search for messages across the Slack workspace. Args: query: Search query sort: Sort by 'score' or 'timestamp' sort_dir: Sort direction 'asc' or 'desc' count: Number of results to return """ try: client = SlackClient() result = await client.search_messages(query, sort, sort_dir, count) return json.dumps(result, indent=2) except Exception as e: return json.dumps({"error": str(e)}, indent=2)
- slack_mcp/server.py:151-156 (helper)Helper method in SlackClient class that makes the actual Slack API call to 'search.messages' endpoint with the provided parameters.async def search_messages( self, query: str, sort: str = "timestamp", sort_dir: str = "desc", count: int = 20 ) -> Dict[str, Any]: """Search for messages across the workspace.""" params = {"query": query, "sort": sort, "sort_dir": sort_dir, "count": count} return await self._make_request("GET", "search.messages", params=params)