Skip to content

Commit 4c6a6bd

Browse files
committed
unexport and remove unused structs
1 parent 1846596 commit 4c6a6bd

File tree

2 files changed

+40
-51
lines changed

2 files changed

+40
-51
lines changed

internal/mcp/mcp_parse.go

Lines changed: 37 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,6 @@ type MCPToolDef struct {
1919
OutputSchema Schema `json:"outputSchema"`
2020
}
2121

22-
type InputProperty struct {
23-
Name string
24-
Type string
25-
Description string
26-
ItemType string
27-
}
28-
2922
type Schema struct {
3023
Schema string `json:"$schema"`
3124
SchemaObject
@@ -70,15 +63,45 @@ type SchemaPrimitive struct {
7063

7164
func (s SchemaPrimitive) Type() string { return s.Kind }
7265

73-
type PropertyType struct {
74-
Type string `json:"type"`
66+
type parser struct {
67+
errors []error
7568
}
7669

77-
type Parser struct {
78-
errors []error
70+
func LoadToolDefinitions(data []byte) (map[string]*MCPToolDef, error) {
71+
defs := struct {
72+
Tools []struct {
73+
Name string `json:"name"`
74+
Description string `json:"description"`
75+
InputSchema RawSchema `json:"inputSchema"`
76+
OutputSchema RawSchema `json:"outputSchema"`
77+
} `json:"tools"`
78+
}{}
79+
80+
if err := json.Unmarshal(data, &defs); err != nil {
81+
// TODO: think we should panic instead
82+
return nil, err
83+
}
84+
85+
tools := map[string]*MCPToolDef{}
86+
parser := &parser{}
87+
88+
for _, t := range defs.Tools {
89+
tools[t.Name] = &MCPToolDef{
90+
Name: t.Name,
91+
Description: t.Description,
92+
InputSchema: parser.parseRootSchema(t.InputSchema),
93+
OutputSchema: parser.parseRootSchema(t.OutputSchema),
94+
}
95+
}
96+
97+
if len(parser.errors) > 0 {
98+
return tools, errors.Append(nil, parser.errors...)
99+
}
100+
101+
return tools, nil
79102
}
80103

81-
func (p *Parser) parseRootSchema(r RawSchema) Schema {
104+
func (p *parser) parseRootSchema(r RawSchema) Schema {
82105
return Schema{
83106
Schema: r.Schema,
84107
SchemaObject: SchemaObject{
@@ -91,7 +114,7 @@ func (p *Parser) parseRootSchema(r RawSchema) Schema {
91114
}
92115
}
93116

94-
func (p *Parser) parseSchema(r *RawSchema) SchemaValue {
117+
func (p *parser) parseSchema(r *RawSchema) SchemaValue {
95118
switch r.Type {
96119
case "object":
97120
return &SchemaObject{
@@ -130,7 +153,7 @@ func (p *Parser) parseSchema(r *RawSchema) SchemaValue {
130153
}
131154
}
132155

133-
func (p *Parser) parseProperties(props map[string]json.RawMessage) map[string]SchemaValue {
156+
func (p *parser) parseProperties(props map[string]json.RawMessage) map[string]SchemaValue {
134157
res := make(map[string]SchemaValue)
135158
for name, raw := range props {
136159
var r RawSchema
@@ -142,37 +165,3 @@ func (p *Parser) parseProperties(props map[string]json.RawMessage) map[string]Sc
142165
}
143166
return res
144167
}
145-
146-
func LoadMCPToolDefinitions(data []byte) (map[string]*MCPToolDef, error) {
147-
defs := struct {
148-
Tools []struct {
149-
Name string `json:"name"`
150-
Description string `json:"description"`
151-
InputSchema RawSchema `json:"inputSchema"`
152-
OutputSchema RawSchema `json:"outputSchema"`
153-
} `json:"tools"`
154-
}{}
155-
156-
if err := json.Unmarshal(data, &defs); err != nil {
157-
// TODO: think we should panic instead
158-
return nil, err
159-
}
160-
161-
tools := map[string]*MCPToolDef{}
162-
parser := &Parser{}
163-
164-
for _, t := range defs.Tools {
165-
tools[t.Name] = &MCPToolDef{
166-
Name: t.Name,
167-
Description: t.Description,
168-
InputSchema: parser.parseRootSchema(t.InputSchema),
169-
OutputSchema: parser.parseRootSchema(t.OutputSchema),
170-
}
171-
}
172-
173-
if len(parser.errors) > 0 {
174-
return tools, errors.Append(nil, parser.errors...)
175-
}
176-
177-
return tools, nil
178-
}

internal/mcp/mcp_parse_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
package main
1+
package mcp
22

33
import (
44
"testing"
55
)
66

7-
func TestLoadMCPToolDefinitions(t *testing.T) {
7+
func TestLoadToolDefinitions(t *testing.T) {
88
toolJSON := []byte(`{
99
"tools": [
1010
{
@@ -37,7 +37,7 @@ func TestLoadMCPToolDefinitions(t *testing.T) {
3737
]
3838
}`)
3939

40-
tools, err := LoadMCPToolDefinitions(toolJSON)
40+
tools, err := LoadToolDefinitions(toolJSON)
4141
if err != nil {
4242
t.Fatalf("Failed to load tool definitions: %v", err)
4343
}

0 commit comments

Comments
 (0)