Skip to content

Commit bc067f6

Browse files
klapaudiusgithub-actions[bot]
authored andcommitted
Fix styling
1 parent 5d598bf commit bc067f6

File tree

4 files changed

+23
-21
lines changed

4 files changed

+23
-21
lines changed

src/Exceptions/ToolParamsValidatorException.php

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,15 @@
44

55
use Exception;
66

7-
class ToolParamsValidatorException extends Exception {
8-
public function __construct(string $message, private readonly array $errors) {
7+
class ToolParamsValidatorException extends Exception
8+
{
9+
public function __construct(string $message, private readonly array $errors)
10+
{
911
parent::__construct($message);
1012
}
1113

12-
public function getErrors(): array {
14+
public function getErrors(): array
15+
{
1316
return $this->errors;
1417
}
1518
}

src/Protocol/MCPProtocol.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ private function handleRequestProcess(string $clientId, RequestData $requestData
143143
} catch (JsonRpcErrorException $e) {
144144
$this->pushMessage(clientId: $clientId, message: new JsonRpcErrorResource(exception: $e, id: $messageId));
145145
} catch (ToolParamsValidatorException $e) {
146-
$jsonRpcErrorException = new JsonRpcErrorException(message: $e->getMessage() . implode( ',', $e->getErrors() ), code: JsonRpcErrorCode::INVALID_PARAMS);
146+
$jsonRpcErrorException = new JsonRpcErrorException(message: $e->getMessage().implode(',', $e->getErrors()), code: JsonRpcErrorCode::INVALID_PARAMS);
147147
$this->pushMessage(clientId: $clientId, message: new JsonRpcErrorResource(exception: $jsonRpcErrorException, id: $messageId));
148148
} catch (Exception $e) {
149149
$jsonRpcErrorException = new JsonRpcErrorException(message: $e->getMessage(), code: JsonRpcErrorCode::INTERNAL_ERROR);

src/Server/Request/ToolsCallHandler.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,10 @@
44

55
use KLP\KlpMcpServer\Exceptions\Enums\JsonRpcErrorCode;
66
use KLP\KlpMcpServer\Exceptions\JsonRpcErrorException;
7+
use KLP\KlpMcpServer\Exceptions\ToolParamsValidatorException;
78
use KLP\KlpMcpServer\Protocol\Handlers\RequestHandler;
89
use KLP\KlpMcpServer\Services\ToolService\ToolParamsValidator;
910
use KLP\KlpMcpServer\Services\ToolService\ToolRepository;
10-
use KLP\KlpMcpServer\Exceptions\ToolParamsValidatorException;
1111

1212
class ToolsCallHandler implements RequestHandler
1313
{
@@ -26,9 +26,10 @@ public function isHandle(string $method): bool
2626
/**
2727
* Executes a specified method with provided parameters and returns the result.
2828
*
29-
* @param string $method The method to be executed.
30-
* @param array|null $params An associative array of parameters required for execution. Must include 'name' as the tool identifier and optionally 'arguments'.
29+
* @param string $method The method to be executed.
30+
* @param array|null $params An associative array of parameters required for execution. Must include 'name' as the tool identifier and optionally 'arguments'.
3131
* @return array The response array containing the execution result, which may vary based on the method.
32+
*
3233
* @throws JsonRpcErrorException If the tool name is missing or the tool is not found
3334
* @throws ToolParamsValidatorException If the provided arguments are invalid.
3435
*/

src/Services/ToolService/ToolParamsValidator.php

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@
77
class ToolParamsValidator
88
{
99
private static ?self $instance = null;
10-
private static array $errors = [];
1110

11+
private static array $errors = [];
1212

1313
/**
1414
* The constructor method is private to restrict external instantiation of the class.
@@ -38,16 +38,15 @@ private function __clone() {}
3838
*/
3939
public static function getInstance(): self
4040
{
41-
return self::$instance ??= new self();
41+
return self::$instance ??= new self;
4242
}
4343

44-
4544
/**
4645
* Validates the provided arguments against the tool schema.
4746
*
48-
* @param array<string, mixed> $toolSchema The schema defining required arguments and their types.
49-
* @param array<string, mixed> $arguments The arguments to be validated.
50-
* @return void
47+
* @param array<string, mixed> $toolSchema The schema defining required arguments and their types.
48+
* @param array<string, mixed> $arguments The arguments to be validated.
49+
*
5150
* @throws ToolParamsValidatorException if validation fails.
5251
*/
5352
public static function validate(array $toolSchema, array $arguments): void
@@ -58,32 +57,31 @@ public static function validate(array $toolSchema, array $arguments): void
5857
foreach ($arguments as $argument => $value) {
5958
$test = isset($toolSchema['arguments'][$argument])
6059
&& self::validateType($toolSchema['arguments'][$argument]['type'], $value);
61-
if (!$test) {
60+
if (! $test) {
6261
self::$errors[] = isset($toolSchema['arguments'][$argument])
63-
? "Invalid argument type for: $argument. Expected: {$toolSchema['arguments'][$argument]['type']}, got: " . gettype($value)
62+
? "Invalid argument type for: $argument. Expected: {$toolSchema['arguments'][$argument]['type']}, got: ".gettype($value)
6463
: "Unknown argument: $argument";
6564
}
6665
$valid &= $test;
6766
}
6867
foreach ($toolSchema['required'] as $argument) {
69-
$test = !empty($arguments[$argument]);
70-
if (!$test) {
68+
$test = ! empty($arguments[$argument]);
69+
if (! $test) {
7170
self::$errors[] = "Missing required argument: $argument";
7271
}
7372
$valid &= $test;
7473
}
7574

76-
if (!$valid) {
75+
if (! $valid) {
7776
throw new ToolParamsValidatorException('Tool arguments validation failed.', self::$errors);
7877
}
7978
}
8079

8180
/**
8281
* Validates if the actual value matches the expected type.
8382
*
84-
* @param string $expectedType The expected data type (e.g., 'string', 'integer', 'boolean').
85-
* @param mixed $actualValue The value to be checked against the expected type.
86-
*
83+
* @param string $expectedType The expected data type (e.g., 'string', 'integer', 'boolean').
84+
* @param mixed $actualValue The value to be checked against the expected type.
8785
* @return bool Returns true if the actual value matches the expected type; otherwise, returns false.
8886
*/
8987
private static function validateType(string $expectedType, mixed $actualValue): bool

0 commit comments

Comments
 (0)