MCPcopy Create free account
hub / github.com/subquery/subql / zodToArgs

Function zodToArgs

packages/cli/src/adapters/utils.ts:146–187  ·  view source on GitHub ↗
(schema: ZodObject<Shape>)

Source from the content-addressed store, hash-verified

144}
145
146export function zodToArgs<Shape extends Record<string, ZodTypeAny>>(schema: ZodObject<Shape>): ArgsFromSchema<Shape> {
147 const args: Record<string, Arg<any>> = {};
148
149 for (const [key, def] of Object.entries(schema.shape)) {
150 const description = def.description ?? '';
151
152 const {array, default: defaultValue, optional, type} = unwrap(def);
153
154 if (type instanceof z.ZodString) {
155 args[key] = Args.string({
156 description,
157 required: !optional,
158 default: defaultValue,
159 multiple: array,
160 });
161 } else if (type instanceof z.ZodNumber) {
162 args[key] = Args.integer({
163 description,
164 required: !optional,
165 default: defaultValue,
166 });
167 } else if (type instanceof z.ZodBoolean) {
168 args[key] = Args.boolean({
169 description,
170 default: defaultValue,
171 multiple: array,
172 });
173 } else if (type instanceof z.ZodEnum) {
174 args[key] = Args.string({
175 description,
176 required: !optional,
177 default: defaultValue,
178 multiple: array,
179 options: type.options,
180 });
181 } else {
182 throw new Error(`Unsupported Zod type for arg: ${key}`);
183 }
184 }
185
186 return args as ArgsFromSchema<Shape>;
187}
188
189export function mcpLogger(server: McpServer['server']): Logger {
190 const log = (level: 'error' | 'debug' | 'info' | 'notice') => (input: string) => {

Callers 10

BuildManifestClass · 0.90
InitClass · 0.90
PublishClass · 0.90
BuildClass · 0.90
RemoveApiKeyClass · 0.90
CreateNetworkApiKeyClass · 0.90
MultiChainAddClass · 0.90
CodegenClass · 0.90
ImportAbiClass · 0.90

Calls 1

unwrapFunction · 0.85

Tested by

no test coverage detected