search_messages
Search for messages in a Slack workspace using a query, with options to sort by relevance or timestamp and control the number of results returned.
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 |
|---|---|---|---|
| count | No | ||
| query | Yes | ||
| sort | No | timestamp | |
| sort_dir | No | desc |
Implementation Reference
- slack_mcp/server.py:368-384 (handler)MCP tool handler for search_messages that creates a SlackClient instance, calls its search_messages method with provided parameters, and returns the JSON-formatted result or error.@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)SlackClient helper method that makes an authenticated GET request to Slack's search.messages API endpoint with the search 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)