awslabs.cloudwatch-appsignals-mcp-server 0.1.5__py3-none-any.whl → 0.1.8__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (19) hide show
  1. awslabs/cloudwatch_appsignals_mcp_server/__init__.py +1 -1
  2. awslabs/cloudwatch_appsignals_mcp_server/audit_presentation_utils.py +231 -0
  3. awslabs/cloudwatch_appsignals_mcp_server/audit_utils.py +699 -0
  4. awslabs/cloudwatch_appsignals_mcp_server/aws_clients.py +88 -0
  5. awslabs/cloudwatch_appsignals_mcp_server/server.py +675 -1220
  6. awslabs/cloudwatch_appsignals_mcp_server/service_audit_utils.py +231 -0
  7. awslabs/cloudwatch_appsignals_mcp_server/service_tools.py +659 -0
  8. awslabs/cloudwatch_appsignals_mcp_server/sli_report_client.py +5 -12
  9. awslabs/cloudwatch_appsignals_mcp_server/slo_tools.py +386 -0
  10. awslabs/cloudwatch_appsignals_mcp_server/trace_tools.py +658 -0
  11. awslabs/cloudwatch_appsignals_mcp_server/utils.py +172 -0
  12. awslabs_cloudwatch_appsignals_mcp_server-0.1.8.dist-info/METADATA +636 -0
  13. awslabs_cloudwatch_appsignals_mcp_server-0.1.8.dist-info/RECORD +18 -0
  14. awslabs_cloudwatch_appsignals_mcp_server-0.1.5.dist-info/METADATA +0 -321
  15. awslabs_cloudwatch_appsignals_mcp_server-0.1.5.dist-info/RECORD +0 -10
  16. {awslabs_cloudwatch_appsignals_mcp_server-0.1.5.dist-info → awslabs_cloudwatch_appsignals_mcp_server-0.1.8.dist-info}/WHEEL +0 -0
  17. {awslabs_cloudwatch_appsignals_mcp_server-0.1.5.dist-info → awslabs_cloudwatch_appsignals_mcp_server-0.1.8.dist-info}/entry_points.txt +0 -0
  18. {awslabs_cloudwatch_appsignals_mcp_server-0.1.5.dist-info → awslabs_cloudwatch_appsignals_mcp_server-0.1.8.dist-info}/licenses/LICENSE +0 -0
  19. {awslabs_cloudwatch_appsignals_mcp_server-0.1.5.dist-info → awslabs_cloudwatch_appsignals_mcp_server-0.1.8.dist-info}/licenses/NOTICE +0 -0
@@ -14,4 +14,4 @@
14
14
 
15
15
  """AWS Application Signals MCP Server."""
16
16
 
