Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions src/main/php/io/modelcontextprotocol/StreamableHttp.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,21 @@ public function version($version) {
$this->endpoint->with(['MCP-Protocol-Version' => $version]);
}

/** @return [:string] */
public function headers() { return $this->endpoint->headers(); }

/**
* Adds headers to be sent with every request
*
* @param string|[:string] $arg
* @param ?string $value
* @return self
*/
public function with($arg, $value= null) {
$this->endpoint->with($arg, $value);
return $this;
}

/**
* Sends a notification
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,32 @@ private function newFixture(array &$sessions, string $base= '/mcp'): StreamableH
return new StreamableHttp(new TestEndpoint($routes, $base));
}

#[Test]
public function accepts_json_and_event_stream_by_default() {
Assert::equals(
'text/event-stream, application/json',
(new StreamableHttp('https://example.com/'))->headers()['Accept']
);
}

#[Test]
public function pass_header() {
$token= 'Token test';
Assert::equals($token, (new StreamableHttp('https://example.com/'))
->with('Authorization', $token)
->headers()['Authorization']
);
}

#[Test]
public function pass_headers() {
$token= 'Token test';
Assert::equals($token, (new StreamableHttp('https://example.com/'))
->with(['Authorization' => $token])
->headers()['Authorization']
);
}

#[Test, Values(['application/json', 'application/json; charset=utf-8'])]
public function json($type) {
$value= ['name' => 'test', 'version' => '1.0.0'];
Expand Down
Loading