open-reload
OfficialThis server does not currently have a deployable release on Glama. Follow the repository's setup instructions to install and configure it for your MCP client, including any required credentials and local dependencies.
open-reload
Self-reloading MCP meta-plugin for OpenCode. Watches plugin source files and its own brain, re-imports on change, and serves tools, resources, and prompts via MCP with live tools/list_changed notifications. No restart required — not even to improve the tool itself.
v2 — Full plugin platform with context threading, Zod schema passthrough, cross-plugin events, MCP resources, MCP prompts, multi-agent namespace routing, plugin dependency resolution, and persistent state.
Core Idea
open-reload can reload ~80% of itself at runtime. The architecture splits into:
Shell (~650 lines, never reloads): MCP stdio transport, process lifecycle, watcher handles, brain swapper
Brain (everything else, hot-reloadable): config loading, plugin management, tool/resource/prompt routing, watch policy, event bus, state persistence
An AI agent can edit brain code → the shell detects the change → purges the brain module graph → re-imports → atomically swaps the live brain. If the new brain fails, the old one stays active.
Plugins return tools, resources, prompts, and a dispose hook. The brain threads per-call context (CWD, session ID, agent ID) to plugin execute functions, passes Zod schemas through for client-side validation, and routes events between plugins.
┌──────────────┐ stdio ┌──────────────────────────────────────────┐
│ OpenCode │ <────────────> │ Shell (permanent) │
│ (client) │ MCP proto │ ┌────────────────────────────────────┐ │
└──────────────┘ │ │ Brain (hot-swappable) │ │
│ │ - config loading │ │
│ │ - plugin cache-bust import │ │
│ │ - tool/resource/prompt extraction │ │
│ │ - tool routing + context threading │ │
│ │ - cross-plugin event bus │ │
│ │ - dependency-ordered loading │ │
│ │ - namespace + agent filtering │ │
│ │ - persistent state (snapshot) │ │
│ │ - system prompts │ │
│ │ - watch policy │ │
│ └────────────────────────────────────┘ │
│ │
│ fs.watch(src/brain/**) → reload │
│ fs.watch(plugin dirs) → delegate │
└──────────────────────────────────────────┘Related MCP server: MCP Reloader
How Plugin Reload Works
Watch plugin source directories for
.ts/.jschangesRe-import the plugin module with Bun cache busting
Diff old vs new tool/resource/prompt list
Notify client via MCP
notifications/tools/list_changedClient re-fetches
tools/listand gets the updated tools
When a plugin with dependents changes, all downstream plugins are reloaded in dependency order. Each plugin's dispose() hook is called before re-import.
How Self-Reload Works
Shell hardcodes a watcher on
src/brain/**On any change: purge all brain modules from
Loader.registryRe-import
src/brain/entry.tswith cache-busting query stringCall
factory.create(ctx, { snapshot })with state from old brainIf success: dispose old brain, swap pointer. If failure: keep old brain.
Native Plugin Mode
open-reload can also run as a native OpenCode plugin instead of an MCP server. In this mode, it installs directly into OpenCode's plugin system and uses trampoline tools/hooks for hot-reload.
Setup
Add to your OpenCode config (.opencode/config.json):
{
"plugins": ["/path/to/open-reload/src/native/index.ts"]
}Plugin configuration is still read from .opencode/open-reload.json — same format as MCP mode.
How It Works
At init, open-reload loads all configured plugins and creates trampoline tools + hooks
Each trampoline delegates to a mutable backing function
File watchers monitor plugin source directories
On change: bust Bun module cache → re-import → swap backing implementations
Next LLM turn uses the updated tool implementations — no restart needed
Trampoline Pattern
OpenCode calls tool "plugin_echo"
→ Trampoline (fixed reference, registered at init)
→ Backing function (mutable, swapped on reload)
→ Actual plugin implementationV1 Limitations
Tool schemas (args, description) are fixed at init. Only execute functions are hot-swappable.
New tools added by reloaded plugins won't appear (the tool map is frozen at init).
Only
opencode-pluginformat supported in native mode.
Why MCP?
Approach | Hot-reload? | Self-reload? | Upstream changes? |
Native plugin | No | No | N/A |
MCP meta-server | Yes | ~80% | None |
With native mode, open-reload now supports both approaches:
Mode | Tool hot-reload | Hook hot-reload | Self-reload |
MCP server | Yes (full) | No | ~80% |
Native plugin | Yes (implementations only) | Yes | No |
Quick Start
bun install
bun run dev # Start the MCP server
bun test # Run tests (211 tests across 26 files)Configuration
Create open-reload.json in one of:
.opencode/open-reload.json(local project)~/.config/open-reload/open-reload.json(global)
{
"plugins": [
{
"name": "my-plugin",
"entry": "/absolute/path/to/plugin/src/index.ts",
"watchDir": "/absolute/path/to/plugin/src",
"exportType": "opencode-plugin",
"namespace": "my-namespace",
"agentVisibility": ["build", "oracle"],
"dependsOn": ["core-plugin"]
}
],
"debounceMs": 300,
"logLevel": "info",
"logFile": "/tmp/open-reload.log",
"systemPrompts": [
{
"name": "project-context",
"content": "This project uses Bun and TypeScript.",
"priority": 10
}
],
"statePath": "/tmp/open-reload-state.json"
}Configuration Fields
Field | Purpose |
| Unique plugin identifier |
| Absolute path to plugin entry file |
| Directory to watch for changes (defaults to entry's parent) |
| Module shape: |
| Prefix tool names with plugin name (default: true) |
| Worktree root — loads plugin from worktree instead of parent repo |
| Namespace for multi-agent tool filtering |
| Restrict tool visibility to specific agent IDs |
| Array of plugin names this plugin depends on (controls load order) |
| File change debounce interval (default: 300) |
| Log verbosity: |
| Write logs to file in addition to stderr |
| Brain-level MCP prompts injected as |
| Higher priority = earlier in prompt list |
| Absolute path for disk-backed snapshot persistence |
Plugin Export Types
Type | Module Shape | Returns |
|
| Tools + resources + prompts + dispose hook |
|
| Tools only |
|
| Tools only |
The opencode-plugin format supports the full v2 feature set. Plugin functions receive a context object with directory, worktree, and an events object for cross-plugin communication.
Plugin Capabilities
Context Threading
Every tool call receives a ToolCallContext with the caller's CWD, session ID, and agent ID. This is forwarded to plugin execute functions so they can resolve paths and tailor behavior per-agent.
type ToolCallContext = {
cwd: string;
sessionId?: string;
agentId?: string;
metadata?: Record<string, unknown>;
};Zod Schema Passthrough
Plugins using opencode-plugin format can define args with Zod schemas via tool.schema.*. open-reload converts these to JSON Schema for MCP transport and passes the original Zod schema as zodInputSchema for clients that support it.
Cross-Plugin Events
Plugins can emit and subscribe to typed events via the event bus:
// In plugin execute function (via context.events)
context.events.emit("build:complete", { path: "/dist" });
context.events.on("build:complete", (event) => { /* react */ });Event handlers are automatically cleaned up when a plugin is reloaded or disposed.
MCP Resources
Plugins can expose readable resources (files, data streams, etc.) via the resource map:
export default (ctx) => ({
tool: { /* ... */ },
resource: {
"project://status": {
description: "Current project status",
mimeType: "application/json",
read: async () => JSON.stringify({ healthy: true }),
},
},
});MCP Prompts
Plugins can expose prompt templates via the prompt map:
export default (ctx) => ({
tool: { /* ... */ },
prompt: {
"review-code": {
description: "Code review prompt",
arguments: [{ name: "file", required: true }],
get: async (args) => [
{ role: "user", content: { type: "text", text: `Review ${args.file}` } },
],
},
},
});Brain-level system prompts (configured in open-reload.json) are also served as MCP prompts with the system: prefix.
Plugin Dispose
Plugins can return a dispose function that is called before reload or shutdown:
export default (ctx) => ({
tool: { /* ... */ },
dispose: async () => {
// Clean up connections, timers, etc.
},
});Multi-Agent Routing
Plugins can be scoped to specific agents using namespace and agentVisibility:
namespace: Groups tools under a logical namespace. When the router filters by namespace, only tools in the matching namespace are returned.agentVisibility: Restricts tool visibility to specific agent IDs. A tool withagentVisibility: ["build"]is only visible to thebuildagent.
{
"plugins": [
{
"name": "deploy-tools",
"entry": "/path/to/deploy/index.ts",
"exportType": "opencode-plugin",
"namespace": "infrastructure",
"agentVisibility": ["build", "deploy"]
}
]
}Plugin Dependencies
Plugins can declare dependencies via dependsOn. open-reload performs topological sorting to ensure plugins load in the correct order. Circular dependencies are detected and rejected at startup.
When a dependency is reloaded (due to file changes), all downstream dependents are reloaded in order.
{
"plugins": [
{ "name": "core", "entry": "/path/to/core.ts", "exportType": "opencode-plugin" },
{ "name": "auth", "entry": "/path/to/auth.ts", "exportType": "opencode-plugin", "dependsOn": ["core"] },
{ "name": "api", "entry": "/path/to/api.ts", "exportType": "opencode-plugin", "dependsOn": ["core", "auth"] }
]
}Persistent State
When statePath is configured, the brain saves a snapshot of plugin state (reload counts, tool/resource/prompt inventories) to disk on dispose. On next startup, the snapshot is restored so plugins retain their reload history across process restarts.
{
"statePath": "/tmp/open-reload-state.json"
}Worktree-Aware Reload
Plugins can be loaded from git worktrees instead of the parent repo. Set worktreePath to the worktree's source directory — open-reload resolves the entry point relative to this path while keeping the original watchDir for change detection.
This enables per-task plugin development: create a worktree, edit the plugin, and open-reload loads the worktree version without affecting other environments.
{
"plugins": [
{
"name": "my-plugin",
"entry": "/repos/my-plugin/src/index.ts",
"watchDir": "/repos/my-plugin/src",
"worktreePath": "/worktrees/env_abc/my-plugin/src",
"exportType": "opencode-plugin"
}
]
}Agent Setup
OpenCode (settings.json or equivalent):
{
"mcpServers": {
"open-reload": {
"command": "bun",
"args": ["run", "/path/to/open-reload/src/shell/main.ts"]
}
}
}Project Structure
src/
index.ts # Barrel exports
shell/ # PERMANENT — never reloads
brain-api.ts # Stable contract: ToolCallContext, ResourceSpec, PromptSpec, BrainAPI
brain-loader.ts # Purge + import + atomic swap
watch-driver.ts # fs.watch() orchestration + debouncing
core-tools.ts # openreload_reload, openreload_status (always work)
mcp.ts # MCP server + stdio transport (tools, resources, prompts)
main.ts # Process entry
brain/ # HOT-RELOADABLE — all interesting logic
entry.ts # BrainFactory → BrainAPI, topoSort, dependency-cascading reload
config/
types.ts # PluginConfig (namespace, dependsOn, agentVisibility), OpenReloadConfig (systemPrompts, statePath)
loader.ts # Config resolution + validation
loader/
module-loader.ts # Bun cache-busting plugin import, tool/resource/prompt extraction
router/
tool-router.ts # Tool name → plugin execute routing, namespace + agent filtering
events/
event-bus.ts # Cross-plugin event bus with per-plugin handler tracking
watcher/
policy.ts # WatchPlan generation + event classification
state/
plugin-state.ts # Per-plugin state management, snapshots, resource/prompt tracking
native/ # NATIVE OpenCode plugin mode
index.ts # Plugin entry point (default export)
manager.ts # Plugin lifecycle: load, reload, watch
trampolines.ts # Trampoline tool + hook backing managementArchitecture Invariants
Shell never imports from
src/brain/. Contract lives insrc/shell/brain-api.ts.Brain reload invalidates the entire
src/brain/**module graph.Brain reload is atomic: new brain succeeds or old brain stays.
openreload_reloadtool always works, even if brain is broken.Shell self-watch triggers reload without consulting brain.
Plugin dependencies are topologically sorted — circular dependencies are rejected.
Event handlers are cleaned up on plugin reload — no leaked subscriptions.
Persistent state uses atomic write (write to
.tmp, rename) — no partial snapshots.
License
MIT
Tool Schema Changelog
Recent tool additions, removals, and schema changes observed during successful MCP inspections.
Loading tool schema changelog…
This server cannot be deployed
Maintenance
Related MCP Connectors
Hot Module Reload (HMR) for Python with reactive programming and MCP tools
Nifty's MCP server — exposes tasks, projects, messages, and files as tools for AI agents.
The official Svelte MCP server providing docs and autofixing tools for Svelte development
Lean 4 MCP server: compile, prove theorems, and formalize math with Mathlib.
Related MCP Servers
AlicenseNot gradedqualityDmaintenanceA dynamic MCP server implementation that automatically loads tools, resources, and prompts from their respective directories, allowing for easy extension and configuration.MIT- AlicenseNot gradedqualityDmaintenanceA hot-reload development tool that enables real-time development of MCP (Model Context Protocol) servers by automatically reloading tools as they're modified without requiring manual restarts.11MIT
- AlicenseNot gradedqualityDmaintenanceA hot-reloadable MCP proxy server that enables users to create and manage custom Python tools through dynamic module loading. Users can build their own utilities, wrap APIs, and extend functionality by simply adding Python files to designated folders.7Apache 2.0
- AlicenseCqualityDmaintenanceEnables to create MCP tools by simply placing .ts or .js files in a folder, with hot reload and TypeScript support.1611 npmMIT