@myrialabs/clopen 0.4.37 → 0.4.38

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 (101) hide show
  1. package/README.md +2 -2
  2. package/backend/auth/permissions.ts +14 -0
  3. package/backend/bootstrap.ts +16 -0
  4. package/backend/database/crypto/envelope.test.ts +93 -0
  5. package/backend/database/crypto/envelope.ts +127 -0
  6. package/backend/database/crypto/index.ts +22 -0
  7. package/backend/database/crypto/master-key.ts +129 -0
  8. package/backend/database/crypto/secret-columns.ts +147 -0
  9. package/backend/database/migrations/071_create_notes_tables.ts +90 -0
  10. package/backend/database/migrations/072_encrypt_stored_secrets.ts +107 -0
  11. package/backend/database/migrations/073_create_integration_tables.ts +119 -0
  12. package/backend/database/migrations/074_create_work_tables.ts +94 -0
  13. package/backend/database/migrations/index.ts +28 -0
  14. package/backend/database/queries/db-client-connection-queries.ts +23 -12
  15. package/backend/database/queries/engine-queries.ts +23 -10
  16. package/backend/database/queries/index.ts +6 -1
  17. package/backend/database/queries/integration-queries.ts +297 -0
  18. package/backend/database/queries/mcp-server-queries.ts +38 -11
  19. package/backend/database/queries/note-queries.test.ts +190 -0
  20. package/backend/database/queries/note-queries.ts +269 -0
  21. package/backend/database/queries/profile-queries.ts +1 -1
  22. package/backend/database/queries/ssh-connection-queries.ts +19 -8
  23. package/backend/database/queries/work-queries.ts +210 -0
  24. package/backend/engine/docs/artifacts.md +22 -9
  25. package/backend/files/os-clipboard.test.ts +209 -0
  26. package/backend/files/os-clipboard.ts +567 -0
  27. package/backend/http/integration-hooks.ts +42 -0
  28. package/backend/http/notes-images.test.ts +228 -0
  29. package/backend/http/notes-images.ts +196 -0
  30. package/backend/index.ts +9 -0
  31. package/backend/integrations/accounts.ts +229 -0
  32. package/backend/integrations/health.ts +146 -0
  33. package/backend/integrations/index.ts +36 -0
  34. package/backend/integrations/projections/index.ts +120 -0
  35. package/backend/integrations/projections/mcp-projector.test.ts +204 -0
  36. package/backend/integrations/projections/mcp-projector.ts +159 -0
  37. package/backend/integrations/projections/types.ts +51 -0
  38. package/backend/integrations/registry/define.ts +38 -0
  39. package/backend/integrations/registry/index.ts +56 -0
  40. package/backend/integrations/registry/providers/context7.ts +44 -0
  41. package/backend/integrations/registry/providers/firecrawl.ts +41 -0
  42. package/backend/integrations/registry/providers/github.ts +78 -0
  43. package/backend/integrations/registry/types.ts +96 -0
  44. package/backend/integrations/webhooks/gateway.ts +160 -0
  45. package/backend/integrations/webhooks/verify.ts +65 -0
  46. package/backend/mcp/README.md +25 -3
  47. package/backend/mcp/external/config.ts +35 -1
  48. package/backend/mcp/index.ts +1 -1
  49. package/backend/mcp/internal/config.ts +1 -1
  50. package/backend/notes/access.test.ts +82 -0
  51. package/backend/notes/access.ts +27 -0
  52. package/backend/notes/storage.test.ts +77 -0
  53. package/backend/notes/storage.ts +114 -0
  54. package/backend/permissions/service.ts +2 -2
  55. package/backend/profiles/service.ts +1 -1
  56. package/backend/projects/project-cleanup.ts +6 -0
  57. package/backend/work/bindings.ts +124 -0
  58. package/backend/work/index.ts +42 -0
  59. package/backend/work/prompts.ts +150 -0
  60. package/backend/work/providers/github/actions-logs.ts +180 -0
  61. package/backend/work/providers/github/adapter.test.ts +88 -0
  62. package/backend/work/providers/github/adapter.ts +1255 -0
  63. package/backend/work/providers/github/client.ts +280 -0
  64. package/backend/work/providers/github/list-range.test.ts +158 -0
  65. package/backend/work/providers/github/token-kind.test.ts +42 -0
  66. package/backend/work/pull-requests.ts +242 -0
  67. package/backend/work/registry.ts +27 -0
  68. package/backend/work/service.ts +436 -0
  69. package/backend/work/start-work.test.ts +71 -0
  70. package/backend/work/start-work.ts +232 -0
  71. package/backend/work/types.ts +180 -0
  72. package/backend/ws/files/clipboard.ts +78 -0
  73. package/backend/ws/files/index.ts +5 -0
  74. package/backend/ws/git/diff-budget.ts +70 -11
  75. package/backend/ws/index.ts +11 -1
  76. package/backend/ws/integrations/crud.ts +219 -0
  77. package/backend/ws/integrations/index.ts +22 -0
  78. package/backend/ws/mcp/crud.ts +25 -1
  79. package/backend/ws/notes/index.ts +278 -0
  80. package/backend/ws/profiles/crud.ts +1 -1
  81. package/backend/ws/work/actions.ts +206 -0
  82. package/backend/ws/work/context.ts +51 -0
  83. package/backend/ws/work/crud.ts +347 -0
  84. package/backend/ws/work/index.ts +17 -0
  85. package/backend/ws/work/pull-requests.ts +177 -0
  86. package/backend/ws/work/schemas.ts +226 -0
  87. package/dist/assets/{index-sJmS_CCm.js → index-CyH7fSbR.js} +1 -1
  88. package/dist/assets/{index-Bik9TCBi.js → index-DSHIANSy.js} +1 -1
  89. package/dist/assets/main-D2IOjftb.css +1 -0
  90. package/dist/assets/main-DM-tHKbW.js +1152 -0
  91. package/dist/index.html +2 -2
  92. package/package.json +1 -1
  93. package/shared/constants/engine-tools.ts +1 -1
  94. package/shared/constants/tool-icons.ts +33 -0
  95. package/shared/types/database/schema.ts +41 -0
  96. package/shared/types/integrations.ts +140 -0
  97. package/shared/types/stores/settings.ts +8 -0
  98. package/shared/types/work.ts +426 -0
  99. package/shared/utils/logger.ts +3 -0
  100. package/dist/assets/main-DLqolBI2.css +0 -1
  101. package/dist/assets/main-Df1I3hnw.js +0 -1096
