Skip to main content
Glama

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
NameRequiredDescriptionDefault
descriptionYesNatural language description of the data structure you want a schema for
formatNoOutput format: json_schema (standard JSON Schema), typescript (TS interface), or zod (Zod validation schema)json_schema
strictNoIf true, all fields are required. If false, optional fields are marked as optional

Implementation Reference

  • 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.`,
            },
          ],
        };
      }
    );

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/marras0914/agent-toolbelt'

If you have feedback or need assistance with the MCP directory API, please join our Discord server