|
| 1 | +# Reference |
| 2 | + |
| 3 | +## `Server` class |
| 4 | + |
| 5 | +The `Server` class is a core component of the MCP for WordPress implementation and is a small wrapper around the [MCP PHP SDK](https://github.com/logiscape/mcp-sdk-php). |
| 6 | + |
| 7 | +This class provides: |
| 8 | + |
| 9 | +- Tool registration (`register_tool()`) |
| 10 | +- Resource registration (`register_resource()`) |
| 11 | +- JSON-RPC request handling (`handle_message()`) |
| 12 | + |
| 13 | +### Examples |
| 14 | + |
| 15 | +Register a Tool |
| 16 | + |
| 17 | +```PHP |
| 18 | +$server->register_tool( |
| 19 | + [ |
| 20 | + 'name' => 'calculate_total', |
| 21 | + 'description' => 'Calculate the total amount' |
| 22 | + 'callable' => function( $params ) { |
| 23 | + return $params['price'] * $params['quantity']; |
| 24 | + }, |
| 25 | + 'inputSchema' => [ |
| 26 | + 'properties' => [ |
| 27 | + 'price' => [ 'type' => 'integer' ], |
| 28 | + 'quantity' => [ 'type' => 'integer' ] |
| 29 | + ], |
| 30 | + ], |
| 31 | + ] |
| 32 | +); |
| 33 | +``` |
| 34 | + |
| 35 | + |
| 36 | +## `RouteInformation` class |
| 37 | + |
| 38 | +The `RouteInformation` class encapsulates metadata about a WordPress REST API route. It provides methods to determine route characteristics, REST method type, and controller details. |
| 39 | + |
| 40 | +This class is used to: |
| 41 | + |
| 42 | +- Identify REST route types (`singular`/`list`, `GET`/`POST`/`DELETE`, etc.). |
| 43 | +- Validate and process REST controller callbacks. |
| 44 | +- Generate sanitized route names for MCP registration. |
| 45 | + |
| 46 | +### Methods |
| 47 | + |
| 48 | +| Name | Return Type | Description | |
| 49 | +|----------------------------------------------------------|-------------|-------------------------------------------------------------| |
| 50 | +| `RouteInformation::__construct($route, $method, $title)` | `void` | Initializes the class with a REST route, method, and title. | |
| 51 | +| `RouteInformation::get_name()` | `string` | Get a tool name for the route. | |
| 52 | +| `RouteInformation::get_description()` | `string` | Get a human-friendly description. | |
| 53 | + |
| 54 | +## `RestApi` class |
| 55 | + |
| 56 | +The `RestApi` class is responsible for mapping WordPress REST API endpoints into MCP tools. It does this by: |
| 57 | + |
| 58 | +- Extracting route details from the REST API. |
| 59 | +- Generating input schemas from REST arguments. |
| 60 | +- Creating AI tools dynamically based on route metadata. |
| 61 | + |
| 62 | +This enables seamless AI-driven interactions with the WordPress REST API. |
| 63 | + |
| 64 | +### Methods |
| 65 | + |
| 66 | +| Name | Return Type | Description | |
| 67 | +|--------------------------------------------------------------------|-------------|-------------------------------------------------------| |
| 68 | +| `RestApi::args_to_schema( $args )` | `array` | Converts REST API arguments into a structured schema. | |
| 69 | +| `RestApi::sanitize_type( $type )` | `string` | Maps input types to standard schema types. | |
| 70 | +| `RestApi::get_tools()` | `array` | Registers REST API endpoints as AI tools in MCP. | |
| 71 | +| `RestApi::rest_callable( $inputs, $route, $method_name, $server )` | `array` | Executes a REST API call dynamically. | |
| 72 | + |
| 73 | +## `MediaManager` class |
| 74 | + |
| 75 | +The `MediaManager` class provides a static method to upload a media file to the WordPress Media Library. It: |
| 76 | + |
| 77 | +- Copies a file into the WordPress uploads directory. |
| 78 | +- Registers the file as a WordPress media attachment. |
| 79 | +- Generates and updates attachment metadata. |
| 80 | + |
| 81 | +This class is useful for automated media uploads within WP-CLI or AI-powered workflows. |
| 82 | + |
| 83 | +### Methods |
| 84 | + |
| 85 | +| Name | Return Type | Description | |
| 86 | +|--------------------------------------------------------|-------------|------------------------------------------------------------------| |
| 87 | +| `MediaManager::upload_to_media_library( $media_path )` | `int` | Uploads a media file to WordPress and returns its attachment ID. | |
| 88 | + |
| 89 | +## `ImageTools` class |
| 90 | + |
| 91 | +The `ImageTools` class provides AI-powered image generation functionality within WP-CLI. |
| 92 | +It: |
| 93 | + |
| 94 | +- Integrates AI-based image generation tools. |
| 95 | +- Registers the tool in the system for easy access. |
| 96 | +- Uses a client to fetch AI-generated images. |
| 97 | + |
| 98 | +This class is used to dynamically generate images based on user prompts. |
| 99 | + |
| 100 | +### Methods |
| 101 | + |
| 102 | +| Name | Return Type | Description | |
| 103 | +|---------------------------------------|-------------|----------------------------------------------| |
| 104 | +| `ImageTools::__construct( $client )` | `void` | Initializes ImageTools with an AI client. | |
| 105 | +| `ImageTools::get_tools()` | `array` | Returns a list of available AI tools. | |
| 106 | +| `ImageTools::image_generation_tool()` | `Tool` | Creates an AI-powered image generation tool. | |
0 commit comments