Mattermost MCP Server

by pvev

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 :获取用户的详细个人资料信息

设置

  1. 克隆此存储库:
git clone https://github.com/yourusername/mattermost-mcp.git cd mattermost-mcp
  1. 安装依赖项:
npm install
  1. 配置服务器:仓库包含一个包含占位符值的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 } }
    这种方法可以将您的真实凭据保留在存储库之外,同时为其他人维护模板。
  2. 构建服务器:
npm run build
  1. 运行服务器:
npm start

主题监控配置

监控系统可配置以下选项:

  • enabled (布尔值):是否启用监控
  • schedule (字符串):用于指定何时检查新消息的 Cron 表达式(例如,每 15 分钟检查一次“*/15 * * * *”)
  • channels (string[]):要监视的通道名称数组
  • topics (string[]):在消息中查找的主题数组
  • messageLimit (数字):每次检查要分析的最新消息的数量
  • notificationChannelId (字符串,可选):通知发送渠道 ID。若未提供,系统将自动使用私信渠道。
  • userId (字符串,可选):您在通知中提及的用户 ID。如果未提供,系统将自动检测当前用户。

要启用监控,请在config.local.json文件中将enabled设置为true

手动运行监控

您可以通过多种方式手动触发监控过程:

  1. 使用提供的脚本
    • ./run-monitoring-http.sh - 通过 HTTP 触发监控,无需重启服务器(推荐)
    • ./run-monitoring.sh - 启动一个启用监控的新服务器实例
    • ./trigger-monitoring.sh - 运行监控进程并退出(对于 cron 作业有用)
    • ./view-channel-messages.js <channel-name> [count] - 查看频道中的最新消息
    • ./analyze-channel.js <channel-name> [count] - 分析频道内的消息统计
    • ./get-last-message.js <channel-name> - 获取频道中的最后一条消息
  2. 使用命令行界面 (CLI)
    • 当服务器运行时,只需在终端中输入以下命令之一:
      • run运行监控进程
      • monitor -与run相同
      • check - 与run相同
    • 其他可用命令:
      • help -显示可用的命令
      • exit ——关闭服务器
  3. 使用 MCP 工具
    • 通过 MCP 接口使用mattermost_run_monitoring工具
    • 这将立即检查您感兴趣的主题的所有已配置频道
  4. 使用命令行标志
    • 使用--run-monitoring标志启动服务器:GXP6
    • 这将在服务器启动后立即运行监控进程
    • 添加--exit-after-monitoring在监控过程完成后退出:GXP7
    • 这对于从 cron 作业运行监控过程很有用

工具详细信息

渠道工具

mattermost_list_channels

  • 列出工作区中的公共频道
  • 可选输入:
    • limit (数字,默认值:100,最大值:200):返回的最大通道数
    • page (数字,默认值:0):分页的页码
  • 返回:频道列表及其 ID 和信息

mattermost_get_channel_history

  • 获取频道的最新消息
  • 必需输入:
    • channel_id (字符串):频道的ID
  • 可选输入:
    • limit (数字,默认值:30):要检索的消息数量
    • page (数字,默认值:0):分页的页码
  • 返回:消息及其内容和元数据的列表

消息工具

mattermost_post_message

  • 向 Mattermost 频道发布新消息
  • 必需输入:
    • channel_id (string): 要发布到的频道的 ID
    • message (字符串):要发布的消息文本
  • 返回:消息发布确认和ID

mattermost_reply_to_thread

  • 回复特定消息线程
  • 必需输入:
    • channel_id (字符串):包含线程的通道
    • post_id (字符串):父消息的 ID
    • message (字符串):回复文本
  • 返回:回复确认和ID

mattermost_add_reaction

  • 在消息中添加表情符号反应
  • 必需输入:
    • channel_id (字符串):包含消息的频道
    • post_id (字符串):要响应的消息 ID
    • emoji_name (字符串):不带冒号的表情符号名称
  • 返回:反应确认

mattermost_get_thread_replies

  • 获取消息线程中的所有回复
  • 必需输入:
    • channel_id (字符串):包含线程的通道
    • post_id (字符串):父消息的 ID
  • 返回:回复列表及其内容和元数据

用户工具

mattermost_get_users

  • 获取具有基本个人资料信息的工作区用户列表
  • 可选输入:
    • limit (数字,默认值:100,最大值:200):返回的最大用户数
    • page (数字,默认值:0):分页的页码
  • 返回:用户及其基本资料的列表

mattermost_get_user_profile

  • 获取特定用户的详细个人资料信息
  • 必需输入:
    • user_id (字符串):用户的 ID
  • 返回:详细的用户资料信息

与 Claude Desktop 一起使用

将以下内容添加到您的claude_desktop_config.json中:

{ "mcpServers": { "mattermost": { "command": "node", "args": [ "/path/to/mattermost-mcp/build/index.js" ] } } }

故障排除

如果遇到权限错误,请验证:

  1. 您的个人访问令牌具有必要的权限
  2. 令牌已正确复制到您的配置中
  3. 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

这是推荐的手动触发监控的方法,因为它:

  • 不重启服务器
  • 不会干扰预定的监控
  • 可从任何终端可靠地工作

查看频道消息.js

此脚本允许您查看任何频道中的最新消息:

# View messages in a channel (channel name is required) node view-channel-messages.js <channel-name> # View a specific number of messages node view-channel-messages.js <channel-name> <message-count> # Example: View the last 10 messages in a channel node view-channel-messages.js general 10

该脚本将显示:

  • 频道信息(名称、目的、消息总数)
  • 带有时间戳和用户名的最新消息
  • 如果该频道不存在,它将列出所有可用的频道

分析-channel.js

此脚本提供有关频道中消息的详细统计信息:

# Analyze messages in a channel (channel name is required) node analyze-channel.js <channel-name> # Analyze a specific number of messages node analyze-channel.js <channel-name> <message-count> # Example: Analyze the last 50 messages in a channel node analyze-channel.js general 50

该脚本将显示:

  • 频道信息和元数据
  • 消息总数(包括系统消息)
  • 用户消息与系统消息的细分
  • 按用户统计的消息数量
  • 频道中最新消息

获取最后一条消息.js

此脚本仅从频道中检索最新消息:

# Get the last message from a channel (channel name is required) node get-last-message.js <channel-name> # Example: Get the last message from the general channel node get-last-message.js general

该脚本将显示:

  • 发件人的用户 ID 和用户名
  • 消息的时间戳
  • 完整消息内容

执照

此 MCP 服务器根据 MIT 许可证获得许可。

ID: affmyvem9i