wpnav_gutenberg_list_blocks
Retrieve all Gutenberg blocks from a WordPress post as structured data, showing block types, attributes, and hierarchical paths for content analysis.
Instructions
Get all blocks in a post as Intermediate Representation (IR). Returns block structure with types, attributes, and paths.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| post_id | Yes | WordPress post or page ID to load blocks from |
Implementation Reference
- src/tools/gutenberg/index.ts:64-90 (handler)The core handler function for wpnav_gutenberg_list_blocks. It validates the post_id input, fetches the Gutenberg blocks as an Intermediate Representation (IR) document via the WordPress REST API, generates a summary using formatIRSummary helper, and returns both the summary and full IR in the response content.handler: async (args, context) => { validateRequired(args, ['post_id']); const id = validateId(args.post_id, 'Post'); const result = await context.wpRequest(`/wpnav/v1/gutenberg/blocks?post_id=${id}`); if (!result.success) { return { content: [{ type: 'text', text: context.clampText(JSON.stringify({ error: result.error }, null, 2)), }], isError: true, }; } // Include both full IR and summary const summary = formatIRSummary(result.ir_document); return { content: [{ type: 'text', text: context.clampText( `${summary}\n\nFull IR Document:\n${JSON.stringify(result.ir_document, null, 2)}` ), }], };
- src/tools/gutenberg/index.ts:53-62 (schema)The input schema for the tool, requiring a single 'post_id' parameter of type number.inputSchema: { type: 'object', properties: { post_id: { type: 'number', description: 'WordPress post or page ID to load blocks from', }, }, required: ['post_id'], },
- src/tools/gutenberg/index.ts:49-93 (registration)The tool registration block in toolRegistry.register, including name, description, inputSchema, handler, and category.toolRegistry.register({ definition: { name: 'wpnav_gutenberg_list_blocks', description: 'Get all blocks in a post as Intermediate Representation (IR). Returns block structure with types, attributes, and paths.', inputSchema: { type: 'object', properties: { post_id: { type: 'number', description: 'WordPress post or page ID to load blocks from', }, }, required: ['post_id'], }, }, handler: async (args, context) => { validateRequired(args, ['post_id']); const id = validateId(args.post_id, 'Post'); const result = await context.wpRequest(`/wpnav/v1/gutenberg/blocks?post_id=${id}`); if (!result.success) { return { content: [{ type: 'text', text: context.clampText(JSON.stringify({ error: result.error }, null, 2)), }], isError: true, }; } // Include both full IR and summary const summary = formatIRSummary(result.ir_document); return { content: [{ type: 'text', text: context.clampText( `${summary}\n\nFull IR Document:\n${JSON.stringify(result.ir_document, null, 2)}` ), }], }; }, category: ToolCategory.CONTENT, });
- Helper function formatIRSummary used by the handler to generate a human-readable summary of the IR document structure, including block count, types, and root children count. Relies on internal countBlocks and getBlockTypes functions.export function formatIRSummary(ir: any): string { if (!ir || !ir.root) { return 'Empty IR document'; } const blockCount = countBlocks(ir.root.children); const blockTypes = getBlockTypes(ir.root.children); return `IR Document Summary: - Total blocks: ${blockCount} - Block types: ${blockTypes.join(', ')} - Root children: ${ir.root.children.length}`; }