Skip to content

Commit a06d1bd

Browse files
fix: json schema validator error being thrown for tools with no argument
1 parent 02747af commit a06d1bd

File tree

2 files changed

+6
-14
lines changed

2 files changed

+6
-14
lines changed

src/Processor.php

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -285,15 +285,15 @@ private function handlePromptsList(array $params): ListPromptsResult
285285
private function handleToolCall(array $params): CallToolResult
286286
{
287287
$toolName = $params['name'] ?? null;
288-
$argumentsRaw = $params['arguments'] ?? null;
288+
$arguments = $params['arguments'] ?? null;
289289

290290
if (! is_string($toolName) || empty($toolName)) {
291291
throw McpServerException::invalidParams("Missing or invalid 'name' parameter for tools/call.");
292292
}
293293

294-
if ($argumentsRaw === null) {
295-
$argumentsRaw = new stdClass;
296-
} elseif (! is_array($argumentsRaw) && ! $argumentsRaw instanceof stdClass) {
294+
if ($arguments === null || $arguments === []) {
295+
$arguments = new stdClass;
296+
} elseif (! is_array($arguments) && ! $arguments instanceof stdClass) {
297297
throw McpServerException::invalidParams("Parameter 'arguments' must be an object/array for tools/call.");
298298
}
299299

@@ -303,9 +303,8 @@ private function handleToolCall(array $params): CallToolResult
303303
}
304304

305305
$inputSchema = $definition->getInputSchema();
306-
$argumentsForValidation = is_object($argumentsRaw) ? (array) $argumentsRaw : $argumentsRaw;
307306

308-
$validationErrors = $this->schemaValidator->validateAgainstJsonSchema($argumentsForValidation, $inputSchema);
307+
$validationErrors = $this->schemaValidator->validateAgainstJsonSchema($arguments, $inputSchema);
309308

310309
if (! empty($validationErrors)) {
311310
$errorMessages = [];
@@ -325,7 +324,7 @@ private function handleToolCall(array $params): CallToolResult
325324
throw McpServerException::invalidParams($summaryMessage, data: ['validation_errors' => $validationErrors]);
326325
}
327326

328-
$argumentsForPhpCall = (array) $argumentsRaw;
327+
$argumentsForPhpCall = (array) $arguments;
329328

330329
try {
331330
$instance = $this->container->get($definition->getClassName());

tests/Unit/Support/SchemaGeneratorTest.php

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -143,13 +143,6 @@ function setupDocBlockExpectations(Mockery\MockInterface $parserMock, Reflection
143143
});
144144

145145
test('generates schema for enum types', function () {
146-
// Skip test if PHP version is less than 8.1
147-
if (version_compare(PHP_VERSION, '8.1', '<')) {
148-
expect(true)->toBeTrue(); // Placeholder assertion
149-
150-
return; // Skip test
151-
}
152-
153146
$method = new ReflectionMethod(SchemaGeneratorTestStub::class, 'enumTypes');
154147
setupDocBlockExpectations($this->docBlockParserMock, $method);
155148

0 commit comments

Comments
 (0)