Skip to content

Commit afca690

Browse files
committed
Omit the required key when schema projection empties it
1 parent 365ed16 commit afca690

2 files changed

Lines changed: 10 additions & 3 deletions

File tree

‎packages/plugins/apps/src/plugin/apps-plugin.test.ts‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -256,8 +256,12 @@ describe("apps plugin schema projection", () => {
256256
},
257257
},
258258
},
259-
required: undefined,
260259
});
260+
// The response schema requires JSON values: a `required` key holding
261+
// undefined fails encoding (the /api/tools/schema 400), so the key must
262+
// be absent entirely when all required fields were projected away.
263+
expect("required" in (result.inputSchema as Record<string, unknown>)).toBe(false);
264+
expect(JSON.parse(JSON.stringify(result.inputSchema))).toEqual(result.inputSchema);
261265
}),
262266
);
263267
});

‎packages/plugins/apps/src/plugin/apps-plugin.ts‎

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -564,11 +564,14 @@ export const projectAppsToolSchema = (
564564
const required = Array.isArray(schema.required)
565565
? schema.required.filter((field) => !projectedFields.has(String(field)))
566566
: undefined;
567+
// Rebuild without the `required` key rather than setting it to undefined:
568+
// an explicit undefined is not a JSON value and fails response encoding.
569+
const { required: _dropped, ...rest } = schema;
567570
return {
568571
inputSchema: {
569-
...schema,
572+
...rest,
570573
properties,
571-
...(required && required.length > 0 ? { required } : { required: undefined }),
574+
...(required && required.length > 0 ? { required } : {}),
572575
},
573576
outputSchema,
574577
};

0 commit comments

Comments
 (0)