1717 IncidentResponderRequest ,
1818 IncidentResponderRequestResponse ,
1919 ListResponseModel ,
20+ LogEntry ,
2021 MCPContext ,
2122 ServiceReference ,
2223 UserReference ,
3233 add_responders ,
3334 create_incident ,
3435 get_incident ,
36+ get_incident_log_entries ,
3537 list_incidents ,
3638 manage_incidents ,
3739)
@@ -61,6 +63,80 @@ def setUpClass(cls):
6163 "html_url" : "https://test.pagerduty.com/incidents/PINCIDENT123" ,
6264 }
6365
66+ cls .sample_log_entry_data = [
67+ {
68+ "id" : "RO52CY6QBZKDN9PEGS3YPN35TH" ,
69+ "type" : "resolve_log_entry" ,
70+ "summary" : "Resolved through the API." ,
71+ "self" : "https://api.pagerduty.com/log_entries/RO52CY6QBZKDN9PEGS3YPN35TH" ,
72+ "html_url" : None ,
73+ "created_at" : "2025-09-18T22:59:28Z" ,
74+ "agent" : {
75+ "id" : "PWB6A94" ,
76+ "type" : "events_api_v2_inbound_integration_reference" ,
77+ "summary" : "AlertManager" ,
78+ "self" : "https://api.pagerduty.com/services/P9TYXZJ/integrations/PWB6A94" ,
79+ "html_url" : "https://thousandeyesops.pagerduty.com/services/P9TYXZJ/integrations/PWB6A94" ,
80+ },
81+ "channel" : {
82+ "type" : "integration" ,
83+ "client" : "Alertmanager" ,
84+ "client_url" : "https://alertmanager.example.com" ,
85+ },
86+ "service" : {
87+ "id" : "P9TYXZJ" ,
88+ "type" : "service_reference" ,
89+ "summary" : "[PROD] Webapps" ,
90+ "self" : "https://api.pagerduty.com/services/P9TYXZJ" ,
91+ "html_url" : "https://thousandeyesops.pagerduty.com/service-directory/P9TYXZJ" ,
92+ },
93+ "incident" : {
94+ "id" : "Q0Y9H9AUGZHAHS" ,
95+ "type" : "incident_reference" ,
96+ "summary" : "[#568677] Test incident" ,
97+ "self" : "https://api.pagerduty.com/incidents/Q0Y9H9AUGZHAHS" ,
98+ "html_url" : "https://thousandeyesops.pagerduty.com/incidents/Q0Y9H9AUGZHAHS" ,
99+ },
100+ "teams" : [],
101+ "contexts" : [],
102+ "event_details" : {},
103+ },
104+ {
105+ "id" : "RONF3S8XQ8TVEA2DXQS6FRPBEV" ,
106+ "type" : "acknowledge_log_entry" ,
107+ "summary" : "Acknowledged by Test User." ,
108+ "self" : "https://api.pagerduty.com/log_entries/RONF3S8XQ8TVEA2DXQS6FRPBEV" ,
109+ "html_url" : None ,
110+ "created_at" : "2025-09-18T22:54:38Z" ,
111+ "agent" : {
112+ "id" : "PE9XZ7K" ,
113+ "type" : "user_reference" ,
114+ "summary" : "Test User" ,
115+ "self" : "https://api.pagerduty.com/users/PE9XZ7K" ,
116+ "html_url" : "https://thousandeyesops.pagerduty.com/users/PE9XZ7K" ,
117+ },
118+ "channel" : {"type" : "mobile" },
119+ "service" : {
120+ "id" : "P9TYXZJ" ,
121+ "type" : "service_reference" ,
122+ "summary" : "[PROD] Webapps" ,
123+ "self" : "https://api.pagerduty.com/services/P9TYXZJ" ,
124+ "html_url" : "https://thousandeyesops.pagerduty.com/service-directory/P9TYXZJ" ,
125+ },
126+ "incident" : {
127+ "id" : "Q0Y9H9AUGZHAHS" ,
128+ "type" : "incident_reference" ,
129+ "summary" : "[#568677] Test incident" ,
130+ "self" : "https://api.pagerduty.com/incidents/Q0Y9H9AUGZHAHS" ,
131+ "html_url" : "https://thousandeyesops.pagerduty.com/incidents/Q0Y9H9AUGZHAHS" ,
132+ },
133+ "teams" : [],
134+ "contexts" : [],
135+ "acknowledgement_timeout" : 3600 ,
136+ "event_details" : {},
137+ },
138+ ]
139+
64140 cls .sample_user_data = Mock ()
65141 cls .sample_user_data .id = "PUSER123"
66142 cls .sample_user_data .teams = [Mock (id = "PTEAM123" )]
@@ -182,6 +258,68 @@ def test_get_incident_api_error(self, mock_get_client):
182258
183259 self .assertIn ("API Error" , str (context .exception ))
184260
261+ @patch ("pagerduty_mcp.tools.incidents.get_client" )
262+ def test_get_incident_log_entries_success (self , mock_get_client ):
263+ """Test getting incident log entries successfully."""
264+ # Setup mock
265+ mock_client = Mock ()
266+ mock_client .rget .return_value = self .sample_log_entry_data
267+ mock_get_client .return_value = mock_client
268+
269+ # Test
270+ result = get_incident_log_entries ("PINCIDENT123" )
271+
272+ # Assertions
273+ self .assertIsInstance (result , list )
274+ self .assertEqual (len (result ), 2 )
275+ self .assertIsInstance (result [0 ], LogEntry )
276+ self .assertIsInstance (result [1 ], LogEntry )
277+
278+ # Check first log entry (resolve)
279+ self .assertEqual (result [0 ].id , "RO52CY6QBZKDN9PEGS3YPN35TH" )
280+ self .assertEqual (result [0 ].type , "resolve_log_entry" )
281+ self .assertEqual (result [0 ].summary , "Resolved through the API." )
282+ self .assertIsNotNone (result [0 ].agent )
283+ self .assertEqual (result [0 ].agent .summary , "AlertManager" )
284+
285+ # Check second log entry (acknowledge)
286+ self .assertEqual (result [1 ].id , "RONF3S8XQ8TVEA2DXQS6FRPBEV" )
287+ self .assertEqual (result [1 ].type , "acknowledge_log_entry" )
288+ self .assertEqual (result [1 ].summary , "Acknowledged by Test User." )
289+ self .assertEqual (result [1 ].acknowledgement_timeout , 3600 )
290+
291+ mock_client .rget .assert_called_once_with ("/incidents/PINCIDENT123/log_entries" )
292+
293+ @patch ("pagerduty_mcp.tools.incidents.get_client" )
294+ def test_get_incident_log_entries_empty (self , mock_get_client ):
295+ """Test getting incident log entries with empty response."""
296+ # Setup mock
297+ mock_client = Mock ()
298+ mock_client .rget .return_value = []
299+ mock_get_client .return_value = mock_client
300+
301+ # Test
302+ result = get_incident_log_entries ("PINCIDENT123" )
303+
304+ # Assertions
305+ self .assertIsInstance (result , list )
306+ self .assertEqual (len (result ), 0 )
307+ mock_client .rget .assert_called_once_with ("/incidents/PINCIDENT123/log_entries" )
308+
309+ @patch ("pagerduty_mcp.tools.incidents.get_client" )
310+ def test_get_incident_log_entries_api_error (self , mock_get_client ):
311+ """Test get_incident_log_entries with API error."""
312+ # Setup mock to raise exception
313+ mock_client = Mock ()
314+ mock_client .rget .side_effect = Exception ("API Error" )
315+ mock_get_client .return_value = mock_client
316+
317+ # Test that exception is raised
318+ with self .assertRaises (Exception ) as context :
319+ get_incident_log_entries ("PINCIDENT123" )
320+
321+ self .assertIn ("API Error" , str (context .exception ))
322+
185323 @patch ("pagerduty_mcp.tools.incidents.get_client" )
186324 def test_create_incident_success (self , mock_get_client ):
187325 """Test creating an incident successfully."""
@@ -467,10 +605,7 @@ def test_add_note_to_incident_success(self, mock_get_client):
467605 "id" : "PNOTE123" ,
468606 "content" : "This is a test note" ,
469607 "created_at" : "2023-01-01T10:00:00Z" ,
470- "user" : {
471- "id" : "PUSER123" ,
472- "summary" : "Test User"
473- }
608+ "user" : {"id" : "PUSER123" , "summary" : "Test User" },
474609 }
475610
476611 mock_client = Mock ()
@@ -488,9 +623,9 @@ def test_add_note_to_incident_success(self, mock_get_client):
488623
489624 # Verify API call
490625 mock_client .rpost .assert_called_once_with (
491- "/incidents/PINC123/notes" ,
492- json = {"note" : {"content" : "This is a test note" }}
626+ "/incidents/PINC123/notes" , json = {"note" : {"content" : "This is a test note" }}
493627 )
494628
629+
495630if __name__ == "__main__" :
496631 unittest .main ()
0 commit comments