A Slack app with MCP integration running on Cloudflare Workers.
npm installCreate a .env file with your Slack credentials:
SLACK_SIGNING_SECRET=your_slack_signing_secret
SLACK_BOT_TOKEN=xoxb-your_bot_token
SLACK_APP_TOKEN=xapp-your_app_token
OPENAI_API_KEY=your_openai_api_key
ENCRYPTION_KEY=your_encryption_key
Create your own KV namespace:
# Create production KV namespace
npx wrangler kv namespace create SNACK-KV
# Copy the returned namespace ID and update wrangler.jsonc
# Replace the "id" field in the kv_namespaces sectionNote: The wrangler.jsonc file contains a placeholder KV namespace ID. You must replace it with your own namespace ID after creating it.
Generate Cloudflare Workers types:
npm run update-typesnpm run devFirst, set up your secrets:
# Set up required secrets
wrangler secret put SLACK_SIGNING_SECRET
wrangler secret put SLACK_BOT_TOKEN
wrangler secret put SLACK_APP_TOKEN
wrangler secret put OPENAI_API_KEY
wrangler secret put ENCRYPTION_KEYThen deploy:
npm run deploy- Create a Slack app at api.slack.com
- Set the Event Request URL to:
https://your-worker.your-subdomain.workers.dev/slack/events - Set the Interactive Components Request URL to:
https://your-worker.your-subdomain.workers.dev/slack/events - Subscribe to
message.channelsandmessage.groupsevents - Add the bot to your workspace
-
Create OAuth App in Sentry:
- Go to Settings → Developer Settings → Auth → OAuth Applications
- Create new app with redirect URI:
https://your-worker.your-subdomain.workers.dev/oauth/callback - Select scopes:
project:readandevent:read
-
Set Environment Variables:
wrangler secret put SENTRY_CLIENT_ID wrangler secret put SENTRY_CLIENT_SECRET wrangler secret put SENTRY_REDIRECT_URI
wrangler secret put GITHUB_CLIENT_ID
wrangler secret put GITHUB_CLIENT_SECRET
wrangler secret put GITHUB_REDIRECT_URIImportant: For local development, you'll need to expose your local server to the internet using a tool like ngrok:
# Install ngrok if you haven't already
npm install -g ngrok
# In one terminal, start your dev server
npm run dev
# In another terminal, expose localhost:1337
ngrok http 1337Then use the ngrok URL (e.g., https://abc123.ngrok.io/slack/events) for both the Event Request URL and Interactive Components Request URL in your Slack app settings.
If the Slack buttons are not responding:
- Check Interactive Components URL: Ensure your Slack app has the Interactive Components Request URL set to your worker's
/slack/eventsendpoint - Verify Environment Variables: Make sure all required environment variables are set, including
ENCRYPTION_KEY - Check Logs: Look at the wrangler dev console output for any error messages
- Test with ngrok: For local development, use ngrok to expose your local server to the internet
If you're not seeing logs in the console:
- Check wrangler dev: Make sure
wrangler devis running and you can see the output - Verify endpoint: Test your endpoint with
curl http://localhost:1337/slack/events - Check Slack app logs: Look at your Slack app's event logs in the Slack API dashboard
src/
├── launch.js # Message handling
├── servers.js # Server management
├── tools.js # Tool listing
├── auth.js # Authentication
├── mcp.ts # MCP integration
└── utils/ # Utilities
npm run dev- Start development servernpm run deploy- Deploy to Cloudflare Workersnpm test- Run tests