Skip to content

Commit 8b3bbc8

Browse files
committed
CS
1 parent 36db61d commit 8b3bbc8

3 files changed

Lines changed: 75 additions & 4 deletions

File tree

src/MCP/McpPolicy.php

Lines changed: 33 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,29 @@
77
use Saltus\WP\Framework\Rest\ModelRestPolicy;
88

99
class McpPolicy {
10-
10+
/**
11+
* Modeler instance.
12+
* It is responsible for providing models and model types.
13+
*
14+
* @var Modeler
15+
*/
1116
private Modeler $modeler;
1217

18+
/**
19+
* @param Modeler $modeler
20+
*/
1321
public function __construct( Modeler $modeler ) {
1422
$this->modeler = $modeler;
1523
}
1624

25+
/**
26+
* Check if a capability is enabled.
27+
*
28+
* @param string $capability The capability.
29+
* @param string|null $model_type The model type.
30+
*
31+
* @return bool
32+
*/
1733
public function has_capability( string $capability, ?string $model_type = null ): bool {
1834
if ( $capability === ModelRestPolicy::CAPABILITY_HEALTH ) {
1935
return true;
@@ -32,6 +48,14 @@ public function has_capability( string $capability, ?string $model_type = null )
3248
return false;
3349
}
3450

51+
/**
52+
* Check if a capability is enabled for a model.
53+
*
54+
* @param Model $model The model.
55+
* @param string $capability The capability.
56+
*
57+
* @return bool
58+
*/
3559
public function is_enabled( Model $model, string $capability ): bool {
3660
$options = $model->get_options();
3761

@@ -49,7 +73,11 @@ public function is_enabled( Model $model, string $capability ): bool {
4973
}
5074

5175
/**
76+
* Resolve whether a capability should be shown in MCP.
77+
*
5278
* @param array<string, mixed> $config
79+
*
80+
* @return bool
5381
*/
5482
private function resolve_show_in_mcp( array $config, string $capability ): bool {
5583
$map = [
@@ -73,7 +101,10 @@ private function resolve_show_in_mcp( array $config, string $capability ): bool
73101
}
74102

75103
/**
76-
* @param string $name
104+
* Get a model by name.
105+
*
106+
* @param string $name The model name.
107+
* @return Model|null
77108
*/
78109
public function get_model( string $name ): ?Model {
79110
$models = $this->modeler->get_models();

src/Modeler.php

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,11 +35,23 @@ class Modeler implements RestRouteProvider, ToolContributor {
3535
/** @var array<string, Model> */
3636
protected array $model_list = [];
3737

38+
39+
40+
/**
41+
* Construct the modeler.
42+
43+
* @param ModelFactory $model_factory
44+
*/
3845
public function __construct( ModelFactory $model_factory ) {
3946
$this->model_factory = $model_factory;
4047
// should contain a list of loaded models
4148
}
4249

50+
/**
51+
* Initialize the modeler.
52+
*
53+
* @param string $project_path The project path.
54+
*/
4355
public function init( string $project_path ): void {
4456
$path = $this->get_path( $project_path );
4557
if ( ! $path ) {
@@ -50,6 +62,10 @@ public function init( string $project_path ): void {
5062

5163
/**
5264
* Get custom path
65+
*
66+
* @param string $project_path The project path.
67+
*
68+
* @return string|null The path.
5369
*/
5470
protected function get_path( string $project_path ): ?string {
5571

@@ -69,7 +85,9 @@ protected function get_path( string $project_path ): ?string {
6985
}
7086

7187
/**
72-
* Load Models
88+
* Load Models.
89+
*
90+
* @param string $path The path to the model
7391
*/
7492
protected function load( string $path ): void {
7593
if ( file_exists( $path ) ) {
@@ -176,6 +194,8 @@ protected function create( AbstractConfig $config ): void {
176194

177195
/**
178196
* Adds the model to a list
197+
*
198+
* @param Model $model The model.
179199
*/
180200
protected function add( Model $model ): void {
181201
$this->model_list[ $model->get_name() ] = $model;
@@ -184,13 +204,17 @@ protected function add( Model $model ): void {
184204
/**
185205
* Return all loaded models.
186206
*
187-
* @return array<string, \Saltus\WP\Framework\Models\Model> Associative array keyed by model name.
207+
* @return array<string, Model> Associative array keyed by model name.
188208
*/
189209
public function get_models(): array {
190210
return $this->model_list;
191211
}
192212

193213
/**
214+
* Get rest routes.
215+
*
216+
* @param Modeler $modeler
217+
* @param ModelRestPolicy $policy
194218
* @return list<RestRouteDefinition>
195219
*/
196220
public function get_rest_routes( Modeler $modeler, ModelRestPolicy $policy ): array {
@@ -203,6 +227,10 @@ public function get_rest_routes( Modeler $modeler, ModelRestPolicy $policy ): ar
203227
}
204228

205229
/**
230+
* Get MCP tools.
231+
*
232+
* @param Modeler $modeler
233+
* @param ModelRestPolicy|null $policy
206234
* @return list<ToolInterface>
207235
*/
208236
public function get_mcp_tools( Modeler $modeler, ?ModelRestPolicy $policy = null ): array {

tests/MCP/MCPConfigTest.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,18 @@ function ( array $category ): array {
9797
$this->assertSame( 'Overridden Label', $category['label'] );
9898
}
9999

100+
public function testGetAbilityCategoryFilterReturnsIncompleteArrayMergesWithDefaults(): void {
101+
global $wp_filter_values;
102+
$wp_filter_values['saltus/framework/mcp/ability_category'] = [
103+
'id' => 'custom-id',
104+
];
105+
106+
$category = MCPConfig::get_ability_category();
107+
$this->assertSame( 'custom-id', $category['id'] );
108+
$this->assertSame( 'Saltus Framework', $category['label'] );
109+
$this->assertSame( 'Saltus Framework content modeling and administration abilities.', $category['description'] );
110+
}
111+
100112
public function testGetAbilityPrefixReturnsDefault(): void {
101113
$this->assertSame( 'saltus/', MCPConfig::get_ability_prefix() );
102114
}

0 commit comments

Comments
 (0)