Skip to content

Commit 8b52418

Browse files
committed
Add documentation for CORS and browser client support in Streamable HTTP mode
1 parent c850a88 commit 8b52418

File tree

1 file changed

+31
-0
lines changed

1 file changed

+31
-0
lines changed

docs/streamable-http.md

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ The Streamable HTTP mode enables the GitHub MCP Server to run as an HTTP service
88
- **OAuth Metadata Endpoints** — Standard `.well-known/oauth-protected-resource` discovery for OAuth clients
99
- **Scope Challenge Support** — Automatic scope validation with proper HTTP 403 responses and `WWW-Authenticate` headers
1010
- **Scope Filtering** — Restrict available tools based on authenticated credentials and permissions
11+
- **CORS & Browser Client Support** — Built-in CORS middleware and configurable cross-origin protection for browser-based MCP clients
1112
- **Custom Base Paths** — Support for reverse proxy deployments with customizable base URLs
1213

1314
## Running the Server
@@ -59,6 +60,36 @@ The OAuth protected resource metadata's `resource` attribute will be populated w
5960

6061
This allows OAuth clients to discover authentication requirements and endpoint information automatically.
6162

63+
## Cross-Origin & Browser Client Support
64+
65+
The HTTP server includes built-in CORS middleware and cross-origin request handling to support browser-based MCP clients (e.g., web apps, MCP Inspector).
66+
67+
### Default Behavior
68+
69+
`RunHTTPServer` enables browser cross-origin support out of the box by wiring in two things:
70+
71+
1. **CORS middleware** (`SetCorsHeaders`) — responds to preflight `OPTIONS` requests and sets `Access-Control-*` headers on all MCP endpoint responses
72+
2. **Cross-origin protection bypass** — bypasses the SDK's `Sec-Fetch-Site` rejection so cross-origin POST requests are allowed
73+
74+
This is safe because the server authenticates exclusively via bearer tokens (`Authorization` header), which are not ambient credentials — a malicious cross-origin page cannot cause the browser to attach them automatically. Standard CSRF protection is therefore not required.
75+
76+
> **Note:** CORS headers on MCP endpoints are provided by `SetCorsHeaders` middleware. OAuth metadata discovery routes (e.g., `/.well-known/oauth-protected-resource`) handle CORS independently.
77+
78+
### Library / Custom Integrations
79+
80+
If you embed the server as a library (using `ServerConfig` directly rather than `RunHTTPServer`), neither the CORS middleware nor the cross-origin bypass is applied automatically. To support browser clients, you must:
81+
82+
1. Add `middleware.SetCorsHeaders` to your router
83+
2. Set the `CrossOriginProtection` field on `ServerConfig` with an appropriate bypass pattern
84+
85+
The `CrossOriginProtection` options are:
86+
87+
- **`nil`**`RunHTTPServer` auto-bypasses (allows all origins); library consumers get the SDK default (reject cross-origin POSTs)
88+
- **Explicit bypass** — Create a `CrossOriginProtection` with `AddInsecureBypassPattern("/")` to allow all cross-origin requests
89+
- **SDK default** — Use `http.NewCrossOriginProtection()` without any bypass patterns to reject cross-origin POSTs
90+
91+
The SDK default is appropriate when browser cross-origin clients are not required (e.g., native CLI clients only, or same-origin browser deployments where the client and server share the same origin).
92+
6293
## Client Configuration
6394

6495
### Using OAuth Authentication

0 commit comments

Comments
 (0)