chore: auto-commit (4 archivos)
- integration_test.go - main.go - tool_search.go - tool_proposal.go Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
+32
-2
@@ -3,6 +3,7 @@ package main
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"strings"
|
||||
|
||||
"github.com/mark3labs/mcp-go/mcp"
|
||||
|
||||
@@ -15,6 +16,8 @@ type searchArgs struct {
|
||||
Lang string `json:"lang,omitempty"`
|
||||
Domain string `json:"domain,omitempty"`
|
||||
Purity string `json:"purity,omitempty"`
|
||||
Tag string `json:"tag,omitempty"`
|
||||
Tags string `json:"tags,omitempty"`
|
||||
Limit int `json:"limit,omitempty"`
|
||||
}
|
||||
|
||||
@@ -52,6 +55,12 @@ func searchTool() mcp.Tool {
|
||||
mcp.Description("Filter by purity (functions only)."),
|
||||
mcp.Enum("pure", "impure"),
|
||||
),
|
||||
mcp.WithString("tag",
|
||||
mcp.Description("Filter by single tag (exact match against tags JSON array). Ej: 'notebook', 'metabase'."),
|
||||
),
|
||||
mcp.WithString("tags",
|
||||
mcp.Description("Filter by multiple tags (CSV). AND across tags: all must be present. Ej: 'metabase,client'."),
|
||||
),
|
||||
mcp.WithNumber("limit",
|
||||
mcp.Description("Max hits returned (default 50)."),
|
||||
mcp.Min(1),
|
||||
@@ -68,7 +77,9 @@ func (d *deps) handleSearch(ctx context.Context, _ mcp.CallToolRequest, args sea
|
||||
|
||||
q := sanitizeFTS5(args.Query)
|
||||
|
||||
fns, err := d.db.SearchFunctions(q, registry.Kind(args.Kind), registry.Purity(args.Purity), args.Lang, args.Domain)
|
||||
tagFilters := parseTagFilters(args.Tag, args.Tags)
|
||||
|
||||
fns, err := d.db.SearchFunctions(q, registry.Kind(args.Kind), registry.Purity(args.Purity), args.Lang, args.Domain, tagFilters...)
|
||||
if err != nil {
|
||||
return mcp.NewToolResultError("search functions: " + err.Error()), nil
|
||||
}
|
||||
@@ -93,7 +104,7 @@ func (d *deps) handleSearch(ctx context.Context, _ mcp.CallToolRequest, args sea
|
||||
|
||||
// Types: only when no kind filter (kind applies only to functions).
|
||||
if args.Kind == "" && len(hits) < limit {
|
||||
ts, err := d.db.SearchTypes(q, args.Lang, args.Domain)
|
||||
ts, err := d.db.SearchTypes(q, args.Lang, args.Domain, tagFilters...)
|
||||
if err != nil {
|
||||
return mcp.NewToolResultError("search types: " + err.Error()), nil
|
||||
}
|
||||
@@ -122,3 +133,22 @@ func (d *deps) handleSearch(ctx context.Context, _ mcp.CallToolRequest, args sea
|
||||
b, _ := json.MarshalIndent(out, "", " ")
|
||||
return mcp.NewToolResultText(string(b)), nil
|
||||
}
|
||||
|
||||
// parseTagFilters merges single `tag` and CSV `tags` into a deduplicated slice.
|
||||
func parseTagFilters(tag, csv string) []string {
|
||||
seen := map[string]bool{}
|
||||
var out []string
|
||||
add := func(s string) {
|
||||
s = strings.TrimSpace(s)
|
||||
if s == "" || seen[s] {
|
||||
return
|
||||
}
|
||||
seen[s] = true
|
||||
out = append(out, s)
|
||||
}
|
||||
add(tag)
|
||||
for _, t := range strings.Split(csv, ",") {
|
||||
add(t)
|
||||
}
|
||||
return out
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user