Skip to content

Commit 0550756

Browse files
authored
Add tool get incident (#77)
* Get an incident if an ID is provided * improve prompts and add default limit if not specified
1 parent 575361c commit 0550756

File tree

2 files changed

+46
-2
lines changed

2 files changed

+46
-2
lines changed

tools/incident.go

Lines changed: 34 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,13 @@ type ListIncidentsParams struct {
1818
func listIncidents(ctx context.Context, args ListIncidentsParams) (*incident.QueryIncidentPreviewsResponse, error) {
1919
c := mcpgrafana.IncidentClientFromContext(ctx)
2020
is := incident.NewIncidentsService(c)
21+
22+
// Set default limit to 10 if not specified
23+
limit := args.Limit
24+
if limit <= 0 {
25+
limit = 10
26+
}
27+
2128
query := ""
2229
if !args.Drill {
2330
query = "isdrill:false"
@@ -29,7 +36,7 @@ func listIncidents(ctx context.Context, args ListIncidentsParams) (*incident.Que
2936
Query: incident.IncidentPreviewsQuery{
3037
QueryString: query,
3138
OrderDirection: "DESC",
32-
Limit: args.Limit,
39+
Limit: limit,
3340
},
3441
})
3542
if err != nil {
@@ -103,12 +110,37 @@ func addActivityToIncident(ctx context.Context, args AddActivityToIncidentParams
103110

104111
var AddActivityToIncident = mcpgrafana.MustTool(
105112
"add_activity_to_incident",
106-
"Add an activity to an incident",
113+
"Add a note to an incident's timeline. The note will appear in the incident's activity feed. Use this if there is a request to add context to an incident with a note.",
107114
addActivityToIncident,
108115
)
109116

110117
func AddIncidentTools(mcp *server.MCPServer) {
111118
ListIncidents.Register(mcp)
112119
CreateIncident.Register(mcp)
113120
AddActivityToIncident.Register(mcp)
121+
GetIncident.Register(mcp)
122+
}
123+
124+
type GetIncidentParams struct {
125+
ID string `json:"id" jsonschema:"description=The ID of the incident to retrieve"`
126+
}
127+
128+
func getIncident(ctx context.Context, args GetIncidentParams) (*incident.Incident, error) {
129+
c := mcpgrafana.IncidentClientFromContext(ctx)
130+
is := incident.NewIncidentsService(c)
131+
132+
incidentResp, err := is.GetIncident(ctx, incident.GetIncidentRequest{
133+
IncidentID: args.ID,
134+
})
135+
if err != nil {
136+
return nil, fmt.Errorf("get incident by ID: %w", err)
137+
}
138+
139+
return &incidentResp.Incident, nil
114140
}
141+
142+
var GetIncident = mcpgrafana.MustTool(
143+
"get_incident",
144+
"Get a single incident by ID. Returns the full incident details including title, status, severity, and other metadata.",
145+
getIncident,
146+
)

tools/incident_integration_test.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,4 +50,16 @@ func TestCloudIncidentTools(t *testing.T) {
5050
assert.NotNil(t, result.IncidentPreviews, "IncidentPreviews should not be nil")
5151
assert.LessOrEqual(t, len(result.IncidentPreviews), 1, "Should not return more incidents than the limit")
5252
})
53+
54+
t.Run("get incident by ID", func(t *testing.T) {
55+
ctx := createCloudTestContext(t)
56+
result, err := getIncident(ctx, GetIncidentParams{
57+
ID: "1",
58+
})
59+
require.NoError(t, err)
60+
assert.NotNil(t, result, "Result should not be nil")
61+
assert.Equal(t, "1", result.IncidentID, "Should return the requested incident ID")
62+
assert.NotEmpty(t, result.Title, "Incident should have a title")
63+
assert.NotEmpty(t, result.Status, "Incident should have a status")
64+
})
5365
}

0 commit comments

Comments
 (0)