MCPGODEBUG update for 1.6.0 (#893)

This commit is contained in:
Maciej Kisiel 2026-04-30 09:54:32 +02:00 • committed by GitHub
commit f5f2015413
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -11,8 +11,6 @@ import (
"fmt"
internaljson "github.com/modelcontextprotocol/go-sdk/internal/json"
"github.com/modelcontextprotocol/go-sdk/internal/mcpgodebug"
)
// ID is a Request identifier, which is defined by the spec to be a string, integer, or null.
@ -219,18 +217,8 @@ func marshalToRaw(obj any) (json.RawMessage, error) {
return json.RawMessage(data), nil
}
// jsonescaping is a compatibility parameter that allows to restore
// JSON escaping in the JSON marshaling, which stopped being the default
// in the 1.4.0 version of the SDK. See the documentation for the
// mcpgodebug package for instructions how to enable it.
// The option will be removed in the 1.6.0 version of the SDK.
var jsonescaping = mcpgodebug.Value("jsonescaping")
// jsonMarshal marshals obj to JSON like json.Marshal but without HTML escaping.
func jsonMarshal(obj any) ([]byte, error) {
if jsonescaping == "1" {
return json.Marshal(obj)
}
var buf bytes.Buffer
enc := json.NewEncoder(&buf)
enc.SetEscapeHTML(false)