@mrcarb0n/opencode-mcp-watchdog 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +44 -0
- package/index.js +123 -0
- package/package.json +19 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 MrCarb0n
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
# opencode-mcp-watchdog
|
|
2
|
+
|
|
3
|
+
Opencode plugin: on every startup it checks all configured MCP servers via
|
|
4
|
+
opencode's own API, reconnects the failed ones, and shows a TUI toast summary.
|
|
5
|
+
No sidecar processes — opencode core keeps owning MCP lifecycles.
|
|
6
|
+
|
|
7
|
+
## Install
|
|
8
|
+
|
|
9
|
+
Local (works today):
|
|
10
|
+
|
|
11
|
+
```bash
|
|
12
|
+
cp index.js ~/.config/opencode/plugins/mcp-watchdog.js
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
Restart opencode. ~8s after launch you get a toast like:
|
|
16
|
+
|
|
17
|
+
```
|
|
18
|
+
MCP watchdog (startup) — 14/15 connected · disabled: git
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
Via config (npm, live at https://www.npmjs.com/package/@mrcarb0n/opencode-mcp-watchdog):
|
|
22
|
+
|
|
23
|
+
```json
|
|
24
|
+
{ "plugin": ["@mrcarb0n/opencode-mcp-watchdog"] }
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
## Tool
|
|
28
|
+
|
|
29
|
+
`mcp_watchdog` with one arg:
|
|
30
|
+
|
|
31
|
+
- `status` — list every server with state (`✓ connected`, `✗ failed`, `○ disabled`, `⚠ needs_auth`)
|
|
32
|
+
- `reconnect` — reconnect failed servers now, report what recovered
|
|
33
|
+
|
|
34
|
+
## Triggers
|
|
35
|
+
|
|
36
|
+
| Trigger | Behavior |
|
|
37
|
+
|---|---|
|
|
38
|
+
| Startup (+8s) | check + heal + toast |
|
|
39
|
+
| `server.connected` | check + heal + toast (15s dedup guard) |
|
|
40
|
+
| `session.error` | silent heal, toasts only if something recovered/failed |
|
|
41
|
+
|
|
42
|
+
Servers reporting `needs_auth` / `needs_client_registration` are listed, never
|
|
43
|
+
retried. Outside the TUI (`serve`/`web`/headless) the toast is skipped and the
|
|
44
|
+
tool keeps working.
|
package/index.js
ADDED
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
import { tool } from "@opencode-ai/plugin"
|
|
2
|
+
|
|
3
|
+
// Opencode core owns MCP processes. This plugin only status-checks via the
|
|
4
|
+
// core API, reconnects failures, and toasts a summary. No sidecars.
|
|
5
|
+
|
|
6
|
+
const STARTUP_DELAY_MS = 8000
|
|
7
|
+
const DEDUP_WINDOW_MS = 15000
|
|
8
|
+
const TOAST_DURATION_MS = 5000
|
|
9
|
+
|
|
10
|
+
let lastRun = 0
|
|
11
|
+
|
|
12
|
+
async function getStatuses(client) {
|
|
13
|
+
const { data, error } = await client.mcp.status()
|
|
14
|
+
if (error) throw new Error(`mcp.status failed: ${JSON.stringify(error)}`)
|
|
15
|
+
return data ?? {}
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
async function showToast(client, body) {
|
|
19
|
+
try {
|
|
20
|
+
await client.tui.showToast({ body })
|
|
21
|
+
} catch {
|
|
22
|
+
// No TUI attached (serve/web/headless) — status tool still works.
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
function summarize(healed, after) {
|
|
27
|
+
const names = Object.keys(after)
|
|
28
|
+
const ok = names.filter((n) => after[n]?.status === "connected").length
|
|
29
|
+
const failed = names.filter((n) => after[n]?.status === "failed")
|
|
30
|
+
const needsAuth = names.filter(
|
|
31
|
+
(n) => after[n]?.status === "needs_auth" || after[n]?.status === "needs_client_registration",
|
|
32
|
+
)
|
|
33
|
+
const disabled = names.filter((n) => after[n]?.status === "disabled")
|
|
34
|
+
const recovered = healed.filter((n) => after[n]?.status === "connected")
|
|
35
|
+
return { total: names.length, ok, failed, needsAuth, disabled, recovered }
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
async function checkAndHeal(client, reason, { quiet = false } = {}) {
|
|
39
|
+
if (Date.now() - lastRun < DEDUP_WINDOW_MS) return null
|
|
40
|
+
lastRun = Date.now()
|
|
41
|
+
|
|
42
|
+
const before = await getStatuses(client)
|
|
43
|
+
const healed = []
|
|
44
|
+
for (const [name, s] of Object.entries(before)) {
|
|
45
|
+
if (s?.status !== "failed") continue
|
|
46
|
+
try {
|
|
47
|
+
const { data } = await client.mcp.connect({ path: { name } })
|
|
48
|
+
if (data) healed.push(name)
|
|
49
|
+
} catch {
|
|
50
|
+
// Still down — reported below.
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
const after = await getStatuses(client).catch(() => before)
|
|
54
|
+
const sum = summarize(healed, after)
|
|
55
|
+
|
|
56
|
+
const bits = [`${sum.ok}/${sum.total} connected`]
|
|
57
|
+
if (sum.recovered.length) bits.push(`reconnected: ${sum.recovered.join(", ")}`)
|
|
58
|
+
if (sum.failed.length) bits.push(`failed: ${sum.failed.join(", ")}`)
|
|
59
|
+
if (sum.needsAuth.length) bits.push(`needs auth: ${sum.needsAuth.join(", ")}`)
|
|
60
|
+
if (sum.disabled.length) bits.push(`disabled: ${sum.disabled.join(", ")}`)
|
|
61
|
+
const variant = sum.failed.length ? "error" : sum.needsAuth.length ? "warning" : "success"
|
|
62
|
+
|
|
63
|
+
if (!quiet || sum.recovered.length || sum.failed.length) {
|
|
64
|
+
await showToast(client, {
|
|
65
|
+
title: `MCP watchdog (${reason})`,
|
|
66
|
+
message: bits.join(" · "),
|
|
67
|
+
variant,
|
|
68
|
+
duration: TOAST_DURATION_MS,
|
|
69
|
+
})
|
|
70
|
+
}
|
|
71
|
+
return sum
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
function formatStatus(statuses) {
|
|
75
|
+
return Object.entries(statuses)
|
|
76
|
+
.map(([name, s]) => {
|
|
77
|
+
const icon =
|
|
78
|
+
s.status === "connected" ? "✓" : s.status === "disabled" ? "○" : s.status === "failed" ? "✗" : "⚠"
|
|
79
|
+
const extra = s.error ? ` — ${s.error}` : ""
|
|
80
|
+
return ` ${icon} ${name} - ${s.status}${extra}`
|
|
81
|
+
})
|
|
82
|
+
.join("\n")
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
export const McpWatchdog = async ({ client }) => {
|
|
86
|
+
// Opencode itself triggers this on every startup.
|
|
87
|
+
setTimeout(() => {
|
|
88
|
+
checkAndHeal(client, "startup").catch((e) => console.log(`[mcp-watchdog] startup check failed: ${e.message}`))
|
|
89
|
+
}, STARTUP_DELAY_MS)
|
|
90
|
+
|
|
91
|
+
return {
|
|
92
|
+
event: async ({ event }) => {
|
|
93
|
+
if (event.type === "server.connected") {
|
|
94
|
+
await checkAndHeal(client, "server.connected").catch((e) =>
|
|
95
|
+
console.log(`[mcp-watchdog] check failed: ${e.message}`),
|
|
96
|
+
)
|
|
97
|
+
}
|
|
98
|
+
if (event.type === "session.error") {
|
|
99
|
+
await checkAndHeal(client, "session.error", { quiet: true }).catch(() => {})
|
|
100
|
+
}
|
|
101
|
+
},
|
|
102
|
+
tool: {
|
|
103
|
+
mcp_watchdog: tool({
|
|
104
|
+
description: "Show MCP server statuses, reconnect failed servers",
|
|
105
|
+
args: {
|
|
106
|
+
action: tool.schema
|
|
107
|
+
.enum(["status", "reconnect"])
|
|
108
|
+
.describe("status lists servers, reconnect reconnects failed ones"),
|
|
109
|
+
},
|
|
110
|
+
async execute(args) {
|
|
111
|
+
if (args.action === "status") return formatStatus(await getStatuses(client))
|
|
112
|
+
const r = await checkAndHeal(client, "manual")
|
|
113
|
+
if (!r) return "Check ran recently — see toast for status."
|
|
114
|
+
return (
|
|
115
|
+
`Reconnected: ${r.recovered.join(", ") || "none"}\n` +
|
|
116
|
+
`Still failing: ${r.failed.join(", ") || "none"}\n` +
|
|
117
|
+
`Needs auth: ${r.needsAuth.join(", ") || "none"}`
|
|
118
|
+
)
|
|
119
|
+
},
|
|
120
|
+
}),
|
|
121
|
+
},
|
|
122
|
+
}
|
|
123
|
+
}
|
package/package.json
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@mrcarb0n/opencode-mcp-watchdog",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "Opencode plugin: auto-check and reconnect failed MCP servers, with TUI toast status",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "index.js",
|
|
7
|
+
"exports": {
|
|
8
|
+
".": "./index.js"
|
|
9
|
+
},
|
|
10
|
+
"dependencies": {
|
|
11
|
+
"@opencode-ai/plugin": "^1.17.13"
|
|
12
|
+
},
|
|
13
|
+
"license": "MIT",
|
|
14
|
+
"author": "MrCarb0n",
|
|
15
|
+
"repository": {
|
|
16
|
+
"type": "git",
|
|
17
|
+
"url": "https://github.com/MrCarb0n/opencode-mcp-watchdog.git"
|
|
18
|
+
}
|
|
19
|
+
}
|