-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcritical_fixes.patch
More file actions
137 lines (111 loc) · 4.18 KB
/
Copy pathcritical_fixes.patch
File metadata and controls
137 lines (111 loc) · 4.18 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
# Critical Runtime Fixes for SecurityAgents Platform
# Generated by Execution Test Agent - 2026-03-10
## Fix 1: Slack MCP Client Import Error
## File: mcp-integration/slack-workflows/slack_mcp_client.py
### Replace lines 25-28:
```python
# OLD (causes import error):
import sys
import os
sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
from gateway.enterprise_mcp_gateway import SecurityEvent, EventSeverity, EventType
# NEW (correct relative import):
from ..gateway.enterprise_mcp_gateway import SecurityEvent, EventSeverity, EventType
```
## Fix 2: MCPServerConfig Input Validation
## File: mcp-integration/gateway/mcp_server_manager.py
### Add after line 54 (end of MCPServerConfig class):
```python
def __post_init__(self):
"""Validate configuration parameters."""
if not self.server_name or not self.server_name.strip():
raise ValueError("server_name cannot be empty")
if not self.server_url or not self.server_url.strip():
raise ValueError("server_url cannot be empty")
# Basic URL validation
if not (self.server_url.startswith('http://') or self.server_url.startswith('https://')):
raise ValueError("server_url must start with http:// or https://")
# Validate auth_type
valid_auth_types = ['oauth2', 'api_key', 'iam', 'bearer_token']
if self.auth_type not in valid_auth_types:
raise ValueError(f"auth_type must be one of: {valid_auth_types}")
```
## Fix 3: Enhanced MCP Error Messages
## File: mcp-integration/gateway/mcp_server_manager.py
### Replace around line 456 in _make_mcp_request method:
```python
# OLD:
except Exception as e:
error_msg = f"MCP client error: {self.config.server_url}"
# NEW:
except Exception as e:
error_msg = f"MCP client error connecting to {self.config.server_url}: {str(e)}"
```
## Fix 4: Health Check Validation
## Add to CrowdStrike, AWS, and GitHub clients:
### In each client's get_health_status method, add connection test:
```python
async def get_health_status(self) -> Dict[str, Any]:
"""Get health status with actual connectivity test."""
base_status = {
# ... existing status fields ...
}
# Test actual connectivity
try:
# Attempt a lightweight MCP call
await self.mcp_manager.call_mcp_tool('list_tools', {})
base_status['connectivity_test'] = 'healthy'
base_status['last_connectivity_check'] = datetime.now().isoformat()
except Exception as e:
base_status['connectivity_test'] = 'failed'
base_status['connectivity_error'] = str(e)
base_status['last_connectivity_check'] = datetime.now().isoformat()
return base_status
```
## Application Instructions
1. **Slack Import Fix**:
```bash
cd projects/security-agents
# Edit mcp-integration/slack-workflows/slack_mcp_client.py
# Replace lines 25-28 with the new import
```
2. **Config Validation Fix**:
```bash
# Edit mcp-integration/gateway/mcp_server_manager.py
# Add __post_init__ method to MCPServerConfig class
```
3. **Test Fixes**:
```bash
source venv/bin/activate
python run_example.py # Should now import Slack client successfully
python -c "
from mcp_integration.gateway.mcp_server_manager import MCPServerConfig
try:
MCPServerConfig('', 'bad-url', 'bad-auth')
except ValueError as e:
print(f'✅ Validation working: {e}')
"
```
## Validation Commands
After applying fixes, run these tests to verify:
```bash
cd projects/security-agents && source venv/bin/activate
# Test 1: Verify Slack import works
python -c "from mcp_integration.slack_workflows.slack_mcp_client import SlackMCPClient; print('✅ Slack import fixed')"
# Test 2: Verify config validation
python -c "
from mcp_integration.gateway.mcp_server_manager import MCPServerConfig
try:
MCPServerConfig('', '', '')
print('❌ Validation not working')
except ValueError:
print('✅ Config validation working')
"
# Test 3: Full platform test
python run_example.py
```
Expected results after fixes:
- ✅ All imports successful (including Slack)
- ✅ Invalid configs rejected at creation time
- ✅ Better error messages for connection failures
- ✅ Health checks include connectivity tests