feat: remove deprecated service and types, and refactor tool search request handling
This commit is contained in:
@@ -104,9 +104,9 @@ func (t *ToolSearchTool) InvokableRun(ctx context.Context, argumentsInJSON strin
|
||||
}
|
||||
|
||||
type toolSearchRequest struct {
|
||||
Query string
|
||||
ToolCode string
|
||||
Arguments map[string]any
|
||||
Query string `json:"query"`
|
||||
ToolCode string `json:"toolCode"`
|
||||
Arguments map[string]any `json:"arguments"`
|
||||
}
|
||||
|
||||
type toolSearchCandidate struct {
|
||||
@@ -122,22 +122,16 @@ func parseToolSearchRequest(argumentsInJSON string) (*toolSearchRequest, error)
|
||||
if argumentsInJSON == "" {
|
||||
return &toolSearchRequest{}, nil
|
||||
}
|
||||
raw := make(map[string]any)
|
||||
if err := json.Unmarshal([]byte(argumentsInJSON), &raw); err != nil {
|
||||
var req toolSearchRequest
|
||||
if err := json.Unmarshal([]byte(argumentsInJSON), &req); err != nil {
|
||||
return nil, fmt.Errorf("invalid tool_search arguments: %w", err)
|
||||
}
|
||||
req := &toolSearchRequest{
|
||||
Query: strings.TrimSpace(getStringValue(raw, "query")),
|
||||
ToolCode: strings.TrimSpace(getStringValue(raw, "toolCode")),
|
||||
req.Query = strings.TrimSpace(req.Query)
|
||||
req.ToolCode = strings.TrimSpace(req.ToolCode)
|
||||
if req.Arguments == nil {
|
||||
req.Arguments = map[string]any{}
|
||||
}
|
||||
if value, ok := raw["arguments"]; ok {
|
||||
args, ok := value.(map[string]any)
|
||||
if !ok {
|
||||
return nil, fmt.Errorf("tool_search arguments must be an object")
|
||||
}
|
||||
req.Arguments = args
|
||||
}
|
||||
return req, nil
|
||||
return &req, nil
|
||||
}
|
||||
|
||||
func (t *ToolSearchTool) searchCandidates(ctx context.Context, query string) (string, error) {
|
||||
|
||||
@@ -0,0 +1,32 @@
|
||||
package tools
|
||||
|
||||
import "testing"
|
||||
|
||||
func TestParseToolSearchRequest(t *testing.T) {
|
||||
req, err := parseToolSearchRequest(`{"query":" search docs ","toolCode":" mcp_server/search ","arguments":{"q":"hello"}}`)
|
||||
if err != nil {
|
||||
t.Fatalf("parseToolSearchRequest returned error: %v", err)
|
||||
}
|
||||
if req.Query != "search docs" {
|
||||
t.Fatalf("unexpected query: %q", req.Query)
|
||||
}
|
||||
if req.ToolCode != "mcp_server/search" {
|
||||
t.Fatalf("unexpected toolCode: %q", req.ToolCode)
|
||||
}
|
||||
if req.Arguments["q"] != "hello" {
|
||||
t.Fatalf("unexpected arguments: %#v", req.Arguments)
|
||||
}
|
||||
}
|
||||
|
||||
func TestParseToolSearchRequestDefaultsArguments(t *testing.T) {
|
||||
req, err := parseToolSearchRequest(`{"query":"list"}`)
|
||||
if err != nil {
|
||||
t.Fatalf("parseToolSearchRequest returned error: %v", err)
|
||||
}
|
||||
if req.Arguments == nil {
|
||||
t.Fatalf("expected non-nil arguments map")
|
||||
}
|
||||
if len(req.Arguments) != 0 {
|
||||
t.Fatalf("expected empty arguments map, got %#v", req.Arguments)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user