MCPcopy Create free account
hub / github.com/bytebase/dbhub / zodToParameters

Function zodToParameters

src/utils/tool-metadata.ts:74–107  ·  view source on GitHub ↗
(schema: Record<string, z.ZodType<any>>)

Source from the content-addressed store, hash-verified

72 * @returns Array of tool parameters
73 */
74export function zodToParameters(schema: Record<string, z.ZodType<any>>): ToolParameter[] {
75 const parameters: ToolParameter[] = [];
76
77 for (const [key, zodType] of Object.entries(schema)) {
78 // Extract description from Zod schema
79 const description = zodType.description || "";
80
81 // Determine if required (Zod types are required by default unless optional)
82 const required = !(zodType instanceof z.ZodOptional);
83
84 // Determine type from Zod type
85 let type = "string"; // default
86 if (zodType instanceof z.ZodString) {
87 type = "string";
88 } else if (zodType instanceof z.ZodNumber) {
89 type = "number";
90 } else if (zodType instanceof z.ZodBoolean) {
91 type = "boolean";
92 } else if (zodType instanceof z.ZodArray) {
93 type = "array";
94 } else if (zodType instanceof z.ZodObject) {
95 type = "object";
96 }
97
98 parameters.push({
99 name: key,
100 type,
101 required,
102 description,
103 });
104 }
105
106 return parameters;
107}
108
109/**
110 * Get execute_sql tool metadata for a specific source

Callers 1

buildExecuteSqlToolFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected