Labsco
tuannvm logo

Slack MCP Client in Go

β˜… 171

from tuannvm

A Slack bot client that bridges Slack and Model Context Protocol (MCP) servers, enabling LLMs to use MCP tools.

πŸ”₯πŸ”₯πŸ”₯βœ“ VerifiedFreeAdvanced setup

Slack MCP Client

A production-ready bridge between Slack and AI models with full MCP compatibility.

This client enables AI models (OpenAI GPT-4.1, Anthropic Claude 4.5, Ollama local models) to interact with real tools and systems through Slack conversations. Built on the industry-standard Model Context Protocol (MCP), it provides secure access to filesystems, databases, Kubernetes clusters, Git repositories, and custom tools.

GitHub Workflow Status Go Version Trivy Scan Docker Image GitHub Release License: MIT

Compatible with MCP Specification 2025-06-18 - Compliant with the latest Model Context Protocol standards

Recent Updates

Oct 2025: langchaingo v0.1.14 with streaming fixes, enhanced agent parsing, and API key sanitization.

Key Features

  • Universal MCP Compatibility - Supports all transport methods (HTTP, SSE, stdio)
  • Multi-Provider LLM Support - OpenAI GPT-4.1/4o, Anthropic Claude 4.5, Ollama (Llama 3.3, Qwen, Mistral, DeepSeek)
  • Agent Mode - Multi-step reasoning with LangChain for complex workflows
  • RAG Integration - Knowledge base with semantic search capabilities
  • Thread-Aware Context - Maintains separate conversation history per Slack thread
  • User Context Integration - Personalized responses with cached user information
  • Unique Tool Naming - Server-prefixed tool names prevent conflicts across MCP servers
  • Production Ready - Comprehensive configuration, monitoring, and security

Use Cases

  • DevOps Teams - Infrastructure automation and monitoring through Slack
  • Development Teams - Code review, Git operations, and file management
  • Support Teams - Database queries, system status checks, and troubleshooting
  • General Use - AI assistance with actual tools and system integration

MCP Compatibility

Compliant with the official Model Context Protocol (2025-06-18 specification):

  • All Transport Methods - HTTP, SSE, and stdio protocols
  • JSON-RPC 2.0 - Standard communication protocol
  • Official MCP Servers - Compatible with all modelcontextprotocol/servers
  • Custom MCP Servers - Works with any MCP-compliant server
  • Security Standards - Implements user consent, data privacy, and tool safety requirements

Authenticating to SSE MCP Servers

Authentication with Server-Sent Events (SSE) MCP servers can be achieved using the following setup:

Example:

Copy & paste β€” that's it
{
  "httpHeaders": {
    "Authorization": "Bearer YOUR_TOKEN_HERE"
  }
}

Make sure to replace YOUR_TOKEN_HERE with your actual token for authentication.

How It Works

Image

