| 1 | // Copyright 2025 The Go MCP SDK Authors. All rights reserved. |
| 2 | // Use of this source code is governed by an MIT-style |
| 3 | // license that can be found in the LICENSE file. |
| 4 | |
| 5 | package mcp |
| 6 | |
| 7 | import ( |
| 8 | "encoding/json" |
| 9 | |
| 10 | internaljson "github.com/modelcontextprotocol/go-sdk/internal/json" |
| 11 | ) |
| 12 | |
| 13 | func assert(cond bool, msg string) { |
| 14 | if !cond { |
| 15 | panic(msg) |
| 16 | } |
| 17 | } |
| 18 | |
| 19 | // remarshal marshals from to JSON, and then unmarshals into to, which must be |
| 20 | // a pointer type. |
| 21 | func remarshal(from, to any) error { |
| 22 | data, err := json.Marshal(from) |
| 23 | if err != nil { |
| 24 | return err |
| 25 | } |
| 26 | if err := internaljson.Unmarshal(data, to); err != nil { |
| 27 | return err |
| 28 | } |
| 29 | return nil |
| 30 | } |