Skip to main content
Glama

wpnav_gutenberg_insert_pattern

Insert Gutenberg block patterns into WordPress posts at specific locations using pattern slugs and post IDs.

Instructions

Insert a Gutenberg block pattern at specified path. Use wpnav_gutenberg_list_patterns to discover available patterns first.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
post_idYesPost ID to modify
pathYesPath where pattern should be inserted (e.g., [0] for first position)
pattern_slugYesPattern slug/ID from wpnav_gutenberg_list_patterns

Implementation Reference

  • The handler function executes the tool: validates post_id, path (using validatePath helper), and pattern_slug; makes a POST request to WP REST API /wpnav/v1/gutenberg/patterns/insert; returns formatted success or error content.
    handler: async (args, context) => { validateRequired(args, ['post_id', 'path', 'pattern_slug']); const id = validateId(args.post_id, 'Post'); if (!validatePath(args.path)) { return { content: [{ type: 'text', text: context.clampText(JSON.stringify({ error: 'invalid_path', message: 'Path must be non-empty array of non-negative integers', }, null, 2)), }], isError: true, }; } // Call REST API const result = await context.wpRequest('/wpnav/v1/gutenberg/patterns/insert', { method: 'POST', body: JSON.stringify({ post_id: id, path: args.path, pattern_slug: args.pattern_slug, }), }); if (!result.success) { return { content: [{ type: 'text', text: context.clampText(JSON.stringify({ error: result.error }, null, 2)), }], isError: true, }; } return { content: [{ type: 'text', text: context.clampText(JSON.stringify({ success: true, post_id: id, path: args.path, pattern_slug: args.pattern_slug, message: 'Pattern inserted successfully', }, null, 2)), }], }; },
  • Input schema defining parameters: post_id (number, required), path (array of numbers, required), pattern_slug (string, required).
    inputSchema: { type: 'object', properties: { post_id: { type: 'number', description: 'Post ID to modify', }, path: { type: 'array', items: { type: 'number' }, description: 'Path where pattern should be inserted (e.g., [0] for first position)', }, pattern_slug: { type: 'string', description: 'Pattern slug/ID from wpnav_gutenberg_list_patterns', }, }, required: ['post_id', 'path', 'pattern_slug'], },
  • Registration of the wpnav_gutenberg_insert_pattern tool in toolRegistry, including definition (name, description, schema), inline handler, and category.
    toolRegistry.register({ definition: { name: 'wpnav_gutenberg_insert_pattern', description: 'Insert a Gutenberg block pattern at specified path. Use wpnav_gutenberg_list_patterns to discover available patterns first.', inputSchema: { type: 'object', properties: { post_id: { type: 'number', description: 'Post ID to modify', }, path: { type: 'array', items: { type: 'number' }, description: 'Path where pattern should be inserted (e.g., [0] for first position)', }, pattern_slug: { type: 'string', description: 'Pattern slug/ID from wpnav_gutenberg_list_patterns', }, }, required: ['post_id', 'path', 'pattern_slug'], }, }, handler: async (args, context) => { validateRequired(args, ['post_id', 'path', 'pattern_slug']); const id = validateId(args.post_id, 'Post'); if (!validatePath(args.path)) { return { content: [{ type: 'text', text: context.clampText(JSON.stringify({ error: 'invalid_path', message: 'Path must be non-empty array of non-negative integers', }, null, 2)), }], isError: true, }; } // Call REST API const result = await context.wpRequest('/wpnav/v1/gutenberg/patterns/insert', { method: 'POST', body: JSON.stringify({ post_id: id, path: args.path, pattern_slug: args.pattern_slug, }), }); if (!result.success) { return { content: [{ type: 'text', text: context.clampText(JSON.stringify({ error: result.error }, null, 2)), }], isError: true, }; } return { content: [{ type: 'text', text: context.clampText(JSON.stringify({ success: true, post_id: id, path: args.path, pattern_slug: args.pattern_slug, message: 'Pattern inserted successfully', }, null, 2)), }], }; }, category: ToolCategory.CONTENT, });
  • validatePath helper function used in the handler to validate the path parameter is a non-empty array of non-negative integers.
    export function validatePath(path: number[]): boolean { if (!Array.isArray(path)) { return false; } if (path.length === 0) { return false; } return path.every(n => Number.isInteger(n) && n >= 0); }

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/littlebearapps/wp-navigator-mcp'

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