mcp-proxy-adapter 6.2.24__py3-none-any.whl → 6.2.25__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 (31) hide show
  1. mcp_proxy_adapter/api/app.py +0 -3
  2. mcp_proxy_adapter/api/middleware/protocol_middleware.py +10 -10
  3. mcp_proxy_adapter/commands/health_command.py +1 -1
  4. mcp_proxy_adapter/core/protocol_manager.py +9 -9
  5. mcp_proxy_adapter/examples/create_certificates_simple.py +7 -17
  6. mcp_proxy_adapter/examples/examples/basic_framework/__init__.py +9 -0
  7. mcp_proxy_adapter/examples/examples/basic_framework/commands/__init__.py +4 -0
  8. mcp_proxy_adapter/examples/examples/basic_framework/hooks/__init__.py +4 -0
  9. mcp_proxy_adapter/examples/examples/basic_framework/main.py +44 -0
  10. mcp_proxy_adapter/examples/examples/full_application/__init__.py +12 -0
  11. mcp_proxy_adapter/examples/examples/full_application/commands/__init__.py +7 -0
  12. mcp_proxy_adapter/examples/examples/full_application/commands/custom_echo_command.py +80 -0
  13. mcp_proxy_adapter/examples/examples/full_application/commands/dynamic_calculator_command.py +90 -0
  14. mcp_proxy_adapter/examples/examples/full_application/hooks/__init__.py +7 -0
  15. mcp_proxy_adapter/examples/examples/full_application/hooks/application_hooks.py +75 -0
  16. mcp_proxy_adapter/examples/examples/full_application/hooks/builtin_command_hooks.py +71 -0
  17. mcp_proxy_adapter/examples/examples/full_application/main.py +173 -0
  18. mcp_proxy_adapter/examples/examples/full_application/proxy_endpoints.py +154 -0
  19. mcp_proxy_adapter/examples/generate_test_configs.py +70 -33
  20. mcp_proxy_adapter/examples/run_full_test_suite.py +302 -109
  21. mcp_proxy_adapter/examples/run_security_tests.py +14 -5
  22. mcp_proxy_adapter/examples/scripts/config_generator.py +740 -0
  23. mcp_proxy_adapter/examples/scripts/create_certificates_simple.py +560 -0
  24. mcp_proxy_adapter/examples/scripts/generate_certificates_and_tokens.py +369 -0
  25. mcp_proxy_adapter/main.py +0 -2
  26. {mcp_proxy_adapter-6.2.24.dist-info → mcp_proxy_adapter-6.2.25.dist-info}/METADATA +1 -1
  27. {mcp_proxy_adapter-6.2.24.dist-info → mcp_proxy_adapter-6.2.25.dist-info}/RECORD +31 -15
  28. {mcp_proxy_adapter-6.2.24.dist-info → mcp_proxy_adapter-6.2.25.dist-info}/WHEEL +0 -0
  29. {mcp_proxy_adapter-6.2.24.dist-info → mcp_proxy_adapter-6.2.25.dist-info}/entry_points.txt +0 -0
  30. {mcp_proxy_adapter-6.2.24.dist-info → mcp_proxy_adapter-6.2.25.dist-info}/licenses/LICENSE +0 -0
  31. {mcp_proxy_adapter-6.2.24.dist-info → mcp_proxy_adapter-6.2.25.dist-info}/top_level.txt +0 -0
@@ -1,125 +1,318 @@
1
1
  #!/usr/bin/env python3
2
2
  """
3
- Full Test Suite Runner for MCP Proxy Adapter
4
- This script automatically runs the complete test suite:
5
- 1. Setup test environment
6
- 2. Generate configurations
7
- 3. Create certificates
8
- 4. Run security tests
9
-
10
3
  Author: Vasiliy Zdanovskiy
11
4
  email: vasilyvz@gmail.com
5
+ Full test suite runner for MCP Proxy Adapter.
6
+ Automates the complete testing workflow.
12
7
  """
8
+ import os
13
9
  import sys
14
10
  import subprocess
15
- import os
11
+ import time
16
12
  from pathlib import Path
13
+ from typing import List, Dict, Optional
17
14
 
