search_messages
Find specific messages in your Slack workspace by entering search terms to locate conversations, information, or discussions across channels.
Instructions
Search for messages across the workspace
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| query | Yes | Search query | |
| count | No | Number of results to return | |
| sort | No | Sort order | score |
Implementation Reference
- src/tools/messages.ts:86-101 (handler)The main handler function for the 'search_messages' tool. It validates input using searchMessagesSchema, calls Slack's search.messages API via the client, and returns formatted results including messages and total count.export async function searchMessages(client: SlackClientWrapper, args: unknown) { const params = searchMessagesSchema.parse(args); return await client.safeCall(async () => { const result = await client.getClient().search.messages({ query: params.query, count: params.count, sort: params.sort, }); return { messages: result.messages, total: result.messages?.total || 0, }; }); }
- src/utils/validators.ts:72-76 (schema)Zod schema used for input validation in the searchMessages handler.export const searchMessagesSchema = z.object({ query: z.string().min(1), count: z.number().min(1).max(100).optional().default(20), sort: z.enum(['score', 'timestamp']).optional().default('score'), });
- src/index.ts:430-430 (registration)Registration of the 'search_messages' tool handler in the toolHandlers map, linking the tool name to the searchMessages function from messageTools.search_messages: (args) => messageTools.searchMessages(slackClient, args),
- src/index.ts:264-289 (registration)Tool specification in the tools array, including name, description, and inputSchema for the MCP list_tools endpoint.{ name: 'search_messages', description: 'Search for messages across the workspace', inputSchema: { type: 'object', properties: { query: { type: 'string', description: 'Search query', }, count: { type: 'number', description: 'Number of results to return', default: 20, minimum: 1, maximum: 100, }, sort: { type: 'string', enum: ['score', 'timestamp'], description: 'Sort order', default: 'score', }, }, required: ['query'], },