@@ -12,6 +12,7 @@ package mcp
1212
1313import (
1414 "encoding/json"
15+ "fmt"
1516
1617 "github.com/modelcontextprotocol/go-sdk/jsonschema"
1718)
@@ -163,6 +164,93 @@ type ClientCapabilities struct {
163164 Elicitation * ElicitationCapabilities `json:"elicitation,omitempty"`
164165}
165166
167+ type CompleteParamsArgument struct {
168+ // The name of the argument
169+ Name string `json:"name"`
170+ // The value of the argument to use for completion matching.
171+ Value string `json:"value"`
172+ }
173+
174+ // CompleteContext represents additional, optional context for completions.
175+ type CompleteContext struct {
176+ // Previously-resolved variables in a URI template or prompt.
177+ Arguments []string `json:"arguments,omitempty"`
178+ }
179+
180+ // CompleteReference represents a completion reference type (ref/prompt ref/resource).
181+ // The Type field determines which other fields are relevant.
182+ type CompleteReference struct {
183+ Type string `json:"type"`
184+ // Name is relevant when Type is "ref/prompt".
185+ Name string `json:"name,omitempty"`
186+ // URI is relevant when Type is "ref/resource".
187+ URI string `json:"uri,omitempty"`
188+ }
189+
190+ func (r * CompleteReference ) UnmarshalJSON (data []byte ) error {
191+ type wireCompleteReference CompleteReference // for naive unmarshaling
192+ var r2 wireCompleteReference
193+ if err := json .Unmarshal (data , & r2 ); err != nil {
194+ return err
195+ }
196+ switch r2 .Type {
197+ case "ref/prompt" , "ref/resource" :
198+ if r2 .Type == "ref/prompt" && r2 .URI != "" {
199+ return fmt .Errorf ("reference of type %q must not have a URI set" , r2 .Type )
200+ }
201+ if r2 .Type == "ref/resource" && r2 .Name != "" {
202+ return fmt .Errorf ("reference of type %q must not have a Name set" , r2 .Type )
203+ }
204+ default :
205+ return fmt .Errorf ("unrecognized content type %q" , r2 .Type )
206+ }
207+ * r = CompleteReference (r2 )
208+ return nil
209+ }
210+
211+ func (r * CompleteReference ) MarshalJSON () ([]byte , error ) {
212+ // Validation for marshalling: ensure consistency before converting to JSON.
213+ switch r .Type {
214+ case "ref/prompt" :
215+ if r .URI != "" {
216+ return nil , fmt .Errorf ("reference of type %q must not have a URI set for marshalling" , r .Type )
217+ }
218+ case "ref/resource" :
219+ if r .Name != "" {
220+ return nil , fmt .Errorf ("reference of type %q must not have a Name set for marshalling" , r .Type )
221+ }
222+ default :
223+ return nil , fmt .Errorf ("unrecognized reference type %q for marshalling" , r .Type )
224+ }
225+
226+ type wireReference CompleteReference
227+ return json .Marshal (wireReference (* r ))
228+ }
229+
230+ type CompleteParams struct {
231+ // This property is reserved by the protocol to allow clients and servers to
232+ // attach additional metadata to their responses.
233+ Meta `json:"_meta,omitempty"`
234+ // The argument's information
235+ Argument CompleteParamsArgument `json:"argument"`
236+ Context * CompleteContext `json:"context,omitempty"`
237+ Ref * CompleteReference `json:"ref"`
238+ }
239+
240+ type CompletionResultDetails struct {
241+ HasMore bool `json:"hasMore,omitempty"`
242+ Total int `json:"total,omitempty"`
243+ Values []string `json:"values"`
244+ }
245+
246+ // The server's response to a completion/complete request
247+ type CompleteResult struct {
248+ // This property is reserved by the protocol to allow clients and servers to
249+ // attach additional metadata to their responses.
250+ Meta `json:"_meta,omitempty"`
251+ Completion CompletionResultDetails `json:"completion"`
252+ }
253+
166254type CreateMessageParams struct {
167255 // This property is reserved by the protocol to allow clients and servers to
168256 // attach additional metadata to their responses.
@@ -817,6 +905,9 @@ type implementation struct {
817905 Version string `json:"version"`
818906}
819907
908+ // Present if the server supports argument autocompletion suggestions.
909+ type completionCapabilities struct {}
910+
820911// Present if the server supports sending log messages to the client.
821912type loggingCapabilities struct {}
822913
@@ -839,7 +930,7 @@ type resourceCapabilities struct {
839930// additional capabilities.
840931type serverCapabilities struct {
841932 // Present if the server supports argument autocompletion suggestions.
842- Completions struct {} `json:"completions,omitempty"`
933+ Completions * completionCapabilities `json:"completions,omitempty"`
843934 // Experimental, non-standard capabilities that the server supports.
844935 Experimental map [string ]struct {} `json:"experimental,omitempty"`
845936 // Present if the server supports sending log messages to the client.
0 commit comments