MCPcopy Create free account
hub / github.com/agentrpc/agentrpc / validateFunctionSchema

Function validateFunctionSchema

sdk-node/src/util.ts:73–110  ·  view source on GitHub ↗
(
  input: JsonSchemaInput,
)

Source from the content-addressed store, hash-verified

71 * Validate a function schema.
72 */
73export const validateFunctionSchema = (
74 input: JsonSchemaInput,
75): { path: string; error: string }[] => {
76 delete input.properties?.undefined;
77
78 if (!input || !input.properties) {
79 return [{ path: "", error: "Schema must be defined" }];
80 }
81
82 const errors = Object.keys(input.properties)
83 .map((key) => {
84 return validateProperty(key, input.properties[key]);
85 })
86 .flat();
87
88 if (errors.length > 0) {
89 return errors;
90 }
91
92 const ajv = new Ajv();
93 addFormats(ajv);
94
95 try {
96 ajv.compile({
97 ...input,
98 $schema: undefined,
99 });
100 } catch (error) {
101 if (error instanceof Error) {
102 return ajvErrorToFailures(error);
103 }
104 throw new AgentRPCError("Unknown JSON schema compilation error", {
105 error,
106 });
107 }
108
109 return [];
110};
111
112/**
113 * Recursively validate $.properties

Callers 1

util.test.tsFile · 0.90

Calls 2

validatePropertyFunction · 0.85
ajvErrorToFailuresFunction · 0.85

Tested by

no test coverage detected