| 1 |
<?php |
| 2 |
/** |
| 3 |
* Ability: Return the bundled WDesignKit Abilities Guide (SKILL.md) so any |
| 4 |
* MCP client can fetch it and follow the documented rules before calling |
| 5 |
* wdesignkit/* or nexter-blocks/* abilities. |
| 6 |
*/ |
| 7 |
|
| 8 |
declare(strict_types=1); |
| 9 |
|
| 10 |
if (!defined('ABSPATH')) { |
| 11 |
exit(); |
| 12 |
} |
| 13 |
|
| 14 |
wp_register_ability('wdesignkit/get-abilities-guide', [ |
| 15 |
'label' => __('Get WDesignKit Abilities Guide', 'wdesignkit'), |
| 16 |
'description' => __( |
| 17 |
'Returns the full WDesignKit Abilities Guide (Markdown) — builder mapping, the create-code-verify widget workflow, the Nexter Blocks dedicated-ability rule, and safety rules for irreversible calls (dry_run before confirm, login before cloud, read before write). Call this BEFORE the first wdesignkit/* or nexter-blocks/* call in a session so subsequent calls follow the documented contracts.', |
| 18 |
'wdesignkit', |
| 19 |
), |
| 20 |
'category' => 'wdesignkit', |
| 21 |
'input_schema' => [ |
| 22 |
'type' => 'object', |
| 23 |
], |
| 24 |
'output_schema' => [ |
| 25 |
'type' => 'object', |
| 26 |
'properties' => [ |
| 27 |
'success' => ['type' => 'boolean'], |
| 28 |
'guide' => ['type' => 'string'], |
| 29 |
], |
| 30 |
], |
| 31 |
'execute_callback' => 'wdesignkit_mcp_get_abilities_guide', |
| 32 |
'permission_callback' => 'wdesignkit_mcp_permission_callback', |
| 33 |
'meta' => [ |
| 34 |
'public' => true, |
| 35 |
'show_in_rest' => true, |
| 36 |
'mcp' => ['public' => true], |
| 37 |
'annotations' => [ |
| 38 |
'instructions' => implode("\n", [ |
| 39 |
'Call this once at the start of any session that will use wdesignkit/ or nexter-blocks/* abilities.', |
| 40 |
'Returns Markdown covering: builder mapping (Elementor/Gutenberg/Nexter/Bricks), the create-widget → get-widget → update-widget → widget-preview workflow, the Nexter Blocks add-tpgb-* + verify-page rule, and confirm/dry_run safety rules for irreversible abilities.', |
| 41 |
'wdesignkit/list-abilities enumerates every ability if something is not covered by the guide.', |
| 42 |
]), |
| 43 |
'readonly' => true, |
| 44 |
'destructive' => false, |
| 45 |
'idempotent' => true, |
| 46 |
], |
| 47 |
], |
| 48 |
]); |
| 49 |
|
| 50 |
/** |
| 51 |
* Execute callback: returns the WDesignKit Abilities Guide as Markdown. |
| 52 |
* |
| 53 |
* @param array $input Ability input arguments (unused; kept for callback signature). |
| 54 |
* @return array|WP_Error array{success:bool,guide:string} on success, WP_Error when |
| 55 |
* the bundled guide file is missing or unreadable so the MCP |
| 56 |
* client can surface a real failure instead of silently |
| 57 |
* treating an empty guide as valid output. |
| 58 |
*/ |
| 59 |
function wdesignkit_mcp_get_abilities_guide(array $input) { |
| 60 |
unset($input); |
| 61 |
|
| 62 |
$path = WDKIT_INCLUDES . 'abilities/skills/wdesignkit-abilities/SKILL.md'; |
| 63 |
|
| 64 |
if (!is_readable($path)) { |
| 65 |
return new WP_Error( |
| 66 |
'skill_unreadable', |
| 67 |
__('WDesignKit abilities guide is missing or unreadable.', 'wdesignkit') |
| 68 |
); |
| 69 |
} |
| 70 |
|
| 71 |
// phpcs:ignore WordPress.WP.AlternativeFunctions.file_get_contents_file_get_contents -- Local plugin file path, not a remote URL. |
| 72 |
return [ |
| 73 |
'success' => true, |
| 74 |
'guide' => (string) file_get_contents($path), |
| 75 |
]; |
| 76 |
} |
| 77 |
|