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

View File

@@ -108,6 +108,7 @@ abstract class AbstractApiTestCase extends ApiTestCase
$response = $client->request('POST', '/_mcp', [
'headers' => [
'Content-Type' => 'application/json',
'Accept' => 'application/json, text/event-stream',
'X-Profile-Id' => $profileId,
'X-Profile-Password' => $password,
],
@@ -128,6 +129,7 @@ abstract class AbstractApiTestCase extends ApiTestCase
$client->request('POST', '/_mcp', [
'headers' => [
'Content-Type' => 'application/json',
'Accept' => 'application/json, text/event-stream',
'X-Profile-Id' => $profileId,
'X-Profile-Password' => $password,
'Mcp-Session-Id' => $sessionId,
@@ -149,6 +151,7 @@ abstract class AbstractApiTestCase extends ApiTestCase
$response = $session['client']->request('POST', '/_mcp', [
'headers' => [
'Content-Type' => 'application/json',
'Accept' => 'application/json, text/event-stream',
'X-Profile-Id' => $session['profileId'],
'X-Profile-Password' => $session['password'],
'Mcp-Session-Id' => $session['sessionId'],
@@ -164,7 +167,24 @@ abstract class AbstractApiTestCase extends ApiTestCase
]),
]);
$data = $response->toArray(false);
$raw = $response->getContent(false);
$data = json_decode($raw, true);
if (null === $data) {
// SSE format: parse "data: {...}" lines
foreach (explode("\n", $raw) as $line) {
if (str_starts_with($line, 'data: ')) {
$parsed = json_decode(substr($line, 6), true);
if ($parsed && (isset($parsed['result']) || isset($parsed['error']))) {
$data = $parsed;
break;
}
}
}
}
$data ??= [];
if (isset($data['result']['content'][0]['text'])) {
$data['_parsed'] = json_decode($data['result']['content'][0]['text'], true);