mcp-proxy-adapter 6.1.1__py3-none-any.whl → 6.2.0__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.
- mcp_proxy_adapter/__main__.py +27 -7
- mcp_proxy_adapter/api/app.py +18 -7
- mcp_proxy_adapter/commands/ssl_setup_command.py +234 -351
- mcp_proxy_adapter/core/app_factory.py +87 -3
- mcp_proxy_adapter/core/app_runner.py +272 -0
- mcp_proxy_adapter/core/certificate_utils.py +291 -73
- mcp_proxy_adapter/core/client.py +574 -0
- mcp_proxy_adapter/core/client_manager.py +284 -0
- mcp_proxy_adapter/core/server_adapter.py +17 -80
- mcp_proxy_adapter/core/server_engine.py +5 -99
- mcp_proxy_adapter/core/ssl_utils.py +13 -12
- mcp_proxy_adapter/core/transport_manager.py +5 -5
- mcp_proxy_adapter/examples/__init__.py +16 -0
- mcp_proxy_adapter/examples/basic_framework/__init__.py +7 -0
- mcp_proxy_adapter/examples/basic_framework/commands/__init__.py +4 -0
- mcp_proxy_adapter/examples/basic_framework/hooks/__init__.py +4 -0
- mcp_proxy_adapter/examples/basic_framework/main.py +21 -40
- mcp_proxy_adapter/examples/commands/__init__.py +5 -1
- mcp_proxy_adapter/examples/create_certificates_simple.py +260 -75
- mcp_proxy_adapter/examples/debug_request_state.py +4 -36
- mcp_proxy_adapter/examples/debug_role_chain.py +2 -49
- mcp_proxy_adapter/examples/demo_client.py +0 -66
- mcp_proxy_adapter/examples/full_application/__init__.py +11 -0
- mcp_proxy_adapter/examples/full_application/commands/__init__.py +7 -0
- mcp_proxy_adapter/examples/full_application/commands/custom_echo_command.py +0 -19
- mcp_proxy_adapter/examples/full_application/commands/dynamic_calculator_command.py +0 -16
- mcp_proxy_adapter/examples/full_application/hooks/__init__.py +7 -0
- mcp_proxy_adapter/examples/full_application/hooks/application_hooks.py +0 -22
- mcp_proxy_adapter/examples/full_application/hooks/builtin_command_hooks.py +0 -24
- mcp_proxy_adapter/examples/full_application/main.py +65 -44
- mcp_proxy_adapter/examples/full_application/proxy_endpoints.py +154 -0
- mcp_proxy_adapter/examples/generate_all_certificates.py +0 -67
- mcp_proxy_adapter/examples/generate_certificates.py +0 -15
- mcp_proxy_adapter/examples/generate_certificates_and_tokens.py +369 -0
- mcp_proxy_adapter/examples/generate_test_configs.py +204 -0
- mcp_proxy_adapter/examples/proxy_registration_example.py +3 -70
- mcp_proxy_adapter/examples/run_example.py +1 -23
- mcp_proxy_adapter/examples/run_security_tests.py +2 -60
- mcp_proxy_adapter/examples/run_security_tests_fixed.py +0 -53
- mcp_proxy_adapter/examples/security_test_client.py +18 -123
- mcp_proxy_adapter/examples/setup_test_environment.py +179 -0
- mcp_proxy_adapter/examples/test_config.py +148 -0
- mcp_proxy_adapter/examples/test_config_generator.py +1 -25
- mcp_proxy_adapter/examples/test_examples.py +4 -67
- mcp_proxy_adapter/examples/universal_client.py +154 -162
- mcp_proxy_adapter/main.py +51 -161
- mcp_proxy_adapter/version.py +1 -1
- mcp_proxy_adapter-6.2.0.dist-info/METADATA +687 -0
- mcp_proxy_adapter-6.2.0.dist-info/RECORD +122 -0
- mcp_proxy_adapter/docs/EN/TROUBLESHOOTING.md +0 -285
- mcp_proxy_adapter/docs/RU/TROUBLESHOOTING.md +0 -285
- mcp_proxy_adapter/examples/README.md +0 -257
- mcp_proxy_adapter/examples/README_EN.md +0 -258
- mcp_proxy_adapter/examples/SECURITY_TESTING.md +0 -455
- mcp_proxy_adapter/examples/basic_framework/configs/http_auth.json +0 -37
- mcp_proxy_adapter/examples/basic_framework/configs/http_simple.json +0 -23
- mcp_proxy_adapter/examples/basic_framework/configs/https_auth.json +0 -43
- mcp_proxy_adapter/examples/basic_framework/configs/https_no_protocol_middleware.json +0 -36
- mcp_proxy_adapter/examples/basic_framework/configs/https_simple.json +0 -29
- mcp_proxy_adapter/examples/basic_framework/configs/mtls_no_protocol_middleware.json +0 -34
- mcp_proxy_adapter/examples/basic_framework/configs/mtls_no_roles.json +0 -39
- mcp_proxy_adapter/examples/basic_framework/configs/mtls_simple.json +0 -35
- mcp_proxy_adapter/examples/basic_framework/configs/mtls_with_roles.json +0 -45
- mcp_proxy_adapter/examples/basic_framework/roles.json +0 -21
- mcp_proxy_adapter/examples/cert_config.json +0 -9
- mcp_proxy_adapter/examples/certs/admin.crt +0 -32
- mcp_proxy_adapter/examples/certs/admin.key +0 -52
- mcp_proxy_adapter/examples/certs/admin_cert.pem +0 -21
- mcp_proxy_adapter/examples/certs/admin_key.pem +0 -28
- mcp_proxy_adapter/examples/certs/ca_cert.pem +0 -23
- mcp_proxy_adapter/examples/certs/ca_cert.srl +0 -1
- mcp_proxy_adapter/examples/certs/ca_key.pem +0 -28
- mcp_proxy_adapter/examples/certs/cert_config.json +0 -9
- mcp_proxy_adapter/examples/certs/client.crt +0 -32
- mcp_proxy_adapter/examples/certs/client.key +0 -52
- mcp_proxy_adapter/examples/certs/client_admin.crt +0 -32
- mcp_proxy_adapter/examples/certs/client_admin.key +0 -52
- mcp_proxy_adapter/examples/certs/client_user.crt +0 -32
- mcp_proxy_adapter/examples/certs/client_user.key +0 -52
- mcp_proxy_adapter/examples/certs/guest_cert.pem +0 -21
- mcp_proxy_adapter/examples/certs/guest_key.pem +0 -28
- mcp_proxy_adapter/examples/certs/mcp_proxy_adapter_ca_ca.crt +0 -23
- mcp_proxy_adapter/examples/certs/proxy_cert.pem +0 -21
- mcp_proxy_adapter/examples/certs/proxy_key.pem +0 -28
- mcp_proxy_adapter/examples/certs/readonly.crt +0 -32
- mcp_proxy_adapter/examples/certs/readonly.key +0 -52
- mcp_proxy_adapter/examples/certs/readonly_cert.pem +0 -21
- mcp_proxy_adapter/examples/certs/readonly_key.pem +0 -28
- mcp_proxy_adapter/examples/certs/server.crt +0 -32
- mcp_proxy_adapter/examples/certs/server.key +0 -52
- mcp_proxy_adapter/examples/certs/server_cert.pem +0 -32
- mcp_proxy_adapter/examples/certs/server_key.pem +0 -52
- mcp_proxy_adapter/examples/certs/test_ca_ca.crt +0 -20
- mcp_proxy_adapter/examples/certs/user.crt +0 -32
- mcp_proxy_adapter/examples/certs/user.key +0 -52
- mcp_proxy_adapter/examples/certs/user_cert.pem +0 -21
- mcp_proxy_adapter/examples/certs/user_key.pem +0 -28
- mcp_proxy_adapter/examples/client_configs/api_key_client.json +0 -13
- mcp_proxy_adapter/examples/client_configs/basic_auth_client.json +0 -13
- mcp_proxy_adapter/examples/client_configs/certificate_client.json +0 -22
- mcp_proxy_adapter/examples/client_configs/jwt_client.json +0 -15
- mcp_proxy_adapter/examples/client_configs/no_auth_client.json +0 -9
- mcp_proxy_adapter/examples/full_application/configs/http_auth.json +0 -37
- mcp_proxy_adapter/examples/full_application/configs/http_simple.json +0 -23
- mcp_proxy_adapter/examples/full_application/configs/https_auth.json +0 -39
- mcp_proxy_adapter/examples/full_application/configs/https_simple.json +0 -25
- mcp_proxy_adapter/examples/full_application/configs/mtls_no_roles.json +0 -39
- mcp_proxy_adapter/examples/full_application/configs/mtls_with_roles.json +0 -45
- mcp_proxy_adapter/examples/full_application/roles.json +0 -21
- mcp_proxy_adapter/examples/keys/ca_key.pem +0 -28
- mcp_proxy_adapter/examples/keys/mcp_proxy_adapter_ca_ca.key +0 -28
- mcp_proxy_adapter/examples/keys/test_ca_ca.key +0 -28
- mcp_proxy_adapter/examples/logs/mcp_proxy_adapter.log +0 -220
- mcp_proxy_adapter/examples/logs/mcp_proxy_adapter.log.1 +0 -1
- mcp_proxy_adapter/examples/logs/mcp_proxy_adapter.log.2 +0 -1
- mcp_proxy_adapter/examples/logs/mcp_proxy_adapter.log.3 +0 -1
- mcp_proxy_adapter/examples/logs/mcp_proxy_adapter.log.4 +0 -1
- mcp_proxy_adapter/examples/logs/mcp_proxy_adapter.log.5 +0 -1
- mcp_proxy_adapter/examples/logs/mcp_proxy_adapter_access.log +0 -220
- mcp_proxy_adapter/examples/logs/mcp_proxy_adapter_access.log.1 +0 -1
- mcp_proxy_adapter/examples/logs/mcp_proxy_adapter_access.log.2 +0 -1
- mcp_proxy_adapter/examples/logs/mcp_proxy_adapter_access.log.3 +0 -1
- mcp_proxy_adapter/examples/logs/mcp_proxy_adapter_access.log.4 +0 -1
- mcp_proxy_adapter/examples/logs/mcp_proxy_adapter_access.log.5 +0 -1
- mcp_proxy_adapter/examples/logs/mcp_proxy_adapter_error.log +0 -2
- mcp_proxy_adapter/examples/logs/mcp_proxy_adapter_error.log.1 +0 -1
- mcp_proxy_adapter/examples/logs/mcp_proxy_adapter_error.log.2 +0 -1
- mcp_proxy_adapter/examples/logs/mcp_proxy_adapter_error.log.3 +0 -1
- mcp_proxy_adapter/examples/logs/mcp_proxy_adapter_error.log.4 +0 -1
- mcp_proxy_adapter/examples/logs/mcp_proxy_adapter_error.log.5 +0 -1
- mcp_proxy_adapter/examples/roles.json +0 -38
- mcp_proxy_adapter/examples/server_configs/config_basic_http.json +0 -204
- mcp_proxy_adapter/examples/server_configs/config_http_token.json +0 -238
- mcp_proxy_adapter/examples/server_configs/config_https.json +0 -215
- mcp_proxy_adapter/examples/server_configs/config_https_token.json +0 -231
- mcp_proxy_adapter/examples/server_configs/config_mtls.json +0 -215
- mcp_proxy_adapter/examples/server_configs/config_proxy_registration.json +0 -250
- mcp_proxy_adapter/examples/server_configs/config_simple.json +0 -46
- mcp_proxy_adapter/examples/server_configs/roles.json +0 -38
- mcp_proxy_adapter-6.1.1.dist-info/METADATA +0 -205
- mcp_proxy_adapter-6.1.1.dist-info/RECORD +0 -197
- {mcp_proxy_adapter-6.1.1.dist-info → mcp_proxy_adapter-6.2.0.dist-info}/WHEEL +0 -0
- {mcp_proxy_adapter-6.1.1.dist-info → mcp_proxy_adapter-6.2.0.dist-info}/entry_points.txt +0 -0
- {mcp_proxy_adapter-6.1.1.dist-info → mcp_proxy_adapter-6.2.0.dist-info}/licenses/LICENSE +0 -0
- {mcp_proxy_adapter-6.1.1.dist-info → mcp_proxy_adapter-6.2.0.dist-info}/top_level.txt +0 -0
@@ -0,0 +1,179 @@
|
|
1
|
+
#!/usr/bin/env python3
|
2
|
+
"""
|
3
|
+
Author: Vasiliy Zdanovskiy
|
4
|
+
email: vasilyvz@gmail.com
|
5
|
+
Script for setting up test environment for MCP Proxy Adapter.
|
6
|
+
Prepares the test environment with all necessary files and directories.
|
7
|
+
Uses mcp_security_framework for certificate generation.
|
8
|
+
"""
|
9
|
+
import os
|
10
|
+
import shutil
|
11
|
+
import sys
|
12
|
+
from pathlib import Path
|
13
|
+
# Import mcp_security_framework
|
14
|
+
try:
|
15
|
+
from mcp_security_framework.core.cert_manager import CertificateManager
|
16
|
+
from mcp_security_framework.schemas.config import CertificateConfig, CAConfig, ServerCertConfig, ClientCertConfig
|
17
|
+
from mcp_security_framework.schemas.models import CertificateType
|
18
|
+
SECURITY_FRAMEWORK_AVAILABLE = True
|
19
|
+
except ImportError:
|
20
|
+
SECURITY_FRAMEWORK_AVAILABLE = False
|
21
|
+
print("Warning: mcp_security_framework not available")
|
22
|
+
def setup_test_environment():
|
23
|
+
"""
|
24
|
+
Setup test environment with all necessary files and directories.
|
25
|
+
"""
|
26
|
+
print("🔧 Setting up test environment...")
|
27
|
+
# Create test environment directory structure
|
28
|
+
directories = [
|
29
|
+
"examples/basic_framework",
|
30
|
+
"examples/full_application",
|
31
|
+
"scripts",
|
32
|
+
"configs",
|
33
|
+
"certs",
|
34
|
+
"keys",
|
35
|
+
"tokens",
|
36
|
+
"logs"
|
37
|
+
]
|
38
|
+
for directory in directories:
|
39
|
+
os.makedirs(directory, exist_ok=True)
|
40
|
+
print(f"✅ Created directory: {directory}")
|
41
|
+
# Copy example files
|
42
|
+
source_examples = "../mcp_proxy_adapter/examples"
|
43
|
+
if os.path.exists(source_examples):
|
44
|
+
# Copy basic framework
|
45
|
+
basic_framework_src = os.path.join(source_examples, "basic_framework")
|
46
|
+
if os.path.exists(basic_framework_src):
|
47
|
+
shutil.copytree(basic_framework_src, "examples/basic_framework", dirs_exist_ok=True)
|
48
|
+
print("✅ Copied basic_framework examples")
|
49
|
+
# Copy full application
|
50
|
+
full_application_src = os.path.join(source_examples, "full_application")
|
51
|
+
if os.path.exists(full_application_src):
|
52
|
+
shutil.copytree(full_application_src, "examples/full_application", dirs_exist_ok=True)
|
53
|
+
print("✅ Copied full_application examples")
|
54
|
+
# Copy utility scripts
|
55
|
+
source_utils = "../mcp_proxy_adapter/utils"
|
56
|
+
if os.path.exists(source_utils):
|
57
|
+
config_generator_src = os.path.join(source_utils, "config_generator.py")
|
58
|
+
if os.path.exists(config_generator_src):
|
59
|
+
shutil.copy2(config_generator_src, "scripts/")
|
60
|
+
print("✅ Copied config_generator.py")
|
61
|
+
# Copy certificate generation script
|
62
|
+
source_examples = "../mcp_proxy_adapter/examples"
|
63
|
+
if os.path.exists(source_examples):
|
64
|
+
cert_script_src = os.path.join(source_examples, "create_certificates_simple.py")
|
65
|
+
if os.path.exists(cert_script_src):
|
66
|
+
shutil.copy2(cert_script_src, "scripts/")
|
67
|
+
print("✅ Copied create_certificates_simple.py")
|
68
|
+
# Copy new certificate generation script
|
69
|
+
cert_tokens_src = os.path.join(source_examples, "generate_certificates_and_tokens.py")
|
70
|
+
if os.path.exists(cert_tokens_src):
|
71
|
+
shutil.copy2(cert_tokens_src, "scripts/")
|
72
|
+
print("✅ Copied generate_certificates_and_tokens.py")
|
73
|
+
print("🎉 Test environment setup completed successfully!")
|
74
|
+
def generate_certificates_with_framework():
|
75
|
+
"""
|
76
|
+
Generate certificates using mcp_security_framework.
|
77
|
+
"""
|
78
|
+
if not SECURITY_FRAMEWORK_AVAILABLE:
|
79
|
+
print("❌ mcp_security_framework not available for certificate generation")
|
80
|
+
return False
|
81
|
+
try:
|
82
|
+
print("🔐 Generating certificates using mcp_security_framework...")
|
83
|
+
# Configure certificate manager
|
84
|
+
cert_config = CertificateConfig(
|
85
|
+
cert_storage_path="./certs",
|
86
|
+
key_storage_path="./keys",
|
87
|
+
default_validity_days=365,
|
88
|
+
key_size=2048,
|
89
|
+
hash_algorithm="sha256"
|
90
|
+
)
|
91
|
+
cert_manager = CertificateManager(cert_config)
|
92
|
+
# Generate CA certificate
|
93
|
+
ca_config = CAConfig(
|
94
|
+
common_name="MCP Proxy Adapter Test CA",
|
95
|
+
organization="Test Organization",
|
96
|
+
organizational_unit="Certificate Authority",
|
97
|
+
country="US",
|
98
|
+
state="Test State",
|
99
|
+
locality="Test City",
|
100
|
+
validity_years=10, # Используем validity_years вместо validity_days
|
101
|
+
key_size=2048,
|
102
|
+
hash_algorithm="sha256"
|
103
|
+
)
|
104
|
+
cert_pair = cert_manager.create_root_ca(ca_config)
|
105
|
+
if not cert_pair or not cert_pair.certificate_path:
|
106
|
+
print(f"❌ Failed to create CA certificate: Invalid certificate pair")
|
107
|
+
return False
|
108
|
+
print("✅ CA certificate created successfully")
|
109
|
+
# Find CA key file
|
110
|
+
ca_key_path = cert_pair.private_key_path
|
111
|
+
# Generate server certificate
|
112
|
+
server_config = ServerCertConfig(
|
113
|
+
common_name="localhost",
|
114
|
+
organization="Test Organization",
|
115
|
+
organizational_unit="Server",
|
116
|
+
country="US",
|
117
|
+
state="Test State",
|
118
|
+
locality="Test City",
|
119
|
+
validity_days=365,
|
120
|
+
key_size=2048,
|
121
|
+
hash_algorithm="sha256",
|
122
|
+
subject_alt_names=["localhost", "127.0.0.1"], # Используем subject_alt_names вместо san_dns
|
123
|
+
ca_cert_path=cert_pair.certificate_path,
|
124
|
+
ca_key_path=ca_key_path
|
125
|
+
)
|
126
|
+
cert_pair = cert_manager.create_server_certificate(server_config)
|
127
|
+
if not cert_pair or not cert_pair.certificate_path:
|
128
|
+
print(f"❌ Failed to create server certificate: Invalid certificate pair")
|
129
|
+
return False
|
130
|
+
print("✅ Server certificate created successfully")
|
131
|
+
# Generate client certificates
|
132
|
+
client_configs = [
|
133
|
+
("admin", ["admin"], ["read", "write", "execute", "delete", "admin", "register", "unregister", "heartbeat", "discover"]),
|
134
|
+
("user", ["user"], ["read", "execute", "register", "unregister", "heartbeat", "discover"]),
|
135
|
+
("readonly", ["readonly"], ["read", "discover"]),
|
136
|
+
("guest", ["guest"], ["read", "discover"]),
|
137
|
+
("proxy", ["proxy"], ["register", "unregister", "heartbeat", "discover"])
|
138
|
+
]
|
139
|
+
for client_name, roles, permissions in client_configs:
|
140
|
+
client_config = ClientCertConfig(
|
141
|
+
common_name=f"{client_name}-client",
|
142
|
+
organization="Test Organization",
|
143
|
+
organizational_unit="Client",
|
144
|
+
country="US",
|
145
|
+
state="Test State",
|
146
|
+
locality="Test City",
|
147
|
+
validity_days=730,
|
148
|
+
key_size=2048,
|
149
|
+
hash_algorithm="sha256",
|
150
|
+
roles=roles,
|
151
|
+
permissions=permissions,
|
152
|
+
ca_cert_path=cert_pair.certificate_path,
|
153
|
+
ca_key_path=ca_key_path
|
154
|
+
)
|
155
|
+
cert_pair = cert_manager.create_client_certificate(client_config)
|
156
|
+
if not cert_pair or not cert_pair.certificate_path:
|
157
|
+
print(f"❌ Failed to create client certificate {client_name}: Invalid certificate pair")
|
158
|
+
return False
|
159
|
+
print(f"✅ Client certificate {client_name} created successfully")
|
160
|
+
print("🎉 All certificates generated successfully using mcp_security_framework!")
|
161
|
+
return True
|
162
|
+
except Exception as e:
|
163
|
+
print(f"❌ Error generating certificates with framework: {e}")
|
164
|
+
return False
|
165
|
+
def main():
|
166
|
+
"""Main function for command line execution."""
|
167
|
+
try:
|
168
|
+
setup_test_environment()
|
169
|
+
# Generate certificates if framework is available
|
170
|
+
if SECURITY_FRAMEWORK_AVAILABLE:
|
171
|
+
generate_certificates_with_framework()
|
172
|
+
else:
|
173
|
+
print("⚠️ Skipping certificate generation (mcp_security_framework not available)")
|
174
|
+
except Exception as e:
|
175
|
+
print(f"❌ Error setting up test environment: {e}", file=sys.stderr)
|
176
|
+
return 1
|
177
|
+
return 0
|
178
|
+
if __name__ == "__main__":
|
179
|
+
exit(main())
|
@@ -0,0 +1,148 @@
|
|
1
|
+
#!/usr/bin/env python3
|
2
|
+
"""
|
3
|
+
Author: Vasiliy Zdanovskiy
|
4
|
+
email: vasilyvz@gmail.com
|
5
|
+
Script for testing MCP Proxy Adapter configurations.
|
6
|
+
Tests a specific configuration by creating an application and validating it.
|
7
|
+
Uses mcp_security_framework for security validation.
|
8
|
+
"""
|
9
|
+
import json
|
10
|
+
import os
|
11
|
+
import sys
|
12
|
+
import argparse
|
13
|
+
import time
|
14
|
+
import subprocess
|
15
|
+
from pathlib import Path
|
16
|
+
from typing import Dict, Any, Optional
|
17
|
+
# Import mcp_security_framework
|
18
|
+
try:
|
19
|
+
from mcp_security_framework import SecurityManager
|
20
|
+
from mcp_security_framework.schemas.config import SecurityConfig
|
21
|
+
SECURITY_FRAMEWORK_AVAILABLE = True
|
22
|
+
except ImportError:
|
23
|
+
SECURITY_FRAMEWORK_AVAILABLE = False
|
24
|
+
print("Warning: mcp_security_framework not available")
|
25
|
+
# Add parent directory to path to import mcp_proxy_adapter
|
26
|
+
sys.path.insert(0, os.path.join(os.path.dirname(__file__), "../.."))
|
27
|
+
def validate_security_config(config: Dict[str, Any]) -> bool:
|
28
|
+
"""
|
29
|
+
Validate security configuration using mcp_security_framework.
|
30
|
+
Args:
|
31
|
+
config: Configuration dictionary
|
32
|
+
Returns:
|
33
|
+
True if validation passed, False otherwise
|
34
|
+
"""
|
35
|
+
if not SECURITY_FRAMEWORK_AVAILABLE:
|
36
|
+
print("⚠️ Skipping security validation (mcp_security_framework not available)")
|
37
|
+
return True
|
38
|
+
try:
|
39
|
+
security_section = config.get("security", {})
|
40
|
+
if not security_section.get("enabled", False):
|
41
|
+
print("🔓 Security framework disabled in configuration")
|
42
|
+
return True
|
43
|
+
print("🔒 Validating security configuration with mcp_security_framework...")
|
44
|
+
# Create SecurityConfig from configuration
|
45
|
+
security_config = SecurityConfig(
|
46
|
+
auth=security_section.get("auth", {}),
|
47
|
+
ssl=security_section.get("ssl", {}),
|
48
|
+
permissions=security_section.get("permissions", {}),
|
49
|
+
rate_limit=security_section.get("rate_limit", {})
|
50
|
+
)
|
51
|
+
# Create SecurityManager for validation
|
52
|
+
security_manager = SecurityManager(security_config)
|
53
|
+
# Validate configuration
|
54
|
+
validation_result = security_manager.validate_configuration()
|
55
|
+
if validation_result.is_valid:
|
56
|
+
print("✅ Security configuration validation passed")
|
57
|
+
return True
|
58
|
+
else:
|
59
|
+
print("❌ Security configuration validation failed:")
|
60
|
+
for error in validation_result.errors:
|
61
|
+
print(f" - {error}")
|
62
|
+
return False
|
63
|
+
except Exception as e:
|
64
|
+
print(f"❌ Error validating security configuration: {e}")
|
65
|
+
return False
|
66
|
+
def test_configuration(config_path: str, timeout: int = 30) -> bool:
|
67
|
+
"""
|
68
|
+
Test a configuration by creating an application and validating it.
|
69
|
+
Args:
|
70
|
+
config_path: Path to configuration file
|
71
|
+
timeout: Timeout in seconds for server startup
|
72
|
+
Returns:
|
73
|
+
True if test passed, False otherwise
|
74
|
+
"""
|
75
|
+
print(f"🧪 Testing configuration: {config_path}")
|
76
|
+
print("=" * 60)
|
77
|
+
try:
|
78
|
+
# Load configuration
|
79
|
+
with open(config_path, 'r') as f:
|
80
|
+
config = json.load(f)
|
81
|
+
# Import required modules
|
82
|
+
from mcp_proxy_adapter.core.app_factory import create_application
|
83
|
+
from mcp_proxy_adapter.core.app_runner import ApplicationRunner
|
84
|
+
# Create application
|
85
|
+
print("🔧 Creating application...")
|
86
|
+
app = create_application(config)
|
87
|
+
print("✅ Application created successfully")
|
88
|
+
# Create runner and validate configuration
|
89
|
+
print("🔍 Validating configuration...")
|
90
|
+
runner = ApplicationRunner(app, config)
|
91
|
+
errors = runner.validate_configuration()
|
92
|
+
if errors:
|
93
|
+
print("❌ Configuration validation failed:")
|
94
|
+
for error in errors:
|
95
|
+
print(f" - {error}")
|
96
|
+
return False
|
97
|
+
print("✅ Configuration validation passed")
|
98
|
+
# Validate security configuration
|
99
|
+
if not validate_security_config(config):
|
100
|
+
return False
|
101
|
+
# Test server startup (without actually starting)
|
102
|
+
print("🚀 Testing server startup...")
|
103
|
+
server_config = config.get("server", {})
|
104
|
+
host = server_config.get("host", "127.0.0.1")
|
105
|
+
port = server_config.get("port", 8000)
|
106
|
+
print(f"✅ Server configuration: {host}:{port}")
|
107
|
+
# Test SSL configuration if enabled
|
108
|
+
ssl_config = config.get("ssl", {})
|
109
|
+
if ssl_config.get("enabled", False):
|
110
|
+
print("🔐 SSL configuration:")
|
111
|
+
print(f" - Certificate: {ssl_config.get('cert_file', 'N/A')}")
|
112
|
+
print(f" - Key: {ssl_config.get('key_file', 'N/A')}")
|
113
|
+
print(f" - Client verification: {ssl_config.get('verify_client', False)}")
|
114
|
+
# Test security configuration if enabled
|
115
|
+
security_config = config.get("security", {})
|
116
|
+
if security_config.get("enabled", False):
|
117
|
+
print("🔒 Security configuration:")
|
118
|
+
auth_config = security_config.get("auth", {})
|
119
|
+
if auth_config.get("enabled", False):
|
120
|
+
methods = auth_config.get("methods", [])
|
121
|
+
print(f" - Authentication methods: {methods}")
|
122
|
+
permissions_config = security_config.get("permissions", {})
|
123
|
+
if permissions_config.get("enabled", False):
|
124
|
+
print(f" - Roles file: {permissions_config.get('roles_file', 'N/A')}")
|
125
|
+
# Test protocol configuration
|
126
|
+
protocols_config = config.get("protocols", {})
|
127
|
+
if protocols_config.get("enabled", False):
|
128
|
+
allowed_protocols = protocols_config.get("allowed_protocols", [])
|
129
|
+
print(f"🌐 Allowed protocols: {allowed_protocols}")
|
130
|
+
print("=" * 60)
|
131
|
+
print("✅ Configuration test completed successfully!")
|
132
|
+
return True
|
133
|
+
except Exception as e:
|
134
|
+
print(f"❌ Configuration test failed: {e}")
|
135
|
+
return False
|
136
|
+
def main():
|
137
|
+
"""Main function for command line execution."""
|
138
|
+
parser = argparse.ArgumentParser(description="Test MCP Proxy Adapter configuration")
|
139
|
+
parser.add_argument("--config", "-c", required=True, help="Path to configuration file")
|
140
|
+
parser.add_argument("--timeout", "-t", type=int, default=30, help="Timeout in seconds")
|
141
|
+
args = parser.parse_args()
|
142
|
+
if not os.path.exists(args.config):
|
143
|
+
print(f"❌ Configuration file not found: {args.config}")
|
144
|
+
return 1
|
145
|
+
success = test_configuration(args.config, args.timeout)
|
146
|
+
return 0 if success else 1
|
147
|
+
if __name__ == "__main__":
|
148
|
+
exit(main())
|
@@ -1,48 +1,37 @@
|
|
1
1
|
#!/usr/bin/env python3
|
2
2
|
"""
|
3
3
|
Test script for configuration generator utility.
|
4
|
-
|
5
4
|
This script tests the configuration generator to ensure it properly generates
|
6
5
|
configurations with the new protocols section and fixes for ProtocolMiddleware issues.
|
7
6
|
"""
|
8
|
-
|
9
7
|
import sys
|
10
8
|
import json
|
11
9
|
from pathlib import Path
|
12
|
-
|
13
10
|
# Add the project root to the path
|
14
11
|
project_root = Path(__file__).parent.parent.parent
|
15
12
|
sys.path.insert(0, str(project_root))
|
16
|
-
|
17
13
|
from mcp_proxy_adapter.utils.config_generator import ConfigGenerator
|
18
|
-
|
19
|
-
|
20
14
|
def test_config_generator():
|
21
15
|
"""Test the configuration generator with different types."""
|
22
16
|
generator = ConfigGenerator()
|
23
|
-
|
24
17
|
# Test configuration types
|
25
18
|
config_types = [
|
26
19
|
"basic_http",
|
27
|
-
"http_token",
|
20
|
+
"http_token",
|
28
21
|
"https",
|
29
22
|
"https_token",
|
30
23
|
"https_no_protocol_middleware",
|
31
24
|
"mtls",
|
32
25
|
"mtls_no_protocol_middleware"
|
33
26
|
]
|
34
|
-
|
35
27
|
print("Testing Configuration Generator")
|
36
28
|
print("=" * 50)
|
37
|
-
|
38
29
|
for config_type in config_types:
|
39
30
|
print(f"\nTesting {config_type} configuration:")
|
40
31
|
print("-" * 30)
|
41
|
-
|
42
32
|
try:
|
43
33
|
# Generate configuration
|
44
34
|
config = generator._get_config_by_type(config_type)
|
45
|
-
|
46
35
|
# Check if protocols section exists
|
47
36
|
if "protocols" in config:
|
48
37
|
protocols = config["protocols"]
|
@@ -52,13 +41,11 @@ def test_config_generator():
|
|
52
41
|
print(f" - default_protocol: {protocols.get('default_protocol', 'NOT SET')}")
|
53
42
|
else:
|
54
43
|
print("❌ Protocols section missing!")
|
55
|
-
|
56
44
|
# Check SSL configuration
|
57
45
|
ssl_enabled = config.get("ssl", {}).get("enabled", False)
|
58
46
|
security_ssl_enabled = config.get("security", {}).get("ssl", {}).get("enabled", False)
|
59
47
|
print(f" - legacy ssl.enabled: {ssl_enabled}")
|
60
48
|
print(f" - security.ssl.enabled: {security_ssl_enabled}")
|
61
|
-
|
62
49
|
# Check if configuration is valid for its type
|
63
50
|
if config_type == "https_no_protocol_middleware" or config_type == "mtls_no_protocol_middleware":
|
64
51
|
if protocols.get("enabled") == False:
|
@@ -70,41 +57,30 @@ def test_config_generator():
|
|
70
57
|
print("✅ ProtocolMiddleware correctly enabled")
|
71
58
|
else:
|
72
59
|
print("❌ ProtocolMiddleware should be enabled but is disabled")
|
73
|
-
|
74
60
|
# Save configuration to file for inspection
|
75
61
|
output_file = f"test_config_{config_type}.json"
|
76
62
|
with open(output_file, 'w') as f:
|
77
63
|
json.dump(config, f, indent=2)
|
78
64
|
print(f" - Configuration saved to {output_file}")
|
79
|
-
|
80
65
|
except Exception as e:
|
81
66
|
print(f"❌ Error generating {config_type} configuration: {e}")
|
82
|
-
|
83
67
|
print("\n" + "=" * 50)
|
84
68
|
print("Configuration generator test completed!")
|
85
|
-
|
86
|
-
|
87
69
|
def test_config_with_comments():
|
88
70
|
"""Test configuration generation with comments."""
|
89
71
|
generator = ConfigGenerator()
|
90
|
-
|
91
72
|
print("\nTesting configuration with comments:")
|
92
73
|
print("-" * 40)
|
93
|
-
|
94
74
|
try:
|
95
75
|
# Generate HTTPS configuration with comments
|
96
76
|
commented_config = generator.generate_config_with_comments("https")
|
97
77
|
print("✅ HTTPS configuration with comments generated successfully")
|
98
|
-
|
99
78
|
# Save to file
|
100
79
|
with open("test_https_with_comments.json", 'w') as f:
|
101
80
|
f.write(commented_config)
|
102
81
|
print(" - Configuration saved to test_https_with_comments.json")
|
103
|
-
|
104
82
|
except Exception as e:
|
105
83
|
print(f"❌ Error generating configuration with comments: {e}")
|
106
|
-
|
107
|
-
|
108
84
|
if __name__ == "__main__":
|
109
85
|
test_config_generator()
|
110
86
|
test_config_with_comments()
|