@punica/form-mcp 0.3.1 → 0.4.0-next.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.
Files changed (64) hide show
  1. package/README.md +8 -6
  2. package/bundled/form/controller/index.d.ts +6 -0
  3. package/bundled/form/define/Form.d.ts +41 -0
  4. package/bundled/form/define/index.d.ts +2 -0
  5. package/bundled/form/model/command/service.d.ts +7 -1
  6. package/bundled/form/model/constants/index.d.ts +4 -0
  7. package/bundled/form/model/form/index.d.ts +32 -0
  8. package/bundled/form/model/item/index.d.ts +35 -2
  9. package/bundled/form/package.json +1 -1
  10. package/bundled/form/utils/deepCopy.d.ts +2 -1
  11. package/bundled/form/utils/index.d.ts +1 -0
  12. package/bundled/form/utils/isEqual.d.ts +7 -0
  13. package/bundled/form-json/conditions.d.ts +8 -0
  14. package/bundled/form-json/definition/fromJsonSchema.d.ts +22 -0
  15. package/bundled/form-json/definition/index.d.ts +6 -0
  16. package/bundled/form-json/definition/limits.d.ts +31 -0
  17. package/bundled/form-json/definition/schema.d.ts +202 -0
  18. package/bundled/form-json/definition/types.d.ts +87 -0
  19. package/bundled/form-json/definition/validate.d.ts +15 -0
  20. package/bundled/form-json/fromSchema.d.ts +50 -0
  21. package/bundled/form-json/index.d.ts +4 -0
  22. package/bundled/form-json/package.json +1 -0
  23. package/bundled/form-json/rules.d.ts +19 -0
  24. package/bundled/form-kit/decorators.d.ts +39 -1
  25. package/bundled/form-kit/json/index.d.ts +33 -0
  26. package/bundled/form-kit/package.json +1 -1
  27. package/bundled/form-kit/react/FieldList.d.ts +33 -0
  28. package/bundled/form-kit/react/Rows.d.ts +9 -0
  29. package/bundled/form-kit/react/fields.d.ts +5 -11
  30. package/bundled/form-kit/react/index.d.ts +5 -4
  31. package/bundled/form-kit/types.d.ts +45 -3
  32. package/bundled/form-kit/validation.d.ts +4 -0
  33. package/bundled/form-react/index.d.ts +3 -0
  34. package/bundled/form-react/package.json +1 -1
  35. package/bundled/form-react/useController.d.ts +15 -0
  36. package/bundled/form-react/useFieldArray.d.ts +34 -0
  37. package/bundled/form-react/useFormController.d.ts +2 -7
  38. package/bundled/form-react/useFormState.d.ts +7 -0
  39. package/bundled/form-schema/decorator.d.ts +26 -0
  40. package/bundled/form-schema/index.d.ts +11 -0
  41. package/bundled/form-schema/issues.d.ts +22 -0
  42. package/bundled/form-schema/package.json +1 -0
  43. package/bundled/form-schema/schema.d.ts +17 -0
  44. package/bundled/form-schema/service.d.ts +27 -0
  45. package/bundled/form-schema/standard.d.ts +30 -0
  46. package/bundled/form-service/fieldArray/index.d.ts +47 -0
  47. package/bundled/form-service/formValidation.d.ts +36 -0
  48. package/bundled/form-service/index.d.ts +13 -0
  49. package/bundled/form-service/message.d.ts +2 -0
  50. package/bundled/form-service/package.json +1 -1
  51. package/bundled/form-service/readValues.d.ts +6 -0
  52. package/bundled/form-service/rows.d.ts +67 -0
  53. package/bundled/form-service/setValue/index.d.ts +1 -0
  54. package/bundled/form-service/submit/index.d.ts +20 -0
  55. package/bundled/form-service/touch/index.d.ts +13 -0
  56. package/bundled/form-service/trigger/index.d.ts +3 -0
  57. package/bundled/form-service/validate/index.d.ts +2 -1
  58. package/bundled/form-service/validateItem.d.ts +25 -9
  59. package/bundled/form-service/valuesOf.d.ts +3 -0
  60. package/package.json +7 -5
  61. package/src/create.mjs +78 -3
  62. package/src/guide.md +156 -8
  63. package/src/load.mjs +7 -2
  64. package/src/main.mjs +5 -2
