@myrialabs/clopen 0.4.4 → 0.4.6

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.
Files changed (53) hide show
  1. package/backend/auth/permissions.ts +15 -1
  2. package/backend/database/migrations/044_create_skills_table.ts +29 -0
  3. package/backend/database/migrations/index.ts +7 -0
  4. package/backend/database/queries/index.ts +3 -1
  5. package/backend/database/queries/skill-queries.ts +105 -0
  6. package/backend/engine/adapters/claude/stream.ts +5 -0
  7. package/backend/engine/adapters/codex/credential.ts +120 -13
  8. package/backend/engine/adapters/codex/stream.ts +34 -8
  9. package/backend/engine/adapters/copilot/stream.ts +4 -0
  10. package/backend/engine/adapters/opencode/stream.ts +4 -0
  11. package/backend/engine/adapters/qwen/stream.ts +3 -0
  12. package/backend/engine/docs/lessons-learned.md +54 -50
  13. package/backend/git/git-service.ts +40 -0
  14. package/backend/index.ts +10 -1
  15. package/backend/mcp/README.md +77 -24
  16. package/backend/mcp/external/config.ts +82 -101
  17. package/backend/mcp/external/parse.test.ts +190 -0
  18. package/backend/mcp/external/parse.ts +293 -0
  19. package/backend/mcp/external/proxy.ts +202 -0
  20. package/backend/mcp/index.ts +6 -3
  21. package/backend/mcp/internal/remote-server.ts +103 -55
  22. package/backend/skills/index.ts +21 -0
  23. package/backend/skills/marketplace.ts +172 -0
  24. package/backend/skills/service.ts +245 -0
  25. package/backend/skills/spec.ts +214 -0
  26. package/backend/skills/store.ts +99 -0
  27. package/backend/skills/sync.ts +187 -0
  28. package/backend/snapshot/gitignore.ts +230 -7
  29. package/backend/snapshot/helpers.ts +34 -10
  30. package/backend/ws/files/read.ts +10 -1
  31. package/backend/ws/git/branch-name.ts +20 -4
  32. package/backend/ws/git/branch.ts +66 -11
  33. package/backend/ws/git/commit-message.ts +18 -3
  34. package/backend/ws/git/commit.ts +50 -16
  35. package/backend/ws/git/conflict.ts +47 -5
  36. package/backend/ws/git/diff.ts +38 -4
  37. package/backend/ws/git/log.ts +22 -2
  38. package/backend/ws/git/remote.ts +82 -33
  39. package/backend/ws/git/staging.ts +39 -9
  40. package/backend/ws/git/status.ts +52 -0
  41. package/backend/ws/index.ts +5 -1
  42. package/backend/ws/mcp/crud.ts +30 -1
  43. package/backend/ws/skills/catalog.ts +79 -0
  44. package/backend/ws/skills/crud.ts +123 -0
  45. package/backend/ws/skills/index.ts +15 -0
  46. package/backend/ws/snapshot/timeline.ts +1 -1
  47. package/dist/assets/main-BkMrek4_.css +1 -0
  48. package/dist/assets/{main-AqTMkV9D.js → main-TYNK6Orl.js} +332 -295
  49. package/dist/index.html +2 -2
  50. package/package.json +1 -1
  51. package/shared/types/git.ts +20 -0
  52. package/shared/utils/logger.ts +1 -0
  53. package/dist/assets/main-DJf71Zum.css +0 -1
@@ -35,6 +35,8 @@ import {
35
35
  assertSafeGitRevish,
36
36
  assertSafeGitShowRef
37
37
  } from './git-spawn-validation';
38
+ import { findNestedRepoPaths, findSubmodulePaths } from '../snapshot/gitignore';
39
+ import path from 'node:path';
38
40
 
