slack_post_message
Send messages directly to a specified Slack channel using the Slack MCP Server, enabling integration with MCP clients for streamlined communication and collaboration.
Instructions
Post a new message to a Slack channel
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| channel_id | Yes | The Channel ID to post the message to | |
| text | Yes | The message text to post |
Implementation Reference
- src/index.ts:40-52 (handler)Executes the slack_post_message tool: validates input arguments, calls slackClient.postMessage, and returns the JSON response.case "slack_post_message": { const args = request.params.arguments as unknown as PostMessageArgs; if (!args.channel_id || !args.text) { throw new Error("Missing required arguments: channel_id and text"); } const response = await slackClient.postMessage( args.channel_id, args.text ); return { content: [{ type: "text", text: JSON.stringify(response) }], }; }
- src/slack/messages.ts:3-25 (schema)Defines the input schema and Tool object for slack_post_message, including PostMessageArgs interface and inputSchema.export interface PostMessageArgs { channel_id: string; text: string; } export const postMessageTool: Tool = { name: "slack_post_message", description: "Post a new message to a Slack channel", inputSchema: { type: "object", properties: { channel_id: { type: "string", description: "The Channel ID to post the message to", }, text: { type: "string", description: "The message text to post", }, }, required: ["channel_id", "text"], }, };
- src/index.ts:25-29 (registration)Registers the slack_post_message tool (as postMessageTool) in the list of available tools.server.setRequestHandler(ListToolsRequestSchema, async () => { return { tools: [getUsersTool, postMessageTool], }; });
- src/slack/client.ts:34-45 (helper)Implements the core Slack API call for posting a message, used by the tool handler.async postMessage(channel_id: string, text: string): Promise<any> { const response = await fetch("https://slack.com/api/chat.postMessage", { method: "POST", headers: this.botHeaders, body: JSON.stringify({ channel: channel_id, text: text, }), }); return response.json(); }