A Mattermost integration that connects to Model Context Protocol (MCP) servers, leveraging a LangGraph-based AI agent to provide an intelligent interface for interacting with users and executing tools directly within Mattermost. Demo 1. Github Agent in support channel - searches the existing issues and PRs and creates a new issue if not found 2. Search internet and post to a channel using Mattermost-MCP-server Scroll below for full demo in YouTube Features - 🤖 **Langgraph Agent Integration**: Uses a LangGraph agent to understand user requests and orchestrate responses. - 🔌 **MCP Server Integration**: Connects to multiple MCP servers defined in mcp-servers.json. - 🛠️ **Dynamic Tool Loading**: Automatically discovers tools from connected MCP servers and makes them available to the AI agent. Converts MCP tools to langchain structured tools. - 💬 **Thread-Aware Conversations**: Maintains conversational context within Mattermost threads for coherent interactions. - 🔄 **Intelligent Tool Use**: The AI agent can decide when to use available tools (including chaining multiple calls) to fulfill user requests. - 🔍 **MCP Capability Discovery**: Allows users to list available servers, tools, resources, and prompts via direct commands. - #️⃣ **Direct Command Interface**: Interact directly with MCP servers using a command prefix (default: #). Overview The integration works as follows: 1. **Mattermost Connection (mattermost_client.py)**: Connects to the Mattermost server via API and WebSocket to listen for messages in a specified channel. 2. **MCP Connections (mcp_client.py)**: Establishes connections (primarily stdio) to each MCP server defined in src/mattermost_mcp_host/mcp-servers.json. It discovers available tools on each server. 3. **Agent Initialization (agent/llm_agent.py)**: A LangGraphAgent is created, configured with the chosen LLM provider and the dynamically loaded tools from all connected MCP servers. 4. **Message Handling (main.py)**: * If a message starts with the command prefix (#), it's parsed as a direct command to list servers/tools or call a specific tool via the corresponding MCPClient. * Otherwise, the message (along with thread history) is passed to the LangGraphAgent. 5. **Agent Execution**: The agent processes the request, potentially calling one or more MCP tools via the MCPClient instances, and generates a response. 6. **Response Delivery**: The final response from the agent or command execution is posted back to the appropriate Mattermost channel/thread. Setup 1. **Clone the repository:** 2. **Install:** * Using uv (recommended): 3. **Configure Environment (.env file):** Copy the .env.example and fill in the values or Create a .env file in the project root (or set environment variables): See .env.example for more options. 4. **Configure MCP Servers:** Edit src/mattermost_mcp_host/mcp-servers.json to define the MCP servers you want to connect to. See src/mattermost_mcp_host/mcp-servers-example.json. Depending on the server configuration, you might npx, uvx, docker installed in your system and in path.