@@ -13,13 +13,11 @@ package main
13
13
14
14
import (
15
15
"bytes"
16
- "cmp"
17
16
"encoding/json"
18
17
"flag"
19
18
"fmt"
20
19
"go/format"
21
20
"io"
22
- "iter"
23
21
"log"
24
22
"net/http"
25
23
"os"
@@ -28,6 +26,7 @@ import (
28
26
"strings"
29
27
30
28
"golang.org/x/tools/internal/mcp/internal/jsonschema"
29
+ "golang.org/x/tools/internal/mcp/internal/util"
31
30
)
32
31
33
32
var schemaFile = flag .String ("schema_file" , "" , "if set, use this file as the persistent schema file" )
@@ -54,31 +53,36 @@ var declarations = config{
54
53
"CallToolRequest" : {
55
54
Fields : config {"Params" : {Name : "CallToolParams" }},
56
55
},
57
- "CallToolResult" : {
58
- Name : "CallToolResult" ,
59
- },
56
+ "CallToolResult" : {Name : "CallToolResult" },
60
57
"CancelledNotification" : {
61
58
Fields : config {"Params" : {Name : "CancelledParams" }},
62
59
},
63
60
"ClientCapabilities" : {Name : "ClientCapabilities" },
64
- "Implementation" : {Name : "Implementation" },
61
+ "GetPromptRequest" : {
62
+ Fields : config {"Params" : {Name : "GetPromptParams" }},
63
+ },
64
+ "GetPromptResult" : {Name : "GetPromptResult" },
65
+ "Implementation" : {Name : "Implementation" },
65
66
"InitializeRequest" : {
66
67
Fields : config {"Params" : {Name : "InitializeParams" }},
67
68
},
68
- "InitializeResult" : {
69
- Name : "InitializeResult" ,
70
- },
69
+ "InitializeResult" : {Name : "InitializeResult" },
71
70
"InitializedNotification" : {
72
71
Fields : config {"Params" : {Name : "InitializedParams" }},
73
72
},
73
+ "ListPromptsRequest" : {
74
+ Fields : config {"Params" : {Name : "ListPromptsParams" }},
75
+ },
76
+ "ListPromptsResult" : {Name : "ListPromptsResult" },
74
77
"ListToolsRequest" : {
75
78
Fields : config {"Params" : {Name : "ListToolsParams" }},
76
79
},
77
- "ListToolsResult" : {
78
- Name : "ListToolsResult" ,
79
- },
80
- "RequestId" : {Substitute : "any" }, // null|number|string
81
- "Role" : {Name : "Role" },
80
+ "ListToolsResult" : {Name : "ListToolsResult" },
81
+ "Prompt" : {Name : "Prompt" },
82
+ "PromptMessage" : {Name : "PromptMessage" },
83
+ "PromptArgument" : {Name : "PromptArgument" },
84
+ "RequestId" : {Substitute : "any" }, // null|number|string
85
+ "Role" : {Name : "Role" },
82
86
"ServerCapabilities" : {
83
87
Name : "ServerCapabilities" ,
84
88
Fields : config {
@@ -92,9 +96,7 @@ var declarations = config{
92
96
Name : "Tool" ,
93
97
Fields : config {"InputSchema" : {Substitute : "*jsonschema.Schema" }},
94
98
},
95
- "ToolAnnotations" : {
96
- Name : "ToolAnnotations" ,
97
- },
99
+ "ToolAnnotations" : {Name : "ToolAnnotations" },
98
100
}
99
101
100
102
func main () {
@@ -114,7 +116,7 @@ func main() {
114
116
// writing types, we collect definitions and concatenate them later. This
115
117
// also allows us to sort.
116
118
named := make (map [string ]* bytes.Buffer )
117
- for name , def := range sorted (schema .Definitions ) {
119
+ for name , def := range util . Sorted (schema .Definitions ) {
118
120
config := declarations [name ]
119
121
if config == nil {
120
122
continue
@@ -142,7 +144,7 @@ import (
142
144
` )
143
145
144
146
// Write out types.
145
- for _ , b := range sorted (named ) {
147
+ for _ , b := range util . Sorted (named ) {
146
148
fmt .Fprintln (buf )
147
149
fmt .Fprint (buf , b .String ())
148
150
}
@@ -242,8 +244,8 @@ func writeType(w io.Writer, config *typeConfig, def *jsonschema.Schema, named ma
242
244
// unmarshal them into a map[string]any, or delay unmarshalling with
243
245
// json.RawMessage. For now, use json.RawMessage as it defers the choice.
244
246
if def .Type == "object" && canHaveAdditionalProperties (def ) {
245
- w .Write ([]byte ("json.RawMessage " ))
246
- return nil
247
+ w .Write ([]byte ("map[string] " ))
248
+ return writeType ( w , nil , def . AdditionalProperties , named )
247
249
}
248
250
249
251
if def .Type == "" {
@@ -269,7 +271,7 @@ func writeType(w io.Writer, config *typeConfig, def *jsonschema.Schema, named ma
269
271
270
272
case "object" :
271
273
fmt .Fprintf (w , "struct {\n " )
272
- for name , fieldDef := range sorted (def .Properties ) {
274
+ for name , fieldDef := range util . Sorted (def .Properties ) {
273
275
if fieldDef .Description != "" {
274
276
fmt .Fprintf (w , "%s\n " , toComment (fieldDef .Description ))
275
277
}
@@ -385,28 +387,3 @@ func assert(cond bool, msg string) {
385
387
panic (msg )
386
388
}
387
389
}
388
-
389
- // Helpers below are copied from gopls' moremaps package.
390
-
391
- // sorted returns an iterator over the entries of m in key order.
392
- func sorted [M ~ map [K ]V , K cmp.Ordered , V any ](m M ) iter.Seq2 [K , V ] {
393
- // TODO(adonovan): use maps.Sorted if proposal #68598 is accepted.
394
- return func (yield func (K , V ) bool ) {
395
- keys := keySlice (m )
396
- slices .Sort (keys )
397
- for _ , k := range keys {
398
- if ! yield (k , m [k ]) {
399
- break
400
- }
401
- }
402
- }
403
- }
404
-
405
- // keySlice returns the keys of the map M, like slices.Collect(maps.Keys(m)).
406
- func keySlice [M ~ map [K ]V , K comparable , V any ](m M ) []K {
407
- r := make ([]K , 0 , len (m ))
408
- for k := range m {
409
- r = append (r , k )
410
- }
411
- return r
412
- }
0 commit comments