Skip to content
/ BNFR55 Public

FastAPI Slack bot using a modular LangChain agent with RAG (ChromaDB). Includes an HTTP MCP server for tool discovery and vector search over GitHub, enabling advanced, tool-driven reasoning.

Notifications You must be signed in to change notification settings

red512/BNFR55

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

21 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

BNFR MCP HTTP Streaming & Slack Bot with Modular LangChain Agent

image

This project provides an intelligent Slack bot with enhanced agent capabilities powered by modular LLM providers (Gemini, OpenAI, Claude) and MCP (Model Control Protocol) tools. The bot uses LangChain's agent framework for better reasoning, problem-solving, and tool usage through an HTTP-based MCP server architecture.

Architecture

graph TD
  User["Slack User"] <-->|Messages| Slack["Slack Platform"]
  Slack <-->|Events API / Webhooks| Bot["BNFR Bot (FastAPI)"]

  subgraph "BNFR Bot Service"
    Bot
    LangChainAgent["🤖 Modular LangChain Agent<br/>(Advanced Reasoning + Tool Calling)"]
    MCPClient["MCP Client"]

    Bot <--> LangChainAgent
    LangChainAgent <--> MCPClient
  end

  LangChainAgent <-->|LangChain Framework| LLMProviders["🔄 LLM Providers (Configurable)<br/>• Google Gemini<br/>• OpenAI<br/>• Anthropic Claude<br/>• Local LLMs (Ollama/Docker)"]

  MCPClient <-->|HTTP JSON-RPC| MCPServer["BNFR MCP Server"]

  subgraph "BNFR MCP Server Service"
    MCPServer
    Tools["Tools Registry"]
    SearchTool["search_knowledge_base<br/>(vector search)"]

    MCPServer --> Tools
    Tools --> JokeTools["Joke Tools"]
    Tools --> TimeTools["Time Tools"]
    Tools --> SearchTool
    SearchTool --> VectorDB["ChromaDB Vector Store"]
  end

  GitHubRepo["GitHub Repositories"] -.->|Indexed Content| VectorDB
Loading
  • bnfrmcp/ - MCP server with HTTP streaming support

    • Joke tools (get random programming jokes)
    • GitHub ingestion: clone repositories, extract text files (.md, .py, .tf, Dockerfile, etc.) and index them in ChromaDB
    • Time zone tools (London, New York)
    • Runs on http://127.0.0.1:8000/bnfr/mcp
  • bnfrbot/ - FastAPI-based Slack bot with Modular LangChain Agent

    • 🤖 Modular LLM Support: Choose between Gemini, OpenAI, or Anthropic by changing one config variable
    • LangChain Agent Mode: Advanced reasoning with tool calling capabilities
    • Multiple Providers: Gemini 2.5-flash-lite, OpenAI GPT-4o-mini, Claude 3.5 Haiku, or Local LLMs (Ollama/Docker)
    • LangChain Integration: Leverages LangChain's agent framework for better tool orchestration
    • Smart Tool Usage: Systematically analyzes problems and chooses appropriate tools
    • MCP Integration: Automatically discovers and uses MCP tools through LangChain
    • Persistent Chat History: Per-user conversation memory with LangChain memory management
    • Agent Executor: Built-in retry logic and error handling
    • Runs on http://0.0.0.0:3000

Quick Start

1. Set up the MCP Server

cd bnfrmcp
pip install -r requirements.txt
python server.py --host 127.0.0.1 --port 8000

The server will be available at http://127.0.0.1:8000/bnfr/mcp

2. Set up the Slack Bot

cd bnfrbot
pip install -r requirements.txt

# Copy and configure environment variables
cp .env.example .env
# Edit .env with your actual values

3. Configure Environment Variables

Edit bnfrbot/.env with your credentials:

# Slack Configuration
SLACK_SIGNING_SECRET=your_slack_signing_secret
SLACK_BOT_TOKEN=xoxb-your-bot-token
VERIFICATION_TOKEN=your_verification_token

# LLM Provider Configuration (Choose one: gemini | openai | anthropic | local)
LLM_PROVIDER=gemini

# Provider-specific API Keys (configure the one you're using)
GEMINI_API_KEY=your_gemini_api_key        # For Gemini
OPENAI_API_KEY=your_openai_api_key        # For OpenAI
ANTHROPIC_API_KEY=your_anthropic_api_key  # For Claude

