M8B is a grumpy but competent Slack bot that helps solve IT issues. It uses OpenAI for reasoning and can query one or more MetricsHub MCP servers for real metrics. Built with Slack Bolt (Node.js).
- 🤖 AI-powered IT troubleshooting using OpenAI GPT models
- 📊 Real-time metrics from MetricsHub MCP servers
- 🔍 Prometheus PromQL query support
- 📁 File analysis (images, PDFs, code files)
- 🧠 Knowledge base with vector store search
- 💬 Slack-native with streaming responses
- 🔧 Grumpy personality for maximum entertainment
m8b-slackbot/
├── app.js # Application entry point
├── ai/
│ ├── index.js # AI module exports
│ ├── respond.js # Main response orchestrator
│ ├── mcp_registry.js # MCP server management
│ ├── prometheus.js # Prometheus PromQL integration
│ ├── config/
│ │ └── system-prompt.js # Bot personality and configuration
│ ├── services/
│ │ ├── openai.js # OpenAI client and helpers
│ │ ├── streaming.js # Response streaming handler
│ │ ├── context-manager.js # Conversation context management
│ │ ├── function-calls.js # Tool call processing
│ │ ├── slack-files.js # File upload handling
│ │ └── citations.js # Citation post-processing
│ ├── tools/
│ │ └── index.js # Tool definitions
│ └── utils/
│ ├── tokens.js # Token estimation utilities
│ ├── output-handler.js # Large output handling
│ └── json-parser.js # JSON parsing utilities
├── listeners/
│ ├── actions/ # Slack action handlers
│ ├── assistant/ # Assistant thread handlers
│ └── events/ # Event handlers (app_mention, etc.)
└── tests/ # Test files (in __tests__ directories)
- Node.js 20+ and npm
- A Slack workspace where you can install apps
- OpenAI API key
- Optional: MetricsHub MCP servers (URLs + API tokens)
- Optional: Prometheus server for PromQL queries
- Clone and install dependencies:
git clone https://github.com/MetricsHub/m8b-slack.git
cd m8b-slack
npm install- Create
.envfile:
cp .env.example .env
# Edit .env with your tokens- Start the bot:
npm start
# Or with auto-reload:
npm run dev| Script | Description |
|---|---|
npm start |
Start the bot |
npm run dev |
Start with auto-reload (watch mode) |
npm test |
Run tests |
npm run test:watch |
Run tests in watch mode |
npm run test:coverage |
Run tests with coverage report |
npm run lint |
Check code with Biome |
npm run lint:fix |
Fix linting issues |
npm run format |
Format code |
npm run check |
TypeScript type checking |
npm run validate |
Run lint + check + test |
# Required
SLACK_BOT_TOKEN=xoxb-...
SLACK_APP_TOKEN=xapp-...
OPENAI_API_KEY=sk-...
# Optional
NODE_ENV=production
SLACK_API_URL=https://slack.com/api
# MetricsHub MCP Server (single server mode)
MCP_AGENT_URL=https://metricshub.example.com/sse
MCP_AGENT_TOKEN=...
# Prometheus
M8B_PROMETHEUS_URL=http://prometheus.example.com:9090
# OpenAI Vector Stores (for knowledge base)
OPENAI_VECTOR_STORE_IDS=vs_123,vs_456
# Or single ID:
OPENAI_VECTOR_STORE_ID=vs_123Create ai/mcp.config.local.js (not tracked by git):
export default [
{
server_label: "metricshub-paris",
server_url: process.env.MCP_PARIS_URL,
token: process.env.MCP_PARIS_TOKEN,
},
{
server_label: "metricshub-nyc",
server_url: process.env.MCP_NYC_URL,
token: process.env.MCP_NYC_TOKEN,
},
];- Go to https://api.slack.com/apps/new and choose "From an app manifest"
- Pick your workspace
- Paste the contents of
manifest.json(JSON tab) and click Next - Review and Create the app
- On the app page, go to Install App and install to your workspace
You will need two tokens from Slack:
- SLACK_BOT_TOKEN (Bot User OAuth Token)
- SLACK_APP_TOKEN (App-level token with
connections:write)
Basic systemd service (/etc/systemd/system/m8b-slack.service):
[Unit]
Description=M8B Slack Bot
After=network.target
[Service]
Type=simple
User=m8b
WorkingDirectory=/opt/m8b-slack
EnvironmentFile=/etc/m8b-slack.env
ExecStart=/usr/bin/node app.js
Restart=always
RestartSec=10
[Install]
WantedBy=multi-user.target# Run all tests
npm test
# Run with coverage
npm run test:coverage
# Watch mode
npm run test:watch# Check linting
npm run lint
# Fix linting issues
npm run lint:fix
# Format code
npm run format
# Type checking
npm run check
# Run all validations
npm run validateThe codebase is organized into clear modules:
- Config: System prompts, model settings, constants
- Services: Core business logic (OpenAI, streaming, context)
- Tools: Function definitions for AI tool calls
- Utils: Helper functions (token counting, output handling)
Each module is testable and has a single responsibility.
- Fork the repository
- Create a feature branch
- Make your changes
- Run
npm run validateto ensure quality - Submit a pull request
MIT License - see LICENSE for details.