-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathmcp.go
99 lines (80 loc) · 2.09 KB
/
mcp.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
package mcp
type Request[T any] struct {
Params *T
method string
id string
}
func (r *Request[T]) ID() string {
return r.id
}
func NewRequest[T any](params *T) *Request[T] {
return &Request[T]{
Params: params,
}
}
// Any returns the concrete request params as an empty interface, so that
// *Request implements the [AnyRequest] interface.
func (r *Request[_]) Any() any {
return r.Params
}
func (r *Request[_]) Method() string {
return r.method
}
// internalOnly implements AnyRequest.
func (r *Request[_]) internalOnly() {}
// AnyRequest is the common method set of every [Request], regardless of type
// parameter. It's used in unary interceptors.
//
// To preserve our ability to add methods to this interface without breaking
// backward compatibility, only types defined in this package can implement
// AnyRequest.
type AnyRequest interface {
Any() any
ID() string
Method() string
internalOnly()
}
type Response[T any] struct {
Result *T
id string
}
func NewResponse[T any](result *T) *Response[T] {
return &Response[T]{
Result: result,
}
}
// Any returns the concrete result as an empty interface, so that
// *Response implements the [AnyResponse] interface.
func (r *Response[_]) Any() any {
return r.Result
}
func (r *Response[_]) ID() string {
return r.id
}
// internalOnly implements AnyResponse.
func (r *Response[_]) internalOnly() {}
// AnyResponse is the common method set of every [Response], regardless of type
// parameter. It's used in unary interceptors.
//
// Headers and trailers beginning with "Connect-" and "Grpc-" are reserved for
// use by the gRPC and Connect protocols: applications may read them but
// shouldn't write them.
//
// To preserve our ability to add methods to this interface without breaking
// backward compatibility, only types defined in this package can implement
// AnyResponse.
type AnyResponse interface {
Any() any
ID() string
internalOnly()
}
type Error struct {
code int
err error
}
func (e *Error) Error() string {
return e.err.Error()
}
func NewError(code int, underlying error) *Error {
return &Error{code: code, err: underlying}
}