Copy & paste β€” that's it
flowchart LR
    User([πŸ‘€ User]) --> Slack{πŸ”— Slack Interface}

    subgraph Infrastructure[Observability]
        Config[πŸ“‹ Unified Config<br/>JSON Schema]
        Monitoring[πŸ“Š Monitoring<br/>Prometheus Metrics]
        Tracing[πŸ” OpenTelemetry Tracing<br/>Langfuse & OTLP]
        Logging[πŸ“ Structured Logging<br/>Debug & Analytics]
    end
    
    subgraph Core[Features]
        Slack --> Bridge[πŸŒ‰ LLM-MCP Bridge<br/>Orchestration Layer]
        
        subgraph LLM[πŸ€– AI Processing]
            Bridge --> LLMRegistry[LLM Provider Registry]
            LLMRegistry --> OpenAI[OpenAI<br/>GPT-4o]
            LLMRegistry --> Anthropic[Anthropic<br/>Claude]
            LLMRegistry --> Ollama[Ollama<br/>Local Models]
            
            Bridge --> Agent{🎯 Agent Mode?}
            Agent -->|Yes| LangChain[πŸ”„ LangChain Agent<br/>Multi-step Reasoning]
            Agent -->|No| Standard[⚑ Standard Mode<br/>Single Response]
        end
        
        subgraph Knowledge[πŸ“š Knowledge & Memory]
            Bridge --> RAG[🧠 RAG System]
            RAG --> SimpleRAG[πŸ“„ JSON Store<br/>Simple Documents]
            RAG --> VectorRAG[πŸ” OpenAI Vector Store<br/>Semantic Search]
        end
        
        subgraph Tools[πŸ› οΈ MCP Mode]
            Bridge --> MCPManager[MCP Client]
            MCPManager --> FileSystem[πŸ“ Filesystem MCP Server<br/>Read/Write Files]
            MCPManager --> Git[🌿 Git MCP Server <br/>Repository Tools]
            MCPManager --> Kubernetes[☸️ Kubernetes MCP Server<br/>Cluster Management]
        end
    end
    
    
    Config -.-> Core
    Core -.-> Monitoring
    Core -.-> Tracing
    Core -.-> Logging
    
    style Core fill:#F8F9FA,stroke:#6C757D,stroke-width:3px
    style LLM fill:#E3F2FD,stroke:#1976D2,stroke-width:2px
    style Knowledge fill:#E8F5E8,stroke:#388E3C,stroke-width:2px
    style Tools fill:#FFF3E0,stroke:#F57C00,stroke-width:2px
    style Infrastructure fill:#F3E5F5,stroke:#7B1FA2,stroke-width:2px
    
    style User fill:#4CAF50,stroke:#2E7D32,stroke-width:2px,color:#fff
    style Slack fill:#4A90E2,stroke:#1565C0,stroke-width:2px,color:#fff
    style Bridge fill:#FF9800,stroke:#E65100,stroke-width:2px,color:#fff
    style LangChain fill:#9C27B0,stroke:#4A148C,stroke-width:2px,color:#fff
    style RAG fill:#2196F3,stroke:#0D47A1,stroke-width:2px,color:#fff
  1. User interacts through Slack, sending messages that trigger intelligent AI workflows
  2. LLM-MCP Bridge serves as the intelligent orchestration layer that:
    • Routes requests to appropriate LLM providers (OpenAI, Anthropic, Ollama)
    • Chooses between Agent Mode (multi-step reasoning) or Standard Mode (single response)
    • Integrates RAG system for knowledge retrieval and context enhancement
    • Manages tool discovery and execution across multiple MCP servers
  3. Knowledge & Memory system provides contextual intelligence:
    • Simple JSON store for lightweight document storage
    • OpenAI Vector Store for semantic search and enterprise-grade RAG
  4. Tool Ecosystem connects to diverse external systems:
    • Filesystem operations for file management
    • Git integration for repository interactions
    • Kubernetes cluster management and monitoring
    • Custom tools via HTTP, SSE, or stdio protocols
  5. Infrastructure ensures production-ready deployment:
    • Unified JSON configuration with environment variable support
    • Prometheus metrics for observability and monitoring
    • OpenTelemetry tracing with Langfuse and OTLP providers
    • Structured logging for debugging and analytics

