conversations_add_message
Post messages to Slack channels, threads, or direct messages using markdown or plain text formatting. Requires OAuth authentication and channel targeting.
Instructions
Posts a message to a channel, thread, or DM. Supports markdown and plain text. NOTE: Disabled by default for safety - set SLACK_MCP_ADD_MESSAGE_TOOL environment variable to enable.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| accessToken | Yes | Slack OAuth token (xoxp-... or xoxb-...) with chat:write scope | |
| channel_id | Yes | Target channel ID, name (#general), or DM (@username) | |
| thread_ts | No | Thread timestamp; omit to post to channel directly | |
| payload | Yes | Message content to post | |
| content_type | No | Content format (default: text/markdown) |
Implementation Reference
- src/tools.ts:235-288 (handler)Main execution logic for conversations_add_message tool: validates args with schema, resolves channel ID, checks env-enabled channels, posts message via Slack chat.postMessage, handles errors.export async function conversationsAddMessage(args: any): Promise<ToolResponse> { try { // Safety check - require explicit enable const enabledChannels = process.env.SLACK_MCP_ADD_MESSAGE_TOOL; if (!enabledChannels) { return { success: false, error: 'Message posting is disabled by default for safety. Set SLACK_MCP_ADD_MESSAGE_TOOL environment variable to enable.' }; } const validated = ConversationsAddMessageSchema.parse(args); const client = new WebClient(validated.accessToken); console.log('Posting message to channel:', validated.channel_id); // Resolve channel name/username to ID if needed const channelId = await resolveChannelId(client, validated.channel_id); // Check if channel is in enabled list (if not '*') if (enabledChannels !== '*') { const allowedChannels = enabledChannels.split(',').map(c => c.trim()); if (!allowedChannels.includes(channelId) && !allowedChannels.includes(validated.channel_id)) { return { success: false, error: `Message posting not enabled for channel: ${validated.channel_id}` }; } } // Post message const result = await client.chat.postMessage({ channel: channelId, text: validated.payload, thread_ts: validated.thread_ts, mrkdwn: validated.content_type === 'text/markdown' }); return { success: true, data: { ok: result.ok, channel: result.channel, ts: result.ts, message: result.message } }; } catch (error: any) { if (error.name === 'ZodError') { return { success: false, error: `Validation error: ${error.errors.map((e: any) => e.message).join(', ')}` }; } return handleSlackError(error); } }
- src/schemas.ts:29-39 (schema)Zod input schema for conversations_add_message tool, defining parameters: accessToken, channel_id, optional thread_ts, payload, content_type.* Schema for conversations_add_message tool * Posts messages to channels, threads, or DMs * Note: Disabled by default for safety - requires configuration to enable */ export const ConversationsAddMessageSchema = z.object({ accessToken: z.string().describe("Slack OAuth token (xoxp-... or xoxb-...) with chat:write scope"), channel_id: z.string().describe("Target channel ID, name (#general), or DM (@username)"), thread_ts: z.string().optional().describe("Thread timestamp; omit to post to channel directly"), payload: z.string().describe("Message content to post"), content_type: z.enum(['text/markdown', 'text/plain']).optional().describe("Content format (default: text/markdown)") });
- src/index.ts:106-108 (registration)Tool registration in MCP server's listTools response: specifies name, description, and converts Zod schema to MCP inputSchema.name: 'conversations_add_message', description: 'Posts a message to a channel, thread, or DM. Supports markdown and plain text. NOTE: Disabled by default for safety - set SLACK_MCP_ADD_MESSAGE_TOOL environment variable to enable.', inputSchema: zodToMCPSchema(ConversationsAddMessageSchema)
- src/index.ts:137-139 (registration)Dispatch logic in MCP callTool handler: routes 'conversations_add_message' calls to the conversationsAddMessage function.case 'conversations_add_message': result = await conversationsAddMessage(args); break;