package mcp import ( "encoding/json" "log" ) // extractUCPAgentMeta checks whether the JSON arguments carry a "meta" key with // a nested "ucp-agent.profile" (the UCP-Agent profile advertisement, a sibling // of the real arguments per the UCP spec). If present it logs the profile for // observability and strips "meta" so it does not leak into the tool's argument // namespace. When absent it returns the arguments unchanged — a no-op for tools // that don't speak UCP. func extractUCPAgentMeta(arguments json.RawMessage) json.RawMessage { if len(arguments) == 0 { return arguments } var obj map[string]json.RawMessage if err := json.Unmarshal(arguments, &obj); err != nil { return arguments } metaRaw, hasMeta := obj["meta"] if !hasMeta { return arguments } var meta struct { UCPAgent *struct { Profile string `json:"profile"` } `json:"ucp-agent"` } if err := json.Unmarshal(metaRaw, &meta); err == nil && meta.UCPAgent != nil && meta.UCPAgent.Profile != "" { log.Printf("ucp-agent: profile=%s", meta.UCPAgent.Profile) } delete(obj, "meta") cleaned, err := json.Marshal(obj) if err != nil { return arguments } return cleaned }