Enables AI assistants to interact with Slack workspaces through secure OAuth 2.0, providing tools for posting messages, reading channel history, and listing channels across multiple Slack teams.
Click on "Install Server".
Wait a few minutes for the server to deploy. Once ready, it will show a "Started" state.
In the chat, type
@followed by the MCP server name and your instructions, e.g., "@Slack MCP Serverpost 'Meeting starts in 5 minutes' to the general channel"
That's it! The server will respond to your query, and you can continue using it as needed.
Here is a step-by-step guide with screenshots.
Slack MCP Server
A production-ready Model Context Protocol (MCP) server for Slack integration. This server enables AI assistants to interact with Slack workspaces through a secure, multi-tenant OAuth flow.
Features
π Secure OAuth 2.0 Flow - Full Slack OAuth v2 implementation with state validation
π’ Multi-Tenant Support - Handle multiple Slack workspaces simultaneously
π Token Rotation - Automatic token refresh for long-lived installations
π‘οΈ Production Security - CORS, API key protection, Helmet.js, request timeouts
π Structured Logging - Pino logger with configurable log levels
π³ Docker Ready - Multi-stage Dockerfile with non-root user
β‘ MCP Tools - Post messages, read channel history, list channels
Architecture
This server uses the Streamable HTTP transport for MCP, making it suitable for web-based AI assistants. It manages:
OAuth Flow:
/slack/installand/slack/oauth/callbackendpointsMCP Endpoint:
/mcpfor all MCP protocol communicationSession Management: Automatic session pruning with configurable TTL
Installation Storage: Pluggable storage interface (in-memory by default)
Prerequisites
Slack App - Create a Slack app at api.slack.com/apps
Node.js - Version 18+ required
pnpm - Package manager (or npm/yarn)
Quick Start
1. Install Dependencies
2. Configure Environment
Copy the example environment file and fill in your values:
Required variables:
SLACK_CLIENT_ID- From your Slack app's OAuth settingsSLACK_CLIENT_SECRET- From your Slack app's OAuth settingsSLACK_REDIRECT_URI- Your callback URL (e.g.,https://yourdomain.com/slack/oauth/callback)SLACK_SCOPES- Comma-separated bot scopes (e.g.,chat:write,channels:history,channels:read)AFFINITYBOTS_MCP_API_KEY- Secret key to protect your MCP endpoint
3. Run Development Server
The server will start on http://localhost:8080 by default.
4. Install Slack App
Navigate to
http://localhost:8080/slack/installAuthorize the app for your workspace
You'll be redirected back with a success message
5. Use MCP Tools
Connect your MCP client to http://localhost:8080/mcp with:
Authorization header:
Bearer YOUR_AFFINITYBOTS_MCP_API_KEYOrigin header: Must match
ALLOWED_ORIGINSif configured
Available MCP Tools
slack_post_message
Post a message to a Slack channel.
Parameters:
team_id(string) - Slack workspace/team ID (T...)channel_id(string) - Channel/DM ID (C... or D...)text(string) - Message text (1-4000 characters)thread_ts(string, optional) - Thread timestamp to reply to
slack_get_channel_history
Read messages from a Slack channel.
Parameters:
team_id(string) - Slack workspace/team IDchannel_id(string) - Channel/DM IDlimit(number, optional) - Number of messages (1-200, default: 50)
slack_list_channels
List all channels in the workspace.
Parameters:
team_id(string) - Slack workspace/team IDtypes(string, optional) - Channel types:public_channel,private_channel,mpim,im(default:public_channel)limit(number, optional) - Number of channels (1-1000, default: 200)
Configuration
Environment Variables
Variable | Required | Default | Description |
| No |
| Server port |
| No |
| Server host |
| No |
| Public URL for OAuth redirects |
| Yes | - | Slack app client ID |
| Yes | - | Slack app client secret |
| Yes | - | OAuth callback URL |
| Yes | - | Comma-separated bot scopes |
| Recommended | - | API key for MCP endpoint |
| No | - | Comma-separated allowed origins for CORS |
| No |
| MCP session timeout (15 min) |
| No |
| Log level: trace, debug, info, warn, error, fatal |
Required Slack Scopes
At minimum, your Slack app needs these bot token scopes:
chat:write- Post messageschannels:history- Read public channel messageschannels:read- List public channels
Additional recommended scopes:
groups:history- Read private channel messagesgroups:read- List private channelsim:history- Read direct messagesim:read- List direct messagesmpim:history- Read group DM messagesmpim:read- List group DMs
Production Deployment
Using Docker
Build the image:
Run the container:
Production Checklist
Set
AFFINITYBOTS_MCP_API_KEYto a strong random valueConfigure
ALLOWED_ORIGINSwith your frontend domainsUse HTTPS for all endpoints (required by Slack)
Set
PUBLIC_BASE_URLto your public HTTPS URLReplace
InMemoryInstallStorewith persistent storage (Redis/PostgreSQL)Set up monitoring and alerting
Configure log aggregation
Set appropriate
SESSION_TTL_MSfor your use caseEnable Slack token rotation in your app settings (recommended)
Set up rate limiting at the reverse proxy level
Configure health check monitoring on
/health
Storage
The default InMemoryInstallStore is suitable for development but not for production. For production, implement the InstallStore interface with a persistent backend:
Recommended storage options:
PostgreSQL - Best for relational data and complex queries
Redis - Fast, simple key-value storage
MongoDB - Document-based storage
DynamoDB - Serverless AWS option
Security Features
Implemented
β CSRF protection via OAuth state parameter
β API key authentication for MCP endpoint
β CORS with origin allowlist
β Helmet.js security headers
β Request timeouts (30s)
β Session expiration and pruning
β Automatic token refresh
β Secure error messages (no info leakage)
β Non-root Docker user
Recommended Additional Security
Add rate limiting (e.g., express-rate-limit)
Use a reverse proxy (nginx, Caddy) with TLS
Implement request size limits
Add request ID tracking
Set up WAF rules
Enable Slack signing secret verification for webhooks (if added)
Monitoring
Health Check
Returns ok if the server is running.
Logs
The server uses structured JSON logging via Pino. Key log events:
OAuth flow initiation and completion
MCP session creation and expiration
Token refresh operations
API errors and warnings
Security events (unauthorized access, invalid origins)
Set LOG_LEVEL=debug for detailed debugging.
Troubleshooting
OAuth Errors
"Invalid or expired state"
The OAuth state token expired (10 min TTL)
Try the installation flow again
"Slack OAuth failed: invalid_code"
The authorization code was already used or expired
Restart the installation flow
"Origin not allowed"
Your frontend origin is not in
ALLOWED_ORIGINSAdd your origin to the environment variable
MCP Errors
"Unauthorized"
Missing or invalid
AuthorizationheaderEnsure you're sending
Bearer YOUR_API_KEY
"Unknown or expired session"
MCP session expired (default 15 min)
Reinitialize the MCP connection
"No Slack installation found"
The workspace hasn't installed the app
Complete the OAuth flow first
Token Errors
"Token refresh failed"
The refresh token is invalid or revoked
User needs to reinstall the app
Check if token rotation is enabled in Slack app settings
Development
Project Structure
Adding New Tools
Register new tools in src/mcp.ts:
Testing
License
MIT
Support
For issues and questions:
Check the IMPLEMENTATION.md guide
Review Slack API documentation at api.slack.com
Check MCP documentation at modelcontextprotocol.io
Contributing
Contributions welcome! Please:
Follow the existing code style
Add tests for new features
Update documentation
Ensure all lints pass