MCP服务器热重载工具

MCPmon是一个用于MCP服务器的热重载工具,支持单服务器和多服务器网关模式,自动重启服务器并更新工具列表。

  • by b17z
  • Python
  • 本地部署
  • 更新于

使用说明

麦普蒙

MCP服务器的热重新加载。类似于nodemon,但适用于MCP。

特性

  • 热重载 -文件更改时重新启动服务器
  • 工具刷新 -发送 notifications/tools/list_changed 因此,Claude Code可以在不重新启动会话的情况下看到新工具
  • 网关模式 -在一个网关后聚合多个MCP服务器
  • 双重实施 -Python和Bun/TypeScript具有全功能奇偶性

安装

# Python
pip install mcpmon

# Bun (no install needed)
bunx mcpmon

# npm
npm install -g mcpmon

# Or download binary from GitHub releases (no dependencies)

用法

单服务器模式

mcpmon --watch src/ -- python -m my_mcp_server

网关模式(多服务器)

mcpmon --config .mcpmon.yaml
# .mcpmon.yaml
servers:
  sage:
    command: sage-mcp
    watch: ~/.sage/src/

  crucible:
    command: crucible-mcp
    watch: ~/crucible/src/

  my-server:
    command: python
    args: ["-m", "my_server"]
    watch: ./src/
    extensions: py,json

Gateway使用前缀聚合工具: sage::recall, crucible::review等等。

选项

选项 描述
-c, --config <file> 多服务器网关模式的配置文件
-w, --watch <dir> 要监视的目录(默认: .)
-e, --ext <exts> 要监视的扩展名,逗号分隔(默认值: py)
-q, --quiet 仅显示错误
-v, --verbose 显示文件更改详细信息
--debug 显示所有调试输出
-t, --timestamps 在输出中包含时间戳
-l, --log-file <file> 同时将日志写入文件

日志记录级别

--quiet       Only errors
(default)     Start, stop, restart events + PID
--verbose     + file change details
--debug       + everything

例子

# Basic - watch current directory for .py changes
mcpmon -- python server.py

# Watch specific directory and extensions
mcpmon --watch src/ --ext py,json -- python -m myserver

# With timestamps and log file
mcpmon --timestamps --log-file mcpmon.log -- python server.py

# Gateway mode - multiple servers
mcpmon --config .mcpmon.yaml

示例输出

[mcpmon 16:08:50] Watching src/ for .py changes
[mcpmon 16:08:50 pid:53307] Started: python -m my_server
[mcpmon 16:08:54] File modified: tools.py
[mcpmon 16:08:54 pid:53307] Restarting...
[mcpmon 16:08:54 pid:53411] Started: python -m my_server
[mcpmon 16:08:54 pid:53411] Restart #1 complete
[mcpmon 16:08:54] Sent tools/list_changed notification

MCP配置

单台服务器

{
  "mcpServers": {
    "my-server": {
      "command": "mcpmon",
      "args": ["--watch", "src/", "--", "python", "-m", "my_server"]
    }
  }
}

网关(多台服务器)

{
  "mcpServers": {
    "gateway": {
      "command": "mcpmon",
      "args": ["--config", ".mcpmon.yaml"]
    }
  }
}

运作原理

单服务器模式

  1. 将MCP服务器作为子进程启动
  2. 监视指定目录以进行文件更改
  3. 关于变化:SIGTERM→ 等待2秒→ 西格尔→ 重新启动
  4. 发送 notifications/tools/list_changed 通知
  5. Claude Code自动刷新工具缓存

网关模式

  1. 读取配置文件,启动所有后端服务器
  2. 从所有后端聚合工具(前缀: backend::tool)
  3. 将工具调用路由到正确的后端
  4. 独立监视每个后端的文件
  5. 更改时热重新加载单个后端
  6. 配置更改时热添加/删除后端

发展

# Python
pip install -e ".[dev]"
pytest tests/ -v  # 42 tests

# Bun/TypeScript
bun test  # 16 tests

许可证

麻省理工学院