|
15 | 15 |
|
16 | 16 | final class ApiMethodSummaryToolOutputSchema |
17 | 17 | { |
18 | | - public const PARAMETER = [ |
19 | | - 'type' => 'object', |
20 | | - 'properties' => [ |
21 | | - 'name' => ['type' => 'string'], |
22 | | - 'type' => ['type' => ['string', 'null']], |
23 | | - 'required' => ['type' => 'boolean'], |
24 | | - 'allowsNull' => ['type' => 'boolean'], |
25 | | - 'hasDefault' => ['type' => 'boolean'], |
26 | | - 'defaultValue' => [], |
27 | | - ], |
28 | | - 'required' => ['name', 'type', 'required', 'allowsNull', 'hasDefault', 'defaultValue'], |
29 | | - 'additionalProperties' => false, |
30 | | - ]; |
31 | | - |
32 | | - public const ITEM = [ |
33 | | - 'type' => 'object', |
34 | | - 'properties' => [ |
35 | | - 'module' => ['type' => 'string'], |
36 | | - 'action' => ['type' => 'string'], |
37 | | - 'method' => ['type' => 'string'], |
38 | | - 'parameters' => [ |
39 | | - 'type' => 'array', |
40 | | - 'items' => self::PARAMETER, |
| 18 | + /** |
| 19 | + * @return array<string, mixed> |
| 20 | + */ |
| 21 | + public static function parameter(): array |
| 22 | + { |
| 23 | + return [ |
| 24 | + 'type' => 'object', |
| 25 | + 'properties' => [ |
| 26 | + 'name' => ['type' => 'string'], |
| 27 | + 'type' => ['type' => ['string', 'null']], |
| 28 | + 'required' => ['type' => 'boolean'], |
| 29 | + 'allowsNull' => ['type' => 'boolean'], |
| 30 | + 'hasDefault' => ['type' => 'boolean'], |
| 31 | + // `new \stdClass()` so `json_encode` emits `{}` (an empty JSON Schema = |
| 32 | + // "any value"); `[]` would encode as `[]` and fail MCP schema validation. |
| 33 | + 'defaultValue' => new \stdClass(), |
41 | 34 | ], |
42 | | - 'operationCategory' => [ |
43 | | - 'type' => ['string', 'null'], |
44 | | - 'enum' => [ |
45 | | - ApiMethodOperationClassifier::CATEGORY_READ, |
46 | | - ApiMethodOperationClassifier::CATEGORY_CREATE, |
47 | | - ApiMethodOperationClassifier::CATEGORY_UPDATE, |
48 | | - ApiMethodOperationClassifier::CATEGORY_DELETE, |
49 | | - null, |
| 35 | + 'required' => ['name', 'type', 'required', 'allowsNull', 'hasDefault', 'defaultValue'], |
| 36 | + 'additionalProperties' => false, |
| 37 | + ]; |
| 38 | + } |
| 39 | + |
| 40 | + /** |
| 41 | + * @return array<string, mixed> |
| 42 | + */ |
| 43 | + public static function item(): array |
| 44 | + { |
| 45 | + return [ |
| 46 | + 'type' => 'object', |
| 47 | + 'properties' => [ |
| 48 | + 'module' => ['type' => 'string'], |
| 49 | + 'action' => ['type' => 'string'], |
| 50 | + 'method' => ['type' => 'string'], |
| 51 | + 'parameters' => [ |
| 52 | + 'type' => 'array', |
| 53 | + 'items' => self::parameter(), |
| 54 | + ], |
| 55 | + 'operationCategory' => [ |
| 56 | + 'type' => ['string', 'null'], |
| 57 | + 'enum' => [ |
| 58 | + ApiMethodOperationClassifier::CATEGORY_READ, |
| 59 | + ApiMethodOperationClassifier::CATEGORY_CREATE, |
| 60 | + ApiMethodOperationClassifier::CATEGORY_UPDATE, |
| 61 | + ApiMethodOperationClassifier::CATEGORY_DELETE, |
| 62 | + null, |
| 63 | + ], |
50 | 64 | ], |
51 | 65 | ], |
52 | | - ], |
53 | | - 'required' => [ |
54 | | - 'module', |
55 | | - 'action', |
56 | | - 'method', |
57 | | - 'parameters', |
58 | | - 'operationCategory', |
59 | | - ], |
60 | | - 'additionalProperties' => false, |
61 | | - ]; |
| 66 | + 'required' => [ |
| 67 | + 'module', |
| 68 | + 'action', |
| 69 | + 'method', |
| 70 | + 'parameters', |
| 71 | + 'operationCategory', |
| 72 | + ], |
| 73 | + 'additionalProperties' => false, |
| 74 | + ]; |
| 75 | + } |
62 | 76 |
|
63 | | - public const PAGINATED_LIST = [ |
64 | | - 'type' => 'object', |
65 | | - 'properties' => [ |
66 | | - 'methods' => [ |
67 | | - 'type' => 'array', |
68 | | - 'items' => self::ITEM, |
| 77 | + /** |
| 78 | + * @return array<string, mixed> |
| 79 | + */ |
| 80 | + public static function paginatedList(): array |
| 81 | + { |
| 82 | + return [ |
| 83 | + 'type' => 'object', |
| 84 | + 'properties' => [ |
| 85 | + 'methods' => [ |
| 86 | + 'type' => 'array', |
| 87 | + 'items' => self::item(), |
| 88 | + ], |
| 89 | + 'next_cursor' => ['type' => ['string', 'null']], |
| 90 | + 'has_more' => ['type' => 'boolean'], |
| 91 | + 'total_rows' => ['type' => 'integer'], |
69 | 92 | ], |
70 | | - 'next_cursor' => ['type' => ['string', 'null']], |
71 | | - 'has_more' => ['type' => 'boolean'], |
72 | | - 'total_rows' => ['type' => 'integer'], |
73 | | - ], |
74 | | - 'required' => ['methods', 'next_cursor', 'has_more', 'total_rows'], |
75 | | - 'additionalProperties' => false, |
76 | | - ]; |
| 93 | + 'required' => ['methods', 'next_cursor', 'has_more', 'total_rows'], |
| 94 | + 'additionalProperties' => false, |
| 95 | + ]; |
| 96 | + } |
77 | 97 | } |
0 commit comments