keryx 0.36.0 → 0.36.2
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/package.json +1 -1
- package/util/mcpServer.ts +47 -16
package/package.json
CHANGED
package/util/mcpServer.ts
CHANGED
|
@@ -324,21 +324,29 @@ export async function adoptMcpSession(
|
|
|
324
324
|
const promise = (async () => {
|
|
325
325
|
const mcpServer = createMcpServer();
|
|
326
326
|
api.mcp.mcpServers.push(mcpServer);
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
327
|
+
try {
|
|
328
|
+
const transport = new WebStandardStreamableHTTPServerTransport({
|
|
329
|
+
sessionIdGenerator: () => sessionId,
|
|
330
|
+
enableJsonResponse: true,
|
|
331
|
+
// Local registration only — no hooks, no registry write (see doc above).
|
|
332
|
+
onsessioninitialized: (sid) => {
|
|
333
|
+
api.mcp.transports.set(sid, { transport, clientId });
|
|
334
|
+
},
|
|
335
|
+
onsessionclosed: (sid) => terminateMcpSession(sid, mcpServer),
|
|
336
|
+
});
|
|
337
|
+
transport.onclose = () =>
|
|
338
|
+
forgetMcpSession(transport.sessionId, mcpServer);
|
|
339
|
+
|
|
340
|
+
await mcpServer.connect(transport);
|
|
341
|
+
await driveSyntheticInitialize(transport, protocolVersion);
|
|
342
|
+
return transport;
|
|
343
|
+
} catch (e) {
|
|
344
|
+
// Adoption failed partway (e.g. the synthetic initialize errored) — drop
|
|
345
|
+
// the McpServer we optimistically registered so it can't linger in the
|
|
346
|
+
// broadcast list nor leave a half-initialized transport behind.
|
|
347
|
+
forgetMcpSession(sessionId, mcpServer);
|
|
348
|
+
throw e;
|
|
349
|
+
}
|
|
342
350
|
})();
|
|
343
351
|
|
|
344
352
|
adoptionsInFlight.set(sessionId, promise);
|
|
@@ -355,9 +363,24 @@ export async function adoptMcpSession(
|
|
|
355
363
|
* Actions with `mcp.tool === false` are excluded from tool registration.
|
|
356
364
|
*/
|
|
357
365
|
export function createMcpServer(): McpServer {
|
|
366
|
+
// Advertise the MCP Apps UI extension so hosts negotiate UI support during
|
|
367
|
+
// `initialize` (spec 2026-01-26, SEP-1724). Only declared when at least one
|
|
368
|
+
// action ships a UI, keeping the capability surface minimal.
|
|
369
|
+
const hasUiActions = api.actions.actions.some((a: Action) => a.mcp?.ui);
|
|
358
370
|
const mcpServer = new McpServer(
|
|
359
371
|
{ name: pkg.name, version: pkg.version },
|
|
360
|
-
{
|
|
372
|
+
{
|
|
373
|
+
instructions: config.server.mcp.instructions,
|
|
374
|
+
...(hasUiActions
|
|
375
|
+
? {
|
|
376
|
+
capabilities: {
|
|
377
|
+
extensions: {
|
|
378
|
+
[UI_EXTENSION_ID]: { mimeTypes: [MCP_APP_MIME_TYPE] },
|
|
379
|
+
},
|
|
380
|
+
},
|
|
381
|
+
}
|
|
382
|
+
: {}),
|
|
383
|
+
},
|
|
361
384
|
);
|
|
362
385
|
|
|
363
386
|
registerTools(mcpServer);
|
|
@@ -368,6 +391,12 @@ export function createMcpServer(): McpServer {
|
|
|
368
391
|
return mcpServer;
|
|
369
392
|
}
|
|
370
393
|
|
|
394
|
+
/**
|
|
395
|
+
* MCP Apps extension identifier used for capability negotiation during `initialize`.
|
|
396
|
+
* @see https://github.com/modelcontextprotocol/ext-apps
|
|
397
|
+
*/
|
|
398
|
+
const UI_EXTENSION_ID = "io.modelcontextprotocol/ui";
|
|
399
|
+
|
|
371
400
|
/**
|
|
372
401
|
* Compute the `ui://` resource URI for an action's MCP App.
|
|
373
402
|
* Defaults to `ui://<tool-name>` when `mcp.ui.resourceUri` is not set.
|
|
@@ -488,6 +517,8 @@ function registerTools(mcpServer: McpServer) {
|
|
|
488
517
|
|
|
489
518
|
// MCP App responses carry both a text block (added to model context)
|
|
490
519
|
// and structuredContent (delivered to the app UI for rendering).
|
|
520
|
+
// ext-apps hosts render the UI from the tool's `_meta.ui.resourceUri`
|
|
521
|
+
// and the separate `ui://` resource — the content array stays text-only.
|
|
491
522
|
if (response instanceof UIResponse) {
|
|
492
523
|
return {
|
|
493
524
|
content: [{ type: "text" as const, text: response.text }],
|