18
-
19
- def run_command(cmd: list, description: str) -> bool:
20
- """Run a command and return success status."""
21
- try:
22
- print(f"\n🚀 {description}")
23
- print("=" * 60)
24
-
25
- # Change to script directory if running from package
26
- script_dir = Path(__file__).parent
27
- if script_dir.name == "examples":
28
- os.chdir(script_dir)
29
-
30
- result = subprocess.run(
31
- cmd,
32
- capture_output=False,
33
- text=True,
34
- check=True,
35
- cwd=script_dir
36
- )
37
- print(f"✅ {description} completed successfully")
38
- return True
39
- except subprocess.CalledProcessError as e:
40
- print(f" {description} failed:")
41
- print(f" Command: {' '.join(cmd)}")
42
- print(f" Error: {e.stderr}")
43
- return False
44
- except Exception as e:
45
- print(f"{description} failed: {e}")
46
- return False
47
-
48
-
49
- def main():
50
- """Run the complete test suite."""
51
- print("🧪 MCP Proxy Adapter - Full Test Suite")
52
- print("=" * 60)
53
-
54
- # Check if we're in the right directory
55
- current_dir = Path.cwd()
56
- if not (current_dir / "setup_test_environment.py").exists():
57
- print("❌ Please run this script from the examples directory")
58
- return 1
59
-
60
- success = True
61
-
62
- # 1. Setup test environment
63
- if not run_command([
64
- sys.executable, "-m", "mcp_proxy_adapter.examples.setup_test_environment",
65
- "--output-dir", "."
66
- ], "Setting up test environment"):
67
- success = False
68
-
69
- # 2. Generate configurations
70
- if success and not run_command([
71
- sys.executable, "-m", "mcp_proxy_adapter.examples.generate_test_configs",
72
- "--output-dir", "configs"
73
- ], "Generating test configurations"):
74
- success = False
75
-
76
- # 3. Create certificates
77
- if success and not run_command([
78
- sys.executable, "-m", "mcp_proxy_adapter.examples.create_certificates_simple"
79
- ], "Creating certificates"):
80
- success = False
81
-
82
- # 4. Copy roles.json to root directory
83
- if success:
84
- import shutil
85
- from pathlib import Path
86
- roles_file = Path("configs/roles.json")
87
- if roles_file.exists():
88
- shutil.copy2(roles_file, "roles.json")
89
- print("✅ Copied roles.json to root directory")
15
+ class FullTestSuiteRunner:
16
+ """Comprehensive test suite runner that automates the entire testing process."""
17
+
18
+ def __init__(self):
19
+ """Initialize the test suite runner."""
20
+ self.working_dir = Path.cwd()
21
+ self.configs_dir = self.working_dir / "configs"
22
+ self.certs_dir = self.working_dir / "certs"
23
+ self.keys_dir = self.working_dir / "keys"
24
+ self.roles_file = self.working_dir / "configs" / "roles.json"
25
+
26
+ def print_step(self, step: str, description: str):
27
+ """Print a formatted step header."""
28
+ print(f"\n{'='*60}")
29
+ print(f"🔧 STEP {step}: {description}")
30
+ print(f"{'='*60}")
31
+
32
+ def print_success(self, message: str):
33
+ """Print a success message."""
34
+ print(f"✅ {message}")
35
+
36
+ def print_error(self, message: str):
37
+ """Print an error message."""
38
+ print(f" {message}")
39
+
40
+ def print_info(self, message: str):
41
+ """Print an info message."""
42
+ print(f"ℹ️ {message}")
43
+
44
+ def check_environment(self) -> bool:
45
+ """Check if the environment is properly set up."""
46
+ self.print_step("1", "Environment Validation")
47
+
48
+ # Check if we're in a virtual environment
49
+ if not hasattr(sys, 'real_prefix') and not (hasattr(sys, 'base_prefix') and sys.base_prefix != sys.prefix):
50
+ self.print_error("Not running in a virtual environment!")
51
+ self.print_info("Please activate your virtual environment first:")
52
+ self.print_info(" source venv/bin/activate # or .venv/bin/activate")
53
+ return False
54
+
55
+ self.print_success("Virtual environment is active")
56
+
57
+ # Check if mcp_proxy_adapter is installed
58
+ try:
59
+ import mcp_proxy_adapter
60
+ self.print_success(f"mcp_proxy_adapter is installed (version: {mcp_proxy_adapter.__version__})")
61
+ except ImportError:
62
+ self.print_error("mcp_proxy_adapter is not installed!")
63
+ self.print_info("Please install it first:")
64
+ self.print_info(" pip install mcp_proxy_adapter")
65
+ return False
66
+
67
+ # Check Python version
68
+ python_version = sys.version_info
69
+ if python_version.major >= 3 and python_version.minor >= 8:
70
+ self.print_success(f"Python version: {python_version.major}.{python_version.minor}.{python_version.micro}")
90
71
  else:
