@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.
- package/backend/auth/permissions.ts +15 -1
- package/backend/database/migrations/044_create_skills_table.ts +29 -0
- package/backend/database/migrations/index.ts +7 -0
- package/backend/database/queries/index.ts +3 -1
- package/backend/database/queries/skill-queries.ts +105 -0
- package/backend/engine/adapters/claude/stream.ts +5 -0
- package/backend/engine/adapters/codex/credential.ts +120 -13
- package/backend/engine/adapters/codex/stream.ts +34 -8
- package/backend/engine/adapters/copilot/stream.ts +4 -0
- package/backend/engine/adapters/opencode/stream.ts +4 -0
- package/backend/engine/adapters/qwen/stream.ts +3 -0
- package/backend/engine/docs/lessons-learned.md +54 -50
- package/backend/git/git-service.ts +40 -0
- package/backend/index.ts +10 -1
- package/backend/mcp/README.md +77 -24
- package/backend/mcp/external/config.ts +82 -101
- package/backend/mcp/external/parse.test.ts +190 -0
- package/backend/mcp/external/parse.ts +293 -0
- package/backend/mcp/external/proxy.ts +202 -0
- package/backend/mcp/index.ts +6 -3
- package/backend/mcp/internal/remote-server.ts +103 -55
- package/backend/skills/index.ts +21 -0
- package/backend/skills/marketplace.ts +172 -0
- package/backend/skills/service.ts +245 -0
- package/backend/skills/spec.ts +214 -0
- package/backend/skills/store.ts +99 -0
- package/backend/skills/sync.ts +187 -0
- package/backend/snapshot/gitignore.ts +230 -7
- package/backend/snapshot/helpers.ts +34 -10
- package/backend/ws/files/read.ts +10 -1
- package/backend/ws/git/branch-name.ts +20 -4
- package/backend/ws/git/branch.ts +66 -11
- package/backend/ws/git/commit-message.ts +18 -3
- package/backend/ws/git/commit.ts +50 -16
- package/backend/ws/git/conflict.ts +47 -5
- package/backend/ws/git/diff.ts +38 -4
- package/backend/ws/git/log.ts +22 -2
- package/backend/ws/git/remote.ts +82 -33
- package/backend/ws/git/staging.ts +39 -9
- package/backend/ws/git/status.ts +52 -0
- package/backend/ws/index.ts +5 -1
- package/backend/ws/mcp/crud.ts +30 -1
- package/backend/ws/skills/catalog.ts +79 -0
- package/backend/ws/skills/crud.ts +123 -0
- package/backend/ws/skills/index.ts +15 -0
- package/backend/ws/snapshot/timeline.ts +1 -1
- package/dist/assets/main-BkMrek4_.css +1 -0
- package/dist/assets/{main-AqTMkV9D.js → main-TYNK6Orl.js} +332 -295
- package/dist/index.html +2 -2
- package/package.json +1 -1
- package/shared/types/git.ts +20 -0
- package/shared/utils/logger.ts +1 -0
- 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
|
package/backend/mcp/README.md
CHANGED
|
@@ -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
|
|
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
|
|
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
|
-
│
|
|
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
|
-
|
|
1203
|
-
|
|
1204
|
-
|
|
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
|
|
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.
|
|
1229
|
-
|
|
1230
|
-
|
|
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:
|
|
1259
|
-
|
|
1260
|
-
|
|
1261
|
-
`
|
|
1262
|
-
|
|
1263
|
-
|
|
1264
|
-
|
|
1265
|
-
|
|
1266
|
-
|
|
1267
|
-
|
|
|
1268
|
-
|
|
1269
|
-
|
|
|
1270
|
-
|
|
|
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
|
-
*
|
|
5
|
-
*
|
|
6
|
-
*
|
|
7
|
-
*
|
|
8
|
-
*
|
|
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
|
-
*
|
|
11
|
-
*
|
|
12
|
-
*
|
|
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 {
|
|
17
|
-
import type {
|
|
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
|
-
/**
|
|
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
|
-
|
|
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:
|
|
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
|
-
|
|
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: `
|
|
128
|
-
export function getOpenCodeExternalMcpConfig(): Record<string,
|
|
129
|
-
const out: Record<string,
|
|
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
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
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
|
|
157
|
-
*
|
|
158
|
-
*
|
|
159
|
-
*
|
|
160
|
-
*
|
|
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
|
-
|
|
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: `
|
|
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
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
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`
|
|
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
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
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;
|