mcp-restart
A supervisor MCP server that starts, stops, and restarts local agents as child processes over HTTP, allowing agents to restart themselves and evolve without human intervention.
README
mcp-restart
Supervise your local agents over MCP — start, stop, and restart them, including restarting themselves.
mcp-restart is a small supervisor server. You run it, it starts your agent (Claude Code, or anything else you can launch from a command line) as a child process, and exposes start_agent, stop_agent, restart_agent over a Model Context Protocol endpoint on localhost.
The killer feature: because the agent is a child of the supervisor, the agent can call restart_agent on itself. It edits its own launch config, restarts, and comes back up as the new version — an evolution loop with no human in the middle.
┌─────────────────────────────────────────────┐
│ mcp-restart (supervisor) │
│ │
│ http://127.0.0.1:4310/mcp ◄── MCP tools │
│ │ │
│ │ spawn / SIGTERM / SIGKILL │
│ ▼ │
│ ┌───────────────────────────┐ │
│ │ claude (child process) │ │
│ │ --mcp-config → restart │ │
│ └───────────────────────────┘ │
└─────────────────────────────────────────────┘
Why a supervisor instead of an MCP server the agent spawns?
An MCP server over stdio is a child of the agent. If the agent kills itself, its pipes close and the server dies with it — you can't restart something from inside a process it spawned.
mcp-restart inverts that: the supervisor is the parent, the agent is the child. Restarting an agent is just kill + respawn, the supervisor owns one port for the whole session (no port contention across restarts), and the supervisor's lifetime is independent of any single agent's lifetime. The agent talks to it over loopback HTTP, so the connection is re-established on every boot.
Quickstart
# install
npm install -g mcp-restart # or: npx mcp-restart ... (no install)
# create a config
mcp-restart init
# → wrote ./mcp-restart.config.json
# start the supervisor (starts agents with "autostart": true)
mcp-restart serve
Generated config:
{
"host": "127.0.0.1",
"port": 4310,
"agents": [
{
"name": "claude",
"command": "claude",
"cwd": ".",
"autostart": true
}
]
}
When serve starts, it spawns Claude with --mcp-config <generated> pointing at http://127.0.0.1:4310/mcp. Claude has the restart tools from the moment it boots. Ctrl+C the supervisor and everything shuts down cleanly together.
MCP tools
| Tool | Description |
|---|---|
list_agents |
All configured agents with state, pid, uptime, last exit code |
server_status |
Version, pid, endpoint URL, uptime, agent statuses |
start_agent |
Start a configured agent (name) |
stop_agent |
Stop gracefully: SIGTERM → wait for graceful timeout → SIGKILL |
restart_agent |
Stop, re-read the config file, start again with the fresh config |
Every tool returns structured JSON. Unknown agents and invalid operations come back as MCP tool errors, never crashes.
The self-restart loop (agent evolution)
The point of this project. An agent that can restart itself can evolve: edit its code or its launch config, then reboot into the new version.
- The agent writes its own entry into
mcp-restart.config.json(it knows how it's launched). - It calls
restart_agentwith its own name. - The supervisor terminates it, re-reads the config file, and spawns the replacement.
- The new agent boots, reconnects to the same endpoint, and picks up where the loop left off.
Because the config is re-read on every restart, changes take effect immediately — no supervisor restart required. The supervisor itself only cares that the agent is running; what the agent becomes is up to the agent.
Config reference
Top-level:
| Field | Default | Description |
|---|---|---|
host |
127.0.0.1 |
Bind address. Non-loopback addresses require a token. |
port |
4310 |
TCP port. 0 picks a free port. |
token |
— | Bearer token required on all MCP requests (also settable via MCP_RESTART_TOKEN). |
stateDir |
~/.local/state/mcp-restart |
Generated MCP configs, supervisor log, agent logs. |
agents |
[] |
Array of agent definitions. |
Per agent:
| Field | Default | Description |
|---|---|---|
name |
— | Unique name used to address the agent (letters, digits, ., _, -). |
command |
— | Executable to spawn, resolved via PATH. No shell involved — put everything in args. |
args |
[] |
Arguments. |
cwd |
supervisor's cwd | Working directory. |
env |
— | Extra environment variables. |
autostart |
false |
Start when the supervisor starts. |
gracefulTimeoutMs |
10000 |
How long to wait after SIGTERM before SIGKILL. |
injectMcp |
true |
Wire the restart MCP config into the agent (see below). |
logFile |
<stateDir>/logs/<name>.log |
Agent stdout/stderr in --daemon mode. |
MCP injection
With injectMcp: true (default), the supervisor:
- generates a standard MCP config file (
{ "mcpServers": { "restart": { "type": "http", "url": ... } } }) in<stateDir>/mcp-config/<name>.mcp.json, - sets
MCP_RESTART_URLandMCP_RESTART_CONFIG_FILEenv vars for the agent, - for Claude Code (
commandbasename starting withclaude), appends--mcp-config <file>so it's wired up automatically.
Any MCP-capable agent can read MCP_RESTART_CONFIG_FILE and register the restart server itself.
Running in the background
mcp-restart serve --daemon
Daemon mode detaches from the terminal, writes the supervisor log to <stateDir>/mcp-restart.log, and routes agent output to per-agent log files. Agents run headless. Stop it with pkill -TERM -f "mcp-restart serve" or a service manager.
For always-on setups, run serve --daemon under launchd/systemd/whatever you already use for long-running things.
Security
- Loopback only by default. Binding anything else is refused unless you set a
token. - Token auth — when set, every MCP request requires
Authorization: Bearer <token>. - The supervisor only touches processes it spawned. There is no "kill arbitrary PID" tool.
restart_agentoperates exclusively on configured agents. - Graceful-then-forced stops. SIGTERM first, SIGKILL only after
gracefulTimeoutMs. - No shell.
command/argsare passed toexecvpdirectly — no shell injection surface.
FAQ
Why not stdio? Because a stdio MCP server dies with the agent that spawned it. The whole point is surviving the agent's death — and the supervisor model removes the "detached respawn" dance entirely.
Why HTTP instead of spawning a fresh MCP server per boot? One supervisor owns one port for the whole session. No port contention, no config re-wiring across restarts, and the loopback endpoint is reachable by any local process.
Does my agent auto-restart when it crashes? No. autostart only runs at supervisor boot; crashes are logged, never restarted silently. No crash loops. If you want crash-restart, wrap the agent (or run it under launchd/systemd) — the supervisor will happily supervise whatever comes up.
What about Windows? The code has basic support (no process-group kills — children are signalled directly) but it's untested. macOS and Linux are the supported platforms.
What if I remove an agent from the config while it's running? The process keeps running (we don't kill things just because you edited a file) but it stops appearing in list_agents. Use stop_agent first.
Development
npm install
npm run build # tsc → dist/
npm test # 30 tests: config validation, supervision, full MCP loop, CLI
npm run typecheck # strict typecheck of src + test
The integration test boots the real stack (HTTP server + MCP client) with a fake agent, restarts it through the MCP protocol, verifies the replacement sees the edited config, and confirms auth rejection without a token.
License
MIT
推荐服务器
Baidu Map
百度地图核心API现已全面兼容MCP协议,是国内首家兼容MCP协议的地图服务商。
Playwright MCP Server
一个模型上下文协议服务器,它使大型语言模型能够通过结构化的可访问性快照与网页进行交互,而无需视觉模型或屏幕截图。
Magic Component Platform (MCP)
一个由人工智能驱动的工具,可以从自然语言描述生成现代化的用户界面组件,并与流行的集成开发环境(IDE)集成,从而简化用户界面开发流程。
Audiense Insights MCP Server
通过模型上下文协议启用与 Audiense Insights 账户的交互,从而促进营销洞察和受众数据的提取和分析,包括人口统计信息、行为和影响者互动。
VeyraX
一个单一的 MCP 工具,连接你所有喜爱的工具:Gmail、日历以及其他 40 多个工具。
graphlit-mcp-server
模型上下文协议 (MCP) 服务器实现了 MCP 客户端与 Graphlit 服务之间的集成。 除了网络爬取之外,还可以将任何内容(从 Slack 到 Gmail 再到播客订阅源)导入到 Graphlit 项目中,然后从 MCP 客户端检索相关内容。
Kagi MCP Server
一个 MCP 服务器,集成了 Kagi 搜索功能和 Claude AI,使 Claude 能够在回答需要最新信息的问题时执行实时网络搜索。
e2b-mcp-server
使用 MCP 通过 e2b 运行代码。
Neon MCP Server
用于与 Neon 管理 API 和数据库交互的 MCP 服务器
Exa MCP Server
模型上下文协议(MCP)服务器允许像 Claude 这样的 AI 助手使用 Exa AI 搜索 API 进行网络搜索。这种设置允许 AI 模型以安全和受控的方式获取实时的网络信息。