@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
|
@@ -16,24 +16,40 @@
|
|
|
16
16
|
* config, then the app-local rows, then plugin contributions. That is the same
|
|
17
17
|
* rule the settings pane merges with, so the list a user sees and the list a
|
|
18
18
|
* session receives cannot disagree about which entry is live.
|
|
19
|
+
*
|
|
20
|
+
* Enablement is omp's own: the user-level `disabledServers` denylist wins, then
|
|
21
|
+
* the entry's `enabled: false`, then the `enabledServers` allowlist. A server
|
|
22
|
+
* disabled in `mcp.json` must not reach a session just because Kabmo read the
|
|
23
|
+
* file itself.
|
|
19
24
|
*/
|
|
20
25
|
|
|
21
26
|
import { getDb } from '@/server/db.server';
|
|
22
|
-
import {
|
|
27
|
+
import {
|
|
28
|
+
isProjectMcpConfigEnabled,
|
|
29
|
+
isServerEnabled,
|
|
30
|
+
readProjectMcpConfig,
|
|
31
|
+
readUserMcpConfig,
|
|
32
|
+
} from '@/server/lib/omp/config/mcp';
|
|
33
|
+
import type { McpServer } from '@/server/lib/omp/config/mcp-shared';
|
|
23
34
|
import { readCustomMcpServers } from '@/server/lib/mcp/store.server';
|
|
24
|
-
import { pluginMcpServers } from '@/server/lib/plugins/mcp.server';
|
|
25
|
-
import type {
|
|
35
|
+
import { pluginMcpServers, type RegisteredPluginMcpServer } from '@/server/lib/plugins/mcp.server';
|
|
36
|
+
import type { SessionMcpOverrides } from '@/server/lib/mcp/session-state.server';
|
|
37
|
+
import type { McpServerItem, McpTransport } from '@/shared/types';
|
|
38
|
+
import { rowsToRecord } from '@/shared/lib/mcp/key-value';
|
|
26
39
|
import type { AcpMcpServer } from '@/server/lib/harness/acp/protocol';
|
|
27
40
|
|
|
28
41
|
/** One server, in the transport-neutral shape both deliveries read. */
|
|
29
42
|
export interface McpServerDefinition {
|
|
30
43
|
name: string;
|
|
31
|
-
transport:
|
|
44
|
+
transport: McpTransport;
|
|
32
45
|
command?: string;
|
|
33
46
|
args?: string[];
|
|
34
47
|
env?: Record<string, string>;
|
|
48
|
+
cwd?: string;
|
|
35
49
|
url?: string;
|
|
36
50
|
headers?: Record<string, string>;
|
|
51
|
+
/** Per-request timeout in milliseconds; 0 disables client-side timeouts. */
|
|
52
|
+
timeout?: number;
|
|
37
53
|
}
|
|
38
54
|
|
|
39
55
|
function stringRecord(value: unknown): Record<string, string> | undefined {
|
|
@@ -44,9 +60,17 @@ function stringRecord(value: unknown): Record<string, string> | undefined {
|
|
|
44
60
|
|
|
45
61
|
/** A native `mcp.json` entry, or null when it names neither a command nor a URL. */
|
|
46
62
|
export function definitionFromNative(name: string, config: McpServer): McpServerDefinition | null {
|
|
63
|
+
const timeout = typeof config.timeout === 'number' ? config.timeout : undefined;
|
|
47
64
|
if (typeof config.url === 'string' && config.url.trim()) {
|
|
48
65
|
const headers = stringRecord(config.headers);
|
|
49
|
-
|
|
66
|
+
const transport: McpTransport = config.type === 'sse' ? 'sse' : 'http';
|
|
67
|
+
return {
|
|
68
|
+
name,
|
|
69
|
+
transport,
|
|
70
|
+
url: config.url.trim(),
|
|
71
|
+
...(headers ? { headers } : {}),
|
|
72
|
+
...(timeout !== undefined ? { timeout } : {}),
|
|
73
|
+
};
|
|
50
74
|
}
|
|
51
75
|
if (typeof config.command === 'string' && config.command.trim()) {
|
|
52
76
|
const args = Array.isArray(config.args) ? config.args.filter((arg): arg is string => typeof arg === 'string') : [];
|
|
@@ -57,6 +81,8 @@ export function definitionFromNative(name: string, config: McpServer): McpServer
|
|
|
57
81
|
command: config.command.trim(),
|
|
58
82
|
...(args.length > 0 ? { args } : {}),
|
|
59
83
|
...(env ? { env } : {}),
|
|
84
|
+
...(typeof config.cwd === 'string' && config.cwd.trim() ? { cwd: config.cwd.trim() } : {}),
|
|
85
|
+
...(timeout !== undefined ? { timeout } : {}),
|
|
60
86
|
};
|
|
61
87
|
}
|
|
62
88
|
return null;
|
|
@@ -65,91 +91,214 @@ export function definitionFromNative(name: string, config: McpServer): McpServer
|
|
|
65
91
|
/** An app-local settings row, or null when it is disabled or malformed. */
|
|
66
92
|
export function definitionFromItem(item: McpServerItem): McpServerDefinition | null {
|
|
67
93
|
if (!item.enabled) return null;
|
|
68
|
-
|
|
94
|
+
const transport: McpTransport = item.transport ?? (item.linkUrl ? 'http' : 'stdio');
|
|
95
|
+
const timeout = typeof item.timeout === 'number' ? item.timeout : undefined;
|
|
96
|
+
if (transport !== 'stdio') {
|
|
69
97
|
const url = (item.linkUrl ?? item.commandArgs[0] ?? '').trim();
|
|
70
|
-
|
|
98
|
+
if (!url) return null;
|
|
99
|
+
const headers = rowsToRecord(item.headers);
|
|
100
|
+
return {
|
|
101
|
+
name: item.name,
|
|
102
|
+
transport,
|
|
103
|
+
url,
|
|
104
|
+
...(headers ? { headers } : {}),
|
|
105
|
+
...(timeout !== undefined ? { timeout } : {}),
|
|
106
|
+
};
|
|
71
107
|
}
|
|
72
108
|
const [command, ...args] = item.commandArgs;
|
|
73
109
|
if (!command?.trim()) return null;
|
|
74
|
-
const env
|
|
75
|
-
for (const entry of item.envVars ?? []) {
|
|
76
|
-
// A masked value is a display placeholder, never a credential: injecting it
|
|
77
|
-
// would hand the agent the literal dots.
|
|
78
|
-
if (entry?.key && entry.value && entry.value !== '••••••••') env[entry.key] = entry.value;
|
|
79
|
-
}
|
|
110
|
+
const env = rowsToRecord(item.envVars);
|
|
80
111
|
return {
|
|
81
112
|
name: item.name,
|
|
82
113
|
transport: 'stdio',
|
|
83
114
|
command: command.trim(),
|
|
84
115
|
...(args.length > 0 ? { args } : {}),
|
|
85
|
-
...(
|
|
116
|
+
...(env ? { env } : {}),
|
|
117
|
+
...(item.cwd?.trim() ? { cwd: item.cwd.trim() } : {}),
|
|
118
|
+
...(timeout !== undefined ? { timeout } : {}),
|
|
119
|
+
};
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
/** Where a server was declared. The settings pane and the session list both
|
|
123
|
+
* need it, and a second derivation would drift from this one. */
|
|
124
|
+
export type McpServerSource = 'user' | 'project' | 'custom' | 'plugin';
|
|
125
|
+
|
|
126
|
+
/**
|
|
127
|
+
* One server as the session sees it: the native `mcp.json` shape (so a
|
|
128
|
+
* per-session overlay can write it back verbatim, credentials included), the
|
|
129
|
+
* transport for display, and the enablement AFTER the session's overrides.
|
|
130
|
+
*/
|
|
131
|
+
export interface McpServerEntry {
|
|
132
|
+
name: string;
|
|
133
|
+
config: McpServer;
|
|
134
|
+
transport: McpTransport;
|
|
135
|
+
source: McpServerSource;
|
|
136
|
+
enabled: boolean;
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
/** The transport a native entry names, by the same rule `definitionFromNative` uses. */
|
|
140
|
+
function transportOf(config: McpServer): McpTransport {
|
|
141
|
+
if (typeof config.url === 'string' && config.url.trim()) return config.type === 'sse' ? 'sse' : 'http';
|
|
142
|
+
return 'stdio';
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
/** An app-local row in omp's native shape. Redacted credentials are dropped,
|
|
146
|
+
* exactly as `definitionFromItem` drops them — the sentinel is a display
|
|
147
|
+
* placeholder and must never be written to a config file. */
|
|
148
|
+
function nativeFromItem(item: McpServerItem): McpServer | null {
|
|
149
|
+
const transport: McpTransport = item.transport ?? (item.linkUrl ? 'http' : 'stdio');
|
|
150
|
+
const timeout = typeof item.timeout === 'number' ? item.timeout : undefined;
|
|
151
|
+
if (transport !== 'stdio') {
|
|
152
|
+
const url = (item.linkUrl ?? item.commandArgs[0] ?? '').trim();
|
|
153
|
+
if (!url) return null;
|
|
154
|
+
const headers = rowsToRecord(item.headers);
|
|
155
|
+
return {
|
|
156
|
+
type: transport,
|
|
157
|
+
url,
|
|
158
|
+
...(headers ? { headers } : {}),
|
|
159
|
+
...(timeout !== undefined ? { timeout } : {}),
|
|
160
|
+
};
|
|
161
|
+
}
|
|
162
|
+
const [command, ...args] = item.commandArgs;
|
|
163
|
+
if (!command?.trim()) return null;
|
|
164
|
+
const env = rowsToRecord(item.envVars);
|
|
165
|
+
return {
|
|
166
|
+
command: command.trim(),
|
|
167
|
+
...(args.length > 0 ? { args } : {}),
|
|
168
|
+
...(env ? { env } : {}),
|
|
169
|
+
...(item.cwd?.trim() ? { cwd: item.cwd.trim() } : {}),
|
|
170
|
+
...(timeout !== undefined ? { timeout } : {}),
|
|
171
|
+
};
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
/** A plugin contribution in omp's native shape. */
|
|
175
|
+
function nativeFromPlugin(server: RegisteredPluginMcpServer['server']): McpServer {
|
|
176
|
+
if (server.transport === 'stdio') {
|
|
177
|
+
return {
|
|
178
|
+
command: server.command ?? '',
|
|
179
|
+
...(server.args?.length ? { args: server.args } : {}),
|
|
180
|
+
...(server.env ? { env: server.env } : {}),
|
|
181
|
+
};
|
|
182
|
+
}
|
|
183
|
+
return {
|
|
184
|
+
type: server.transport,
|
|
185
|
+
url: server.url ?? '',
|
|
186
|
+
...(server.headers ? { headers: server.headers } : {}),
|
|
86
187
|
};
|
|
87
188
|
}
|
|
88
189
|
|
|
89
190
|
/**
|
|
90
|
-
* Every
|
|
191
|
+
* Every server a session in `cwd` can see, enabled or not, with the session's
|
|
192
|
+
* overrides applied.
|
|
91
193
|
*
|
|
92
|
-
*
|
|
93
|
-
*
|
|
94
|
-
*
|
|
194
|
+
* This is the ONE merge: the settings pane, the ACP injection, the omp-rpc
|
|
195
|
+
* overlay and the navbar list all read it, so they cannot disagree about which
|
|
196
|
+
* entry is live. Precedence is by NAME, first wins: user, project, app-local,
|
|
197
|
+
* plugin.
|
|
198
|
+
*
|
|
199
|
+
* `overrides` is the per-session map (`true` = enabled, `false` = disabled).
|
|
200
|
+
* A name absent from it keeps the configured state, which is what lets a
|
|
201
|
+
* settings edit reach a session that never touched that server.
|
|
95
202
|
*/
|
|
96
|
-
export async function
|
|
97
|
-
|
|
203
|
+
export async function mcpServerEntriesFor(
|
|
204
|
+
cwd: string,
|
|
205
|
+
options: { overrides?: SessionMcpOverrides; sources?: readonly McpServerSource[] } = {},
|
|
206
|
+
): Promise<McpServerEntry[]> {
|
|
207
|
+
const overrides = options.overrides ?? {};
|
|
208
|
+
const wanted = options.sources ? new Set(options.sources) : null;
|
|
209
|
+
const entries: McpServerEntry[] = [];
|
|
98
210
|
const seen = new Set<string>();
|
|
99
|
-
const add = (
|
|
100
|
-
if (!
|
|
101
|
-
|
|
211
|
+
const add = (entry: McpServerEntry | null) => {
|
|
212
|
+
if (!entry) return;
|
|
213
|
+
if (wanted && !wanted.has(entry.source)) return;
|
|
214
|
+
const key = entry.name.toLowerCase();
|
|
102
215
|
if (seen.has(key)) return;
|
|
103
216
|
seen.add(key);
|
|
104
|
-
|
|
217
|
+
const override = overrides[entry.name];
|
|
218
|
+
entries.push({ ...entry, enabled: override === undefined ? entry.enabled : override });
|
|
105
219
|
};
|
|
106
220
|
|
|
107
221
|
const user = await readUserMcpConfig();
|
|
108
222
|
if (user.error) console.error(`[mcp] user config skipped: ${user.error}`);
|
|
109
223
|
for (const entry of user.servers) {
|
|
110
|
-
|
|
111
|
-
|
|
224
|
+
add({
|
|
225
|
+
name: entry.name,
|
|
226
|
+
config: entry.config,
|
|
227
|
+
transport: transportOf(entry.config),
|
|
228
|
+
source: 'user',
|
|
229
|
+
enabled: isServerEnabled(entry.name, entry.config, user.disabledServers, user.enabledServers),
|
|
230
|
+
});
|
|
112
231
|
}
|
|
113
232
|
|
|
114
|
-
if (cwd) {
|
|
233
|
+
if (cwd && (await isProjectMcpConfigEnabled())) {
|
|
115
234
|
const project = await readProjectMcpConfig(cwd);
|
|
116
235
|
if (project.error) console.error(`[mcp] project config skipped: ${project.error}`);
|
|
117
236
|
for (const entry of project.servers) {
|
|
118
|
-
|
|
119
|
-
|
|
237
|
+
add({
|
|
238
|
+
name: entry.name,
|
|
239
|
+
config: entry.config,
|
|
240
|
+
transport: transportOf(entry.config),
|
|
241
|
+
source: 'project',
|
|
242
|
+
enabled: isServerEnabled(entry.name, entry.config, user.disabledServers, user.enabledServers),
|
|
243
|
+
});
|
|
120
244
|
}
|
|
121
245
|
}
|
|
122
246
|
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
247
|
+
if (!wanted || wanted.has('custom')) {
|
|
248
|
+
const custom = await readCustomMcpServers(await getDb());
|
|
249
|
+
for (const item of custom) {
|
|
250
|
+
if (item.scope === 'this-project' && item.projectPath !== cwd) continue;
|
|
251
|
+
const config = nativeFromItem(item);
|
|
252
|
+
if (!config) continue;
|
|
253
|
+
add({ name: item.name, config, transport: transportOf(config), source: 'custom', enabled: item.enabled });
|
|
254
|
+
}
|
|
127
255
|
}
|
|
128
256
|
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
257
|
+
if (!wanted || wanted.has('plugin')) {
|
|
258
|
+
for (const entry of pluginMcpServers()) {
|
|
259
|
+
const config = nativeFromPlugin(entry.server);
|
|
260
|
+
add({ name: entry.name, config, transport: transportOf(config), source: 'plugin', enabled: true });
|
|
261
|
+
}
|
|
133
262
|
}
|
|
134
263
|
|
|
135
|
-
return
|
|
264
|
+
return entries;
|
|
136
265
|
}
|
|
137
266
|
|
|
138
|
-
/**
|
|
267
|
+
/**
|
|
268
|
+
* Every ENABLED server a session in `cwd` should receive, in the
|
|
269
|
+
* transport-neutral shape the ACP handshake and the settings pane consume.
|
|
270
|
+
*
|
|
271
|
+
* A read that fails is reported and skipped: one unreadable config must not
|
|
272
|
+
* stop a chat from starting, and the settings pane is where the user can see
|
|
273
|
+
* the reason.
|
|
274
|
+
*/
|
|
275
|
+
export async function mcpServersFor(
|
|
276
|
+
cwd: string,
|
|
277
|
+
options: { overrides?: SessionMcpOverrides } = {},
|
|
278
|
+
): Promise<McpServerDefinition[]> {
|
|
279
|
+
const entries = await mcpServerEntriesFor(cwd, options);
|
|
280
|
+
return entries.flatMap((entry) => {
|
|
281
|
+
if (!entry.enabled) return [];
|
|
282
|
+
const definition = definitionFromNative(entry.name, entry.config);
|
|
283
|
+
return definition ? [definition] : [];
|
|
284
|
+
});
|
|
285
|
+
}
|
|
286
|
+
|
|
287
|
+
/** The ACP wire shape: stdio is the baseline, `http`/`sse` are the typed variants. */
|
|
139
288
|
export function toAcpMcpServers(definitions: readonly McpServerDefinition[]): AcpMcpServer[] {
|
|
140
289
|
return definitions.map((definition) =>
|
|
141
|
-
definition.transport === '
|
|
290
|
+
definition.transport === 'stdio'
|
|
142
291
|
? {
|
|
143
|
-
type: 'http' as const,
|
|
144
|
-
name: definition.name,
|
|
145
|
-
url: definition.url ?? '',
|
|
146
|
-
headers: Object.entries(definition.headers ?? {}).map(([name, value]) => ({ name, value })),
|
|
147
|
-
}
|
|
148
|
-
: {
|
|
149
292
|
name: definition.name,
|
|
150
293
|
command: definition.command ?? '',
|
|
151
294
|
args: definition.args ?? [],
|
|
152
295
|
env: Object.entries(definition.env ?? {}).map(([name, value]) => ({ name, value })),
|
|
296
|
+
}
|
|
297
|
+
: {
|
|
298
|
+
type: definition.transport,
|
|
299
|
+
name: definition.name,
|
|
300
|
+
url: definition.url ?? '',
|
|
301
|
+
headers: Object.entries(definition.headers ?? {}).map(([name, value]) => ({ name, value })),
|
|
153
302
|
},
|
|
154
303
|
);
|
|
155
304
|
}
|
|
@@ -56,9 +56,10 @@ function item(overrides: Partial<McpServerItem> = {}): McpServerItem {
|
|
|
56
56
|
name: 'custom',
|
|
57
57
|
scope: 'every-project',
|
|
58
58
|
enabled: true,
|
|
59
|
-
|
|
59
|
+
transport: 'stdio',
|
|
60
60
|
commandArgs: ['npx', '-y', 'custom-mcp'],
|
|
61
61
|
envVars: [],
|
|
62
|
+
headers: [],
|
|
62
63
|
...overrides,
|
|
63
64
|
};
|
|
64
65
|
}
|
|
@@ -83,6 +84,22 @@ describe('definitionFromNative', () => {
|
|
|
83
84
|
});
|
|
84
85
|
});
|
|
85
86
|
|
|
87
|
+
test('an sse entry keeps its transport, and timeout/cwd survive', () => {
|
|
88
|
+
expect(definitionFromNative('legacy', { type: 'sse', url: 'https://x/sse', timeout: 5000 })).toEqual({
|
|
89
|
+
name: 'legacy',
|
|
90
|
+
transport: 'sse',
|
|
91
|
+
url: 'https://x/sse',
|
|
92
|
+
timeout: 5000,
|
|
93
|
+
});
|
|
94
|
+
expect(definitionFromNative('local', { command: 'x', cwd: '/tmp/w', timeout: 0 })).toEqual({
|
|
95
|
+
name: 'local',
|
|
96
|
+
transport: 'stdio',
|
|
97
|
+
command: 'x',
|
|
98
|
+
cwd: '/tmp/w',
|
|
99
|
+
timeout: 0,
|
|
100
|
+
});
|
|
101
|
+
});
|
|
102
|
+
|
|
86
103
|
test('an entry naming neither is dropped, not guessed at', () => {
|
|
87
104
|
expect(definitionFromNative('broken', {})).toBeNull();
|
|
88
105
|
});
|
|
@@ -100,25 +117,53 @@ describe('definitionFromItem', () => {
|
|
|
100
117
|
expect(definition?.env).toEqual({ MODE: 'fast' });
|
|
101
118
|
});
|
|
102
119
|
|
|
103
|
-
test('a link row becomes an http server', () => {
|
|
104
|
-
expect(
|
|
120
|
+
test('a link row becomes an http server with its headers', () => {
|
|
121
|
+
expect(
|
|
122
|
+
definitionFromItem(
|
|
123
|
+
item({
|
|
124
|
+
transport: 'http',
|
|
125
|
+
linkUrl: 'https://mcp.example',
|
|
126
|
+
headers: [{ id: 'h1', key: 'Authorization', value: 'Bearer x' }],
|
|
127
|
+
timeout: 1000,
|
|
128
|
+
}),
|
|
129
|
+
),
|
|
130
|
+
).toEqual({
|
|
105
131
|
name: 'custom',
|
|
106
132
|
transport: 'http',
|
|
107
133
|
url: 'https://mcp.example',
|
|
134
|
+
headers: { Authorization: 'Bearer x' },
|
|
135
|
+
timeout: 1000,
|
|
136
|
+
});
|
|
137
|
+
});
|
|
138
|
+
|
|
139
|
+
test('an sse row keeps the sse transport', () => {
|
|
140
|
+
expect(definitionFromItem(item({ transport: 'sse', linkUrl: 'https://x/sse' }))).toMatchObject({
|
|
141
|
+
transport: 'sse',
|
|
142
|
+
url: 'https://x/sse',
|
|
143
|
+
});
|
|
144
|
+
});
|
|
145
|
+
|
|
146
|
+
test('a stdio row carries cwd and timeout', () => {
|
|
147
|
+
expect(definitionFromItem(item({ cwd: '/tmp/w', timeout: 0 }))).toMatchObject({
|
|
148
|
+
transport: 'stdio',
|
|
149
|
+
cwd: '/tmp/w',
|
|
150
|
+
timeout: 0,
|
|
108
151
|
});
|
|
109
152
|
});
|
|
110
153
|
});
|
|
111
154
|
|
|
112
155
|
describe('toAcpMcpServers', () => {
|
|
113
|
-
test('maps
|
|
156
|
+
test('maps all transports to the wire shape', () => {
|
|
114
157
|
expect(
|
|
115
158
|
toAcpMcpServers([
|
|
116
159
|
{ name: 'a', transport: 'stdio', command: 'npx', args: ['x'], env: { K: 'V' } },
|
|
117
160
|
{ name: 'b', transport: 'http', url: 'https://x', headers: { H: '1' } },
|
|
161
|
+
{ name: 'c', transport: 'sse', url: 'https://y/sse' },
|
|
118
162
|
]),
|
|
119
163
|
).toEqual([
|
|
120
164
|
{ name: 'a', command: 'npx', args: ['x'], env: [{ name: 'K', value: 'V' }] },
|
|
121
165
|
{ type: 'http', name: 'b', url: 'https://x', headers: [{ name: 'H', value: '1' }] },
|
|
166
|
+
{ type: 'sse', name: 'c', url: 'https://y/sse', headers: [] },
|
|
122
167
|
]);
|
|
123
168
|
});
|
|
124
169
|
});
|
|
@@ -166,4 +211,31 @@ describe('mcpServersFor', () => {
|
|
|
166
211
|
expect((await mcpServersFor(project)).some((server) => server.name === 'scoped')).toBe(true);
|
|
167
212
|
expect((await mcpServersFor(elsewhere)).some((server) => server.name === 'scoped')).toBe(false);
|
|
168
213
|
});
|
|
214
|
+
|
|
215
|
+
test('a server disabled in the file or in the denylist never reaches a session', async () => {
|
|
216
|
+
await writeFile(
|
|
217
|
+
join(agentDir, 'mcp.json'),
|
|
218
|
+
JSON.stringify({
|
|
219
|
+
mcpServers: {
|
|
220
|
+
off: { command: 'off-command', enabled: false },
|
|
221
|
+
denied: { command: 'denied-command' },
|
|
222
|
+
allowed: { command: 'allowed-command', enabled: false },
|
|
223
|
+
},
|
|
224
|
+
disabledServers: ['denied'],
|
|
225
|
+
enabledServers: ['allowed'],
|
|
226
|
+
}),
|
|
227
|
+
);
|
|
228
|
+
await writeCustomMcpServers(await getDb(), []);
|
|
229
|
+
expect((await mcpServersFor('')).map((server) => server.name)).toEqual(['allowed']);
|
|
230
|
+
});
|
|
231
|
+
|
|
232
|
+
test('mcp.enableProjectConfig=false hides the project file from a session', async () => {
|
|
233
|
+
await writeFile(join(agentDir, 'config.yml'), 'mcp:\n enableProjectConfig: false\n');
|
|
234
|
+
try {
|
|
235
|
+
expect((await mcpServersFor(project)).some((server) => server.name === 'project')).toBe(false);
|
|
236
|
+
} finally {
|
|
237
|
+
await rm(join(agentDir, 'config.yml'), { force: true });
|
|
238
|
+
}
|
|
239
|
+
expect((await mcpServersFor(project)).some((server) => server.name === 'project')).toBe(true);
|
|
240
|
+
});
|
|
169
241
|
});
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* SPDX-License-Identifier: MIT
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Per-session MCP enablement, persisted.
|
|
8
|
+
*
|
|
9
|
+
* The list a session receives is a SPAWN property: omp reads `mcp.json` once at
|
|
10
|
+
* start, and an ACP agent receives `mcpServers` on `session/new`. A toggle that
|
|
11
|
+
* only lived in the client would therefore be lost on the next respawn (idle
|
|
12
|
+
* reclaim, a restart, a second instance), so the override is a server row keyed
|
|
13
|
+
* by the session id — the same keying `harness_sessions` uses.
|
|
14
|
+
*
|
|
15
|
+
* Deliberately NOT `session_ui_state`: that blob is the client's whole layout
|
|
16
|
+
* and is written by the browser, while this row is read by the spawn path
|
|
17
|
+
* before any client exists.
|
|
18
|
+
*/
|
|
19
|
+
|
|
20
|
+
import type { DbClient } from '@/server/lib/db/client';
|
|
21
|
+
|
|
22
|
+
const SESSION_MCP_SQL = `
|
|
23
|
+
CREATE TABLE IF NOT EXISTS session_mcp_state (
|
|
24
|
+
session_id TEXT PRIMARY KEY,
|
|
25
|
+
-- JSON object: server name -> true (enabled) | false (disabled). Only the
|
|
26
|
+
-- names that DIFFER from the configured state are stored, so a settings
|
|
27
|
+
-- change still reaches a session that never overrode that server.
|
|
28
|
+
overrides TEXT NOT NULL DEFAULT '{}',
|
|
29
|
+
updated_at DATETIME DEFAULT CURRENT_TIMESTAMP
|
|
30
|
+
);
|
|
31
|
+
`;
|
|
32
|
+
|
|
33
|
+
export async function ensureSessionMcpSchema(db: DbClient): Promise<void> {
|
|
34
|
+
await db.exec(SESSION_MCP_SQL);
|
|
35
|
+
}
|
|
@@ -0,0 +1,164 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* SPDX-License-Identifier: MIT
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* The per-session MCP override store and the agent-dir overlay it builds.
|
|
8
|
+
*
|
|
9
|
+
* The contract these pin: an override is a MAP (both directions are real), a
|
|
10
|
+
* toggle back to the configured state removes the entry, and the overlay is a
|
|
11
|
+
* real agent dir — every other entry symlinked, `mcp.json` written from the
|
|
12
|
+
* merged list, and the project's own file switched off for the child.
|
|
13
|
+
*/
|
|
14
|
+
|
|
15
|
+
import { afterAll, beforeAll, beforeEach, describe, expect, test } from 'bun:test';
|
|
16
|
+
import fs from 'fs';
|
|
17
|
+
import os from 'os';
|
|
18
|
+
import path from 'path';
|
|
19
|
+
import { isolateDb, releaseDb } from '@/test-support/isolated-db';
|
|
20
|
+
import { removeDir } from '@/test-support/remove-dir';
|
|
21
|
+
import {
|
|
22
|
+
clearSessionMcpOverrides,
|
|
23
|
+
readSessionMcpOverrides,
|
|
24
|
+
writeSessionMcpOverrides,
|
|
25
|
+
} from '@/server/lib/mcp/session-state.server';
|
|
26
|
+
import {
|
|
27
|
+
ensureSessionMcpOverlay,
|
|
28
|
+
removeSessionMcpOverlay,
|
|
29
|
+
sessionMcpOverlayDir,
|
|
30
|
+
} from '@/server/lib/mcp/session-overlay.server';
|
|
31
|
+
import { sessionMcpSpawn } from '@/server/lib/omp/rpc/spawn-mcp';
|
|
32
|
+
import { cachedMcpProbe, probeMcpServer } from '@/server/lib/mcp/probe.server';
|
|
33
|
+
import { mcpServerEntriesFor } from '@/server/lib/mcp/registry.server';
|
|
34
|
+
|
|
35
|
+
const ROOT = path.join(os.tmpdir(), `kabmo-session-mcp-${process.pid}`);
|
|
36
|
+
const AGENT = path.join(ROOT, 'agent');
|
|
37
|
+
const PROJECT = path.join(ROOT, 'project');
|
|
38
|
+
const SESSION = 'aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee';
|
|
39
|
+
const previousAgentDir = Bun.env.PI_CODING_AGENT_DIR;
|
|
40
|
+
|
|
41
|
+
beforeAll(async () => {
|
|
42
|
+
removeDir(ROOT);
|
|
43
|
+
fs.mkdirSync(AGENT, { recursive: true });
|
|
44
|
+
fs.mkdirSync(path.join(PROJECT, '.omp'), { recursive: true });
|
|
45
|
+
Bun.env.PI_CODING_AGENT_DIR = AGENT;
|
|
46
|
+
fs.writeFileSync(
|
|
47
|
+
path.join(AGENT, 'mcp.json'),
|
|
48
|
+
JSON.stringify({
|
|
49
|
+
mcpServers: {
|
|
50
|
+
alpha: { command: 'alpha-cmd' },
|
|
51
|
+
beta: { command: 'beta-cmd' },
|
|
52
|
+
off: { command: 'off-cmd' },
|
|
53
|
+
},
|
|
54
|
+
disabledServers: ['off'],
|
|
55
|
+
}),
|
|
56
|
+
);
|
|
57
|
+
fs.writeFileSync(path.join(AGENT, 'config.yml'), 'theme:\n dark: titanium\n');
|
|
58
|
+
fs.writeFileSync(
|
|
59
|
+
path.join(PROJECT, '.omp', 'mcp.json'),
|
|
60
|
+
JSON.stringify({ mcpServers: { gamma: { command: 'gamma-cmd' } } }),
|
|
61
|
+
);
|
|
62
|
+
});
|
|
63
|
+
|
|
64
|
+
afterAll(async () => {
|
|
65
|
+
await releaseDb();
|
|
66
|
+
if (previousAgentDir === undefined) delete Bun.env.PI_CODING_AGENT_DIR;
|
|
67
|
+
else Bun.env.PI_CODING_AGENT_DIR = previousAgentDir;
|
|
68
|
+
removeDir(ROOT);
|
|
69
|
+
});
|
|
70
|
+
|
|
71
|
+
beforeEach(async () => {
|
|
72
|
+
await isolateDb();
|
|
73
|
+
await removeSessionMcpOverlay(SESSION);
|
|
74
|
+
});
|
|
75
|
+
|
|
76
|
+
describe('session MCP overrides', () => {
|
|
77
|
+
test('round-trips both directions and drops the row when empty', async () => {
|
|
78
|
+
expect(await readSessionMcpOverrides(SESSION)).toEqual({});
|
|
79
|
+
await writeSessionMcpOverrides(SESSION, { beta: false, off: true });
|
|
80
|
+
expect(await readSessionMcpOverrides(SESSION)).toEqual({ beta: false, off: true });
|
|
81
|
+
await writeSessionMcpOverrides(SESSION, {});
|
|
82
|
+
expect(await readSessionMcpOverrides(SESSION)).toEqual({});
|
|
83
|
+
});
|
|
84
|
+
|
|
85
|
+
test('clear removes the row', async () => {
|
|
86
|
+
await writeSessionMcpOverrides(SESSION, { beta: false });
|
|
87
|
+
await clearSessionMcpOverrides(SESSION);
|
|
88
|
+
expect(await readSessionMcpOverrides(SESSION)).toEqual({});
|
|
89
|
+
});
|
|
90
|
+
});
|
|
91
|
+
|
|
92
|
+
describe('session MCP overlay', () => {
|
|
93
|
+
test('writes the merged list with the session enablement, and symlinks the rest', async () => {
|
|
94
|
+
const overlay = await ensureSessionMcpOverlay(SESSION, PROJECT, { beta: false, off: true });
|
|
95
|
+
expect(overlay).toBeDefined();
|
|
96
|
+
const dir = sessionMcpOverlayDir(SESSION);
|
|
97
|
+
expect(overlay?.dir).toBe(dir);
|
|
98
|
+
|
|
99
|
+
const written = JSON.parse(fs.readFileSync(path.join(dir, 'mcp.json'), 'utf8')) as {
|
|
100
|
+
mcpServers: Record<string, { command?: string; enabled?: boolean }>;
|
|
101
|
+
};
|
|
102
|
+
// `beta` is disabled for this session; `off` was disabled in the file and
|
|
103
|
+
// the session turned it back on; `gamma` comes from the project file.
|
|
104
|
+
expect(written.mcpServers.beta).toEqual({ command: 'beta-cmd', enabled: false });
|
|
105
|
+
expect(written.mcpServers.off).toEqual({ command: 'off-cmd' });
|
|
106
|
+
expect(written.mcpServers.gamma).toEqual({ command: 'gamma-cmd' });
|
|
107
|
+
expect(written.mcpServers.alpha).toEqual({ command: 'alpha-cmd' });
|
|
108
|
+
|
|
109
|
+
// Everything else is the real agent dir, so auth/sessions/config stay one copy.
|
|
110
|
+
expect(fs.lstatSync(path.join(dir, 'config.yml')).isSymbolicLink()).toBe(true);
|
|
111
|
+
expect(fs.readFileSync(path.join(dir, 'config.yml'), 'utf8')).toContain('titanium');
|
|
112
|
+
// The secondary user file is NOT linked: it would resurrect a disabled server.
|
|
113
|
+
expect(fs.existsSync(path.join(dir, '.mcp.json'))).toBe(false);
|
|
114
|
+
|
|
115
|
+
expect(fs.readFileSync(overlay?.configPath ?? '', 'utf8')).toContain('enableProjectConfig: false');
|
|
116
|
+
});
|
|
117
|
+
|
|
118
|
+
test('no overrides means no overlay', async () => {
|
|
119
|
+
await ensureSessionMcpOverlay(SESSION, PROJECT, { beta: false });
|
|
120
|
+
expect(fs.existsSync(sessionMcpOverlayDir(SESSION))).toBe(true);
|
|
121
|
+
expect(await ensureSessionMcpOverlay(SESSION, PROJECT, {})).toBeUndefined();
|
|
122
|
+
expect(fs.existsSync(sessionMcpOverlayDir(SESSION))).toBe(false);
|
|
123
|
+
});
|
|
124
|
+
|
|
125
|
+
test('keep builds the full list for a live child whose last override was removed', async () => {
|
|
126
|
+
const overlay = await ensureSessionMcpOverlay(SESSION, PROJECT, {}, { keep: true });
|
|
127
|
+
expect(overlay).toBeDefined();
|
|
128
|
+
const written = JSON.parse(fs.readFileSync(path.join(sessionMcpOverlayDir(SESSION), 'mcp.json'), 'utf8')) as {
|
|
129
|
+
mcpServers: Record<string, { command?: string; enabled?: boolean }>;
|
|
130
|
+
};
|
|
131
|
+
expect(written.mcpServers.beta).toEqual({ command: 'beta-cmd' });
|
|
132
|
+
expect(written.mcpServers.off).toEqual({ command: 'off-cmd', enabled: false });
|
|
133
|
+
});
|
|
134
|
+
});
|
|
135
|
+
|
|
136
|
+
describe('session MCP spawn wiring', () => {
|
|
137
|
+
test('a session with overrides points the child at the overlay', async () => {
|
|
138
|
+
await writeSessionMcpOverrides(SESSION, { beta: false });
|
|
139
|
+
const spawn = await sessionMcpSpawn(SESSION, PROJECT, { KABMO_MODES: 'plan' });
|
|
140
|
+
const overlay = spawn.overlay;
|
|
141
|
+
if (!overlay) throw new Error('expected an overlay for a session with overrides');
|
|
142
|
+
expect(overlay.dir).toBe(sessionMcpOverlayDir(SESSION));
|
|
143
|
+
expect(spawn.extraArgs).toEqual(['--config', overlay.configPath]);
|
|
144
|
+
expect(spawn.env).toEqual({ KABMO_MODES: 'plan', PI_CODING_AGENT_DIR: overlay.dir });
|
|
145
|
+
});
|
|
146
|
+
|
|
147
|
+
test('a session without overrides keeps the real agent dir', async () => {
|
|
148
|
+
const spawn = await sessionMcpSpawn(SESSION, PROJECT, undefined);
|
|
149
|
+
expect(spawn.overlay).toBeUndefined();
|
|
150
|
+
expect(spawn.extraArgs).toEqual([]);
|
|
151
|
+
expect(spawn.env).toBeUndefined();
|
|
152
|
+
});
|
|
153
|
+
});
|
|
154
|
+
|
|
155
|
+
describe('session MCP probe', () => {
|
|
156
|
+
test('a failed handshake is cached per session and server', async () => {
|
|
157
|
+
const entries = await mcpServerEntriesFor(PROJECT, { sources: ['user', 'project'] });
|
|
158
|
+
const broken = { ...entries[0], name: 'broken', config: { command: 'definitely-not-a-real-binary' } };
|
|
159
|
+
expect(cachedMcpProbe(SESSION, 'broken')).toBeUndefined();
|
|
160
|
+
const result = await probeMcpServer(SESSION, broken, PROJECT);
|
|
161
|
+
expect(result.ok).toBe(false);
|
|
162
|
+
expect(cachedMcpProbe(SESSION, 'broken')).toEqual(result);
|
|
163
|
+
});
|
|
164
|
+
});
|