@amoree-code/ocean 1.4.0 → 1.5.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/dist/application/clients/clients.js +122 -6
- package/dist/infrastructure/mcp/remote-mcp-client.js +46 -0
- package/dist/interfaces/cli/clients-command.js +39 -2
- package/dist/interfaces/cli/command-registry.js +7 -3
- package/dist/interfaces/cli/gateway-findings.js +32 -0
- package/dist/interfaces/cli/help-command.js +3 -3
- package/dist/interfaces/cli/market-command.js +142 -5
- package/dist/interfaces/cli/mcp-gateway-command.js +28 -11
- package/dist/interfaces/cli/mcp-status-command.js +135 -0
- package/dist/interfaces/cli/onboard-command.js +6 -2
- package/node_modules/@ocean/brain/package.json +1 -1
- package/node_modules/@ocean/context/package.json +1 -1
- package/node_modules/@ocean/core/package.json +1 -1
- package/node_modules/@ocean/loop/package.json +1 -1
- package/node_modules/@ocean/market/dist/adapters/mcp-adapter.js +13 -2
- package/node_modules/@ocean/market/dist/install/default-marketplace.js +1 -0
- package/node_modules/@ocean/market/dist/install/own-server.js +110 -0
- package/node_modules/@ocean/market/dist/mcp/mcp-gateway.js +113 -10
- package/node_modules/@ocean/market/dist/mcp/mcp-launch.js +167 -23
- package/node_modules/@ocean/market/dist/mcp/mcp-runner.js +6 -1
- package/node_modules/@ocean/market/dist/registry/official-registry.js +76 -0
- package/node_modules/@ocean/market/dist/security/secrets.js +66 -0
- package/node_modules/@ocean/market/package.json +1 -1
- package/node_modules/@ocean/services/package.json +1 -1
- package/ocean-marketplace.json +28 -28
- package/package.json +7 -7
|
@@ -12,7 +12,112 @@ import { marketplacePaths } from "@ocean/market/install/default-marketplace.js";
|
|
|
12
12
|
import { ENTRY_KEYS, ManualEdit, } from "./editors.js";
|
|
13
13
|
import { CLIENT_ADAPTERS, mcpClientOf, } from "./registry.js";
|
|
14
14
|
// Keys Ocean already manages for its own servers; a marketplace server never takes one.
|
|
15
|
-
const RESERVED_KEYS = new Set(["ocean", "ocean-obsidian"]);
|
|
15
|
+
const RESERVED_KEYS = new Set(["ocean", "ocean-obsidian", "ocean-gateway"]);
|
|
16
|
+
// What a gateway-wired client runs: every installed server through one process, without
|
|
17
|
+
// Ocean's own servers, which stay direct entries so their tool names do not change.
|
|
18
|
+
export const GATEWAY_COMMAND = ["mcp", "gateway", "--installed-only"];
|
|
19
|
+
function gatewayClientsFile() {
|
|
20
|
+
return oceanPath(SYSTEM_DIR, "state", "clients", "gateway.json");
|
|
21
|
+
}
|
|
22
|
+
function readGatewayChoice(file) {
|
|
23
|
+
const choice = {
|
|
24
|
+
default: "per-server",
|
|
25
|
+
gateway: [],
|
|
26
|
+
perServer: [],
|
|
27
|
+
};
|
|
28
|
+
let raw;
|
|
29
|
+
try {
|
|
30
|
+
raw = JSON.parse(readFileSync(file, "utf8"));
|
|
31
|
+
}
|
|
32
|
+
catch {
|
|
33
|
+
return choice;
|
|
34
|
+
}
|
|
35
|
+
const ids = (value) => Array.isArray(value)
|
|
36
|
+
? value.filter((id) => typeof id === "string")
|
|
37
|
+
: [];
|
|
38
|
+
if (raw.default === "gateway")
|
|
39
|
+
choice.default = "gateway";
|
|
40
|
+
// `clients` is the T-309 phase-4 name of `gateway`.
|
|
41
|
+
choice.gateway = [...new Set([...ids(raw.gateway), ...ids(raw.clients)])];
|
|
42
|
+
choice.perServer = ids(raw.perServer);
|
|
43
|
+
return choice;
|
|
44
|
+
}
|
|
45
|
+
async function writeGatewayChoice(file, choice) {
|
|
46
|
+
await mkdir(path.dirname(file), { recursive: true });
|
|
47
|
+
await atomicWrite(file, `${JSON.stringify({
|
|
48
|
+
default: choice.default,
|
|
49
|
+
gateway: [...new Set(choice.gateway)].sort(),
|
|
50
|
+
perServer: [...new Set(choice.perServer)].sort(),
|
|
51
|
+
}, null, 2)}\n`);
|
|
52
|
+
}
|
|
53
|
+
const clientIds = () => CLIENT_ADAPTERS.map((adapter) => adapter.id);
|
|
54
|
+
export function readGatewayClients(file = gatewayClientsFile(), ids = clientIds()) {
|
|
55
|
+
const choice = readGatewayChoice(file);
|
|
56
|
+
return new Set(choice.default === "gateway"
|
|
57
|
+
? ids.filter((id) => !choice.perServer.includes(id))
|
|
58
|
+
: choice.gateway.filter((id) => ids.includes(id)));
|
|
59
|
+
}
|
|
60
|
+
export function gatewayDefault(file = gatewayClientsFile()) {
|
|
61
|
+
return readGatewayChoice(file).default;
|
|
62
|
+
}
|
|
63
|
+
// `ocean clients gateway <client> on|off`: recorded here, applied by `ocean clients apply`.
|
|
64
|
+
export async function setGatewayClient(client, on, file = gatewayClientsFile()) {
|
|
65
|
+
if (!clientIds().includes(client))
|
|
66
|
+
throw new Error(`Unknown client ${client}; one of: ${clientIds().join(", ")}`);
|
|
67
|
+
const choice = readGatewayChoice(file);
|
|
68
|
+
choice.gateway = choice.gateway.filter((id) => id !== client);
|
|
69
|
+
choice.perServer = choice.perServer.filter((id) => id !== client);
|
|
70
|
+
if (on && choice.default !== "gateway")
|
|
71
|
+
choice.gateway.push(client);
|
|
72
|
+
if (!on && choice.default === "gateway")
|
|
73
|
+
choice.perServer.push(client);
|
|
74
|
+
await writeGatewayChoice(file, choice);
|
|
75
|
+
return [...readGatewayClients(file)].sort();
|
|
76
|
+
}
|
|
77
|
+
// `ocean clients gateway --default gateway|per-server`; the per-client choices are kept.
|
|
78
|
+
export async function setGatewayDefault(mode, file = gatewayClientsFile()) {
|
|
79
|
+
const choice = readGatewayChoice(file);
|
|
80
|
+
choice.default = mode;
|
|
81
|
+
await writeGatewayChoice(file, choice);
|
|
82
|
+
return [...readGatewayClients(file)].sort();
|
|
83
|
+
}
|
|
84
|
+
// A fresh machine (no choice recorded, no client approved yet) starts with the gateway as the
|
|
85
|
+
// default. A machine already wired per server keeps that until its owner switches.
|
|
86
|
+
export async function defaultToGatewayOnFreshSetup(file = gatewayClientsFile()) {
|
|
87
|
+
if (existsSync(file))
|
|
88
|
+
return false;
|
|
89
|
+
if (Object.keys(await approvedClients()).length)
|
|
90
|
+
return false;
|
|
91
|
+
await writeGatewayChoice(file, {
|
|
92
|
+
default: "gateway",
|
|
93
|
+
gateway: [],
|
|
94
|
+
perServer: [],
|
|
95
|
+
});
|
|
96
|
+
return true;
|
|
97
|
+
}
|
|
98
|
+
// The marketplace entries one client should have: the single gateway entry when it is wired to
|
|
99
|
+
// the gateway, otherwise one entry per installed server.
|
|
100
|
+
function marketFor(client, env) {
|
|
101
|
+
if (env.gateway?.clients.has(client)) {
|
|
102
|
+
const entry = env.gateway.entry;
|
|
103
|
+
// The client's id travels in its own entry, so the gateway's access rules match the name
|
|
104
|
+
// Ocean wrote rather than the name the client gives itself.
|
|
105
|
+
return new Map([
|
|
106
|
+
[
|
|
107
|
+
"ocean-gateway",
|
|
108
|
+
{
|
|
109
|
+
...entry,
|
|
110
|
+
args: [
|
|
111
|
+
...(Array.isArray(entry.args) ? entry.args : []),
|
|
112
|
+
"--client",
|
|
113
|
+
client,
|
|
114
|
+
],
|
|
115
|
+
},
|
|
116
|
+
],
|
|
117
|
+
]);
|
|
118
|
+
}
|
|
119
|
+
return env.market;
|
|
120
|
+
}
|
|
16
121
|
// A node inside a version manager's tree disappears when that version is removed (T-307).
|
|
17
122
|
const VERSIONED_NODE = /[\\/](?:node-versions|\.nvm[\\/]versions[\\/]node|\.volta[\\/]tools[\\/]image[\\/]node|\.asdf[\\/]installs[\\/]nodejs|mise[\\/]installs[\\/]node|n[\\/]versions[\\/]node)[\\/]/;
|
|
18
123
|
export function isVersionedNode(execPath) {
|
|
@@ -77,6 +182,10 @@ export function defaultClientEnv() {
|
|
|
77
182
|
: [],
|
|
78
183
|
entry: oceanServerEntry(),
|
|
79
184
|
market: marketServerEntries(marketplacePaths().mcpServers),
|
|
185
|
+
gateway: {
|
|
186
|
+
clients: readGatewayClients(),
|
|
187
|
+
entry: oceanServerEntry(undefined, undefined, undefined, GATEWAY_COMMAND),
|
|
188
|
+
},
|
|
80
189
|
};
|
|
81
190
|
}
|
|
82
191
|
const sha = (value) => createHash("sha256").update(value).digest("hex");
|
|
@@ -215,12 +324,19 @@ function opsFor(adapter, text, entry, market) {
|
|
|
215
324
|
}
|
|
216
325
|
return { ops };
|
|
217
326
|
}
|
|
218
|
-
// An Ocean-managed entry that starts
|
|
327
|
+
// An Ocean-managed entry that starts installed marketplace servers: one `ocean market exec`, or
|
|
328
|
+
// the client's gateway entry. A gateway entry the owner added by hand (`ocean mcp
|
|
329
|
+
// gateway-config`, no `--installed-only`) is the owner's and is left alone.
|
|
219
330
|
function isMarketExec(value) {
|
|
220
331
|
if (!isOceanShaped(value) || !Array.isArray(value.args))
|
|
221
332
|
return false;
|
|
222
333
|
const at = value.args.indexOf("market");
|
|
223
|
-
|
|
334
|
+
if (at >= 0 && value.args[at + 1] === "exec")
|
|
335
|
+
return true;
|
|
336
|
+
const gateway = value.args.indexOf("gateway");
|
|
337
|
+
return (gateway > 0 &&
|
|
338
|
+
value.args[gateway - 1] === "mcp" &&
|
|
339
|
+
value.args.includes("--installed-only"));
|
|
224
340
|
}
|
|
225
341
|
export async function planClients(env = defaultClientEnv()) {
|
|
226
342
|
const plans = [];
|
|
@@ -245,7 +361,7 @@ export async function planClients(env = defaultClientEnv()) {
|
|
|
245
361
|
plan.status = adapter.tier === "supported" ? "unknown" : adapter.tier;
|
|
246
362
|
else {
|
|
247
363
|
const text = (await readText(path.join(env.home, adapter.config.file))) ?? "";
|
|
248
|
-
const { ops, manual } = opsFor(adapter, text, env.entry, env
|
|
364
|
+
const { ops, manual } = opsFor(adapter, text, env.entry, marketFor(adapter.id, env));
|
|
249
365
|
plan.ops = ops;
|
|
250
366
|
plan.status = ops.length ? "change" : "current";
|
|
251
367
|
if (!manual && ops.length)
|
|
@@ -265,7 +381,7 @@ export async function planClients(env = defaultClientEnv()) {
|
|
|
265
381
|
if (plan.status === "manual")
|
|
266
382
|
plan.snippet = JSON.stringify({
|
|
267
383
|
ocean: env.entry,
|
|
268
|
-
...Object.fromEntries(
|
|
384
|
+
...Object.fromEntries(marketFor(adapter.id, env) ?? []),
|
|
269
385
|
});
|
|
270
386
|
}
|
|
271
387
|
plans.push(plan);
|
|
@@ -446,7 +562,7 @@ export async function applyClients(options = {}) {
|
|
|
446
562
|
const config = adapter.config;
|
|
447
563
|
const file = path.join(env.home, config.file);
|
|
448
564
|
const result = await edit(file, (text) => {
|
|
449
|
-
const { ops, manual } = opsFor(adapter, text, env.entry, env
|
|
565
|
+
const { ops, manual } = opsFor(adapter, text, env.entry, marketFor(adapter.id, env));
|
|
450
566
|
if (manual || !ops.length)
|
|
451
567
|
return null;
|
|
452
568
|
// Each op's "before" is the table as the earlier ops of this batch left it.
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { Client } from "@modelcontextprotocol/sdk/client/index.js";
|
|
2
|
+
import { SSEClientTransport } from "@modelcontextprotocol/sdk/client/sse.js";
|
|
3
|
+
import { StreamableHTTPClientTransport } from "@modelcontextprotocol/sdk/client/streamableHttp.js";
|
|
4
|
+
import { mcpToolSchema, } from "@ocean/core/domain/mcp/mcp-contract.js";
|
|
5
|
+
// The gateway's client for a remote member (streamable HTTP or the older SSE transport).
|
|
6
|
+
// Redirects stay on the same origin, so a call never leaves the host the capability declared.
|
|
7
|
+
// Header values (tokens) come resolved from the launcher, from the environment or the secret
|
|
8
|
+
// store; same-origin redirects keep them from reaching another host.
|
|
9
|
+
export class RemoteMcpClient {
|
|
10
|
+
#client;
|
|
11
|
+
#transport;
|
|
12
|
+
constructor(member, version) {
|
|
13
|
+
const url = new URL(member.url);
|
|
14
|
+
const options = {
|
|
15
|
+
redirectPolicy: "same-origin",
|
|
16
|
+
...(member.headers ? { requestInit: { headers: member.headers } } : {}),
|
|
17
|
+
};
|
|
18
|
+
this.#transport =
|
|
19
|
+
member.type === "sse"
|
|
20
|
+
? new SSEClientTransport(url, options)
|
|
21
|
+
: new StreamableHTTPClientTransport(url, options);
|
|
22
|
+
this.#client = new Client({ name: "ocean-gateway", version });
|
|
23
|
+
}
|
|
24
|
+
async connect() {
|
|
25
|
+
await this.#client.connect(this.#transport);
|
|
26
|
+
}
|
|
27
|
+
async listTools() {
|
|
28
|
+
const tools = [];
|
|
29
|
+
let cursor;
|
|
30
|
+
do {
|
|
31
|
+
const page = await this.#client.listTools(cursor ? { cursor } : undefined);
|
|
32
|
+
for (const tool of page.tools)
|
|
33
|
+
tools.push(mcpToolSchema.parse(tool));
|
|
34
|
+
cursor = page.nextCursor;
|
|
35
|
+
} while (cursor);
|
|
36
|
+
return tools;
|
|
37
|
+
}
|
|
38
|
+
// The arguments go to the server unchanged, as for a stdio member.
|
|
39
|
+
forwardToolCall(name, args) {
|
|
40
|
+
return this.#client.callTool({ name, arguments: args });
|
|
41
|
+
}
|
|
42
|
+
close() {
|
|
43
|
+
void this.#client.close().catch(() => { });
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
//# sourceMappingURL=remote-mcp-client.js.map
|
|
@@ -1,9 +1,11 @@
|
|
|
1
|
+
import { marketplacePaths } from "@ocean/market/install/default-marketplace.js";
|
|
2
|
+
import { updateGatewayAccess } from "@ocean/market/mcp/mcp-gateway.js";
|
|
1
3
|
import { readCallLedger, summarizeCallLedger, } from "@ocean/services/infrastructure/mcp/call-ledger.js";
|
|
2
|
-
import { applyClients, attributeLedger, confirmClient, defaultClientEnv, planClients, recordVerification, repairClients, restoreClients, temporaryEntryProblem, verifyClient, } from "../../application/clients/clients.js";
|
|
4
|
+
import { applyClients, attributeLedger, confirmClient, defaultClientEnv, gatewayDefault, planClients, readGatewayClients, recordVerification, repairClients, restoreClients, setGatewayClient, setGatewayDefault, temporaryEntryProblem, verifyClient, } from "../../application/clients/clients.js";
|
|
3
5
|
import { applyHooks, planHooks, restoreHooks, } from "../../application/clients/hooks.js";
|
|
4
6
|
import { applyNative, planNative, restoreNative, } from "../../application/clients/native.js";
|
|
5
7
|
import { applyOpencodePlugin, planOpencodePlugin, restoreOpencodePlugin, } from "../../application/clients/opencode-plugin.js";
|
|
6
|
-
const usage = "Usage: ocean clients detect|plan [--json] | apply [--client <id>…] [--yes] | verify [<id>…] | confirm <id>… --label in-app|headless|connected|blocked [--via <evidence>] [--reason <why>] | ledger | repair | restore [--batch <id>]";
|
|
8
|
+
const usage = "Usage: ocean clients detect|plan [--json] | apply [--client <id>…] [--yes] | verify [<id>…] | confirm <id>… --label in-app|headless|connected|blocked [--via <evidence>] [--reason <why>] | gateway [<id> on|off] [--default gateway|per-server] | allow|deny|unset <id> <server> | ledger | repair | restore [--batch <id>]";
|
|
7
9
|
// `ocean clients` (T-296 P2/P3b): every installed AI client's `ocean` MCP entry and, where the
|
|
8
10
|
// client has a verified session-start event, Ocean's session hook. `apply` shows the plan until
|
|
9
11
|
// --yes; `repair` only re-applies clients already approved; `restore` undoes an apply batch
|
|
@@ -106,6 +108,41 @@ export async function runClientsCommand(args) {
|
|
|
106
108
|
else if (action === "ledger")
|
|
107
109
|
// Which client called which Ocean tool, and when last — the in-app evidence (T-307).
|
|
108
110
|
result = attributeLedger(summarizeCallLedger(await readCallLedger()));
|
|
111
|
+
else if (action === "gateway") {
|
|
112
|
+
// Which clients get one `ocean-gateway` entry instead of an entry per marketplace server
|
|
113
|
+
// (T-309); `ocean clients apply` then rewires them.
|
|
114
|
+
const mode = values("--default")[0];
|
|
115
|
+
const [client, state] = rest.filter((arg, index) => !arg.startsWith("--") && rest[index - 1] !== "--default");
|
|
116
|
+
if ((mode && mode !== "gateway" && mode !== "per-server") ||
|
|
117
|
+
(client && state !== "on" && state !== "off"))
|
|
118
|
+
throw new Error("Usage: ocean clients gateway [<id> on|off] [--default gateway|per-server]");
|
|
119
|
+
if (mode === "gateway" || mode === "per-server")
|
|
120
|
+
await setGatewayDefault(mode);
|
|
121
|
+
const clients = client
|
|
122
|
+
? await setGatewayClient(client, state === "on")
|
|
123
|
+
: [...readGatewayClients()].sort();
|
|
124
|
+
result = {
|
|
125
|
+
default: gatewayDefault(),
|
|
126
|
+
clients,
|
|
127
|
+
...(client || mode
|
|
128
|
+
? {
|
|
129
|
+
next: `ocean clients apply${client ? ` --client ${client}` : ""} --yes`,
|
|
130
|
+
}
|
|
131
|
+
: {}),
|
|
132
|
+
};
|
|
133
|
+
}
|
|
134
|
+
else if (action === "allow" || action === "deny" || action === "unset") {
|
|
135
|
+
// Which installed server a gateway-wired client sees (bridge/market/gateway-access.json).
|
|
136
|
+
const [client, capability] = rest.filter((arg) => !arg.startsWith("--"));
|
|
137
|
+
if (!client || !capability)
|
|
138
|
+
throw new Error(`Usage: ocean clients ${action} <id> <server name>`);
|
|
139
|
+
const access = await updateGatewayAccess(marketplacePaths().gatewayAccess, client, capability, action);
|
|
140
|
+
result = {
|
|
141
|
+
client,
|
|
142
|
+
rule: access.clients[client] ?? "default",
|
|
143
|
+
next: "restart the client (the gateway reads its rules at start)",
|
|
144
|
+
};
|
|
145
|
+
}
|
|
109
146
|
else if (action === "repair")
|
|
110
147
|
result = await repairClients();
|
|
111
148
|
else if (action === "restore") {
|
|
@@ -51,6 +51,7 @@ import { runClientTestCommand } from "./client-test-command.js";
|
|
|
51
51
|
import { runClientsCommand } from "./clients-command.js";
|
|
52
52
|
import { runContextCommand, runContextCostCommand } from "./context-command.js";
|
|
53
53
|
import { runDailyCommand } from "./daily-command.js";
|
|
54
|
+
import { gatewayFindings } from "./gateway-findings.js";
|
|
54
55
|
import { runLifecycleCommand, runPolicyCommand } from "./governance-command.js";
|
|
55
56
|
import { runHandoffCommand } from "./handoff-command.js";
|
|
56
57
|
import { runIdeaCommand } from "./idea-command.js";
|
|
@@ -58,6 +59,7 @@ import { intercept } from "./intercept-command.js";
|
|
|
58
59
|
import { runLayoutCommand } from "./layout-command.js";
|
|
59
60
|
import { runMarketCommand } from "./market-command.js";
|
|
60
61
|
import { runMcpGatewayCommand } from "./mcp-gateway-command.js";
|
|
62
|
+
import { runMcpStatusCommand } from "./mcp-status-command.js";
|
|
61
63
|
import { runMemoryCommand } from "./memory-command.js";
|
|
62
64
|
import { runMigrateCommand } from "./migrate-command.js";
|
|
63
65
|
import { runObserveCommand } from "./observe-command.js";
|
|
@@ -332,11 +334,13 @@ async function commandMcp() {
|
|
|
332
334
|
embedder: mcpEmbedder(),
|
|
333
335
|
});
|
|
334
336
|
else if (action === "gateway")
|
|
335
|
-
await runMcpGatewayCommand();
|
|
337
|
+
await runMcpGatewayCommand(process.argv.slice(4));
|
|
338
|
+
else if (action === "status")
|
|
339
|
+
await runMcpStatusCommand(process.argv.slice(4));
|
|
336
340
|
else if (action === "browser-service")
|
|
337
341
|
await runBrowserServiceCommand(process.argv[4] ?? "");
|
|
338
342
|
else {
|
|
339
|
-
console.error("Usage: ocean mcp config|playwright-config|gateway-config|serve|gateway|browser-service uninstall");
|
|
343
|
+
console.error("Usage: ocean mcp config|playwright-config|gateway-config|serve|gateway|status [--check] [--json]|browser-service uninstall");
|
|
340
344
|
process.exitCode = 1;
|
|
341
345
|
}
|
|
342
346
|
}
|
|
@@ -923,7 +927,7 @@ async function commandUpdateOrRemove(command) {
|
|
|
923
927
|
async function commandDoctor() {
|
|
924
928
|
const report = await workspaceReport(defaultWrapperManager);
|
|
925
929
|
// T-296: every installed AI client's `ocean` entry (supported fail, unknown warn).
|
|
926
|
-
report.findings.push(...(await clientFindings()), ...(await nativeFindings()), ...(await browserFindings()));
|
|
930
|
+
report.findings.push(...(await clientFindings()), ...(await nativeFindings()), ...(await browserFindings()), ...(await gatewayFindings()));
|
|
927
931
|
if (process.argv.includes("--json"))
|
|
928
932
|
console.log(JSON.stringify(report, null, 2));
|
|
929
933
|
else
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { marketplacePaths } from "@ocean/market/install/default-marketplace.js";
|
|
2
|
+
import { readGatewayAccess } from "@ocean/market/mcp/mcp-gateway.js";
|
|
3
|
+
import { readGatewayClients } from "../../application/clients/clients.js";
|
|
4
|
+
// `ocean doctor` (T-309): which clients reach installed servers through the one gateway entry,
|
|
5
|
+
// and whether the access file the gateway reads at start is valid; an invalid one stops the
|
|
6
|
+
// gateway, and with it every installed server in those clients. Nothing set up is nothing to
|
|
7
|
+
// report.
|
|
8
|
+
export async function gatewayFindings(options = {}) {
|
|
9
|
+
const accessFile = options.accessFile ?? marketplacePaths().gatewayAccess;
|
|
10
|
+
const clients = [...(options.clients ?? readGatewayClients())].sort();
|
|
11
|
+
const finding = (severity, message) => ({
|
|
12
|
+
code: "GATEWAY",
|
|
13
|
+
severity,
|
|
14
|
+
message,
|
|
15
|
+
fixable: false,
|
|
16
|
+
});
|
|
17
|
+
let rules;
|
|
18
|
+
try {
|
|
19
|
+
rules = Object.keys((await readGatewayAccess(accessFile)).clients);
|
|
20
|
+
}
|
|
21
|
+
catch (error) {
|
|
22
|
+
return [
|
|
23
|
+
finding("FAIL", `${error instanceof Error ? error.message : String(error)}; the gateway will not start until it is fixed`),
|
|
24
|
+
];
|
|
25
|
+
}
|
|
26
|
+
if (!clients.length && !rules.length)
|
|
27
|
+
return [];
|
|
28
|
+
return [
|
|
29
|
+
finding("OK", `${clients.length ? `wired through ocean-gateway: ${clients.join(", ")}` : "no client wired through ocean-gateway"}; access rules for ${rules.length ? rules.join(", ") : "no client (the default hides servers that write files or drive a browser)"}. Undo with \`ocean clients gateway <id> off\` and \`ocean clients apply\``),
|
|
30
|
+
];
|
|
31
|
+
}
|
|
32
|
+
//# sourceMappingURL=gateway-findings.js.map
|
|
@@ -108,7 +108,7 @@ export const commandHelp = {
|
|
|
108
108
|
],
|
|
109
109
|
clients: [
|
|
110
110
|
"Connect installed AI clients to Ocean's MCP server and hooks; apply shows the plan until --yes.",
|
|
111
|
-
"ocean clients detect|plan [--json] | apply [--client <id>…] [--yes] | verify [<id>…] | confirm <id>… --label in-app|headless|connected|blocked [--via <evidence>] [--reason <why>] | ledger | repair | restore [--batch <id>]",
|
|
111
|
+
"ocean clients detect|plan [--json] | apply [--client <id>…] [--yes] | verify [<id>…] | confirm <id>… --label in-app|headless|connected|blocked [--via <evidence>] [--reason <why>] | gateway [<id> on|off] [--default gateway|per-server] | allow|deny|unset <id> <server> | ledger | repair | restore [--batch <id>]",
|
|
112
112
|
],
|
|
113
113
|
install: [
|
|
114
114
|
"Install a supported AI client CLI.",
|
|
@@ -122,11 +122,11 @@ export const commandHelp = {
|
|
|
122
122
|
],
|
|
123
123
|
mcp: [
|
|
124
124
|
"Print MCP client configs, or serve Ocean's MCP server and gateway.",
|
|
125
|
-
"ocean mcp config|playwright-config|gateway-config|serve|gateway|browser-service uninstall",
|
|
125
|
+
"ocean mcp config|playwright-config|gateway-config|serve|gateway|status [--check] [--json]|browser-service uninstall",
|
|
126
126
|
],
|
|
127
127
|
market: [
|
|
128
128
|
"List, install, update and run marketplace packages; permissions need --yes.",
|
|
129
|
-
"ocean market list|install <name> [--version <v>]|update <name>|uninstall <name>|
|
|
129
|
+
"ocean market list|install <name> [--version <v>]|update <name>|uninstall <name>|search <term>|add <server.json|registry name>|secret list|set|remove <name> [<value name>] [--index <file>]... [--yes] [--accept-flagged]",
|
|
130
130
|
],
|
|
131
131
|
browser: [
|
|
132
132
|
"Drive a browser session; uploads and submits need --approve.",
|
|
@@ -1,13 +1,101 @@
|
|
|
1
|
+
import { existsSync, readFileSync } from "node:fs";
|
|
2
|
+
import { readFile } from "node:fs/promises";
|
|
3
|
+
import path from "node:path";
|
|
4
|
+
import { mcpServerFile } from "@ocean/market/adapters/mcp-adapter.js";
|
|
1
5
|
import { createDefaultMarketplace, marketplacePaths, } from "@ocean/market/install/default-marketplace.js";
|
|
6
|
+
import { addOwnMcpServer } from "@ocean/market/install/own-server.js";
|
|
7
|
+
import { sensitivityOf } from "@ocean/market/mcp/mcp-gateway.js";
|
|
8
|
+
import { launchInputs, } from "@ocean/market/mcp/mcp-launch.js";
|
|
2
9
|
import { runInstalledMcp } from "@ocean/market/mcp/mcp-runner.js";
|
|
3
|
-
|
|
10
|
+
import { fetchRegistryServer, searchRegistry, } from "@ocean/market/registry/official-registry.js";
|
|
11
|
+
import { keychainStore } from "@ocean/market/security/secrets.js";
|
|
12
|
+
import { oceanVersion } from "../../version.js";
|
|
13
|
+
const usage = "Usage: ocean market list|search <term>|add <server.json|registry name> [--version <v>]|install <name> [--version <v>]|update <name>|uninstall <name>|exec <name>|secret list|set|remove <name> [<value name>] [--index <file>]... [--yes] [--accept-flagged]";
|
|
14
|
+
function installedServer(name) {
|
|
15
|
+
try {
|
|
16
|
+
return JSON.parse(readFileSync(mcpServerFile(marketplacePaths().mcpServers, name), "utf8"));
|
|
17
|
+
}
|
|
18
|
+
catch {
|
|
19
|
+
throw new Error(`${name} is not an installed MCP server`);
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
// What each value an installed server needs is set from, never the value itself.
|
|
23
|
+
function inputStates(name) {
|
|
24
|
+
const installed = installedServer(name);
|
|
25
|
+
const store = keychainStore();
|
|
26
|
+
return launchInputs(installed.server).map((input) => ({
|
|
27
|
+
...input,
|
|
28
|
+
from: process.env[input.name] !== undefined
|
|
29
|
+
? "environment"
|
|
30
|
+
: store.get(installed.capability, input.name) !== undefined
|
|
31
|
+
? store.name
|
|
32
|
+
: "missing",
|
|
33
|
+
}));
|
|
34
|
+
}
|
|
35
|
+
// A server the gateway hides by default says so at install, with the command that shows it.
|
|
36
|
+
function printVisibility(name) {
|
|
37
|
+
let installed;
|
|
38
|
+
try {
|
|
39
|
+
installed = installedServer(name);
|
|
40
|
+
}
|
|
41
|
+
catch {
|
|
42
|
+
return;
|
|
43
|
+
}
|
|
44
|
+
const reason = sensitivityOf(installed);
|
|
45
|
+
if (reason)
|
|
46
|
+
console.error(`${name} ${reason}, so gateway-wired clients do not see it until allowed: ocean clients allow <client> ${name}`);
|
|
47
|
+
}
|
|
48
|
+
// After an add: which values still have to be set before the server starts, and how.
|
|
49
|
+
function printInputs(name) {
|
|
50
|
+
for (const input of inputStates(name))
|
|
51
|
+
if (input.from === "missing")
|
|
52
|
+
console.error(`${name} ${input.required ? "needs" : "can take"} ${input.name}${input.description ? ` (${input.description})` : ""}: ocean market secret set ${name} ${input.name}`);
|
|
53
|
+
}
|
|
54
|
+
async function readStdin() {
|
|
55
|
+
if (process.stdin.isTTY)
|
|
56
|
+
console.error("Paste the value, then press Enter and Ctrl-D:");
|
|
57
|
+
let text = "";
|
|
58
|
+
process.stdin.setEncoding("utf8");
|
|
59
|
+
for await (const chunk of process.stdin)
|
|
60
|
+
text += chunk;
|
|
61
|
+
return text.replace(/\r?\n$/, "");
|
|
62
|
+
}
|
|
63
|
+
// `ocean market secret list|set|remove <name> [<value name>]`: the value is read from stdin, so
|
|
64
|
+
// it never appears in shell history or a process list, and is never printed.
|
|
65
|
+
async function runSecretCommand(args) {
|
|
66
|
+
const [verb, name, input] = args.filter((arg) => !arg.startsWith("--"));
|
|
67
|
+
if (!name || !["list", "set", "remove"].includes(verb))
|
|
68
|
+
throw new Error("Usage: ocean market secret list <name> | set <name> <value name> | remove <name> <value name>");
|
|
69
|
+
if (verb === "list") {
|
|
70
|
+
console.log(JSON.stringify(inputStates(name), null, 2));
|
|
71
|
+
return;
|
|
72
|
+
}
|
|
73
|
+
const installed = installedServer(name);
|
|
74
|
+
const known = launchInputs(installed.server).map((each) => each.name);
|
|
75
|
+
if (!input || !known.includes(input))
|
|
76
|
+
throw new Error(`${name} takes ${known.length ? known.join(", ") : "no values"}`);
|
|
77
|
+
const store = keychainStore();
|
|
78
|
+
if (verb === "set") {
|
|
79
|
+
const value = await readStdin();
|
|
80
|
+
if (!value)
|
|
81
|
+
throw new Error("no value given on stdin");
|
|
82
|
+
store.set(installed.capability, input, value);
|
|
83
|
+
console.log(JSON.stringify({ name, set: input, in: store.name }));
|
|
84
|
+
}
|
|
85
|
+
else
|
|
86
|
+
console.log(JSON.stringify({
|
|
87
|
+
name,
|
|
88
|
+
removed: input,
|
|
89
|
+
found: store.remove(installed.capability, input),
|
|
90
|
+
}));
|
|
91
|
+
}
|
|
4
92
|
function flagValues(args, flag) {
|
|
5
93
|
return args.flatMap((arg, index) => arg === flag && args[index + 1] ? [args[index + 1]] : []);
|
|
6
94
|
}
|
|
7
95
|
export async function runMarketCommand(action, args) {
|
|
8
96
|
const approved = args.includes("--yes");
|
|
9
|
-
const
|
|
10
|
-
indexFiles
|
|
97
|
+
const createMarketplace = (indexFiles) => createDefaultMarketplace({
|
|
98
|
+
indexFiles,
|
|
11
99
|
acceptFlagged: args.includes("--accept-flagged"),
|
|
12
100
|
// Non-interactive: permissions are granted only by an explicit --yes, and are always shown.
|
|
13
101
|
consent: async (manifest) => {
|
|
@@ -17,6 +105,7 @@ export async function runMarketCommand(action, args) {
|
|
|
17
105
|
return approved;
|
|
18
106
|
},
|
|
19
107
|
});
|
|
108
|
+
const marketplace = createMarketplace(flagValues(args, "--index"));
|
|
20
109
|
const name = args.find((arg, index) => !arg.startsWith("--") &&
|
|
21
110
|
!["--index", "--version"].includes(args[index - 1]));
|
|
22
111
|
if (action === "list") {
|
|
@@ -30,6 +119,51 @@ export async function runMarketCommand(action, args) {
|
|
|
30
119
|
})), null, 2));
|
|
31
120
|
return;
|
|
32
121
|
}
|
|
122
|
+
if (action === "search" && name) {
|
|
123
|
+
const hits = await searchRegistry(args.filter((arg) => !arg.startsWith("--")).join(" "));
|
|
124
|
+
if (args.includes("--json"))
|
|
125
|
+
console.log(JSON.stringify(hits, null, 2));
|
|
126
|
+
else if (!hits.length)
|
|
127
|
+
console.log("No server in the MCP registry matches.");
|
|
128
|
+
else
|
|
129
|
+
for (const hit of hits)
|
|
130
|
+
console.log(`${hit.name}@${hit.version} [${hit.runs}${hit.status === "active" ? "" : `, ${hit.status}`}${hit.needs.length ? `, needs ${hit.needs.join(", ")}` : ""}]\n ${hit.description}`);
|
|
131
|
+
return;
|
|
132
|
+
}
|
|
133
|
+
if (action === "add" && name) {
|
|
134
|
+
// A path to a server.json, or a name in the MCP registry.
|
|
135
|
+
const file = path.resolve(name);
|
|
136
|
+
let server;
|
|
137
|
+
let from;
|
|
138
|
+
if (name.endsWith(".json") || existsSync(file)) {
|
|
139
|
+
server = JSON.parse(await readFile(file, "utf8"));
|
|
140
|
+
from = path.basename(file);
|
|
141
|
+
}
|
|
142
|
+
else {
|
|
143
|
+
const found = await fetchRegistryServer(name, {
|
|
144
|
+
version: flagValues(args, "--version")[0],
|
|
145
|
+
});
|
|
146
|
+
if (found.status !== "active")
|
|
147
|
+
console.error(`${name} is ${found.status} in the MCP registry.`);
|
|
148
|
+
server = found.server;
|
|
149
|
+
from = "the MCP registry";
|
|
150
|
+
}
|
|
151
|
+
const result = await addOwnMcpServer({
|
|
152
|
+
server,
|
|
153
|
+
from,
|
|
154
|
+
indexFile: marketplacePaths().index,
|
|
155
|
+
oceanVersion: await oceanVersion(),
|
|
156
|
+
marketplace: () => createMarketplace([]),
|
|
157
|
+
});
|
|
158
|
+
console.log(JSON.stringify(result, null, 2));
|
|
159
|
+
printInputs(result.name);
|
|
160
|
+
printVisibility(result.name);
|
|
161
|
+
return;
|
|
162
|
+
}
|
|
163
|
+
if (action === "secret") {
|
|
164
|
+
await runSecretCommand(args);
|
|
165
|
+
return;
|
|
166
|
+
}
|
|
33
167
|
if (action === "exec" && name) {
|
|
34
168
|
const paths = marketplacePaths();
|
|
35
169
|
process.exitCode = await runInstalledMcp(name, {
|
|
@@ -40,8 +174,11 @@ export async function runMarketCommand(action, args) {
|
|
|
40
174
|
}
|
|
41
175
|
if (!name || !["install", "update", "uninstall"].includes(action))
|
|
42
176
|
throw new Error(usage);
|
|
43
|
-
if (action === "install")
|
|
44
|
-
|
|
177
|
+
if (action === "install") {
|
|
178
|
+
const result = await marketplace.install(name, flagValues(args, "--version")[0]);
|
|
179
|
+
console.log(JSON.stringify(result, null, 2));
|
|
180
|
+
printVisibility(result.name);
|
|
181
|
+
}
|
|
45
182
|
else if (action === "update")
|
|
46
183
|
console.log(JSON.stringify(await marketplace.update(name), null, 2));
|
|
47
184
|
else {
|
|
@@ -1,29 +1,46 @@
|
|
|
1
1
|
import { marketplacePaths } from "@ocean/market/install/default-marketplace.js";
|
|
2
|
-
import { gatewayMembers, McpGateway, serveMcpGateway, } from "@ocean/market/mcp/mcp-gateway.js";
|
|
2
|
+
import { gatewayMembers, McpGateway, readGatewayAccess, serveMcpGateway, } from "@ocean/market/mcp/mcp-gateway.js";
|
|
3
|
+
import { keychainStore } from "@ocean/market/security/secrets.js";
|
|
3
4
|
import { McpClient } from "@ocean/services/infrastructure/mcp/mcp-client.js";
|
|
5
|
+
import { RemoteMcpClient } from "../../infrastructure/mcp/remote-mcp-client.js";
|
|
4
6
|
import { oceanVersion } from "../../version.js";
|
|
7
|
+
// How the gateway (and `ocean mcp status --check`) talks to one member.
|
|
8
|
+
export function gatewayClientFor(member, version, stderrLabel = `ocean mcp gateway [${member.capability}]`) {
|
|
9
|
+
return member.transport === "remote"
|
|
10
|
+
? new RemoteMcpClient(member, version)
|
|
11
|
+
: new McpClient({
|
|
12
|
+
command: member.command,
|
|
13
|
+
args: member.args,
|
|
14
|
+
cwd: member.cwd,
|
|
15
|
+
env: member.env,
|
|
16
|
+
inheritEnv: member.inheritEnv,
|
|
17
|
+
stderrLabel,
|
|
18
|
+
});
|
|
19
|
+
}
|
|
5
20
|
// `ocean mcp gateway`: one stdio MCP endpoint for every registered server. Logs go to stderr,
|
|
6
21
|
// which MCP clients keep as the server's log.
|
|
7
|
-
|
|
22
|
+
// `--installed-only`: leave out Ocean's own servers, for a client wired to them directly.
|
|
23
|
+
// `--client <id>`: the client this process serves, for the access rules.
|
|
24
|
+
export async function runMcpGatewayCommand(args = []) {
|
|
8
25
|
const log = (line) => console.error(`ocean mcp gateway: ${line}`);
|
|
9
26
|
const paths = marketplacePaths();
|
|
10
27
|
const { members, skipped } = await gatewayMembers({
|
|
11
28
|
serversRoot: paths.mcpServers,
|
|
12
29
|
stateRoot: paths.mcpState,
|
|
30
|
+
firstParty: !args.includes("--installed-only"),
|
|
31
|
+
secrets: keychainStore(),
|
|
13
32
|
});
|
|
14
33
|
for (const skip of skipped)
|
|
15
34
|
log(`${skip.capability} not routed: ${skip.reason}`);
|
|
35
|
+
const version = await oceanVersion();
|
|
16
36
|
const gateway = new McpGateway(members, {
|
|
17
|
-
client: (member) =>
|
|
18
|
-
|
|
19
|
-
args: member.args,
|
|
20
|
-
cwd: member.cwd,
|
|
21
|
-
env: member.env,
|
|
22
|
-
inheritEnv: member.inheritEnv,
|
|
23
|
-
stderrLabel: `ocean mcp gateway [${member.capability}]`,
|
|
24
|
-
}),
|
|
25
|
-
version: await oceanVersion(),
|
|
37
|
+
client: (member) => gatewayClientFor(member, version),
|
|
38
|
+
version,
|
|
26
39
|
log,
|
|
40
|
+
access: await readGatewayAccess(paths.gatewayAccess),
|
|
41
|
+
clientId: args.includes("--client")
|
|
42
|
+
? args[args.indexOf("--client") + 1]
|
|
43
|
+
: undefined,
|
|
27
44
|
});
|
|
28
45
|
await serveMcpGateway(gateway);
|
|
29
46
|
}
|