@@ -0,0 +1,36 @@
1
+ import { CommandService, FormItem } from '@punica/form';
2
+ /**
3
+ * A validation of a form as a whole: returns the messages of what is wrong,
4
+ * none for a valid form.
5
+ */
6
+ export type FormValidation = () => string[] | Promise<string[]>;
7
+ /**
8
+ * Adds a validation of the form as a whole, for what does not belong to one
9
+ * item, such as two dates that have to be in order. A service adds it when
10
+ * it is initialized. `Validate` and `Submit` run it after the items: its
11
+ * messages are added to the errors of the form (`state.errors`), and a form
12
+ * that has some is not valid (`state.valid`) and not submitted. `Reset` and
13
+ * `ClearErrors` remove them.
14
+ * @param command - What the service received when it was initialized
15
+ */
16
+ export declare const addFormValidation: <E, F extends FormItem<E>>(command: CommandService<E, F>, validation: FormValidation) => void;
17
+ /**
18
+ * What tells a validation of the form that the form was reset since:
19
+ * read it before validating the items and give it to `validateForm`.
20
+ */
21
+ export declare const formEpoch: (command: object) => number;
22
+ /**
23
+ * Runs the validations of the form as a whole and writes their messages
24
+ * among the errors of the form; the other errors, such as the one of a
25
+ * rejected submit, stay. A form without such validations is left alone.
26
+ * @param epoch - `formEpoch` from before the items were validated
27
+ * @returns Whether there is no message. `false` as well when the form was
28
+ * reset meanwhile
29
+ */
30
+ export declare const validateForm: <E, F extends FormItem<E>>(command: CommandService<E, F>, epoch?: number) => Promise<boolean>;
31
+ /**
32
+ * Removes the messages of the validations of the form as a whole.
33
+ * @param reset - The form is reset: validations that are running do not
34
+ * count any more
35
+ */
36
+ export declare const clearFormValidation: <E, F extends FormItem<E>>(command: CommandService<E, F>, reset?: boolean) => void;
@@ -1,29 +1,42 @@
1
1
  import type { FormItem } from '@punica/form';
2
2
  import type { ClearError } from './clearError';
3
3
  import type { ClearErrors } from './clearErrors';
4
+ import type { FieldArray } from './fieldArray';
4
5
  import type { GetValues } from './getValues';
5
6
  import type { Reset } from './reset';
6
7
  import type { ResetItem } from './resetItem';
7
8
  import type { SetValue } from './setValue';
9
+ import type { Submit } from './submit';
10
+ import type { Touch } from './touch';
8
11
  import type { Trigger } from './trigger';
9
12
  import type { Validate } from './validate';
10
13
  export * from './clearError';
11
14
  export * from './clearErrors';
15
+ export * from './fieldArray';
16
+ export { addFormValidation } from './formValidation';
17
+ export { wrapValidation } from './rows';
18
+ export type { FormValidation } from './formValidation';
19
+ export type { FormRow } from './rows';
12
20
  export * from './getValues';
13
21
  export * from './reset';
14
22
  export * from './resetItem';
15
23
  export * from './setValue';
16
24
  export * from './store';
25
+ export * from './submit';
26
+ export * from './touch';
17
27
  export * from './trigger';
18
28
  export * from './validate';