91
- success = False
92
- print("❌ roles.json not found in configs directory")
72
+ self.print_error(f"Python {python_version.major}.{python_version.minor} is not supported. Need Python 3.8+")
73
+ return False
74
+
75
+ return True
76
+
77
+ def create_directories(self) -> bool:
78
+ """Create necessary directories for testing."""
79
+ self.print_step("2", "Directory Creation")
80
+
81
+ try:
82
+ # Create configs directory
83
+ self.configs_dir.mkdir(exist_ok=True)
84
+ self.print_success(f"Created/verified configs directory: {self.configs_dir}")
85
+
86
+ # Create certs directory
87
+ self.certs_dir.mkdir(exist_ok=True)
88
+ self.print_success(f"Created/verified certs directory: {self.certs_dir}")
89
+
90
+ # Create keys directory
91
+ self.keys_dir.mkdir(exist_ok=True)
92
+ self.print_success(f"Created/verified keys directory: {self.keys_dir}")
93
+
94
+ return True
95
+
96
+ except Exception as e:
97
+ self.print_error(f"Failed to create directories: {e}")
98
+ return False
99
+
100
+ def generate_certificates(self) -> bool:
101
+ """Generate SSL certificates for testing."""
102
+ self.print_step("3", "Certificate Generation")
103
+
104
+ try:
105
+ # Run certificate generation script
106
+ cmd = [sys.executable, "-m", "mcp_proxy_adapter.examples.create_certificates_simple"]
107
+ self.print_info("Running certificate generation script...")
108
+
109
+ result = subprocess.run(cmd, capture_output=True, text=True, cwd=self.working_dir)
110
+
111
+ if result.returncode == 0:
112
+ self.print_success("Certificates generated successfully")
113
+ if result.stdout:
114
+ print(result.stdout)
115
+ return True
116
+ else:
117
+ self.print_error("Certificate generation failed!")
118
+ if result.stderr:
119
+ print("Error output:")
120
+ print(result.stderr)
121
+ return False
122
+
123
+ except Exception as e:
124
+ self.print_error(f"Failed to generate certificates: {e}")
125
+ return False
126
+
127
+ def generate_configurations(self) -> bool:
128
+ """Generate test configurations."""
129
+ self.print_step("4", "Configuration Generation")
130
+
131
+ try:
132
+ # Run configuration generation script
133
+ cmd = [sys.executable, "-m", "mcp_proxy_adapter.examples.generate_test_configs"]
134
+ self.print_info("Running configuration generation script...")
135
+
136
+ result = subprocess.run(cmd, capture_output=True, text=True, cwd=self.working_dir)
137
+
138
+ if result.returncode == 0:
139
+ self.print_success("Configurations generated successfully")
140
+ if result.stdout:
141
+ print(result.stdout)
142
+ return True
143
+ else:
144
+ self.print_error("Configuration generation failed!")
145
+ if result.stderr:
146
+ print("Error output:")
147
+ print(result.stderr)
148
+ return False
149
+
150
+ except Exception as e:
151
+ self.print_error(f"Failed to generate configurations: {e}")
152
+ return False
153
+
154
+ def run_security_tests(self) -> bool:
155
+ """Run the security test suite."""
156
+ self.print_step("5", "Security Testing")
157
+
158
+ try:
159
+ # Run security tests
160
+ cmd = [sys.executable, "-m", "mcp_proxy_adapter.examples.run_security_tests", "--verbose"]
161
+ self.print_info("Running security tests...")
162
+
163
+ # Debug: show current working directory and check files
164
+ self.print_info(f"DEBUG: Current working directory: {os.getcwd()}")
165
+ self.print_info(f"DEBUG: Working directory from class: {self.working_dir}")
166
+
167
+ # Check if certificates exist before running tests
168
+ localhost_cert = self.certs_dir / "localhost_server.crt"
169
+ self.print_info(f"DEBUG: localhost_server.crt exists: {localhost_cert.exists()}")
170
+ if localhost_cert.exists():
171
+ self.print_info(f"DEBUG: localhost_server.crt is symlink: {localhost_cert.is_symlink()}")
172
+ if localhost_cert.is_symlink():
173
+ self.print_info(f"DEBUG: localhost_server.crt symlink target: {localhost_cert.readlink()}")
174
+
175
+ # List all files in certs directory
176
+ self.print_info("DEBUG: Files in certs directory:")
177
+ for file in self.certs_dir.iterdir():
178
+ self.print_info(f"DEBUG: {file.name} -> {file}")
179
+
180
+ result = subprocess.run(cmd, capture_output=True, text=True, cwd=self.working_dir)
181
+
182
+ if result.returncode == 0:
183
+ self.print_success("Security tests completed successfully!")
184
+ if result.stdout:
185
+ print(result.stdout)
186
+ return True
187
+ else:
188
+ self.print_error("Security tests failed!")
189
+ if result.stdout:
190
+ print("Test output:")
191
+ print(result.stdout)
192
+ if result.stderr:
193
+ print("Error output:")
194
+ print(result.stderr)
195
+ return False
196
+
197
+ except Exception as e:
198
+ self.print_error(f"Failed to run security tests: {e}")
199
+ return False
200
+
201
+ def cleanup(self):
202
+ """Clean up temporary files and processes."""
203
+ self.print_info("Cleaning up...")
204
+
205
+ # Simple cleanup - just print success message
206
+ # Process cleanup is handled by the test scripts themselves
207
+ print("✅ Cleanup completed")
208
+
93
209
 
