-
Notifications
You must be signed in to change notification settings - Fork 21
/
Copy pathtool_response_types.go
162 lines (135 loc) · 6.8 KB
/
tool_response_types.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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
package mcp_golang
import (
"encoding/json"
"fmt"
)
// Capabilities that a server may support. Known capabilities are defined here, in
// this schema, but this is not a closed set: any server can define its own,
// additional capabilities.
type ServerCapabilities struct {
// Experimental, non-standard capabilities that the server supports.
Experimental ServerCapabilitiesExperimental `json:"experimental,omitempty" yaml:"experimental,omitempty" mapstructure:"experimental,omitempty"`
// Present if the server supports sending log messages to the client.
Logging ServerCapabilitiesLogging `json:"logging,omitempty" yaml:"logging,omitempty" mapstructure:"logging,omitempty"`
// Present if the server offers any prompt templates.
Prompts *ServerCapabilitiesPrompts `json:"prompts,omitempty" yaml:"prompts,omitempty" mapstructure:"prompts,omitempty"`
// Present if the server offers any resources to read.
Resources *ServerCapabilitiesResources `json:"resources,omitempty" yaml:"resources,omitempty" mapstructure:"resources,omitempty"`
// Present if the server offers any tools to call.
Tools *ServerCapabilitiesTools `json:"tools,omitempty" yaml:"tools,omitempty" mapstructure:"tools,omitempty"`
}
// Experimental, non-standard capabilities that the server supports.
type ServerCapabilitiesExperimental map[string]map[string]interface{}
// Present if the server supports sending log messages to the client.
type ServerCapabilitiesLogging map[string]interface{}
// Present if the server offers any prompt templates.
type ServerCapabilitiesPrompts struct {
// Whether this server supports notifications for changes to the prompt list.
ListChanged *bool `json:"listChanged,omitempty" yaml:"listChanged,omitempty" mapstructure:"listChanged,omitempty"`
}
// Present if the server offers any resources to read.
type ServerCapabilitiesResources struct {
// Whether this server supports notifications for changes to the resource list.
ListChanged *bool `json:"listChanged,omitempty" yaml:"listChanged,omitempty" mapstructure:"listChanged,omitempty"`
// Whether this server supports subscribing to resource updates.
Subscribe *bool `json:"subscribe,omitempty" yaml:"subscribe,omitempty" mapstructure:"subscribe,omitempty"`
}
// Present if the server offers any tools to call.
type ServerCapabilitiesTools struct {
// Whether this server supports notifications for changes to the tool list.
ListChanged *bool `json:"listChanged,omitempty" yaml:"listChanged,omitempty" mapstructure:"listChanged,omitempty"`
}
// After receiving an initialize request from the client, the server sends this
// response.
type InitializeResponse struct {
// This result property is reserved by the protocol to allow clients and servers
// to attach additional metadata to their responses.
Meta initializeResultMeta `json:"_meta,omitempty" yaml:"_meta,omitempty" mapstructure:"_meta,omitempty"`
// Capabilities corresponds to the JSON schema field "capabilities".
Capabilities ServerCapabilities `json:"capabilities" yaml:"capabilities" mapstructure:"capabilities"`
// Instructions describing how to use the server and its features.
//
// This can be used by clients to improve the LLM's understanding of available
// tools, resources, etc. It can be thought of like a "hint" to the model. For
// example, this information MAY be added to the system prompt.
Instructions *string `json:"instructions,omitempty" yaml:"instructions,omitempty" mapstructure:"instructions,omitempty"`
// The version of the Model Context Protocol that the server wants to use. This
// may not match the version that the client requested. If the client cannot
// support this version, it MUST disconnect.
ProtocolVersion string `json:"protocolVersion" yaml:"protocolVersion" mapstructure:"protocolVersion"`
// ServerInfo corresponds to the JSON schema field "serverInfo".
ServerInfo implementation `json:"serverInfo" yaml:"serverInfo" mapstructure:"serverInfo"`
}
// This result property is reserved by the protocol to allow clients and servers to
// attach additional metadata to their responses.
type initializeResultMeta map[string]interface{}
// UnmarshalJSON implements json.Unmarshaler.
func (j *InitializeResponse) UnmarshalJSON(b []byte) error {
var raw map[string]interface{}
if err := json.Unmarshal(b, &raw); err != nil {
return err
}
if _, ok := raw["capabilities"]; raw != nil && !ok {
return fmt.Errorf("field capabilities in initializeResult: required")
}
if _, ok := raw["protocolVersion"]; raw != nil && !ok {
return fmt.Errorf("field protocolVersion in initializeResult: required")
}
if _, ok := raw["serverInfo"]; raw != nil && !ok {
return fmt.Errorf("field serverInfo in initializeResult: required")
}
type Plain InitializeResponse
var plain Plain
if err := json.Unmarshal(b, &plain); err != nil {
return err
}
*j = InitializeResponse(plain)
return nil
}
// Describes the name and version of an MCP implementation.
type implementation struct {
// Name corresponds to the JSON schema field "name".
Name string `json:"name" yaml:"name" mapstructure:"name"`
// Version corresponds to the JSON schema field "version".
Version string `json:"version" yaml:"version" mapstructure:"version"`
}
// UnmarshalJSON implements json.Unmarshaler.
func (j *implementation) UnmarshalJSON(b []byte) error {
var raw map[string]interface{}
if err := json.Unmarshal(b, &raw); err != nil {
return err
}
if _, ok := raw["name"]; raw != nil && !ok {
return fmt.Errorf("field name in implementation: required")
}
if _, ok := raw["version"]; raw != nil && !ok {
return fmt.Errorf("field version in implementation: required")
}
type Plain implementation
var plain Plain
if err := json.Unmarshal(b, &plain); err != nil {
return err
}
*j = implementation(plain)
return nil
}
type baseCallToolRequestParams struct {
// Arguments corresponds to the JSON schema field "arguments".
// It is stored as a []byte to enable efficient marshaling and unmarshaling into custom types later on in the protocol
Arguments json.RawMessage `json:"arguments" yaml:"arguments" mapstructure:"arguments"`
// Name corresponds to the JSON schema field "name".
Name string `json:"name" yaml:"name" mapstructure:"name"`
}
// Definition for a tool the client can call.
type ToolRetType struct {
// A human-readable description of the tool.
Description *string `json:"description,omitempty" yaml:"description,omitempty" mapstructure:"description,omitempty"`
// A JSON Schema object defining the expected parameters for the tool.
InputSchema interface{} `json:"inputSchema" yaml:"inputSchema" mapstructure:"inputSchema"`
// The name of the tool.
Name string `json:"name" yaml:"name" mapstructure:"name"`
}
type ToolsResponse struct {
Tools []ToolRetType `json:"tools" yaml:"tools" mapstructure:"tools"`
NextCursor *string `json:"nextCursor,omitempty" yaml:"nextCursor,omitempty" mapstructure:"nextCursor,omitempty"`
}