wp_seo_validate_schema
Validate JSON-LD schema markup for correctness and compliance with SEO standards to improve search engine visibility.
Instructions
Validate JSON-LD schema markup for correctness and compliance
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| site | No | Site identifier for multi-site setups | |
| schema | Yes | JSON-LD schema object to validate | |
| schemaType | No | Expected schema type for validation | |
| useGoogleValidator | No | Use Google's Rich Results Test API for validation |
Implementation Reference
- src/tools/seo/SEOHandlers.ts:136-157 (handler)The primary MCP handler function for the wp_seo_validate_schema tool. It processes input arguments, constructs parameters, and delegates execution to the SEOTools instance's validateSchema method.export async function handleValidateSchema(client: WordPressClient, args: Record<string, unknown>): Promise<unknown> { const logger = LoggerFactory.tool("wp_seo_validate_schema"); try { const seoTools = getSEOToolsInstance(); const params: SEOToolParams = { schema: args.schema, schemaType: args.schemaType as SchemaType, site: args.site as string, }; // Add Google validator flag if provided if (args.useGoogleValidator) { params.useGoogleValidator = args.useGoogleValidator as boolean; } return await seoTools.validateSchema(params); } catch (error) { logger.error("Failed to validate schema", { error, args }); throw error; } }
- Tool definition including name, description, and input schema for the wp_seo_validate_schema tool, used for MCP registration.export const validateSchemaTool: Tool = { name: "wp_seo_validate_schema", description: "Validate JSON-LD schema markup for correctness and compliance", inputSchema: { type: "object", properties: { schema: { type: "object", description: "JSON-LD schema object to validate", }, schemaType: { type: "string", description: "Expected schema type for validation", }, useGoogleValidator: { type: "boolean", description: "Use Google's Rich Results Test API for validation", }, site: { type: "string", description: "Site identifier for multi-site setups", }, }, required: ["schema"], }, };
- src/tools/seo/SEOTools.ts:378-399 (registration)Handler mapping function that associates the tool name 'wp_seo_validate_schema' with its handler function handleValidateSchema. Used by getTools() for MCP tool registration.private getHandlerForTool(toolName: string): unknown { const handlers: Record<string, unknown> = { wp_seo_analyze_content: handleAnalyzeContent, wp_seo_generate_metadata: handleGenerateMetadata, wp_seo_bulk_update_metadata: handleBulkUpdateMetadata, wp_seo_generate_schema: handleGenerateSchema, wp_seo_validate_schema: handleValidateSchema, wp_seo_suggest_internal_links: handleSuggestInternalLinks, wp_seo_site_audit: handlePerformSiteAudit, wp_seo_track_serp: handleTrackSERPPositions, wp_seo_keyword_research: handleKeywordResearch, wp_seo_test_integration: handleTestSEOIntegration, wp_seo_get_live_data: handleGetLiveSEOData, }; return ( handlers[toolName] || (() => { throw new Error(`Unknown SEO tool: ${toolName}`); }) ); }
- src/tools/seo/SEOTools.ts:261-279 (handler)Core implementation method in SEOTools class that performs the schema validation logic, including caching, error handling, and delegation to performSchemaValidation.async validateSchema(params: SEOToolParams): Promise<unknown> { const siteLogger = LoggerFactory.tool("wp_seo_validate_schema", params.site); return await siteLogger.time("Validate schema markup", async () => { try { validateRequired(params, ["schema"]); // Implementation will be added in validators const validation = await this.performSchemaValidation(params); return validation; } catch (_error) { handleToolError(_error, "validate schema", { site: params.site, }); throw _error; } }); }
- src/tools/seo/SEOTools.ts:556-571 (helper)Private helper method that executes the actual schema validation using SchemaGenerator and formats the response.private async performSchemaValidation(params: SEOToolParams): Promise<unknown> { if (!params.schema) { throw new Error("Schema markup is required for validation"); } // Basic validation using the SchemaGenerator's validation method const validation = this.schemaGenerator.validateSchema(params.schema as SchemaMarkup); return { valid: validation.valid, errors: validation.errors, warnings: [], // Could add warnings for best practices schemaType: (params.schema as SchemaMarkup)["@type"], validatedAt: new Date().toISOString(), }; }