17
- __version__ = '0.1.5'
17
+ __version__ = '0.1.8'
@@ -0,0 +1,231 @@
1
+ # Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
2
+ #
3
+ # Licensed under the Apache License, Version 2.0 (the "License");
4
+ # you may not use this file except in compliance with the License.
5
+ # You may obtain a copy of the License at
6
+ #
7
+ # http://www.apache.org/licenses/LICENSE-2.0
8
+ #
9
+ # Unless required by applicable law or agreed to in writing, software
10
+ # distributed under the License is distributed on an "AS IS" BASIS,
11
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ # See the License for the specific language governing permissions and
13
+ # limitations under the License.
14
+
15
+ """Utilities for presenting audit findings and managing user interaction."""
16
+
17
+ import json
18
+ from loguru import logger
19
+ from typing import Any, Dict, List, Tuple
20
+
21
+
22
+ def extract_findings_summary(audit_result: str) -> Tuple[List[Dict[str, Any]], str]:
23
+ """Extract findings from audit result and return summary with original result.
24
+
25
+ Returns:
26
+ Tuple of (findings_list, original_result)
27
+ """
28
+ try:
29
+ # Find the JSON part in the audit result
30
+ json_start = audit_result.find('{')
31
+ if json_start == -1:
32
+ return [], audit_result
33
+
34
+ json_part = audit_result[json_start:]
35
+ audit_data = json.loads(json_part)
36
+
37
+ findings = audit_data.get('AuditFindings', [])
38
+ return findings, audit_result
39
+
40
+ except (json.JSONDecodeError, KeyError) as e:
41
+ logger.warning(f'Failed to parse audit result for findings extraction: {e}')
42
+ return [], audit_result
43
+
44
+
45
+ def format_findings_summary(findings: List[Dict[str, Any]], audit_type: str = 'service') -> str:
46
+ """Format findings into a user-friendly summary for selection.
47
+
48
+ Args:
49
+ findings: List of audit findings
50
+ audit_type: Type of audit ("service", "slo", "operation")
51
+
52
+ Returns:
53
+ Formatted summary string
54
+ """
55
+ if not findings:
56
+ return f'✅ No issues found in {audit_type} audit. All targets appear healthy.'
57
+
58
+ # Group findings by severity
59
+ critical_findings = []
60
+ warning_findings = []
61
+ info_findings = []
62
+
63
+ for finding in findings:
64
+ severity = finding.get('Severity', 'INFO').upper()
65
+ if severity == 'CRITICAL':
66
+ critical_findings.append(finding)
67
+ elif severity == 'WARNING':
68
+ warning_findings.append(finding)
69
+ else:
70
+ info_findings.append(finding)
71
+
72
+ # Build summary
73
+ summary = f'🔍 **{audit_type.title()} Audit Results Summary**\n\n'
74
+ summary += f'Found **{len(findings)} total findings**:\n'
75
+
76
+ if critical_findings:
77
+ summary += (
78
+ f'🚨 **{len(critical_findings)} Critical Issues** (require immediate attention)\n'
79
+ )
80
+ if warning_findings:
81
+ summary += f'⚠️ **{len(warning_findings)} Warning Issues** (should be investigated)\n'
82
+ if info_findings:
83
+ summary += f'ℹ️ **{len(info_findings)} Info Issues** (for awareness)\n'
84
+
85
+ summary += '\n---\n\n'
86
+
87
+ # List findings with selection numbers
88
+ finding_counter = 1
89
+
90
+ if critical_findings:
91
+ summary += '🚨 **CRITICAL ISSUES:**\n'
92
+ for finding in critical_findings:
93
+ finding_id = finding.get('FindingId', f'finding-{finding_counter}')
94
+ description = finding.get('Description', 'No description available')
95
+ summary += f'**{finding_counter}.** Finding ID: {finding_id}\n'
96
+ summary += f' 💬 {description}\n\n'
97
+ finding_counter += 1
98
+
99
+ if warning_findings:
100
+ summary += '⚠️ **WARNING ISSUES:**\n'
101
+ for finding in warning_findings:
102
+ finding_id = finding.get('FindingId', f'finding-{finding_counter}')
103
+ description = finding.get('Description', 'No description available')
104
+ summary += f'**{finding_counter}.** Finding ID: {finding_id}\n'
105
+ summary += f' 💬 {description}\n\n'
106
+ finding_counter += 1
107
+
108
+ if info_findings:
109
+ summary += 'ℹ️ **INFORMATIONAL:**\n'
110
+ for finding in info_findings:
111
+ finding_id = finding.get('FindingId', f'finding-{finding_counter}')
112
+ description = finding.get('Description', 'No description available')
113
+ summary += f'**{finding_counter}.** Finding ID: {finding_id}\n'
114
+ summary += f' 💬 {description}\n\n'
115
+ finding_counter += 1
116
+
117
+ summary += '---\n\n'
118
+ summary += '🎯 **Next Steps:**\n'
119
+ summary += "To investigate any specific issue in detail, please let me know which finding number you'd like me to analyze further.\n"
120
+ summary += 'I can perform comprehensive root cause analysis including traces, logs, metrics, and dependencies.\n\n'
121
+ summary += '**Example:** "Please investigate finding #1 in detail" or "Show me root cause analysis for finding #3"\n'
122
+
123
+ return summary
124
+
125
+
126
+ def create_targeted_audit_request(
127
+ original_targets: List[Dict[str, Any]],
128
+ findings: List[Dict[str, Any]],
129
+ selected_finding_index: int,
130
+ audit_type: str,
131
+ ) -> Dict[str, Any]:
132
+ """Create a targeted audit request for a specific finding.
133
+
134
+ Args:
135
+ original_targets: Original audit targets
136
+ findings: List of all findings
137
+ selected_finding_index: Index of the selected finding (1-based)
138
+ audit_type: Type of audit ("service", "slo", "operation")
139
+
140
+ Returns:
141
+ Dictionary with targeted audit parameters
142
+ """
143
+ if selected_finding_index < 1 or selected_finding_index > len(findings):
144
+ raise ValueError(
145
+ f'Invalid finding index {selected_finding_index}. Must be between 1 and {len(findings)}'
146
+ )
147
+
148
+ selected_finding = findings[selected_finding_index - 1]
149
+ target_name = selected_finding.get('TargetName', '')
150
+
151
+ # Find the matching target from original targets
152
+ targeted_targets = []
153
+
154
+ for target in original_targets:
155
+ target_matches = False
156
+
157
+ if audit_type == 'service':
158
+ service_data = target.get('Data', {}).get('Service', {})
159
+ service_name = service_data.get('Name', '')
160
+ if service_name == target_name:
161
+ target_matches = True
162
+ elif audit_type == 'slo':
163
+ slo_data = target.get('Data', {}).get('Slo', {})
164
+ slo_name = slo_data.get('SloName', '')
165
+ if slo_name == target_name:
166
+ target_matches = True
167
+ elif audit_type == 'operation':
168
+ service_op_data = target.get('Data', {}).get('ServiceOperation', {})
169
+ service_data = service_op_data.get('Service', {})
170
+ service_name = service_data.get('Name', '')
171
+ operation = service_op_data.get('Operation', '')
172
+ # For operations, target name might be "service-name:operation"
173
+ if f'{service_name}:{operation}' == target_name or service_name == target_name:
174
+ target_matches = True
175
+
176
+ if target_matches:
177
+ targeted_targets.append(target)
178
+
179
+ if not targeted_targets:
180
+ # If we can't find exact match, create a new target based on the finding
181
+ logger.warning(
182
+ f'Could not find exact target match for finding {selected_finding_index}, creating new target'
183
+ )
184
+ if audit_type == 'service':
185
+ targeted_targets = [
186
+ {'Type': 'service', 'Data': {'Service': {'Type': 'Service', 'Name': target_name}}}
187
+ ]
188
+ elif audit_type == 'slo':
189
+ targeted_targets = [{'Type': 'slo', 'Data': {'Slo': {'SloName': target_name}}}]
190
+
191
+ return {
192
+ 'targets': targeted_targets,
193
+ 'finding': selected_finding,
194
+ 'auditors': 'all', # Use all auditors for comprehensive root cause analysis
195
+ }
196
+
197
+
198
+ def format_detailed_finding_analysis(finding: Dict[str, Any], detailed_result: str) -> str:
199
+ """Format the detailed analysis result for a specific finding.
200
+
201
+ Args:
202
+ finding: The specific finding being analyzed
203
+ detailed_result: The detailed audit result
204
+
205
+ Returns:
206
+ Formatted analysis string
207
+ """
208
+ target_name = finding.get('TargetName', 'Unknown Target')
209
+ finding_type = finding.get('FindingType', 'Unknown')
210
+ title = finding.get('Title', 'No title')
211
+ severity = finding.get('Severity', 'INFO').upper()
212
+
213
+ # Severity emoji mapping
214
+ severity_emoji = {'CRITICAL': '🚨', 'WARNING': '⚠️', 'INFO': 'ℹ️'}
215
+
216
+ analysis = f'{severity_emoji.get(severity, "ℹ️")} **DETAILED ROOT CAUSE ANALYSIS**\n\n'
217
+ analysis += f'**Target:** {target_name}\n'
218
+ analysis += f'**Issue Type:** {finding_type}\n'
219
+ analysis += f'**Severity:** {severity}\n'
220
+ analysis += f'**Title:** {title}\n\n'
221
+
222
+ # Add the original finding description if available
223
+ description = finding.get('Description', '')
224
+ if description:
225
+ analysis += f'**Issue Description:**\n{description}\n\n'
226
+
227
+ analysis += '---\n\n'
228
+ analysis += '**COMPREHENSIVE ANALYSIS RESULTS:**\n\n'
229
+ analysis += detailed_result
230
+
231
+ return analysis