PluginProbe
Elementor Website Builder – more than just a page builder / 4.3.3
Elementor Website Builder – more than just a page builder v4.3.3
4.3.3 4.3.2 4.3.1 4.3.0 4.3.0-beta3 4.3.0-beta2 4.3.0-beta1 4.2.4 4.2.3 4.2.2 4.2.1 4.2.0 4.1.5 4.2.0-beta2 4.2.0-dev2 4.2.0-beta1 4.1.4 4.1.3 4.1.2 4.1.1 4.1.0 4.1.0-beta3 4.1.0-dev3 4.0.9 4.1.0-beta2 All 456 releases
← All changes | modules/mcp/abilities/abstract-ability.php +53 -2 4.3.0-beta1 → 4.3.3 View file →
@@ -1,9 +1,11 @@
1 1 <?php
2 2
3 3 namespace Elementor\Modules\Mcp\Abilities;
4 4
5 +use Elementor\MCP\Composer\Admin\McpSettingsController;
5 6 use Elementor\Modules\Mcp\Utils\Editor_Sync_State;
7 +use Elementor\Modules\Mcp\Utils\Mcp_V4_Gate;
6 8
7 9 if ( ! defined( 'ABSPATH' ) ) {
8 10 exit;
9 11 }
@@ -22,8 +24,13 @@
22 24
23 25 abstract public function execute( $input = [] );
24 26
25 27 final public function execute_guarded( $input = [] ) {
28 + $availability = $this->is_available();
29 + if ( is_wp_error( $availability ) ) {
30 + return $availability;
31 + }
32 +
26 33 $is_mutating = self::KIND_TOOL === $this->get_kind() && $this->is_destructive();
27 34
28 35 if ( $is_mutating ) {
29 36 $guard = apply_filters( 'elementor/mcp/pre_execute_guard', null, $input );
@@ -50,11 +57,16 @@
50 57
51 58 public function register(): void {
52 59 $definition = $this->definition()->to_array();
53 60 $definition['execute_callback'] = [ $this, 'execute_guarded' ];
61 + $definition['description'] = $this->get_description_for_llm();
62 +
54 63 $meta = is_array( $definition['meta'] ?? null ) ? $definition['meta'] : [];
55 64 $mcp = is_array( $meta['mcp'] ?? null ) ? $meta['mcp'] : [];
56 - $mcp['public'] = true;
65 + $mcp['public'] = McpSettingsController::is_enabled();
66 + if ( isset( $mcp['description'] ) ) {
67 + $mcp['description'] = $this->maybe_append_unavailable_notice( (string) $mcp['description'] );
68 + }
57 69 $meta['mcp'] = $mcp;
58 70 $meta['show_in_rest'] = true;
59 71 $definition['meta'] = $meta;
60 72 wp_register_ability( $this->get_id(), $definition );
@@ -76,11 +88,17 @@
76 88 return $this->mcp_meta()['mimeType'] ?? null;
77 89 }
78 90
79 91 public function get_resource_description(): ?string {
80 - return $this->mcp_meta()['description'] ?? $this->definition()->description;
92 + $base = $this->mcp_meta()['description'] ?? $this->definition()->description;
93 +
94 + return $this->maybe_append_unavailable_notice( (string) $base );
81 95 }
82 96
97 + public function get_description_for_llm(): string {
98 + return $this->maybe_append_unavailable_notice( (string) $this->definition()->description );
99 + }
100 +
83 101 public function get_display_name(): string {
84 102 return (string) ( $this->mcp_meta()['name'] ?? $this->definition()->label );
85 103 }
86 104
@@ -91,8 +109,23 @@
91 109
92 110 return substr( $this->get_id(), strlen( self::ABILITY_ID_PREFIX ) );
93 111 }
94 112
113 + /**
114 + * Whether this ability may currently run.
115 + *
116 + * Subclasses may override to add reasons beyond the default Atomic Editor gate
117 + * (missing plugin, licence tier, post-type support, ...). Return `true`
118 + * when available, or a `\WP_Error` explaining why not. Include a
119 + * `description_notice` entry in the error data to add a short hint to
120 + * this ability's description in `tools/list` / `elementor/list-resources`.
121 + *
122 + * @return true|\WP_Error
123 + */
124 + public function is_available() {
125 + return Mcp_V4_Gate::is_available( $this->get_id() );
126 + }
127 +
95 128 public function is_exposed_via_proxy(): bool {
96 129 return true;
97 130 }
98 131
@@ -119,6 +152,24 @@
119 152 private function mcp_meta(): array {
120 153 $meta = $this->definition()->meta;
121 154
122 155 return is_array( $meta['mcp'] ?? null ) ? $meta['mcp'] : [];
156 + }
157 +
158 + private function maybe_append_unavailable_notice( string $description ): string {
159 + $availability = $this->is_available();
160 + if ( ! is_wp_error( $availability ) ) {
161 + return $description;
162 + }
163 +
164 + $data = $availability->get_error_data();
165 + $notice = is_array( $data ) && isset( $data['description_notice'] )
166 + ? (string) $data['description_notice']
167 + : $availability->get_error_message();
168 +
169 + if ( '' === $notice ) {
170 + return $description;
171 + }
172 +
173 + return '' === $description ? $notice : rtrim( $description ) . ' ' . $notice;
123 174 }
124 175 }