How to use Slack MCP server
Quick answer
Use the
mcp Python SDK to create a Slack MCP server that connects AI agents to Slack via the Model Context Protocol. Implement the server with mcp.server.stdio.stdio_server or a custom transport, then run it to handle Slack events and commands. This enables seamless AI integration with Slack workflows.PREREQUISITES
Python 3.8+pip install mcpSlack app with bot token and event subscriptions configuredEnvironment variable SLACK_BOT_TOKEN setBasic knowledge of Slack API and MCP protocol
Setup
Install the mcp Python package and set your Slack bot token as an environment variable. Ensure your Slack app has event subscriptions enabled and the bot token has necessary scopes.
pip install mcp Step by step
This example shows how to create a basic Slack MCP server using the mcp SDK's stdio transport. The server listens for Slack events and responds to messages.
import os
from mcp.server import Server
from mcp.server.stdio import stdio_server
# Define a simple handler for Slack events
async def handle_message(event):
if event.get('type') == 'message' and 'text' in event:
text = event['text']
user = event.get('user', 'unknown')
print(f"Received message from {user}: {text}")
# Here you can add AI agent logic or respond back
async def main():
# Create MCP server instance
server = Server()
# Register event handler
server.register_handler('event_callback', handle_message)
# Run the stdio MCP server (connects Slack events via stdio)
await stdio_server(server)
if __name__ == '__main__':
import asyncio
asyncio.run(main()) output
Received message from U123456: Hello from Slack!
Common variations
- Use different MCP transports like SSE or WebSocket instead of stdio for production.
- Integrate with AI models by calling OpenAI or Anthropic APIs inside event handlers.
- Use async frameworks like FastAPI to embed MCP server in a web app.
- Customize event handlers to respond to commands, mentions, or interactive components.
Troubleshooting
- If the server does not receive events, verify Slack event subscription URLs and bot token scopes.
- Check environment variables are correctly set before running the server.
- Use logging inside handlers to debug event payloads.
- Ensure Python version is 3.8 or higher to support async MCP server.
Key Takeaways
- Use the official
mcpPython SDK to build Slack MCP servers with async handlers. - Run the MCP server with
stdio_serverfor local development and testing. - Customize event handlers to integrate AI models and respond to Slack events.
- Ensure Slack app configuration and environment variables are correct for event delivery.