Skip to main content
Glama

validate_schema

Validate JSON-LD schemas by checking required fields, proper @context, valid @type, and identifying common issues to ensure schema compliance.

Instructions

Validate an existing JSON-LD schema. Checks for required fields, proper @context, valid @type, and common issues.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
jsonYesJSON-LD string to validate

Implementation Reference

  • The 'validateSchema' function implements the validation logic for the 'validate_schema' tool, checking for JSON format, '@context', '@type', and type-specific fields.
    function validateSchema(jsonString: string): {
      valid: boolean;
      errors: string[];
      warnings: string[];
    } {
      const errors: string[] = [];
      const warnings: string[] = [];
    
      let parsed: unknown;
      try {
        parsed = JSON.parse(jsonString);
      } catch {
        return {
          valid: false,
          errors: ["Invalid JSON: unable to parse the provided string"],
          warnings: [],
        };
      }
    
      if (typeof parsed !== "object" || parsed === null || Array.isArray(parsed)) {
        return {
          valid: false,
          errors: ["JSON-LD must be a JSON object (not an array or primitive)"],
          warnings: [],
        };
      }
    
      const schema = parsed as Record<string, unknown>;
    
      if (!schema["@context"]) {
        errors.push('Missing required field: @context (should be "https://schema.org")');
      } else if (schema["@context"] !== "https://schema.org") {
        warnings.push(
          `@context is "${schema["@context"]}" — recommended value is "https://schema.org"`
        );
      }
    
      if (!schema["@type"]) {
        errors.push("Missing required field: @type");
      } else {
        const type = schema["@type"] as string;
        const supportedTypes = Object.keys(SCHEMA_TYPES);
        if (!supportedTypes.includes(type)) {
          warnings.push(
            `@type "${type}" is not in the commonly supported types: ${supportedTypes.join(", ")}`
          );
        }
    
        // Type-specific required field checks
        if (type === "Person" && !schema.name) {
          errors.push("Person schema requires a 'name' field");
        }
  • Registration of the 'validate_schema' tool, which wraps the 'validateSchema' handler function and takes 'json' as an input parameter.
    server.tool(
      "validate_schema",
      "Validate an existing JSON-LD schema. Checks for required fields, proper @context, valid @type, and common issues.",
      {
        json: z
          .string()
          .describe("JSON-LD string to validate"),
      },
      async ({ json }) => {
        const result = validateSchema(json);

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