-
Notifications
You must be signed in to change notification settings - Fork 651
Expand file tree
/
Copy pathsearch.go
More file actions
91 lines (76 loc) · 2.27 KB
/
Copy pathsearch.go
File metadata and controls
91 lines (76 loc) · 2.27 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
package handlers
import (
"context"
"fmt"
zep "github.com/getzep/zep-go/v3"
"github.com/modelcontextprotocol/go-sdk/mcp"
"github.com/getzep/zep/mcp/zep-mcp-server/internal/transform"
zepclient "github.com/getzep/zep/mcp/zep-mcp-server/pkg/zep"
)
// HandleSearchGraph handles the search_graph tool using the new MCP SDK signature
func HandleSearchGraph(client *zepclient.Client) mcp.ToolHandlerFor[SearchGraphInput, any] {
return func(ctx context.Context, req *mcp.CallToolRequest, input SearchGraphInput) (*mcp.CallToolResult, any, error) {
if err := input.Validate(); err != nil {
return nil, nil, err
}
// Apply defaults (after validation so explicit out-of-range limits are rejected)
if input.Scope == "" {
input.Scope = "edges"
}
if input.Limit == 0 {
input.Limit = 10
}
// Build search request
searchReq := &zep.GraphSearchQuery{
UserID: &input.UserID,
Query: input.Query,
Limit: &input.Limit,
}
// Set scope as GraphSearchScope type
searchScope, err := zep.NewGraphSearchScopeFromString(input.Scope)
if err != nil {
return nil, nil, fmt.Errorf("invalid search scope: %w", err)
}
searchReq.Scope = &searchScope
if input.Reranker != "" {
rerankerType := zep.Reranker(input.Reranker)
searchReq.Reranker = &rerankerType
}
if input.MinFactRating > 0.0 {
searchReq.MinFactRating = &input.MinFactRating
}
if input.MmrLambda > 0.0 {
searchReq.MmrLambda = &input.MmrLambda
}
if input.CenterNodeUUID != "" {
searchReq.CenterNodeUUID = &input.CenterNodeUUID
}
if len(input.NodeLabels) > 0 || len(input.EdgeTypes) > 0 {
filters := &zep.SearchFilters{}
if len(input.NodeLabels) > 0 {
filters.NodeLabels = input.NodeLabels
}
if len(input.EdgeTypes) > 0 {
filters.EdgeTypes = input.EdgeTypes
}
searchReq.SearchFilters = filters
}
// Execute search
results, err := client.Graph.Search(ctx, searchReq)
if err != nil {
return nil, nil, fmt.Errorf("graph search failed: %w", err)
}
// Format results as JSON
resultJSON, err := transform.FormatJSON(results)
if err != nil {
return nil, nil, fmt.Errorf("failed to format results: %w", err)
}
return &mcp.CallToolResult{
Content: []mcp.Content{
&mcp.TextContent{
Text: resultJSON,
},
},
}, results, nil
}
}