search_messages
Find Slack messages containing specified text and return matching results with an optional limit on the number of messages.
Instructions
Search for messages in Slack containing specific text
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| query | Yes | Search query (e.g., 'build failed', 'Cuti-E-Admin') | |
| limit | No | Maximum number of results (default: 10) |
Implementation Reference
- index.js:87-105 (registration)Tool 'search_messages' is registered in the ListToolsRequestSchema handler with name, description, and inputSchema.
{ name: "search_messages", description: "Search for messages in Slack containing specific text", inputSchema: { type: "object", properties: { query: { type: "string", description: "Search query (e.g., 'build failed', 'Cuti-E-Admin')", }, limit: { type: "number", description: "Maximum number of results (default: 10)", default: 10, }, }, required: ["query"], }, }, - index.js:88-105 (schema)Input schema for search_messages: requires 'query' (string), optional 'limit' (number, default 10).
name: "search_messages", description: "Search for messages in Slack containing specific text", inputSchema: { type: "object", properties: { query: { type: "string", description: "Search query (e.g., 'build failed', 'Cuti-E-Admin')", }, limit: { type: "number", description: "Maximum number of results (default: 10)", default: 10, }, }, required: ["query"], }, }, - index.js:338-390 (handler)Handler for 'search_messages' tool. Calls Slack search.messages API with the query and limit, formats results with timestamp, channel, text, and user. Handles missing_scope error for search:read permission.
case "search_messages": { const query = args?.query; if (!query) { return { content: [ { type: "text", text: "Error: query parameter is required", }, ], }; } const limit = Math.min(args?.limit || 10, 100); try { const result = await slack.search.messages({ query: query, count: limit, sort: "timestamp", sort_dir: "desc", }); const matches = (result.messages?.matches || []).map((match) => ({ timestamp: new Date(parseFloat(match.ts) * 1000).toISOString(), channel: match.channel?.name, text: match.text?.substring(0, 500), user: match.user, })); return { content: [ { type: "text", text: JSON.stringify({ results: matches, total: result.messages?.total || 0 }, null, 2), }, ], }; } catch (error) { // Search requires additional OAuth scopes if (error.data?.error === "missing_scope") { return { content: [ { type: "text", text: "Error: Bot token missing 'search:read' scope. Add it in your Slack App settings.", }, ], }; } throw error; } }