Skip to main content
Glama

wpnav_gutenberg_delete_block

Remove Gutenberg blocks from WordPress posts by specifying the post ID and block path to modify content directly.

Instructions

Delete a Gutenberg block at specified path. WARNING: This action modifies post content immediately.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
post_idYesPost ID to modify
pathYesPath to block to delete (e.g., [0] = first block, [1, 0] = first child of second block)

Implementation Reference

  • The main handler function for the wpnav_gutenberg_delete_block tool. It validates the input arguments (post_id and path), calls the WordPress REST API endpoint '/wpnav/v1/gutenberg/blocks/delete' with a POST request, and returns success or error response.
    handler: async (args, context) => { validateRequired(args, ['post_id', 'path']); 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/blocks/delete', { method: 'POST', body: JSON.stringify({ post_id: id, path: args.path, }), }); 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, message: 'Block deleted successfully', }, null, 2)), }], }; },
  • The inputSchema for the tool, specifying post_id as number and path as array of numbers, both required.
    inputSchema: { type: 'object', properties: { post_id: { type: 'number', description: 'Post ID to modify', }, path: { type: 'array', items: { type: 'number' }, description: 'Path to block to delete (e.g., [0] = first block, [1, 0] = first child of second block)', }, }, required: ['post_id', 'path'], },
  • The toolRegistry.register call that registers the wpnav_gutenberg_delete_block tool, including its name, description, schema, handler, and category.
    toolRegistry.register({ definition: { name: 'wpnav_gutenberg_delete_block', description: 'Delete a Gutenberg block at specified path. WARNING: This action modifies post content immediately.', inputSchema: { type: 'object', properties: { post_id: { type: 'number', description: 'Post ID to modify', }, path: { type: 'array', items: { type: 'number' }, description: 'Path to block to delete (e.g., [0] = first block, [1, 0] = first child of second block)', }, }, required: ['post_id', 'path'], }, }, handler: async (args, context) => { validateRequired(args, ['post_id', 'path']); 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/blocks/delete', { method: 'POST', body: JSON.stringify({ post_id: id, path: args.path, }), }); 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, message: 'Block deleted successfully', }, null, 2)), }], }; }, category: ToolCategory.CONTENT, });
  • validatePath helper function used in the handler to ensure the path is a valid 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