From 45b381b8065e87fdabeb5457dcbda84f0cb70854 Mon Sep 17 00:00:00 2001 From: Michael Dyrynda Date: Wed, 21 Jan 2026 23:29:52 +1030 Subject: [PATCH 1/3] add support for passing custom headers in HttpTransport --- README.md | 3 +++ src/Transport/HttpTransport.php | 16 ++++++++++++++++ tests/Unit/Transport/HttpTransportTest.php | 22 ++++++++++++++++++++++ 3 files changed, 41 insertions(+) diff --git a/README.md b/README.md index 856216d..a0bb783 100644 --- a/README.md +++ b/README.md @@ -136,6 +136,9 @@ For MCP servers that communicate over HTTP: 'api_key' => env('RELAY_GITHUB_SERVER_API_KEY'), 'timeout' => 30, 'transport' => Transport::Http, + 'headers' => [ + 'User-Agent' => 'prism-php-relay/1.0', + ] ], ``` diff --git a/src/Transport/HttpTransport.php b/src/Transport/HttpTransport.php index d09015d..7e2df63 100644 --- a/src/Transport/HttpTransport.php +++ b/src/Transport/HttpTransport.php @@ -78,6 +78,10 @@ protected function sendHttpRequest(array $payload): Response $this->hasApiKey(), fn ($http) => $http->withToken($this->getApiKey()) ) + ->when( + $this->hasHeaders(), + fn ($http) => $http->withHeaders($this->getHeaders()) + ) ->post($this->getServerUrl(), $payload); } @@ -91,11 +95,23 @@ protected function hasApiKey(): bool return isset($this->config['api_key']) && $this->config['api_key'] !== null; } + protected function hasHeaders(): bool + { + return isset($this->config['headers']) + && is_array($this->config['headers']) + && ! empty($this->config['headers']); + } + protected function getApiKey(): string { return (string) ($this->config['api_key'] ?? ''); } + protected function getHeaders(): array + { + return $this->config['headers'] ?? []; + } + protected function getServerUrl(): string { return $this->config['url']; diff --git a/tests/Unit/Transport/HttpTransportTest.php b/tests/Unit/Transport/HttpTransportTest.php index 889e4b5..0a71f0f 100644 --- a/tests/Unit/Transport/HttpTransportTest.php +++ b/tests/Unit/Transport/HttpTransportTest.php @@ -202,3 +202,25 @@ Http::assertSent(fn ($request) => $request->hasHeader('Accept', 'application/json')); }); + +it('supports passing arbitrary request headers', function (): void { + $transport = new HttpTransport([ + 'url' => 'http://example.com/api', + 'timeout' => 30, + 'headers' => [ + 'User-Agent' => 'prism-php-relay/1.0', + ], + ]); + + Http::fake([ + 'http://example.com/api' => Http::response([ + 'jsonrpc' => '2.0', + 'id' => '1', + 'result' => ['status' => 'success'], + ]), + ]); + + $transport->sendRequest('test/method'); + + Http::assertSent(fn ($request) => $request->hasHeader('User-Agent', 'prism-php-relay/1.0')); +}); From f1851f0a7efca4eeb0891f48c865d9c08960ba54 Mon Sep 17 00:00:00 2001 From: Michael Dyrynda Date: Wed, 21 Jan 2026 23:58:28 +1030 Subject: [PATCH 2/3] add array annotation --- src/Transport/HttpTransport.php | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/Transport/HttpTransport.php b/src/Transport/HttpTransport.php index 7e2df63..c8e1ec8 100644 --- a/src/Transport/HttpTransport.php +++ b/src/Transport/HttpTransport.php @@ -107,6 +107,9 @@ protected function getApiKey(): string return (string) ($this->config['api_key'] ?? ''); } + /** + * @return array + */ protected function getHeaders(): array { return $this->config['headers'] ?? []; From e20fe0144d38d15f35537a806d7fa83096e6f9d9 Mon Sep 17 00:00:00 2001 From: Michael Dyrynda Date: Wed, 21 Jan 2026 23:59:37 +1030 Subject: [PATCH 3/3] formatting --- src/Relay.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Relay.php b/src/Relay.php index cca3b53..9cdd7dc 100644 --- a/src/Relay.php +++ b/src/Relay.php @@ -340,7 +340,7 @@ protected function getSchemeParameters(array $properties, string $definitionName * * @throws RelayException */ - protected function getSchemeParameter(string $name, array $property, string $definitionName): Schema|null + protected function getSchemeParameter(string $name, array $property, string $definitionName): ?Schema { if ($property === []) { return null;