ai-agentmanager 1.42.0 → 1.43.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/CHANGELOG.md CHANGED
@@ -1,5 +1,13 @@
1
1
  # Changelog
2
2
 
3
+ ## 1.43.0 (2026-11-11)
4
+
5
+ - **An MCP session of its own.** Each folder (your home folder or an agent's workspace) gets one Claude Code process for MCP, separate from any agent's session. Listing servers, signing in, reconnecting and calling a tool make no model call and don't interrupt an agent. It closes after 15 minutes unused; **Refresh all** starts a new one.
6
+ - **Sign in to MCP servers.** A server that needs it shows **Sign in** (or `agentmgr mcp signin`), which opens its sign-in page. Claude Code keeps the tokens; the app never sees them. From another device, paste the address the browser ended on.
7
+ - **Reconnect one server** with **↻** (or `agentmgr mcp reconnect`), leaving the others alone.
8
+ - **Run a tool directly.** **Run** with JSON arguments (or none) calls the tool with no model call and shows its output as it is; plain words still go through a one-off Claude Code call allowed only that tool, and **Run in agent session** asks the agent. The last 30 runs are kept with their results, and **↗ Window** opens the panel on its own (`#mcp`). The `mcp.run` plugin policy now gets `where`.
9
+ - **Update from the app** shows an in-page dialog with live progress (install, restart, reload) instead of a browser confirm and a short toast.
10
+
3
11
  ## 1.42.0 (2026-11-11)
4
12
 
5
13
  - **MCP servers and tools.** **MCP** in the top bar (or **MCP tools** in an agent's detail, or `agentmgr mcp [agent]`) lists the MCP servers Claude Code has in your home folder or an agent's workspace: your own, the project's `.mcp.json`, claude.ai connectors and plugins' servers. Each shows its status, where it comes from and its tools. Listing makes no model call, and secrets are never shown.
package/README.md CHANGED
@@ -27,7 +27,7 @@ Run one background [Claude Code](https://claude.com/claude-code) agent per inten
27
27
  - **Slack alerts.** A message in your channel when an agent needs input, finishes a backlog item, or fails.
28
28
  - **Priority.** Mark agents P0–P3. P0 and P1 are highlighted, and lists sort by priority.
29
29
  - **Share for review.** One click writes an **Analysis**, **Design**, **Flow** or **Proposal** document from the agent's work, a human time **Estimate** for planning, or the change's **Documentation** with an OpenAPI spec of any API changes. Copy it as Markdown, download it, or print it to PDF with diagrams.
30
- - **MCP servers and tools.** See every MCP server Claude Code has in a folder (yours, the project's, claude.ai connectors and plugins) with its tools, and run any tool in an agent's session or once in its workspace.
30
+ - **MCP servers and tools.** See every MCP server Claude Code has in a folder (yours, the project's, claude.ai connectors and plugins) with its tools, sign in to the ones that need it, and run any tool directly, through Claude Code, or in an agent's session.
31
31
  - **Human vs AI.** It splits the open questions about the work into the top 5 that need your judgment and the ones a model can answer from the evidence. It answers those, then a second model double-checks every answer.
32
32
  - **Review changes.** Each agent's diff file by file, line comments sent back to the agent as one message, then **Commit all** and **Push & open PR**, without leaving the page.
33
33
  - **Standup.** Each weekday at 9:00 (or whenever you press **Standup**, or `p`), each agent with news since the last one is read aloud in a sentence or two, each in its own voice: what it did, what it's on, what it needs from you. Agents that need you go first and quiet ones are left out. It stops on an agent that needs you, with its questions beside it to answer by tap, or by voice when **Answer by voice** is on (what you say is read back, then sent when you say "send"). The wording comes from one short tool-less model call, plain wording if that fails. A Slack alert says when it's ready (Alerts). Change the time, weekends and wording in the player, or in config.json: `"standup": { "at": "09:00", "weekends": false, "ai": true, "notify": true }`. Speech is your browser's own; voice answers may be sent to your browser's maker to be turned into text.
@@ -111,7 +111,7 @@ npm install
111
111
  npm link
112
112
  ```
113
113
 
114
- **Updating.** `agentmgr update` installs the newest release and restarts onto it; running agents pause briefly and resume. In the app, **Update to …** appears in the top bar when a release is out (checked twice a day; turn it off in **☰ → Settings** or with `agentmgr update --auto-check off`), and **About → Update and restart** does the same. Both work from a signed-in phone too: the install and restart run on the computer, and the page reloads when it's back. A clone at a release tag (or one you `npm link`ed) moves to the newest tag; a clone on a branch or with uncommitted changes is left alone. By hand, use the command for how you installed, then `agentmgr restart`:
114
+ **Updating.** `agentmgr update` installs the newest release and restarts onto it; running agents pause briefly and resume. In the app, **Update to …** appears in the top bar when a release is out (checked twice a day; turn it off in **☰ → Settings** or with `agentmgr update --auto-check off`), and **About → Update and restart** does the same. Either one opens a window that asks first, then shows each step as it happens: the install (how long it has taken, how many packages npm has fetched and its last line), the restart, and the page's reload. If the install fails, the error stays on screen with the command to run by hand, and nothing is restarted. Both work from a signed-in phone too: the install and restart run on the computer, and the page reloads when it's back. A clone at a release tag (or one you `npm link`ed) moves to the newest tag; a clone on a branch or with uncommitted changes is left alone. By hand, use the command for how you installed, then `agentmgr restart`:
115
115
 
116
116
  | Installed with | Update |
117
117
  | --- | --- |
@@ -1130,13 +1130,20 @@ Usage comes from the session transcripts and is refreshed every few seconds whil
1130
1130
 
1131
1131
  ## MCP servers and tools
1132
1132
 
1133
- **MCP** in the top bar (or **MCP tools** in an agent's detail, or `agentmgr mcp [agent]`) lists the MCP servers Claude Code has in a folder: your own servers, the project's `.mcp.json`, local ones, claude.ai connectors and plugins' servers. Each shows its status, where it comes from, where it runs and its tools, marked *read-only* or *destructive* when the server says so. Pick the home folder or any agent's workspace at the top, since a workspace adds its project's servers. The app asks Claude Code itself through its control protocol, which connects to each server but makes no model call. The list is kept for 5 minutes, and **Refresh** asks again. Environment variables, headers, URL queries and secret-looking arguments are never shown.
1133
+ **MCP** in the top bar (or **MCP tools** in an agent's detail, or `agentmgr mcp [agent]`) lists the MCP servers Claude Code has in a folder: your own servers, the project's `.mcp.json`, local ones, claude.ai connectors and plugins' servers. Each shows its status, where it comes from, where it runs and its tools, marked *read-only* or *destructive* when the server says so. Pick the home folder or any agent's workspace at the top, since a workspace adds its project's servers. Environment variables, headers, URL queries and secret-looking arguments are never shown.
1134
1134
 
1135
- **Run…** on a tool takes an optional request in plain words, then runs it in one of two ways:
1136
- - **Run in session** tells the agent to use the tool, with its conversation and context. The answer is in the session. This works for Claude Code agents.
1137
- - **Run once in workspace** (or `agentmgr mcp run <agent|home> <server> <tool> [request]`) is a separate one-off Claude Code call in that folder. It may use only that one tool, works out the arguments from your request, and shows what the tool returned. The agent isn't interrupted.
1135
+ **Its own MCP session.** Each folder gets an MCP session of its own on the daemon: one Claude Code process, separate from any agent's session, that the app talks to through Claude Code's control protocol. It keeps the servers connected, so listing, signing in, reconnecting and calling a tool make no model call and don't interrupt an agent. The session closes after 15 minutes unused and starts again when needed. **Refresh all** starts a new one, which reads the configuration again. **↗ Window** opens the panel in a window of its own (`#mcp` or `#mcp/<agent>`), and **Runs in this MCP session** at the bottom keeps the last 30 runs with their results.
1138
1136
 
1139
- A destructive tool needs a second click. Plugins can refuse one-off runs with the `mcp.run` policy.
1137
+ **Signing in.** A server that needs it shows **needs sign-in** and a **Sign in** button (or `agentmgr mcp signin <agent|home> <server>`), which opens that server's sign-in page in a new tab and keeps the link on the page. Claude Code runs the sign-in and keeps the tokens; the app never sees them. When you finish, the server connects by itself. The sign-in ends on an address on the computer the daemon runs on, so from another device (or when that last page doesn't load) paste the address the browser ended on into the box under the link. A claude.ai connector is connected on claude.ai instead: the link goes there.
1138
+
1139
+ **↻ on each server** (or `agentmgr mcp reconnect <agent|home> <server>`) connects that one server again and lists its tools, after signing in or when it failed. The others are left alone.
1140
+
1141
+ **Run…** on a tool takes its input and runs it in one of three ways:
1142
+ - **Run** with the tool's arguments as JSON (`{"query": "…"}`), or with nothing: the tool is called directly in the folder's MCP session, with no model call, and its output is shown as it is.
1143
+ - **Run** with a request in plain words: a separate one-off Claude Code call in that folder, allowed only that one tool, works out the arguments and shows what the tool returned.
1144
+ - **Run in agent session** tells the agent to use the tool, with its conversation and context. The answer is in the session. This works for Claude Code agents.
1145
+
1146
+ `agentmgr mcp run <agent|home> <server> <tool> [arguments or request]` does the first two, and `--session` the third. A destructive tool needs a second click. Plugins can refuse runs outside an agent's session with the `mcp.run` policy.
1140
1147
 
1141
1148
  ## Configuration
1142
1149
 
package/docs/plugins.md CHANGED
@@ -53,7 +53,7 @@ Policies are synchronous so every code path can call them. Keep them fast; do sl
53
53
  | `agent.start` | Before an agent's engine is launched or resumed (including after a restart) | `agent`, `fresh` |
54
54
  | `agent.message` | Before a message is typed into an agent (`tell`, inbox replies) | `agent`, `text`, `source` |
55
55
  | `agent.remove` | Before an agent is deleted | `agent`, `deleteWorkspace` |
56
- | `mcp.run` | Before an MCP tool runs once in a folder (the MCP panel's **Run once**, `agentmgr mcp run`); running it in a session goes through `agent.message` | `agent` (or null for the home folder), `dir`, `tool`, `input` |
56
+ | `mcp.run` | Before an MCP tool runs in a folder's MCP session (the MCP panel's **Run**, `agentmgr mcp run`); running it in an agent's session goes through `agent.message` | `agent` (or null for the home folder), `dir`, `tool`, `input`, `where` (`direct`: called with the JSON arguments in `input`; `workspace`: through a one-off Claude Code call) |
57
57
  | `agent.commit` | Before Commit in the review screen commits an agent's worktree | `agent`, `message` |
58
58
  | `agent.pr` | Before the review screen pushes an agent's branch and opens a pull request | `agent`, `title`, `draft` |
59
59
  | `agent.merge` | Before Merge (or auto-merge) in the Land tab merges an agent's pull request | `agent`, `url`, `method`, `auto` |
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ai-agentmanager",
3
- "version": "1.42.0",
3
+ "version": "1.43.0",
4
4
  "description": "Run background coding agents (Claude Code, Codex) per intent, and keep track of them from a web UI, your phone or the CLI",
5
5
  "keywords": [
6
6
  "claude",
package/public/app.js CHANGED
@@ -67,8 +67,10 @@ const standupOnLoad = hashId === 'standup';
67
67
  const mapOnLoad = hashId === 'map';
68
68
  const valueOnLoad = hashId === 'value';
69
69
  const reviewsOnLoad = hashId === 'reviews';
70
+ // "#mcp" or "#mcp/<agent>": the MCP window on its own.
71
+ const mcpOnLoad = hashId === 'mcp';
70
72
  let watchShown = false;
71
- let selectedId = (watchOnLoad || standupOnLoad || mapOnLoad || valueOnLoad || reviewsOnLoad ? null : hashId) || null;
73
+ let selectedId = (watchOnLoad || standupOnLoad || mapOnLoad || valueOnLoad || reviewsOnLoad || mcpOnLoad ? null : hashId) || null;
72
74
  let openTermOnLoad = hashView === 'term' || hashView === 'code' || isShell(hashView) || isBrowser(hashView);
73
75
  let filterText = '';
74
76
  // "Only agents created in the last N days": remembered in this browser.
@@ -4404,6 +4406,11 @@ function handleEvent(msg) {
4404
4406
  history.replaceState(null, '', '#');
4405
4407
  standupUi.open();
4406
4408
  }
4409
+ if (mcpOnLoad && !watchShown) {
4410
+ watchShown = true;
4411
+ history.replaceState(null, '', '#');
4412
+ mcpUi.open(agents.has(hashView) ? hashView : null);
4413
+ }
4407
4414
  if (watchOnLoad && !watchUi.isOpen() && !watchShown) {
4408
4415
  watchShown = true;
4409
4416
  watchUi.show(true);
package/public/index.html CHANGED
@@ -857,6 +857,12 @@
857
857
  </div>
858
858
  </dialog>
859
859
 
860
+ <dialog id="update-dialog" class="update-dialog" aria-label="Update">
861
+ <h2 id="update-title">Update</h2>
862
+ <div id="update-body"></div>
863
+ <div class="dialog-actions" id="update-actions"></div>
864
+ </dialog>
865
+
860
866
  <dialog id="about-dialog" class="about-dialog">
861
867
  <h2>AI Agent Manager</h2>
862
868
  <p class="hint">Run and track background coding agents, one per intent.</p>
package/public/mcp.js CHANGED
@@ -1,9 +1,27 @@
1
1
  // MCP: the MCP servers Claude Code has in an agent's folder (or the home folder), each with its
2
- // status, where it comes from and its tools; any tool runs in the agent's session, or once in the
3
- // workspace with only that tool allowed.
2
+ // status, where it comes from and its tools. Each folder has its own MCP session on the daemon
3
+ // (apart from any agent's), where a server is signed in to, connected again and its tools are
4
+ // called directly; a tool can also run through Claude Code from plain words, or in the agent's
5
+ // session. The window also opens on its own (#mcp or #mcp/<agent>).
4
6
 
5
7
  const SOURCE = { project: 'Project (.mcp.json)', user: 'User', local: 'Local', claudeai: 'claude.ai connector', dynamic: 'Added at launch', enterprise: 'Managed' };
6
8
  const STATUS = { connected: 'mcp-ok', pending: 'mcp-wait', failed: 'fail', 'needs-auth': 'mcp-wait', disabled: '' };
9
+ const STATUS_LABEL = { 'needs-auth': 'needs sign-in' };
10
+ const RAN = { direct: 'called directly', workspace: 'through Claude Code', session: 'in the session' };
11
+ const SIGN_IN_WAIT_MS = 5 * 60_000;
12
+
13
+ /** Arguments typed for a tool: nothing or a JSON object is a direct call; anything else is plain words. */
14
+ export function directArgs(input) {
15
+ const text = String(input ?? '').trim();
16
+ if (!text) return true;
17
+ if (!text.startsWith('{')) return false;
18
+ try {
19
+ const v = JSON.parse(text);
20
+ return Boolean(v) && typeof v === 'object' && !Array.isArray(v);
21
+ } catch {
22
+ return false;
23
+ }
24
+ }
7
25
 
8
26
  export function initMcp({ api, $, esc, ago, md, toast, agents }) {
9
27
  const dialog = $('#mcp-dialog');
@@ -12,33 +30,63 @@ export function initMcp({ api, $, esc, ago, md, toast, agents }) {
12
30
  let data = null;
13
31
  let loading = false;
14
32
  let query = '';
15
- const results = new Map(); // "<where>:<tool id>" -> { text, ms, at } | { error } | { running }
33
+ const results = new Map(); // "<where>:<tool id>" -> a run | { error } | { running } | { told }
16
34
  const forms = new Set(); // tool ids with their run form open
17
35
  const sure = new Set(); // destructive tools waiting for a second click
36
+ const signIns = new Map(); // "<where>:<server>" -> { url, callback, local, since, error, busy }
37
+ const reconnecting = new Set(); // "<where>:<server>"
38
+ let watching = null;
18
39
 
19
40
  const sourceOf = (s) => SOURCE[s.source] ?? (String(s.source ?? '').startsWith('plugin') ? `Plugin${s.source.includes(':') ? `: ${s.source.split(':').slice(1).join(':')}` : ''}` : s.source ?? s.scope ?? '');
20
41
 
21
- async function load(refresh = false) {
22
- loading = true;
23
- render();
42
+ async function load({ refresh = false, quiet = false } = {}) {
43
+ if (!quiet) {
44
+ loading = true;
45
+ render();
46
+ }
47
+ const at = where;
24
48
  try {
25
- data = await api('GET', `/mcp?agent=${encodeURIComponent(where)}${refresh ? '&refresh=1' : ''}`);
49
+ const next = await api('GET', `/mcp?agent=${encodeURIComponent(at)}${refresh ? '&refresh=1' : ''}`);
50
+ if (at !== where) return;
51
+ data = next;
26
52
  } catch (e) {
27
- data = { servers: [], error: e.message };
53
+ if (at !== where) return;
54
+ data = { servers: [], runs: [], error: e.message };
28
55
  } finally {
29
56
  loading = false;
30
57
  }
58
+ // A sign-in is over once its server is connected.
59
+ for (const s of data.servers ?? []) if (s.status === 'connected' && signIns.delete(`${where}:${s.name}`)) toast(`Signed in to ${s.name}`);
31
60
  render();
32
61
  }
33
62
 
63
+ /** While a sign-in is open, look again every few seconds: the server connects by itself when it's done. */
64
+ function watch() {
65
+ clearInterval(watching);
66
+ watching = setInterval(() => {
67
+ for (const [k, v] of signIns) if (Date.now() - v.since > SIGN_IN_WAIT_MS) signIns.delete(k);
68
+ if (!signIns.size || !dialog.open) return clearInterval(watching);
69
+ if ([...signIns.keys()].some((k) => k.startsWith(`${where}:`))) load({ quiet: true });
70
+ }, 3000);
71
+ }
72
+
34
73
  function picker() {
35
74
  const list = agents().filter((a) => a.workdir && a.status !== 'preparing');
36
- return `<select id="mcp-where" title="Whose folder: an agent's workspace has its project's servers too">
75
+ return `<select id="mcp-where" title="Whose folder: an agent's workspace has its project's servers too. Each folder has its own MCP session">
37
76
  <option value="home" ${where === 'home' ? 'selected' : ''}>Home folder (your servers and connectors)</option>
38
77
  ${list.map((a) => `<option value="${esc(a.id)}" ${where === a.id ? 'selected' : ''}>${esc(a.name)}</option>`).join('')}
39
78
  </select>`;
40
79
  }
41
80
 
81
+ const resultHtml = (r) =>
82
+ r?.error
83
+ ? `<p class="error">${esc(r.error)}</p>`
84
+ : r?.text
85
+ ? `<div class="mcp-result ${r.isError ? 'failed' : ''}"><p class="hint">${r.isError ? 'The tool reported an error · ' : ''}Ran ${ago(r.at)} in ${(r.ms / 1000).toFixed(1)} s, ${RAN[r.where] ?? ''}</p><div class="md">${md(r.text)}</div></div>`
86
+ : r?.told
87
+ ? `<p class="hint">Sent to ${esc(r.told)}. Its answer is in the session.</p>`
88
+ : '';
89
+
42
90
  function toolHtml(s, t) {
43
91
  const key = `${where}:${t.id}`;
44
92
  const r = results.get(key);
@@ -48,65 +96,95 @@ export function initMcp({ api, $, esc, ago, md, toast, agents }) {
48
96
  const tags = `${t.readOnly ? '<span class="tag mcp-ok" title="The server says it only reads">read-only</span>' : ''}${t.destructive ? '<span class="tag fail" title="The server says it may change or delete things">destructive</span>' : ''}`;
49
97
  const form = open
50
98
  ? `<div class="mcp-form">
51
- <textarea data-mcp-input="${esc(t.id)}" rows="2" placeholder="What it should do, or its arguments in plain words (optional)"></textarea>
99
+ <textarea data-mcp-input="${esc(t.id)}" rows="2" placeholder='Its arguments as JSON, like {"query": "…"}, or nothing: called directly, no model. Or say what it should do in plain words: Claude Code works out the arguments.'></textarea>
52
100
  ${sure.has(t.id) ? `<p class="hint error">${esc(t.name)} may change or delete things. Click again to run it.</p>` : ''}
53
101
  <div class="mcp-actions">
54
- ${agent ? `<button type="button" class="small" data-mcp-run="session" data-server="${esc(s.name)}" data-tool="${esc(t.name)}" ${canSession ? '' : 'disabled'} title="${canSession ? `Tell ${esc(agent.name)} to use it, with its conversation and context${agent.running ? '' : ' (resumes the session)'}` : 'Works for Claude Code agents'}">Run in session</button>` : ''}
55
- <button type="button" class="small primary" data-mcp-run="workspace" data-server="${esc(s.name)}" data-tool="${esc(t.name)}" ${r?.running ? 'disabled' : ''} title="A separate one-off Claude Code call in ${agent ? 'the workspace' : 'your home folder'} that may use only this tool; the agent is not interrupted">${r?.running ? 'Running…' : `Run once in ${agent ? 'workspace' : 'home folder'}`}</button>
102
+ ${agent ? `<button type="button" class="small" data-mcp-run="session" data-server="${esc(s.name)}" data-tool="${esc(t.name)}" ${canSession ? '' : 'disabled'} title="${canSession ? `Tell ${esc(agent.name)} to use it, with its conversation and context${agent.running ? '' : ' (resumes the session)'}` : 'Works for Claude Code agents'}">Run in agent session</button>` : ''}
103
+ <button type="button" class="small primary" data-mcp-run="here" data-server="${esc(s.name)}" data-tool="${esc(t.name)}" ${r?.running ? 'disabled' : ''} title="In this folder's MCP session, apart from the agent's: JSON arguments (or none) call the tool directly; plain words go through a one-off Claude Code call that may use only this tool">${r?.running ? 'Running…' : 'Run'}</button>
56
104
  </div>
57
105
  </div>`
58
106
  : '';
59
- const out = r?.error
60
- ? `<p class="error">${esc(r.error)}</p>`
61
- : r?.text
62
- ? `<div class="mcp-result"><p class="hint">Ran ${ago(r.at)} in ${(r.ms / 1000).toFixed(1)} s</p><div class="md">${md(r.text)}</div></div>`
63
- : r?.told
64
- ? `<p class="hint">Sent to ${esc(r.told)}. Its answer is in the session.</p>`
65
- : '';
66
107
  return `<li class="mcp-tool">
67
108
  <div class="mcp-tool-row"><code title="${esc(t.id)}">${esc(t.name)}</code>${t.title ? ` <span class="hint">${esc(t.title)}</span>` : ''} ${tags}
68
109
  <span class="spacer"></span>${s.status === 'connected' ? `<button type="button" class="small ghost" data-mcp-form="${esc(t.id)}">${open ? 'Hide' : 'Run…'}</button>` : ''}</div>
69
- ${form}${out}
110
+ ${form}${resultHtml(r)}
70
111
  </li>`;
71
112
  }
72
113
 
114
+ function signInHtml(s) {
115
+ const si = signIns.get(`${where}:${s.name}`);
116
+ if (!si) return s.status === 'needs-auth' ? '<p class="hint">Sign in to use its tools. Claude Code keeps the sign-in; this app never sees it.</p>' : '';
117
+ if (si.busy) return '<p class="hint">Getting the sign-in page…</p>';
118
+ if (si.error) return `<p class="error">${esc(si.error)}</p>`;
119
+ return `<div class="mcp-signin">
120
+ <p><a href="${esc(si.url)}" target="_blank" rel="noopener">Open the sign-in page ↗</a> <span class="hint">${si.callback ? 'When you finish there, this server connects by itself.' : 'When you have connected it there, press ↻ here.'}</span></p>
121
+ ${si.callback ? `<details data-keep="cb:${esc(s.name)}"><summary class="hint">Signing in on another device, or the page at the end doesn't load?</summary>
122
+ <p class="hint">The sign-in ends on an address on this computer (localhost). Copy that address from the browser and paste it here.</p>
123
+ <div class="mcp-paste"><input type="text" data-mcp-callback="${esc(s.name)}" placeholder="http://localhost:…/callback?code=…" /><button type="button" class="small" data-mcp-callback-send="${esc(s.name)}">Finish sign-in</button></div>
124
+ </details>` : ''}
125
+ </div>`;
126
+ }
127
+
73
128
  function serverHtml(s) {
74
129
  const q = query.toLowerCase();
75
130
  const tools = s.tools.filter((t) => !q || s.name.toLowerCase().includes(q) || t.name.toLowerCase().includes(q) || (t.title ?? '').toLowerCase().includes(q));
76
- if (q && !tools.length) return '';
77
- return `<details class="mcp-server" ${q || s.tools.length <= 12 ? 'open' : ''}>
78
- <summary><b>${esc(s.name)}</b> <span class="tag ${STATUS[s.status] ?? ''}">${esc(s.status)}</span> <span class="tag">${esc(sourceOf(s))}</span>
79
- <span class="hint">${s.tools.length} tool${s.tools.length === 1 ? '' : 's'}</span></summary>
131
+ if (q && !tools.length && !s.name.toLowerCase().includes(q)) return '';
132
+ const busy = reconnecting.has(`${where}:${s.name}`);
133
+ const needs = s.status === 'needs-auth';
134
+ return `<details class="mcp-server" data-keep="srv:${esc(s.name)}" ${q || s.tools.length <= 12 ? 'open' : ''}>
135
+ <summary><b>${esc(s.name)}</b> <span class="tag ${STATUS[s.status] ?? ''}">${esc(STATUS_LABEL[s.status] ?? s.status)}</span> <span class="tag">${esc(sourceOf(s))}</span>
136
+ <span class="hint">${s.tools.length} tool${s.tools.length === 1 ? '' : 's'}</span><span class="spacer"></span>
137
+ ${needs && s.canSignIn ? `<button type="button" class="small primary" data-mcp-signin="${esc(s.name)}" title="Open ${esc(s.name)}'s sign-in page">Sign in</button>` : ''}
138
+ ${s.status === 'disabled' ? '' : `<button type="button" class="small ghost mcp-again" data-mcp-reconnect="${esc(s.name)}" ${busy ? 'disabled' : ''} title="Connect ${esc(s.name)} again and list its tools${needs ? ' (after signing in)' : ''}" aria-label="Refresh ${esc(s.name)}">${busy ? '…' : '↻'}</button>`}</summary>
80
139
  ${s.target ? `<p class="hint mcp-target" title="${esc(s.transport ?? '')}">${esc(s.target)}</p>` : ''}
81
140
  ${s.error ? `<p class="error">${esc(s.error)}</p>` : ''}
82
- ${s.status === 'needs-auth' ? '<p class="hint">Sign in to it from Claude Code (/mcp) to use its tools.</p>' : ''}
141
+ ${signInHtml(s)}
83
142
  ${tools.length ? `<ul class="mcp-tools">${tools.map((t) => toolHtml(s, t)).join('')}</ul>` : s.status === 'connected' ? '<p class="hint">No tools.</p>' : ''}
84
143
  </details>`;
85
144
  }
86
145
 
146
+ function runsHtml() {
147
+ const runs = data.runs ?? [];
148
+ if (!runs.length) return '';
149
+ return `<details class="mcp-runs" data-keep="runs"><summary><b>Runs in this MCP session</b> <span class="hint">${runs.length}, newest first</span></summary>
150
+ <ul class="mcp-tools">${runs.map((r) => `<li class="mcp-tool"><details data-keep="run:${esc(r.at)}"><summary><code>${esc(r.server)}: ${esc(r.name)}</code> ${r.isError ? '<span class="tag fail">error</span>' : ''} <span class="hint">${ago(r.at)} · ${(r.ms / 1000).toFixed(1)} s · ${RAN[r.where] ?? ''}</span></summary>
151
+ ${r.input ? `<p class="hint mcp-target">${esc(r.input)}</p>` : ''}<div class="mcp-result ${r.isError ? 'failed' : ''}"><div class="md">${md(r.text)}</div></div></details></li>`).join('')}</ul>
152
+ </details>`;
153
+ }
154
+
87
155
  function render() {
88
156
  if (!dialog.open) return;
89
- const focus = document.activeElement?.dataset?.mcpInput;
90
- const typed = Object.fromEntries([...body.querySelectorAll('[data-mcp-input]')].map((t) => [t.dataset.mcpInput, t.value]));
157
+ // What was typed, where the cursor is and what was folded all survive a redraw.
158
+ const boxKey = (t) => (t?.dataset?.mcpInput ? `in:${t.dataset.mcpInput}` : t?.dataset?.mcpCallback ? `cb:${t.dataset.mcpCallback}` : null);
159
+ const boxes = () => [...body.querySelectorAll('[data-mcp-input], [data-mcp-callback]')];
160
+ const active = document.activeElement;
161
+ const focus = boxKey(active) && { key: boxKey(active), from: active.selectionStart, to: active.selectionEnd };
162
+ const typed = new Map(boxes().map((t) => [boxKey(t), t.value]));
163
+ const folded = new Map([...body.querySelectorAll('details[data-keep]')].map((d) => [d.dataset.keep, d.open]));
91
164
  const n = data?.servers?.reduce((k, s) => k + s.tools.length, 0) ?? 0;
92
165
  $('#mcp-head').innerHTML = `${picker()}<input id="mcp-filter" type="search" placeholder="Filter servers and tools" value="${esc(query)}" />
93
- <button type="button" class="small" id="mcp-refresh" ${loading ? 'disabled' : ''} title="Ask Claude Code again (it connects to each server)">${loading ? 'Listing…' : 'Refresh'}</button>`;
166
+ <button type="button" class="small" id="mcp-refresh" ${loading ? 'disabled' : ''} title="Start this folder's MCP session again: it reads the configuration again and connects to every server">${loading ? 'Listing…' : 'Refresh all'}</button>
167
+ ${window.name === 'agentmgr-mcp' ? '' : '<button type="button" class="small ghost" id="mcp-window" title="Open this in its own window">↗ Window</button>'}`;
94
168
  body.innerHTML = loading && !data
95
- ? '<p class="hint">Asking Claude Code for its MCP servers here (it connects to each one)…</p>'
169
+ ? '<p class="hint">Starting the MCP session here and asking Claude Code for its servers (it connects to each one)…</p>'
96
170
  : !data
97
171
  ? ''
98
- : `<p class="hint">${data.servers.length} server${data.servers.length === 1 ? '' : 's'}, ${n} tool${n === 1 ? '' : 's'}${data.at ? `, listed ${ago(data.at)}` : ''}${data.dir ? ` in <code>${esc(data.dir)}</code>` : ''}. The same servers Claude Code has there: your own, the project's .mcp.json, claude.ai connectors and plugins.</p>
172
+ : `<p class="hint">${data.servers.length} server${data.servers.length === 1 ? '' : 's'}, ${n} tool${n === 1 ? '' : 's'}${data.at ? `, listed ${ago(data.at)}` : ''}${data.dir ? ` in <code>${esc(data.dir)}</code>` : ''}. The same servers Claude Code has there: your own, the project's .mcp.json, claude.ai connectors and plugins. ${data.session ? `This folder's MCP session has been up since ${ago(data.session.startedAt)}; it is separate from any agent's session.` : ''}</p>
99
173
  ${data.error ? `<p class="error">${esc(data.error)}</p>` : ''}
100
- ${data.servers.map(serverHtml).join('') || (data.error ? '' : '<p class="hint">No MCP servers here. Add one with <code>claude mcp add</code>, or a .mcp.json in the project.</p>')}`;
101
- for (const [id, v] of Object.entries(typed)) {
102
- const box = body.querySelector(`[data-mcp-input="${CSS.escape(id)}"]`);
103
- if (box) box.value = v;
174
+ ${data.servers.map(serverHtml).join('') || (data.error ? '' : '<p class="hint">No MCP servers here. Add one with <code>claude mcp add</code>, or a .mcp.json in the project.</p>')}
175
+ ${runsHtml()}`;
176
+ for (const box of boxes()) {
177
+ const key = boxKey(box);
178
+ if (typed.has(key)) box.value = typed.get(key);
179
+ if (focus?.key === key) {
180
+ box.focus();
181
+ box.setSelectionRange(focus.from, focus.to);
182
+ }
104
183
  }
105
- if (focus) body.querySelector(`[data-mcp-input="${CSS.escape(focus)}"]`)?.focus();
184
+ for (const d of body.querySelectorAll('details[data-keep]')) if (folded.has(d.dataset.keep)) d.open = folded.get(d.dataset.keep);
106
185
  }
107
186
 
108
187
  async function run(btn) {
109
- const how = btn.dataset.mcpRun;
110
188
  const server = btn.dataset.server;
111
189
  const tool = btn.dataset.tool;
112
190
  const t = data.servers.find((s) => s.name === server)?.tools.find((x) => x.name === tool);
@@ -118,7 +196,7 @@ export function initMcp({ api, $, esc, ago, md, toast, agents }) {
118
196
  sure.delete(t.id);
119
197
  const input = body.querySelector(`[data-mcp-input="${CSS.escape(t.id)}"]`)?.value ?? '';
120
198
  const key = `${where}:${t.id}`;
121
- if (how === 'session') {
199
+ if (btn.dataset.mcpRun === 'session') {
122
200
  try {
123
201
  await api('POST', '/mcp/run', { agent: where, server, tool, input, where: 'session' });
124
202
  results.set(key, { told: data.agent.name });
@@ -131,18 +209,82 @@ export function initMcp({ api, $, esc, ago, md, toast, agents }) {
131
209
  results.set(key, { running: true });
132
210
  render();
133
211
  try {
134
- results.set(key, await api('POST', '/mcp/run', { agent: where, server, tool, input, where: 'workspace' }));
212
+ const r = await api('POST', '/mcp/run', { agent: where, server, tool, input, where: directArgs(input) ? 'direct' : 'workspace' });
213
+ results.set(key, r);
214
+ data.runs = [r, ...(data.runs ?? [])].slice(0, 30);
135
215
  } catch (e) {
136
216
  results.set(key, { error: e.message });
137
217
  }
138
218
  render();
139
219
  }
140
220
 
221
+ /** Sign in: the page opens in a new tab at once (so the browser doesn't block it), then goes to the address. */
222
+ async function signIn(name) {
223
+ const key = `${where}:${name}`;
224
+ const tab = window.open('', '_blank');
225
+ signIns.set(key, { busy: true, since: Date.now() });
226
+ render();
227
+ try {
228
+ const r = await api('POST', '/mcp/signin', { agent: where, server: name });
229
+ if (!r.url) {
230
+ tab?.close();
231
+ signIns.delete(key);
232
+ toast(`${name} is already signed in`);
233
+ return load({ quiet: true });
234
+ }
235
+ signIns.set(key, { url: r.url, callback: r.callback, local: r.local, since: Date.now() });
236
+ if (tab) tab.location = r.url;
237
+ watch();
238
+ } catch (e) {
239
+ tab?.close();
240
+ signIns.set(key, { error: e.message, since: Date.now() });
241
+ }
242
+ render();
243
+ }
244
+
245
+ async function reconnect(name) {
246
+ const key = `${where}:${name}`;
247
+ reconnecting.add(key);
248
+ render();
249
+ try {
250
+ data = await api('POST', '/mcp/reconnect', { agent: where, server: name });
251
+ const s = data.servers.find((x) => x.name === name);
252
+ if (s?.status === 'connected') signIns.delete(key);
253
+ toast(`${name}: ${STATUS_LABEL[s?.status] ?? s?.status ?? 'not listed'}${s?.status === 'connected' ? `, ${s.tools.length} tool${s.tools.length === 1 ? '' : 's'}` : ''}`);
254
+ } catch (e) {
255
+ toast(`${name}: ${e.message}`, 6000);
256
+ } finally {
257
+ reconnecting.delete(key);
258
+ }
259
+ render();
260
+ }
261
+
262
+ async function finishSignIn(name) {
263
+ const url = body.querySelector(`[data-mcp-callback="${CSS.escape(name)}"]`)?.value.trim();
264
+ if (!url) return;
265
+ try {
266
+ data = await api('POST', '/mcp/signin/callback', { agent: where, server: name, url });
267
+ if (data.servers.find((x) => x.name === name)?.status === 'connected') {
268
+ signIns.delete(`${where}:${name}`);
269
+ toast(`Signed in to ${name}`);
270
+ }
271
+ } catch (e) {
272
+ toast(e.message, 8000);
273
+ }
274
+ render();
275
+ }
276
+
141
277
  dialog.addEventListener('click', (e) => {
142
278
  const b = e.target.closest('button');
143
279
  if (!b) return;
280
+ // Buttons in a server's heading don't fold it.
281
+ if (b.closest('summary')) e.preventDefault();
144
282
  if (b.id === 'mcp-close') return dialog.close();
145
- if (b.id === 'mcp-refresh') return load(true);
283
+ if (b.id === 'mcp-refresh') return load({ refresh: true });
284
+ if (b.id === 'mcp-window') return void window.open(`/#mcp${where === 'home' ? '' : `/${where}`}`, 'agentmgr-mcp', 'width=1040,height=820');
285
+ if (b.dataset.mcpSignin) return signIn(b.dataset.mcpSignin);
286
+ if (b.dataset.mcpReconnect) return reconnect(b.dataset.mcpReconnect);
287
+ if (b.dataset.mcpCallbackSend) return finishSignIn(b.dataset.mcpCallbackSend);
146
288
  if (b.dataset.mcpForm) {
147
289
  if (forms.has(b.dataset.mcpForm)) forms.delete(b.dataset.mcpForm);
148
290
  else forms.add(b.dataset.mcpForm);
@@ -177,7 +319,7 @@ export function initMcp({ api, $, esc, ago, md, toast, agents }) {
177
319
  data = null;
178
320
  forms.clear();
179
321
  }
180
- dialog.showModal();
322
+ if (!dialog.open) dialog.showModal();
181
323
  render();
182
324
  load();
183
325
  },
package/public/style.css CHANGED
@@ -512,6 +512,19 @@ dialog::backdrop { background: rgba(0, 0, 0, .45); }
512
512
  .dialog-actions { display: flex; justify-content: flex-end; gap: 8px; }
513
513
  .error { color: var(--red); margin: 0; font-size: 13px; }
514
514
 
515
+ .update-dialog { width: min(520px, calc(100vw - 32px)); padding: 20px; }
516
+ .update-dialog h2 { margin: 0 0 8px; font-size: 17px; }
517
+ .update-dialog p { margin: 6px 0; font-size: 13px; }
518
+ .update-steps { list-style: none; margin: 10px 0; padding: 0; display: grid; gap: 8px; }
519
+ .update-steps li { display: grid; grid-template-columns: 22px 1fr; gap: 4px 6px; align-items: baseline; color: var(--muted); }
520
+ .update-steps li.now { color: var(--text); font-weight: 600; }
521
+ .update-steps li.done { color: var(--text); }
522
+ .update-steps li .hint { grid-column: 2; font-weight: 400; word-break: break-word; }
523
+ .update-bar { height: 4px; border-radius: 2px; background: var(--border); overflow: hidden; margin: 4px 0 10px; }
524
+ .update-bar span { display: block; height: 100%; width: 35%; background: var(--accent); border-radius: 2px; animation: update-slide 1.4s ease-in-out infinite; }
525
+ @keyframes update-slide { 0% { margin-left: -35%; } 100% { margin-left: 100%; } }
526
+ @media (prefers-reduced-motion: reduce) { .update-bar span { animation: none; width: 100%; opacity: 0.5; } }
527
+
515
528
  .toast button { margin-left: 8px; }
516
529
  .toast {
517
530
  position: fixed; bottom: 16px; left: 50%; transform: translateX(-50%); background: var(--text); color: var(--bg);
@@ -746,6 +759,14 @@ pre.diff .meta { color: var(--muted); font-weight: 600; }
746
759
  .mcp-form textarea { width: 100%; box-sizing: border-box; }
747
760
  .mcp-actions { display: flex; gap: 6px; justify-content: flex-end; flex-wrap: wrap; }
748
761
  .mcp-result { border-left: 3px solid var(--border); padding-left: 10px; margin: 6px 0; max-height: 320px; overflow: auto; }
762
+ .mcp-server summary .spacer { flex: 1; }
763
+ .mcp-again { min-width: 28px; font-size: 15px; line-height: 1; }
764
+ .mcp-signin p { margin: 6px 0; }
765
+ .mcp-paste { display: flex; gap: 6px; margin: 6px 0; }
766
+ .mcp-paste input { flex: 1; min-width: 0; }
767
+ .mcp-result.failed { border-left-color: var(--red); }
768
+ .mcp-runs { margin: 14px 0 0; padding: 6px 10px; border: 1px dashed var(--border); border-radius: 6px; }
769
+ .mcp-runs summary { cursor: pointer; }
749
770
  .tag.mcp-ok { color: var(--green); }
750
771
  .tag.mcp-wait { color: var(--yellow); }
751
772
  .rv-summary { display: flex; flex-wrap: wrap; gap: 6px 14px; align-items: center; font-size: 13px; }