internal/mcp: unify json tag parsing
Do a thorough job of parsing json struct tags. Move the code to a place where both mcp and jsonschema can use it. Change-Id: I6c86308834706b12a1e22cd96ae120590f49d3f4 Reviewed-on: https://go-review.googlesource.com/c/tools/+/678757 LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Robert Findley <rfindley@google.com>
This commit is contained in:
parent
b1eb3c8804
commit
12761ffcb6
1 changed files with 101 additions and 97 deletions
|
|
@ -17,6 +17,8 @@ import (
|
|||
"reflect"
|
||||
"regexp"
|
||||
"slices"
|
||||
|
||||
"github.com/modelcontextprotocol/go-sdk/internal/util"
|
||||
)
|
||||
|
||||
// A Schema is a JSON schema object.
|
||||
|
|
@ -426,8 +428,9 @@ var (
|
|||
|
||||
func init() {
|
||||
for _, sf := range reflect.VisibleFields(reflect.TypeFor[Schema]()) {
|
||||
if name, ok := jsonName(sf); ok {
|
||||
schemaFieldInfos = append(schemaFieldInfos, structFieldInfo{sf, name})
|
||||
info := util.FieldJSONInfo(sf)
|
||||
if !info.Omit {
|
||||
schemaFieldInfos = append(schemaFieldInfos, structFieldInfo{sf, info.Name})
|
||||
}
|
||||
}
|
||||
slices.SortFunc(schemaFieldInfos, func(i1, i2 structFieldInfo) int {
|
||||
|
|
|
|||
Loading…
Reference in a new issue