keryx 0.36.1 → 0.37.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.
@@ -19,11 +19,18 @@
19
19
  * its `structuredContent` via {@link UIResponse.toJSON}, so the same action still
20
20
  * returns useful JSON everywhere.
21
21
  *
22
+ * The class is generic over the shape of `structuredContent`. When you construct a
23
+ * `UIResponse` from an object literal, `T` is inferred, so the field types flow through
24
+ * to the action's `run()` return type — and from there into the generated OpenAPI/MCP
25
+ * response schema, giving the app UI a fully-typed payload to bind against.
26
+ *
22
27
  * Use the static factory {@link UIResponse.from} or the constructor directly.
23
28
  */
24
- export class UIResponse {
29
+ export class UIResponse<
30
+ T extends Record<string, unknown> = Record<string, unknown>,
31
+ > {
25
32
  /** Structured data delivered to the app UI for rendering (not added to model context). */
26
- readonly structuredContent: Record<string, unknown>;
33
+ readonly structuredContent: T;
27
34
  /**
28
35
  * Text representation added to the model's context. Defaults to
29
36
  * `JSON.stringify(structuredContent)` when not provided.
@@ -33,15 +40,12 @@ export class UIResponse {
33
40
  /**
34
41
  * @param structuredContent - The structured data the app UI will render. Must be a
35
42
  * JSON-serializable object; it is delivered to the app verbatim and is not added to
36
- * the model's context.
43
+ * the model's context. Its shape is captured as `T` so downstream schemas stay typed.
37
44
  * @param options - Optional model-facing text.
38
45
  * @param options.text - Text representation added to the model's context. When omitted,
39
46
  * defaults to `JSON.stringify(structuredContent)`.
40
47
  */
41
- constructor(
42
- structuredContent: Record<string, unknown>,
43
- options?: { text?: string },
44
- ) {
48
+ constructor(structuredContent: T, options?: { text?: string }) {
45
49
  this.structuredContent = structuredContent;
46
50
  this.text = options?.text ?? JSON.stringify(structuredContent);
47
51
  }
@@ -51,12 +55,12 @@ export class UIResponse {
51
55
  *
52
56
  * @param structuredContent - The structured data the app UI will render.
53
57
  * @param options - Optional model-facing text (see the constructor).
54
- * @returns A new `UIResponse`.
58
+ * @returns A new `UIResponse` whose `structuredContent` type is inferred from the argument.
55
59
  */
56
- static from(
57
- structuredContent: Record<string, unknown>,
60
+ static from<T extends Record<string, unknown>>(
61
+ structuredContent: T,
58
62
  options?: { text?: string },
59
- ): UIResponse {
63
+ ): UIResponse<T> {
60
64
  return new UIResponse(structuredContent, options);
61
65
  }
62
66
 
@@ -66,7 +70,7 @@ export class UIResponse {
66
70
  *
67
71
  * @returns The `structuredContent` object.
68
72
  */
69
- toJSON(): Record<string, unknown> {
73
+ toJSON(): T {
70
74
  return this.structuredContent;
71
75
  }
72
76
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "keryx",
3
- "version": "0.36.1",
3
+ "version": "0.37.0",
4
4
  "module": "index.ts",
5
5
  "type": "module",
6
6
  "license": "MIT",
package/util/mcpServer.ts CHANGED
@@ -363,9 +363,24 @@ export async function adoptMcpSession(
363
363
  * Actions with `mcp.tool === false` are excluded from tool registration.
364
364
  */
365
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);
366
370
  const mcpServer = new McpServer(
367
371
  { name: pkg.name, version: pkg.version },
368
- { instructions: config.server.mcp.instructions },
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
+ },
369
384
  );
370
385
 
371
386
  registerTools(mcpServer);
@@ -376,6 +391,12 @@ export function createMcpServer(): McpServer {
376
391
  return mcpServer;
377
392
  }
378
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
+
379
400
  /**
380
401
  * Compute the `ui://` resource URI for an action's MCP App.
381
402
  * Defaults to `ui://<tool-name>` when `mcp.ui.resourceUri` is not set.
@@ -496,6 +517,8 @@ function registerTools(mcpServer: McpServer) {
496
517
 
497
518
  // MCP App responses carry both a text block (added to model context)
498
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.
499
522
  if (response instanceof UIResponse) {
500
523
  return {
501
524
  content: [{ type: "text" as const, text: response.text }],
@@ -134,6 +134,10 @@ export function typeToJsonSchema(
134
134
 
135
135
  if (!propType) continue;
136
136
 
137
+ // Skip methods — they are not JSON-serializable data and would otherwise
138
+ // leak into the response schema as empty objects (e.g. a `toJSON` helper).
139
+ if (propType.getCallSignatures().length > 0) continue;
140
+
137
141
  properties[propName] = typeToJsonSchema(propType, newVisited);
138
142
 
139
143
  // Check if property is optional