package mcp import ( "encoding/json" "testing" ) // The fingerprint must cover everything the approval was given for, and must // not move when only the JSON spelling of the schema does. func TestFingerprintCoversTheDeclaredShape(t *testing.T) { base := Tool{Name: "list_tasks", Description: "list them", ReadOnly: true, InputSchema: json.RawMessage(`{"type":"object","properties":{}}`)} same := base same.InputSchema = json.RawMessage("{\n \"properties\": {},\n \"type\": \"object\"\n}") if Fingerprint(base) != Fingerprint(same) { t.Error("reformatting the schema must not read as a redefinition") } for name, mut := range map[string]func(*Tool){ "description": func(x *Tool) { x.Description = "delete them" }, "schema": func(x *Tool) { x.InputSchema = json.RawMessage(`{"required":["id"]}`) }, "readonly": func(x *Tool) { x.ReadOnly = false }, "name": func(x *Tool) { x.Name = "delete_tasks" }, } { t.Run(name, func(t *testing.T) { got := base mut(&got) if Fingerprint(got) == Fingerprint(base) { t.Error("a redefinition must change the fingerprint") } }) } }