turno-cli 0.2.0 → 0.3.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 +148 -0
- package/README.md +127 -39
- package/dist/accounts/audit.js +27 -15
- package/dist/accounts/builtin.js +35 -7
- package/dist/accounts/delegate.js +30 -7
- package/dist/accounts/policy.js +4 -2
- package/dist/accounts/registry.js +3 -1
- package/dist/agents/adapter.js +22 -0
- package/dist/agents/claude.js +54 -3
- package/dist/agents/codex.js +94 -6
- package/dist/agents/copilot.js +19 -2
- package/dist/agents/cursor.js +19 -2
- package/dist/agents/index.js +1 -1
- package/dist/agents/snippets.js +37 -10
- package/dist/cli/args.js +32 -15
- package/dist/cli/commands/accounts.js +29 -7
- package/dist/cli/commands/auto.js +50 -12
- package/dist/cli/commands/browser-identity.js +514 -0
- package/dist/cli/commands/browser-session.js +102 -0
- package/dist/cli/commands/browser-vault.js +193 -0
- package/dist/cli/commands/browser.js +159 -59
- package/dist/cli/commands/complete.js +13 -3
- package/dist/cli/commands/completion.js +4 -0
- package/dist/cli/commands/config.js +90 -13
- package/dist/cli/commands/demo.js +36 -7
- package/dist/cli/commands/doctor.js +170 -36
- package/dist/cli/commands/identity.js +99 -12
- package/dist/cli/commands/init.js +42 -10
- package/dist/cli/commands/limit.js +65 -9
- package/dist/cli/commands/mcp-call.js +240 -0
- package/dist/cli/commands/mcp-oauth.js +33 -6
- package/dist/cli/commands/mcp-observe.js +128 -23
- package/dist/cli/commands/mcp-share.js +201 -0
- package/dist/cli/commands/mcp.js +203 -42
- package/dist/cli/commands/mcpd.js +76 -12
- package/dist/cli/commands/open.js +26 -3
- package/dist/cli/commands/profile.js +212 -30
- package/dist/cli/commands/resolve.js +8 -1
- package/dist/cli/commands/run.js +24 -4
- package/dist/cli/commands/secret.js +23 -38
- package/dist/cli/commands/session.js +16 -5
- package/dist/cli/commands/sessions.js +7 -1
- package/dist/cli/commands/setup.js +83 -11
- package/dist/cli/commands/status.js +67 -15
- package/dist/cli/commands/statusline.js +7 -2
- package/dist/cli/commands/ui.js +17 -5
- package/dist/cli/commands/undo.js +39 -7
- package/dist/cli/commands/uninstall.js +24 -5
- package/dist/cli/commands/upgrade.js +113 -76
- package/dist/cli/commands/usage.js +11 -10
- package/dist/cli/commands/version.js +20 -8
- package/dist/cli/commands/which.js +5 -3
- package/dist/cli/diagnostics.js +184 -0
- package/dist/cli/exit.js +65 -0
- package/dist/cli/group.js +20 -8
- package/dist/cli/help.js +6 -1
- package/dist/cli/hints.js +30 -0
- package/dist/cli/io.js +24 -8
- package/dist/cli/launch.js +31 -2
- package/dist/cli/launchers.js +25 -10
- package/dist/cli/main.js +52 -18
- package/dist/cli/optional.js +144 -0
- package/dist/cli/output.js +123 -0
- package/dist/cli/picker.js +17 -5
- package/dist/cli/registry.js +20 -2
- package/dist/cli/safe.js +87 -0
- package/dist/cli/secret-input.js +63 -0
- package/dist/cli/security.js +31 -9
- package/dist/cli/style.js +35 -5
- package/dist/cli/topics.js +142 -0
- package/dist/core/config.js +39 -3
- package/dist/core/fsutil.js +2 -10
- package/dist/core/journal.js +19 -11
- package/dist/core/manifest.js +28 -1
- package/dist/core/paths.js +6 -112
- package/dist/core/profiles.js +28 -8
- package/dist/core/resolve.js +13 -3
- package/dist/core/secrets.js +4 -154
- package/dist/core/state-file.js +107 -0
- package/dist/core/update.js +14 -11
- package/dist/core/version.js +57 -10
- package/dist/demo/server.js +10 -2
- package/dist/mcpd/cache.js +6 -7
- package/dist/mcpd/calllog.js +10 -9
- package/dist/mcpd/client-names.js +8 -13
- package/dist/mcpd/connectors.js +42 -3
- package/dist/mcpd/daemon.js +29 -8
- package/dist/mcpd/folder-sets.js +5 -2
- package/dist/mcpd/gateway.js +57 -29
- package/dist/mcpd/health.js +69 -25
- package/dist/mcpd/importer.js +106 -9
- package/dist/mcpd/instances.js +59 -31
- package/dist/mcpd/jsonrpc.js +3 -1
- package/dist/mcpd/middleware.js +144 -0
- package/dist/mcpd/modern.js +57 -19
- package/dist/mcpd/oauth.js +71 -17
- package/dist/mcpd/peerpid.js +15 -3
- package/dist/mcpd/pressure.js +4 -1
- package/dist/mcpd/rss.js +34 -19
- package/dist/mcpd/service.js +28 -4
- package/dist/mcpd/share.js +217 -0
- package/dist/mcpd/state.js +16 -16
- package/dist/mcpd/sync.js +22 -12
- package/dist/mcpd/systemd.js +4 -1
- package/dist/mcpd/tokens.js +4 -8
- package/dist/mcpd/upstream.js +12 -5
- package/dist/statusline/cost.js +17 -4
- package/dist/statusline/input.js +15 -3
- package/dist/ui/fonts.js +1 -1
- package/dist/ui/settings.js +6 -1
- package/npm-shrinkwrap.json +12 -3
- package/package.json +7 -6
package/dist/cli/commands/mcp.js
CHANGED
|
@@ -10,13 +10,16 @@ import { loadManifest, parseManifest, servesProfile } from "../../core/manifest.
|
|
|
10
10
|
import { PRIVATE_DIR_MODE, PRIVATE_FILE_MODE, ensurePrivateDir, paths, tildify } from "../../core/paths.js";
|
|
11
11
|
import { agentOf, listProfiles } from "../../core/profiles.js";
|
|
12
12
|
import { liveSessions } from "../../core/sessions.js";
|
|
13
|
-
import { DRY_RUN, FORCE, JSON_FLAG, bool, parseFlags,
|
|
13
|
+
import { DRY_RUN, FORCE, JSON_FLAG, bool, parseFlags, str } from "../args.js";
|
|
14
14
|
import { group } from "../group.js";
|
|
15
15
|
import { highlightJson, highlightToml } from "../highlight.js";
|
|
16
16
|
import { colors, fail, paint, plural } from "../io.js";
|
|
17
17
|
import { duration, profileColor, style } from "../style.js";
|
|
18
|
-
import {
|
|
19
|
-
import {
|
|
18
|
+
import { emit, jsonOutput } from "../output.js";
|
|
19
|
+
import { LOG_FLAGS, LOG_JSON, SAVINGS_FLAGS, SAVINGS_JSON, TOP_FLAGS, TOP_JSON } from "./mcp-observe.js";
|
|
20
|
+
import { LOGIN_FLAGS, LOGIN_JSON, LOGOUT_FLAGS, describeLogin, oauthLogins } from "./mcp-oauth.js";
|
|
21
|
+
import { CALL_FLAGS, CALL_JSON } from "./mcp-call.js";
|
|
22
|
+
import { EXPORT_FLAGS, EXPORT_JSON, IMPORT_FLAGS as IMPORT_FILE_FLAGS } from "./mcp-share.js";
|
|
20
23
|
const run = promisify(execFile);
|
|
21
24
|
const flagsOf = (spec) => Object.keys(spec).map((k) => `--${k}`);
|
|
22
25
|
/**
|
|
@@ -54,11 +57,35 @@ async function mcpdAnswers(env) {
|
|
|
54
57
|
}
|
|
55
58
|
// list ---------------------------------------------------------------------------------------
|
|
56
59
|
const LIST_FLAGS = { ...JSON_FLAG };
|
|
57
|
-
/**
|
|
60
|
+
/** `turno mcp list --json`: one element per server; remote and stdio servers fill different fields. */
|
|
61
|
+
const LIST_JSON = jsonOutput([
|
|
62
|
+
"name",
|
|
63
|
+
"kind",
|
|
64
|
+
"url",
|
|
65
|
+
"proxy",
|
|
66
|
+
"auth",
|
|
67
|
+
"logins",
|
|
68
|
+
"command",
|
|
69
|
+
"scope",
|
|
70
|
+
"exclusive",
|
|
71
|
+
"idleSeconds",
|
|
72
|
+
"profiles",
|
|
73
|
+
"package",
|
|
74
|
+
"variants",
|
|
75
|
+
"tools",
|
|
76
|
+
"variantTools",
|
|
77
|
+
]);
|
|
78
|
+
/** `turno mcp config --json`. */
|
|
79
|
+
const CONFIG_JSON = jsonOutput(["agent", "profile", "servers", "file", "notes", "text"]);
|
|
80
|
+
/** `turno mcp doctor --json`. */
|
|
81
|
+
const DOCTOR_JSON = jsonOutput(["ok", "plugins", "direct", "logins"]);
|
|
82
|
+
/** "allow get_*, list_*, deny *_delete": a tool filter as text, or "" when it filters nothing. */
|
|
58
83
|
function filterText(f) {
|
|
59
84
|
if (!f)
|
|
60
85
|
return "";
|
|
61
|
-
return [f.allow ? `allow ${f.allow.join(", ")}` : "", f.deny ? `deny ${f.deny.join(", ")}` : ""]
|
|
86
|
+
return [f.allow ? `allow ${f.allow.join(", ")}` : "", f.deny ? `deny ${f.deny.join(", ")}` : ""]
|
|
87
|
+
.filter(Boolean)
|
|
88
|
+
.join(", ");
|
|
62
89
|
}
|
|
63
90
|
async function list(args, io) {
|
|
64
91
|
const flags = parseFlags(args, LIST_FLAGS, 0);
|
|
@@ -67,7 +94,7 @@ async function list(args, io) {
|
|
|
67
94
|
const logins = await oauthLogins(io.env);
|
|
68
95
|
const loginsOf = (name) => logins.filter((l) => l.server === name);
|
|
69
96
|
if (bool(flags, "json")) {
|
|
70
|
-
|
|
97
|
+
emit(io, flags, LIST_JSON, names.map((n) => {
|
|
71
98
|
const s = m.servers[n];
|
|
72
99
|
const tools = s.tools ?? null;
|
|
73
100
|
return s.kind === "remote"
|
|
@@ -78,7 +105,9 @@ async function list(args, io) {
|
|
|
78
105
|
proxy: Boolean(s.proxy),
|
|
79
106
|
profiles: s.profiles,
|
|
80
107
|
tools,
|
|
81
|
-
...(s.oauth
|
|
108
|
+
...(s.oauth
|
|
109
|
+
? { auth: "oauth", logins: Object.fromEntries(loginsOf(n).map((l) => [l.variant, l.state])) }
|
|
110
|
+
: {}),
|
|
82
111
|
}
|
|
83
112
|
: {
|
|
84
113
|
name: n,
|
|
@@ -122,15 +151,21 @@ async function list(args, io) {
|
|
|
122
151
|
const good = rows.every((l) => l.state === "logged in" || l.state === "expired");
|
|
123
152
|
return good ? st.lead("ok", "oauth") : st.lead("warn", st.warn("oauth"));
|
|
124
153
|
}
|
|
125
|
-
const refs = Object.values(s.kind === "remote"
|
|
154
|
+
const refs = Object.values(s.kind === "remote"
|
|
155
|
+
? s.headers
|
|
156
|
+
: { ...s.env, ...Object.assign({}, ...Object.values(s.variants).map((v) => v.env)) });
|
|
126
157
|
return refs.some((v) => typeof v === "string" && /^(keychain|env):/.test(v)) ? "secret" : st.muted("-");
|
|
127
158
|
};
|
|
128
159
|
// Column titles: muted lowercase on a terminal, as in turno status; uppercase in plain text.
|
|
129
|
-
const rows = [
|
|
160
|
+
const rows = [
|
|
161
|
+
["SERVER", "KIND", "SCOPE", "IDLE", "PROFILES", "STATE", "AUTH", "DETAILS"].map((h) => st.muted(st.color ? h.toLowerCase() : h)),
|
|
162
|
+
];
|
|
130
163
|
const sep = st.muted("; ");
|
|
131
164
|
for (const name of names) {
|
|
132
165
|
const s = m.servers[name];
|
|
133
|
-
const where = s.profiles.includes("*")
|
|
166
|
+
const where = s.profiles.includes("*")
|
|
167
|
+
? "all"
|
|
168
|
+
: s.profiles.map((p) => st.profile(p, profileColor(profileColors, p))).join(st.color ? " " : ", ");
|
|
134
169
|
const tools = filterText(s.tools) ? `tools: ${filterText(s.tools)}` : "";
|
|
135
170
|
if (s.kind === "remote") {
|
|
136
171
|
const logins = loginsOf(name).map((l) => {
|
|
@@ -138,7 +173,16 @@ async function list(args, io) {
|
|
|
138
173
|
return l.state === "logged in" || l.state === "expired" ? text : st.warn(text);
|
|
139
174
|
});
|
|
140
175
|
const details = [st.accent(s.url), tools, ...logins].filter(Boolean).join(sep);
|
|
141
|
-
rows.push([
|
|
176
|
+
rows.push([
|
|
177
|
+
st.bold(name),
|
|
178
|
+
"remote",
|
|
179
|
+
s.proxy ? "via mcpd" : "direct",
|
|
180
|
+
s.proxy ? `${Math.round(s.idle / 60)}m` : st.muted("-"),
|
|
181
|
+
where,
|
|
182
|
+
state(s),
|
|
183
|
+
auth(s),
|
|
184
|
+
details,
|
|
185
|
+
]);
|
|
142
186
|
continue;
|
|
143
187
|
}
|
|
144
188
|
const variants = Object.keys(s.variants);
|
|
@@ -152,7 +196,16 @@ async function list(args, io) {
|
|
|
152
196
|
]
|
|
153
197
|
.filter(Boolean)
|
|
154
198
|
.join(sep);
|
|
155
|
-
rows.push([
|
|
199
|
+
rows.push([
|
|
200
|
+
st.bold(name),
|
|
201
|
+
s.builtin ? "builtin" : "stdio",
|
|
202
|
+
`${s.scope}${s.exclusive ? ", exclusive" : ""}`,
|
|
203
|
+
`${Math.round(s.idle / 60)}m`,
|
|
204
|
+
where,
|
|
205
|
+
state(s),
|
|
206
|
+
auth(s),
|
|
207
|
+
details,
|
|
208
|
+
]);
|
|
156
209
|
}
|
|
157
210
|
io.out(st.header("MCP servers"));
|
|
158
211
|
// A narrow terminal drops idle times, then auth and scope; the details wrap under their column.
|
|
@@ -170,6 +223,11 @@ async function runningServers(env) {
|
|
|
170
223
|
const instances = r.body.instances;
|
|
171
224
|
return new Set((Array.isArray(instances) ? instances : []).flatMap((i) => (typeof i?.server === "string" ? [i.server] : [])));
|
|
172
225
|
}
|
|
226
|
+
// sync ---------------------------------------------------------------------------------------
|
|
227
|
+
/** The profile the hub config (plain claude) gets gateway entries for: `system`, else "default". */
|
|
228
|
+
export function hubProfileOf(config) {
|
|
229
|
+
return config.system || "default";
|
|
230
|
+
}
|
|
173
231
|
function targets(io, config, only) {
|
|
174
232
|
const out = [];
|
|
175
233
|
const sharedDone = new Set();
|
|
@@ -187,8 +245,9 @@ function targets(io, config, only) {
|
|
|
187
245
|
}
|
|
188
246
|
out.push({ profile: name, file: mcpFileFor(name, agent, io.env), agent });
|
|
189
247
|
}
|
|
190
|
-
// The hub config belongs to the system profile (the default agent started without a launcher)
|
|
191
|
-
|
|
248
|
+
// The hub config belongs to the system profile (the default agent started without a launcher);
|
|
249
|
+
// without one (unset, or system = "") its entries carry the token of the "default" name.
|
|
250
|
+
const hubProfile = hubProfileOf(config);
|
|
192
251
|
const hubFile = adapter(DEFAULT_AGENT).mcp.hubFile(io.env);
|
|
193
252
|
if ((!only.length || only.includes(hubProfile) || only.includes("hub")) && existsSync(hubFile)) {
|
|
194
253
|
out.push({ profile: hubProfile, file: hubFile, agent: DEFAULT_AGENT, plain: true });
|
|
@@ -209,7 +268,12 @@ function busyState(env, config) {
|
|
|
209
268
|
const SYNC_FLAGS = { ...DRY_RUN, ...FORCE };
|
|
210
269
|
async function sync(args, io) {
|
|
211
270
|
const flags = parseFlags(args, SYNC_FLAGS);
|
|
212
|
-
const r = await syncProfiles(io, {
|
|
271
|
+
const r = await syncProfiles(io, {
|
|
272
|
+
dryRun: bool(flags, "dry-run"),
|
|
273
|
+
force: bool(flags, "force"),
|
|
274
|
+
only: flags.positionals,
|
|
275
|
+
command: `mcp sync ${args.join(" ")}`.trim(),
|
|
276
|
+
});
|
|
213
277
|
return r.skipped ? 1 : 0;
|
|
214
278
|
}
|
|
215
279
|
/** Point every profile's agent config at the gateway. `changed` counts the files that change (or would). */
|
|
@@ -218,7 +282,7 @@ export async function syncProfiles(io, opts = {}) {
|
|
|
218
282
|
const force = Boolean(opts.force);
|
|
219
283
|
const only = opts.only ?? [];
|
|
220
284
|
const config = loadConfig(io.env);
|
|
221
|
-
const known = new Set([...listProfiles(config, io.env), config
|
|
285
|
+
const known = new Set([...listProfiles(config, io.env), hubProfileOf(config), "hub"]);
|
|
222
286
|
for (const name of only)
|
|
223
287
|
if (!known.has(name))
|
|
224
288
|
fail(`no profile '${name}' (turno profile list shows them)`);
|
|
@@ -226,7 +290,7 @@ export async function syncProfiles(io, opts = {}) {
|
|
|
226
290
|
const { ensureToken, mcpdPort, readToken } = await import("../../mcpd/state.js");
|
|
227
291
|
const manifest = loadManifest(io.env);
|
|
228
292
|
// A dry run never creates the token; without one, entries show a placeholder. Entries get
|
|
229
|
-
// each profile's own token derived from this master token
|
|
293
|
+
// each profile's own token derived from this master token, never the master.
|
|
230
294
|
const token = dryRun ? (readToken(io.env) ?? "<token>") : ensureToken(io.env);
|
|
231
295
|
const port = mcpdPort(io.env);
|
|
232
296
|
const p = paths(io.env);
|
|
@@ -249,9 +313,16 @@ export async function syncProfiles(io, opts = {}) {
|
|
|
249
313
|
: t.profile
|
|
250
314
|
? st.profile(t.profile, profileColor(config.profiles, t.profile))
|
|
251
315
|
: st.bold(`${a.label} profiles`);
|
|
252
|
-
const isBusy = t.plain
|
|
316
|
+
const isBusy = t.plain
|
|
317
|
+
? busy.plain || busy.profiles.has(t.profile)
|
|
318
|
+
: Boolean(t.profile) && busy.profiles.has(t.profile);
|
|
253
319
|
if (isBusy && !force) {
|
|
254
|
-
rows.push([
|
|
320
|
+
rows.push([
|
|
321
|
+
st.icon("warn"),
|
|
322
|
+
label,
|
|
323
|
+
st.muted(where),
|
|
324
|
+
st.warn(`${dryRun ? "would skip" : "skipped"}: has open sessions; close them or use --force`),
|
|
325
|
+
]);
|
|
255
326
|
skipped++;
|
|
256
327
|
continue;
|
|
257
328
|
}
|
|
@@ -271,8 +342,12 @@ export async function syncProfiles(io, opts = {}) {
|
|
|
271
342
|
changed++;
|
|
272
343
|
if (!dryRun)
|
|
273
344
|
managed[t.file] = Object.keys(wanted);
|
|
274
|
-
const verbs = dryRun
|
|
275
|
-
|
|
345
|
+
const verbs = dryRun
|
|
346
|
+
? ["would add", "would update", "would remove", "would leave alone"]
|
|
347
|
+
: ["added", "updated", "removed", "left alone"];
|
|
348
|
+
const parts = [res.added, res.updated, res.removed, res.foreign]
|
|
349
|
+
.map((names, i) => (names.length ? `${verbs[i]} ${names.join(", ")}` : ""))
|
|
350
|
+
.filter(Boolean);
|
|
276
351
|
const detail = parts.length ? parts.join("; ") : res.changed ? "" : st.muted("no changes");
|
|
277
352
|
rows.push([st.icon(!res.changed ? "skip" : dryRun ? "info" : "ok"), label, st.muted(where), detail]);
|
|
278
353
|
const after = res.added.length && !dryRun ? a.mcp.afterSync?.(res.added) : undefined;
|
|
@@ -300,7 +375,7 @@ export async function syncProfiles(io, opts = {}) {
|
|
|
300
375
|
}
|
|
301
376
|
/**
|
|
302
377
|
* Agents that read the gateway token from the environment (Codex, Copilot, Cursor) get it from
|
|
303
|
-
* a private file per profile that their launcher reads
|
|
378
|
+
* a private file per profile that their launcher reads. Written even for profiles
|
|
304
379
|
* with open sessions: those already hold their token, and the next launch needs the new one.
|
|
305
380
|
*/
|
|
306
381
|
async function syncTokenFiles(io, config, only, master, dryRun) {
|
|
@@ -319,7 +394,9 @@ async function syncTokenFiles(io, config, only, master, dryRun) {
|
|
|
319
394
|
if (!adapter(agent).tokenFromEnv)
|
|
320
395
|
continue;
|
|
321
396
|
synced.add(name);
|
|
322
|
-
if (dryRun
|
|
397
|
+
if (dryRun
|
|
398
|
+
? readProfileTokenFile(name, io.env) !== profileToken(master, name)
|
|
399
|
+
: writeProfileTokenFile(name, master, io.env))
|
|
323
400
|
changed.push(name);
|
|
324
401
|
const launcher = join(paths(io.env).bin, launcherName(name, agent));
|
|
325
402
|
if (isGenerated(launcher) && !readFileSync(launcher, "utf8").includes("mcpd-tokens/"))
|
|
@@ -329,7 +406,7 @@ async function syncTokenFiles(io, config, only, master, dryRun) {
|
|
|
329
406
|
if (changed.length)
|
|
330
407
|
io.out(st.note(dryRun ? "info" : "ok", `${dryRun ? "would write" : "wrote"} the gateway token of ${changed.join(", ")} for their launchers`));
|
|
331
408
|
// A full sync removes the token files it wrote for profiles that are gone. The token itself
|
|
332
|
-
// stays valid until a rotation
|
|
409
|
+
// stays valid until a rotation; the file is just no longer needed.
|
|
333
410
|
const gone = only.length ? [] : [...synced].filter((n) => !profiles.includes(n)).sort();
|
|
334
411
|
for (const name of gone) {
|
|
335
412
|
synced.delete(name);
|
|
@@ -366,7 +443,7 @@ async function config(args, io) {
|
|
|
366
443
|
writeProfileTokenFile(profile, ensureToken(io.env), io.env);
|
|
367
444
|
const s = gatewaySnippet(agent, servers, mcpdPort(io.env), profile, tildify(profileTokenFile(profile, io.env), io.env));
|
|
368
445
|
if (bool(p, "json")) {
|
|
369
|
-
|
|
446
|
+
emit(io, p, CONFIG_JSON, { agent, profile, servers, file: s.file, notes: s.notes, text: s.text });
|
|
370
447
|
return 0;
|
|
371
448
|
}
|
|
372
449
|
io.out(paint(io, `# ${s.file}`, "2"));
|
|
@@ -401,8 +478,16 @@ export async function binOf(io, pkg) {
|
|
|
401
478
|
return undefined;
|
|
402
479
|
}
|
|
403
480
|
}
|
|
404
|
-
const IMPORT_FLAGS = {
|
|
481
|
+
const IMPORT_FLAGS = {
|
|
482
|
+
write: { type: "boolean" },
|
|
483
|
+
"move-secrets": { type: "boolean" },
|
|
484
|
+
...FORCE,
|
|
485
|
+
...DRY_RUN,
|
|
486
|
+
};
|
|
405
487
|
async function importCmd(args, io) {
|
|
488
|
+
const file = parseFlags(args, IMPORT_FILE_FLAGS, 1).positionals[0];
|
|
489
|
+
if (file !== undefined)
|
|
490
|
+
return (await import("./mcp-share.js")).importFile(file, args, io);
|
|
406
491
|
const flags = parseFlags(args, IMPORT_FLAGS, 0);
|
|
407
492
|
const write = bool(flags, "write");
|
|
408
493
|
const moveSecrets = bool(flags, "move-secrets");
|
|
@@ -436,7 +521,13 @@ async function importCmd(args, io) {
|
|
|
436
521
|
for (const s of report.secrets)
|
|
437
522
|
io.err(` would move ${s.where} to keychain:${s.service}`);
|
|
438
523
|
io.out(colors(io) ? highlightToml(report.preview.trimEnd()) : report.preview.trimEnd());
|
|
439
|
-
const again = [
|
|
524
|
+
const again = [
|
|
525
|
+
"turno mcp import --write",
|
|
526
|
+
moveSecrets || report.literalSecrets.length ? "--move-secrets" : "",
|
|
527
|
+
exists ? "--force" : "",
|
|
528
|
+
]
|
|
529
|
+
.filter(Boolean)
|
|
530
|
+
.join(" ");
|
|
440
531
|
io.err(`Nothing written. Write it with: ${again}`);
|
|
441
532
|
return 0;
|
|
442
533
|
}
|
|
@@ -544,7 +635,9 @@ async function install(args, io) {
|
|
|
544
635
|
const lock = join(dir, "package-lock.json");
|
|
545
636
|
let deps = {};
|
|
546
637
|
try {
|
|
547
|
-
deps =
|
|
638
|
+
deps =
|
|
639
|
+
JSON.parse(readFileSync(join(dir, "package.json"), "utf8"))
|
|
640
|
+
.dependencies ?? {};
|
|
548
641
|
}
|
|
549
642
|
catch {
|
|
550
643
|
/* first install */
|
|
@@ -565,12 +658,16 @@ async function install(args, io) {
|
|
|
565
658
|
if (!existsSync(join(dir, "package.json")))
|
|
566
659
|
writeFileSync(join(dir, "package.json"), `{ "private": true }\n`, { mode: PRIVATE_FILE_MODE });
|
|
567
660
|
const common = ["--no-audit", "--no-fund", "--prefix", dir, ...(allowScripts ? [] : ["--ignore-scripts"])];
|
|
568
|
-
const npmArgs = fromLock
|
|
661
|
+
const npmArgs = fromLock
|
|
662
|
+
? ["ci", ...common]
|
|
663
|
+
: ["install", "--save-exact", "--package-lock=true", ...common, pinned];
|
|
569
664
|
io.out(`installing ${pinned} for ${s.name}${fromLock ? " from its lockfile" : ""}...`);
|
|
570
665
|
try {
|
|
571
666
|
await npm(io, npmArgs, 300_000);
|
|
572
667
|
const bin = join(dir, "node_modules", ".bin", s.command);
|
|
573
|
-
io.out(existsSync(bin)
|
|
668
|
+
io.out(existsSync(bin)
|
|
669
|
+
? ` ok: ${tildify(bin, io.env)}`
|
|
670
|
+
: ` ${paint(io, "warning", "33")}: installed but no bin named ${s.command}`);
|
|
574
671
|
}
|
|
575
672
|
catch (err) {
|
|
576
673
|
failed++;
|
|
@@ -618,7 +715,9 @@ async function refreshInDaemon(env, server) {
|
|
|
618
715
|
}
|
|
619
716
|
if (r.status === 404)
|
|
620
717
|
return "unsupported";
|
|
621
|
-
const msg = typeof r.body === "object" && r.body && "error" in r.body
|
|
718
|
+
const msg = typeof r.body === "object" && r.body && "error" in r.body
|
|
719
|
+
? String(r.body.error)
|
|
720
|
+
: `HTTP ${r.status}`;
|
|
622
721
|
return msg;
|
|
623
722
|
}
|
|
624
723
|
async function refresh(args, io) {
|
|
@@ -700,11 +799,11 @@ async function doctor(args, io) {
|
|
|
700
799
|
const missing = logins.filter((l) => l.state === "not logged in" || l.state === "login required");
|
|
701
800
|
const code = plugins.length + direct.length + missing.length ? 1 : 0;
|
|
702
801
|
if (bool(flags, "json")) {
|
|
703
|
-
|
|
802
|
+
emit(io, flags, DOCTOR_JSON, { ok: code === 0, ...found, ...(logins.length ? { logins: missing } : {}) });
|
|
704
803
|
return code;
|
|
705
804
|
}
|
|
706
805
|
if (missing.length) {
|
|
707
|
-
io.out(paint(io, "Remote OAuth servers that need a login
|
|
806
|
+
io.out(paint(io, "Remote OAuth servers that need a login:", "1"));
|
|
708
807
|
for (const l of missing)
|
|
709
808
|
io.out(` ${l.server}${l.variant === "default" ? "" : `@${l.variant}`}: ${describeLogin(l)}`);
|
|
710
809
|
}
|
|
@@ -726,7 +825,13 @@ async function doctor(args, io) {
|
|
|
726
825
|
}
|
|
727
826
|
// command ------------------------------------------------------------------------------------
|
|
728
827
|
const SUBS = {
|
|
729
|
-
list: {
|
|
828
|
+
list: {
|
|
829
|
+
synopsis: "[--json]",
|
|
830
|
+
summary: "servers in mcp.toml and where they run",
|
|
831
|
+
flags: flagsOf(LIST_FLAGS),
|
|
832
|
+
json: LIST_JSON,
|
|
833
|
+
run: list,
|
|
834
|
+
},
|
|
730
835
|
sync: {
|
|
731
836
|
synopsis: "[profile...] [--dry-run] [--force]",
|
|
732
837
|
summary: "write gateway entries into every profile config",
|
|
@@ -738,14 +843,24 @@ const SUBS = {
|
|
|
738
843
|
synopsis: "--agent <a> [--profile <p>] [--json]",
|
|
739
844
|
summary: "print gateway entries for other agents",
|
|
740
845
|
flags: flagsOf(CONFIG_FLAGS),
|
|
846
|
+
json: CONFIG_JSON,
|
|
741
847
|
run: config,
|
|
742
848
|
},
|
|
743
849
|
import: {
|
|
744
|
-
synopsis: "[--write] [--move-secrets] [--force]",
|
|
745
|
-
summary: "draft mcp.toml from your agent configs",
|
|
850
|
+
synopsis: "[file] [--write] [--move-secrets] [--force]",
|
|
851
|
+
summary: "draft mcp.toml from your agent configs, or merge a file",
|
|
746
852
|
flags: flagsOf(IMPORT_FLAGS),
|
|
853
|
+
details: 'Without a file it drafts mcp.toml from every agent config on this machine (a\npreview until --write; --force replaces an existing mcp.toml). With a file it\nmerges that file\'s servers into mcp.toml: an export (turno mcp export), a JSON\nfile with mcpServers, or a Codex config.toml. Servers already in mcp.toml are\nkept unless --force replaces them. With --write, remote servers that answer\nwith an OAuth challenge get auth = "oauth".',
|
|
747
854
|
run: importCmd,
|
|
748
855
|
},
|
|
856
|
+
export: {
|
|
857
|
+
synopsis: "[--profile <p>] [--json]",
|
|
858
|
+
summary: "print mcp.toml without secret values, for another machine",
|
|
859
|
+
flags: flagsOf(EXPORT_FLAGS),
|
|
860
|
+
json: EXPORT_JSON,
|
|
861
|
+
details: "Prints mcp.toml with each secret named, never its value: keychain: and env:\nreferences stay, literal secrets become keychain:turno/<server>/<key>\nreferences, and the top of the file lists the turno secret set commands the\nother machine needs. A secret inside args or a URL is replaced by <secret>.\n--profile keeps only the servers that profile gets, and only its own variant.",
|
|
862
|
+
run: async (rest, io) => (await import("./mcp-share.js")).exportCmd(rest, io),
|
|
863
|
+
},
|
|
749
864
|
install: {
|
|
750
865
|
synopsis: "[server...] [--dry-run] [--allow-scripts]",
|
|
751
866
|
summary: "install packages at exact versions",
|
|
@@ -753,13 +868,26 @@ const SUBS = {
|
|
|
753
868
|
flags: flagsOf(INSTALL_FLAGS),
|
|
754
869
|
run: install,
|
|
755
870
|
},
|
|
756
|
-
refresh: {
|
|
757
|
-
|
|
871
|
+
refresh: {
|
|
872
|
+
synopsis: "[server...] [--dry-run]",
|
|
873
|
+
summary: "make mcpd relearn tool lists",
|
|
874
|
+
args: ["server"],
|
|
875
|
+
flags: flagsOf(REFRESH_FLAGS),
|
|
876
|
+
run: refresh,
|
|
877
|
+
},
|
|
878
|
+
doctor: {
|
|
879
|
+
synopsis: "[--json]",
|
|
880
|
+
summary: "find servers that bypass the gateway",
|
|
881
|
+
flags: flagsOf(DOCTOR_FLAGS),
|
|
882
|
+
json: DOCTOR_JSON,
|
|
883
|
+
run: doctor,
|
|
884
|
+
},
|
|
758
885
|
login: {
|
|
759
886
|
synopsis: "<server> [--profile <p>] [--scope <s>] [--no-browser] [--dry-run] [--json]",
|
|
760
887
|
summary: "log mcpd in to a remote OAuth server, once per variant",
|
|
761
888
|
args: ["server"],
|
|
762
889
|
flags: flagsOf(LOGIN_FLAGS),
|
|
890
|
+
json: LOGIN_JSON,
|
|
763
891
|
details: 'For servers declared with auth = "oauth" in mcp.toml. mcpd keeps the tokens in the secret store\n(Keychain or Secret Service) and refreshes them; agents reach the server through mcpd.\n--profile logs in the variant of that profile ([server.<name>.variant.<profile>]); without one,\nthe login serves every profile that has no variant of its own.',
|
|
764
892
|
run: async (rest, io) => (await import("./mcp-oauth.js")).login(rest, io),
|
|
765
893
|
},
|
|
@@ -774,23 +902,35 @@ const SUBS = {
|
|
|
774
902
|
synopsis: "[-f] [-n N] [--server S] [--profile P] [--json]",
|
|
775
903
|
summary: "tool calls mcpd relayed (no arguments or results)",
|
|
776
904
|
flags: flagsOf(LOG_FLAGS),
|
|
905
|
+
json: LOG_JSON,
|
|
777
906
|
details: "One line per tool call: time, outcome, duration, server, tool, profile, agent and sizes.\n-f keeps printing new calls; --json prints one JSON record per line.\nTurn the log off with call_log = false under [mcpd] in config.toml.",
|
|
778
907
|
run: async (rest, io) => (await import("./mcp-observe.js")).log(rest, io),
|
|
779
908
|
},
|
|
780
909
|
top: {
|
|
781
|
-
synopsis: "[--once] [--json]",
|
|
910
|
+
synopsis: "[--once | --watch] [--json]",
|
|
782
911
|
summary: "memory, sessions and calls of each running server",
|
|
783
912
|
flags: flagsOf(TOP_FLAGS),
|
|
784
|
-
|
|
913
|
+
json: TOP_JSON,
|
|
914
|
+
details: "Refreshes every 2 seconds in a terminal (Ctrl-C quits); prints one snapshot otherwise.\n--watch keeps refreshing anywhere; with --json it prints one snapshot per line (NDJSON).\nExits 5 when mcpd is not running.",
|
|
785
915
|
run: async (rest, io) => (await import("./mcp-observe.js")).top(rest, io),
|
|
786
916
|
},
|
|
787
917
|
savings: {
|
|
788
918
|
synopsis: "[--json]",
|
|
789
919
|
summary: "memory mcpd saves compared with no gateway",
|
|
790
920
|
flags: flagsOf(SAVINGS_FLAGS),
|
|
921
|
+
json: SAVINGS_JSON,
|
|
791
922
|
details: "Compares mcpd plus its servers now with an estimate where each live agent session\nstarts its own copy of every stdio server its profile uses.",
|
|
792
923
|
run: async (rest, io) => (await import("./mcp-observe.js")).savings(rest, io),
|
|
793
924
|
},
|
|
925
|
+
call: {
|
|
926
|
+
synopsis: "<server> [tool] [--args JSON] [--arg k=v ...] [--profile <p>] [--json]",
|
|
927
|
+
summary: "call one tool through mcpd, as a profile's session would",
|
|
928
|
+
args: ["server", "any"],
|
|
929
|
+
flags: flagsOf(CALL_FLAGS),
|
|
930
|
+
json: CALL_JSON,
|
|
931
|
+
details: "For debugging a server without opening an agent. The call goes through mcpd\nwith the token of --profile (default: the profile this folder resolves to,\nelse the system one) and this folder, so tool filters and [[projects]] server\nsets apply as they would to an agent here. --args takes a JSON object;\n--arg key=value adds a string and --arg key:=json any JSON value. Without a\ntool it lists the server's tools. Exits 1 when the tool returns isError, 5\nwhen mcpd is not running.",
|
|
932
|
+
run: async (rest, io) => (await import("./mcp-call.js")).call(rest, io),
|
|
933
|
+
},
|
|
794
934
|
daemon: {
|
|
795
935
|
synopsis: "<start|stop|restart|status|logs>",
|
|
796
936
|
summary: "the gateway daemon (same as turno mcpd)",
|
|
@@ -810,9 +950,30 @@ const SUBS = {
|
|
|
810
950
|
export const command = group("mcp", "MCP servers behind the lazy gateway, and the gateway daemon itself", SUBS, {
|
|
811
951
|
fallback: "list",
|
|
812
952
|
footer: `config prints entries for ${SNIPPET_AGENTS.join(", ")}.
|
|
813
|
-
import reads ~/.claude.json, .mcp.json, ~/.codex, ~/.cursor and ~/.copilot
|
|
814
|
-
It only previews, with secrets hidden, until --write.
|
|
953
|
+
import reads ~/.claude.json, .mcp.json, ~/.codex, ~/.cursor and ~/.copilot,
|
|
954
|
+
or one file. It only previews, with secrets hidden, until --write.
|
|
815
955
|
Docs: docs/mcp.md in the turno repository.`,
|
|
956
|
+
examples: [
|
|
957
|
+
"turno mcp list --json=name,kind",
|
|
958
|
+
"turno mcp import --write --move-secrets",
|
|
959
|
+
"turno mcp import servers.toml --write",
|
|
960
|
+
"turno mcp export --profile work > servers.toml",
|
|
961
|
+
"turno mcp install",
|
|
962
|
+
"turno mcp sync",
|
|
963
|
+
"turno mcp config --agent opencode",
|
|
964
|
+
"turno mcp refresh github",
|
|
965
|
+
"turno mcp doctor",
|
|
966
|
+
"turno mcp login linear --profile work",
|
|
967
|
+
"turno mcp logout linear --all",
|
|
968
|
+
"turno mcp log -f --server github",
|
|
969
|
+
"turno mcp top --watch --json # one JSON line every 2 s",
|
|
970
|
+
"turno mcp savings",
|
|
971
|
+
"turno mcp call github",
|
|
972
|
+
"turno mcp call github search_issues --arg query=bug --arg limit:=5",
|
|
973
|
+
'turno mcp call fs read_file --args \'{"path": "README.md"}\' --profile work --json',
|
|
974
|
+
"turno mcp daemon status",
|
|
975
|
+
"turno mcp token rotate",
|
|
976
|
+
],
|
|
816
977
|
});
|
|
817
978
|
import { isObject, readJsonFile } from "../../core/fsutil.js";
|
|
818
979
|
//# sourceMappingURL=mcp.js.map
|
|
@@ -3,7 +3,9 @@ import { join } from "node:path";
|
|
|
3
3
|
import { fileURLToPath } from "node:url";
|
|
4
4
|
import { Journal } from "../../core/journal.js";
|
|
5
5
|
import { paths, tildify } from "../../core/paths.js";
|
|
6
|
-
import { DRY_RUN, JSON_FLAG, TAIL, bool, count, parseFlags,
|
|
6
|
+
import { DRY_RUN, JSON_FLAG, TAIL, bool, count, parseFlags, str } from "../args.js";
|
|
7
|
+
import { Exit } from "../exit.js";
|
|
8
|
+
import { emit, jsonOutput } from "../output.js";
|
|
7
9
|
import { group } from "../group.js";
|
|
8
10
|
import { fail, paint, plural } from "../io.js";
|
|
9
11
|
import { duration, spinner, style } from "../style.js";
|
|
@@ -63,22 +65,39 @@ export async function downReasons(env) {
|
|
|
63
65
|
out.push(`stale lock from pid ${lock.pid} (${tildify(daemonFiles(env).lock, env)}); the next start clears it`);
|
|
64
66
|
return out;
|
|
65
67
|
}
|
|
68
|
+
/** `turno mcp daemon status --json`: mcpd's /status, or `{ running: false, problems }`. */
|
|
69
|
+
const STATUS_JSON = jsonOutput([
|
|
70
|
+
"running",
|
|
71
|
+
"problems",
|
|
72
|
+
"pid",
|
|
73
|
+
"version",
|
|
74
|
+
"port",
|
|
75
|
+
"startedAt",
|
|
76
|
+
"sessions",
|
|
77
|
+
"agents",
|
|
78
|
+
"memoryPressure",
|
|
79
|
+
"instances",
|
|
80
|
+
"manifest",
|
|
81
|
+
"config",
|
|
82
|
+
"callLog",
|
|
83
|
+
"serverRss",
|
|
84
|
+
]);
|
|
66
85
|
async function status(args, io) {
|
|
67
86
|
const p = parseFlags(args, JSON_FLAG, 0);
|
|
68
87
|
const s = await fetchStatus(io.env);
|
|
69
88
|
if (!s) {
|
|
70
89
|
const reasons = await downReasons(io.env);
|
|
71
90
|
if (bool(p, "json"))
|
|
72
|
-
|
|
91
|
+
emit(io, p, STATUS_JSON, { running: false, problems: reasons });
|
|
73
92
|
else {
|
|
74
93
|
io.out("mcpd is not running (turno mcp daemon start)");
|
|
75
94
|
for (const r of reasons)
|
|
76
95
|
io.out(` ${r}`);
|
|
77
96
|
}
|
|
78
|
-
return
|
|
97
|
+
return Exit.gatewayDown;
|
|
79
98
|
}
|
|
80
99
|
if (bool(p, "json")) {
|
|
81
|
-
|
|
100
|
+
emit(io, p, STATUS_JSON, s);
|
|
82
101
|
return 0;
|
|
83
102
|
}
|
|
84
103
|
const instances = s.instances ?? [];
|
|
@@ -173,7 +192,11 @@ async function runDaemon(args, io) {
|
|
|
173
192
|
let waiting = false;
|
|
174
193
|
for (;;) {
|
|
175
194
|
try {
|
|
176
|
-
const d = await startDaemon({
|
|
195
|
+
const d = await startDaemon({
|
|
196
|
+
env: io.env,
|
|
197
|
+
logToStdout: Boolean(process.stdout.isTTY) && !service,
|
|
198
|
+
...(port !== undefined ? { port } : {}),
|
|
199
|
+
});
|
|
177
200
|
io.err(`mcpd listening on 127.0.0.1:${d.port}`);
|
|
178
201
|
const unguard = installCrashGuards(d.log, () => d.stop());
|
|
179
202
|
await new Promise((resolve) => {
|
|
@@ -384,17 +407,49 @@ async function token(args, io) {
|
|
|
384
407
|
return code;
|
|
385
408
|
}
|
|
386
409
|
const SUBS = {
|
|
387
|
-
start: {
|
|
388
|
-
|
|
410
|
+
start: {
|
|
411
|
+
synopsis: "[--dry-run]",
|
|
412
|
+
summary: "install the service (LaunchAgent or systemd user unit) and start mcpd",
|
|
413
|
+
flags: ["--dry-run"],
|
|
414
|
+
run: start,
|
|
415
|
+
},
|
|
416
|
+
stop: {
|
|
417
|
+
synopsis: "[--dry-run]",
|
|
418
|
+
summary: "stop mcpd and remove the service, so it does not start at login",
|
|
419
|
+
flags: ["--dry-run"],
|
|
420
|
+
run: stop,
|
|
421
|
+
},
|
|
389
422
|
restart: { summary: "restart the service (open sessions reconnect)", run: restart },
|
|
390
|
-
status: {
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
423
|
+
status: {
|
|
424
|
+
synopsis: "[--json]",
|
|
425
|
+
summary: "running servers, their clients and memory; why mcpd is down (exit 5)",
|
|
426
|
+
flags: ["--json"],
|
|
427
|
+
json: STATUS_JSON,
|
|
428
|
+
run: status,
|
|
429
|
+
},
|
|
430
|
+
logs: {
|
|
431
|
+
synopsis: "[-n N] [--utc]",
|
|
432
|
+
summary: "last lines of the mcpd log, in local time",
|
|
433
|
+
flags: ["--tail", "--utc"],
|
|
434
|
+
run: logs,
|
|
435
|
+
},
|
|
436
|
+
run: {
|
|
437
|
+
synopsis: "[--port N]",
|
|
438
|
+
summary: "run the gateway in the foreground (what the service runs)",
|
|
439
|
+
flags: ["--port"],
|
|
440
|
+
run: runDaemon,
|
|
441
|
+
},
|
|
442
|
+
token: {
|
|
443
|
+
synopsis: "rotate [--dry-run]",
|
|
444
|
+
summary: "replace the gateway token (then turno mcp sync)",
|
|
445
|
+
args: ["any"],
|
|
446
|
+
flags: ["--dry-run"],
|
|
447
|
+
run: token,
|
|
448
|
+
},
|
|
394
449
|
};
|
|
395
450
|
export const tokenCommand = {
|
|
396
451
|
summary: "replace the gateway token",
|
|
397
|
-
usage: "Usage: turno mcp token rotate [--dry-run]\n\nWrites a new token (mode 600), restarts mcpd, and asks you to run turno mcp sync
|
|
452
|
+
usage: "Usage: turno mcp token rotate [--dry-run]\n\nWrites a new token (mode 600), restarts mcpd, and asks you to run turno mcp sync.\n\nExamples:\n $ turno mcp token rotate --dry-run\n $ turno mcp token rotate && turno mcp sync",
|
|
398
453
|
run: async (args, io) => {
|
|
399
454
|
if (!args.includes("--help") && !args.includes("-h"))
|
|
400
455
|
return token(args, io);
|
|
@@ -405,5 +460,14 @@ export const tokenCommand = {
|
|
|
405
460
|
export const command = group("mcp daemon", "run or manage the MCP gateway daemon", SUBS, {
|
|
406
461
|
footer: "mcpd listens on 127.0.0.1 at mcpd.port (config.toml) and never moves to another port.\n" +
|
|
407
462
|
"start keeps it alive with a LaunchAgent on macOS or a systemd user unit on Linux; stop removes it.",
|
|
463
|
+
examples: [
|
|
464
|
+
"turno mcp daemon start",
|
|
465
|
+
"turno mcp daemon status --json",
|
|
466
|
+
"turno mcp daemon restart",
|
|
467
|
+
"turno mcp daemon logs -n 50",
|
|
468
|
+
"turno mcp daemon stop --dry-run",
|
|
469
|
+
"turno mcp daemon run --port 47900",
|
|
470
|
+
"turno mcp daemon token rotate",
|
|
471
|
+
],
|
|
408
472
|
});
|
|
409
473
|
//# sourceMappingURL=mcpd.js.map
|