Skip to main content
Glama

wp_seo_generate_schema

Generate JSON-LD structured data for WordPress posts to enhance search engine visibility and rich results display.

Instructions

Generate JSON-LD structured data schema for enhanced search results

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
siteNoSite identifier for multi-site setups
postIdYesWordPress post ID
schemaTypeYesType of schema.org structured data to generate
customDataNoAdditional custom data for the schema

Implementation Reference

  • Defines the Tool object for 'wp_seo_generate_schema' including name, description, and input schema validation.
    export const generateSchemaTool: Tool = { name: "wp_seo_generate_schema", description: "Generate JSON-LD structured data schema for enhanced search results", inputSchema: { type: "object", properties: { postId: { type: "number", description: "WordPress post ID", }, schemaType: { type: "string", enum: [ "Article", "Product", "FAQ", "HowTo", "Organization", "Website", "BreadcrumbList", "Event", "Recipe", "Course", "LocalBusiness", "Person", "Review", "VideoObject", ], description: "Type of schema.org structured data to generate", }, customData: { type: "object", description: "Additional custom data for the schema", }, site: { type: "string", description: "Site identifier for multi-site setups", }, }, required: ["postId", "schemaType"], }, };
  • MCP handler function that extracts parameters from args and delegates to SEOTools.generateSchema.
    export async function handleGenerateSchema(client: WordPressClient, args: Record<string, unknown>): Promise<unknown> { const logger = LoggerFactory.tool("wp_seo_generate_schema"); try { const seoTools = getSEOToolsInstance(); const params: SEOToolParams = { postId: args.postId as number, schemaType: args.schemaType as SchemaType, site: args.site as string, }; // Add custom data if provided if (args.customData) { params.customData = args.customData; } return await seoTools.generateSchema(params); } catch (error) { logger.error("Failed to generate schema", { error, args }); throw error; }
  • Maps tool name 'wp_seo_generate_schema' to its handler function handleGenerateSchema in getHandlerForTool method, used by getTools() for MCP 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}`); }) ); }
  • Core business logic for generating schema: handles caching, fetches post, calls SchemaGenerator via createSchema.
    async generateSchema(params: SEOToolParams): Promise<SchemaMarkup> { const siteLogger = LoggerFactory.tool("wp_seo_generate_schema", params.site); return await siteLogger.time("Generate schema markup", async () => { try { validateRequired(params, ["postId", "schemaType"]); const client = this.getSiteClient(params.site); // Check cache const cacheKey = `seo:schema:${params.site}:${params.postId as number}:${params.schemaType}`; const cached = await this.getCachedResult(cacheKey); if (cached) { return cached as SchemaMarkup; } // Generate schema (implementation in generators) const schema = await this.createSchema(client, params); // Cache for 24 hours await this.cacheResult(cacheKey, schema, 86400); return schema; } catch (_error) { handleToolError(_error, "generate schema", { site: params.site, postId: params.postId as number, schemaType: params.schemaType, }); throw _error; } }); }
  • Exact implementation: Generates JSON-LD schema markup based on schemaType using switch statement dispatching to type-specific generators and content extraction helpers.
    async generateSchema(post: WordPressPost, params: SEOToolParams, options: SchemaOptions = {}): Promise<SchemaMarkup> { this.logger.debug("Generating schema markup", { postId: post.id, schemaType: params.schemaType, title: post.title?.rendered?.substring(0, 50), }); if (!params.schemaType) { throw new Error("Schema type is required for schema generation"); } const baseSchema: SchemaMarkup = { "@context": "https://schema.org", "@type": params.schemaType, }; // Generate schema based on type switch (params.schemaType) { case "Article": return this.generateArticleSchema(post, baseSchema, options); case "Product": return this.generateProductSchema(post, baseSchema, options); case "FAQ": return this.generateFAQSchema(post, baseSchema, options); case "HowTo": return this.generateHowToSchema(post, baseSchema, options); case "Organization": return this.generateOrganizationSchema(post, baseSchema, options); case "LocalBusiness": return this.generateLocalBusinessSchema(post, baseSchema, options); case "Website": return this.generateWebsiteSchema(post, baseSchema, options); case "BreadcrumbList": return this.generateBreadcrumbSchema(post, baseSchema, options); case "Event": return this.generateEventSchema(post, baseSchema, options); case "Recipe": return this.generateRecipeSchema(post, baseSchema, options); case "Course": return this.generateCourseSchema(post, baseSchema, options); case "VideoObject": return this.generateVideoSchema(post, baseSchema, options); case "Person": return this.generatePersonSchema(post, baseSchema, options); case "Review": return this.generateReviewSchema(post, baseSchema, options); default: throw new Error(`Unsupported schema type: ${params.schemaType}`); } }

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/docdyhr/mcp-wordpress'

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