Skip to content
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 16 additions & 2 deletions pkg/search/query/runquery.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package query

import (
"context"
"encoding/json"
"fmt"
"log"
"strings"
Expand All @@ -12,7 +13,6 @@ import (

"github.com/algolia/algoliasearch-client-go/v3/algolia/opt"
"github.com/algolia/algoliasearch-client-go/v3/algolia/search"
"github.com/algolia/mcp/pkg/mcputil"
)

func RegisterRunQuery(mcps *server.MCPServer, client *search.Client, index *search.Index) {
Expand Down Expand Up @@ -97,6 +97,20 @@ func RegisterRunQuery(mcps *server.MCPServer, client *search.Client, index *sear
}
log.Printf("Search for %q took %v", query, time.Since(start))

return mcputil.JSONToolResult("query results", resp)
// Marshal only the Hits field from the response
hitsJSONData, err := json.Marshal(resp.Hits) // Assume resp has a 'Hits' field
if err != nil {
return nil, fmt.Errorf("could not marshal search hits to JSON: %w", err)
}

// Construct the result with the hits-only JSON string
return &mcp.CallToolResult{
Content: []mcp.Content{
&mcp.TextContent{
Type: "text",
Text: string(hitsJSONData), // Use the hits-only JSON
},
},
}, nil
})
}