@@ -51,6 +51,56 @@ export const BRANCH_NAME_BUDGET: DiffBudget = {
51
51
  contextLines: 0
52
52
  };
53
53
 
54
+ /**
55
+ * Budget for pull-request descriptions. The most generous of the three: a PR
56
+ * description covers a whole branch rather than one commit, and a description
57
+ * written from a heavily sampled diff is the one that invents changes.
58
+ */
59
+ export const PR_DESCRIPTION_BUDGET: DiffBudget = {
60
+ perFileBytes: 8 * 1024,
61
+ totalBytes: 40 * 1024,
62
+ maxFiles: 60,
63
+ contextLines: 3
64
+ };
65
+
66
+ /**
67
+ * WHICH diff to budget.
68
+ *
69
+ * Extracted when the pull-request composer needed `base...head` instead of
70
+ * `--cached`. Everything below is identical for both — the file walk, the
71
+ * skip list, the per-file clipping — so the scope is a parameter rather than a
72
+ * second copy of the builder that would drift from this one.
73
+ */
74
+ export interface DiffScope {
75
+ /** Operands inserted into every `git diff` invocation. */
76
+ args: string[];
77
+ /** How the patch section is introduced. */
78
+ label: string;
79
+ /** Wording when nothing changed, used by the caller's empty check. */
80
+ emptyLabel: string;
81
+ }
82
+
83
+ export const STAGED_SCOPE: DiffScope = {
84
+ args: ['--cached'],
85
+ label: 'Staged diff',
86
+ emptyLabel: 'staged changes'
87
+ };
88
+
89
+ /**
90
+ * Everything on `head` that is not on `base`.
91
+ *
92
+ * Three dots, not two: `base..head` would also show changes made to base since
93
+ * the branch left it, which are not this pull request's changes and are exactly
94
+ * what makes an AI-written description claim work someone else did.
95
+ */
96
+ export function rangeScope(base: string, head: string): DiffScope {
97
+ return {
98
+ args: [`${base}...${head}`],
99
+ label: `Diff (${base}...${head})`,
100
+ emptyLabel: `changes between ${base} and ${head}`
101
+ };
102
+ }
103
+
54
104
  /**
55
105
  * Paths whose diff is machine-generated: enormous, uninformative, and the single
56
106
  * biggest source of wasted context. They still appear in the `--stat` header, so
@@ -123,29 +173,30 @@ export interface BudgetedDiff {
123
173
  text: string;
124
174
  /** True when any file's patch was clipped or dropped. */
