Mattermost MCP服务器
Mattermost API的MCP服务器,使Claude和其他MCP客户能够与Mattermost工作空间进行交互。
特性
此MCP服务器提供与Mattermost交互的工具,包括:
主题监控
该服务器包括一个主题监控系统,可以:
- 监视包含感兴趣主题的消息的指定频道
- 按照可配置的时间表运行(使用cron语法)
- 讨论相关主题时发送通知
- 找到主题时,在指定频道中提及您
渠道工具
mattermost_list_channels:列出工作区中的公共频道mattermost_get_channel_history:从频道获取最新消息
消息工具
mattermost_post_message:向频道发布新消息mattermost_reply_to_thread:回复特定消息线程mattermost_add_reaction:在消息中添加表情符号反应mattermost_get_thread_replies:在一个帖子中获取所有回复
监视工具
mattermost_run_monitoring:立即触发主题监控流程
用户工具
mattermost_get_users:获取工作区中的用户列表mattermost_get_user_profile:获取用户的详细个人资料信息
设置
- 克隆此存储库:
git clone https://github.com/yourusername/mattermost-mcp.git
cd mattermost-mcp- 安装依赖项:
npm install- 配置服务器:
存储库包括 config.json 带有占位符值的文件。对于您的实际配置,创建一个 config.local.json 包含您真实凭据的文件(gitignored):
{
"mattermostUrl": "https://your-mattermost-instance.com/api/v4",
"token": "your-personal-access-token",
"teamId": "your-team-id",
"monitoring": {
"enabled": false,
"schedule": "*/15 * * * *",
"channels": ["town-square", "off-topic"],
"topics": ["tv series", "champions league"],
"messageLimit": 50
}
}这种方法将您的真实凭据保留在存储库之外,同时为其他人维护模板。
- 构建服务器:
npm run build- 运行服务器:
npm start主题监控配置
监控系统可以配置以下选项:
enabled(boolean):是否启用监控schedule(string):用于何时检查新消息的Cron表达式(例如,每15分钟检查一次“\*/15\*\*\*\*”)channels(string\[\]):要监视的通道名称数组topics(string\[\]):要在消息中查找的主题数组messageLimit(number):每次检查要分析的最近消息数notificationChannelId(字符串,可选):将发送通知的通道ID。如果没有提供,系统将自动使用直接消息通道。userId(字符串,可选):通知中提及的用户ID。如果没有提供,系统将自动检测当前用户。
要启用监控,请设置 enabled 向 true 在你的 config.local.json 文件。
手动运行监控
您可以通过多种方式手动触发监控过程:
- 使用提供的脚本:
- ./run-monitoring-http.sh -通过HTTP触发监控,而无需重新启动服务器(推荐) - ./run-monitoring.sh -启动启用监控的新服务器实例 - ./trigger-monitoring.sh -运行监控进程并退出(对cron作业有用) - ./view-channel-messages.js [count] -查看频道中的最后一条消息 - ./analyze-channel.js [count] -分析通道中的消息统计信息 - ./get-last-message.js -从频道获取最后一条消息
- 使用命令行界面(CLI):
- 服务器运行时,只需在终端中键入以下命令之一: - run -运行监控过程 - monitor -与 run - check -与 run - 其他可用命令: - help -显示可用命令 - exit -关闭服务器
- 使用MCP工具:
- 使用 mattermost_run_monitoring 通过MCP接口使用工具 - 这将立即检查您感兴趣的主题的所有配置频道
- 使用命令行标志:
- 使用启动服务器 --run-monitoring 标志:
npm start -- --run-monitoring- 这将在服务器启动后立即运行监控过程 - 添加 --exit-after-monitoring 在监控过程完成后退出:
npm start -- --run-monitoring --exit-after-monitoring- 这对于从cron作业运行监控进程非常有用
工具详细信息
渠道工具
mattermost_list_channels
- 列出工作区中的公共频道
- 可选输入:
- limit (数字,默认值:100,最大值:200):要返回的最大通道数 - page (数字,默认值:0):分页页码
- 返回:通道列表及其ID和信息
mattermost_get_channel_history
- 从频道获取最新消息
- 所需输入:
- channel_id (string):通道的ID
- 可选输入:
- limit (数字,默认值:30):要检索的邮件数 - page (数字,默认值:0):分页页码
- 返回:消息及其内容和元数据的列表
消息工具
mattermost_post_message
- 在Mattermost频道发布新消息
- 所需输入:
- channel_id (string):要发布的频道的ID - message (string):要发布的消息文本
- 返回:消息发布确认和ID
mattermost_reply_to_thread
- 回复特定消息线程
- 所需输入:
- channel_id (string):包含线程的通道 - post_id (string):父消息的ID - message (string):回复文本
- 返回:回复确认和ID
mattermost_add_reaction
- 在消息中添加表情符号反应
- 所需输入:
- channel_id (string):包含消息的通道 - post_id (string):要响应的消息ID - emoji_name (字符串):不带冒号的表情符号名称
- 返回:反应确认
mattermost_get_thread_replies
- 获取消息线程中的所有回复
- 所需输入:
- channel_id (string):包含线程的通道 - post_id (string):父消息的ID
- 返回:回复列表及其内容和元数据
用户工具
mattermost_get_users
- 获取包含基本配置文件信息的工作区用户列表
- 可选输入:
- limit (数字,默认值:100,最大值:200):可返回的最大用户数 - page (数字,默认值:0):分页页码
- 返回:用户及其基本配置文件的列表
mattermost_get_user_profile
- 获取特定用户的详细个人资料信息
- 所需输入:
- user_id (string):用户的ID
- 返回:详细的用户配置文件信息
使用Claude Desktop
将以下内容添加到您的 claude_desktop_config.json:
{
"mcpServers": {
"mattermost": {
"command": "node",
"args": [
"/path/to/mattermost-mcp/build/index.js"
]
}
}
}故障排除
如果遇到权限错误,请验证:
- 您的个人访问令牌具有必要的权限
- 令牌已正确复制到您的配置中
- Mattermost URL和团队ID正确
HTTP端点
服务器公开HTTP端点以进行远程控制:
- 运行监控:
http://localhost:3456/run-monitoring
- 立即启动监控流程 - 返回带有成功/错误信息的JSON响应
- 检查状态:
http://localhost:3456/status
- 返回有关服务器和监视状态的信息 - 可用于健康检查
您可以将这些端点与curl或任何HTTP客户端一起使用:
# Trigger monitoring
curl http://localhost:3456/run-monitoring
# Check status
curl http://localhost:3456/status实用程序脚本
运行监控-http.sh
此脚本通过HTTP端点触发监控过程:
./run-monitoring-http.sh这是手动触发监控的推荐方式,因为它:
- 不重新启动服务器
- 不会干扰预定的监控
- 从任何终端可靠工作
view-channel-messages.js
此脚本允许您查看任何频道中的最新消息:
# View messages in a channel (channel name is required)
node view-channel-messages.js
# View a specific number of messages
node view-channel-messages.js
# Example: View the last 10 messages in a channel
node view-channel-messages.js general 10脚本将显示:
- 通道信息(名称、目的、消息总数)
- 带有时间戳和用户名的最新消息
- 如果频道不存在,它将列出所有可用频道
analyze-channel.js
此脚本提供有关通道中消息的详细统计信息:
# Analyze messages in a channel (channel name is required)
node analyze-channel.js
# Analyze a specific number of messages
node analyze-channel.js
# Example: Analyze the last 50 messages in a channel
node analyze-channel.js general 50脚本将显示:
- 频道信息和元数据
- 消息总数(包括系统消息)
- 用户消息与系统消息的细分
- 用户消息计数
- 频道中的最新消息
get_last-message.js
此脚本仅从频道检索最新消息:
# Get the last message from a channel (channel name is required)
node get-last-message.js
# Example: Get the last message from the general channel
node get-last-message.js general脚本将显示:
- 发件人的用户ID和用户名
- 消息的时间戳
- 完整消息内容
许可证
此MCP服务器根据MIT许可证获得许可。
