Post Slack Message
slack_post_messagePost a message to a Slack channel or direct message using channel ID and text content.
Instructions
Post a new message to a Slack channel or direct message to user
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| channel_id | Yes | The ID of the channel or user to post to | |
| text | Yes | The message text to post |
Implementation Reference
- index.ts:248-264 (registration)Registration of the 'slack_post_message' tool on the MCP server with its schema and handler callback.
server.registerTool( "slack_post_message", { title: "Post Slack Message", description: "Post a new message to a Slack channel or direct message to user", inputSchema: { channel_id: z.string().describe("The ID of the channel or user to post to"), text: z.string().describe("The message text to post"), }, }, async ({ channel_id, text }) => { const response = await slackClient.postMessage(channel_id, text); return { content: [{ type: "text", text: JSON.stringify(response) }], }; } ); - index.ts:17-20 (schema)TypeScript interface PostMessageArgs defining the input schema for the tool (channel_id and text).
interface PostMessageArgs { channel_id: string; text: string; } - index.ts:258-263 (handler)The handler function that executes the 'slack_post_message' tool logic, delegating to slackClient.postMessage().
async ({ channel_id, text }) => { const response = await slackClient.postMessage(channel_id, text); return { content: [{ type: "text", text: JSON.stringify(response) }], }; } - index.ts:111-122 (helper)SlackClient.postMessage() helper method that makes the actual HTTP POST to Slack's chat.postMessage API.
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(); }