Skip to content

Commit 2070d4e

Browse files
committed
Read until end of line
Fixes #1
1 parent ce31c39 commit 2070d4e

File tree

3 files changed

+29
-5
lines changed

3 files changed

+29
-5
lines changed

ChangeLog.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,14 @@ Model Context Protocol change log
33

44
## ?.?.? / ????-??-??
55

6+
## 0.2.0 / 2025-07-29
7+
8+
* Fixed issue #1: Standard I/O default line limit (8192 bytes) exceeded
9+
(@thekid)
10+
* Renamed *first()* -> *value()* to more accurately match what is being
11+
returned
12+
(@thekid)
13+
614
## 0.1.0 / 2025-06-14
715

816
* Hello World! First release - @thekid

src/main/php/io/modelcontextprotocol/StdIo.class.php

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
class StdIo extends Transport {
1111
private $process;
1212
private $cat= null;
13+
private $buffer= '';
1314

1415
/**
1516
* Creates a new transport instance
@@ -66,13 +67,18 @@ public function notify($method) {
6667
public function call($method, $params= null) {
6768
$this->send(['id' => uniqid(), 'method' => $method, 'params' => $params ?: (object)[]]);
6869

69-
$response= $this->process->out->readLine();
70-
$this->cat && $this->cat->debug('<<<', $response);
71-
if (false === $response) {
72-
$this->process->close();
73-
throw new CallFailed(-1, 'Unexpected EOF from process');
70+
while (false === ($p= strpos($this->buffer, "\n"))) {
71+
if (false === ($chunk= $this->process->out->read())) {
72+
$this->process->close();
73+
throw new CallFailed(-1, 'Unexpected EOF from process');
74+
}
75+
$this->buffer.= $chunk;
7476
}
7577

78+
$response= substr($this->buffer, 0, $p);
79+
$this->buffer= substr($this->buffer, $p);
80+
$this->cat && $this->cat->debug('<<<', $response);
81+
7682
return Result::from(json_decode($response, true));
7783
}
7884

src/test/php/io/modelcontextprotocol/unittest/StdIoTest.class.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,16 @@ public function call() {
1515
Assert::equals($value, $fixture->call('test')->value());
1616
}
1717

18+
#[Test, Values([8192, 65536, 1048576])]
19+
public function call_with_output_of_size($size) {
20+
$fixture= new StdIo(new Process(PHP_BINARY, [
21+
'-r',
22+
"echo json_encode(['jsonrpc' => '2.0', 'id' => '6100', 'result' => str_repeat('*', {$size})]), PHP_EOL;"
23+
]));
24+
25+
Assert::equals($size, strlen($fixture->call('test')->value()));
26+
}
27+
1828
#[Test, Expect(class: CallFailed::class, message: '#-1: Unexpected EOF from process')]
1929
public function unexpected_eof() {
2030
(new StdIo(new Process(PHP_BINARY, ['-r', "exit(0);"])))->call('test');

0 commit comments

Comments
 (0)