From 2a2f7fbbfd3e42d818575e4a221cb05b2c6da541 Mon Sep 17 00:00:00 2001 From: Edouard Courty Date: Mon, 6 Oct 2025 22:38:55 +0200 Subject: [PATCH] fix(discovery): fix empty schema in tool discovery --- src/Service/ResponseFactory.php | 3 +++ tests/Controller/EntrypointControllerTest.php | 2 +- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/src/Service/ResponseFactory.php b/src/Service/ResponseFactory.php index c872f5b..f893fc1 100644 --- a/src/Service/ResponseFactory.php +++ b/src/Service/ResponseFactory.php @@ -9,6 +9,7 @@ use Ecourty\McpServerBundle\HttpFoundation\JsonRpcResponse; use Symfony\Component\HttpFoundation\JsonResponse; use Symfony\Component\Serializer\Normalizer\AbstractObjectNormalizer; +use Symfony\Component\Serializer\Serializer; use Symfony\Component\Serializer\SerializerInterface; /** @@ -46,6 +47,8 @@ private function createResponse(JsonRpcResponse $response): JsonResponse { $json = $this->serializer->serialize($response, 'json', [ AbstractObjectNormalizer::SKIP_NULL_VALUES => true, + AbstractObjectNormalizer::PRESERVE_EMPTY_OBJECTS => true, + Serializer::EMPTY_ARRAY_AS_OBJECT => true, ]); return JsonResponse::fromJsonString($json, JsonResponse::HTTP_OK); diff --git a/tests/Controller/EntrypointControllerTest.php b/tests/Controller/EntrypointControllerTest.php index 4e3055e..53e0235 100644 --- a/tests/Controller/EntrypointControllerTest.php +++ b/tests/Controller/EntrypointControllerTest.php @@ -152,7 +152,7 @@ public function testToolList(): void ], $tools[0]['annotations']); $this->assertArrayHasKey('inputSchema', $tools[1]); - $this->assertSame([], $tools[1]['inputSchema']); + $this->assertEmpty($tools[1]['inputSchema']); $this->assertArrayHasKey('inputSchema', $tools[2]); $this->assertSame([