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:
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user