Skip to content

Commit fa158a3

Browse files
authored
feat: Add support for passing along custom headers for MCP connections (#45)
2 parents 0e3037b + 060347e commit fa158a3

2 files changed

Lines changed: 13 additions & 5 deletions

File tree

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
"laravel/prompts": "^0.3.5",
3232
"phpstan/phpstan": "^2.1",
3333
"phpunit/phpunit": "^11.0 || ^12.0",
34-
"swisnl/mcp-client": "^0.4 || ^0.5",
34+
"swisnl/mcp-client": "^0.5.1 || ^0.6",
3535
"swisnl/php-http-fixture-client": "^3.1",
3636
"symfony/console": "^7.2",
3737
"vlucas/phpdotenv": "^5.6"

src/Mcp/McpConnection.php

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -70,11 +70,15 @@ public function __construct(
7070
* Create a new MCP connection for a given Streamable HTTP endpoint
7171
*
7272
* @param string $endpoint
73+
* @param array<string, string> $headers
7374
* @return self
7475
*/
75-
public static function forStreamableHttp(string $endpoint): self
76+
public static function forStreamableHttp(string $endpoint, array $headers = []): self
7677
{
77-
$client = Client::withStreamableHttp($endpoint);
78+
$client = Client::withStreamableHttp(
79+
endpoint: $endpoint,
80+
headers: $headers,
81+
);
7882

7983
$connection = new self($client, 'MCP server');
8084
$connection->withCacheKey('mcp_tools_' . md5($endpoint));
@@ -86,11 +90,15 @@ public static function forStreamableHttp(string $endpoint): self
8690
* Create a new MCP connection for a given SSE endpoint
8791
*
8892
* @param string $endpoint
93+
* @param array<string, string> $headers
8994
* @return self
9095
*/
91-
public static function forSse(string $endpoint): self
96+
public static function forSse(string $endpoint, array $headers = []): self
9297
{
93-
$client = Client::withSse($endpoint);
98+
$client = Client::withSse(
99+
endpoint: $endpoint,
100+
headers: $headers,
101+
);
94102

95103
$connection = new self($client, 'MCP server');
96104
$connection->withCacheKey('mcp_tools_' . md5($endpoint));

0 commit comments

Comments
 (0)