Skip to content

Commit 505a7b0

Browse files
committed
simplify types fold: Schema into SchemaObject
1 parent 58bbc3c commit 505a7b0

File tree

2 files changed

+27
-34
lines changed

2 files changed

+27
-34
lines changed

internal/mcp/mcp_parse.go

Lines changed: 23 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
//go:generate ../../scripts/gen-mcp-tool-json.sh mcp_tools.json
21
package mcp
32

43
import (
@@ -13,10 +12,10 @@ import (
1312
var _ []byte
1413

1514
type ToolDef struct {
16-
Name string `json:"name"`
17-
Description string `json:"description"`
18-
InputSchema Schema `json:"inputSchema"`
19-
OutputSchema Schema `json:"outputSchema"`
15+
Name string `json:"name"`
16+
Description string `json:"description"`
17+
InputSchema SchemaObject `json:"inputSchema"`
18+
OutputSchema SchemaObject `json:"outputSchema"`
2019
}
2120

2221
type RawSchema struct {
@@ -29,39 +28,35 @@ type RawSchema struct {
2928
Items json.RawMessage `json:"items"`
3029
}
3130

32-
type Schema struct {
33-
Schema string `json:"$schema"`
34-
SchemaObject
35-
}
36-
3731
type SchemaValue interface {
38-
Type() string
32+
ValueType() string
3933
}
4034

4135
type SchemaObject struct {
42-
Kind string `json:"type"`
36+
Type string `json:"type"`
4337
Description string `json:"description"`
38+
Schema string `json:"$schema,omitempty"`
4439
Required []string `json:"required,omitempty"`
4540
AdditionalProperties bool `json:"additionalProperties"`
4641
Properties map[string]SchemaValue `json:"properties"`
4742
}
4843

49-
func (s SchemaObject) Type() string { return s.Kind }
44+
func (s SchemaObject) ValueType() string { return s.Type }
5045

5146
type SchemaArray struct {
52-
Kind string `json:"type"`
47+
Type string `json:"type"`
5348
Description string `json:"description"`
5449
Items SchemaValue `json:"items,omitempty"`
5550
}
5651

57-
func (s SchemaArray) Type() string { return s.Kind }
52+
func (s SchemaArray) ValueType() string { return s.Type }
5853

5954
type SchemaPrimitive struct {
55+
Type string `json:"type"`
6056
Description string `json:"description"`
61-
Kind string `json:"type"`
6257
}
6358

64-
func (s SchemaPrimitive) Type() string { return s.Kind }
59+
func (s SchemaPrimitive) ValueType() string { return s.Type }
6560

6661
type decoder struct {
6762
errors []error
@@ -100,24 +95,22 @@ func LoadToolDefinitions(data []byte) (map[string]*ToolDef, error) {
10095
return tools, nil
10196
}
10297

103-
func (d *decoder) decodeRootSchema(r RawSchema) Schema {
104-
return Schema{
105-
Schema: r.SchemaVersion,
106-
SchemaObject: SchemaObject{
107-
Kind: r.Type,
108-
Description: r.Description,
109-
Required: r.Required,
110-
AdditionalProperties: r.AdditionalProperties,
111-
Properties: d.decodeProperties(r.Properties),
112-
},
98+
func (d *decoder) decodeRootSchema(r RawSchema) SchemaObject {
99+
return SchemaObject{
100+
Schema: r.SchemaVersion,
101+
Type: r.Type,
102+
Description: r.Description,
103+
Required: r.Required,
104+
AdditionalProperties: r.AdditionalProperties,
105+
Properties: d.decodeProperties(r.Properties),
113106
}
114107
}
115108

116109
func (d *decoder) decodeSchema(r *RawSchema) SchemaValue {
117110
switch r.Type {
118111
case "object":
119112
return &SchemaObject{
120-
Kind: r.Type,
113+
Type: r.Type,
121114
Description: r.Description,
122115
Required: r.Required,
123116
AdditionalProperties: r.AdditionalProperties,
@@ -140,13 +133,13 @@ func (d *decoder) decodeSchema(r *RawSchema) SchemaValue {
140133
}
141134
}
142135
return &SchemaArray{
143-
Kind: r.Type,
136+
Type: r.Type,
144137
Description: r.Description,
145138
Items: items,
146139
}
147140
default:
148141
return &SchemaPrimitive{
149-
Kind: r.Type,
142+
Type: r.Type,
150143
Description: r.Description,
151144
}
152145
}

internal/mcp/mcp_parse_test.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -71,8 +71,8 @@ func TestLoadToolDefinitions(t *testing.T) {
7171
t.Fatal("Property 'tags' not found in inputSchema")
7272
}
7373

74-
if tagsProp.Type() != "array" {
75-
t.Errorf("Expected tags type 'array', got '%s'", tagsProp.Type())
74+
if tagsProp.ValueType() != "array" {
75+
t.Errorf("Expected tags type 'array', got '%s'", tagsProp.ValueType())
7676
}
7777

7878
arraySchema, ok := tagsProp.(*SchemaArray)
@@ -85,8 +85,8 @@ func TestLoadToolDefinitions(t *testing.T) {
8585
}
8686

8787
itemSchema := arraySchema.Items
88-
if itemSchema.Type() != "object" {
89-
t.Errorf("Expected item type 'object', got '%s'", itemSchema.Type())
88+
if itemSchema.ValueType() != "object" {
89+
t.Errorf("Expected item type 'object', got '%s'", itemSchema.ValueType())
9090
}
9191

9292
objectSchema, ok := itemSchema.(*SchemaObject)

0 commit comments

Comments
 (0)