94
- # 5. Run security tests
95
- if success and not run_command([
96
- sys.executable, "-m", "mcp_proxy_adapter.examples.run_security_tests"
97
- ], "Running security tests"):
98
- success = False
99
210
 
100
- # Final result
101
- print("\n" + "=" * 60)
102
- if success:
103
- print("🎉 FULL TEST SUITE COMPLETED SUCCESSFULLY!")
104
- print("=" * 60)
105
- print("\n📋 SUMMARY:")
106
- print("✅ Test environment setup")
107
- print("✅ Configuration generation")
108
- print("✅ Certificate creation")
109
- print("✅ Roles configuration")
110
- print("✅ Security testing")
111
- print("\n🚀 All systems are working correctly!")
112
- return 0
113
- else:
114
- print("❌ FULL TEST SUITE FAILED!")
211
+ def cleanup_directories(self) -> bool:
212
+ """Clean up existing test directories before starting."""
213
+ self.print_info("Cleaning up existing test directories...")
214
+
215
+ try:
216
+ import shutil
217
+
218
+ # Directories to clean
219
+ dirs_to_clean = [self.configs_dir, self.certs_dir, self.keys_dir]
220
+ files_to_clean = [self.working_dir / "roles.json"]
221
+
222
+ # Remove directories
223
+ for dir_path in dirs_to_clean:
224
+ if dir_path.exists():
225
+ shutil.rmtree(dir_path)
226
+ print(f"🗑️ Removed directory: {dir_path}")
227
+
228
+ # Remove files
229
+ for file_path in files_to_clean:
230
+ if file_path.exists():
231
+ file_path.unlink()
232
+ print(f"🗑️ Removed file: {file_path}")
233
+
234
+ self.print_success("Directory cleanup completed")
235
+ return True
236
+
237
+ except Exception as e:
238
+ self.print_error(f"Failed to cleanup directories: {e}")
239
+ return False
240
+
241
+ def run_full_suite(self) -> bool:
242
+ """Run the complete test suite."""
243
+ print("🚀 MCP Proxy Adapter - Full Test Suite")
115
244
  print("=" * 60)
