-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathtest_cursor_integration.py
More file actions
executable file
·229 lines (186 loc) · 6.7 KB
/
test_cursor_integration.py
File metadata and controls
executable file
·229 lines (186 loc) · 6.7 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
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
#!/usr/bin/env python3
"""
Test script for Cursor MCP Graylog integration.
This script tests the Docker setup and provides configuration examples
for integrating the MCP Graylog server with Cursor.
"""
import os
import sys
import subprocess
import json
from pathlib import Path
def check_environment_variables():
"""Check if required environment variables are set."""
print("Checking environment variables...")
required_vars = {
"GRAYLOG_ENDPOINT": "Graylog server URL (e.g., https://graylog.example.com:9000)",
"GRAYLOG_USERNAME": "Graylog username for authentication",
"GRAYLOG_PASSWORD": "Graylog password for authentication",
}
missing_vars = []
for var, description in required_vars.items():
value = os.getenv(var)
if value:
print(f"Environment variable {var}: {'*' * len(value)} ({description})")
else:
missing_vars.append(var)
print(f"Missing: {var} ({description})")
if missing_vars:
print(f"\nWarning: {len(missing_vars)} environment variables are missing.")
print("You can set them in your environment or create a .env file.")
return False
print("Using Username/Password authentication")
return True
def check_docker_image():
"""Check if the Docker image exists."""
print("\nChecking Docker image...")
try:
result = subprocess.run(
[
"docker",
"images",
"mcp-graylog:latest",
"--format",
"{{.Repository}}:{{.Tag}}",
],
capture_output=True,
text=True,
check=True,
)
if result.stdout.strip():
print("Docker image mcp-graylog:latest found")
return True
else:
print("Docker image mcp-graylog:latest not found")
print("You can build it with: docker build -t mcp-graylog .")
return False
except subprocess.CalledProcessError:
print("ERROR: Failed to check Docker images")
return False
except FileNotFoundError:
print("ERROR: Docker not found. Please install Docker.")
return False
def test_container_startup():
"""Test if the container can start successfully."""
print("\nTesting container startup...")
# Get environment variables for the test
env_vars = {
"GRAYLOG_ENDPOINT": os.getenv("GRAYLOG_ENDPOINT", "https://example.com:9000"),
"GRAYLOG_USERNAME": os.getenv("GRAYLOG_USERNAME", "test"),
"GRAYLOG_PASSWORD": os.getenv("GRAYLOG_PASSWORD", "test"),
"GRAYLOG_VERIFY_SSL": "false",
"GRAYLOG_TIMEOUT": "10",
}
try:
# Build the docker run command
cmd = [
"docker",
"run",
"--rm",
"-d",
"--name",
"mcp-graylog-test",
"-p",
"8001:8000", # Use different port for testing
]
# Add environment variables
for key, value in env_vars.items():
cmd.extend(["-e", f"{key}={value}"])
cmd.append("mcp-graylog:latest")
print(f"Running: {' '.join(cmd)}")
# Start the container
result = subprocess.run(cmd, capture_output=True, text=True)
if result.returncode == 0:
container_id = result.stdout.strip()
print(f"Container started with ID: {container_id}")
# Wait a moment for startup
import time
time.sleep(3)
# Check if container is still running
check_result = subprocess.run(
[
"docker",
"ps",
"--filter",
f"id={container_id}",
"--format",
"{{.Status}}",
],
capture_output=True,
text=True,
)
if check_result.stdout.strip():
print("Container starts successfully")
# Stop the test container
subprocess.run(["docker", "stop", container_id], capture_output=True)
print("Container started (timeout reached - this is expected)")
return True
else:
print("Container stopped unexpectedly")
return False
else:
print(f"ERROR: Failed to start container: {result.stderr}")
return False
except Exception as e:
print(f"ERROR: Container test failed: {e}")
return False
def generate_cursor_config():
"""Generate Cursor configuration examples."""
print("\nGenerating Cursor configuration examples...")
# Get current environment variables
endpoint = os.getenv("GRAYLOG_ENDPOINT", "https://your-graylog-server:9000")
username = os.getenv("GRAYLOG_USERNAME", "your-username")
password = os.getenv("GRAYLOG_PASSWORD", "your-password")
print("Using Username/Password configuration")
# Generate Docker-based configuration
docker_config = {
"mcpServers": {
"graylog": {
"command": "docker",
"args": [
"run",
"--rm",
"-i",
"-e",
f"GRAYLOG_ENDPOINT={endpoint}",
"-e",
f"GRAYLOG_USERNAME={username}",
"-e",
f"GRAYLOG_PASSWORD={password}",
"-e",
"GRAYLOG_VERIFY_SSL=true",
"-e",
"GRAYLOG_TIMEOUT=30",
"mcp-graylog:latest",
],
"env": {},
}
}
}
print("Copy this configuration to Cursor settings:")
print(json.dumps(docker_config, indent=2))
return True
def main():
"""Main test function."""
print("Testing Cursor MCP Graylog Integration")
print("=" * 60)
# Run tests
env_ok = check_environment_variables()
docker_ok = check_docker_image()
container_ok = test_container_startup()
config_ok = generate_cursor_config()
# Summary
print("\nTest Summary:")
print(f"Environment Variables: {'PASS' if env_ok else 'FAIL'}")
print(f"Docker Image: {'PASS' if docker_ok else 'FAIL'}")
print(f"Container Test: {'PASS' if container_ok else 'FAIL'}")
print(f"Configuration: {'PASS' if config_ok else 'FAIL'}")
all_passed = all([env_ok, docker_ok, container_ok, config_ok])
if all_passed:
print("\nAll tests passed! Your setup is ready for Cursor integration.")
return 0
else:
print("\nSome tests failed. Please fix the issues above.")
return 1
if __name__ == "__main__":
sys.exit(main())