post_message
Send messages to Slack channels to communicate updates, share information, or coordinate team activities directly from the MCP server.
Instructions
Post a message to a Slack channel.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| channel_id | Yes | ||
| text | Yes |
Implementation Reference
- main.py:145-156 (handler)The handler function for the 'post_message' tool. It is registered via @mcp.tool() decorator and implements posting a message to a Slack channel by calling the Slack chat.postMessage API using the make_slack_request helper. Input schema derived from type hints: channel_id (str), text (str).@mcp.tool() async def post_message(channel_id: str, text: str) -> str: """Post a message to a Slack channel.""" params = { "channel": channel_id, "text": text } data = await make_slack_request("chat.postMessage", params) if data and data.get("ok"): return "✅ Message posted successfully!" return f"❌ Failed to post message. Error: {data.get('error', 'Unknown')}"
- main.py:19-33 (helper)Helper function used by post_message (and other tools) to make authenticated HTTP requests to the Slack Web API.async def make_slack_request(method: str, params: dict[str, Any] | None = None) -> dict[str, Any] | None: """Make a request to the Slack Web API with proper error handling.""" headers = { "Authorization": f"Bearer {SLACK_TOKEN}", "Content-Type": "application/x-www-form-urlencoded" } async with httpx.AsyncClient() as client: try: response = await client.post(f"{SLACK_API_BASE}/{method}", data=params, headers=headers, timeout=10.0) response.raise_for_status() return response.json() except Exception as e: print(f"Slack API error: {e}") return None