@@ -137,32 +137,6 @@ func createTools(cfg config) ([]mcp.ToolDefinition, error) {
137137 Execute : newGetMonitorsHistoryHandler (cfg , httpClient ),
138138 RateLimit : rate .NewLimiter (rate .Limit (cfg .monitorsRateLimit ), cfg .monitorsRateBurst ),
139139 },
140- {
141- Metadata : mcp.Tool {
142- Name : "getQueryHistory" ,
143- Description : ptr ("Get your recent APL query execution history" ),
144- InputSchema : mcp.ToolInputSchema {
145- Type : "object" ,
146- Properties : mcp.ToolInputSchemaProperties {
147- "limit" : map [string ]any {
148- "type" : "number" ,
149- "description" : "Maximum number of query history entries to return (default: 50, max: 500)" ,
150- "default" : 50 ,
151- },
152- "user" : map [string ]any {
153- "type" : "string" ,
154- "description" : "Filter by specific user ID (optional - defaults to current user)" ,
155- },
156- "dataset" : map [string ]any {
157- "type" : "string" ,
158- "description" : "Filter by dataset name (optional)" ,
159- },
160- },
161- },
162- },
163- Execute : newGetQueryHistoryHandler (client , cfg , httpClient ),
164- RateLimit : rate .NewLimiter (rate .Limit (cfg .queryRateLimit ), cfg .queryRateBurst ),
165- },
166140 }, nil
167141}
168142
@@ -339,14 +313,7 @@ type SavedQuery struct {
339313 ID string `json:"id"`
340314}
341315
342- // QueryHistoryEntry represents a query execution record from the axiom-history dataset
343- type QueryHistoryEntry struct {
344- Timestamp string `json:"timestamp"`
345- Dataset string `json:"dataset"`
346- Query string `json:"query"`
347- UserID string `json:"userId"`
348- Created string `json:"created"`
349- }
316+
350317
351318// newGetSavedQueriesHandler creates a handler for retrieving saved queries
352319func newGetSavedQueriesHandler (cfg config , httpClient * http.Client ) func (mcp.CallToolRequestParams ) (mcp.CallToolResult , error ) {
@@ -554,110 +521,4 @@ func newGetMonitorsHistoryHandler(cfg config, httpClient *http.Client) func(mcp.
554521 }
555522}
556523
557- // getCurrentUserId gets the current user ID from /v2/user endpoint using PAT
558- func getCurrentUserId (cfg config , httpClient * http.Client ) (string , error ) {
559- ctx := context .Background ()
560-
561- if cfg .token == "" {
562- return "" , fmt .Errorf ("personal Access Token (PAT) is required" )
563- }
564-
565- baseURL := cfg .url
566- fullURL := baseURL + "/v2/user"
567-
568- req , err := http .NewRequestWithContext (ctx , "GET" , fullURL , nil )
569- if err != nil {
570- return "" , fmt .Errorf ("failed to create request: %w" , err )
571- }
572-
573- req .Header .Set ("Authorization" , "Bearer " + cfg .token )
574- req .Header .Set ("Accept" , "application/json" )
575-
576- resp , err := httpClient .Do (req )
577- if err != nil {
578- return "" , fmt .Errorf ("failed to execute request: %w" , err )
579- }
580- defer resp .Body .Close ()
581-
582- if resp .StatusCode != http .StatusOK {
583- body , _ := io .ReadAll (resp .Body )
584- return "" , fmt .Errorf ("request failed with status %d: %s" , resp .StatusCode , string (body ))
585- }
586-
587- body , err := io .ReadAll (resp .Body )
588- if err != nil {
589- return "" , fmt .Errorf ("failed to read response body: %w" , err )
590- }
591- var userResponse struct {
592- ID string `json:"id"`
593- }
594- if err := json .Unmarshal (body , & userResponse ); err != nil {
595- return "" , fmt .Errorf ("failed to parse user response: %w" , err )
596- }
597-
598- if userResponse .ID == "" {
599- return "" , fmt .Errorf ("user ID not found in response" )
600- }
601-
602- return userResponse .ID , nil
603- }
604-
605- // newGetQueryHistoryHandler creates a handler for retrieving query execution history from axiom-history dataset
606- func newGetQueryHistoryHandler (client * axiom.Client , cfg config , httpClient * http.Client ) func (mcp.CallToolRequestParams ) (mcp.CallToolResult , error ) {
607- return func (params mcp.CallToolRequestParams ) (mcp.CallToolResult , error ) {
608- ctx := context .Background ()
609-
610- limit := 50
611- if limitParam , ok := params .Arguments ["limit" ].(float64 ); ok && limitParam > 0 {
612- limit = int (limitParam )
613- if limit > 500 {
614- limit = 500
615- }
616- }
617-
618- currentUserId , err := getCurrentUserId (cfg , httpClient )
619- if err != nil {
620- return mcp.CallToolResult {}, fmt .Errorf ("failed to get current user: %w" , err )
621- }
622-
623- var whereFilters []string
624- whereFilters = append (whereFilters , "kind == \" apl\" " )
625-
626- // Use current user by default, but allow override - if the user provides another ID
627- userToFilter := currentUserId
628- if userParam , ok := params .Arguments ["user" ].(string ); ok && userParam != "" {
629- userToFilter = userParam
630- }
631- whereFilters = append (whereFilters , fmt .Sprintf ("who == \" %s\" " , userToFilter ))
632-
633- // Optional dataset filter
634- if datasetParam , ok := params .Arguments ["dataset" ].(string ); ok && datasetParam != "" {
635- whereFilters = append (whereFilters , fmt .Sprintf ("dataset == \" %s\" " , datasetParam ))
636- }
637-
638- aplQuery := fmt .Sprintf (
639- "[\" axiom-history\" ] | where %s | sort by _time desc | take %d | project _time, dataset, [\" query.apl\" ], who, created" ,
640- strings .Join (whereFilters , " and " ),
641- limit ,
642- )
643524
644- result , err := client .Query (ctx , aplQuery )
645- if err != nil {
646- return mcp.CallToolResult {}, fmt .Errorf ("failed to execute query history query: %w" , err )
647- }
648-
649- jsonData , err := json .MarshalIndent (result , "" , " " )
650- if err != nil {
651- return mcp.CallToolResult {}, fmt .Errorf ("failed to marshal query history response: %w" , err )
652- }
653-
654- return mcp.CallToolResult {
655- Content : []any {
656- mcp.TextContent {
657- Text : string (jsonData ),
658- Type : "text" ,
659- },
660- },
661- }, nil
662- }
663- }
0 commit comments