A simple Slack bot that uses the OpenAI Agents SDK to interact with Model Context Protocol (MCP) servers.
See also: agentic-telegram-bot — a similar demo bot for Telegram.
- Channel @mention and DM support
- Thread-aware conversations (follow-ups stay in the same thread)
- Connects to any MCP server via
servers_config.json - Supports OpenAI, Azure OpenAI, and OpenAI-compatible proxy endpoints
- Per-conversation history with automatic truncation
uv sync- Create a new Slack app at api.slack.com/apps.
- Enable Socket Mode and generate an app-level token (
xapp-...). - Under OAuth & Permissions, add the following bot token scopes:
app_mentions:readchat:writeim:historyusers:read
- Under Event Subscriptions, subscribe to:
app_mentionmessage.im
- Install the app to your workspace and copy the bot token (
xoxb-...).
Create a .envrc or .env file in the root directory:
export SLACK_BOT_TOKEN=""
export SLACK_APP_TOKEN=""
export OPENAI_API_KEY=""
export OPENAI_MODEL="gpt-5.4"
If you are using Azure OpenAI, set these instead:
export AZURE_OPENAI_API_KEY=""
export AZURE_OPENAI_ENDPOINT="https://<myopenai>.azure.com/"
export OPENAI_MODEL="gpt-5.4"
export OPENAI_API_VERSION="2025-03-01-preview"
If you are using an OpenAI-compatible proxy:
export OPENAI_PROXY_BASE_URL="https://my-proxy.example.com/v1"
export OPENAI_PROXY_API_KEY=""
Optional HTTP proxy for outbound requests:
export HTTP_PROXY=""
Create a servers_config.json file to add your MCP servers. If this file is not provided, the bot starts with no MCP servers configured.
{
"instructions": "Your custom system prompt here.",
"mcpServers": {
"my-server": {
"command": "uvx",
"args": ["my-mcp-server"]
}
}
}For HTTP-based MCP servers (Streamable HTTP), use httpUrl:
{
"mcpServers": {
"my-server": {
"httpUrl": "https://mcp.example.com/mcp",
"headers": {
"Accept": "application/json, text/event-stream"
}
}
}
}For local MCP servers, use uv --directory:
{
"instructions": "Your custom system prompt here.",
"mcpServers": {
"my-server": {
"command": "uv",
"args": ["--directory", "/path/to/my-server", "run", "my-entrypoint"]
}
}
}uv run botdocker build -t agentic-slackbot .
docker run -d \
--name slackbot \
-e SLACK_BOT_TOKEN="" \
-e SLACK_APP_TOKEN="" \
-e OPENAI_API_KEY="" \
-e OPENAI_MODEL="gpt-5.4" \
agentic-slackbotTo use MCP servers, mount your config file:
docker run -d \
--name slackbot \
-e SLACK_BOT_TOKEN="" \
-e SLACK_APP_TOKEN="" \
-e OPENAI_API_KEY="" \
-e OPENAI_MODEL="gpt-5.4" \
-v /path/to/servers_config.json:/app/servers_config.json \
agentic-slackbotThis project is based on the sooperset/mcp-client-slackbot example.