Skip to main content

Auto-reload OpenCode MCP servers without restarting

Project description

OpenCode MCP Auto-Reload Watcher

PyPI version Python 3.8+ License: MIT GitHub stars

๐Ÿš€ Never restart OpenCode again! Auto-reload MCP servers when config changes.

Tired of exiting and restarting OpenCode every time you modify an MCP server? MCP Watch monitors your opencode.json and automatically restarts only the changed MCP servers - in seconds, not minutes.

Demo

โœจ Features

  • โšก Instant Reload - Changes apply in ~1 second, not 30+ seconds
  • ๐ŸŽฏ Smart Detection - Only restarts MCPs that actually changed
  • ๐Ÿ” File Watching - Uses efficient inotify/watchdog (no polling)
  • ๐Ÿ“Š Process Management - Graceful shutdown with fallback to force kill
  • ๐Ÿ“ Detailed Logging - See exactly what changed and when
  • ๐ŸŽ›๏ธ CLI Commands - Status, manual restart, stop all, etc.
  • ๐Ÿง Cross-Platform - Linux, macOS, Windows support
  • ๐Ÿ”ง Zero Config - Works out of the box with your existing setup

๐Ÿš€ Quick Start

Installation

# Via pip (recommended)
pip install mcp-watch

# Or install from source
git clone https://github.com/efrg123/MCP-watch.git
cd MCP-watch
pip install -e .

Start Watching

# Start the watcher (runs in background)
mcp-watch-start

# That's it! Now edit ~/.config/opencode/opencode.json
# and watch your changes apply automatically

Stop Watching

mcp-watch-stop

๐Ÿ“– Usage

Automatic Mode (Recommended)

  1. Start the watcher:

    mcp-watch-start
    
  2. Edit your OpenCode config:

    vim ~/.config/opencode/opencode.json
    
  3. Save the file โ†’ MCP servers restart automatically!

CLI Commands

# Check status of all MCP servers
mcp-watch --status

# Restart a specific MCP server
mcp-watch --restart pandas-mcp-server

# Restart all MCP servers
mcp-watch --restart-all

# Stop all MCP servers
mcp-watch --kill

# Show help
mcp-watch --help

Systemd Service (Linux)

Enable automatic startup on boot:

# Enable the service
systemctl --user enable mcp-watch.service

# Start the service
systemctl --user start mcp-watch.service

# Check status
systemctl --user status mcp-watch.service

# View logs
journalctl --user -u mcp-watch.service -f

๐ŸŽฏ Why MCP Watch?

Without MCP Watch With MCP Watch
Edit config Edit config
Exit OpenCode Save file
Wait for shutdown โœ… Done in 1 second
Restart OpenCode
Wait 30+ seconds
Reconnect to session

Time saved: 30+ seconds per config change

๐Ÿ”ง How It Works

โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”     โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”     โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚  opencode.json  โ”‚โ”€โ”€โ”€โ”€โ–ถโ”‚  MCP Watch   โ”‚โ”€โ”€โ”€โ”€โ–ถโ”‚  Restart MCPs   โ”‚
โ”‚   (watched)     โ”‚     โ”‚  (detector)  โ”‚     โ”‚  (only changed) โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜     โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜     โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
         โ”‚                                               โ”‚
         โ”‚                                               โ”‚
         โ–ผ                                               โ–ผ
   You edit config                             MCP servers restart
   and save file                               (others keep running)

Technical Details

  1. File Watching: Uses watchdog library with inotify on Linux for efficient file system monitoring
  2. Change Detection: SHA256 hash comparison to detect actual changes, not just file timestamps
  3. Process Management:
    • Sends SIGTERM for graceful shutdown
    • Waits 1 second
    • Sends SIGKILL if still running
  4. Debouncing: 2-second debounce to handle rapid successive saves

๐Ÿ“Š Log Output

