Skip to content

Commit c6703bc

Browse files
authored
Merge pull request #8 from axiomhq/remove-queryHistory
remove getQueryHistory tool and use API tokens
2 parents 73d0b18 + 512ce70 commit c6703bc

File tree

3 files changed

+11
-151
lines changed

3 files changed

+11
-151
lines changed

README.md

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,16 @@ A [Model Context Protocol](https://modelcontextprotocol.io/) server implementati
44

55
## Status
66

7-
Works with Claude desktop app. Implements seven MCP [tools](https://modelcontextprotocol.io/docs/concepts/tools):
7+
Works with Claude desktop app. Implements six MCP [tools](https://modelcontextprotocol.io/docs/concepts/tools):
88

99
- queryApl: Execute APL queries against Axiom datasets
1010
- listDatasets: List available Axiom datasets
1111
- getDatasetSchema: Get dataset schema
1212
- getSavedQueries: Retrieve saved/starred APL queries
1313
- getMonitors: List monitoring configurations
1414
- getMonitorsHistory: Get monitor execution history
15-
- getQueryHistory: Get your recent APL query execution history (shows your queries by default)
1615

17-
**Note:** All tools require a Personal Access Token (PAT) for authentication. Use your PAT as the `token` parameter.
16+
**Note:** All tools require an API token for authentication. Use your API token as the `token` parameter.
1817

1918
No support for MCP [resources](https://modelcontextprotocol.io/docs/concepts/resources) or [prompts](https://modelcontextprotocol.io/docs/concepts/prompts) yet.
2019

@@ -36,7 +35,7 @@ Configure using one of these methods:
3635

3736
### Config File Example (config.txt):
3837
```txt
39-
token xapt-your-personal-access-token
38+
token xaat-your-api-token
4039
url https://api.axiom.co
4140
org-id your-org-id
4241
query-rate 1
@@ -48,7 +47,7 @@ datasets-burst 1
4847
### Command Line Flags:
4948
```bash
5049
axiom-mcp \
51-
-token xapt-your-personal-access-token \
50+
-token xaat-your-api-token \
5251
-url https://api.axiom.co \
5352
-org-id your-org-id \
5453
-query-rate 1 \
@@ -59,7 +58,7 @@ axiom-mcp \
5958

6059
### Environment Variables:
6160
```bash
62-
export AXIOM_TOKEN=xapt-your-personal-access-token
61+
export AXIOM_TOKEN=xaat-your-api-token
6362
export AXIOM_URL=https://api.axiom.co
6463
export AXIOM_ORG_ID=your-org-id
6564
export AXIOM_QUERY_RATE=1
@@ -72,7 +71,7 @@ export AXIOM_DATASETS_BURST=1
7271

7372
1. Create a config file:
7473
```bash
75-
echo "token xapt-your-personal-access-token" > config.txt
74+
echo "token xaat-your-api-token" > config.txt
7675
```
7776

7877
2. Configure the Claude app to use the MCP server:
@@ -88,7 +87,7 @@ code ~/Library/Application\ Support/Claude/claude_desktop_config.json
8887
"command": "/path/to/your/axiom-mcp-binary",
8988
"args" : ["--config", "/path/to/your/config.txt"],
9089
"env": { // Alternatively, you can set the environment variables here
91-
"AXIOM_TOKEN": "xapt-your-personal-access-token",
90+
"AXIOM_TOKEN": "xaat-your-api-token",
9291
"AXIOM_URL": "https://api.axiom.co",
9392
"AXIOM_ORG_ID": "your-org-id"
9493
}

main.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ var (
4343
// config holds the server configuration parameters
4444
type config struct {
4545
// Axiom connection settings
46-
token string // Personal Access Token (PAT)
46+
token string // API token
4747
url string // Optional custom API URL
4848
orgID string // Organization ID
4949

@@ -61,7 +61,7 @@ func setupConfig() (config, error) {
6161
fs := flag.NewFlagSet("axiom-mcp", flag.ExitOnError)
6262

6363
var cfg config
64-
fs.StringVar(&cfg.token, "token", "", "Axiom Personal Access Token (PAT)")
64+
fs.StringVar(&cfg.token, "token", "", "Axiom API token")
6565
fs.StringVar(&cfg.url, "url", "", "Axiom API URL (optional)")
6666
fs.StringVar(&cfg.orgID, "org-id", "", "Axiom organization ID")
6767
fs.Float64Var(&cfg.queryRateLimit, "query-rate", 1, "Queries per second limit")
@@ -84,7 +84,7 @@ func setupConfig() (config, error) {
8484
}
8585

8686
if cfg.token == "" {
87-
return cfg, errors.New("Axiom Personal Access Token (PAT) must be provided via -token flag, AXIOM_TOKEN env var, or config file")
87+
return cfg, errors.New("Axiom API token must be provided via -token flag, AXIOM_TOKEN env var, or config file")
8888
}
8989

9090
return cfg, nil

tools.go

Lines changed: 1 addition & 140 deletions
Original file line numberDiff line numberDiff line change
@@ -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
352319
func 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

Comments
 (0)