19
29
  declare module '@punica/form' {
20
30
  interface ServiceRegistry<E, F extends FormItem<E>> {
21
31
  clearError: ClearError<E, F>;
22
32
  clearErrors: ClearErrors<E, F>;
33
+ fieldArray: FieldArray<E, F>;
23
34
  getValues: GetValues<E, F>;
24
35
  reset: Reset<E, F>;
25
36
  resetItem: ResetItem<E, F>;
26
37
  setValue: SetValue<E, F>;
38
+ submit: Submit<E, F>;
39
+ touch: Touch<E, F>;
27
40
  trigger: Trigger<E, F>;
28
41
  validate: Validate<E, F>;
29
42
  }
@@ -0,0 +1,2 @@
1
+ /** What a form shows for something that was thrown. */
2
+ export declare const messageOf: (error: unknown) => string;
@@ -1 +1 @@
1
- {"version":"2.1.1"}
1
+ {"version":"2.2.0-next.1"}
@@ -0,0 +1,6 @@
1
+ import { CommandService, FormItem } from '@punica/form';
2
+ /**
3
+ * A copy of the entity the form was created from, holding the current
4
+ * values. The entity itself is never changed.
5
+ */
6
+ export declare const readValues: <E, F extends FormItem<E>>(command: CommandService<E, F>) => E;
@@ -0,0 +1,67 @@
1
+ import { CommandService, FormController, FormItem, IService } from '@punica/form';
2
+ /**
3
+ * A row of a list: a form of its own. `key` identifies the row for as long
4
+ * as it is part of the list, wherever it is moved to.
5
+ */
6
+ export type FormRow<R extends object = object, F extends FormItem<R> = FormItem<R>> = {
7
+ key: string;
8
+ controller: FormController<R, F>;
9
+ };
10
+ type AnyRow = FormRow<any, any>;
11
+ /** Whether the item of a property is a list whose rows were created. */
12
+ export declare const hasRows: (command: object, property: PropertyKey) => boolean;
13
+ /** The properties of the lists of a form. */
14
+ export declare const listProperties: (command: object) => PropertyKey[];
15
+ /**
16
+ * The rows of a list.
17
+ * @throws When the item of the property is not a list
18
+ */
19
+ export declare const rowsOf: (command: object, property: PropertyKey) => readonly AnyRow[];
20
+ /**
21
+ * Creates the rows of every list of a form from the values of their items.
22
+ * @param validate - The class of the service a row is validated with: the
23
+ * validation of the item of a list also validates its rows. A row whose
24
+ * class lists services of its own, without that one, counts as valid
25
+ */
26
+ export declare const createLists: <E, F extends FormItem<E>>(command: CommandService<E, F>, validate: new () => IService & {
27
+ run: () => Promise<boolean>;
28
+ }) => Promise<void>;
29
+ /**
30
+ * Wraps the validations of the items of a form, for a service that adds a
31
+ * validation of its own to them. It works with lists whatever the order of
32
+ * the services: the validation of a list item is wrapped inside the
33
+ * validation of its rows, so what it finds stays while the rows change.
34
+ * @param wrap - Returns the new validation of an item for its current one
35
+ */
36
+ export declare const wrapValidation: <E, F extends FormItem<E>>(command: CommandService<E, F>, wrap: (item: F, validation: F["validation"]) => F["validation"]) => void;
37
+ /**
38
+ * Adds a row to a list.
39
+ * @param index - Where; at the end when it is left out
40
+ */
41
+ export declare const insertRow: <E, F extends FormItem<E>>(command: CommandService<E, F>, property: keyof E, value?: object, index?: number) => Promise<AnyRow>;
42
+ /** Removes a row from a list: the row itself or the one at an index. */
43
+ export declare const removeRow: <E, F extends FormItem<E>>(command: CommandService<E, F>, property: keyof E, row: AnyRow | number) => Promise<void>;
44
+ /** Moves the row at an index of a list to another one. */
45
+ export declare const moveRow: <E, F extends FormItem<E>>(command: CommandService<E, F>, property: keyof E, from: number, to: number) => Promise<void>;
46
+ /** Replaces the rows of a list by rows for the values. */
47
+ export declare const replaceRows: <E, F extends FormItem<E>>(command: CommandService<E, F>, property: keyof E, values: unknown) => Promise<void>;
48
+ /**
49
+ * Brings the rows of a list, or of every list, back to the ones the form
50
+ * was started with. The items of the lists are not written until that is
51
+ * done; the caller resets them meanwhile.
52
+ * @returns `undefined`, at once, for a form without lists
53
+ */
54
+ export declare const resetRows: <E, F extends FormItem<E>>(command: CommandService<E, F>, property?: keyof E) => Promise<void> | undefined;
55
+ /**
56
+ * The service of a class of the form of a row; `undefined` when the row
57
+ * does not have it.
58
+ */
59
+ export declare const serviceOf: <S extends IService>(row: AnyRow, service: new () => S) => S | undefined;
60
+ /**
61
+ * Clears the errors of the rows of a list, or of every list, of a form and
62
+ * forgets the result of the validation of the items of the lists.
63
+ * @param clear - Clears the errors of a row
64
+ * @returns `undefined`, at once, for a form without lists
65
+ */
66
+ export declare const clearRows: <E, F extends FormItem<E>>(command: CommandService<E, F>, property: keyof E | undefined, clear: (row: AnyRow) => unknown) => Promise<void> | undefined;
67
+ export {};
@@ -10,6 +10,7 @@ export declare class SetValue<E, F extends FormItem<E> = FormItem<E>> implements
10
10
  * Fires UPDATE_ITEM with the changed item and the items its control returned.
11
11
  * When the property is set again, or the form is reset, while the control
12
12
  * function is still running, the result of that older run is dropped.
13
+ * The value of a list replaces its rows.
13
14
  * @throws When the form has no item for the property
14
15
  */
15
16
  run(property: keyof E, value: unknown): Promise<void>;
@@ -0,0 +1,20 @@
1
+ import { CommandService, FormItem, IServiceControl, IServiceInitialize } from '@punica/form';
2
+ /**
3
+ * Submits the form: validates it and gives its values to a handler.
4
+ */
5
+ export declare class Submit<E, F extends FormItem<E> = FormItem<E>> implements IServiceInitialize<E, F>, IServiceControl {
6
+ #private;
7
+ get name(): string;
8
+ initialize(command: CommandService<E, F>): void;
9
+ /**
10
+ * Validates every item and, when the form is valid, calls the handler with
11
+ * its values and fires SUBMIT. While it runs the state of the form is
12
+ * `submitting`; a submit that is started meanwhile is ignored.
13
+ *
14
+ * What the handler or a validation throws does not reject: the message of
15
+ * the error, or a general one when it has none, becomes an error of the
16
+ * form (`state.errors`) and SUBMIT_ERROR is fired.
17
+ * @returns Whether the form was valid and the handler finished
18
+ */
19
+ run(handler?: (values: E) => void | Promise<void>): Promise<boolean>;
20
+ }
@@ -0,0 +1,13 @@
1
+ import { CommandService, FormItem, IServiceControl, IServiceInitialize } from '@punica/form';
2
+ /**
3
+ * Marks an item as touched: the user has left its field.
4
+ */
5
+ export declare class Touch<E, F extends FormItem<E> = FormItem<E>> implements IServiceInitialize<E, F>, IServiceControl {
6
+ #private;
7
+ get name(): string;
8
+ initialize(command: CommandService<E, F>): void;
9
+ /**
10
+ * @throws When the form has no item for the property
11
+ */
12
+ run(property: keyof E): Promise<void>;
13
+ }
@@ -7,6 +7,9 @@ export declare class Trigger<E, F extends FormItem<E> = FormItem<E>> implements
7
7
  get name(): string;
8
8
  initialize(command: CommandService<E, F>): void;
9
9
  /**
10
+ * Waits for `validateDebounce` of the item first, when it has one; the
11
+ * validation is skipped when the item is triggered again, validated,
12
+ * changed or reset meanwhile.
10
13
  * @throws When the form has no item for the property
11
14
  */
12
15
  run(property: keyof E): Promise<void>;
@@ -7,7 +7,8 @@ export declare class Validate<E, F extends FormItem<E> = FormItem<E>> implements
7
7
  get name(): string;
8
8
  initialize(command: CommandService<E, F>): void;
9
9
  /**
10
- * @returns Whether every validated item is valid
10
+ * @returns Whether every validated item is valid, and the form as a
11
+ * whole when it has validations of its own (`addFormValidation`)
11
12
  */
12
13
  run(): Promise<boolean>;
13
14
  }
