mirror of
https://github.com/shishantbiswas/bknd.git
synced 2026-03-18 05:16:04 +00:00
initialized mcp support
This commit is contained in:
51
app/src/modules/mcp/utils.ts
Normal file
51
app/src/modules/mcp/utils.ts
Normal file
@@ -0,0 +1,51 @@
|
||||
import * as s from "jsonv-ts";
|
||||
import { isPlainObject, transformObject } from "bknd/utils";
|
||||
|
||||
export function rescursiveClean(
|
||||
input: s.Schema,
|
||||
opts?: {
|
||||
removeRequired?: boolean;
|
||||
removeDefault?: boolean;
|
||||
},
|
||||
): s.Schema {
|
||||
const json = input.toJSON();
|
||||
|
||||
const removeRequired = (obj: any) => {
|
||||
if (isPlainObject(obj)) {
|
||||
if ("required" in obj && opts?.removeRequired) {
|
||||
obj.required = undefined;
|
||||
}
|
||||
|
||||
if ("default" in obj && opts?.removeDefault) {
|
||||
obj.default = undefined;
|
||||
}
|
||||
|
||||
if ("properties" in obj && isPlainObject(obj.properties)) {
|
||||
for (const key in obj.properties) {
|
||||
obj.properties[key] = removeRequired(obj.properties[key]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return obj;
|
||||
};
|
||||
|
||||
removeRequired(json);
|
||||
return s.fromSchema(json);
|
||||
}
|
||||
|
||||
export function excludePropertyTypes(
|
||||
input: s.ObjectSchema<any, any>,
|
||||
props: (new (...args: any[]) => s.Schema)[],
|
||||
): s.TProperties {
|
||||
const properties = { ...input.properties };
|
||||
|
||||
return transformObject(properties, (value, key) => {
|
||||
for (const prop of props) {
|
||||
if (value instanceof prop) {
|
||||
return undefined;
|
||||
}
|
||||
}
|
||||
return value;
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user