39
41
  export class GitService {
40
42
  /**
@@ -311,6 +313,44 @@ export class GitService {
311
313
  }
312
314
  }
313
315
 
316
+ // Discover nested git repos (submodules, gitignored embedded repos,
317
+ // worktrees) and aggregate their branch info so the Branches tab can
318
+ // render one collapsible group per sub-repo. Failures in a single
319
+ // nested repo must not break the outer result — we record the error
320
+ // on the entry and move on.
321
+ try {
322
+ const [nestedPaths, submodulePaths] = await Promise.all([
323
+ findNestedRepoPaths(cwd),
324
+ findSubmodulePaths(cwd)
325
+ ]);
326
+ if (nestedPaths.length > 0) {
327
+ const nestedResults = await Promise.all(
328
+ nestedPaths.map(async (repoPath) => {
329
+ const relPath = path.relative(cwd, repoPath).replace(/\\/g, '/');
330
+ const isSubmodule = submodulePaths.has(relPath);
331
+ try {
332
+ const info = await this.getBranches(repoPath, selectedRemote);
333
+ return { path: repoPath, relPath, isSubmodule, info };
334
+ } catch (err) {
335
+ const message = err instanceof Error ? err.message : String(err);
336
+ return {
337
+ path: repoPath,
338
+ relPath,
339
+ isSubmodule,
340
+ info: { current: '', local: [], remote: [], ahead: 0, behind: 0 },
341
+ error: message
342
+ };
343
+ }
344
+ })
345
+ );
346
+ // Stable order for the UI (sorted by relPath).
347
+ nestedResults.sort((a, b) => a.relPath.localeCompare(b.relPath));
348
+ branchInfo.nested = nestedResults;
349
+ }
350
+ } catch (err) {
351
+ debug.warn('git', `Failed to enumerate nested repos: ${err instanceof Error ? err.message : String(err)}`);
352
+ }
353
+
314
354
  return branchInfo;
315
355
  }
316
356
 
package/backend/index.ts CHANGED
@@ -40,7 +40,7 @@ import { audioRoute } from './http/audio';
40
40
  import { browserPreviewServiceManager } from './preview';
41
41
 
42
42
  // MCP remote server for Open Code custom tools
43
- import { handleMcpRequest, closeMcpServer, completeAuthorization } from './mcp';
43
+ import { handleMcpRequest, handleExternalMcpRequest, closeMcpServer, completeAuthorization } from './mcp';
44
44
 
45
45
  // Auth middleware
46
46
  import { checkRouteAccess } from './auth/permissions';
@@ -109,6 +109,15 @@ const app = new Elysia()
109
109
  return handleMcpRequest(request);
110
110
  })
111
111
 
112
+ // Per-server proxy for user-installed (external) MCP servers. Clopen connects
113
+ // to the upstream third-party server and re-exposes its sanitized tools here,
114
+ // so engines never connect to it directly — see backend/mcp/external/proxy.ts.
115
+ // Same long-lived semantics as `/mcp`: disable Bun's idle timeout.
116
+ .all('/mcp/ext/:slug', async ({ request, params, server }) => {
117
+ server?.timeout(request, 0);
118
+ return handleExternalMcpRequest(request, params.slug);
119
+ })
120
+
112
121
  // Stable OAuth redirect target for centralized MCP sign-in. The browser is
113
122
  // redirected here after the user consents; we exchange the code for tokens
114
123
  // (stored against the server) and show a self-closing confirmation page. The
@@ -9,14 +9,21 @@ disk and in their namespace keys:
9
9
  | Managed | By developers (this README) | By users in **Settings → MCP** |
10
10
  | Stored | In code (`internal/servers/`) | In the DB (`mcp_servers` table) |
11
11
  | Namespace | `clopen-mcp` bridge (non-Claude) / server name (Claude) | one bare `<slug>` per server (no prefix) |
12
- | Execution | In-process (no subprocess) | Engine connects directly (stdio subprocess or remote HTTP) |
12
+ | Execution | In-process (no subprocess) | Engine connects to Clopen's `/mcp/ext/<slug>` proxy; Clopen connects to the real upstream (stdio subprocess or remote HTTP) |
13
13
 
14
14
  Both are merged behind the **facade** `backend/mcp/index.ts` — the only module
15
15
  the rest of the backend imports from (`getEnabledMcpServers()`,
16
16
  `getXxxMcpConfig()`, `resolveOpenCodeToolName()` all return the combined view).
17
17
 
18
18
  The rest of this document covers the **internal** custom-tool system. External
19
- servers need no code — see `external/registry-client.ts` and `external/config.ts`.
19
+ servers need no code — see `external/registry-client.ts`, `external/config.ts`,
20
+ and `external/proxy.ts` (the per-server `/mcp/ext/<slug>` proxy bridge).
21
+
22
+ > **External servers are proxied, not direct.** Engines never connect straight
23
+ > to a third-party MCP server. Clopen connects to it (as an MCP client) and
24
+ > re-exposes its **sanitized** tools through a per-server endpoint on the same
25
+ > Streamable-HTTP bridge the internal tools use. See
26
+ > [External Servers, OAuth & Connection Status](#external-servers-oauth--connection-status).
20
27
 
21
28
  ---
22
29
 
@@ -180,7 +187,10 @@ backend/mcp/
180
187
  ├── external/ # User-installed servers from the official registry
181
188
  │ ├── types.ts # CatalogServer / ResolvedExternalServer
182
189
  │ ├── registry-client.ts # Fetch + normalise registry.modelcontextprotocol.io
183
- │ └── config.ts # Per-engine builders (bare <slug>) + resolveExternalToolName
190
+ │ ├── proxy.ts # `/mcp/ext/<slug>` proxy: Clopen ↔ upstream, schema sanitiser
191
+ │ ├── probe.ts # Connection health probe (Settings → MCP status)
192
+ │ ├── oauth.ts # Centralized OAuth (discovery + dynamic reg + PKCE)
193
+ │ └── config.ts # Per-engine builders (bridge URL, bare <slug>) + resolveExternalToolName
184
194
  └── README.md # This file
185
195
  ```
186
196
 
@@ -1198,10 +1208,12 @@ checklist in `backend/engine/README.md` §9.12. The summary:
1198
1208
  4. Wire the engine's auto-approval path (runtime callback or static
1199
1209
  per-tool config) so MCP tool calls don't get cancelled.
1200
1210
  5. Add a sibling `getXxxExternalMcpConfig()` in
1201
- `backend/mcp/external/config.ts` for user-installed registry servers,
1202
- and **forward `headers`** so the centrally-managed OAuth bearer (and
1203
- any static API key) reaches the engine. Use the SDK's real header
1204
- field — Codex uses `http_headers`, **not** `bearer_token`. See
1211
+ `backend/mcp/external/config.ts` for user-installed registry servers.
1212
+ Every external server is proxied, so this is now a one-liner per server:
1213
+ emit the bridge URL `http://localhost:<port>/mcp/ext/<slug>` plus the
1214
+ service-token header in the SDK's shape. No stdio branch, no upstream
1215
+ credential handling (the proxy injects it). Codex still uses
1216
+ `http_headers`, **not** `bearer_token`. See
1205
1217
  [External Servers, OAuth & Connection Status](#external-servers-oauth--connection-status)
1206
1218
  and `backend/engine/docs/lessons-learned.md` §9.18.
1207
1219
 
@@ -1211,7 +1223,8 @@ checklist in `backend/engine/README.md` §9.12. The summary:
1211
1223
  |------|----------|---------|
1212
1224
  | Public facade | `backend/mcp/index.ts` | Only public entry; merges internal + external |
1213
1225
  | Tool definitions | `backend/mcp/internal/servers/` | Single source of truth (internal) |
1214
- | Remote MCP server | `backend/mcp/internal/remote-server.ts` | HTTP bridge for every non-Claude engine |
1226
+ | Remote MCP server | `backend/mcp/internal/remote-server.ts` | HTTP bridge: internal `/mcp` + external `/mcp/ext/<slug>` |
1227
+ | External proxy | `backend/mcp/external/proxy.ts` | Clopen↔upstream MCP client + schema sanitiser |
1215
1228
  | Server factory | `backend/mcp/internal/servers/helper.ts` | `createRemoteMcpServer()` |
1216
1229
  | Per-engine config (internal) | `backend/mcp/internal/config.ts` | `getOpenCodeMcpConfig()`, `getCodexMcpConfig()`, … (clopen-mcp) |
1217
1230
  | Tool name resolver | `backend/mcp/internal/config.ts` | `resolveOpenCodeToolName()` (handles every engine's prefix variant) |
@@ -1225,9 +1238,43 @@ checklist in `backend/engine/README.md` §9.12. The summary:
1225
1238
 
1226
1239
  Everything above describes **internal** custom tools (the `clopen-mcp`
1227
1240
  bridge). **External** servers are the ones a user installs from the official
1228
- registry (Settings → MCP → Browse), stored in the `mcp_servers` table. Unlike
1229
- internal tools, the engine connects to these **directly** — a stdio subprocess
1230
- or a remote third-party URL — so authentication is Clopen's responsibility.
1241
+ registry (Settings → MCP → Browse), stored in the `mcp_servers` table.
1242
+
1243
+ ### Proxied through the bridge (not direct)
1244
+
1245
+ Engines do **not** connect to a third-party MCP server directly. Each enabled
1246
+ external server gets its own endpoint `GET/POST/DELETE /mcp/ext/<slug>` on the
1247
+ same Streamable-HTTP bridge as the internal tools. Clopen connects to the real
1248
+ upstream (stdio subprocess or remote URL) as an MCP **client**, and re-exposes
1249
+ its tools there. The per-engine builders in `external/config.ts` therefore emit
1250
+ the **identical** shape for every server — a loopback bridge URL plus the
1251
+ service-token header — regardless of the upstream's real transport.
1252
+
1253
+ Why proxy (`external/proxy.ts`):
1254
+
1255
+ 1. **Schema sanitising.** The MCP SDK's `Client.listTools()` eagerly compiles an
1256
+ Ajv validator for every tool's `outputSchema`. A single unresolvable `$ref`
1257
+ (e.g. Stitch's `#/$defs/ScreenInstance`) makes it throw, and the engine CLIs'
1258
+ `discoverTools` swallow that error and surface **zero** tools — a "connected"
1259
+ server that advertises nothing. Clopen reads `tools/list` with a **raw**
1260
+ JSON-RPC request (no Ajv), **drops `outputSchema`**, and strips dangling
1261
+ `$ref`s from `inputSchema` before re-serving. One bad schema can no longer
1262
+ hide a whole server.
1263
+ 2. **One credential path.** OAuth bearer / static API key is injected once, on
1264
+ Clopen's upstream hop (`resolveServerRow`). The engine→bridge hop only
1265
+ carries the service token — so a new engine adapter needs no per-transport
1266
+ or per-credential branching.
1267
+ 3. **Uniform behaviour.** stdio and remote external servers behave identically
1268
+ on every engine (this fixed Qwen advertising no remote tools and Copilot
1269
+ advertising no external tools at all).
1270
+
1271
+ Lifecycle: the upstream client (and any stdio subprocess) is created lazily when
1272
+ an engine opens a bridge session and torn down when that session closes
1273
+ (`internal/remote-server.ts`).
1274
+
1275
+ ### Authentication is Clopen's responsibility
1276
+
1277
+ Because Clopen owns the upstream connection, it also owns auth.
1231
1278
 
1232
1279
  ### Centralized OAuth (one sign-in, every engine)
1233
1280
 
@@ -1255,19 +1302,25 @@ Flow (`backend/mcp/external/oauth.ts`):
1255
1302
  WS routes (admin-only): `mcp:oauth-start` (returns the authorization URL; the
1256
1303
  UI opens it and polls status), `mcp:oauth-complete` (manual paste fallback).
1257
1304
 
1258
- ### Per-engine config: forward the auth headers
1259
-
1260
- Each engine's external builder in `backend/mcp/external/config.ts` MUST forward
1261
- `headers`, and must use the engine's real header field. Dropping headers causes
1262
- silent 401s; the wrong field name can make the engine reject its whole config.
1263
-
1264
- | Engine | Header field | Notes |
1265
- |--------|-------------|-------|
1266
- | Claude | `headers` | http/sse |
1267
- | OpenCode | `headers` | `oauth` left unset = auto-detect fallback |
1268
- | Copilot | `headers` | — |
1269
- | Qwen | `headers` (+ `httpUrl`) | — |
1270
- | **Codex** | **`http_headers`** | **NOT `bearer_token`** — that's rejected for `streamable_http` and aborts the run. Matches the internal bridge. |
1305
+ ### Per-engine config: just the bridge URL + service token
1306
+
1307
+ Because every external server is proxied, each engine's external builder in
1308
+ `backend/mcp/external/config.ts` emits the **same** shape: a loopback bridge URL
1309
+ (`http://localhost:<port>/mcp/ext/<slug>`) plus the service-token bearer. The
1310
+ upstream's real credential (OAuth/API key) is injected by the proxy, not the
1311
+ builder — so there is no per-engine header-field bookkeeping anymore. The only
1312
+ remaining per-engine difference is the SDK's config key for the URL/header:
1313
+
1314
+ | Engine | URL field | Auth header field | Notes |
1315
+ |--------|-----------|-------------------|-------|
1316
+ | Claude | `url` (`type:'http'`) | `headers` | — |
1317
+ | OpenCode | `url` (`type:'remote'`) | `headers` | — |
1318
+ | Copilot | `url` (`type:'http'`) | `headers` | `tools:['*']` so the CLI exposes all proxied tools |
1319
+ | Qwen | `httpUrl` | `headers` | — |
1320
+ | **Codex** | `url` | **`http_headers`** | **NOT `bearer_token`** — rejected for `streamable_http`. |
1321
+
1322
+ A new engine that speaks Streamable-HTTP MCP needs only this one-line builder —
1323
+ no stdio branch, no upstream-credential handling.
1271
1324
 
1272
1325
  ### Required-credential validation
1273
1326
 
@@ -1,42 +1,57 @@
1
1
  /**
2
2
  * External MCP — per-engine config builders.
3
3
  *
4
- * Reads enabled servers from the `mcp_servers` table and emits each engine's
5
- * native MCP config shape. Every external server occupies its OWN namespace
6
- * key (its bare `<slug>`; the `clopen` prefix is reserved for internal) — disjoint from the internal `clopen-mcp` bridge — so the
7
- * two systems never collide. The facade (`backend/mcp/index.ts`) merges these
8
- * with the internal config before handing them to an adapter.
4
+ * Every enabled external server is exposed to engines through Clopen's OWN
5
+ * Streamable-HTTP bridge at `/mcp/ext/<slug>` (see `./proxy.ts`), NOT by
6
+ * pointing the engine straight at the third-party stdio/HTTP server. Each
7
+ * server keeps its bare `<slug>` namespace (the `clopen` prefix is reserved
8
+ * for internal) — disjoint from the internal `clopen-mcp` bridge — so the two
9
+ * systems never collide.
9
10
  *
10
- * Unlike internal tools, external servers are real MCP servers the engine
11
- * connects to directly (stdio subprocess or remote HTTP), NOT routed through
12
- * Clopen's in-process `/mcp` bridge.
11
+ * Routing through the bridge means every engine receives the IDENTICAL shape:
12
+ * a loopback remote URL plus the service-token header. The real upstream
13
+ * transport (stdio/http/sse) and its OAuth/API-key credential are handled once,
14
+ * inside the proxy — so a new engine adapter needs no per-transport branching,
15
+ * and engines are shielded from upstream servers whose tool schemas would
16
+ * otherwise crash their MCP client (see `./proxy.ts`).
17
+ *
18
+ * The facade (`backend/mcp/index.ts`) merges these with the internal config
19
+ * before handing them to an adapter.
13
20
  */
14
21
 
15
22
  import type { McpServerConfig } from '@anthropic-ai/claude-agent-sdk';
16
- import type { McpLocalConfig, McpRemoteConfig } from '@opencode-ai/sdk';
17
- import type { MCPServerConfig as CopilotMcpServerConfig } from '@github/copilot-sdk';
23
+ import type { McpRemoteConfig } from '@opencode-ai/sdk';
24
+ import type { MCPHTTPServerConfig as CopilotMcpServerConfig } from '@github/copilot-sdk';
18
25
  import type { CLIMcpServerConfig as QwenMcpServerConfig } from '@qwen-code/sdk';
19
26
  import { debug } from '$shared/utils/logger';
20
27
  import { mcpServerQueries } from '$backend/database/queries';
21
- import { externalNamespace } from '../shared/constants';
28
+ import { externalNamespace, MCP_TOOL_CALL_TIMEOUT_MS } from '../shared/constants';
29
+ import { getMcpServiceToken } from '../internal/service-token';
30
+ import { SERVER_ENV } from '../../utils/env';
22
31
  import type { McpServerRow } from '$backend/database/queries';
23
32
  import type { ResolvedExternalServer } from './types';
24
33
 
25
- /** Codex flattens `mcp_servers.<name>.<key>` config to `--config` flags. */
34
+ /**
35
+ * Codex `mcp_servers.<name>` config, flattened by the SDK to `--config` flags.
36
+ * Each external server is a Streamable-HTTP remote pointing at our bridge;
37
+ * `http_headers` carries the service-token bearer (Codex rejects an inline
38
+ * `bearer_token` for `streamable_http`).
39
+ */
26
40
  type CodexMcpServerConfig = {
27
- command?: string;
28
- args?: string[];
29
- env?: Record<string, string>;
30
- url?: string;
31
- /**
32
- * Streamable-HTTP auth headers. Codex rejects an inline `bearer_token` for
33
- * streamable_http but accepts an `http_headers` table (the same field the
34
- * internal `clopen-mcp` bridge uses), so the centrally-managed
35
- * `Authorization: Bearer …` and any static API-key headers reach Codex.
36
- */
41
+ url: string;
37
42
  http_headers?: Record<string, string>;
38
43
  };
39
44
 
45
+ /** Loopback URL of the per-server external proxy bridge for `slug`. */
46
+ function bridgeUrl(slug: string): string {
47
+ return `http://localhost:${SERVER_ENV.PORT}/mcp/ext/${slug}`;
48
+ }
49
+
50
+ /** The service-token bearer header every engine→bridge hop carries. */
51
+ function serviceAuthHeaders(): Record<string, string> {
52
+ return { Authorization: `Bearer ${getMcpServiceToken()}` };
53
+ }
54
+
40
55
  function parseJson<T>(raw: string, fallback: T): T {
41
56
  try {
42
57
  return JSON.parse(raw) as T;
@@ -96,124 +111,90 @@ export function remoteNeedsOAuth(s: ResolvedExternalServer): boolean {
96
111
  && Object.keys(s.headers).length === 0;
97
112
  }
98
113
 
99
- /** Qwen OAuth fields for a credential-less remote (dynamic discovery). */
100
- function remoteAuthQwen(s: ResolvedExternalServer): Partial<QwenMcpServerConfig> {
101
- if (!remoteNeedsOAuth(s)) return {};
102
- return { oauth: { enabled: true }, authProviderType: 'dynamic_discovery' };
103
- }
104
-
105
114
  // ---------------------------------------------------------------------------
106
115
  // Per-engine builders
116
+ //
117
+ // Every external server, regardless of its real transport, is emitted as a
118
+ // Streamable-HTTP remote pointing at our `/mcp/ext/<slug>` proxy. The only
119
+ // per-engine difference is the SDK's config shape (field names) — the URL,
120
+ // namespace key, and service-token header are identical. The upstream
121
+ // transport + credential live inside the proxy (see ./proxy.ts).
107
122
  // ---------------------------------------------------------------------------
108
123
 
109
- /** Claude Agent SDK: stdio / sse / http config keyed by namespace. */
124
+ /** Claude Agent SDK: Streamable-HTTP remote keyed by namespace. */
110
125
  export function getClaudeExternalMcpConfig(): Record<string, McpServerConfig> {
111
126
  const out: Record<string, McpServerConfig> = {};
112
127
  for (const s of getEnabledExternalServers()) {
113
- if (s.transport === 'stdio' && s.command) {
114
- out[s.namespace] = { type: 'stdio', command: s.command, args: s.args, env: s.env };
115
- } else if ((s.transport === 'http' || s.transport === 'sse') && s.url) {
116
- out[s.namespace] = {
117
- type: s.transport,
118
- url: s.url,
119
- ...(Object.keys(s.headers).length > 0 ? { headers: s.headers } : {})
120
- };
121
- }
128
+ out[s.namespace] = { type: 'http', url: bridgeUrl(s.slug), headers: serviceAuthHeaders() };
122
129
  }
123
130
  logBuilt('Claude', out);
124
131
  return out;
125
132
  }
126
133
 
127
- /** Open Code: `McpLocalConfig` (stdio) / `McpRemoteConfig` (http/sse). */
128
- export function getOpenCodeExternalMcpConfig(): Record<string, McpLocalConfig | McpRemoteConfig> {
129
- const out: Record<string, McpLocalConfig | McpRemoteConfig> = {};
134
+ /** Open Code: `McpRemoteConfig` pointing at the bridge proxy. */
135
+ export function getOpenCodeExternalMcpConfig(): Record<string, McpRemoteConfig> {
136
+ const out: Record<string, McpRemoteConfig> = {};
130
137
  for (const s of getEnabledExternalServers()) {
131
- if (s.transport === 'stdio' && s.command) {
132
- out[s.namespace] = {
133
- type: 'local',
134
- command: [s.command, ...s.args],
135
- ...(Object.keys(s.env).length > 0 ? { environment: s.env } : {}),
136
- enabled: true
137
- };
138
- } else if ((s.transport === 'http' || s.transport === 'sse') && s.url) {
139
- // `oauth` is intentionally left unset: Open Code's default is OAuth
140
- // auto-detection (set it to `false` only to opt out). Credential-less
141
- // remotes therefore get the authorization handshake for free; the
142
- // interactive sign-in is driven separately via the MCP auth flow.
143
- out[s.namespace] = {
144
- type: 'remote',
145
- url: s.url,
146
- enabled: true,
147
- ...(Object.keys(s.headers).length > 0 ? { headers: s.headers } : {})
148
- };
149
- }
138
+ out[s.namespace] = {
139
+ type: 'remote',
140
+ url: bridgeUrl(s.slug),
141
+ enabled: true,
142
+ timeout: MCP_TOOL_CALL_TIMEOUT_MS,
143
+ headers: serviceAuthHeaders()
144
+ };
150
145
  }
151
146
  logBuilt('Open Code', out);
152
147
  return out;
153
148
  }
154
149
 
155
150
  /**
156
- * Codex: `mcp_servers.<name>` accepts a command (stdio) or url. Note: Codex
157
- * requires per-tool `approval_mode` to auto-approve, but external tool names
158
- * aren't known at install time (config-only, lazy spawn), so external MCP
159
- * tool calls may be cancelled in non-interactive `codex exec`. The server is
160
- * still registered so interactive/known-tool flows work.
151
+ * Codex: `mcp_servers.<name>.url` pointing at the bridge proxy.
152
+ *
153
+ * Note: Codex still requires per-tool `approval_mode` to auto-approve in
154
+ * non-interactive `codex exec`, and external tool names aren't known when this
155
+ * synchronous builder runs — so external MCP tool calls may be cancelled there.
156
+ * The server is registered so interactive/known-tool flows work; this limit is
157
+ * unchanged by the proxy.
161
158
  */
162
159
  export function getCodexExternalMcpConfig(): Record<string, CodexMcpServerConfig> {
163
160
  const out: Record<string, CodexMcpServerConfig> = {};
164
161
  for (const s of getEnabledExternalServers()) {
165
- if (s.transport === 'stdio' && s.command) {
166
- out[s.namespace] = {
167
- command: s.command,
168
- args: s.args,
169
- ...(Object.keys(s.env).length > 0 ? { env: s.env } : {})
170
- };
171
- } else if ((s.transport === 'http' || s.transport === 'sse') && s.url) {
172
- // `http_headers` carries the injected OAuth bearer (and any static API
173
- // key), matching the internal bridge — so Codex authenticates too.
174
- out[s.namespace] = {
175
- url: s.url,
176
- ...(Object.keys(s.headers).length > 0 ? { http_headers: s.headers } : {})
177
- };
178
- }
162
+ out[s.namespace] = { url: bridgeUrl(s.slug), http_headers: serviceAuthHeaders() };
179
163
  }
180
164
  logBuilt('Codex', out);
181
165
  return out;
182
166
  }
183
167
 
184
- /** Copilot: `MCPStdioServerConfig` (stdio) / `MCPHTTPServerConfig` (http/sse). */
168
+ /** Copilot: `MCPHTTPServerConfig` pointing at the bridge proxy. */
185
169
  export function getCopilotExternalMcpConfig(): Record<string, CopilotMcpServerConfig> {
186
170
  const out: Record<string, CopilotMcpServerConfig> = {};
187
171
  for (const s of getEnabledExternalServers()) {
188
- if (s.transport === 'stdio' && s.command) {
189
- out[s.namespace] = { type: 'local', command: s.command, args: s.args, env: s.env };
190
- } else if ((s.transport === 'http' || s.transport === 'sse') && s.url) {
191
- // Leaving `oauthClientId` unset makes the Copilot runtime perform
192
- // dynamic client registration when the server demands OAuth. The
193
- // interactive consent is delegated to us via the `mcp.oauth_required`
194
- // event (see the Copilot adapter's MCP auth wiring).
195
- out[s.namespace] = {
196
- type: s.transport,
197
- url: s.url,
198
- ...(Object.keys(s.headers).length > 0 ? { headers: s.headers } : {})
199
- };
200
- }
172
+ // `tools: ['*']` makes the Copilot runtime expose ALL of the proxy's
173
+ // tools. Leaving it unset relies on the SDK's documented "undefined =
174
+ // all" default, which the bundled CLI does not honour for dynamically
175
+ // discovered servers — the tools never reach the model.
176
+ out[s.namespace] = {
177
+ type: 'http',
178
+ url: bridgeUrl(s.slug),
179
+ tools: ['*'],
180
+ timeout: MCP_TOOL_CALL_TIMEOUT_MS,
181
+ headers: serviceAuthHeaders()
182
+ };
201
183
  }
202
184
  logBuilt('Copilot', out);
203
185
  return out;
204
186
  }
205
187
 
206
- /** Qwen Code: `CLIMcpServerConfig` — command (stdio) or url/httpUrl (remote). */
188
+ /** Qwen Code: `CLIMcpServerConfig` Streamable-HTTP (`httpUrl`) at the bridge proxy. */
207
189
  export function getQwenExternalMcpConfig(): Record<string, QwenMcpServerConfig> {
208
190
  const out: Record<string, QwenMcpServerConfig> = {};
209
191
  for (const s of getEnabledExternalServers()) {
210
- if (s.transport === 'stdio' && s.command) {
211
- out[s.namespace] = { command: s.command, args: s.args, env: s.env, trust: true };
212
- } else if (s.transport === 'http' && s.url) {
213
- out[s.namespace] = { httpUrl: s.url, headers: s.headers, trust: true, ...remoteAuthQwen(s) };
214
- } else if (s.transport === 'sse' && s.url) {
215
- out[s.namespace] = { url: s.url, headers: s.headers, trust: true, ...remoteAuthQwen(s) };
216
- }
192
+ out[s.namespace] = {
193
+ httpUrl: bridgeUrl(s.slug),
194
+ timeout: MCP_TOOL_CALL_TIMEOUT_MS,
195
+ trust: true,
196
+ headers: serviceAuthHeaders()
197
+ };
217
198
  }
218
199
  logBuilt('Qwen', out);
219
200
  return out;