Features

  • βœ… Multi-Mode MCP Client:
    • Server-Sent Events (SSE) for real-time communication with automatic retry
    • HTTP transport for JSON-RPC
    • stdio for local development and testing
  • βœ… Slack Integration:
    • Uses Socket Mode for secure, firewall-friendly communication
    • Works with both channels and direct messages
    • Rich message formatting with Markdown and Block Kit
    • Thread-aware conversation tracking with separate context per thread
    • User context caching for personalized interactions
    • Customizable bot behavior and message history
  • βœ… Multi-Provider LLM Support:
    • OpenAI (GPT-4.1, GPT-4o, o3-pro)
    • Anthropic (Claude Sonnet 4.5, Opus 4.1)
    • Ollama (Llama 3.3, Qwen2.5, Mistral, DeepSeek)
    • Native tool calling and unified LangChain gateway
  • βœ… Agent Mode:
    • Autonomous AI agents powered by LangChain (langchaingo v0.1.14)
    • Enhanced multi-step reasoning and tool orchestration
    • Improved parsing for complex multi-line tool calls
    • Configurable agent iterations and behavior
    • Reliable streaming responses with memory leak fixes
    • Advanced prompt engineering capabilities
  • βœ… RAG (Retrieval-Augmented Generation):
    • Multiple providers: Simple JSON storage, OpenAI Vector Store
    • Reusable vector stores with vectorStoreId support
    • Configurable search parameters and similarity metrics
    • PDF ingestion with intelligent chunking
    • CLI tools for document management
  • βœ… Unified Configuration:
    • Single JSON configuration file with JSON schema validation
    • Comprehensive timeout and retry configuration
    • Environment variable substitution and overrides
    • All underlying package options exposed
    • Smart defaults with full customization capability
    • Server-prefixed tool names to prevent naming conflicts
  • βœ… Production Ready:
    • Docker container support with GHCR publishing
    • Kubernetes Helm charts with OCI registry
    • Comprehensive logging and error handling
    • Test coverage with security scanning
  • βœ… Monitoring & Observability:
    • Prometheus metrics integration
    • Tool invocation tracking with error rates
    • LLM token usage monitoring by model and type
    • OpenTelemetry tracing with Langfuse and simple providers
    • Configurable observability providers with graceful fallbacks
    • Comprehensive span tracking for LLM operations and tool calls
    • Configurable metrics endpoint and logging levels

LLM Integration

The client supports multiple LLM providers through a flexible integration system:

LangChain Gateway

The LangChain gateway enables seamless integration with various LLM providers:

  • OpenAI: Native support for GPT models (default)
  • Ollama: Local LLM support for models like Llama, Mistral, etc.
  • Extensible: Can be extended to support other LangChain-compatible providers

LLM-MCP Bridge

The custom LLM-MCP bridge layer enables any LLM to use MCP tools without requiring native function-calling capabilities:

  • Universal Compatibility: Works with any LLM, including those without function-calling
  • Pattern Recognition: Detects when a user prompt or LLM response should trigger a tool call
  • Natural Language Support: Understands both structured JSON tool calls and natural language requests

Configuration

LLM providers can be configured via environment variables or command-line flags:

Copy & paste β€” that's it
# Set OpenAI as the provider (default)
export LLM_PROVIDER="openai"
export OPENAI_MODEL="gpt-4.1"  # or gpt-4o, o3-pro

# Use Anthropic
export LLM_PROVIDER="anthropic"
export ANTHROPIC_API_KEY="your-anthropic-api-key"
export ANTHROPIC_MODEL="claude-sonnet-4.5"  # or claude-opus-4.1

# Or use Ollama
export LLM_PROVIDER="ollama"
export LANGCHAIN_OLLAMA_URL="http://localhost:11434"
export LANGCHAIN_OLLAMA_MODEL="llama3.3"  # or qwen2.5-coder, mistral-small-3, deepseek-r1

Switching Between Providers

You can easily switch between providers by changing the LLM_PROVIDER environment variable:

Copy & paste β€” that's it
# Use OpenAI
export LLM_PROVIDER=openai

# Use Anthropic
export LLM_PROVIDER=anthropic

# Use Ollama (local)
export LLM_PROVIDER=ollama

Automatic Reload Feature

The client supports optional automatic reloading to handle MCP server restarts without downtime - perfect for Kubernetes deployments where MCP servers may restart independently.

Note: The reload feature is disabled by default and must be explicitly enabled in your configuration file.

Configuration

To enable reload functionality, add reload settings to your config.json:

Copy & paste β€” that's it
{
  "version": "2.0",
  "reload": {
    "enabled": true,
    "interval": "30m"
  }
}

Configuration Options:

  • enabled: Must be set to true to activate reload functionality (default: false)
  • interval: Time between automatic reloads (default: "30m", minimum: "10s")

Usage

Automatic Reload: When enabled, the application automatically reloads at the configured interval to reconnect to MCP servers and refresh tool discovery.

Manual Reload: Even with automatic reload disabled, you can trigger manual reloads using signals:

