keryx 0.36.2 → 0.37.1
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/classes/UIResponse.ts +16 -12
- package/package.json +1 -1
- package/util/mcpServer.ts +11 -0
- package/util/swaggerSchemaGenerator.ts +4 -0
package/classes/UIResponse.ts
CHANGED
|
@@ -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:
|
|
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:
|
|
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():
|
|
73
|
+
toJSON(): T {
|
|
70
74
|
return this.structuredContent;
|
|
71
75
|
}
|
|
72
76
|
}
|
package/package.json
CHANGED
package/util/mcpServer.ts
CHANGED
|
@@ -534,8 +534,19 @@ function registerTools(mcpServer: McpServer) {
|
|
|
534
534
|
})
|
|
535
535
|
: JSON.stringify(response);
|
|
536
536
|
|
|
537
|
+
// Promote plain object responses to structuredContent so MCP Apps can
|
|
538
|
+
// bind without JSON.parse (same shape UIResponse already provides).
|
|
539
|
+
const structuredContent =
|
|
540
|
+
format === MCP_RESPONSE_FORMAT.JSON &&
|
|
541
|
+
response !== null &&
|
|
542
|
+
typeof response === "object" &&
|
|
543
|
+
!Array.isArray(response)
|
|
544
|
+
? (response as Record<string, unknown>)
|
|
545
|
+
: undefined;
|
|
546
|
+
|
|
537
547
|
return {
|
|
538
548
|
content: [{ type: "text" as const, text }],
|
|
549
|
+
...(structuredContent ? { structuredContent } : {}),
|
|
539
550
|
};
|
|
540
551
|
} finally {
|
|
541
552
|
connection.destroy();
|
|
@@ -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
|