refactor(forms): hard-code output schema for signal forms WebMCP tool

Hard-code an explicit `outputSchema` for the implicitly generated signal forms WebMCP tool. This schema accurately describes the simplified success and error object returned by the tool execution, allowing AI agents to confidently interpret the results without hallucination.
This commit is contained in:
Doug Parker
2026-11-20 08:35:37 -08:00
committed by Jessica Janiuk
parent ec0f0583c3
commit 4becefe5c2
@@ -36,6 +36,20 @@ const registerWebMcpForm: RegisterWebMcpForm = (formTree, options) => {
});
};
const FORM_OUTPUT_SCHEMA = {
type: 'object',
properties: {
success: {type: 'boolean', description: 'Whether the form was submitted successfully.'},
errors: {
type: 'array',
items: {type: 'string'},
description: 'Validation error messages if the submission failed.',
},
},
required: ['success'],
additionalProperties: false,
};
async function initWebMcpForm(
formTree: FieldTree<unknown>,
options: {name: string; description: string; annotations?: {consequentialHint?: boolean}},
@@ -56,6 +70,7 @@ async function initWebMcpForm(
name: options.name,
description: options.description,
inputSchema,
outputSchema: FORM_OUTPUT_SCHEMA,
annotations: {
...options.annotations,
@@ -81,12 +96,10 @@ async function initWebMcpForm(
if (success) {
return {success: true};
} else {
const errors = node
.errorSummary()
.map((err) => {
const fieldName = (err.fieldTree() as FieldNode).structure.pathKeys().join('.');
return `${fieldName ? `${fieldName}: ` : ''}${err.message || err.kind}`;
});
const errors = node.errorSummary().map((err) => {
const fieldName = (err.fieldTree() as FieldNode).structure.pathKeys().join('.');
return `${fieldName ? `${fieldName}: ` : ''}${err.message || err.kind}`;
});
return {success: false, errors};
}
},