Skip to main content
Glama

generate_schema

Generate JSON-LD structured data for Schema.org types like Person, Product, and FAQPage using key-value field pairs to create semantic markup.

Instructions

Generate JSON-LD structured data for any Schema.org type. Provide the schema type and a set of key-value field pairs.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
typeYesThe Schema.org type to generate
fieldsYesKey-value pairs of schema fields and their values

Implementation Reference

  • The generate_schema tool is defined and implemented here, using an asynchronous handler to process different Schema.org types and generate the appropriate JSON-LD structure.
    server.tool(
      "generate_schema",
      "Generate JSON-LD structured data for any Schema.org type. Provide the schema type and a set of key-value field pairs.",
      {
        type: z
          .enum([
            "Person",
            "Organization",
            "Product",
            "FAQPage",
            "Article",
            "LocalBusiness",
            "Event",
            "WebSite",
            "BreadcrumbList",
            "HowTo",
            "Review",
            "VideoObject",
          ])
          .describe("The Schema.org type to generate"),
        fields: z
          .record(z.string(), z.unknown())
          .describe("Key-value pairs of schema fields and their values"),
      },
      async ({ type, fields }) => {
        let schema: object;
    
        if (type === "FAQPage" && fields.questions) {
          schema = buildFaqSchema({
            questions: fields.questions as Array<{ question: string; answer: string }>,
          });
        } else if (type === "BreadcrumbList" && fields.items) {
          const items = fields.items as Array<{ name: string; url: string }>;
          schema = {
            "@context": "https://schema.org",
            "@type": "BreadcrumbList",
            itemListElement: items.map((item, index) => ({
              "@type": "ListItem",
              position: index + 1,
              name: item.name,
              item: item.url,
            })),
          };
        } else if (type === "HowTo" && fields.steps) {
          const steps = fields.steps as Array<{
            name: string;
            text: string;
            image?: string;
            url?: string;
          }>;
          const howToFields: Record<string, unknown> = { ...fields };
          delete howToFields.steps;
          howToFields.step = steps.map((step, index) => ({
            "@type": "HowToStep",
            position: index + 1,
            name: step.name,
            text: step.text,
            ...(step.image ? { image: step.image } : {}),
            ...(step.url ? { url: step.url } : {}),
          }));
          schema = buildJsonLd(type, howToFields);
        } else {
          schema = buildJsonLd(type, fields);
        }
    
        return {
          content: [
            {
              type: "text" as const,
              text: JSON.stringify(schema, null, 2),
            },
          ],
        };
      }
    );

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/sharozdawa/schema-gen'

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