Skip to content

John-Lin/agentic-slackbot

Repository files navigation

agentic-slackbot

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.

Features

  • 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

Install Dependencies

uv sync

Slack App Setup

  1. Create a new Slack app at api.slack.com/apps.
  2. Enable Socket Mode and generate an app-level token (xapp-...).
  3. Under OAuth & Permissions, add the following bot token scopes:
    • app_mentions:read
    • chat:write
    • im:history
    • users:read
  4. Under Event Subscriptions, subscribe to:
    • app_mention
    • message.im
  5. Install the app to your workspace and copy the bot token (xoxb-...).

Environment Variables

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=""

MCP Server Configuration (Optional)

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"]
    }
  }
}

Running the Bot

uv run bot

Docker

docker 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-slackbot

To 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-slackbot

Credit

This project is based on the sooperset/mcp-client-slackbot example.

About

An agentic Slack bot with MCP support.

Resources

Stars

Watchers

Forks

Packages

 
 
 

Contributors