@@ -1,16 +1,32 @@
1
- import { CommandService, ErrorDetail, FormItem } from '@punica/form';
1
+ import { CommandService, FormItem } from '@punica/form';
2
2
  /**
3
- * Tells the validations of a form that are still running that their results
4
- * are stale: of one property, or of every property.
3
+ * Cancels the validations of a form that are running or waiting for their
4
+ * delay: of one property, or of every property. Their `signal` is aborted
5
+ * and their results are not written.
5
6
  */
6
7
  export declare const dropValidations: <E, F extends FormItem<E>>(command: CommandService<E, F>, property?: keyof E) => void;
7
8
  /**
8
- * Validates items one after the other and writes the results onto the items
9
- * as they are now: an item may have changed while it was validated, and only
10
- * its error state is what the validation knows. A result is not written when
11
- * it is stale: the value changed, the item was validated again or reset.
9
+ * Waits for the delay of a validation (`validateDebounce` of the item).
10
+ * @returns Whether to validate: `false` when the property was validated,
11
+ * changed again or reset before the delay was over
12
+ */
13
+ export declare const delayValidation: <E, F extends FormItem<E>>(command: CommandService<E, F>, property: keyof E, milliseconds: number) => Promise<boolean>;
14
+ /**
15
+ * Validates items one after the other, each as it is when its turn comes,
16
+ * and writes the results onto the items as they are then: only the error
17
+ * state is what a validation knows.
18
+ *
19
+ * A validation is cancelled when its item is validated again, changed or
20
+ * reset. The validation that replaced it counts then. When a verdict on the
21
+ * items is asked for, an item that changed is validated again with its new
22
+ * value; otherwise it is left alone. A result is never written onto a value
23
+ * it was not made for. Items that take a while are `validating`.
24
+ *
12
25
  * Items without a validation function, hidden items and disabled items are
13
26
  * not validated.
14
- * @returns The results, by the property of the validated items
27
+ * @returns Whether every validated item is valid. `false` as well when the
28
+ * form was reset meanwhile
15
29
  */