2026-03-14 20:07:20,988 - INFO - OpenCode MCP Watcher Started
2026-03-14 20:07:20,988 - INFO - Watching: /home/fahd/.config/opencode/opencode.json
2026-03-14 20:07:52,372 - INFO - Detected change in opencode.json
2026-03-14 20:07:52,372 - INFO - MCP config changed: memory
2026-03-14 20:07:52,373 - INFO - Restarting MCP: memory
2026-03-14 20:07:52,388 - INFO - Sent SIGTERM to MCP: memory (PID: 52771)
2026-03-14 20:07:53,889 - INFO - Started MCP: memory (PID: 88820)

View logs:

tail -f ~/.config/opencode/mcp-watch.log

๐Ÿ› ๏ธ Configuration

Environment Variables

Variable Description Default
MCP_WATCH_CONFIG Path to opencode.json ~/.config/opencode/opencode.json
MCP_WATCH_LOG Path to log file ~/.config/opencode/mcp-watch.log
MCP_WATCH_PID Path to PID file ~/.config/opencode/mcp-watch.pid
MCP_WATCH_DEBOUNCE Debounce time in seconds 2

Example

export MCP_WATCH_CONFIG=/custom/path/opencode.json
export MCP_WATCH_DEBOUNCE=5
mcp-watch-start

๐Ÿ› Troubleshooting

MCP servers not restarting

  1. Check if watcher is running:

    pgrep -f mcp-watch
    
  2. Check logs for errors:

    cat ~/.config/opencode/mcp-watch.log
    
  3. Verify MCP config is valid:

    python3 -c "import json; json.load(open('/home/user/.config/opencode/opencode.json'))"
    

Permission denied

Make sure the script has access to:

  • Read ~/.config/opencode/opencode.json
  • Execute MCP server commands
  • Use pgrep and kill

Windows support

On Windows, the watcher uses polling mode (less efficient but works). For best performance, use WSL2.

๐Ÿค Contributing

We welcome contributions! Please see CONTRIBUTING.md for guidelines.

Development Setup

git clone https://github.com/efrg123/MCP-watch.git
cd MCP-watch
python3 -m venv venv
source venv/bin/activate
pip install -e ".[dev]"
pytest

๐Ÿ“‹ Roadmap

  • Web dashboard for MCP status
  • Health check before marking restart successful
  • Dry-run mode
  • Windows service support
  • Docker container support
  • Integration with Claude Code (when API available)

๐Ÿ“ License

MIT License - see LICENSE file

๐Ÿ™ Acknowledgments

  • Inspired by the frustration of restarting OpenCode 50 times a day
  • Thanks to the OpenCode community for feature requests (#6719)
  • Built with watchdog for efficient file watching

โญ Star History

Star History Chart


Enjoying MCP Watch? Give us a โญ on GitHub!

GitHub stars

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

opencode_mcp_watch-0.1.1.tar.gz (14.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

opencode_mcp_watch-0.1.1-py3-none-any.whl (10.1 kB view details)

Uploaded Python 3

File details

Details for the file opencode_mcp_watch-0.1.1.tar.gz.

File metadata

  • Download URL: opencode_mcp_watch-0.1.1.tar.gz
  • Upload date:
  • Size: 14.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.12

File hashes

Hashes for opencode_mcp_watch-0.1.1.tar.gz
Algorithm Hash digest
SHA256 e5522e6a310ecc93c577c3c336a30be7007cf329015a34ae901e60031e60f5b9
MD5 5bef828eff114d3ff8309d11ea9f51fd
BLAKE2b-256 0c8f220ca1e7eb2f420dc0014fb1b5469c0636909951bc08b234a4a17f0469aa

See more details on using hashes here.

File details

Details for the file opencode_mcp_watch-0.1.1-py3-none-any.whl.

File metadata

File hashes

Hashes for opencode_mcp_watch-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 6dc0c1ee957fbc71809e10dd8dfcdf8f5578270020e88391eb003ebb0998dd49
MD5 84d8a671fefb52331a14aba33bf516bf
BLAKE2b-256 648f79c47eeb77c9a6a3470895adf93eb998b48752478d4e2fcca2e4cf22aec3

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page