Skip to content

Commit 9c88768

Browse files
tae2089claude
andcommitted
fix: validate empty query in searchDocs, normalize nil to [], add mtime to rag cache keys
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
1 parent 0403dcf commit 9c88768

1 file changed

Lines changed: 21 additions & 3 deletions

File tree

internal/mcp/handlers.go

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1385,7 +1385,13 @@ func (h *handlers) getRagTree(ctx context.Context, request mcp.CallToolRequest)
13851385
communityID := request.GetString("community_id", "")
13861386
depth := int(request.GetFloat("depth", 0))
13871387

1388-
key := "get_rag_tree:" + mustJSON(map[string]any{"community_id": communityID, "depth": depth})
1388+
// doc-index.json mtime을 캐시 키에 포함
1389+
var indexMtime int64
1390+
if stat, statErr := os.Stat(h.ragIndexPath()); statErr == nil {
1391+
indexMtime = stat.ModTime().UnixNano()
1392+
}
1393+
1394+
key := "get_rag_tree:" + mustJSON(map[string]any{"community_id": communityID, "depth": depth, "mtime": indexMtime})
13891395
if h.cache != nil {
13901396
if cached, ok := h.cache.Get(key); ok {
13911397
return mcp.NewToolResultText(cached), nil
@@ -1468,12 +1474,21 @@ func (h *handlers) searchDocs(ctx context.Context, request mcp.CallToolRequest)
14681474
if err != nil {
14691475
return mcp.NewToolResultError(fmt.Sprintf("missing parameter: %v", err)), nil
14701476
}
1471-
limit := request.GetInt("limit", 10)
1477+
if strings.TrimSpace(query) == "" {
1478+
return mcp.NewToolResultError("query must not be empty"), nil
1479+
}
1480+
limit := int(request.GetFloat("limit", 10))
14721481
if limit <= 0 {
14731482
limit = 10
14741483
}
14751484

1476-
key := "search_docs:" + mustJSON(map[string]any{"query": query, "limit": limit})
1485+
// doc-index.json mtime을 캐시 키에 포함
1486+
var indexMtime int64
1487+
if stat, statErr := os.Stat(h.ragIndexPath()); statErr == nil {
1488+
indexMtime = stat.ModTime().UnixNano()
1489+
}
1490+
1491+
key := "search_docs:" + mustJSON(map[string]any{"query": query, "limit": limit, "mtime": indexMtime})
14771492
if h.cache != nil {
14781493
if cached, ok := h.cache.Get(key); ok {
14791494
return mcp.NewToolResultText(cached), nil
@@ -1486,6 +1501,9 @@ func (h *handlers) searchDocs(ctx context.Context, request mcp.CallToolRequest)
14861501
}
14871502

14881503
results := ragindex.Search(idx.Root, query, limit)
1504+
if results == nil {
1505+
results = []ragindex.SearchResult{}
1506+
}
14891507

14901508
b, err := json.Marshal(results)
14911509
if err != nil {

0 commit comments

Comments
 (0)