Skip to content

Commit 36ee381

Browse files
committed
review comments
1 parent 505a7b0 commit 36ee381

File tree

2 files changed

+30
-38
lines changed

2 files changed

+30
-38
lines changed

internal/mcp/mcp_parse.go

Lines changed: 28 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -18,27 +18,27 @@ type ToolDef struct {
1818
OutputSchema SchemaObject `json:"outputSchema"`
1919
}
2020

21-
type RawSchema struct {
22-
Type string `json:"type"`
23-
Description string `json:"description"`
24-
SchemaVersion string `json:"$schema"`
25-
Required []string `json:"required,omitempty"`
26-
AdditionalProperties bool `json:"additionalProperties"`
27-
Properties map[string]json.RawMessage `json:"properties"`
28-
Items json.RawMessage `json:"items"`
21+
type rawSchema struct {
22+
Type string `json:"type"`
23+
Description string `json:"description"`
24+
Required []string `json:"required,omitempty"`
25+
Properties map[string]json.RawMessage `json:"properties"`
26+
Items json.RawMessage `json:"items"`
2927
}
3028

3129
type SchemaValue interface {
3230
ValueType() string
3331
}
3432

3533
type SchemaObject struct {
36-
Type string `json:"type"`
37-
Description string `json:"description"`
38-
Schema string `json:"$schema,omitempty"`
39-
Required []string `json:"required,omitempty"`
40-
AdditionalProperties bool `json:"additionalProperties"`
41-
Properties map[string]SchemaValue `json:"properties"`
34+
Type string `json:"type"`
35+
Description string `json:"description"`
36+
Required []string `json:"required,omitempty"`
37+
Properties map[string]SchemaValue `json:"properties"`
38+
39+
// two fields which we do not use from the schema:
40+
// - $schema
41+
// - additionalPropterties
4242
}
4343

4444
func (s SchemaObject) ValueType() string { return s.Type }
@@ -67,8 +67,8 @@ func LoadToolDefinitions(data []byte) (map[string]*ToolDef, error) {
6767
Tools []struct {
6868
Name string `json:"name"`
6969
Description string `json:"description"`
70-
InputSchema RawSchema `json:"inputSchema"`
71-
OutputSchema RawSchema `json:"outputSchema"`
70+
InputSchema rawSchema `json:"inputSchema"`
71+
OutputSchema rawSchema `json:"outputSchema"`
7272
} `json:"tools"`
7373
}{}
7474

@@ -95,26 +95,23 @@ func LoadToolDefinitions(data []byte) (map[string]*ToolDef, error) {
9595
return tools, nil
9696
}
9797

98-
func (d *decoder) decodeRootSchema(r RawSchema) SchemaObject {
98+
func (d *decoder) decodeRootSchema(r rawSchema) SchemaObject {
9999
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),
100+
Type: r.Type,
101+
Description: r.Description,
102+
Required: r.Required,
103+
Properties: d.decodeProperties(r.Properties),
106104
}
107105
}
108106

109-
func (d *decoder) decodeSchema(r *RawSchema) SchemaValue {
107+
func (d *decoder) decodeSchema(r *rawSchema) SchemaValue {
110108
switch r.Type {
111109
case "object":
112110
return &SchemaObject{
113-
Type: r.Type,
114-
Description: r.Description,
115-
Required: r.Required,
116-
AdditionalProperties: r.AdditionalProperties,
117-
Properties: d.decodeProperties(r.Properties),
111+
Type: r.Type,
112+
Description: r.Description,
113+
Required: r.Required,
114+
Properties: d.decodeProperties(r.Properties),
118115
}
119116
case "array":
120117
var items SchemaValue
@@ -124,7 +121,7 @@ func (d *decoder) decodeSchema(r *RawSchema) SchemaValue {
124121
// Sometimes items is defined as "items: true", so we handle it here and
125122
// consider it "empty" array
126123
} else {
127-
var itemRaw RawSchema
124+
var itemRaw rawSchema
128125
if err := json.Unmarshal(r.Items, &itemRaw); err == nil {
129126
items = d.decodeSchema(&itemRaw)
130127
} else {
@@ -148,7 +145,7 @@ func (d *decoder) decodeSchema(r *RawSchema) SchemaValue {
148145
func (d *decoder) decodeProperties(props map[string]json.RawMessage) map[string]SchemaValue {
149146
res := make(map[string]SchemaValue)
150147
for name, raw := range props {
151-
var r RawSchema
148+
var r rawSchema
152149
if err := json.Unmarshal(raw, &r); err != nil {
153150
d.errors = append(d.errors, fmt.Errorf("failed to parse property %q: %w", name, err))
154151
continue

internal/mcp/mcp_parse_test.go

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -56,14 +56,9 @@ func TestLoadToolDefinitions(t *testing.T) {
5656
}
5757

5858
inputSchema := tool.InputSchema
59-
outputSchema := tool.OutputSchema
60-
schemaVersion := "https://localhost/schema-draft/2025-07"
6159

62-
if inputSchema.Schema != schemaVersion {
63-
t.Errorf("Expected input schema version %q, got %q", schemaVersion, inputSchema.Schema)
64-
}
65-
if outputSchema.Schema != schemaVersion {
66-
t.Errorf("Expected output schema version %q, got %q", schemaVersion, outputSchema.Schema)
60+
if len(tool.OutputSchema.Properties) == 0 {
61+
t.Fatalf("expected tool.OutputSchema.Properties not be empty")
6762
}
6863

6964
tagsProp, ok := inputSchema.Properties["tags"]

0 commit comments

Comments
 (0)