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
| Name | Required | Description | Default |
|---|---|---|---|
| json | Yes | JSON-LD string to validate |
Implementation Reference
- mcp-server/src/index.ts:324-375 (handler)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"); } - mcp-server/src/index.ts:701-710 (registration)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);