generate_schema
Create JSON Schema, TypeScript interfaces, or Zod validation schemas from natural language descriptions of data structures like user profiles or product listings.
Instructions
Generate a JSON Schema, TypeScript interface, or Zod validation schema from a natural language description of a data structure. Examples: 'a user profile with name, email, and signup date', 'a product listing with title, price, and inventory count'.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| description | Yes | Natural language description of the data structure you want a schema for | |
| format | No | Output format: json_schema (standard JSON Schema), typescript (TS interface), or zod (Zod validation schema) | json_schema |
| strict | No | If true, all fields are required. If false, optional fields are marked as optional |
Implementation Reference
- mcp-server/src/index.ts:59-111 (registration)Registration and implementation of the "generate_schema" tool. It calls the remote API "schema-generator".
server.registerTool( "generate_schema", { title: "Schema Generator", description: "Generate a JSON Schema, TypeScript interface, or Zod validation schema from a natural language description of a data structure. " + "Examples: 'a user profile with name, email, and signup date', 'a product listing with title, price, and inventory count'.", inputSchema: { description: z .string() .describe( "Natural language description of the data structure you want a schema for" ), format: z .enum(["json_schema", "zod", "typescript"]) .default("json_schema") .describe( "Output format: json_schema (standard JSON Schema), typescript (TS interface), or zod (Zod validation schema)" ), strict: z .boolean() .default(true) .describe( "If true, all fields are required. If false, optional fields are marked as optional" ), }, }, async ({ description, format, strict }) => { const result = await callToolApi("schema-generator", { description, format, strict, }); const data = result as any; const schema = data.result?.schema; // Format output nicely for the LLM const output = typeof schema === "string" ? schema : JSON.stringify(schema, null, 2); return { content: [ { type: "text" as const, text: `Generated ${format || "json_schema"} schema:\n\n\`\`\`${format === "typescript" ? "typescript" : format === "zod" ? "typescript" : "json"}\n${output}\n\`\`\`\n\nGenerated in ${data.durationMs}ms.`, }, ], }; } );