feat: enrich search with msglib display entities

This commit is contained in:
zhaoyilun
2026-07-10 03:09:37 +08:00
parent 8be4a6a6c5
commit 1277316663
11 changed files with 400 additions and 30 deletions

View File

@@ -7,6 +7,7 @@ import (
"github.com/modelcontextprotocol/go-sdk/mcp"
"isphere-ai-bridge/internal/isphere"
"isphere-ai-bridge/internal/msglib"
)
const ToolNameSearchGroups = "isphere_search_groups"
@@ -20,6 +21,10 @@ type SearchGroupsArgs struct {
}
func RegisterISphereGroupTools(server *mcp.Server, source ReceiveMessagesSource) {
RegisterISphereGroupToolsWithDisplayEntities(server, source, nil)
}
func RegisterISphereGroupToolsWithDisplayEntities(server *mcp.Server, source ReceiveMessagesSource, displaySource DisplayEntitySource) {
if source == nil {
source = isphere.EncryptedPacketLogSource{}
}
@@ -36,7 +41,19 @@ func RegisterISphereGroupTools(server *mcp.Server, source ReceiveMessagesSource)
if err != nil {
return nil, nil, err
}
groups := isphere.SearchGroupsFromMessages(messages.Messages, isphere.SearchGroupsQuery{Query: input.Query, Limit: input.Limit})
logGroups := isphere.SearchGroupsFromMessages(messages.Messages, isphere.SearchGroupsQuery{Query: input.Query, Limit: input.Limit})
groups := logGroups
if displaySource != nil {
entities, err := displaySource.DisplayEntities(ctx, msglib.DisplayEntitiesOptions{
EntityType: msglib.EntityTypeGroups,
Query: input.Query,
Limit: displayEntityQueryLimit(input.Limit),
})
if err != nil {
return nil, nil, err
}
groups = mergeGroups(groupsFromDisplayEntities(entities), logGroups.Groups, input.Limit)
}
return nil, searchGroupsResultToMap(groups, started, time.Now().UTC()), nil
})
}