Skip to content

Commit 1443281

Browse files
authored
Merge pull request #30 from grafana/summarize-list-operations
Limit the amount of data returned for list tools
2 parents 77be25c + 1ed9aa7 commit 1443281

File tree

4 files changed

+29
-7
lines changed

4 files changed

+29
-7
lines changed

tools/datasources.go

+24-2
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,35 @@ import (
1212

1313
type ListDatasourcesParams struct{}
1414

15-
func listDatasources(ctx context.Context, args ListDatasourcesParams) (models.DataSourceList, error) {
15+
type dataSourceSummary struct {
16+
ID int64 `json:"id"`
17+
UID string `json:"uid"`
18+
Name string `json:"name"`
19+
Type string `json:"type"`
20+
IsDefault bool `json:"isDefault"`
21+
}
22+
23+
func listDatasources(ctx context.Context, args ListDatasourcesParams) ([]dataSourceSummary, error) {
1624
c := mcpgrafana.GrafanaClientFromContext(ctx)
1725
datasources, err := c.Datasources.GetDataSources()
1826
if err != nil {
1927
return nil, fmt.Errorf("list datasources: %w", err)
2028
}
21-
return datasources.Payload, nil
29+
return summarizeDatasources(datasources.Payload), nil
30+
}
31+
32+
func summarizeDatasources(dataSources models.DataSourceList) []dataSourceSummary {
33+
result := make([]dataSourceSummary, 0, len(dataSources))
34+
for _, ds := range dataSources {
35+
result = append(result, dataSourceSummary{
36+
ID: ds.ID,
37+
UID: ds.UID,
38+
Name: ds.Name,
39+
Type: ds.Type,
40+
IsDefault: ds.IsDefault,
41+
})
42+
}
43+
return result
2244
}
2345

2446
var ListDatasources = mcpgrafana.MustTool(

tools/incident.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ type ListIncidentsParams struct {
1515
Status string `json:"status" jsonschema:"description=The status of the incidents to include"`
1616
}
1717

18-
func listIncidents(ctx context.Context, args ListIncidentsParams) (*incident.QueryIncidentsResponse, error) {
18+
func listIncidents(ctx context.Context, args ListIncidentsParams) (*incident.QueryIncidentPreviewsResponse, error) {
1919
c := mcpgrafana.IncidentClientFromContext(ctx)
2020
is := incident.NewIncidentsService(c)
2121
query := ""
@@ -25,8 +25,8 @@ func listIncidents(ctx context.Context, args ListIncidentsParams) (*incident.Que
2525
if args.Status != "" {
2626
query += fmt.Sprintf(" and status:%s", args.Status)
2727
}
28-
incidents, err := is.QueryIncidents(ctx, incident.QueryIncidentsRequest{
29-
Query: incident.IncidentsQuery{
28+
incidents, err := is.QueryIncidentPreviews(ctx, incident.QueryIncidentPreviewsRequest{
29+
Query: incident.IncidentPreviewsQuery{
3030
QueryString: query,
3131
OrderDirection: "DESC",
3232
Limit: args.Limit,

tools/incident_integration_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,6 @@ func TestCloudIncidentTools(t *testing.T) {
2121
Limit: 2,
2222
})
2323
require.NoError(t, err)
24-
assert.Len(t, result.Incidents, 2)
24+
assert.Len(t, result.IncidentPreviews, 2)
2525
})
2626
}

tools/incident_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ func TestIncidentTools(t *testing.T) {
2222
Limit: 2,
2323
})
2424
require.NoError(t, err)
25-
assert.Len(t, result.Incidents, 2)
25+
assert.Len(t, result.IncidentPreviews, 2)
2626
})
2727

2828
t.Run("create incident", func(t *testing.T) {

0 commit comments

Comments
 (0)