Skip to content

Commit 977cb38

Browse files
committed
Write complete JSON response to log
1 parent 686b748 commit 977cb38

1 file changed

Lines changed: 7 additions & 4 deletions

File tree

src/main/php/io/modelcontextprotocol/server/JsonRpc.class.php

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,10 @@ private function send($response, $id, $result) {
4848
$response->header('Content-Type', self::JSON);
4949

5050
$output= new StreamOutput($response->stream());
51+
$payload= ['jsonrpc' => '2.0', 'id' => $id, 'result' => $result];
5152
try {
52-
$output->write(['jsonrpc' => '2.0', 'id' => $id, 'result' => $result]);
53+
$this->cat && $this->cat->debug('<<<', $payload);
54+
$output->write($payload);
5355
} finally {
5456
$output->close();
5557
}
@@ -69,8 +71,10 @@ private function error($response, $id, $code, $message) {
6971
$response->header('Content-Type', self::JSON);
7072

7173
$output= new StreamOutput($response->stream());
74+
$payload= ['jsonrpc' => '2.0', 'id' => $id, 'error' => ['code' => $code, 'message' => $message]];
7275
try {
73-
$output->write(['jsonrpc' => '2.0', 'id' => $id, 'error' => ['code' => $code, 'message' => $message]]);
76+
$this->cat && $this->cat->debug('<<<', $payload);
77+
$output->write($payload);
7478
} finally {
7579
$output->close();
7680
}
@@ -91,7 +95,6 @@ public function handle($request, $response) {
9195
foreach ($this->routes as $pattern => $route) {
9296
if (preg_match($pattern, $payload['method'], $matches)) {
9397
$result= $route($payload, $request->pass('matches', $matches));
94-
$this->cat && $this->cat->debug('<<<', $result);
9598

9699
if ($result instanceof Response) {
97100
$response->answer($result->status);
@@ -110,7 +113,7 @@ public function handle($request, $response) {
110113
}
111114
}
112115

113-
$this->cat && $this->cat->warn('<<<', 'Unhandled', array_keys($this->routes));
116+
$this->cat && $this->cat->warn('<<<', 'Unhandled', $payload['method']);
114117
$this->error($response, $payload['id'], self::METHOD_NOT_FOUND, $payload['method']);
115118
} catch (FormatException $e) {
116119
$this->cat && $this->cat->warn('<<<', $e);

0 commit comments

Comments
 (0)