16
- export declare const validateItems: <E, F extends FormItem<E>>(command: CommandService<E, F>, items: F[]) => Promise<Map<keyof E, ErrorDetail>>;
30
+ export declare const validateItems: <E, F extends FormItem<E>>(command: CommandService<E, F>, items: F[], { verdict }?: {
31
+ verdict?: boolean;
32
+ }) => Promise<boolean>;
@@ -0,0 +1,3 @@
1
+ import { FormItem } from '@punica/form';
2
+ /** A copy of an entity that holds the values of the items of its form. */
3
+ export declare const valuesOf: <E>(initial: E, items: Array<FormItem<E>>) => E;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@punica/form-mcp",
3
- "version": "0.3.1",
3
+ "version": "0.4.0-next.1",
4
4
  "description": "MCP server for Punica Form: look up the exact API of its packages, read the rules and check code that uses them.",
5
5
  "keywords": [
6
6
  "mcp",
@@ -36,13 +36,15 @@
36
36
  },
37
37
  "dependencies": {
38
38
  "@modelcontextprotocol/sdk": "^1.32.2",
39
+ "@punica/form-json": "^0.1.0-next.0",
39
40
  "zod": "^4.6.7"
40
41
  },
41
42
  "devDependencies": {
42
- "@punica/form": "^2.1.1",
43
- "@punica/form-service": "^2.1.1",
44
- "@punica/form-react": "^0.1.1",
45
- "@punica/form-kit": "^0.2.0"
43
+ "@punica/form": "^2.2.0-next.1",
44
+ "@punica/form-service": "^2.2.0-next.1",
45
+ "@punica/form-react": "^0.2.0-next.1",
46
+ "@punica/form-kit": "^0.3.0-next.1",
47
+ "@punica/form-schema": "^0.1.0-next.0"
46
48
  },