# Local LLM Configuration 
LOCAL_LLM_BASE_URL=http://localhost:11434/v1
LOCAL_LLM_MODEL=llama3.2:latest

# MCP Server
MCP_SERVER_URL=http://127.0.0.1:8000/bnfr/mcp

To switch LLM providers: Simply change LLM_PROVIDER to gemini, openai, anthropic, or local and ensure the corresponding configuration is set.

Local LLM Examples:

  • Ollama: LOCAL_LLM_BASE_URL=http://localhost:11434/v1 with models like llama3.2:latest, mistral:latest
  • LM Studio: LOCAL_LLM_BASE_URL=http://localhost:1234/v1 with your loaded model
  • Docker: LOCAL_LLM_BASE_URL=http://localhost:12434/v1 with your container setup

4. Run the Slack Bot

cd bnfrbot
python app.py

The bot will be available at http://0.0.0.0:3000

Docker Setup (Optional)

For containerized deployment, use Docker Compose:

  1. Configure environment:

    cp .env.example .env
    # Edit .env with your actual credentials
  2. Build and run:

    docker-compose up --build
  3. Services will be available at:

    • MCP Server: http://localhost:8000/bnfr/mcp
    • Slack Bot: http://localhost:3000

Endpoints

MCP Server (bnfrmcp)

  • Main endpoint: http://127.0.0.1:8000/bnfr/mcp
  • Available tools: Joke Tools | Time Tools | search_knowledge_base

Slack Bot (bnfrbot)

  • Slack events: http://localhost:3000/slack/events
  • Health check: http://localhost:3000/health
  • Refresh tools: http://localhost:3000/refresh-tools
  • Interactions: http://localhost:3000/interactions

Usage

🤖 Agent Interactions

The bot now operates in agent mode with enhanced capabilities:

  1. Direct Messages: Send a direct message to the bot for private conversations
  2. App Mentions: Mention @BotName in channels for public interactions
  3. Tool Queries: Ask about available tools: "show me the mcp tools you have"
  4. Complex Questions: The agent breaks down complex problems systematically
  5. Reasoning Display: The bot shows its thinking process for better transparency

Example Interactions

  • "show me the mcp tools you have" - Lists available tools with explanations
  • "what time is it in London?" - Uses time tools intelligently
  • "search for docker configurations" - Searches knowledge base with context
  • "tell me a programming joke" - Uses appropriate tools for entertainment
  • "analyze this project's CI/CD setup" - Combines multiple tools for comprehensive analysis

Agent Behavior

  • 🤖 Agent thinking... - Shows when the agent is processing
  • 🤖 Agent Response: - Indicates agent-generated responses with reasoning
  • Systematic approach - Breaks down complex queries into steps
  • Tool explanation - Explains why specific tools are chosen

Features

🤖 Modular LangChain Agent Capabilities

  • Multiple LLM Providers: Choose between Gemini, OpenAI, or Claude with one config change
  • Advanced Reasoning: LangChain-powered agent with systematic problem analysis
  • Tool Calling Framework: Automatic tool selection and execution with retry logic
  • Conversation Memory: Persistent per-user chat history with LangChain memory management
  • Provider Flexibility: Easy switching between different AI models and providers
  • Graceful Fallback: Works even if advanced agent features aren't available
  • Error Resilience: Built-in error handling and recovery mechanisms

🔧 Technical Features

  • HTTP Streaming: MCP server uses FastAPI with HTTP streaming transport
  • Tool Discovery: Bot automatically discovers MCP tools at startup
  • LangChain Integration: Uses LangChain's agent framework for better orchestration
  • Health Monitoring: Health check endpoints for both services
  • Tool Refresh: Admin endpoint to refresh MCP tools without restart
  • Clean Architecture: Simplified codebase with only essential components

Knowledge Base (GitHub + Docs)

The knowledge base indexes GitHub repositories into a single semantic index stored in a local ChromaDB instance. Key points:

  • Ingestion: bnfrmcp/github_ingest.py clones repositories and extracts text content from supported files. The ingestion pipeline is orchestrated by bnfrmcp/ingest_data.py.
  • Supported file types: .md, .txt, .py, .js, .ts, .html, .css, .json, .yaml, .yml, .sh, Dockerfile, .tf, .hcl, .tfvars (add more in github_ingest.py if needed).
  • Storage & embeddings: Documents are stored in ChromaDB (chroma_data/). Embeddings use embedding_functions.DefaultEmbeddingFunction() (sentence-transformers) and run locally — this avoids external LLM embedding API usage and helps stay within API quotas.
  • Search: Use the MCP tool search_knowledge_base to query the index. The tool returns matching documents and metadata (repo, filepath, filename, source).

