Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions examples/02-discovery-http-userprofile/McpElements.php
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,12 @@ public function sendWelcomeMessage(string $userId, ?string $customMessage = null
return ['success' => true, 'message_sent' => $message];
}

#[McpTool(name: 'test_tool_without_params')]
public function testToolWithoutParams()
{
return ['success' => true, 'message' => 'Test tool without params'];
}

/**
* Generates a prompt to write a bio for a user.
*
Expand Down
4 changes: 2 additions & 2 deletions examples/02-discovery-http-userprofile/server.php
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,8 @@ public function log($level, \Stringable|string $message, array $context = []): v

$server->discover(__DIR__, ['.']);

$transport = new HttpServerTransport('127.0.0.1', 8080, 'mcp');
// $transport = new StreamableHttpServerTransport('127.0.0.1', 8080, 'mcp');
// $transport = new HttpServerTransport('127.0.0.1', 8080, 'mcp');
$transport = new StreamableHttpServerTransport('127.0.0.1', 8080, 'mcp');

$server->listen($transport);

Expand Down
8 changes: 6 additions & 2 deletions src/Utils/SchemaValidator.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,10 @@ public function __construct(LoggerInterface $logger)
*/
public function validateAgainstJsonSchema(mixed $data, array|object $schema): array
{
if (is_array($data) && empty($data)) {
$data = new \stdClass();
}

try {
// --- Schema Preparation ---
if (is_array($schema)) {
Expand Down Expand Up @@ -192,7 +196,7 @@ private function formatValidationError(ValidationError $error): string
switch (strtolower($keyword)) {
case 'required':
$missing = $args['missing'] ?? [];
$formattedMissing = implode(', ', array_map(fn ($p) => "`{$p}`", $missing));
$formattedMissing = implode(', ', array_map(fn($p) => "`{$p}`", $missing));
$message = "Missing required properties: {$formattedMissing}.";
break;
case 'type':
Expand Down Expand Up @@ -286,7 +290,7 @@ private function formatValidationError(ValidationError $error): string
break;
case 'additionalProperties': // Corrected casing
$unexpected = $args['properties'] ?? [];
$formattedUnexpected = implode(', ', array_map(fn ($p) => "`{$p}`", $unexpected));
$formattedUnexpected = implode(', ', array_map(fn($p) => "`{$p}`", $unexpected));
$message = "Object contains unexpected additional properties: {$formattedUnexpected}.";
break;
case 'format':
Expand Down
2 changes: 1 addition & 1 deletion tests/Unit/Utils/SchemaValidatorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,7 @@ function getValidData(): array
$errors = $this->validator->validateAgainstJsonSchema($data, $schema);

expect($errors)->not->toBeEmpty()
->and($errors[0]['keyword'])->toBe('type');
->and($errors[0]['keyword'])->toBe('required');
});

test('handles empty schema (allows anything)', function () {
Expand Down