MCPcopy Create free account
hub / github.com/modelcontextprotocol/go-sdk / MakeID

Function MakeID

internal/jsonrpc2/messages.go:30–40  ·  view source on GitHub ↗

MakeID coerces the given Go value to an ID. The value should be the default JSON marshaling of a Request identifier: nil, float64, or string. Returns an error if the value type was not a valid Request ID type. TODO: ID can't be a json.Marshaler/Unmarshaler, because we want to omitzero. Simplify th

(v any)

Source from the content-addressed store, hash-verified

28// Simplify this package by making ID json serializable once we can rely on
29// omitzero.
30func MakeID(v any) (ID, error) {
31 switch v := v.(type) {
32 case nil:
33 return ID{}, nil
34 case float64:
35 return Int64ID(int64(v)), nil
36 case string:
37 return StringID(v), nil
38 }
39 return ID{}, fmt.Errorf("%w: invalid ID type %T", ErrParse, v)
40}
41
42// Message is the interface to all jsonrpc2 message types.
43// They share no common functionality, but are a closed set of concrete types

Callers 3

PreemptMethod · 0.92
MakeIDFunction · 0.92
DecodeMessageFunction · 0.70

Calls 2

Int64IDFunction · 0.85
StringIDFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…