Quick re-index example (rebuild local vector DB):

cd bnfrmcp
# remove prior index
rm -rf chroma_data
# ingest GitHub repos listed in ingest_data.py
python ingest_data.py

To add a GitHub repository for indexing, edit repo_urls in bnfrmcp/ingest_data.py and re-run the ingestion command above.

Development

Running with ngrok (for Slack development)

# Terminal 1: MCP Server
cd bnfrmcp
python server.py

# Terminal 2: Slack Bot
cd bnfrbot
python app.py

# Terminal 3: ngrok
ngrok http 3000

Use the ngrok URL for your Slack app's event subscriptions.

Running with Docker for Development

# Start services in detached mode
docker-compose up -d

# View logs
docker-compose logs -f

# Stop services
docker-compose down

# Rebuild after code changes
docker-compose up --build

Project Structure

BNFR55-http-new/
├── bnfrmcp/                 # MCP Server
│   ├── server.py           # FastAPI + FastMCP setup
│   ├── main.py             # Server runner
│   ├── requirements.txt    # Python dependencies
│   └── tools/              # MCP tools
│
├── bnfrbot/                # Slack Bot with Modular LangChain Agent
│   ├── app.py              # Main FastAPI application
│   ├── config.py           # Environment configuration (modular LLM providers)
│   ├── mcp_client.py       # HTTP MCP client
│   ├── modular_agent.py    # 🤖 Modular LangChain Agent (Gemini/OpenAI/Claude)
│   ├── requirements.txt    # Python dependencies (LangChain + multiple providers)
│   ├── .env.example        # Environment template with LLM provider options
│   └── tools/              # Local tools (minimal)
│
└── README.md               # This file

Configuration

MCP Server Configuration

  • Host: 127.0.0.1 (configurable via --host)
  • Port: 8000 (configurable via --port)
  • Mount path: /bnfr/mcp

Slack Bot Configuration

  • Host: 0.0.0.0
  • Port: 3000
  • Agent Mode: LangChain-powered Modular Agent with advanced reasoning
  • LLM Providers:
    • Gemini: gemini-2.5-flash-lite (default)
    • OpenAI: gpt-4o-mini
    • Anthropic: claude-3-5-haiku-20241022
    • Local LLMs: Ollama, LM Studio, Docker containers
  • Framework: LangChain + AgentExecutor
  • Modularity: Switch providers by changing LLM_PROVIDER in config
  • Tools: MCP tools integrated through LangChain
  • Conversation history: 100 users max, 10 messages per user
  • MCP tool cache: Refreshed on startup and via admin endpoint

What's New in Agent Mode

🚀 Enhanced Capabilities

  • Agent Thinking: Visible reasoning process (🤖 Agent thinking...)
  • Step-by-step Analysis: Breaks down complex problems systematically
  • Intelligent Tool Usage: Chooses tools based on context and need
  • Better Responses: More structured and informative answers
  • Conversation Flow: Maintains context better across interactions

📈 Upgrade from Basic Integration

Feature Before (Basic) Now (Agent Mode)
Thinking Process Hidden 🤖 Agent thinking...
Responses Simple 🤖 Agent Response: with reasoning
Tool Usage Basic Intelligent selection with explanation
Problem Solving Direct Step-by-step analysis
Context Awareness Limited Enhanced conversation memory

🔧 Current Architecture

  • Modular LangChain Agent: Streamlined architecture with configurable LLM providers
    • Default: Google Gemini 2.5-flash-lite
    • Alternatives: OpenAI GPT-4o-mini, Anthropic Claude 3.5 Haiku
    • Easy Switching: Change LLM_PROVIDER in config to switch providers
    • LangChain AgentExecutor for tool orchestration
    • ChatMessageHistory for conversation memory
    • Graceful fallback if advanced features unavailable
    • MCP tool integration through LangChain framework

About

FastAPI Slack bot using a modular LangChain agent with RAG (ChromaDB). Includes an HTTP MCP server for tool discovery and vector search over GitHub, enabling advanced, tool-driven reasoning.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published