Skip to content

Commit da99324

Browse files
committed
feat: add disablecontenttypecheck MCPGODEBUG option to skip Content-Type validation on POST requests
1 parent f5f2015 commit da99324

4 files changed

Lines changed: 26 additions & 2 deletions

File tree

docs/mcpgodebug.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,15 @@
1818

1919
## `MCPGODEBUG` history
2020

21+
### 1.6.1
22+
23+
Options listed below were added and will be removed in the 1.8.0 version of the SDK.
24+
25+
- `disablecontenttypecheck` added. If set to `1`, Content-Type validation on
26+
HTTP POST requests will be disabled, allowing requests with non-JSON or missing
27+
Content-Type headers. The default behavior is to validate that HTTP POST
28+
requests have Content-Type: application/json.
29+
2130
### 1.6.0
2231

2332
Options listed below were added and will be removed in the 1.8.0 version of the SDK.

internal/docs/mcpgodebug.src.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,15 @@
1717

1818
## `MCPGODEBUG` history
1919

20+
### 1.6.1
21+
22+
Options listed below were added and will be removed in the 1.8.0 version of the SDK.
23+
24+
- `disablecontenttypecheck` added. If set to `1`, Content-Type validation on
25+
HTTP POST requests will be disabled, allowing requests with non-JSON or missing
26+
Content-Type headers. The default behavior is to validate that HTTP POST
27+
requests have Content-Type: application/json.
28+
2029
### 1.6.0
2130

2231
Options listed below were added and will be removed in the 1.8.0 version of the SDK.

mcp/sse.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,7 @@ func (h *SSEHandler) ServeHTTP(w http.ResponseWriter, req *http.Request) {
202202
}
203203

204204
// Validate 'Content-Type' header.
205-
if req.Method == http.MethodPost {
205+
if disablecontenttypecheck != "1" && req.Method == http.MethodPost {
206206
mediaType, _, err := mime.ParseMediaType(req.Header.Get("Content-Type"))
207207
if err != nil || mediaType != "application/json" {
208208
http.Error(w, "Content-Type must be 'application/json'", http.StatusUnsupportedMediaType)

mcp/streamable.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -246,6 +246,12 @@ var disablelocalhostprotection = mcpgodebug.Value("disablelocalhostprotection")
246246
// The option will be removed in the 1.8.0 version of the SDK.
247247
var enableoriginverification = mcpgodebug.Value("enableoriginverification")
248248

249+
// disablecontenttypecheck is a compatibility parameter that allows to disable
250+
// Content-Type validation on POST requests.
251+
// See the documentation for the mcpgodebug package for instructions how to enable it.
252+
// The option will be removed in the 1.8.0 version of the SDK.
253+
var disablecontenttypecheck = mcpgodebug.Value("disablecontenttypecheck")
254+
249255
func (h *StreamableHTTPHandler) ServeHTTP(w http.ResponseWriter, req *http.Request) {
250256
// DNS rebinding protection: auto-enabled for localhost servers.
251257
// See: https://modelcontextprotocol.io/specification/2025-11-25/basic/security_best_practices#local-mcp-server-compromise
@@ -267,7 +273,7 @@ func (h *StreamableHTTPHandler) ServeHTTP(w http.ResponseWriter, req *http.Reque
267273
}
268274

269275
// Validate 'Content-Type' header.
270-
if req.Method == http.MethodPost && baseMediaType(req.Header.Get("Content-Type")) != "application/json" {
276+
if disablecontenttypecheck != "1" && req.Method == http.MethodPost && baseMediaType(req.Header.Get("Content-Type")) != "application/json" {
271277
http.Error(w, "Content-Type must be 'application/json'", http.StatusUnsupportedMediaType)
272278
return
273279
}

0 commit comments

Comments
 (0)