@kabmo-labs/kabmo 0.30.0 → 0.31.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/README.md +79 -21
- package/dist/client/index.html +1 -1
- package/dist/client/index.js +481 -462
- package/dist/client/static/js/{index-5vjbp04s.js → index-r3bhgvkt.js} +882 -883
- package/marketplace/plugins/stats/package.json +2 -2
- package/marketplace/plugins/stats/src/format.test.ts +7 -1
- package/package.json +2 -2
- package/src/client/components/common/context-usage-button/McpSection.tsx +133 -0
- package/src/client/components/common/context-usage-button/Ring.tsx +12 -6
- package/src/client/components/common/context-usage-button/index.test.tsx +24 -13
- package/src/client/components/common/context-usage-button/index.tsx +32 -34
- package/src/client/components/common/session-row/TrailingSlot.tsx +6 -2
- package/src/client/components/common/session-row/session-row.test.tsx +13 -0
- package/src/client/components/layout/desktop-layout/index.tsx +5 -1
- package/src/client/components/mobile/RightSidebar.tsx +2 -1
- package/src/client/components/settings/categories/McpSettings.tsx +10 -3
- package/src/client/components/settings/categories/mcp-settings/AdvancedSection.tsx +244 -0
- package/src/client/components/settings/categories/mcp-settings/ConnectionTest.tsx +3 -3
- package/src/client/components/settings/categories/mcp-settings/DetailPane.tsx +55 -97
- package/src/client/components/settings/categories/mcp-settings/ImportModal.tsx +12 -64
- package/src/client/components/settings/categories/mcp-settings/{EnvVarsSection.tsx → KeyValueSection.tsx} +42 -24
- package/src/client/components/settings/categories/mcp-settings/SidebarList.tsx +1 -1
- package/src/client/components/settings/categories/mcp-settings/TransportSection.tsx +101 -0
- package/src/client/components/workspace/browser-panel/EngineNotice.test.tsx +109 -0
- package/src/client/components/workspace/browser-panel/EngineNotice.tsx +112 -0
- package/src/client/components/workspace/browser-panel/index.tsx +45 -12
- package/src/client/components/workspace/chat-timeline/chat-input/AccessDropdown.test.ts +63 -0
- package/src/client/components/workspace/chat-timeline/chat-input/AccessDropdown.tsx +18 -6
- package/src/client/components/workspace/chat-timeline/chat-input/Toolbar.tsx +3 -1
- package/src/client/components/workspace/chat-timeline/chat-input/access-levels.ts +39 -1
- package/src/client/components/workspace/chat-timeline/tool-renderers/panels/Eval.test.tsx +13 -7
- package/src/client/components/workspace/editor/plugin-rail.test.tsx +6 -1
- package/src/client/components/workspace/terminal-panel/scroll-hold.test.ts +20 -5
- package/src/client/data/settings/mcp.ts +4 -2
- package/src/client/data/settings/omp-schema.json +22 -2
- package/src/client/hooks/browser/use-browser-engine.ts +99 -0
- package/src/client/hooks/chat/context/mcp.ts +159 -0
- package/src/client/hooks/chat/timeline/access-mode.ts +45 -15
- package/src/client/hooks/chat/timeline/index.ts +7 -3
- package/src/client/hooks/chat/timeline/timeline-mode-state.test.ts +33 -4
- package/src/client/hooks/ui/ui-listeners.test.ts +13 -18
- package/src/server/lib/browser/engine.test.ts +118 -0
- package/src/server/lib/browser/engine.ts +102 -0
- package/src/server/lib/db/schema.ts +4 -0
- package/src/server/lib/fs/toolchain-path.test.ts +87 -0
- package/src/server/lib/fs/toolchain-path.ts +49 -0
- package/src/server/lib/harness/acp/protocol.ts +9 -1
- package/src/server/lib/harness/auto-probe.server.ts +3 -2
- package/src/server/lib/harness/launch-table.ts +3 -2
- package/src/server/lib/harness/spawn.server.ts +5 -1
- package/src/server/lib/harness/update-queue.server.ts +2 -1
- package/src/server/lib/harness/update-state.server.ts +6 -2
- package/src/server/lib/mcp/probe.server.ts +71 -0
- package/src/server/lib/mcp/registry.server.ts +195 -46
- package/src/server/lib/mcp/registry.test.ts +76 -4
- package/src/server/lib/mcp/schema.server.ts +35 -0
- package/src/server/lib/mcp/session-mcp.test.ts +164 -0
- package/src/server/lib/mcp/session-overlay.server.ts +152 -0
- package/src/server/lib/mcp/session-state.server.ts +75 -0
- package/src/server/lib/mcp/store.server.ts +6 -1
- package/src/server/lib/omp/config/config-cli.ts +4 -0
- package/src/server/lib/omp/config/mcp-and-cli.test.ts +12 -183
- package/src/server/lib/omp/config/mcp-config.test.ts +277 -0
- package/src/server/lib/omp/config/mcp-shared.ts +36 -0
- package/src/server/lib/omp/config/mcp-test-protocol.ts +89 -0
- package/src/server/lib/omp/config/mcp-test-remote.ts +167 -0
- package/src/server/lib/omp/config/mcp-test.ts +21 -123
- package/src/server/lib/omp/config/mcp-write.ts +179 -0
- package/src/server/lib/omp/config/mcp.ts +138 -118
- package/src/server/lib/omp/core/cli.ts +4 -14
- package/src/server/lib/omp/rpc/manager.ts +12 -17
- package/src/server/lib/omp/rpc/reload-mcp.ts +39 -0
- package/src/server/lib/omp/rpc/session-registry.ts +6 -2
- package/src/server/lib/omp/rpc/spawn-mcp.ts +43 -0
- package/src/server/lib/omp/session/delete.server.ts +7 -0
- package/src/server/lib/plugins/mcp.server.ts +2 -2
- package/src/server/lib/realtime/topics/workspace.server.test.ts +44 -0
- package/src/server/lib/realtime/topics/workspace.server.ts +3 -2
- package/src/server/routes/browser/engine.test.ts +70 -0
- package/src/server/routes/browser/engine.ts +51 -0
- package/src/server/routes/browser/index.ts +5 -0
- package/src/server/routes/fs/git.ts +4 -3
- package/src/server/routes/harness/versions.test.ts +5 -0
- package/src/server/routes/sessions/index.ts +7 -0
- package/src/server/routes/sessions/mcp.test.ts +154 -0
- package/src/server/routes/sessions/mcp.ts +202 -0
- package/src/server/routes/settings/mcp-test.ts +5 -4
- package/src/server/routes/settings/mcp.test.ts +42 -1
- package/src/server/routes/settings/mcp.ts +80 -24
- package/src/shared/lib/code/highlight-memo.test.ts +18 -0
- package/src/shared/lib/code/highlight-memo.ts +46 -17
- package/src/shared/lib/fonts/nerd-symbols.css +14 -0
- package/src/shared/lib/fonts/nerd-symbols.test.ts +86 -0
- package/src/shared/lib/fonts/symbols-nerd-font-mono.woff2 +0 -0
- package/src/shared/lib/mcp/import.ts +112 -0
- package/src/shared/lib/mcp/item.ts +61 -0
- package/src/shared/lib/mcp/key-value.ts +37 -0
- package/src/shared/lib/mcp/mcp-lib.test.ts +119 -0
- package/src/shared/lib/mcp/status.test.ts +36 -0
- package/src/shared/lib/mcp/status.ts +38 -0
- package/src/shared/lib/models/client.ts +27 -6
- package/src/shared/lib/models/provider/models.test.ts +31 -0
- package/src/shared/lib/omp/config/access-mode.test.ts +73 -0
- package/src/shared/lib/omp/config/access-mode.ts +49 -0
- package/src/shared/lib/workspace/right-panels.ts +13 -0
- package/src/shared/lib/workspace/workspace-modules.test.ts +3 -1
- package/src/shared/types/browser.ts +21 -0
- package/src/shared/types/settings/mcp.ts +73 -4
- package/src/test-support/pristine-globals.test.ts +53 -0
- package/src/test-support/pristine-globals.ts +6 -1
|
@@ -0,0 +1,152 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* SPDX-License-Identifier: MIT
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* A per-session agent directory for omp's RPC mode, so one session's MCP list
|
|
8
|
+
* can differ from every other session's.
|
|
9
|
+
*
|
|
10
|
+
* ## Why a directory
|
|
11
|
+
*
|
|
12
|
+
* `omp --mode rpc-ui` reads `mcp.json` from its agent dir ONCE at spawn and has
|
|
13
|
+
* no RPC verb to add or remove a server. The only switch that changes which
|
|
14
|
+
* file it reads is `PI_CODING_AGENT_DIR` — the same lever `utility-agent-dir.ts`
|
|
15
|
+
* uses to spawn an MCP-free child. Measured on 18.20.0: a child pointed at an
|
|
16
|
+
* overlay dir connected the server written there and ignored the real
|
|
17
|
+
* `mcp.json`; `/mcp reload` re-read the overlay, so a toggle applies live.
|
|
18
|
+
*
|
|
19
|
+
* ## What the overlay contains
|
|
20
|
+
*
|
|
21
|
+
* Every entry of the real agent dir is SYMLINKED, so auth, models, sessions,
|
|
22
|
+
* skills, extensions and the databases stay the one real copy — a session must
|
|
23
|
+
* not fork its transcript or its credentials. The two MCP files are the
|
|
24
|
+
* exception: `mcp.json` is written from the merged list (all sources, with this
|
|
25
|
+
* session's enablement), and `.mcp.json` is not linked at all, because omp
|
|
26
|
+
* unions both user files and a linked secondary would resurrect a server this
|
|
27
|
+
* session disabled.
|
|
28
|
+
*
|
|
29
|
+
* Project config is switched off for the child with a `--config` overlay
|
|
30
|
+
* (`mcp.enableProjectConfig: false`), because the project's own `mcp.json` is
|
|
31
|
+
* read from the cwd and would otherwise add back a server the session disabled.
|
|
32
|
+
* Measured on 18.20.0: with the overlay, a project server's command never ran;
|
|
33
|
+
* without it, it did.
|
|
34
|
+
*
|
|
35
|
+
* ## Failure posture
|
|
36
|
+
*
|
|
37
|
+
* An overlay that cannot be built returns `undefined`, and the caller spawns
|
|
38
|
+
* against the real agent dir: a session that starts with the configured list is
|
|
39
|
+
* better than a chat that cannot start. The overlay is rebuilt on every spawn,
|
|
40
|
+
* so a stale directory can never leak a previous list.
|
|
41
|
+
*/
|
|
42
|
+
|
|
43
|
+
import fs from 'fs';
|
|
44
|
+
import path from 'path';
|
|
45
|
+
import { tmpdir } from 'os';
|
|
46
|
+
|
|
47
|
+
import { getAgentDir } from '@/server/lib/omp/core/paths';
|
|
48
|
+
import { mcpServerEntriesFor } from '@/server/lib/mcp/registry.server';
|
|
49
|
+
import type { SessionMcpOverrides } from '@/server/lib/mcp/session-state.server';
|
|
50
|
+
|
|
51
|
+
/** The two files the overlay owns; everything else is a symlink. */
|
|
52
|
+
const OWNED_FILES: Record<string, true> = { 'mcp.json': true, '.mcp.json': true };
|
|
53
|
+
|
|
54
|
+
/** The `--config` overlay that keeps the project's own MCP file out of the child. */
|
|
55
|
+
const CONFIG_OVERLAY = 'kabmo-mcp.yml';
|
|
56
|
+
|
|
57
|
+
const OVERLAY_ROOT = 'kabmo-omp-session-mcp';
|
|
58
|
+
|
|
59
|
+
export interface SessionMcpOverlay {
|
|
60
|
+
/** `PI_CODING_AGENT_DIR` for the child. */
|
|
61
|
+
dir: string;
|
|
62
|
+
/** The `--config` overlay path. */
|
|
63
|
+
configPath: string;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
/** The overlay directory for one session. Deterministic, so a respawn reuses it. */
|
|
67
|
+
export function sessionMcpOverlayDir(sessionId: string): string {
|
|
68
|
+
const safe = sessionId.replace(/[^A-Za-z0-9._-]/g, '_');
|
|
69
|
+
return path.join(tmpdir(), OVERLAY_ROOT, safe);
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
/**
|
|
73
|
+
* Build (or rebuild) the overlay for a session and return it, or `undefined`
|
|
74
|
+
* when the session has no overrides or the real agent dir cannot be read.
|
|
75
|
+
*
|
|
76
|
+
* A session with no overrides gets NO overlay: it reads the real `mcp.json`,
|
|
77
|
+
* which is exactly the configured list, and pays no directory.
|
|
78
|
+
*/
|
|
79
|
+
export async function ensureSessionMcpOverlay(
|
|
80
|
+
sessionId: string,
|
|
81
|
+
cwd: string,
|
|
82
|
+
overrides: SessionMcpOverrides,
|
|
83
|
+
options: { keep?: boolean } = {},
|
|
84
|
+
): Promise<SessionMcpOverlay | undefined> {
|
|
85
|
+
if (Object.keys(overrides).length === 0 && !options.keep) {
|
|
86
|
+
await removeSessionMcpOverlay(sessionId);
|
|
87
|
+
return undefined;
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
const real = getAgentDir();
|
|
91
|
+
let entries: fs.Dirent[];
|
|
92
|
+
try {
|
|
93
|
+
entries = await fs.promises.readdir(real, { withFileTypes: true });
|
|
94
|
+
} catch {
|
|
95
|
+
return undefined;
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
const dir = sessionMcpOverlayDir(sessionId);
|
|
99
|
+
// A misconfigured `PI_CODING_AGENT_DIR` that points at the overlay root would
|
|
100
|
+
// make the rebuild delete the real agent dir. Refuse rather than risk it.
|
|
101
|
+
if (path.resolve(real) === path.resolve(dir)) return undefined;
|
|
102
|
+
try {
|
|
103
|
+
await fs.promises.rm(dir, { recursive: true, force: true });
|
|
104
|
+
await fs.promises.mkdir(dir, { recursive: true });
|
|
105
|
+
for (const entry of entries) {
|
|
106
|
+
if (OWNED_FILES[entry.name]) continue;
|
|
107
|
+
try {
|
|
108
|
+
await fs.promises.symlink(path.join(real, entry.name), path.join(dir, entry.name));
|
|
109
|
+
} catch {
|
|
110
|
+
// One unlinkable entry must not cost the whole overlay: the child still
|
|
111
|
+
// boots, it just sees one fewer file.
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
const servers = await mcpServerEntriesFor(cwd, {
|
|
116
|
+
overrides,
|
|
117
|
+
// Only the sources omp's RPC mode can actually read: its own `mcp.json`
|
|
118
|
+
// files. App-local rows and plugin contributions are ACP-only today, and
|
|
119
|
+
// materializing them here would silently change that delivery.
|
|
120
|
+
sources: ['user', 'project'],
|
|
121
|
+
});
|
|
122
|
+
const mcpServers: Record<string, unknown> = {};
|
|
123
|
+
for (const server of servers) {
|
|
124
|
+
const config = { ...server.config };
|
|
125
|
+
// Written explicitly in BOTH directions: a disabled entry must stay in
|
|
126
|
+
// the file so `/mcp enable <name>` can find it, and an enabled one must
|
|
127
|
+
// not inherit a stale `enabled: false` from the real config.
|
|
128
|
+
if (server.enabled) delete config.enabled;
|
|
129
|
+
else config.enabled = false;
|
|
130
|
+
mcpServers[server.name] = config;
|
|
131
|
+
}
|
|
132
|
+
await fs.promises.writeFile(
|
|
133
|
+
path.join(dir, 'mcp.json'),
|
|
134
|
+
`${JSON.stringify({ mcpServers }, null, 2)}\n`,
|
|
135
|
+
);
|
|
136
|
+
const configPath = path.join(dir, CONFIG_OVERLAY);
|
|
137
|
+
await fs.promises.writeFile(configPath, 'mcp:\n enableProjectConfig: false\n');
|
|
138
|
+
return { dir, configPath };
|
|
139
|
+
} catch {
|
|
140
|
+
await removeSessionMcpOverlay(sessionId);
|
|
141
|
+
return undefined;
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
/** Drop a session's overlay. Safe when there is none. */
|
|
146
|
+
export async function removeSessionMcpOverlay(sessionId: string): Promise<void> {
|
|
147
|
+
try {
|
|
148
|
+
await fs.promises.rm(sessionMcpOverlayDir(sessionId), { recursive: true, force: true });
|
|
149
|
+
} catch {
|
|
150
|
+
// A directory still in use by a live child: the next spawn rebuilds it.
|
|
151
|
+
}
|
|
152
|
+
}
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* SPDX-License-Identifier: MIT
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* The per-session MCP overrides: which servers this session turned on or off
|
|
8
|
+
* against the configured list.
|
|
9
|
+
*
|
|
10
|
+
* A map rather than a disabled list, because both directions are real: a server
|
|
11
|
+
* disabled in `mcp.json` can be enabled for one session, and an enabled one can
|
|
12
|
+
* be disabled for it. Storing only the disabled names would make "enable a
|
|
13
|
+
* globally disabled server" impossible to express.
|
|
14
|
+
*
|
|
15
|
+
* Only names that DIFFER from the configured state are stored. A settings edit
|
|
16
|
+
* therefore still reaches a session that never touched that server, and a
|
|
17
|
+
* toggle back to the configured value removes the row entry instead of pinning
|
|
18
|
+
* the old answer forever.
|
|
19
|
+
*/
|
|
20
|
+
|
|
21
|
+
import { getDb } from '@/server/db.server';
|
|
22
|
+
import { isRecord } from '@/shared/lib/util/guards';
|
|
23
|
+
|
|
24
|
+
export type SessionMcpOverrides = Record<string, boolean>;
|
|
25
|
+
|
|
26
|
+
/** The overrides recorded for one session; `{}` when it never toggled. */
|
|
27
|
+
export async function readSessionMcpOverrides(sessionId: string): Promise<SessionMcpOverrides> {
|
|
28
|
+
if (!sessionId) return {};
|
|
29
|
+
const db = await getDb();
|
|
30
|
+
const row = await db.get<{ overrides: string }>(
|
|
31
|
+
'SELECT overrides FROM session_mcp_state WHERE session_id = ?',
|
|
32
|
+
[sessionId],
|
|
33
|
+
);
|
|
34
|
+
if (!row?.overrides) return {};
|
|
35
|
+
try {
|
|
36
|
+
const parsed: unknown = JSON.parse(row.overrides);
|
|
37
|
+
if (!isRecord(parsed)) return {};
|
|
38
|
+
const overrides: SessionMcpOverrides = {};
|
|
39
|
+
for (const [name, value] of Object.entries(parsed)) {
|
|
40
|
+
if (typeof value === 'boolean') overrides[name] = value;
|
|
41
|
+
}
|
|
42
|
+
return overrides;
|
|
43
|
+
} catch {
|
|
44
|
+
// A corrupt blob is an empty override, not a failed spawn: the session
|
|
45
|
+
// still starts with the configured list.
|
|
46
|
+
return {};
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
/** Replace the overrides for one session. An empty map deletes the row. */
|
|
51
|
+
export async function writeSessionMcpOverrides(
|
|
52
|
+
sessionId: string,
|
|
53
|
+
overrides: SessionMcpOverrides,
|
|
54
|
+
): Promise<void> {
|
|
55
|
+
if (!sessionId) return;
|
|
56
|
+
const db = await getDb();
|
|
57
|
+
const names = Object.keys(overrides);
|
|
58
|
+
if (names.length === 0) {
|
|
59
|
+
await db.run('DELETE FROM session_mcp_state WHERE session_id = ?', [sessionId]);
|
|
60
|
+
return;
|
|
61
|
+
}
|
|
62
|
+
await db.run(
|
|
63
|
+
`INSERT INTO session_mcp_state (session_id, overrides, updated_at)
|
|
64
|
+
VALUES (?, ?, CURRENT_TIMESTAMP)
|
|
65
|
+
ON CONFLICT(session_id) DO UPDATE SET overrides = excluded.overrides, updated_at = CURRENT_TIMESTAMP`,
|
|
66
|
+
[sessionId, JSON.stringify(overrides)],
|
|
67
|
+
);
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
/** Drop the row for a session that is being deleted. */
|
|
71
|
+
export async function clearSessionMcpOverrides(sessionId: string): Promise<void> {
|
|
72
|
+
if (!sessionId) return;
|
|
73
|
+
const db = await getDb();
|
|
74
|
+
await db.run('DELETE FROM session_mcp_state WHERE session_id = ?', [sessionId]);
|
|
75
|
+
}
|
|
@@ -15,6 +15,7 @@
|
|
|
15
15
|
import { DEFAULT_MCP_SERVERS } from '@/client/data/settings/mcp';
|
|
16
16
|
import { createSettingsListStore } from '@/server/lib/db/settings-store';
|
|
17
17
|
import { isMockMode } from '@/server/mock.server';
|
|
18
|
+
import { normalizeMcpItem } from '@/shared/lib/mcp/item';
|
|
18
19
|
import type { DbClient } from '@/server/lib/db/client';
|
|
19
20
|
import type { McpServerItem } from '@/shared/types';
|
|
20
21
|
|
|
@@ -30,7 +31,11 @@ export const mcpStore = createSettingsListStore<McpServerItem>({
|
|
|
30
31
|
|
|
31
32
|
/** The app-local rows, with the mock default only in mock mode. */
|
|
32
33
|
export async function readCustomMcpServers(db: DbClient): Promise<McpServerItem[]> {
|
|
33
|
-
|
|
34
|
+
const stored = await mcpStore.readStored(db, { absent: isMockMode() ? DEFAULT_MCP_SERVERS : [] });
|
|
35
|
+
return stored.flatMap((row) => {
|
|
36
|
+
const item = normalizeMcpItem(row);
|
|
37
|
+
return item ? [item] : [];
|
|
38
|
+
});
|
|
34
39
|
}
|
|
35
40
|
|
|
36
41
|
export async function writeCustomMcpServers(db: DbClient, servers: McpServerItem[]): Promise<void> {
|
|
@@ -124,6 +124,10 @@ export async function getOmpConfigValue(key: string): Promise<unknown> {
|
|
|
124
124
|
if (!result.ok) throw new Error(configFailureLine(result) ?? `omp config get ${key} failed`);
|
|
125
125
|
const text = result.stdout.trim();
|
|
126
126
|
if (!text) return undefined;
|
|
127
|
+
// `omp config get` answers the human sentinel `(not set)` for a key with no
|
|
128
|
+
// value. It is not a value: a caller that treats it as one resolves a path
|
|
129
|
+
// named "(not set)" and reports the engine as missing.
|
|
130
|
+
if (text === '(not set)') return undefined;
|
|
127
131
|
try {
|
|
128
132
|
return JSON.parse(text);
|
|
129
133
|
} catch {
|
|
@@ -4,53 +4,29 @@
|
|
|
4
4
|
*/
|
|
5
5
|
|
|
6
6
|
/**
|
|
7
|
-
* MCP
|
|
8
|
-
*
|
|
7
|
+
* The MCP test-connection decision, the path-scoped setting resolver, and the
|
|
8
|
+
* two CLI bridges' pure parts.
|
|
9
9
|
*
|
|
10
10
|
* Pinned because each decides on untrusted or hand-written input:
|
|
11
|
-
* - `nativeToServerItem` maps a native entry to Kabmo shape; a wrong
|
|
12
|
-
* reach type or a dropped env var makes the UI test a server it cannot run.
|
|
13
|
-
* - `writeUserMcpServer` must preserve credentials the browser redacted, and
|
|
14
|
-
* must reject a name that could escape the file's own key grammar.
|
|
15
11
|
* - `testMcpServer` classifies an unusable configuration WITHOUT spawning
|
|
16
12
|
* anything, so the route answers with a useful error rather than a 500.
|
|
17
13
|
* - `resolvePathScopedSlugs` must not flatten per-project policy: an object
|
|
18
14
|
* entry applies only when its prefix contains the cwd.
|
|
15
|
+
* - `pluginCliError` is the sentence the settings pane shows for a refused CLI.
|
|
19
16
|
*/
|
|
20
17
|
|
|
21
18
|
import { afterAll, beforeEach, describe, expect, test } from 'bun:test';
|
|
22
|
-
import fs from 'fs';
|
|
23
|
-
import { tmpdir } from 'os';
|
|
24
|
-
import { join } from 'path';
|
|
25
19
|
|
|
26
|
-
import {
|
|
27
|
-
MCP_FILENAMES,
|
|
28
|
-
deleteUserMcpServer,
|
|
29
|
-
nativeToServerItem,
|
|
30
|
-
readProjectMcpConfig,
|
|
31
|
-
readUserMcpConfig,
|
|
32
|
-
redactEnvVars,
|
|
33
|
-
resolveProjectMcpConfig,
|
|
34
|
-
writeUserMcpServer,
|
|
35
|
-
} from '@/server/lib/omp/config/mcp';
|
|
36
20
|
import { testMcpServer } from '@/server/lib/omp/config/mcp-test';
|
|
37
21
|
import { isPathScopedEntry, pathScopedEntryValues, resolvePathScopedSlugs } from '@/server/lib/omp/config/path-scoped';
|
|
38
22
|
import { pluginCliError } from '@/server/lib/omp/config/plugin-cli';
|
|
39
23
|
import { getOmpConfigValue, listOmpConfig, resetOmpConfigKey, setOmpConfigValue } from '@/server/lib/omp/config/config-cli';
|
|
40
24
|
|
|
41
|
-
const roots: string[] = [];
|
|
42
25
|
const originalMock = Bun.env.MOCK;
|
|
43
26
|
|
|
44
|
-
|
|
45
|
-
const dir = await fs.promises.mkdtemp(join(tmpdir(), 'omp-mcp-'));
|
|
46
|
-
roots.push(dir);
|
|
47
|
-
return dir;
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
afterAll(async () => {
|
|
27
|
+
afterAll(() => {
|
|
51
28
|
if (originalMock === undefined) delete Bun.env.MOCK;
|
|
52
29
|
else Bun.env.MOCK = originalMock;
|
|
53
|
-
for (const root of roots) await fs.promises.rm(root, { recursive: true, force: true });
|
|
54
30
|
});
|
|
55
31
|
|
|
56
32
|
beforeEach(() => {
|
|
@@ -59,161 +35,14 @@ beforeEach(() => {
|
|
|
59
35
|
Bun.env.MOCK = 'false';
|
|
60
36
|
});
|
|
61
37
|
|
|
62
|
-
describe('nativeToServerItem', () => {
|
|
63
|
-
test('a command server becomes a command item with split args', () => {
|
|
64
|
-
const item = nativeToServerItem('fs', { command: 'npx', args: ['-y', '@mcp/fs'] }, 2, true);
|
|
65
|
-
expect(item).toEqual({
|
|
66
|
-
id: 'omp-user-fs',
|
|
67
|
-
name: 'fs',
|
|
68
|
-
scope: 'every-project',
|
|
69
|
-
enabled: true,
|
|
70
|
-
reachType: 'command',
|
|
71
|
-
commandArgs: ['npx', '-y', '@mcp/fs'],
|
|
72
|
-
linkUrl: undefined,
|
|
73
|
-
envVars: [],
|
|
74
|
-
status: undefined,
|
|
75
|
-
});
|
|
76
|
-
});
|
|
77
|
-
|
|
78
|
-
test('a url server becomes a link item and its env vars are stringified', () => {
|
|
79
|
-
const item = nativeToServerItem('web', { url: 'https://mcp.example/sse', env: { A: 1, B: 'two' } }, 0, false);
|
|
80
|
-
expect(item.reachType).toBe('link');
|
|
81
|
-
expect(item.linkUrl).toBe('https://mcp.example/sse');
|
|
82
|
-
expect(item.commandArgs).toEqual(['https://mcp.example/sse']);
|
|
83
|
-
expect(item.envVars).toEqual([
|
|
84
|
-
{ id: 'env-0-0', key: 'A', value: '1' },
|
|
85
|
-
{ id: 'env-0-1', key: 'B', value: 'two' },
|
|
86
|
-
]);
|
|
87
|
-
});
|
|
88
|
-
|
|
89
|
-
test('a project-scoped item carries the project id and path', () => {
|
|
90
|
-
const item = nativeToServerItem('fs', { command: 'x' }, 1, true, { path: '/proj' });
|
|
91
|
-
expect(item.id).toBe('omp-project-fs');
|
|
92
|
-
expect(item.scope).toBe('this-project');
|
|
93
|
-
expect(item.projectPath).toBe('/proj');
|
|
94
|
-
});
|
|
95
|
-
|
|
96
|
-
test('an empty command yields no args rather than a blank entry', () => {
|
|
97
|
-
expect(nativeToServerItem('blank', {}, 0, true).commandArgs).toEqual([]);
|
|
98
|
-
});
|
|
99
|
-
});
|
|
100
|
-
|
|
101
|
-
describe('redactEnvVars', () => {
|
|
102
|
-
test('values whose key looks sensitive are masked; others are untouched', () => {
|
|
103
|
-
const vars = [
|
|
104
|
-
{ key: 'API_KEY', value: 'sk-secret' },
|
|
105
|
-
{ key: 'authToken', value: 'tok' },
|
|
106
|
-
{ key: 'db_password', value: 'pw' },
|
|
107
|
-
{ key: 'PLAIN', value: 'visible' },
|
|
108
|
-
];
|
|
109
|
-
const out = redactEnvVars(vars);
|
|
110
|
-
expect(out.map((v) => v.value)).toEqual(['••••••••', '••••••••', '••••••••', 'visible']);
|
|
111
|
-
// Non-sensitive rows keep their identity (no needless copies).
|
|
112
|
-
expect(out[3]).toBe(vars[3]);
|
|
113
|
-
});
|
|
114
|
-
});
|
|
115
|
-
|
|
116
|
-
describe('mcp file read/write', () => {
|
|
117
|
-
test('readUserMcpConfig on a missing file is empty and does not throw', async () => {
|
|
118
|
-
const path = join(await tempDir(), 'mcp.json');
|
|
119
|
-
expect(await readUserMcpConfig(path)).toEqual({ path, servers: [], disabledServers: [] });
|
|
120
|
-
});
|
|
121
|
-
|
|
122
|
-
test('readUserMcpConfig sorts servers by name and keeps only string disables', async () => {
|
|
123
|
-
const path = join(await tempDir(), 'mcp.json');
|
|
124
|
-
await Bun.write(path, JSON.stringify({
|
|
125
|
-
mcpServers: { zeta: { command: 'z' }, alpha: { url: 'https://a' } },
|
|
126
|
-
disabledServers: ['zeta', 7, null],
|
|
127
|
-
}));
|
|
128
|
-
const config = await readUserMcpConfig(path);
|
|
129
|
-
expect(config.servers.map((s) => s.name)).toEqual(['alpha', 'zeta']);
|
|
130
|
-
expect(config.disabledServers).toEqual(['zeta']);
|
|
131
|
-
});
|
|
132
|
-
|
|
133
|
-
test('readUserMcpConfig reports malformed content as an error field', async () => {
|
|
134
|
-
const path = join(await tempDir(), 'mcp.json');
|
|
135
|
-
await Bun.write(path, '[1,2,3]');
|
|
136
|
-
expect((await readUserMcpConfig(path)).error).toBe('configuration must contain a JSON object');
|
|
137
|
-
|
|
138
|
-
await Bun.write(path, '{"mcpServers": 5}');
|
|
139
|
-
expect((await readUserMcpConfig(path)).error).toBe('mcpServers must be an object');
|
|
140
|
-
|
|
141
|
-
await Bun.write(path, '{not json');
|
|
142
|
-
expect((await readUserMcpConfig(path)).error).toBeTruthy();
|
|
143
|
-
});
|
|
144
|
-
|
|
145
|
-
test('resolveProjectMcpConfig picks the first existing candidate, else the default', async () => {
|
|
146
|
-
const dir = await tempDir();
|
|
147
|
-
expect((await resolveProjectMcpConfig(dir)).path).toBe(join(dir, MCP_FILENAMES[0]));
|
|
148
|
-
|
|
149
|
-
await Bun.write(join(dir, 'mcp.json'), '{}');
|
|
150
|
-
expect((await resolveProjectMcpConfig(dir)).path).toBe(join(dir, 'mcp.json'));
|
|
151
|
-
|
|
152
|
-
await fs.promises.mkdir(join(dir, '.omp'), { recursive: true });
|
|
153
|
-
await Bun.write(join(dir, '.omp', 'mcp.json'), '{}');
|
|
154
|
-
expect((await resolveProjectMcpConfig(dir)).path).toBe(join(dir, '.omp', 'mcp.json'));
|
|
155
|
-
});
|
|
156
|
-
|
|
157
|
-
test('readProjectMcpConfig reads the resolved project file', async () => {
|
|
158
|
-
const dir = await tempDir();
|
|
159
|
-
await fs.promises.mkdir(join(dir, '.omp'), { recursive: true });
|
|
160
|
-
await Bun.write(join(dir, '.omp', 'mcp.json'), '{"mcpServers":{"p":{"command":"x"}}}');
|
|
161
|
-
expect((await readProjectMcpConfig(dir)).servers.map((s) => s.name)).toEqual(['p']);
|
|
162
|
-
});
|
|
163
|
-
|
|
164
|
-
test('writeUserMcpServer rejects a name outside the grammar and a non-object', async () => {
|
|
165
|
-
const path = join(await tempDir(), 'mcp.json');
|
|
166
|
-
await expect(writeUserMcpServer('bad name', { command: 'x' }, path)).rejects.toThrow('Invalid server name');
|
|
167
|
-
await expect(writeUserMcpServer('ok', 'not an object' as unknown as Record<string, unknown>, path)).rejects.toThrow(
|
|
168
|
-
'Server configuration must be an object',
|
|
169
|
-
);
|
|
170
|
-
});
|
|
171
|
-
|
|
172
|
-
test('writeUserMcpServer preserves redacted env/headers the payload omitted', async () => {
|
|
173
|
-
const path = join(await tempDir(), 'mcp.json');
|
|
174
|
-
await Bun.write(path, JSON.stringify({
|
|
175
|
-
mcpServers: { srv: { command: 'old', env: { KEY: 'sk-secret' }, headers: { Auth: 'Bearer x' } } },
|
|
176
|
-
}));
|
|
177
|
-
await writeUserMcpServer('srv', { command: 'new' }, path);
|
|
178
|
-
|
|
179
|
-
const raw = JSON.parse(await fs.promises.readFile(path, 'utf8'));
|
|
180
|
-
expect(raw.mcpServers.srv).toEqual({
|
|
181
|
-
command: 'new',
|
|
182
|
-
env: { KEY: 'sk-secret' },
|
|
183
|
-
headers: { Auth: 'Bearer x' },
|
|
184
|
-
});
|
|
185
|
-
});
|
|
186
|
-
|
|
187
|
-
test('writeUserMcpServer rename moves the entry and keeps its credentials', async () => {
|
|
188
|
-
const path = join(await tempDir(), 'mcp.json');
|
|
189
|
-
await Bun.write(path, JSON.stringify({ mcpServers: { old: { command: 'x', env: { K: 'v' } } } }));
|
|
190
|
-
await writeUserMcpServer('new', { command: 'x' }, path, 'old');
|
|
191
|
-
|
|
192
|
-
const raw = JSON.parse(await fs.promises.readFile(path, 'utf8'));
|
|
193
|
-
expect(Object.keys(raw.mcpServers)).toEqual(['new']);
|
|
194
|
-
expect(raw.mcpServers.new.env).toEqual({ K: 'v' });
|
|
195
|
-
});
|
|
196
|
-
|
|
197
|
-
test('deleteUserMcpServer removes an entry and refuses a missing one', async () => {
|
|
198
|
-
const path = join(await tempDir(), 'mcp.json');
|
|
199
|
-
await Bun.write(path, JSON.stringify({ mcpServers: { a: { command: 'x' } } }));
|
|
200
|
-
await deleteUserMcpServer('a', path);
|
|
201
|
-
expect(JSON.parse(await fs.promises.readFile(path, 'utf8')).mcpServers).toEqual({});
|
|
202
|
-
|
|
203
|
-
await expect(deleteUserMcpServer('ghost', path)).rejects.toThrow('MCP server was not found');
|
|
204
|
-
const missing = join(await tempDir(), 'nope.json');
|
|
205
|
-
await expect(deleteUserMcpServer('a', missing)).rejects.toThrow('MCP server was not found');
|
|
206
|
-
});
|
|
207
|
-
});
|
|
208
|
-
|
|
209
38
|
describe('testMcpServer decision logic (no spawn, no network)', () => {
|
|
210
39
|
test('a link URL that is not http(s) is rejected without a request', async () => {
|
|
211
40
|
const result = await testMcpServer({
|
|
212
|
-
server: { id: '1', name: 'x', scope: 'every-project', enabled: true,
|
|
41
|
+
server: { id: '1', name: 'x', scope: 'every-project', enabled: true, transport: 'http', commandArgs: [], linkUrl: 'ftp://x', envVars: [], headers: [] },
|
|
213
42
|
});
|
|
214
43
|
expect(result).toEqual({
|
|
215
44
|
ok: false,
|
|
216
|
-
transport: '
|
|
45
|
+
transport: 'http',
|
|
217
46
|
durationMs: 0,
|
|
218
47
|
error: 'Link URL must be a valid http(s) endpoint',
|
|
219
48
|
});
|
|
@@ -221,26 +50,26 @@ describe('testMcpServer decision logic (no spawn, no network)', () => {
|
|
|
221
50
|
|
|
222
51
|
test('a command server with no arguments is rejected without spawning', async () => {
|
|
223
52
|
const result = await testMcpServer({
|
|
224
|
-
server: { id: '1', name: 'x', scope: 'every-project', enabled: true,
|
|
53
|
+
server: { id: '1', name: 'x', scope: 'every-project', enabled: true, transport: 'stdio', commandArgs: [' '], envVars: [], headers: [] },
|
|
225
54
|
});
|
|
226
55
|
expect(result.ok).toBe(false);
|
|
227
|
-
expect(result.transport).toBe('
|
|
56
|
+
expect(result.transport).toBe('stdio');
|
|
228
57
|
expect(result.error).toBe('No command configured');
|
|
229
58
|
});
|
|
230
59
|
|
|
231
60
|
test('mock mode validates the configuration instead of connecting', async () => {
|
|
232
61
|
Bun.env.MOCK = '1';
|
|
233
62
|
const bad = await testMcpServer({
|
|
234
|
-
server: { id: '1', name: 'x', scope: 'every-project', enabled: true,
|
|
63
|
+
server: { id: '1', name: 'x', scope: 'every-project', enabled: true, transport: 'http', commandArgs: [], linkUrl: 'nope', envVars: [], headers: [] },
|
|
235
64
|
});
|
|
236
|
-
expect(bad).toEqual({ ok: false, transport: '
|
|
65
|
+
expect(bad).toEqual({ ok: false, transport: 'http', durationMs: 12, error: 'Invalid server configuration' });
|
|
237
66
|
|
|
238
67
|
const good = await testMcpServer({
|
|
239
|
-
server: { id: '2', name: 'web', scope: 'every-project', enabled: true,
|
|
68
|
+
server: { id: '2', name: 'web', scope: 'every-project', enabled: true, transport: 'sse', commandArgs: [], linkUrl: 'https://mcp.example', envVars: [], headers: [] },
|
|
240
69
|
});
|
|
241
70
|
expect(good).toEqual({
|
|
242
71
|
ok: true,
|
|
243
|
-
transport: '
|
|
72
|
+
transport: 'sse',
|
|
244
73
|
protocolVersion: '2025-06-18',
|
|
245
74
|
serverInfo: { name: 'web', version: '1.0.0' },
|
|
246
75
|
toolCount: 3,
|