125
175
  truncated: boolean;
126
- /** True when there is nothing staged at all. */
176
+ /** True when the scope contains no change at all. */
127
177
  isEmpty: boolean;
128
178
  }
129
179
 
130
180
  /**
131
- * Build the staged-diff section of an AI prompt under `budget`.
181
+ * Build the diff section of an AI prompt under `budget`, for `scope`.
132
182
  *
133
183
  * We deliberately spawn one `git diff` per file rather than one for everything:
134
- * it lets us stop as soon as the budget is spent, so a 200 MB staged blob is
135
- * never read into memory in the first place.
184
+ * it lets us stop as soon as the budget is spent, so a 200 MB blob is never read
185
+ * into memory in the first place.
136
186
  */
137
- export async function buildBudgetedStagedDiff(
187
+ export async function buildBudgetedDiff(
138
188
  cwd: string,
139
- budget: DiffBudget
189
+ budget: DiffBudget,
190
+ scope: DiffScope = STAGED_SCOPE
140
191
  ): Promise<BudgetedDiff> {
141
- const numstat = await execGit(['diff', '--cached', '--numstat', '-z', '-M'], cwd);
192
+ const numstat = await execGit(['diff', ...scope.args, '--numstat', '-z', '-M'], cwd);
142
193
  const entries = parseNumstat(numstat.stdout);
143
194
 
144
195
  if (entries.length === 0) {
145
196
  return { text: '', truncated: false, isEmpty: true };
146
197
  }
147
198
 
148
- const statResult = await execGit(['diff', '--cached', '--stat=200', '-M'], cwd);
199
+ const statResult = await execGit(['diff', ...scope.args, '--stat=200', '-M'], cwd);
149
200
  const stat = statResult.stdout.trim();
150
201
 
151
202
  const skipped: string[] = [];
@@ -180,7 +231,7 @@ export async function buildBudgetedStagedDiff(
180
231
  const result = await execGit(
181
232
  [
182
233
  'diff',
183
- '--cached',
234
+ ...scope.args,
184
235
  '--no-color',
185
236
  `--unified=${budget.contextLines}`,
186
237
  '-M',
@@ -208,8 +259,8 @@ export async function buildBudgetedStagedDiff(
208
259
  }
209
260
  if (patches.length > 0) {
210
261
  const header = truncated
211
- ? 'Staged diff (sampled — some files or lines were omitted to fit context):'
212
- : 'Staged diff:';
262
+ ? `${scope.label} (sampled — some files or lines were omitted to fit context):`
263
+ : `${scope.label}:`;
213
264
  sections.push(`${header}\n${patches.join('\n')}`);
214
265
  }
215
266
  if (filesOmitted > 0) {
@@ -218,3 +269,11 @@ export async function buildBudgetedStagedDiff(
218
269
 
219
270
  return { text: sections.join('\n\n'), truncated, isEmpty: false };
220
271
  }
272
+
273
+ /** The staged diff. Kept as its own name because two callers read better for it. */
274
+ export async function buildBudgetedStagedDiff(
275
+ cwd: string,
276
+ budget: DiffBudget
277
+ ): Promise<BudgetedDiff> {
278
+ return buildBudgetedDiff(cwd, budget, STAGED_SCOPE);
279
+ }
@@ -35,6 +35,7 @@ import { sshRouter } from './ssh';
35
35
  import { portsRouter } from './ports';
36
36
  import { containersRouter } from './containers';
37
37
  import { mcpRouter } from './mcp';
38
+ import { integrationsRouter } from './integrations';
38
39
  import { skillsRouter } from './skills';
39
40
  import { commandsRouter } from './commands';
40
41
  import { subagentsRouter } from './subagents';
@@ -44,6 +45,8 @@ import { profilesRouter } from './profiles';
44
45
  import { artifactsRouter } from './artifacts';
45
46
  import { memoryRouter } from './memory';
46
47
  import { worktreesRouter } from './worktrees';
48
+ import { notesRouter } from './notes';
49
+ import { workRouter } from './work';
47
50
 
48
51
  // ============================================
49
52
  // Main App Router - Merge All Module Routers
@@ -98,6 +101,7 @@ export const wsRouter = createRouter()
98
101
 
99
102
  // External MCP server management (install from the official registry)
100
103
  .merge(mcpRouter)
104
+ .merge(integrationsRouter)
101
105
 
102
106
  // Agent Skills management (create, import, install from a marketplace)
103
107
  .merge(skillsRouter)
@@ -113,7 +117,13 @@ export const wsRouter = createRouter()
113
117
  .merge(artifactsRouter)
114
118
 
115
119
  // Memory Graph (unified episodic + structural memory, shared by every engine)
116
- .merge(memoryRouter);
120
+ .merge(memoryRouter)
121
+
122
+ // Notes (project-scoped markdown)
123
+ .merge(notesRouter)
124
+
125
+ // Issues & PRs surface — work items, pull requests and CI for the current project
126
+ .merge(workRouter);
117
127
 
118
128
  // Export API type for frontend type-safe access
119
129
  export type WSAPI = typeof wsRouter['$api'];
@@ -0,0 +1,219 @@
1
+ /**
2
+ * Integration account handlers.
3
+ *
4
+ * integrations:providers — the registry, as the catalogue renders it
5
+ * integrations:list — connected accounts (never credential values)
6
+ * integrations:connect — create an account and project its capabilities
7
+ * integrations:update — credentials / capabilities / project / enabled
8
+ * integrations:disconnect — release every projection, then drop the account
9
+ * integrations:health — probe one account
10
+ * integrations:secrets-health — state of secrets at rest, for the hub banner
11
+ *
12
+ * Admin-gated in `backend/auth/permissions.ts`, matching the MCP surface it
13
+ * absorbs: connecting an account changes what every engine and every project
14
+ * can reach.
15
+ */
16
+
17
+ import { t } from 'elysia';
18
+ import { createRouter } from '$shared/utils/ws-server';
19
+ import { debug } from '$shared/utils/logger';
20
+ import {
21
+ checkAccountHealth,
22
+ getSecretsHealth,
23
+ integrationAccounts,
24
+ listProviderInfo
25
+ } from '$backend/integrations';
26
+ import { INTEGRATION_CAPABILITIES, INTEGRATION_CATEGORIES } from '$shared/types/integrations';
27
+ import type { IntegrationCapability } from '$shared/types/integrations';
28
+ import { ws as wsServer } from '$backend/utils/ws';
29
+
30
+ /**
31
+ * Tell every connected client an account changed.
32
+ *
33
+ * Global rather than per-project: an account can be bound to a project, but the
34
+ * connector row it projects is instance-wide, and the hub is an instance-wide
35
+ * screen.
36
+ */
37
+ function announce(accountId?: string): void {
38
+ wsServer.emit.global('integrations:changed', accountId ? { accountId } : {});
39
+ }
40
+
41
+ const CAPABILITY_SCHEMA = t.Union(INTEGRATION_CAPABILITIES.map((capability) => t.Literal(capability)));
42
+ const CATEGORY_SCHEMA = t.Union(INTEGRATION_CATEGORIES.map((category) => t.Literal(category)));
43
+
44
+ const STATUS_SCHEMA = t.Union([
45
+ t.Literal('unknown'),
46
+ t.Literal('ok'),
47
+ t.Literal('needs_auth'),
48
+ t.Literal('needs_config'),
49
+ t.Literal('error')
50
+ ]);
51
+
52
+ const AUTH_METHOD_SCHEMA = t.Union([
53
+ t.Literal('api-key'),
54
+ t.Literal('oauth-device'),
55
+ t.Literal('oauth-code'),
56
+ t.Literal('mcp-oauth'),
57
+ t.Literal('connection-string'),
58
+ t.Literal('none')
59
+ ]);
60
+
61
+ const CREDENTIAL_FIELD_SCHEMA = t.Object({
62
+ name: t.String(),
63
+ label: t.String(),
64
+ placeholder: t.Optional(t.String()),
65
+ help: t.Optional(t.String()),
66
+ isSecret: t.Boolean(),
67
+ isRequired: t.Boolean()
68
+ });
69
+
70
+ const PROVIDER_SCHEMA = t.Object({
71
+ id: t.String(),
72
+ name: t.String(),
73
+ category: CATEGORY_SCHEMA,
74
+ description: t.String(),
75
+ docsUrl: t.Optional(t.String()),
76
+ authMethod: AUTH_METHOD_SCHEMA,
77
+ credentialFields: t.Array(CREDENTIAL_FIELD_SCHEMA),
78
+ capabilities: t.Array(CAPABILITY_SCHEMA),
79
+ defaultCapabilities: t.Array(CAPABILITY_SCHEMA),
80
+ providesAgentTools: t.Boolean(),
81
+ acceptsWebhooks: t.Boolean()
82
+ });
83
+
84
+ const ACCOUNT_SCHEMA = t.Object({
85
+ id: t.String(),
86
+ provider: t.String(),
87
+ label: t.String(),
88
+ projectId: t.Union([t.String(), t.Null()]),
89
+ authMethod: AUTH_METHOD_SCHEMA,
90
+ // Which fields hold a value — NOT the values. A credential that reached the
91
+ // client would be a credential in a log, a screenshot and a bug report.
92
+ configuredFields: t.Array(t.String()),
93
+ capabilities: t.Array(CAPABILITY_SCHEMA),
94
+ status: STATUS_SCHEMA,
95
+ statusDetail: t.Union([t.String(), t.Null()]),
96
+ checkedAt: t.Union([t.String(), t.Null()]),
97
+ isEnabled: t.Boolean(),
98
+ createdAt: t.String(),
99
+ updatedAt: t.String(),
100
+ projections: t.Array(t.Object({
101
+ capability: CAPABILITY_SCHEMA,
102
+ targetKind: t.Union([t.Literal('mcp_server'), t.Literal('db_client_connection')]),
103
+ targetId: t.String(),
104
+ adopted: t.Boolean()
105
+ }))
106
+ });
107
+
108
+ const SECRETS_HEALTH_SCHEMA = t.Object({
109
+ keySource: t.Union([t.Literal('env'), t.Literal('file')]),
110
+ keyFingerprint: t.String(),
111
+ failureCount: t.Number(),
112
+ lastFailureAt: t.Union([t.String(), t.Null()]),
113
+ unknownKeyFingerprints: t.Array(t.String()),
114
+ unsealedColumns: t.Array(t.Object({
115
+ table: t.String(),
116
+ column: t.String(),
117
+ count: t.Number()
118
+ }))
119
+ });
120
+
121
+ export const integrationsCrudHandler = createRouter()
122
+ .http('integrations:providers', {
123
+ data: t.Object({}),
124
+ response: t.Object({ providers: t.Array(PROVIDER_SCHEMA) })
125
+ }, async () => {
126
+ debug.log('path', 'integrations:providers');
127
+ return { providers: listProviderInfo() };
128
+ })
129
+
130
+ .http('integrations:list', {
131
+ data: t.Object({}),
132
+ response: t.Object({ accounts: t.Array(ACCOUNT_SCHEMA) })
133
+ }, async () => {
134
+ debug.log('path', 'integrations:list');
135
+ return { accounts: integrationAccounts.list() };
136
+ })
137
+
138
+ .http('integrations:connect', {
139
+ data: t.Object({
140
+ provider: t.String(),
141
+ label: t.Optional(t.String()),
142
+ projectId: t.Optional(t.Union([t.String(), t.Null()])),
143
+ credentials: t.Record(t.String(), t.String()),
144
+ capabilities: t.Optional(t.Array(CAPABILITY_SCHEMA))
145
+ }),
146
+ response: t.Object({ account: ACCOUNT_SCHEMA })
147
+ }, async ({ data }) => {
148
+ debug.log('path', `integrations:connect ${data.provider}`);
149
+ const account = integrationAccounts.connect({
150
+ provider: data.provider,
151
+ label: data.label,
152
+ projectId: data.projectId ?? null,
153
+ credentials: data.credentials,
154
+ capabilities: data.capabilities as IntegrationCapability[] | undefined
155
+ });
156
+ announce(account.id);
157
+ return { account };
158
+ })
159
+
160
+ /**
161
+ * One update handler rather than four.
162
+ *
163
+ * Every field here re-projects, and splitting them into separate events
164
+ * would just be four ways to reach the same pass. Absent fields are left
165
+ * alone; an empty credential value means "not re-typed", not "clear".
166
+ */
167
+ .http('integrations:update', {
168
+ data: t.Object({
169
+ id: t.String(),
170
+ label: t.Optional(t.String({ minLength: 1, maxLength: 120 })),
171
+ credentials: t.Optional(t.Record(t.String(), t.String())),
172
+ capabilities: t.Optional(t.Array(CAPABILITY_SCHEMA)),
173
+ projectId: t.Optional(t.Union([t.String(), t.Null()])),
174
+ enabled: t.Optional(t.Boolean())
175
+ }),
176
+ response: t.Object({ account: ACCOUNT_SCHEMA })
177
+ }, async ({ data }) => {
178
+ debug.log('path', `integrations:update ${data.id}`);
179
+
180
+ if (data.label !== undefined) integrationAccounts.setLabel(data.id, data.label);
181
+ if (data.credentials) integrationAccounts.updateCredentials(data.id, data.credentials);
182
+ if (data.capabilities) integrationAccounts.setCapabilities(data.id, data.capabilities as IntegrationCapability[]);
183
+ if (data.projectId !== undefined) integrationAccounts.setProject(data.id, data.projectId);
184
+ if (data.enabled !== undefined) integrationAccounts.setEnabled(data.id, data.enabled);
185
+
186
+ const account = integrationAccounts.get(data.id);
187
+ if (!account) throw new Error('Integration account not found');
188
+ announce(account.id);
189
+ return { account };
190
+ })
191
+
192
+ .http('integrations:disconnect', {
193
+ data: t.Object({ id: t.String() }),
194
+ response: t.Object({ success: t.Boolean() })
195
+ }, async ({ data }) => {
196
+ debug.log('path', `integrations:disconnect ${data.id}`);
197
+ integrationAccounts.disconnect(data.id);
198
+ announce(data.id);
199
+ return { success: true };
200
+ })
201
+
202
+ .http('integrations:health', {
203
+ data: t.Object({ id: t.String() }),
204
+ response: t.Object({
205
+ status: STATUS_SCHEMA,
206
+ detail: t.Union([t.String(), t.Null()])
207
+ })
208
+ }, async ({ data }) => {
209
+ debug.log('path', `integrations:health ${data.id}`);
210
+ return checkAccountHealth(data.id);
211
+ })
212
+
213
+ .http('integrations:secrets-health', {
214
+ data: t.Object({}),
215
+ response: t.Object({ health: SECRETS_HEALTH_SCHEMA })
216
+ }, async () => {
217
+ debug.log('path', 'integrations:secrets-health');
218
+ return { health: getSecretsHealth() };
219
+ });
@@ -0,0 +1,22 @@
1
+ /**
2
+ * Integrations Router
3
+ *
4
+ * Connect, reconfigure and disconnect third-party accounts. What an integration
5
+ * DOES is not here — that lives in the surface that owns the work.
6
+ */
7
+
8
+ import { t } from 'elysia';
9
+ import { createRouter } from '$shared/utils/ws-server';
10
+ import { integrationsCrudHandler } from './crud';
11
+
12
+ export const integrationsRouter = createRouter()
13
+ .merge(integrationsCrudHandler)
14
+ /**
15
+ * Broadcast after any account mutation. The hub also shows connectors, whose
16
+ * rows a projection creates and removes, so a client that only watched its
17
+ * own request would miss a connector appearing because someone else
18
+ * connected an account.
19
+ */
20
+ .emit('integrations:changed', t.Object({
21
+ accountId: t.Optional(t.String())
22
+ }));
@@ -25,7 +25,8 @@ import {
25
25
  completeAuthorization,
26
26
  getValidAccessToken,
27
27
  parseMcpConfig,
28
- parseToolOverrides
28
+ parseToolOverrides,
29
+ getEngineConfigsForServer
29
30
  } from '$backend/mcp';
30
31
 
31
32
  const TRANSPORT_SCHEMA = t.Union([t.Literal('stdio'), t.Literal('http'), t.Literal('sse')]);
@@ -325,4 +326,27 @@ export const mcpCrudHandler = createRouter()
325
326
  mcpServerQueries.remove(data.id);
326
327
  debug.log('mcp', `🗑️ Uninstalled external MCP server: ${existing.slug}`);
327
328
  return { success: true };
329
+ })
330
+ /**
331
+ * What each engine is actually handed for this server.
332
+ *
333
+ * Not the same thing as the stored row: every external server reaches an
334
+ * engine as a Streamable-HTTP remote pointing at Clopen's own proxy, so
335
+ * showing the row and labelling it "the engine's config" would mislead.
336
+ * Returned as a JSON string per engine because the shapes differ by SDK and
337
+ * the UI only ever prints them.
338
+ */
339
+ .http('mcp:engine-config', {
340
+ data: t.Object({ id: t.Number() }),
341
+ response: t.Object({ configs: t.Record(t.String(), t.String()) })
342
+ }, async ({ data }) => {
343
+ debug.log('path', `mcp:engine-config ${data.id}`);
344
+ const existing = mcpServerQueries.getById(data.id);
345
+ if (!existing) throw new Error('MCP server not found');
346
+
347
+ const configs = Object.fromEntries(
348
+ Object.entries(getEngineConfigsForServer(existing.slug))
349
+ .map(([engine, config]) => [engine, JSON.stringify(config, null, 2)])
350
+ );
351
+ return { configs };
328
352
  });