Mattermost MCP Client

by jagan-shanmugam

MCP Client
  • agent-framework

About

What is Mattermost MCP Client?

A Python-based MCP (Model Context Protocol) client that connects Mattermost with MCP servers, enabling command execution and tool management through Mattermost channels. It runs on any system with Python 3.13.1+ and a Mattermost server, targeting developers and teams wanting to extend Mattermost with AI and automation tools.

How to use Mattermost MCP Client?

Create a virtual environment, install dependencies with uv sync, and configure a .env file with Mattermost URL, bot token, and MCP server settings. Define MCP servers in mcp-servers.json, then run python src/mattermost_mcp_client/main.py. Once running, send commands like !mcp help or !mcp <server_name> call <tool_name> <args> in a Mattermost channel.

Key features of Mattermost MCP Client

- Connects Mattermost to any stdio-based MCP server
- Execute tools and manage resources via channel commands
- Built-in MCP servers for chat, Ollama, and Mattermost API
- Command-line utility to test MCP servers directly
- Configuration through environment variables and JSON files

Use cases of Mattermost MCP Client

- Trigger AI text generation in Mattermost using local Ollama models
- Automate Mattermost actions like posting messages programmatically
- Build custom toolchains that execute from chat commands
- Test and debug MCP servers before deploying to production

FAQ from Mattermost MCP Client

What does this client do that alternatives don’t?

It bridges Mattermost communication with MCP servers, letting users call any MCP tool directly from a Mattermost channel without leaving the chat interface.

Which platforms and models are supported?

The client runs on any OS with Python 3.13.1+. It supports any MCP server configured via stdio; included servers demonstrate integration with Ollama (local models) and the Mattermost API.

How does MCP server configuration work?

Servers are defined in mcp-servers.json as objects with command, args, and type (stdio). Multiple servers can be listed, and the client discovers them at startup.

What are the known limitations?

The client currently lacks support for npx-based MCP servers, built-in authentication, and file uploads. These are noted as planned next steps.

Details

Author
jagan-shanmugam
Category
agent-framework
Repository
jagan-shanmugam/mattermost-mcp-client

Mattermost MCP Client

A Python-based MCP (Model Context Protocol) client that connects Mattermost with MCP servers, enabling command execution and tool management through Mattermost channels.

Demo

MCP Client Demo

Prerequisites

- Python 3.13.1+
- Mattermost server (local or remote)
- Bot account in Mattermost with appropriate permissions

Installation

1. Create a virtual environment

uv venv
source venv/bin/activate  # On Windows: venv\Scripts\activate

On fish shell - source .venv/bin/activate.fish

2. Install required packages

uv sync # Installs all dependencies

3. Set up configuration

Create a .env file with your Mattermost and MCP server settings:

MATTERMOST_URL=http://localhost:8065
MATTERMOST_TOKEN=your-bot-token
MATTERMOST_SCHEME=http
MATTERMOST_PORT=8065
MATTERMOST_TEAM_NAME=your-team-name
MATTERMOST_CHANNEL_NAME=town-square
MCP_SERVER_TYPE=stdio
MCP_COMMAND=python
MCP_ARGS=mcp_server.py
LOG_LEVEL=INFO
For a complete list of configuration options and their default values, refer to the config.py.

Configuration Options

All configuration options can be set through environment variables or in the .env file. Here are the available options:

- COMMAND_PREFIX - Prefix for bot commands (default: '!mcp')
- LOG_LEVEL - Logging level (default: 'INFO')

4. Configure MCP Servers

Create or modify mcp-servers.json in the src/mattermost_mcp_client directory:

{
    "mcpServers": {
      "ollama-mcp-server":{
        "command": "python",
        "args": ["ollama-mcp-server/src/ollama_mcp_server/main.py"],
        "type": "stdio"
      },
      "simple-mcp-server": {
        "command": "python",
        "args": ["simple-mcp-server/server.py"],
        "type": "stdio"
      },
      "mattermost-mcp-server": {
        "command": "python",
        "args": ["mattermost-mcp-server/src/mattermost_mcp_server/server.py"],
        "type": "stdio"
      }
    }
}

Mattermost Setup

1. Start a local Mattermost server (if not already running)

You can use Docker to run Mattermost locally:

docker run --name mattermost-preview -d --publish 8065:8065 mattermost/mattermost-preview

2. Create a Bot Account

- Go to Integrations > Bot Accounts > Add Bot Account
- Give it a name and description
- Note the access token provided

3. Add the bot to your team and channel

Running the Integration

1. Start the Mattermost MCP Client

python src/mattermost_mcp_client/main.py

Using the MCP Tool Caller Utility

The mcp_tool_caller.py utility allows you to interact with MCP servers directly from the command line:

1. List server capabilities

python utils/mcp_tool_caller.py list --server-name simple-mcp-server

2. Call specific tools

python utils/mcp_tool_caller.py call --server-name simple-mcp-server --tool echo --tool-args '{"input": "Hello World"}'

Mattermost Commands

Once the integration is running, use these commands in your Mattermost channel:

- !mcp help - Display help information
- !mcp servers - List available MCP servers
- !mcp <server_name> tools - List available tools for a specific server
- !mcp <server_name> call <tool_name> <args> - Call a specific tool
- !mcp <server_name> resources - List available resources
- !mcp <server_name> prompts - List available prompts

Example:

!mcp simple-mcp-server call echo message "Hello World"

!mcp mattermost-mcp-server call post-message {"channel_id": "5q39mmzqji8bddxyjzsqbziy9a", "message": "Hello from Demo!"}'

!mcp ollama-mcp-server call generate {"prompt": "Write a short poem about AI", "model": "llama3.2:latest"}

MCP Servers included

This repository includes three MCP servers: - simple-mcp-server: A simple MCP server that has two simple tools - ollama-mcp-server: A MCP server that uses Ollama locally to generate text - mattermost-mcp-server: A MCP server that wraps Mattermost API and performs various actions

Troubleshooting

1. Connection Issues:
- Verify Mattermost URL and port
- Check the bot token is valid
- Ensure the MCP server is running

2. Permission Issues:
- Make sure the bot has appropriate permissions in Mattermost
- Check that the bot is a member of the channel

3. MCP Tool Errors:
- Verify that the tools are properly defined in the MCP server
- Check the input format for tool calls
- Use the mcp_tool_caller.py utility to test tools directly

Next Steps

1. Add support for npx based MCP servers
2. Using Tool calling Agent to orchstrate tools in MCP servers
2. Implement authentication for secure communication
3. Add support for file uploads and other Mattermost features

Watch the full demo video:

<a href="https://www.youtube.com/watch?v=YPtfqUstfTI" target="_blank">
Watch the demo video
</a>