You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/reference.md
+62-54Lines changed: 62 additions & 54 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -11,12 +11,11 @@
11
11
12
12
## `AiCommand` class
13
13
14
-
The `AiCommand` class extends `WP_CLI_Command`to integrate AI-powered automation into WordPress through WP-CLI. It enables users to interact with an AI model by:
14
+
The `AiCommand` class registers CLI command for WP-CLI. It is a WP-CLI command handler designed to integrate AI capabilities within WordPress. It connects AI-driven services with WP-CLI using the MCP (Multi-Client Processor) architecture, allowing AI models to:
15
15
16
-
- Executing AI-driven prompts.
17
-
- Registering [tools](tools.md) that can be invoked by AI (e.g., calculations, greetings, image generation).
18
-
- Registering resources accessible by AI (e.g., user lists, product catalogs).
19
-
- Fetching [WordPress community events](https://developer.wordpress.org/reference/classes/wp_community_events/) dynamically.
|`AiCommand::register_tools( $server )`|`void`| Registers AI-powered tools in MCP. See [available tools](tools.md). |
33
32
|`AiCommand::register_resources( $server )`|`void`| Registers data resources (e.g., users, products). |
34
-
|`AiCommand::list_tools()`|`string`| Lists available AI tools. |
35
-
|`AiCommand::fetch_wp_community_events( $params )`|`array`| Retrieves WordPress community events. |
36
33
37
34
## `Client` class
38
35
39
-
`Client` class is part of the `WP_CLI\AiCommand\MCP` namespace and serves as an intermediary between the WP-CLI and an AI-based service. It interacts with an MCP (Multi-Client Processor) AI service using JSON-RPC over a local server instance.
36
+
The `Client` class acts as the AI service interface for the MCP (Multi-Client Processor) system within WP-CLI. It communicates with the `Server` class via JSON-RPC, enabling AI-powered text generation, function calls, and image generation.
40
37
41
-
The service supports:
38
+
This class supports:
42
39
43
-
- Sending and receiving requests from the AI service.
44
-
- Retrieving resources from the AI service.
45
-
- Generating images via AI.
46
-
- Processing AI-generated text responses.
47
-
- Managing function calls and executing AI-invoked functions dynamically.
40
+
- AI service interaction (via `call_ai_service()`).
- Image generation via AI models (`get_image_from_ai_service()`).
48
44
49
45
### Properties
50
46
@@ -67,14 +63,14 @@ The service supports:
67
63
68
64
## `Server` class
69
65
70
-
The Server class serves as the core backend for the AI Command's MCP (Multi-Client Processor) in WP-CLI. It provides:
66
+
The Server class is a core component of MCP (Multi-Client Processor) within WP-CLI. It acts as a JSON-RPC 2.0 server, handling data requests, tool registrations, and AI-driven function execution.
- Validation & Error Handling - Ensures correct data formats and secure execution.
68
+
This class provides:
76
69
77
-
This class acts as the server component in the MCP architecture, interfacing with AI clients to process requests. It follows a JSON-RPC 2.0 protocol, ensuring a standardized communication format.
70
+
- Tool registration (`register_tool()`)
71
+
- Resource registration (`register_resource()`)
72
+
- JSON-RPC request handling (`handle_request()`)
73
+
- AI service capabilities retrieval (`get_capabilities()`)
78
74
79
75
### Properties
80
76
@@ -86,22 +82,21 @@ This class acts as the server component in the MCP architecture, interfacing wit
86
82
87
83
### Methods
88
84
89
-
| Name | Description |
90
-
| --- | --- |
91
-
|`Server::__construct()`| Constructor. Initializes sample user and product data. These datasets are accessible via JSON-RPC requests. |
92
-
|`Server::register_tool()`| Registers AI-callable functions (`tools`). Each tool must include identifier (`name`) and function to execute (`callable`); `description` and `inputSchema` are optional. |
93
-
|`Server::register_resource()`| Registers structured data for AI access. |
94
-
|`Server::get_capabilities()`| Retrives server capabilities and returns the list of available tools and resources. Used by AI clients to understand what functions and data are accessible. |
The `RouteInformation` class encapsulates details about a WordPress REST API route, including its method type (`GET`, `POST`, `PUT`, etc.), callback function, and whether it conforms to a `WP_REST_Controller`. The class provides helper methods for route sanitization, method checking, and controller validation.
165
+
The `RouteInformation` class encapsulates metadata about a WordPress REST API route. It provides methods to determine route characteristics, REST method type, and controller details.
- Generate sanitized route names for MCP registration.
171
172
172
173
### Methods
173
174
174
175
| Name | Return Type | Description |
175
176
| --- | --- | --- |
176
-
|`RouteInformation::get_sanitized_route_name()`|`string`| Returns a cleaned-up route name (e.g., GET_wp-v2-posts_p_id). |
177
-
|`RouteInformation::get_method()`|`string`| Returns the HTTP method (`GET`, `POST`, etc.). |
178
-
|`RouteInformation::is_create()`|`bool`| Returns `true` if the method is `POST`. |
179
-
|`RouteInformation::is_update()`|`bool`| Returns `true` if the method is `PUT` or `PATCH`. |
180
-
|`RouteInformation::is_delete()`|`bool`| Returns `true` if the method is `DELETE`. |
181
-
|`RouteInformation::is_get()`|`bool`| Returns `true` if the method is `GET`. |
182
-
|`RouteInformation::is_singular()`|`bool`| Returns `true` if the route targets a single resource. |
183
-
|`RouteInformation::is_list()`|`bool`| Returns `true` if the route retrieves multiple resources. |
184
-
|`RouteInformation::is_wp_rest_controller()`|`bool`| Returns `true` if the callback is a valid REST controller. |
185
-
|`RouteInformation::get_wp_rest_controller()`|`WP_REST_Controller`| Returns the controller instance (throws an error if invalid). |
177
+
|`RouteInformation::__construct($route, $method, $callback)`|`void`| Initializes the class with a REST route, method, and callback. |
178
+
|`RouteInformation::get_sanitized_route_name()`|`string`| Returns a clean, MCP-compatible route name. |
179
+
|`RouteInformation::get_method()`|`string`| Retrieves the HTTP method (GET, POST, etc.). |
180
+
|`RouteInformation::is_create()`|`bool`| Checks if the method is POST (Create). |
181
+
|`RouteInformation::is_update()`|`bool`| Checks if the method is PUT or PATCH (Update). |
182
+
|`RouteInformation::is_delete()`|`bool`| Checks if the method is DELETE (Delete). |
183
+
|`RouteInformation::is_get()`|`bool`| Checks if the method is GET (Retrieve). |
184
+
|`RouteInformation::is_singular()`|`bool`| Determines if the route targets a single resource. |
185
+
|`RouteInformation::is_list()`|`bool`| Determines if the route retrieves a list. |
186
+
|`RouteInformation::get_scope()`|`string`| Returns the scope (post, user, taxonomy, or default). |
187
+
|`RouteInformation::is_wp_rest_controller()`|`bool`| Checks if the callback belongs to a WP REST controller. |
188
+
|`RouteInformation::get_wp_rest_controller()`|`WP_REST_Controller`| Retrieves the REST controller instance or throws an error. |
186
189
187
190
## `MapRESTtoMCP` class
188
191
189
-
The `MapRESTtoMCP` class is responsible for mapping WordPress REST API endpoints into MCP tools. It dynamically registers REST API routes as AI-callable tools in the MCP system.
192
+
The `MapRESTtoMCP` class is responsible for mapping WordPress REST API endpoints into Machine Contextual Processing (MCP) tools. It does this by:
193
+
194
+
- Extracting route details from the REST API.
195
+
- Generating input schemas from REST arguments.
196
+
- Creating AI tools dynamically based on route metadata.
190
197
191
-
This class enables AI-driven automation by exposing WordPress REST API endpoints to AI services in WP-CLI.
198
+
This enables seamless AI-driven interactions with the WordPress REST API.
192
199
193
200
### Methods
194
201
195
202
| Name | Return Type | Description |
196
203
| --- | --- | --- |
197
-
|`MapRESTtoMCP::args_to_schema()`|`array`| Converts REST API arguments into JSON Schema. |
198
-
|`MapRESTtoMCP::sanitize_type()`|`string`| Maps REST API types to standardized types. |
199
-
|`MapRESTtoMCP::map_rest_to_mcp()`|`void`| Registers REST API endpoints as AI tools in MCP. |
200
-
|`MapRESTtoMCP::generate_description()`|`string`| Creates human-readable descriptions for API tools. |
201
-
|`MapRESTtoMCP::rest_callable()`|`array`| Executes REST API calls and returns formatted data. |
204
+
|`MapRESTtoMCP::args_to_schema( $args )`|`array`| Converts REST API arguments into a structured schema. |
205
+
|`MapRESTtoMCP::sanitize_type( $type )`|`string`| Maps input types to standard schema types. |
206
+
|`MapRESTtoMCP::map_rest_to_mcp()`|`array`| Registers REST API endpoints as AI tools in MCP. |
207
+
|`MapRESTtoMCP::generate_description( $info )`|`string`| Creates human-readable descriptions for API routes. |
208
+
|`MapRESTtoMCP::rest_callable( $inputs, $route, $method_name, $server )`|`array`| Executes a REST API call dynamically. |
0 commit comments