116
- print("\n🔧 TROUBLESHOOTING:")
117
- print("1. Check the error messages above")
118
- print("2. Ensure you have write permissions")
119
- print("3. Make sure ports 20000-20010 are free")
120
- print("4. Check if mcp_security_framework is installed")
121
- return 1
245
+ print(f"Working directory: {self.working_dir}")
246
+ print(f"Python executable: {sys.executable}")
247
+
248
+ try:
249
+ # Step 0: Clean up existing directories
250
+ if not self.cleanup_directories():
251
+ return False
252
+
253
+ # Step 1: Environment validation
254
+ if not self.check_environment():
255
+ return False
256
+
257
+ # Step 2: Directory creation
258
+ if not self.create_directories():
259
+ return False
260
+
261
+ # Step 3: Certificate generation
262
+ if not self.generate_certificates():
263
+ return False
264
+
265
+ # Step 4: Configuration generation
266
+ if not self.generate_configurations():
267
+ return False
268
+
269
+ # Step 5: Security testing
270
+ if not self.run_security_tests():
271
+ return False
272
+
273
+ # All steps completed successfully
274
+ print(f"\n{'='*60}")
275
+ print("🎉 FULL TEST SUITE COMPLETED SUCCESSFULLY!")
276
+ print("="*60)
277
+ print("✅ Environment validated")
278
+ print("✅ Directories cleaned")
279
+ print("✅ Directories created")
280
+ print("✅ Certificates generated")
281
+ print("✅ Configurations generated")
282
+ print("✅ Security tests passed")
283
+ print(f"\n📁 Test artifacts created in: {self.working_dir}")
284
+ print(f"📁 Configurations: {self.configs_dir}")
285
+ print(f"📁 Certificates: {self.certs_dir}")
286
+ print(f"📁 Keys: {self.keys_dir}")
287
+
288
+ return True
289
+
290
+ except KeyboardInterrupt:
291
+ print("\n\n⚠️ Test suite interrupted by user")
292
+ return False
293
+ except Exception as e:
294
+ self.print_error(f"Unexpected error during test suite execution: {e}")
295
+ return False
296
+ finally:
297
+ try:
298
+ self.print_info("Starting cleanup in finally block...")
299
+ self.cleanup()
300
+ self.print_info("Cleanup in finally block completed")
301
+ except Exception as e:
302
+ self.print_error(f"Cleanup failed in finally block: {e}")
303
+ import traceback
304
+ traceback.print_exc()
122
305
 
306
+ def main():
307
+ """Main entry point."""
308
+ runner = FullTestSuiteRunner()
309
+
310
+ try:
311
+ success = runner.run_full_suite()
312
+ sys.exit(0 if success else 1)
313
+ except Exception as e:
314
+ print(f"❌ Fatal error: {e}")
315
+ sys.exit(1)
123
316
 
124
317
  if __name__ == "__main__":
125
- exit(main())
318
+ main()
@@ -81,11 +81,15 @@ class SecurityTestRunner:
81
81
  def _pids_on_port(self, port: int) -> List[int]:
82
82
  pids: List[int] = []
83
83
  try:
84
- for proc in psutil.process_iter(attrs=["pid", "connections"]):
85
- for c in proc.connections(kind="inet"):
86
- if c.laddr and c.laddr.port == port:
87
- pids.append(proc.pid)
88
- break
84
+ for proc in psutil.process_iter(attrs=["pid"]):
85
+ try:
86
+ connections = proc.connections(kind="inet")
87
+ for c in connections:
88
+ if c.laddr and c.laddr.port == port:
89
+ pids.append(proc.pid)
90
+ break
91
+ except (psutil.NoSuchProcess, psutil.AccessDenied):
92
+ pass
89
93
  except Exception:
90
94
  pass
91
95
  return list(set(pids))
@@ -187,7 +191,12 @@ class SecurityTestRunner:
187
191
  "certs/localhost_server.crt",
188
192
  "keys/localhost_server.key"
189
193
  ]
194
+
190
195
  missing_certs = []
196
+ # Check if roles.json exists
197
+ roles_file = "configs/roles.json"
198
+ if not os.path.exists(roles_file):
199
+ missing_certs.append(f"Missing roles file: {roles_file}")
191
200
  for cert_file in cert_files:
192
201
  if not Path(cert_file).exists():
193
202
  missing_certs.append(cert_file)