Skip to content

Commit 7c12b85

Browse files
docs: add CORS configuration documentation for HTTP transport
1 parent 9571b2d commit 7c12b85

File tree

1 file changed

+43
-0
lines changed

1 file changed

+43
-0
lines changed

docs/transports.md

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,8 +111,51 @@ $transport = new StreamableHttpTransport(
111111
- **`request`** (required): `ServerRequestInterface` - The incoming PSR-7 HTTP request
112112
- **`responseFactory`** (required): `ResponseFactoryInterface` - PSR-17 factory for creating HTTP responses
113113
- **`streamFactory`** (required): `StreamFactoryInterface` - PSR-17 factory for creating response body streams
114+
- **`corsHeaders`** (optional): `array` - Custom CORS headers to override defaults. Merges with secure defaults. Defaults to `[]`.
114115
- **`logger`** (optional): `LoggerInterface` - PSR-3 logger for debugging. Defaults to `NullLogger`.
115116

117+
### CORS Configuration
118+
119+
The transport sets secure CORS defaults that can be customized or disabled:
120+
121+
```php
122+
// Default CORS headers (backward compatible)
123+
$transport = new StreamableHttpTransport($request, $responseFactory, $streamFactory);
124+
125+
// Restrict to specific origin
126+
$transport = new StreamableHttpTransport(
127+
$request,
128+
$responseFactory,
129+
$streamFactory,
130+
['Access-Control-Allow-Origin' => 'https://myapp.com']
131+
);
132+
133+
// Disable CORS for proxy scenarios
134+
$transport = new StreamableHttpTransport(
135+
$request,
136+
$responseFactory,
137+
$streamFactory,
138+
['Access-Control-Allow-Origin' => '']
139+
);
140+
141+
// Custom headers with logger
142+
$transport = new StreamableHttpTransport(
143+
$request,
144+
$responseFactory,
145+
$streamFactory,
146+
[
147+
'Access-Control-Allow-Origin' => 'https://api.example.com',
148+
'Access-Control-Max-Age' => '86400'
149+
],
150+
$logger
151+
);
152+
```
153+
154+
Default CORS headers:
155+
- `Access-Control-Allow-Origin: *`
156+
- `Access-Control-Allow-Methods: GET, POST, DELETE, OPTIONS`
157+
- `Access-Control-Allow-Headers: Content-Type, Mcp-Session-Id, Mcp-Protocol-Version, Last-Event-ID, Authorization, Accept`
158+
116159
### Architecture
117160

118161
The HTTP transport doesn't run its own web server. Instead, it processes PSR-7 requests and returns PSR-7 responses that

0 commit comments

Comments
 (0)