Copy & paste β€” that's it
# In Kubernetes
kubectl exec -it <pod-name> -- kill -USR1 1

# Local process
kill -USR1 <process-id>

Benefits

  • Zero Downtime: Application stays running during reload
  • Kubernetes-Friendly: Pod continues running while application components restart
  • Opt-in: Disabled by default, only enabled when explicitly configured
  • Flexible: Both automatic (periodic) and manual (signal) triggers
  • Safe: Minimum interval validation prevents excessive reloading

When enabled, the reload feature automatically:

  • Reconnects to all configured MCP servers
  • Rediscovers available tools
  • Refreshes configuration settings
  • Maintains Slack connection throughout the process

Perfect for production environments where MCP servers may restart due to updates, scaling, or maintenance.

Slack-Formatted Output

The client includes a comprehensive Slack-formatted output system that enhances message display in Slack:

  • Automatic Format Detection: Automatically detects message type (plain text, markdown, JSON Block Kit, structured data) and applies appropriate formatting
  • Markdown Formatting: Supports Slack's mrkdwn syntax with automatic conversion from standard Markdown
    • Converts **bold** to *bold* for proper Slack bold formatting
    • Preserves inline code, block quotes, lists, and other formatting elements
  • Quoted String Enhancement: Automatically converts double-quoted strings to inline code blocks for better visualization
    • Example: "namespace-name" becomes `namespace-name` in Slack
    • Improves readability of IDs, timestamps, and other quoted values
  • Block Kit Integration: Converts structured data to Block Kit layouts for better visual presentation
    • Automatically validates against Slack API limits
    • Falls back to plain text if Block Kit validation fails

For more details, see the Slack Formatting Guide.

Transport Modes

The client supports three transport modes:

  • SSE (default): Uses Server-Sent Events for real-time communication with the MCP server, includes automatic retry logic for enhanced reliability
  • HTTP: Uses HTTP POST requests with JSON-RPC for communication
  • stdio: Uses standard input/output for local development and testing

Documentation

Comprehensive documentation is available in the docs/ directory:

Configuration & Setup

  • Slack Configuration Guide - Complete guide for setting up your Slack app, including required permissions, tokens, and troubleshooting common issues

Development & Implementation

  • Implementation Notes - Detailed technical documentation covering the current architecture, core components, and implementation details
  • Requirements Specification - Comprehensive requirements documentation including implemented features, quality requirements, and future enhancements

User Guides

  • Slack Formatting Guide - Complete guide to message formatting including Markdown-to-Slack conversion, Block Kit layouts, and automatic format detection
  • RAG Implementation Guide - Detailed guide for the improved RAG system with LangChain Go compatibility and performance optimizations
  • RAG SQLite Implementation - Implementation plan for native Go SQLite integration with ChatGPT-like upload experience
  • Testing Guide - Comprehensive testing documentation covering unit tests, integration tests, manual testing procedures, and debugging

Quick Links

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

License

This project is licensed under the MIT License - see the LICENSE file for details.

CI/CD and Releases

This project uses GitHub Actions for continuous integration and GoReleaser for automated releases.

Continuous Integration Checks

Our CI pipeline performs the following checks on all PRs and commits to the main branch:

Code Quality

  • Linting: Using golangci-lint to check for common code issues and style violations
  • Go Module Verification: Ensuring go.mod and go.sum are properly maintained
  • Formatting: Verifying code is properly formatted with gofmt

Security

  • Vulnerability Scanning: Using govulncheck to check for known vulnerabilities in dependencies
  • Dependency Scanning: Using Trivy to scan for vulnerabilities in dependencies
  • SBOM Generation: Creating a Software Bill of Materials for dependency tracking

Testing

  • Unit Tests: Running tests with race detection and code coverage reporting
  • Build Verification: Ensuring the codebase builds successfully

Release Process

When changes are merged to the main branch:

  1. CI checks are run to validate code quality and security
  2. If successful, a new release is automatically created with:
    • Semantic versioning based on commit messages
    • Binary builds for multiple platforms
    • Docker image publishing to GitHub Container Registry
    • Helm chart publishing to GitHub Container Registry