logo
0
0
WeChat Login

BotMCP - Mattermost Bot MCP Server

A standalone MCP (Model Context Protocol) server for Mattermost integration, built with FastMCP 3.0.

Features

  • Message Operations: Send, get, edit, delete messages
  • File Operations: Upload and download files
  • Channel Management: List and get channel information
  • Real-time Subscriptions: WebSocket-based message stream
  • Blocking Wait: wait_for_message for reactive bot behavior
  • FastMCP 3.0: Modern decorator-based tool registration

Installation

# From source cd /workspace/botmcp pip install -e . # Or using pip (after publishing) pip install botmcp

Configuration

Set environment variables:

export MATTERMOST_URL="http://zjty.net:6065" export MATTERMOST_TOKEN="5z3rk5fwftbo3gmdhbzskyauah"

Or create a .env file:

MATTERMOST_URL=http://zjty.net:6065 MATTERMOST_TOKEN=5z3rk5fwftbo3gmdhbzskyauah

注:以上为测试环境账户(garry bot)

Usage

With CodeBuddy (SSE Mode - Recommended)

Step 1: Start BotMCP SSE server

cd /workspace/botmcp export MATTERMOST_URL="http://zjty.net:6065" export MATTERMOST_TOKEN="5z3rk5fwftbo3gmdhbzskyauah" # SSE transport (recommended) fastmcp run run_server.py --transport sse --port 8000

Step 2: Configure ~/.codebuddy/mcp.json

{ "mcpServers": { "botmcp": { "url": "http://127.0.0.1:8000/sse", "transport": "sse" } } }

With CodeBuddy (stdio Mode)

Add to ~/.codebuddy/mcp.json:

{ "mcpServers": { "botmcp": { "command": "python", "args": ["-m", "botmcp.server"], "env": { "MATTERMOST_URL": "http://zjty.net:6065", "MATTERMOST_TOKEN": "5z3rk5fwftbo3gmdhbzskyauah" } } } }

With Claude Desktop

Add to your Claude Desktop config (~/.claude/claude_desktop_config.json):

{ "mcpServers": { "mattermost": { "command": "python", "args": ["-m", "botmcp.server"], "env": { "MATTERMOST_URL": "http://zjty.net:6065", "MATTERMOST_TOKEN": "5z3rk5fwftbo3gmdhbzskyauah" } } } }

Command Line

# Start the MCP server (stdio transport) python -m botmcp.server # Or using FastMCP CLI fastmcp run botmcp.server:mcp # With HTTP transport fastmcp run botmcp.server:mcp --transport http --port 8000

Available Tools (17)

Message Tools (7)

ToolDescription
send_messageSend a message to a channel
get_messageGet a message by ID
edit_messageEdit an existing message
delete_messageDelete a message
get_threadGet all posts in a thread
get_channel_messagesGet recent messages from a channel
search_messagesSearch for messages

File Tools (3)

ToolDescription
upload_fileUpload a file to a channel
download_fileDownload a file
get_file_infoGet file metadata

Channel Tools (3)

ToolDescription
get_channelGet channel information
list_channelsList channels in a team
get_my_channelsGet channels for current user

Realtime Tools (4)

ToolDescription
wait_for_messageBlock until new message arrives (for reactive bots)
get_realtime_messagesGet current message queue
subscribe_channelSubscribe to channel events
mark_message_completedMark message as processed

Resources

URIDescription
mattermost://messages/streamReal-time message stream
mattermost://bot/statusBot connection status
mattermost://channels/subscribedList of monitored channels

Example Usage

Send a Message

{ "name": "send_message", "arguments": { "channel_id": "abc123", "message": "Hello from BotMCP!" } }

Reply to a Thread

{ "name": "send_message", "arguments": { "channel_id": "abc123", "message": "This is a reply", "root_id": "parent_post_id" } }

Upload a File

{ "name": "upload_file", "arguments": { "channel_id": "abc123", "file_name": "document.pdf", "file_data": "<base64-encoded-data>", "content_type": "application/pdf" } }

Environment Variables

VariableRequiredDefaultDescription
MATTERMOST_URLYes-Mattermost server URL
MATTERMOST_TOKENYes-Bot token or personal access token
MATTERMOST_TEAMNo-Default team name
WEBSOCKET_ENABLEDNotrueEnable WebSocket
WEBSOCKET_RECONNECT_DELAYNo5Reconnection delay (seconds)
WEBSOCKET_MAX_RETRIESNo10Maximum reconnection attempts
MESSAGE_QUEUE_SIZENo100Message queue size
MAX_FILE_SIZENo52428800Max upload size (50MB)

Development

# Install dev dependencies pip install -e ".[dev]" # Run tests pytest # Type checking mypy src/botmcp # Linting ruff check src/botmcp

Architecture

Built with FastMCP 3.0 - a modern, decorator-based MCP framework:

from fastmcp import FastMCP mcp = FastMCP("BotMCP") @mcp.tool async def send_message(channel_id: str, message: str) -> str: """Send a message to a Mattermost channel.""" ... @mcp.resource("mattermost://messages/stream") async def get_messages_resource() -> str: """Real-time message stream resource.""" ...

License

MIT License

About

mattermost bot mcp server

Language
Python100%