47
49
  "scripts": {
48
50
  "build": "node build.mjs",
package/src/create.mjs CHANGED
@@ -2,12 +2,22 @@
2
2
  // its rules and the code validator. Transport-free, so tests connect it to
3
3
  // an in-memory client.
4
4
  import { McpServer, ResourceTemplate } from '@modelcontextprotocol/sdk/server/mcp.js';
5
+ import { fromJsonSchema, formDefinitionSchema, validateDefinition } from '@punica/form-json/definition';
5
6
  import { z } from 'zod';
7
+ import { readFileSync } from 'node:fs';
6
8
  import { createKnowledge } from './knowledge.mjs';
7
9
  import { createValidator } from './validate.mjs';
8
10
 
11
+ const { version } = JSON.parse(readFileSync(new URL('../package.json', import.meta.url), 'utf8'));
12
+
9
13
  const text = (value) => ({ content: [{ type: 'text', text: value }] });
10
14
 
15
+ /** The types a form definition may use when the form kit renders it. */
16
+ const KIT_TYPES = ['text', 'textarea', 'number', 'select', 'checkbox', 'switch', 'radio', 'date', 'multiselect', 'password', 'file'];
17
+
18
+ /** A tool argument that is JSON: given as an object, or as its text. */
19
+ const parse = (value) => (typeof value === 'string' ? JSON.parse(value) : value);
20
+
11
21
  /**
12
22
  * @param {{ packages: Array<Parameters<typeof createKnowledge>[0][number] & { installed?: boolean }>, guide: string }} options
13
23
  * `installed` says whether the declarations come from the project or from
@@ -29,9 +39,9 @@ export function createPunicaFormServer({ packages, guide }) {
29
39
  : '';
30
40
 
31
41
  const server = new McpServer(
32
- { name: 'punica-form', version: '0.3.0' },
42
+ { name: 'punica-form', version },
33
43
  {
34
- instructions: `${legacyNote}${versions}. Punica Form is a headless form engine and is rarely in training data: never write an import, a service name or a method from memory. Read get_guide first, look names up with search_api and get_api, and check the code with validate_code before handing it over.`
44
+ instructions: `${legacyNote}${versions}. Punica Form is a headless form engine and is rarely in training data: never write an import, a service name or a method from memory. Read get_guide first, look names up with search_api and get_api, and check the code with validate_code before handing it over. To produce a form at run time as data instead of code, read get_form_schema and check the definition with validate_form.`
35
45
  }
36
46
  );
37
47
 
@@ -52,7 +62,7 @@ export function createPunicaFormServer({ packages, guide }) {
52
62
  {
53
63
  title: 'Find Punica Form exports',
54
64
  description:
55
- 'Finds exports of the Punica Form packages (@punica/form, @punica/form-service, @punica/form-react, @punica/form-kit) by name or by words in their documentation ("validate", "reader", "field"). Without a query: every export.',
65
+ 'Finds exports of the Punica Form packages (@punica/form, @punica/form-service, @punica/form-react, @punica/form-kit, @punica/form-json, @punica/form-schema) by name or by words in their documentation ("validate", "reader", "field"). Without a query: every export.',
56
66
  inputSchema: { query: z.string().optional().describe('Words to look for') },
57
67
  annotations: { readOnlyHint: true }
58
68
  },
@@ -108,6 +118,71 @@ export function createPunicaFormServer({ packages, guide }) {
108
118
  }
109
119
  );
110
120
 
121
+ server.registerTool(
122
+ 'get_form_schema',
123
+ {
124
+ title: 'The format of a form described as data',
125
+ description:
126
+ 'The JSON Schema of a Punica Form definition (@punica/form-json): a form as JSON that an application renders at run time, without code. Read it before writing a form definition, and use it as the schema of structured output.',
127
+ inputSchema: {},
128
+ annotations: { readOnlyHint: true }
129
+ },
130
+ async () =>
131
+ text(
132
+ [
133
+ `Types the form kit renders: ${KIT_TYPES.join(', ')}. An application may have its own.`,
134
+ 'Rules: required, email, integer, min, max, minLength, maxLength, pattern; `value` holds the limit. An application may have more.',
135
+ 'Conditions (visibleWhen, disabledWhen) compare the value of another item: { property, equals | notEquals | in }, combined with { all: [...] } and { any: [...] }.',
136
+ 'A definition holds no code: no functions, no expressions, no HTML. Check it with validate_form.',
137
+ '',
138
+ JSON.stringify(formDefinitionSchema, null, 2)
139
+ ].join('\n')
140
+ )
141
+ );
142
+
143
+ server.registerTool(
144
+ 'validate_form',
145
+ {
146
+ title: 'Check a form definition',
147
+ description:
148
+ 'Checks a form definition (the JSON of @punica/form-json) before it is given to an application: its shape, unknown types and rules, conditions that point to items that do not exist, duplicate properties and anything that is not data. Returns each problem with its path. Give `json_schema` instead to turn a flat JSON Schema into a form definition.',
149
+ inputSchema: {
150
+ definition: z.unknown().optional().describe('The form definition, as an object or as JSON text'),
151
+ json_schema: z.unknown().optional().describe('A JSON Schema to convert into a form definition instead'),
152
+ types: z.array(z.string()).optional().describe('The types the application renders; the types of the form kit by default'),
153
+ rules: z.array(z.string()).optional().describe('Names of rules the application has besides the built-in ones')
154
+ },
155
+ annotations: { readOnlyHint: true }
156
+ },
157
+ async ({ definition, json_schema: schema, types = KIT_TYPES, rules }) => {
158
+ let converted = '';
159
+
160
+ try {
161
+ if (schema !== undefined) {
162
+ definition = fromJsonSchema(parse(schema));
163
+ converted = `\n\n${JSON.stringify(definition, null, 2)}`;
164
+ } else {
165
+ definition = parse(definition);
166
+ }
167
+ } catch (error) {
168
+ return text(`Not usable: ${error.message}`);
169
+ }
170
+
171
+ const problems = validateDefinition(definition, { types, rules });
172
+
173
+ if (!problems.length) {
174
+ return text(`No problems: the form definition is valid.${converted}`);
175
+ }
176
+
177
+ return text(
178
+ [
179
+ `${problems.length} problem${problems.length === 1 ? '' : 's'}:`,
180
+ ...problems.map(({ path, message }) => `${path || 'definition'} ${message}`)
181
+ ].join('\n') + converted
182
+ );
183
+ }
184
+ );
185
+
111
186
  server.registerResource(
112
187
  'guide',
113
188
  'punica-form://guide',