A Model Context Protocol (MCP) server that enables sending messages to Slack through webhooks. This server provides a single tool send_message
for sending formatted messages to Slack channels.
- Send messages to Slack via webhook URLs
- Support for channel override, custom usernames, and icons
- Markdown formatting support
- Comprehensive error handling
- Docker support with multi-stage builds
- Go 1.23 or later
- A Slack webhook URL (see Slack's documentation for setup)
- Docker (optional, for containerized deployment)
git clone <repository-url>
cd mcp-slack-webhook
go mod download
go build -o mcp-slack-webhook .
docker build -t mcp-slack-webhook .
docker run -e SLACK_WEBHOOK_URL="https://hooks.slack.com/services/YOUR/WEBHOOK/URL" mcp-slack-webhook
First, set the required environment variable:
export SLACK_WEBHOOK_URL="https://hooks.slack.com/services/YOUR/WEBHOOK/URL"
Then run the server:
./mcp-slack-webhook
The server will start and listen for MCP protocol messages on stdin/stdout.
The server provides a single tool called send_message
with the following parameters:
text
(string): The message text to send
SLACK_WEBHOOK_URL
: The Slack webhook URL to send messages to
channel
(string): The channel to send the message to (overrides webhook default)username
(string): Username to display as the sendericon_emoji
(string): Emoji to use as the icon (e.g.,:robot_face:
)icon_url
(string): URL to an image to use as the iconmarkdown
(boolean): Whether to enable markdown formatting (default: true)
First, set the environment variable:
export SLACK_WEBHOOK_URL="https://hooks.slack.com/services/YOUR/WEBHOOK/URL"
Then call the tool:
{
"jsonrpc": "2.0",
"id": "1",
"method": "tools/call",
"params": {
"name": "send_message",
"arguments": {
"text": "Hello from MCP! This is a *test* message.",
"channel": "#general",
"username": "MCP Bot",
"icon_emoji": ":robot_face:",
"markdown": true
}
}
}
- Go to Slack API: Incoming Webhooks
- Create a new webhook for your workspace
- Copy the webhook URL for use with this server
SLACK_WEBHOOK_URL
: The Slack webhook URL for sending messages
You may also want to configure:
- Logging levels
- Authentication (not implemented in this basic version)
The included Dockerfile uses a multi-stage build for optimal image size:
# Build the image
docker build -t mcp-slack-webhook .
# Run the container
docker run -i -e SLACK_WEBHOOK_URL="https://hooks.slack.com/services/YOUR/WEBHOOK/URL" mcp-slack-webhook
For production use, you might want to:
# Run with environment file
docker run -i --env-file .env mcp-slack-webhook
# Or run with secrets management
docker run -i -e SLACK_WEBHOOK_URL="$(cat /path/to/webhook_url_secret)" mcp-slack-webhook
mcp-slack-webhook/
├── main.go # Main application code
├── go.mod # Go module dependencies
├── go.sum # Go dependency checksums
├── Dockerfile # Multi-stage Docker build
└── README.md # This file
- github.com/mark3labs/mcp-go v0.32.0 - MCP protocol implementation
# Regular build
go build -o mcp-slack-webhook .
# Cross-compile for Linux
GOOS=linux GOARCH=amd64 go build -o mcp-slack-webhook-linux .
# Run tests (when available)
go test ./...
# Test Docker build
docker build -t mcp-slack-webhook-test .
Messages sent to Slack follow the webhook format:
{
"text": "Your message text",
"channel": "#channel-name",
"username": "Bot Name",
"icon_emoji": ":robot_face:",
"icon_url": "https://example.com/icon.png",
"mrkdwn": true
}
The server handles various error conditions:
- Invalid webhook URLs
- Missing required parameters
- Slack API errors
- Network connectivity issues
All errors are returned as MCP tool result errors with descriptive messages.
- Webhook URLs are securely stored as environment variables and not exposed in tool calls
- Webhook URLs should never be logged or exposed in debug output
- Consider implementing authentication for production use
- Validate input parameters to prevent injection attacks
- Use HTTPS webhook URLs only
- In production, use secure secret management systems instead of plain environment variables
[Add your license information here]
[Add contribution guidelines here]