@@ -271,6 +271,12 @@ var allowsessionsinstateless = mcpgodebug.Value("allowsessionsinstateless")
271271// the client always attempts to surface the underlying JSON-RPC error.
272272var noprotocolerrorbody = mcpgodebug .Value ("noprotocolerrorbody" )
273273
274+ // disablecontenttypecheck is a compatibility parameter that allows to disable
275+ // Content-Type validation on POST requests.
276+ // See the documentation for the mcpgodebug package for instructions how to enable it.
277+ // The option will be removed in the 1.8.0 version of the SDK.
278+ var disablecontenttypecheck = mcpgodebug .Value ("disablecontenttypecheck" )
279+
274280// writeJSONRPCError writes a JSON-RPC error response with the given HTTP
275281// status code, request ID (may be a zero ID for errors that occur before the
276282// request body has been parsed), and JSON-RPC error.
@@ -342,7 +348,7 @@ func (h *StreamableHTTPHandler) serveStateless(w http.ResponseWriter, req *http.
342348 return
343349 }
344350
345- if baseMediaType (req .Header .Get ("Content-Type" )) != "application/json" {
351+ if disablecontenttypecheck != "1" && baseMediaType (req .Header .Get ("Content-Type" )) != "application/json" {
346352 http .Error (w , "Content-Type must be 'application/json'" , http .StatusUnsupportedMediaType )
347353 return
348354 }
@@ -560,7 +566,7 @@ func (h *StreamableHTTPHandler) serveStatefulDELETE(w http.ResponseWriter, req *
560566// ID, a new session is created (this is the normal path for the first
561567// initialize request).
562568func (h * StreamableHTTPHandler ) serveStatefulPOST (w http.ResponseWriter , req * http.Request ) {
563- if baseMediaType (req .Header .Get ("Content-Type" )) != "application/json" {
569+ if disablecontenttypecheck != "1" && baseMediaType (req .Header .Get ("Content-Type" )) != "application/json" {
564570 http .Error (w , "Content-Type must be 'application/json'" , http .StatusUnsupportedMediaType )
565571 return
566572 }
0 commit comments