fix(mcp) : return CallToolResult to prevent structuredContent serialization issue

Tools now return CallToolResult directly instead of Content arrays,
preventing the MCP SDK from auto-generating structuredContent as a
JSON array (which Claude Code rejects — expects a JSON object/record).
Also adds Accept header to test helpers and SSE response parsing.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
Matthieu
2026-03-16 17:24:04 +01:00
parent f965affc94
commit add3a9a21f
60 changed files with 156 additions and 84 deletions
+6 -9
View File
@@ -5,6 +5,7 @@ declare(strict_types=1);
namespace App\Mcp\Tool;
use Mcp\Schema\Content\TextContent;
use Mcp\Schema\Result\CallToolResult;
use RuntimeException;
use Symfony\Bundle\SecurityBundle\Security;
@@ -17,12 +18,11 @@ trait McpToolHelper
}
}
/**
* @return array{TextContent}
*/
private function jsonResponse(array $data): array
private function jsonResponse(array $data): CallToolResult
{
return [new TextContent(text: json_encode($data, JSON_THROW_ON_ERROR | JSON_UNESCAPED_UNICODE))];
return new CallToolResult(
content: [new TextContent(text: json_encode($data, JSON_THROW_ON_ERROR | JSON_UNESCAPED_UNICODE))],
);
}
private function mcpError(string $category, string $message): never
@@ -42,10 +42,7 @@ trait McpToolHelper
return ['page' => $page, 'limit' => $limit, 'offset' => $offset];
}
/**
* @return array{TextContent}
*/
private function paginatedResponse(array $items, int $total, int $page, int $limit): array
private function paginatedResponse(array $items, int $total, int $page, int $limit): CallToolResult
{
return $this->jsonResponse([
'items' => $items,