mcp-proxy-adapter 4.1.1__py3-none-any.whl → 6.0.1__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 +32 -0
- mcp_proxy_adapter/api/app.py +290 -33
- mcp_proxy_adapter/api/handlers.py +32 -6
- mcp_proxy_adapter/api/middleware/__init__.py +38 -32
- mcp_proxy_adapter/api/middleware/command_permission_middleware.py +148 -0
- mcp_proxy_adapter/api/middleware/error_handling.py +9 -0
- mcp_proxy_adapter/api/middleware/factory.py +243 -0
- mcp_proxy_adapter/api/middleware/logging.py +32 -6
- mcp_proxy_adapter/api/middleware/protocol_middleware.py +201 -0
- mcp_proxy_adapter/api/middleware/transport_middleware.py +122 -0
- mcp_proxy_adapter/api/middleware/unified_security.py +197 -0
- mcp_proxy_adapter/api/middleware/user_info_middleware.py +158 -0
- mcp_proxy_adapter/commands/__init__.py +19 -4
- mcp_proxy_adapter/commands/auth_validation_command.py +408 -0
- mcp_proxy_adapter/commands/base.py +66 -32
- mcp_proxy_adapter/commands/builtin_commands.py +95 -0
- mcp_proxy_adapter/commands/catalog_manager.py +838 -0
- mcp_proxy_adapter/commands/cert_monitor_command.py +620 -0
- mcp_proxy_adapter/commands/certificate_management_command.py +608 -0
- mcp_proxy_adapter/commands/command_registry.py +711 -354
- mcp_proxy_adapter/commands/dependency_manager.py +245 -0
- mcp_proxy_adapter/commands/echo_command.py +81 -0
- mcp_proxy_adapter/commands/health_command.py +8 -1
- mcp_proxy_adapter/commands/help_command.py +21 -14
- mcp_proxy_adapter/commands/hooks.py +200 -167
- mcp_proxy_adapter/commands/key_management_command.py +506 -0
- mcp_proxy_adapter/commands/load_command.py +176 -0
- mcp_proxy_adapter/commands/plugins_command.py +235 -0
- mcp_proxy_adapter/commands/protocol_management_command.py +232 -0
- mcp_proxy_adapter/commands/proxy_registration_command.py +409 -0
- mcp_proxy_adapter/commands/reload_command.py +48 -50
- mcp_proxy_adapter/commands/result.py +1 -0
- mcp_proxy_adapter/commands/role_test_command.py +141 -0
- mcp_proxy_adapter/commands/roles_management_command.py +697 -0
- mcp_proxy_adapter/commands/security_command.py +488 -0
- mcp_proxy_adapter/commands/ssl_setup_command.py +366 -0
- mcp_proxy_adapter/commands/token_management_command.py +529 -0
- mcp_proxy_adapter/commands/transport_management_command.py +144 -0
- mcp_proxy_adapter/commands/unload_command.py +158 -0
- mcp_proxy_adapter/config.py +394 -14
- mcp_proxy_adapter/core/app_factory.py +410 -0
- mcp_proxy_adapter/core/app_runner.py +272 -0
- mcp_proxy_adapter/core/auth_validator.py +606 -0
- mcp_proxy_adapter/core/certificate_utils.py +1045 -0
- mcp_proxy_adapter/core/client.py +574 -0
- mcp_proxy_adapter/core/client_manager.py +284 -0
- mcp_proxy_adapter/core/client_security.py +384 -0
- mcp_proxy_adapter/core/config_converter.py +405 -0
- mcp_proxy_adapter/core/config_validator.py +218 -0
- mcp_proxy_adapter/core/logging.py +19 -3
- mcp_proxy_adapter/core/mtls_asgi.py +156 -0
- mcp_proxy_adapter/core/mtls_asgi_app.py +187 -0
- mcp_proxy_adapter/core/protocol_manager.py +385 -0
- mcp_proxy_adapter/core/proxy_client.py +602 -0
- mcp_proxy_adapter/core/proxy_registration.py +522 -0
- mcp_proxy_adapter/core/role_utils.py +426 -0
- mcp_proxy_adapter/core/security_adapter.py +370 -0
- mcp_proxy_adapter/core/security_factory.py +239 -0
- mcp_proxy_adapter/core/security_integration.py +286 -0
- mcp_proxy_adapter/core/server_adapter.py +282 -0
- mcp_proxy_adapter/core/server_engine.py +270 -0
- mcp_proxy_adapter/core/settings.py +1 -0
- mcp_proxy_adapter/core/ssl_utils.py +234 -0
- mcp_proxy_adapter/core/transport_manager.py +292 -0
- mcp_proxy_adapter/core/unified_config_adapter.py +579 -0
- mcp_proxy_adapter/custom_openapi.py +22 -11
- mcp_proxy_adapter/examples/__init__.py +13 -4
- mcp_proxy_adapter/examples/basic_framework/__init__.py +9 -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 +44 -0
- mcp_proxy_adapter/examples/commands/__init__.py +5 -0
- mcp_proxy_adapter/examples/create_certificates_simple.py +550 -0
- mcp_proxy_adapter/examples/debug_request_state.py +112 -0
- mcp_proxy_adapter/examples/debug_role_chain.py +158 -0
- mcp_proxy_adapter/examples/demo_client.py +275 -0
- mcp_proxy_adapter/examples/examples/basic_framework/__init__.py +9 -0
- mcp_proxy_adapter/examples/examples/basic_framework/commands/__init__.py +4 -0
- mcp_proxy_adapter/examples/examples/basic_framework/hooks/__init__.py +4 -0
- mcp_proxy_adapter/examples/examples/basic_framework/main.py +44 -0
- mcp_proxy_adapter/examples/examples/full_application/__init__.py +12 -0
- mcp_proxy_adapter/examples/examples/full_application/commands/__init__.py +7 -0
- mcp_proxy_adapter/examples/examples/full_application/commands/custom_echo_command.py +80 -0
- mcp_proxy_adapter/examples/examples/full_application/commands/dynamic_calculator_command.py +90 -0
- mcp_proxy_adapter/examples/examples/full_application/hooks/__init__.py +7 -0
- mcp_proxy_adapter/examples/examples/full_application/hooks/application_hooks.py +75 -0
- mcp_proxy_adapter/examples/examples/full_application/hooks/builtin_command_hooks.py +71 -0
- mcp_proxy_adapter/examples/examples/full_application/main.py +173 -0
- mcp_proxy_adapter/examples/examples/full_application/proxy_endpoints.py +154 -0
- mcp_proxy_adapter/examples/full_application/__init__.py +12 -0
- mcp_proxy_adapter/examples/full_application/commands/__init__.py +7 -0
- mcp_proxy_adapter/examples/full_application/commands/custom_echo_command.py +80 -0
- mcp_proxy_adapter/examples/full_application/commands/dynamic_calculator_command.py +90 -0
- mcp_proxy_adapter/examples/full_application/hooks/__init__.py +7 -0
- mcp_proxy_adapter/examples/full_application/hooks/application_hooks.py +75 -0
- mcp_proxy_adapter/examples/full_application/hooks/builtin_command_hooks.py +71 -0
- mcp_proxy_adapter/examples/full_application/main.py +173 -0
- mcp_proxy_adapter/examples/full_application/proxy_endpoints.py +154 -0
- mcp_proxy_adapter/examples/generate_all_certificates.py +362 -0
- mcp_proxy_adapter/examples/generate_certificates.py +177 -0
- mcp_proxy_adapter/examples/generate_certificates_and_tokens.py +369 -0
- mcp_proxy_adapter/examples/generate_test_configs.py +331 -0
- mcp_proxy_adapter/examples/proxy_registration_example.py +334 -0
- mcp_proxy_adapter/examples/run_example.py +59 -0
- mcp_proxy_adapter/examples/run_full_test_suite.py +318 -0
- mcp_proxy_adapter/examples/run_proxy_server.py +146 -0
- mcp_proxy_adapter/examples/run_security_tests.py +544 -0
- mcp_proxy_adapter/examples/run_security_tests_fixed.py +247 -0
- mcp_proxy_adapter/examples/scripts/config_generator.py +740 -0
- mcp_proxy_adapter/examples/scripts/create_certificates_simple.py +560 -0
- mcp_proxy_adapter/examples/scripts/generate_certificates_and_tokens.py +369 -0
- mcp_proxy_adapter/examples/security_test_client.py +782 -0
- mcp_proxy_adapter/examples/setup_test_environment.py +328 -0
- mcp_proxy_adapter/examples/test_config.py +148 -0
- mcp_proxy_adapter/examples/test_config_generator.py +86 -0
- mcp_proxy_adapter/examples/test_examples.py +281 -0
- mcp_proxy_adapter/examples/universal_client.py +620 -0
- mcp_proxy_adapter/main.py +93 -0
- mcp_proxy_adapter/utils/config_generator.py +1008 -0
- mcp_proxy_adapter/version.py +5 -2
- mcp_proxy_adapter-6.0.1.dist-info/METADATA +679 -0
- mcp_proxy_adapter-6.0.1.dist-info/RECORD +140 -0
- mcp_proxy_adapter-6.0.1.dist-info/entry_points.txt +2 -0
- {mcp_proxy_adapter-4.1.1.dist-info → mcp_proxy_adapter-6.0.1.dist-info}/licenses/LICENSE +2 -2
- mcp_proxy_adapter/api/middleware/auth.py +0 -146
- mcp_proxy_adapter/api/middleware/rate_limit.py +0 -152
- mcp_proxy_adapter/commands/reload_settings_command.py +0 -125
- mcp_proxy_adapter/examples/README.md +0 -124
- mcp_proxy_adapter/examples/basic_server/README.md +0 -60
- mcp_proxy_adapter/examples/basic_server/__init__.py +0 -7
- mcp_proxy_adapter/examples/basic_server/basic_custom_settings.json +0 -39
- mcp_proxy_adapter/examples/basic_server/config.json +0 -35
- mcp_proxy_adapter/examples/basic_server/custom_settings_example.py +0 -238
- mcp_proxy_adapter/examples/basic_server/server.py +0 -103
- mcp_proxy_adapter/examples/custom_commands/README.md +0 -127
- mcp_proxy_adapter/examples/custom_commands/__init__.py +0 -27
- mcp_proxy_adapter/examples/custom_commands/advanced_hooks.py +0 -250
- mcp_proxy_adapter/examples/custom_commands/auto_commands/__init__.py +0 -6
- mcp_proxy_adapter/examples/custom_commands/auto_commands/auto_echo_command.py +0 -103
- mcp_proxy_adapter/examples/custom_commands/auto_commands/auto_info_command.py +0 -111
- mcp_proxy_adapter/examples/custom_commands/config.json +0 -35
- mcp_proxy_adapter/examples/custom_commands/custom_health_command.py +0 -169
- mcp_proxy_adapter/examples/custom_commands/custom_help_command.py +0 -215
- mcp_proxy_adapter/examples/custom_commands/custom_openapi_generator.py +0 -76
- mcp_proxy_adapter/examples/custom_commands/custom_settings.json +0 -96
- mcp_proxy_adapter/examples/custom_commands/custom_settings_manager.py +0 -241
- mcp_proxy_adapter/examples/custom_commands/data_transform_command.py +0 -135
- mcp_proxy_adapter/examples/custom_commands/echo_command.py +0 -122
- mcp_proxy_adapter/examples/custom_commands/hooks.py +0 -230
- mcp_proxy_adapter/examples/custom_commands/intercept_command.py +0 -123
- mcp_proxy_adapter/examples/custom_commands/manual_echo_command.py +0 -103
- mcp_proxy_adapter/examples/custom_commands/server.py +0 -228
- mcp_proxy_adapter/examples/custom_commands/test_hooks.py +0 -176
- mcp_proxy_adapter/examples/deployment/README.md +0 -49
- mcp_proxy_adapter/examples/deployment/__init__.py +0 -7
- mcp_proxy_adapter/examples/deployment/config.development.json +0 -8
- mcp_proxy_adapter/examples/deployment/config.json +0 -29
- mcp_proxy_adapter/examples/deployment/config.production.json +0 -12
- mcp_proxy_adapter/examples/deployment/config.staging.json +0 -11
- mcp_proxy_adapter/examples/deployment/docker-compose.yml +0 -31
- mcp_proxy_adapter/examples/deployment/run.sh +0 -43
- mcp_proxy_adapter/examples/deployment/run_docker.sh +0 -84
- mcp_proxy_adapter/schemas/base_schema.json +0 -114
- mcp_proxy_adapter/schemas/openapi_schema.json +0 -314
- mcp_proxy_adapter/tests/__init__.py +0 -0
- mcp_proxy_adapter/tests/api/__init__.py +0 -3
- mcp_proxy_adapter/tests/api/test_cmd_endpoint.py +0 -115
- mcp_proxy_adapter/tests/api/test_custom_openapi.py +0 -617
- mcp_proxy_adapter/tests/api/test_handlers.py +0 -522
- mcp_proxy_adapter/tests/api/test_middleware.py +0 -340
- mcp_proxy_adapter/tests/api/test_schemas.py +0 -546
- mcp_proxy_adapter/tests/api/test_tool_integration.py +0 -531
- mcp_proxy_adapter/tests/commands/__init__.py +0 -3
- mcp_proxy_adapter/tests/commands/test_config_command.py +0 -211
- mcp_proxy_adapter/tests/commands/test_echo_command.py +0 -127
- mcp_proxy_adapter/tests/commands/test_help_command.py +0 -136
- mcp_proxy_adapter/tests/conftest.py +0 -131
- mcp_proxy_adapter/tests/functional/__init__.py +0 -3
- mcp_proxy_adapter/tests/functional/test_api.py +0 -253
- mcp_proxy_adapter/tests/integration/__init__.py +0 -3
- mcp_proxy_adapter/tests/integration/test_cmd_integration.py +0 -129
- mcp_proxy_adapter/tests/integration/test_integration.py +0 -255
- mcp_proxy_adapter/tests/performance/__init__.py +0 -3
- mcp_proxy_adapter/tests/performance/test_performance.py +0 -189
- mcp_proxy_adapter/tests/stubs/__init__.py +0 -10
- mcp_proxy_adapter/tests/stubs/echo_command.py +0 -104
- mcp_proxy_adapter/tests/test_api_endpoints.py +0 -271
- mcp_proxy_adapter/tests/test_api_handlers.py +0 -289
- mcp_proxy_adapter/tests/test_base_command.py +0 -123
- mcp_proxy_adapter/tests/test_batch_requests.py +0 -117
- mcp_proxy_adapter/tests/test_command_registry.py +0 -281
- mcp_proxy_adapter/tests/test_config.py +0 -127
- mcp_proxy_adapter/tests/test_utils.py +0 -65
- mcp_proxy_adapter/tests/unit/__init__.py +0 -3
- mcp_proxy_adapter/tests/unit/test_base_command.py +0 -436
- mcp_proxy_adapter/tests/unit/test_config.py +0 -217
- mcp_proxy_adapter-4.1.1.dist-info/METADATA +0 -200
- mcp_proxy_adapter-4.1.1.dist-info/RECORD +0 -110
- {mcp_proxy_adapter-4.1.1.dist-info → mcp_proxy_adapter-6.0.1.dist-info}/WHEEL +0 -0
- {mcp_proxy_adapter-4.1.1.dist-info → mcp_proxy_adapter-6.0.1.dist-info}/top_level.txt +0 -0
@@ -0,0 +1,292 @@
|
|
1
|
+
"""
|
2
|
+
Transport manager module.
|
3
|
+
|
4
|
+
This module provides transport management functionality for the MCP Proxy Adapter.
|
5
|
+
"""
|
6
|
+
|
7
|
+
from typing import Dict, Any, Optional
|
8
|
+
from dataclasses import dataclass
|
9
|
+
from enum import Enum
|
10
|
+
from pathlib import Path
|
11
|
+
|
12
|
+
from mcp_proxy_adapter.core.logging import logger
|
13
|
+
|
14
|
+
|
15
|
+
class TransportType(Enum):
|
16
|
+
"""Transport types enumeration."""
|
17
|
+
HTTP = "http"
|
18
|
+
HTTPS = "https"
|
19
|
+
MTLS = "mtls"
|
20
|
+
|
21
|
+
|
22
|
+
@dataclass
|
23
|
+
class TransportConfig:
|
24
|
+
"""Transport configuration data class."""
|
25
|
+
type: TransportType
|
26
|
+
port: Optional[int]
|
27
|
+
ssl_enabled: bool
|
28
|
+
cert_file: Optional[str]
|
29
|
+
key_file: Optional[str]
|
30
|
+
ca_cert: Optional[str]
|
31
|
+
verify_client: bool
|
32
|
+
client_cert_required: bool
|
33
|
+
|
34
|
+
|
35
|
+
class TransportManager:
|
36
|
+
"""
|
37
|
+
Transport manager for handling different transport types.
|
38
|
+
|
39
|
+
This class manages transport configuration and provides utilities
|
40
|
+
for determining ports and SSL settings based on transport type.
|
41
|
+
"""
|
42
|
+
|
43
|
+
# Default ports for transport types
|
44
|
+
DEFAULT_PORTS = {
|
45
|
+
TransportType.HTTP: 8000,
|
46
|
+
TransportType.HTTPS: 8443,
|
47
|
+
TransportType.MTLS: 9443
|
48
|
+
}
|
49
|
+
|
50
|
+
def __init__(self):
|
51
|
+
"""Initialize transport manager."""
|
52
|
+
self._config: Optional[TransportConfig] = None
|
53
|
+
self._current_transport: Optional[TransportType] = None
|
54
|
+
|
55
|
+
def load_config(self, config: Dict[str, Any]) -> bool:
|
56
|
+
"""
|
57
|
+
Load transport configuration from config dict.
|
58
|
+
|
59
|
+
Args:
|
60
|
+
config: Configuration dictionary
|
61
|
+
|
62
|
+
Returns:
|
63
|
+
True if config loaded successfully, False otherwise
|
64
|
+
"""
|
65
|
+
try:
|
66
|
+
transport_config = config.get("transport", {})
|
67
|
+
|
68
|
+
# Get transport type
|
69
|
+
transport_type_str = transport_config.get("type", "http").lower()
|
70
|
+
try:
|
71
|
+
transport_type = TransportType(transport_type_str)
|
72
|
+
except ValueError:
|
73
|
+
logger.error(f"Invalid transport type: {transport_type_str}")
|
74
|
+
return False
|
75
|
+
|
76
|
+
# Get port (use default if not specified)
|
77
|
+
port = transport_config.get("port")
|
78
|
+
if port is None:
|
79
|
+
port = self.DEFAULT_PORTS.get(transport_type, 8000)
|
80
|
+
|
81
|
+
# Get SSL configuration
|
82
|
+
ssl_config = transport_config.get("ssl", {})
|
83
|
+
ssl_enabled = ssl_config.get("enabled", False)
|
84
|
+
|
85
|
+
# Validate SSL requirements
|
86
|
+
if transport_type in [TransportType.HTTPS, TransportType.MTLS] and not ssl_enabled:
|
87
|
+
logger.error(f"SSL must be enabled for transport type: {transport_type.value}")
|
88
|
+
return False
|
89
|
+
|
90
|
+
if transport_type == TransportType.HTTP and ssl_enabled:
|
91
|
+
logger.warning("SSL enabled for HTTP transport - this may cause issues")
|
92
|
+
|
93
|
+
# Create transport config
|
94
|
+
self._config = TransportConfig(
|
95
|
+
type=transport_type,
|
96
|
+
port=port,
|
97
|
+
ssl_enabled=ssl_enabled,
|
98
|
+
cert_file=ssl_config.get("cert_file") if ssl_enabled else None,
|
99
|
+
key_file=ssl_config.get("key_file") if ssl_enabled else None,
|
100
|
+
ca_cert=ssl_config.get("ca_cert") if ssl_enabled else None,
|
101
|
+
verify_client=ssl_config.get("verify_client", False),
|
102
|
+
client_cert_required=ssl_config.get("client_cert_required", False)
|
103
|
+
)
|
104
|
+
|
105
|
+
self._current_transport = transport_type
|
106
|
+
|
107
|
+
logger.info(f"Transport config loaded: {transport_type.value} on port {port}")
|
108
|
+
return True
|
109
|
+
|
110
|
+
except Exception as e:
|
111
|
+
logger.error(f"Failed to load transport config: {e}")
|
112
|
+
return False
|
113
|
+
|
114
|
+
def get_transport_type(self) -> Optional[TransportType]:
|
115
|
+
"""
|
116
|
+
Get current transport type.
|
117
|
+
|
118
|
+
Returns:
|
119
|
+
Current transport type or None if not configured
|
120
|
+
"""
|
121
|
+
return self._current_transport
|
122
|
+
|
123
|
+
def get_port(self) -> Optional[int]:
|
124
|
+
"""
|
125
|
+
Get configured port.
|
126
|
+
|
127
|
+
Returns:
|
128
|
+
Port number or None if not configured
|
129
|
+
"""
|
130
|
+
return self._config.port if self._config else None
|
131
|
+
|
132
|
+
def is_ssl_enabled(self) -> bool:
|
133
|
+
"""
|
134
|
+
Check if SSL is enabled.
|
135
|
+
|
136
|
+
Returns:
|
137
|
+
True if SSL is enabled, False otherwise
|
138
|
+
"""
|
139
|
+
return self._config.ssl_enabled if self._config else False
|
140
|
+
|
141
|
+
def get_ssl_config(self) -> Optional[Dict[str, Any]]:
|
142
|
+
"""
|
143
|
+
Get SSL configuration.
|
144
|
+
|
145
|
+
Returns:
|
146
|
+
SSL configuration dict or None if SSL not enabled
|
147
|
+
"""
|
148
|
+
if not self._config or not self._config.ssl_enabled:
|
149
|
+
return None
|
150
|
+
|
151
|
+
return {
|
152
|
+
"cert_file": self._config.cert_file,
|
153
|
+
"key_file": self._config.key_file,
|
154
|
+
"ca_cert": self._config.ca_cert,
|
155
|
+
"verify_client": self._config.verify_client,
|
156
|
+
"client_cert_required": self._config.client_cert_required
|
157
|
+
}
|
158
|
+
|
159
|
+
def is_mtls(self) -> bool:
|
160
|
+
"""
|
161
|
+
Check if current transport is MTLS.
|
162
|
+
|
163
|
+
Returns:
|
164
|
+
True if MTLS transport, False otherwise
|
165
|
+
"""
|
166
|
+
return self._current_transport == TransportType.MTLS
|
167
|
+
|
168
|
+
def is_https(self) -> bool:
|
169
|
+
"""
|
170
|
+
Check if current transport is HTTPS.
|
171
|
+
|
172
|
+
Returns:
|
173
|
+
True if HTTPS transport, False otherwise
|
174
|
+
"""
|
175
|
+
return self._current_transport == TransportType.HTTPS
|
176
|
+
|
177
|
+
def is_http(self) -> bool:
|
178
|
+
"""
|
179
|
+
Check if current transport is HTTP.
|
180
|
+
|
181
|
+
Returns:
|
182
|
+
True if HTTP transport, False otherwise
|
183
|
+
"""
|
184
|
+
return self._current_transport == TransportType.HTTP
|
185
|
+
|
186
|
+
def get_transport_info(self) -> Dict[str, Any]:
|
187
|
+
"""
|
188
|
+
Get transport information.
|
189
|
+
|
190
|
+
Returns:
|
191
|
+
Dictionary with transport information
|
192
|
+
"""
|
193
|
+
if not self._config:
|
194
|
+
return {"error": "Transport not configured"}
|
195
|
+
|
196
|
+
return {
|
197
|
+
"type": self._config.type.value,
|
198
|
+
"port": self._config.port,
|
199
|
+
"ssl_enabled": self._config.ssl_enabled,
|
200
|
+
"is_mtls": self.is_mtls(),
|
201
|
+
"is_https": self.is_https(),
|
202
|
+
"is_http": self.is_http(),
|
203
|
+
"ssl_config": self.get_ssl_config()
|
204
|
+
}
|
205
|
+
|
206
|
+
def validate_config(self) -> bool:
|
207
|
+
"""
|
208
|
+
Validate current transport configuration.
|
209
|
+
|
210
|
+
Returns:
|
211
|
+
True if configuration is valid, False otherwise
|
212
|
+
"""
|
213
|
+
if not self._config:
|
214
|
+
logger.error("Transport not configured")
|
215
|
+
return False
|
216
|
+
|
217
|
+
# Validate SSL requirements
|
218
|
+
if self._config.type in [TransportType.HTTPS, TransportType.MTLS]:
|
219
|
+
if not self._config.ssl_enabled:
|
220
|
+
logger.error(f"SSL must be enabled for {self._config.type.value}")
|
221
|
+
return False
|
222
|
+
|
223
|
+
if not self._config.cert_file or not self._config.key_file:
|
224
|
+
logger.error(f"SSL certificate and key required for {self._config.type.value}")
|
225
|
+
return False
|
226
|
+
|
227
|
+
# Validate SSL files exist
|
228
|
+
if not self.validate_ssl_files():
|
229
|
+
return False
|
230
|
+
|
231
|
+
# Validate MTLS requirements
|
232
|
+
if self._config.type == TransportType.MTLS:
|
233
|
+
if not self._config.verify_client:
|
234
|
+
logger.warning("MTLS transport should have client verification enabled")
|
235
|
+
|
236
|
+
if not self._config.ca_cert:
|
237
|
+
logger.warning("CA certificate recommended for MTLS transport")
|
238
|
+
|
239
|
+
logger.info(f"Transport configuration validated: {self._config.type.value}")
|
240
|
+
return True
|
241
|
+
|
242
|
+
def validate_ssl_files(self) -> bool:
|
243
|
+
"""
|
244
|
+
Check if SSL files exist.
|
245
|
+
|
246
|
+
Returns:
|
247
|
+
True if all SSL files exist, False otherwise
|
248
|
+
"""
|
249
|
+
if not self._config or not self._config.ssl_enabled:
|
250
|
+
return True
|
251
|
+
|
252
|
+
files_to_check = []
|
253
|
+
if self._config.cert_file:
|
254
|
+
files_to_check.append(self._config.cert_file)
|
255
|
+
if self._config.key_file:
|
256
|
+
files_to_check.append(self._config.key_file)
|
257
|
+
if self._config.ca_cert:
|
258
|
+
files_to_check.append(self._config.ca_cert)
|
259
|
+
|
260
|
+
for file_path in files_to_check:
|
261
|
+
if not Path(file_path).exists():
|
262
|
+
logger.error(f"SSL file not found: {file_path}")
|
263
|
+
return False
|
264
|
+
|
265
|
+
logger.info(f"All SSL files validated successfully: {files_to_check}")
|
266
|
+
return True
|
267
|
+
|
268
|
+
def get_hypercorn_config(self) -> Dict[str, Any]:
|
269
|
+
"""
|
270
|
+
Get configuration for hypercorn.
|
271
|
+
|
272
|
+
Returns:
|
273
|
+
Hypercorn configuration dictionary
|
274
|
+
"""
|
275
|
+
config = {
|
276
|
+
"host": "0.0.0.0", # Can be moved to settings
|
277
|
+
"port": self.get_port(),
|
278
|
+
"log_level": "info"
|
279
|
+
}
|
280
|
+
|
281
|
+
if self.is_ssl_enabled():
|
282
|
+
ssl_config = self.get_ssl_config()
|
283
|
+
if ssl_config:
|
284
|
+
from mcp_proxy_adapter.core.ssl_utils import SSLUtils
|
285
|
+
hypercorn_ssl = SSLUtils.get_ssl_config_for_hypercorn(ssl_config)
|
286
|
+
config.update(hypercorn_ssl)
|
287
|
+
|
288
|
+
return config
|
289
|
+
|
290
|
+
|
291
|
+
# Global transport manager instance
|
292
|
+
transport_manager = TransportManager()
|