mcp-proxy-adapter 6.0.0__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 +27 -7
- mcp_proxy_adapter/api/app.py +209 -79
- mcp_proxy_adapter/api/handlers.py +16 -5
- mcp_proxy_adapter/api/middleware/__init__.py +14 -9
- mcp_proxy_adapter/api/middleware/command_permission_middleware.py +148 -0
- mcp_proxy_adapter/api/middleware/factory.py +36 -12
- mcp_proxy_adapter/api/middleware/protocol_middleware.py +84 -18
- 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 +7 -1
- mcp_proxy_adapter/commands/base.py +7 -4
- mcp_proxy_adapter/commands/builtin_commands.py +8 -2
- mcp_proxy_adapter/commands/command_registry.py +8 -0
- mcp_proxy_adapter/commands/echo_command.py +81 -0
- mcp_proxy_adapter/commands/health_command.py +1 -1
- mcp_proxy_adapter/commands/help_command.py +21 -14
- mcp_proxy_adapter/commands/proxy_registration_command.py +326 -185
- mcp_proxy_adapter/commands/role_test_command.py +141 -0
- mcp_proxy_adapter/commands/security_command.py +488 -0
- mcp_proxy_adapter/commands/ssl_setup_command.py +234 -351
- mcp_proxy_adapter/commands/token_management_command.py +1 -1
- mcp_proxy_adapter/config.py +323 -40
- mcp_proxy_adapter/core/app_factory.py +410 -0
- 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/client_security.py +384 -0
- mcp_proxy_adapter/core/logging.py +8 -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 +169 -10
- mcp_proxy_adapter/core/proxy_client.py +602 -0
- mcp_proxy_adapter/core/proxy_registration.py +299 -47
- mcp_proxy_adapter/core/security_adapter.py +12 -15
- 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/ssl_utils.py +13 -12
- mcp_proxy_adapter/core/transport_manager.py +5 -5
- mcp_proxy_adapter/core/unified_config_adapter.py +579 -0
- 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 +66 -148
- 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-6.0.0.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/auth_adapter.py +0 -235
- mcp_proxy_adapter/api/middleware/mtls_adapter.py +0 -305
- mcp_proxy_adapter/api/middleware/mtls_middleware.py +0 -296
- mcp_proxy_adapter/api/middleware/rate_limit.py +0 -152
- mcp_proxy_adapter/api/middleware/rate_limit_adapter.py +0 -241
- mcp_proxy_adapter/api/middleware/roles_adapter.py +0 -365
- mcp_proxy_adapter/api/middleware/roles_middleware.py +0 -381
- mcp_proxy_adapter/api/middleware/security.py +0 -376
- mcp_proxy_adapter/api/middleware/token_auth_middleware.py +0 -261
- 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 -70
- mcp_proxy_adapter/examples/basic_server/config_all_protocols.json +0 -54
- mcp_proxy_adapter/examples/basic_server/config_http.json +0 -70
- mcp_proxy_adapter/examples/basic_server/config_http_only.json +0 -52
- mcp_proxy_adapter/examples/basic_server/config_https.json +0 -58
- mcp_proxy_adapter/examples/basic_server/config_mtls.json +0 -58
- mcp_proxy_adapter/examples/basic_server/config_ssl.json +0 -46
- mcp_proxy_adapter/examples/basic_server/custom_settings_example.py +0 -238
- mcp_proxy_adapter/examples/basic_server/server.py +0 -114
- 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 -566
- 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/auto_commands/test_command.py +0 -105
- mcp_proxy_adapter/examples/custom_commands/catalog/commands/test_command.py +0 -129
- mcp_proxy_adapter/examples/custom_commands/config.json +0 -118
- mcp_proxy_adapter/examples/custom_commands/config_all_protocols.json +0 -46
- mcp_proxy_adapter/examples/custom_commands/config_https_only.json +0 -46
- mcp_proxy_adapter/examples/custom_commands/config_https_transport.json +0 -33
- mcp_proxy_adapter/examples/custom_commands/config_mtls_only.json +0 -46
- mcp_proxy_adapter/examples/custom_commands/config_mtls_transport.json +0 -33
- mcp_proxy_adapter/examples/custom_commands/config_single_transport.json +0 -33
- 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/full_help_response.json +0 -1
- mcp_proxy_adapter/examples/custom_commands/generated_openapi.json +0 -629
- mcp_proxy_adapter/examples/custom_commands/get_openapi.py +0 -103
- 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/loadable_commands/test_ignored.py +0 -129
- mcp_proxy_adapter/examples/custom_commands/manual_echo_command.py +0 -103
- mcp_proxy_adapter/examples/custom_commands/proxy_connection_manager.py +0 -278
- mcp_proxy_adapter/examples/custom_commands/server.py +0 -252
- mcp_proxy_adapter/examples/custom_commands/simple_openapi_server.py +0 -75
- mcp_proxy_adapter/examples/custom_commands/start_server_with_proxy_manager.py +0 -299
- mcp_proxy_adapter/examples/custom_commands/start_server_with_registration.py +0 -278
- mcp_proxy_adapter/examples/custom_commands/test_hooks.py +0 -176
- mcp_proxy_adapter/examples/custom_commands/test_openapi.py +0 -27
- mcp_proxy_adapter/examples/custom_commands/test_registry.py +0 -23
- mcp_proxy_adapter/examples/custom_commands/test_simple.py +0 -19
- mcp_proxy_adapter/examples/custom_project_example/README.md +0 -103
- mcp_proxy_adapter/examples/custom_project_example/README_EN.md +0 -103
- 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/examples/simple_custom_commands/README.md +0 -149
- mcp_proxy_adapter/examples/simple_custom_commands/README_EN.md +0 -149
- mcp_proxy_adapter/schemas/base_schema.json +0 -114
- mcp_proxy_adapter/schemas/openapi_schema.json +0 -314
- mcp_proxy_adapter/schemas/roles_schema.json +0 -162
- 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 -270
- mcp_proxy_adapter-6.0.0.dist-info/METADATA +0 -201
- mcp_proxy_adapter-6.0.0.dist-info/RECORD +0 -179
- {mcp_proxy_adapter-6.0.0.dist-info → mcp_proxy_adapter-6.0.1.dist-info}/WHEEL +0 -0
- {mcp_proxy_adapter-6.0.0.dist-info → mcp_proxy_adapter-6.0.1.dist-info}/top_level.txt +0 -0
@@ -0,0 +1,1008 @@
|
|
1
|
+
"""
|
2
|
+
Configuration Generator Utility
|
3
|
+
|
4
|
+
This module provides utilities for generating comprehensive configuration files
|
5
|
+
that combine mcp_proxy_adapter and mcp_security_framework configurations.
|
6
|
+
|
7
|
+
Author: Vasiliy Zdanovskiy
|
8
|
+
email: vasilyvz@gmail.com
|
9
|
+
"""
|
10
|
+
|
11
|
+
import json
|
12
|
+
import logging
|
13
|
+
from pathlib import Path
|
14
|
+
from typing import Dict, Any, Optional
|
15
|
+
|
16
|
+
# Use standard logging instead of project logger to avoid circular imports
|
17
|
+
logger = logging.getLogger(__name__)
|
18
|
+
|
19
|
+
|
20
|
+
class ConfigGenerator:
|
21
|
+
"""
|
22
|
+
Configuration generator for unified mcp_proxy_adapter and mcp_security_framework configs.
|
23
|
+
|
24
|
+
Generates comprehensive configuration files with detailed comments and examples
|
25
|
+
for both the proxy adapter and security framework components.
|
26
|
+
"""
|
27
|
+
|
28
|
+
def __init__(self):
|
29
|
+
"""Initialize configuration generator."""
|
30
|
+
self.template_config = self._get_template_config()
|
31
|
+
|
32
|
+
def _get_template_config(self) -> Dict[str, Any]:
|
33
|
+
"""Get template configuration with all available options."""
|
34
|
+
return {
|
35
|
+
"server": {
|
36
|
+
"host": "0.0.0.0",
|
37
|
+
"port": 8000,
|
38
|
+
"debug": False,
|
39
|
+
"log_level": "INFO",
|
40
|
+
"workers": 1,
|
41
|
+
"reload": False
|
42
|
+
},
|
43
|
+
"ssl": {
|
44
|
+
"enabled": False,
|
45
|
+
"cert_file": None,
|
46
|
+
"key_file": None,
|
47
|
+
"ca_cert": None,
|
48
|
+
"verify_client": False,
|
49
|
+
"client_cert_required": False,
|
50
|
+
"cipher_suites": ["TLS_AES_256_GCM_SHA384", "TLS_CHACHA20_POLY1305_SHA256"],
|
51
|
+
"min_tls_version": "TLSv1.2",
|
52
|
+
"max_tls_version": "1.3"
|
53
|
+
},
|
54
|
+
"security": {
|
55
|
+
"framework": "mcp_security_framework",
|
56
|
+
"enabled": True,
|
57
|
+
"debug": False,
|
58
|
+
"environment": "dev",
|
59
|
+
"version": "1.0.0",
|
60
|
+
|
61
|
+
"ssl": {
|
62
|
+
"enabled": False,
|
63
|
+
"cert_file": None,
|
64
|
+
"key_file": None,
|
65
|
+
"ca_cert_file": None,
|
66
|
+
"client_cert_file": None,
|
67
|
+
"client_key_file": None,
|
68
|
+
"verify_mode": "CERT_REQUIRED",
|
69
|
+
"min_tls_version": "TLSv1.2",
|
70
|
+
"max_tls_version": None,
|
71
|
+
"cipher_suite": None,
|
72
|
+
"check_hostname": True,
|
73
|
+
"check_expiry": True,
|
74
|
+
"expiry_warning_days": 30
|
75
|
+
},
|
76
|
+
|
77
|
+
"auth": {
|
78
|
+
"enabled": False,
|
79
|
+
"methods": [],
|
80
|
+
"api_keys": {},
|
81
|
+
"user_roles": {},
|
82
|
+
"jwt_secret": None,
|
83
|
+
"jwt_algorithm": "HS256",
|
84
|
+
"jwt_expiry_hours": 24,
|
85
|
+
"certificate_auth": False,
|
86
|
+
"certificate_roles_oid": "1.3.6.1.4.1.99999.1.1",
|
87
|
+
"certificate_permissions_oid": "1.3.6.1.4.1.99999.1.2",
|
88
|
+
"basic_auth": False,
|
89
|
+
"oauth2_config": None,
|
90
|
+
"public_paths": ["/health", "/docs", "/openapi.json"],
|
91
|
+
"security_headers": {
|
92
|
+
"X-Content-Type-Options": "nosniff",
|
93
|
+
"X-Frame-Options": "DENY",
|
94
|
+
"X-XSS-Protection": "1; mode=block",
|
95
|
+
"Strict-Transport-Security": "max-age=31536000; includeSubDomains"
|
96
|
+
}
|
97
|
+
},
|
98
|
+
|
99
|
+
"certificates": {
|
100
|
+
"enabled": False,
|
101
|
+
"ca_cert_path": None,
|
102
|
+
"ca_key_path": None,
|
103
|
+
"cert_storage_path": "mcp_proxy_adapter/examples/certs",
|
104
|
+
"key_storage_path": "mcp_proxy_adapter/examples/keys",
|
105
|
+
"default_validity_days": 365,
|
106
|
+
"key_size": 2048,
|
107
|
+
"hash_algorithm": "sha256",
|
108
|
+
"crl_enabled": False,
|
109
|
+
"crl_path": None,
|
110
|
+
"crl_validity_days": 30,
|
111
|
+
"auto_renewal": False,
|
112
|
+
"renewal_threshold_days": 30
|
113
|
+
},
|
114
|
+
|
115
|
+
"permissions": {
|
116
|
+
"enabled": False,
|
117
|
+
"roles_file": None,
|
118
|
+
"default_role": "guest",
|
119
|
+
"admin_role": "admin",
|
120
|
+
"role_hierarchy": {},
|
121
|
+
"permission_cache_enabled": False,
|
122
|
+
"permission_cache_ttl": 300,
|
123
|
+
"wildcard_permissions": False,
|
124
|
+
"strict_mode": False,
|
125
|
+
"roles": {}
|
126
|
+
},
|
127
|
+
|
128
|
+
"rate_limit": {
|
129
|
+
"enabled": False,
|
130
|
+
"default_requests_per_minute": 60,
|
131
|
+
"default_requests_per_hour": 1000,
|
132
|
+
"burst_limit": 2,
|
133
|
+
"window_size_seconds": 60,
|
134
|
+
"storage_backend": "memory",
|
135
|
+
"redis_config": None,
|
136
|
+
"cleanup_interval": 300,
|
137
|
+
"exempt_paths": ["/health", "/docs", "/openapi.json"],
|
138
|
+
"exempt_roles": ["admin"]
|
139
|
+
},
|
140
|
+
|
141
|
+
"logging": {
|
142
|
+
"enabled": True,
|
143
|
+
"level": "INFO",
|
144
|
+
"format": "%(asctime)s - %(name)s - %(levelname)s - %(message)s",
|
145
|
+
"date_format": "%Y-%m-%d %H:%M:%S",
|
146
|
+
"file_path": "./logs/security.log",
|
147
|
+
"max_file_size": 10,
|
148
|
+
"backup_count": 5,
|
149
|
+
"console_output": True,
|
150
|
+
"json_format": False,
|
151
|
+
"include_timestamp": True,
|
152
|
+
"include_level": True,
|
153
|
+
"include_module": True
|
154
|
+
}
|
155
|
+
},
|
156
|
+
|
157
|
+
"registration": {
|
158
|
+
"enabled": False,
|
159
|
+
"server_url": "https://proxy-registry.example.com",
|
160
|
+
"auth_method": "certificate",
|
161
|
+
"certificate": {
|
162
|
+
"enabled": False,
|
163
|
+
"cert_file": "mcp_proxy_adapter/examples/certs/proxy_client.crt",
|
164
|
+
"key_file": "mcp_proxy_adapter/examples/keys/proxy_client.key",
|
165
|
+
"ca_cert_file": "mcp_proxy_adapter/examples/certs/ca.crt",
|
166
|
+
"verify_server": True
|
167
|
+
},
|
168
|
+
"token": {
|
169
|
+
"enabled": False,
|
170
|
+
"token": "proxy_registration_token_123",
|
171
|
+
"token_type": "bearer",
|
172
|
+
"refresh_interval": 3600
|
173
|
+
},
|
174
|
+
"api_key": {
|
175
|
+
"enabled": False,
|
176
|
+
"key": "proxy_api_key_456",
|
177
|
+
"key_header": "X-Proxy-API-Key"
|
178
|
+
},
|
179
|
+
"proxy_info": {
|
180
|
+
"name": "mcp_proxy_adapter",
|
181
|
+
"version": "1.0.0",
|
182
|
+
"description": "MCP Proxy Adapter with security framework",
|
183
|
+
"capabilities": ["jsonrpc", "rest", "security", "certificates"],
|
184
|
+
"endpoints": {
|
185
|
+
"jsonrpc": "/api/jsonrpc",
|
186
|
+
"rest": "/cmd",
|
187
|
+
"health": "/health"
|
188
|
+
}
|
189
|
+
},
|
190
|
+
"heartbeat": {
|
191
|
+
"enabled": True,
|
192
|
+
"interval": 300,
|
193
|
+
"timeout": 30,
|
194
|
+
"retry_attempts": 3,
|
195
|
+
"retry_delay": 60
|
196
|
+
},
|
197
|
+
"auto_discovery": {
|
198
|
+
"enabled": False,
|
199
|
+
"discovery_urls": [],
|
200
|
+
"discovery_interval": 3600,
|
201
|
+
"register_on_discovery": True
|
202
|
+
}
|
203
|
+
},
|
204
|
+
|
205
|
+
"logging": {
|
206
|
+
"level": "INFO",
|
207
|
+
"console_output": True,
|
208
|
+
"file_output": False,
|
209
|
+
"file_path": None,
|
210
|
+
"max_file_size": 10,
|
211
|
+
"backup_count": 5,
|
212
|
+
"format": "%(asctime)s - %(name)s - %(levelname)s - %(message)s"
|
213
|
+
},
|
214
|
+
|
215
|
+
"commands": {
|
216
|
+
"auto_discovery": True,
|
217
|
+
"commands_directory": "./commands",
|
218
|
+
"builtin_commands": ["echo", "health", "config"],
|
219
|
+
"custom_commands": [],
|
220
|
+
"command_timeout": 30
|
221
|
+
},
|
222
|
+
|
223
|
+
"hooks": {
|
224
|
+
"enabled": True,
|
225
|
+
"application_hooks": {
|
226
|
+
"on_startup": [],
|
227
|
+
"on_shutdown": [],
|
228
|
+
"before_request": [],
|
229
|
+
"after_request": [],
|
230
|
+
"on_error": []
|
231
|
+
},
|
232
|
+
"command_hooks": {
|
233
|
+
"before_echo_command": [],
|
234
|
+
"after_echo_command": [],
|
235
|
+
"before_health_command": [],
|
236
|
+
"after_health_command": [],
|
237
|
+
"before_config_command": [],
|
238
|
+
"after_config_command": []
|
239
|
+
}
|
240
|
+
},
|
241
|
+
|
242
|
+
"protocols": {
|
243
|
+
"enabled": True,
|
244
|
+
"allowed_protocols": ["http", "https"],
|
245
|
+
"default_protocol": "http",
|
246
|
+
"strict_mode": False
|
247
|
+
}
|
248
|
+
}
|
249
|
+
|
250
|
+
def generate_config_with_comments(self, config_type: str = "full") -> str:
|
251
|
+
"""
|
252
|
+
Generate configuration with detailed comments.
|
253
|
+
|
254
|
+
Args:
|
255
|
+
config_type: Type of configuration to generate
|
256
|
+
- "full": Complete configuration with all options
|
257
|
+
- "minimal": Minimal working configuration
|
258
|
+
- "secure": Secure configuration with all security features
|
259
|
+
- "development": Development configuration with debug enabled
|
260
|
+
- "basic_http": Basic HTTP configuration
|
261
|
+
- "http_token": HTTP with token authentication
|
262
|
+
- "https": HTTPS configuration
|
263
|
+
- "https_token": HTTPS with token authentication
|
264
|
+
- "mtls": mTLS configuration
|
265
|
+
- "optional_ssl": Configuration with optional SSL
|
266
|
+
- "optional_auth": Configuration with optional authentication
|
267
|
+
- "optional_proxy_reg": Configuration with optional proxy registration
|
268
|
+
- "custom": Custom configuration with specified features
|
269
|
+
|
270
|
+
Returns:
|
271
|
+
JSON configuration string with comments
|
272
|
+
"""
|
273
|
+
config = self._get_config_by_type(config_type)
|
274
|
+
|
275
|
+
# Convert to JSON with comments
|
276
|
+
json_str = json.dumps(config, indent=2, ensure_ascii=False)
|
277
|
+
|
278
|
+
# Add comments
|
279
|
+
commented_config = self._add_comments(json_str, config_type)
|
280
|
+
|
281
|
+
return commented_config
|
282
|
+
|
283
|
+
def _get_config_by_type(self, config_type: str) -> Dict[str, Any]:
|
284
|
+
"""Get configuration based on type."""
|
285
|
+
base_config = self.template_config.copy()
|
286
|
+
|
287
|
+
if config_type == "minimal":
|
288
|
+
return self._get_minimal_config(base_config)
|
289
|
+
elif config_type == "secure":
|
290
|
+
return self._get_secure_config(base_config)
|
291
|
+
elif config_type == "development":
|
292
|
+
return self._get_development_config(base_config)
|
293
|
+
elif config_type == "basic_http":
|
294
|
+
return self._get_basic_http_config(base_config)
|
295
|
+
elif config_type == "http_token":
|
296
|
+
return self._get_http_token_config(base_config)
|
297
|
+
elif config_type == "https":
|
298
|
+
return self._get_https_config(base_config)
|
299
|
+
elif config_type == "https_token":
|
300
|
+
return self._get_https_token_config(base_config)
|
301
|
+
elif config_type == "https_no_protocol_middleware":
|
302
|
+
return self._get_https_no_protocol_middleware_config(base_config)
|
303
|
+
elif config_type == "mtls":
|
304
|
+
return self._get_mtls_config(base_config)
|
305
|
+
elif config_type == "mtls_no_protocol_middleware":
|
306
|
+
return self._get_mtls_no_protocol_middleware_config(base_config)
|
307
|
+
elif config_type == "optional_ssl":
|
308
|
+
return self._get_optional_ssl_config(base_config)
|
309
|
+
elif config_type == "optional_auth":
|
310
|
+
return self._get_optional_auth_config(base_config)
|
311
|
+
elif config_type == "optional_proxy_reg":
|
312
|
+
return self._get_optional_proxy_reg_config(base_config)
|
313
|
+
elif config_type == "custom":
|
314
|
+
return self._get_custom_config(base_config)
|
315
|
+
else: # full
|
316
|
+
return base_config
|
317
|
+
|
318
|
+
def _get_minimal_config(self, base_config: Dict[str, Any]) -> Dict[str, Any]:
|
319
|
+
"""Get minimal working configuration."""
|
320
|
+
config = base_config.copy()
|
321
|
+
|
322
|
+
# Disable security for minimal config
|
323
|
+
config["security"]["enabled"] = False
|
324
|
+
config["security"]["auth"]["enabled"] = False
|
325
|
+
config["security"]["permissions"]["enabled"] = False
|
326
|
+
config["security"]["rate_limit"]["enabled"] = False
|
327
|
+
|
328
|
+
# Disable registration for minimal config
|
329
|
+
config["registration"]["enabled"] = False
|
330
|
+
|
331
|
+
# Keep only essential settings
|
332
|
+
config["server"]["port"] = 8000
|
333
|
+
config["server"]["debug"] = False
|
334
|
+
|
335
|
+
return config
|
336
|
+
|
337
|
+
def _get_basic_http_config(self, base_config: Dict[str, Any]) -> Dict[str, Any]:
|
338
|
+
"""Get basic HTTP configuration."""
|
339
|
+
config = base_config.copy()
|
340
|
+
|
341
|
+
# Basic HTTP settings
|
342
|
+
config["server"]["port"] = 8000
|
343
|
+
config["ssl"]["enabled"] = False
|
344
|
+
config["security"]["ssl"]["enabled"] = False
|
345
|
+
config["security"]["auth"]["enabled"] = False
|
346
|
+
config["security"]["permissions"]["enabled"] = False
|
347
|
+
config["security"]["permissions"]["roles_file"] = None
|
348
|
+
config["protocols"]["enabled"] = True
|
349
|
+
config["protocols"]["allowed_protocols"] = ["http"]
|
350
|
+
config["protocols"]["default_protocol"] = "http"
|
351
|
+
|
352
|
+
# Enable local proxy registration by default for examples
|
353
|
+
config["registration"]["enabled"] = True
|
354
|
+
config["registration"]["auth_method"] = "token"
|
355
|
+
config["registration"]["token"]["enabled"] = True
|
356
|
+
config["registration"]["token"]["token"] = "proxy_registration_token_123"
|
357
|
+
config["registration"]["server_url"] = "http://127.0.0.1:3004/proxy"
|
358
|
+
config["registration"]["proxy_info"]["name"] = "mcp_example_server"
|
359
|
+
config["registration"]["proxy_info"]["capabilities"] = [
|
360
|
+
"jsonrpc", "rest", "security", "proxy_registration"
|
361
|
+
]
|
362
|
+
config["registration"]["heartbeat"]["enabled"] = True
|
363
|
+
config["registration"]["heartbeat"]["interval"] = 30
|
364
|
+
|
365
|
+
return config
|
366
|
+
|
367
|
+
def _get_http_token_config(self, base_config: Dict[str, Any]) -> Dict[str, Any]:
|
368
|
+
"""Get HTTP with token authentication configuration."""
|
369
|
+
config = base_config.copy()
|
370
|
+
|
371
|
+
# HTTP with token auth
|
372
|
+
config["server"]["port"] = 8001
|
373
|
+
config["ssl"]["enabled"] = False
|
374
|
+
config["security"]["ssl"]["enabled"] = False
|
375
|
+
config["security"]["auth"]["enabled"] = True
|
376
|
+
config["security"]["auth"]["methods"] = ["api_key"]
|
377
|
+
config["security"]["auth"]["api_keys"] = {
|
378
|
+
"test-token-123": {
|
379
|
+
"roles": ["admin"],
|
380
|
+
"permissions": ["*"],
|
381
|
+
"expires": None
|
382
|
+
},
|
383
|
+
"user-token-456": {
|
384
|
+
"roles": ["user"],
|
385
|
+
"permissions": ["read", "execute"],
|
386
|
+
"expires": None
|
387
|
+
}
|
388
|
+
}
|
389
|
+
config["security"]["permissions"]["enabled"] = True
|
390
|
+
config["security"]["permissions"]["roles_file"] = "mcp_proxy_adapter/examples/server_configs/roles.json"
|
391
|
+
config["protocols"]["enabled"] = True
|
392
|
+
config["protocols"]["allowed_protocols"] = ["http"]
|
393
|
+
config["protocols"]["default_protocol"] = "http"
|
394
|
+
|
395
|
+
return config
|
396
|
+
|
397
|
+
def _get_https_config(self, base_config: Dict[str, Any]) -> Dict[str, Any]:
|
398
|
+
"""Get HTTPS configuration."""
|
399
|
+
config = base_config.copy()
|
400
|
+
|
401
|
+
# HTTPS settings
|
402
|
+
config["server"]["port"] = 8443
|
403
|
+
config["ssl"]["enabled"] = True
|
404
|
+
config["ssl"]["cert_file"] = "mcp_proxy_adapter/examples/certs/server_cert.pem"
|
405
|
+
config["ssl"]["key_file"] = "mcp_proxy_adapter/examples/certs/server_key.pem"
|
406
|
+
config["ssl"]["ca_cert"] = "mcp_proxy_adapter/examples/certs/ca_cert.pem"
|
407
|
+
|
408
|
+
config["security"]["ssl"]["enabled"] = True
|
409
|
+
config["security"]["ssl"]["cert_file"] = "mcp_proxy_adapter/examples/certs/server_cert.pem"
|
410
|
+
config["security"]["ssl"]["key_file"] = "mcp_proxy_adapter/examples/certs/server_key.pem"
|
411
|
+
config["security"]["ssl"]["ca_cert_file"] = "mcp_proxy_adapter/examples/certs/ca_cert.pem"
|
412
|
+
|
413
|
+
config["security"]["auth"]["enabled"] = False
|
414
|
+
config["security"]["permissions"]["enabled"] = False
|
415
|
+
config["security"]["permissions"]["roles_file"] = None
|
416
|
+
config["protocols"]["enabled"] = True
|
417
|
+
config["protocols"]["allowed_protocols"] = ["http", "https"]
|
418
|
+
config["protocols"]["default_protocol"] = "https"
|
419
|
+
|
420
|
+
return config
|
421
|
+
|
422
|
+
def _get_https_token_config(self, base_config: Dict[str, Any]) -> Dict[str, Any]:
|
423
|
+
"""Get HTTPS with token authentication configuration."""
|
424
|
+
config = base_config.copy()
|
425
|
+
|
426
|
+
# HTTPS with token auth
|
427
|
+
config["server"]["port"] = 8444
|
428
|
+
config["ssl"]["enabled"] = True
|
429
|
+
config["ssl"]["cert_file"] = "mcp_proxy_adapter/examples/certs/server_cert.pem"
|
430
|
+
config["ssl"]["key_file"] = "mcp_proxy_adapter/examples/certs/server_key.pem"
|
431
|
+
config["ssl"]["ca_cert"] = "mcp_proxy_adapter/examples/certs/ca_cert.pem"
|
432
|
+
|
433
|
+
config["security"]["ssl"]["enabled"] = True
|
434
|
+
config["security"]["ssl"]["cert_file"] = "mcp_proxy_adapter/examples/certs/server_cert.pem"
|
435
|
+
config["security"]["ssl"]["key_file"] = "mcp_proxy_adapter/examples/certs/server_key.pem"
|
436
|
+
config["security"]["ssl"]["ca_cert_file"] = "mcp_proxy_adapter/examples/certs/ca_cert.pem"
|
437
|
+
|
438
|
+
config["security"]["auth"]["enabled"] = True
|
439
|
+
config["security"]["auth"]["methods"] = ["api_key"]
|
440
|
+
config["security"]["auth"]["api_keys"] = {
|
441
|
+
"test-token-123": {
|
442
|
+
"roles": ["admin"],
|
443
|
+
"permissions": ["*"],
|
444
|
+
"expires": None
|
445
|
+
},
|
446
|
+
"user-token-456": {
|
447
|
+
"roles": ["user"],
|
448
|
+
"permissions": ["read", "execute"],
|
449
|
+
"expires": None
|
450
|
+
}
|
451
|
+
}
|
452
|
+
config["security"]["permissions"]["enabled"] = True
|
453
|
+
config["security"]["permissions"]["roles_file"] = "mcp_proxy_adapter/examples/server_configs/roles.json"
|
454
|
+
config["protocols"]["enabled"] = True
|
455
|
+
config["protocols"]["allowed_protocols"] = ["http", "https"]
|
456
|
+
config["protocols"]["default_protocol"] = "https"
|
457
|
+
|
458
|
+
return config
|
459
|
+
|
460
|
+
def _get_mtls_config(self, base_config: Dict[str, Any]) -> Dict[str, Any]:
|
461
|
+
"""Get mTLS configuration."""
|
462
|
+
config = base_config.copy()
|
463
|
+
|
464
|
+
# mTLS settings
|
465
|
+
config["server"]["port"] = 8445
|
466
|
+
config["ssl"]["enabled"] = True
|
467
|
+
config["ssl"]["cert_file"] = "mcp_proxy_adapter/examples/certs/server_cert.pem"
|
468
|
+
config["ssl"]["key_file"] = "mcp_proxy_adapter/examples/certs/server_key.pem"
|
469
|
+
config["ssl"]["ca_cert"] = "mcp_proxy_adapter/examples/certs/ca_cert.pem"
|
470
|
+
config["ssl"]["verify_client"] = True
|
471
|
+
config["ssl"]["client_cert_required"] = True
|
472
|
+
|
473
|
+
config["security"]["ssl"]["enabled"] = True
|
474
|
+
config["security"]["ssl"]["cert_file"] = "mcp_proxy_adapter/examples/certs/server_cert.pem"
|
475
|
+
config["security"]["ssl"]["key_file"] = "mcp_proxy_adapter/examples/certs/server_key.pem"
|
476
|
+
config["security"]["ssl"]["ca_cert_file"] = "mcp_proxy_adapter/examples/certs/ca_cert.pem"
|
477
|
+
config["security"]["ssl"]["client_cert_file"] = "mcp_proxy_adapter/examples/certs/client_cert.pem"
|
478
|
+
config["security"]["ssl"]["client_key_file"] = "mcp_proxy_adapter/examples/certs/client_key.pem"
|
479
|
+
config["security"]["ssl"]["verify_mode"] = "CERT_REQUIRED"
|
480
|
+
|
481
|
+
config["security"]["auth"]["enabled"] = True
|
482
|
+
config["security"]["auth"]["methods"] = ["certificate"]
|
483
|
+
config["security"]["auth"]["certificate_auth"] = True
|
484
|
+
config["security"]["permissions"]["enabled"] = True
|
485
|
+
config["security"]["permissions"]["roles_file"] = "mcp_proxy_adapter/examples/server_configs/roles.json"
|
486
|
+
config["protocols"]["enabled"] = True
|
487
|
+
config["protocols"]["allowed_protocols"] = ["https", "mtls"]
|
488
|
+
config["protocols"]["default_protocol"] = "https"
|
489
|
+
|
490
|
+
return config
|
491
|
+
|
492
|
+
def _get_https_no_protocol_middleware_config(self, base_config: Dict[str, Any]) -> Dict[str, Any]:
|
493
|
+
"""Get HTTPS configuration without ProtocolMiddleware."""
|
494
|
+
config = base_config.copy()
|
495
|
+
|
496
|
+
# HTTPS settings
|
497
|
+
config["server"]["port"] = 8445
|
498
|
+
config["ssl"]["enabled"] = True
|
499
|
+
config["ssl"]["cert_file"] = "mcp_proxy_adapter/examples/certs/server_cert.pem"
|
500
|
+
config["ssl"]["key_file"] = "mcp_proxy_adapter/examples/certs/server_key.pem"
|
501
|
+
config["ssl"]["ca_cert"] = "mcp_proxy_adapter/examples/certs/ca_cert.pem"
|
502
|
+
|
503
|
+
config["security"]["ssl"]["enabled"] = True
|
504
|
+
config["security"]["ssl"]["cert_file"] = "mcp_proxy_adapter/examples/certs/server_cert.pem"
|
505
|
+
config["security"]["ssl"]["key_file"] = "mcp_proxy_adapter/examples/certs/server_key.pem"
|
506
|
+
config["security"]["ssl"]["ca_cert_file"] = "mcp_proxy_adapter/examples/certs/ca_cert.pem"
|
507
|
+
|
508
|
+
config["security"]["auth"]["enabled"] = True
|
509
|
+
config["security"]["auth"]["methods"] = ["api_key"]
|
510
|
+
config["security"]["auth"]["api_keys"] = {
|
511
|
+
"test-token-123": {
|
512
|
+
"roles": ["admin"],
|
513
|
+
"permissions": ["*"],
|
514
|
+
"expires": None
|
515
|
+
},
|
516
|
+
"user-token-456": {
|
517
|
+
"roles": ["user"],
|
518
|
+
"permissions": ["read", "execute"],
|
519
|
+
"expires": None
|
520
|
+
}
|
521
|
+
}
|
522
|
+
config["security"]["permissions"]["enabled"] = True
|
523
|
+
config["security"]["permissions"]["roles_file"] = "mcp_proxy_adapter/examples/server_configs/roles.json"
|
524
|
+
config["protocols"]["enabled"] = False # Disable ProtocolMiddleware
|
525
|
+
|
526
|
+
return config
|
527
|
+
|
528
|
+
def _get_mtls_no_protocol_middleware_config(self, base_config: Dict[str, Any]) -> Dict[str, Any]:
|
529
|
+
"""Get mTLS configuration without ProtocolMiddleware."""
|
530
|
+
config = base_config.copy()
|
531
|
+
|
532
|
+
# mTLS settings
|
533
|
+
config["server"]["port"] = 8447
|
534
|
+
config["ssl"]["enabled"] = True
|
535
|
+
config["ssl"]["cert_file"] = "mcp_proxy_adapter/examples/certs/server_cert.pem"
|
536
|
+
config["ssl"]["key_file"] = "mcp_proxy_adapter/examples/certs/server_key.pem"
|
537
|
+
config["ssl"]["ca_cert"] = "mcp_proxy_adapter/examples/certs/ca_cert.pem"
|
538
|
+
config["ssl"]["verify_client"] = True
|
539
|
+
config["ssl"]["client_cert_required"] = True
|
540
|
+
|
541
|
+
config["security"]["ssl"]["enabled"] = True
|
542
|
+
config["security"]["ssl"]["cert_file"] = "mcp_proxy_adapter/examples/certs/server_cert.pem"
|
543
|
+
config["security"]["ssl"]["key_file"] = "mcp_proxy_adapter/examples/certs/server_key.pem"
|
544
|
+
config["security"]["ssl"]["ca_cert_file"] = "mcp_proxy_adapter/examples/certs/ca_cert.pem"
|
545
|
+
config["security"]["ssl"]["client_cert_file"] = "mcp_proxy_adapter/examples/certs/client_cert.pem"
|
546
|
+
config["security"]["ssl"]["client_key_file"] = "mcp_proxy_adapter/examples/certs/client_key.pem"
|
547
|
+
config["security"]["ssl"]["verify_mode"] = "CERT_REQUIRED"
|
548
|
+
|
549
|
+
config["security"]["auth"]["enabled"] = True
|
550
|
+
config["security"]["auth"]["methods"] = ["certificate"]
|
551
|
+
config["security"]["auth"]["certificate_auth"] = True
|
552
|
+
config["security"]["permissions"]["enabled"] = True
|
553
|
+
config["security"]["permissions"]["roles_file"] = "mcp_proxy_adapter/examples/server_configs/roles.json"
|
554
|
+
config["protocols"]["enabled"] = False # Disable ProtocolMiddleware
|
555
|
+
|
556
|
+
return config
|
557
|
+
|
558
|
+
def _get_optional_ssl_config(self, base_config: Dict[str, Any]) -> Dict[str, Any]:
|
559
|
+
"""Get configuration with optional SSL support."""
|
560
|
+
config = base_config.copy()
|
561
|
+
|
562
|
+
# Server configuration
|
563
|
+
config["server"]["port"] = 8000
|
564
|
+
|
565
|
+
# SSL configuration - can be enabled/disabled via environment or config
|
566
|
+
config["ssl"]["enabled"] = False # Default disabled, can be enabled
|
567
|
+
config["ssl"]["cert_file"] = "mcp_proxy_adapter/examples/certs/server_cert.pem"
|
568
|
+
config["ssl"]["key_file"] = "mcp_proxy_adapter/examples/certs/server_key.pem"
|
569
|
+
config["ssl"]["ca_cert"] = "mcp_proxy_adapter/examples/certs/ca_cert.pem"
|
570
|
+
config["ssl"]["verify_client"] = False # Can be enabled for mTLS
|
571
|
+
|
572
|
+
# Security framework SSL - mirrors main SSL config
|
573
|
+
config["security"]["ssl"]["enabled"] = False # Default disabled
|
574
|
+
config["security"]["ssl"]["cert_file"] = "mcp_proxy_adapter/examples/certs/server_cert.pem"
|
575
|
+
config["security"]["ssl"]["key_file"] = "mcp_proxy_adapter/examples/certs/server_key.pem"
|
576
|
+
config["security"]["ssl"]["ca_cert_file"] = "mcp_proxy_adapter/examples/certs/ca_cert.pem"
|
577
|
+
config["security"]["ssl"]["client_cert_file"] = "mcp_proxy_adapter/examples/certs/client_cert.pem"
|
578
|
+
config["security"]["ssl"]["client_key_file"] = "mcp_proxy_adapter/examples/certs/client_key.key"
|
579
|
+
|
580
|
+
# Protocols support both HTTP and HTTPS
|
581
|
+
config["protocols"]["enabled"] = True
|
582
|
+
config["protocols"]["allowed_protocols"] = ["http", "https"]
|
583
|
+
config["protocols"]["default_protocol"] = "http"
|
584
|
+
|
585
|
+
# Enable proxy registration with token auth
|
586
|
+
config["registration"]["enabled"] = True
|
587
|
+
config["registration"]["auth_method"] = "token"
|
588
|
+
config["registration"]["token"]["enabled"] = True
|
589
|
+
config["registration"]["token"]["token"] = "proxy_registration_token_123"
|
590
|
+
config["registration"]["server_url"] = "http://127.0.0.1:3004/proxy"
|
591
|
+
|
592
|
+
return config
|
593
|
+
|
594
|
+
def _get_optional_auth_config(self, base_config: Dict[str, Any]) -> Dict[str, Any]:
|
595
|
+
"""Get configuration with optional authentication support."""
|
596
|
+
config = base_config.copy()
|
597
|
+
|
598
|
+
# Server configuration
|
599
|
+
config["server"]["port"] = 8001
|
600
|
+
|
601
|
+
# SSL disabled by default
|
602
|
+
config["ssl"]["enabled"] = False
|
603
|
+
config["security"]["ssl"]["enabled"] = False
|
604
|
+
|
605
|
+
# Authentication configuration - can be enabled/disabled
|
606
|
+
config["security"]["auth"]["enabled"] = False # Default disabled
|
607
|
+
config["security"]["auth"]["methods"] = ["api_key", "jwt"] # Available methods
|
608
|
+
|
609
|
+
# API keys configuration
|
610
|
+
config["security"]["auth"]["api_keys"] = {
|
611
|
+
"admin-token": {
|
612
|
+
"roles": ["admin"],
|
613
|
+
"permissions": ["*"],
|
614
|
+
"expires": None
|
615
|
+
},
|
616
|
+
"user-token": {
|
617
|
+
"roles": ["user"],
|
618
|
+
"permissions": ["read", "execute"],
|
619
|
+
"expires": None
|
620
|
+
},
|
621
|
+
"guest-token": {
|
622
|
+
"roles": ["guest"],
|
623
|
+
"permissions": ["read"],
|
624
|
+
"expires": None
|
625
|
+
}
|
626
|
+
}
|
627
|
+
|
628
|
+
# JWT configuration
|
629
|
+
config["security"]["auth"]["jwt_secret"] = "your_jwt_secret_here"
|
630
|
+
config["security"]["auth"]["jwt_algorithm"] = "HS256"
|
631
|
+
config["security"]["auth"]["jwt_expiry_hours"] = 24
|
632
|
+
|
633
|
+
# User roles mapping
|
634
|
+
config["security"]["auth"]["user_roles"] = {
|
635
|
+
"admin": ["admin"],
|
636
|
+
"user": ["user"],
|
637
|
+
"guest": ["guest"]
|
638
|
+
}
|
639
|
+
|
640
|
+
# Permissions configuration - can be enabled/disabled
|
641
|
+
config["security"]["permissions"]["enabled"] = False # Default disabled
|
642
|
+
config["security"]["permissions"]["roles_file"] = "mcp_proxy_adapter/examples/server_configs/roles.json"
|
643
|
+
config["security"]["permissions"]["default_role"] = "guest"
|
644
|
+
config["security"]["permissions"]["admin_role"] = "admin"
|
645
|
+
|
646
|
+
# Protocols
|
647
|
+
config["protocols"]["enabled"] = True
|
648
|
+
config["protocols"]["allowed_protocols"] = ["http"]
|
649
|
+
config["protocols"]["default_protocol"] = "http"
|
650
|
+
|
651
|
+
# Enable proxy registration
|
652
|
+
config["registration"]["enabled"] = True
|
653
|
+
config["registration"]["auth_method"] = "token"
|
654
|
+
config["registration"]["token"]["enabled"] = True
|
655
|
+
config["registration"]["token"]["token"] = "proxy_registration_token_123"
|
656
|
+
|
657
|
+
return config
|
658
|
+
|
659
|
+
def _get_optional_proxy_reg_config(self, base_config: Dict[str, Any]) -> Dict[str, Any]:
|
660
|
+
"""Get configuration with optional proxy registration support."""
|
661
|
+
config = base_config.copy()
|
662
|
+
|
663
|
+
# Server configuration
|
664
|
+
config["server"]["port"] = 8002
|
665
|
+
|
666
|
+
# SSL disabled by default
|
667
|
+
config["ssl"]["enabled"] = False
|
668
|
+
config["security"]["ssl"]["enabled"] = False
|
669
|
+
|
670
|
+
# Authentication disabled by default
|
671
|
+
config["security"]["auth"]["enabled"] = False
|
672
|
+
config["security"]["permissions"]["enabled"] = False
|
673
|
+
|
674
|
+
# Proxy registration configuration - can be enabled/disabled
|
675
|
+
config["registration"]["enabled"] = False # Default disabled
|
676
|
+
config["registration"]["server_url"] = "http://127.0.0.1:3004/proxy"
|
677
|
+
config["registration"]["server_id"] = "mcp_proxy_adapter"
|
678
|
+
config["registration"]["server_name"] = "MCP Proxy Adapter"
|
679
|
+
config["registration"]["description"] = "JSON-RPC API for interacting with MCP Proxy"
|
680
|
+
|
681
|
+
# Multiple authentication methods for proxy registration
|
682
|
+
config["registration"]["auth_method"] = "token" # Default method
|
683
|
+
|
684
|
+
# Token authentication
|
685
|
+
config["registration"]["token"]["enabled"] = True
|
686
|
+
config["registration"]["token"]["token"] = "proxy_registration_token_123"
|
687
|
+
config["registration"]["token"]["token_type"] = "bearer"
|
688
|
+
config["registration"]["token"]["refresh_interval"] = 3600
|
689
|
+
|
690
|
+
# Certificate authentication
|
691
|
+
config["registration"]["certificate"]["enabled"] = False
|
692
|
+
config["registration"]["certificate"]["cert_file"] = "mcp_proxy_adapter/examples/certs/proxy_client.crt"
|
693
|
+
config["registration"]["certificate"]["key_file"] = "mcp_proxy_adapter/examples/keys/proxy_client.key"
|
694
|
+
config["registration"]["certificate"]["ca_cert_file"] = "mcp_proxy_adapter/examples/certs/ca.crt"
|
695
|
+
config["registration"]["certificate"]["verify_server"] = True
|
696
|
+
|
697
|
+
# API key authentication
|
698
|
+
config["registration"]["api_key"]["enabled"] = False
|
699
|
+
config["registration"]["api_key"]["key"] = "proxy_api_key_456"
|
700
|
+
config["registration"]["api_key"]["key_header"] = "X-Proxy-API-Key"
|
701
|
+
|
702
|
+
# Proxy information
|
703
|
+
config["registration"]["proxy_info"]["name"] = "mcp_proxy_adapter"
|
704
|
+
config["registration"]["proxy_info"]["version"] = "1.0.0"
|
705
|
+
config["registration"]["proxy_info"]["description"] = "MCP Proxy Adapter with optional features"
|
706
|
+
config["registration"]["proxy_info"]["capabilities"] = ["jsonrpc", "rest", "optional_features"]
|
707
|
+
config["registration"]["proxy_info"]["endpoints"] = {
|
708
|
+
"jsonrpc": "/api/jsonrpc",
|
709
|
+
"rest": "/cmd",
|
710
|
+
"health": "/health"
|
711
|
+
}
|
712
|
+
|
713
|
+
# Heartbeat configuration
|
714
|
+
config["registration"]["heartbeat"]["enabled"] = True
|
715
|
+
config["registration"]["heartbeat"]["interval"] = 300
|
716
|
+
config["registration"]["heartbeat"]["timeout"] = 30
|
717
|
+
config["registration"]["heartbeat"]["retry_attempts"] = 3
|
718
|
+
config["registration"]["heartbeat"]["retry_delay"] = 60
|
719
|
+
|
720
|
+
# Auto-discovery
|
721
|
+
config["registration"]["auto_discovery"]["enabled"] = False
|
722
|
+
config["registration"]["auto_discovery"]["discovery_urls"] = []
|
723
|
+
config["registration"]["auto_discovery"]["discovery_interval"] = 3600
|
724
|
+
config["registration"]["auto_discovery"]["register_on_discovery"] = True
|
725
|
+
|
726
|
+
# Protocols
|
727
|
+
config["protocols"]["enabled"] = True
|
728
|
+
config["protocols"]["allowed_protocols"] = ["http"]
|
729
|
+
config["protocols"]["default_protocol"] = "http"
|
730
|
+
|
731
|
+
return config
|
732
|
+
|
733
|
+
def _get_custom_config(self, base_config: Dict[str, Any]) -> Dict[str, Any]:
|
734
|
+
"""Get custom configuration with configurable features."""
|
735
|
+
config = base_config.copy()
|
736
|
+
|
737
|
+
# Server configuration
|
738
|
+
config["server"]["port"] = 8003
|
739
|
+
|
740
|
+
# SSL configuration - configurable
|
741
|
+
config["ssl"]["enabled"] = False # Can be enabled via config
|
742
|
+
config["ssl"]["cert_file"] = "mcp_proxy_adapter/examples/certs/server_cert.pem"
|
743
|
+
config["ssl"]["key_file"] = "mcp_proxy_adapter/examples/certs/server_key.pem"
|
744
|
+
config["ssl"]["ca_cert"] = "mcp_proxy_adapter/examples/certs/ca_cert.pem"
|
745
|
+
config["ssl"]["verify_client"] = False # Can be enabled for mTLS
|
746
|
+
|
747
|
+
# Security framework - configurable
|
748
|
+
config["security"]["enabled"] = False # Can be enabled via config
|
749
|
+
config["security"]["ssl"]["enabled"] = False # Mirrors main SSL
|
750
|
+
config["security"]["ssl"]["cert_file"] = "mcp_proxy_adapter/examples/certs/server_cert.pem"
|
751
|
+
config["security"]["ssl"]["key_file"] = "mcp_proxy_adapter/examples/certs/server_key.pem"
|
752
|
+
config["security"]["ssl"]["ca_cert_file"] = "mcp_proxy_adapter/examples/certs/ca_cert.pem"
|
753
|
+
|
754
|
+
# Authentication - configurable
|
755
|
+
config["security"]["auth"]["enabled"] = False # Can be enabled via config
|
756
|
+
config["security"]["auth"]["methods"] = ["api_key", "jwt", "certificate"]
|
757
|
+
config["security"]["auth"]["api_keys"] = {
|
758
|
+
"custom-admin": {
|
759
|
+
"roles": ["admin"],
|
760
|
+
"permissions": ["*"],
|
761
|
+
"expires": None
|
762
|
+
},
|
763
|
+
"custom-user": {
|
764
|
+
"roles": ["user"],
|
765
|
+
"permissions": ["read", "execute"],
|
766
|
+
"expires": None
|
767
|
+
}
|
768
|
+
}
|
769
|
+
|
770
|
+
# Permissions - configurable
|
771
|
+
config["security"]["permissions"]["enabled"] = False # Can be enabled via config
|
772
|
+
config["security"]["permissions"]["roles_file"] = "mcp_proxy_adapter/examples/server_configs/roles.json"
|
773
|
+
|
774
|
+
# Rate limiting - configurable
|
775
|
+
config["security"]["rate_limit"]["enabled"] = False # Can be enabled via config
|
776
|
+
config["security"]["rate_limit"]["default_requests_per_minute"] = 60
|
777
|
+
config["security"]["rate_limit"]["default_requests_per_hour"] = 1000
|
778
|
+
|
779
|
+
# Certificates - configurable
|
780
|
+
config["security"]["certificates"]["enabled"] = False # Can be enabled via config
|
781
|
+
config["security"]["certificates"]["cert_storage_path"] = "./certs"
|
782
|
+
config["security"]["certificates"]["key_storage_path"] = "./keys"
|
783
|
+
|
784
|
+
# Proxy registration - configurable
|
785
|
+
config["registration"]["enabled"] = False # Can be enabled via config
|
786
|
+
config["registration"]["auth_method"] = "token"
|
787
|
+
config["registration"]["token"]["enabled"] = True
|
788
|
+
config["registration"]["token"]["token"] = "custom_proxy_token"
|
789
|
+
|
790
|
+
# Protocols
|
791
|
+
config["protocols"]["enabled"] = True
|
792
|
+
config["protocols"]["allowed_protocols"] = ["http", "https"]
|
793
|
+
config["protocols"]["default_protocol"] = "http"
|
794
|
+
|
795
|
+
return config
|
796
|
+
|
797
|
+
def _get_secure_config(self, base_config: Dict[str, Any]) -> Dict[str, Any]:
|
798
|
+
"""Get secure configuration with all security features enabled."""
|
799
|
+
config = base_config.copy()
|
800
|
+
|
801
|
+
# Enable all security features
|
802
|
+
config["security"]["enabled"] = True
|
803
|
+
config["security"]["ssl"]["enabled"] = True
|
804
|
+
config["security"]["auth"]["enabled"] = True
|
805
|
+
config["security"]["permissions"]["enabled"] = True
|
806
|
+
config["security"]["rate_limit"]["enabled"] = True
|
807
|
+
|
808
|
+
# Enable registration with certificate auth
|
809
|
+
config["registration"]["enabled"] = True
|
810
|
+
config["registration"]["auth_method"] = "certificate"
|
811
|
+
config["registration"]["certificate"]["enabled"] = True
|
812
|
+
|
813
|
+
# Set secure defaults
|
814
|
+
config["security"]["ssl"]["min_tls_version"] = "TLSv1.2"
|
815
|
+
config["security"]["auth"]["methods"] = ["api_key", "jwt"]
|
816
|
+
config["security"]["permissions"]["strict_mode"] = True
|
817
|
+
config["security"]["rate_limit"]["burst_limit"] = 1
|
818
|
+
|
819
|
+
return config
|
820
|
+
|
821
|
+
def _get_development_config(self, base_config: Dict[str, Any]) -> Dict[str, Any]:
|
822
|
+
"""Get development configuration with debug enabled."""
|
823
|
+
config = base_config.copy()
|
824
|
+
|
825
|
+
# Enable debug features
|
826
|
+
config["server"]["debug"] = True
|
827
|
+
config["security"]["debug"] = True
|
828
|
+
config["logging"]["level"] = "DEBUG"
|
829
|
+
|
830
|
+
# Enable registration with token auth for development
|
831
|
+
config["registration"]["enabled"] = True
|
832
|
+
config["registration"]["auth_method"] = "token"
|
833
|
+
config["registration"]["token"]["enabled"] = True
|
834
|
+
|
835
|
+
# Relax security for development
|
836
|
+
config["security"]["rate_limit"]["default_requests_per_minute"] = 1000
|
837
|
+
config["security"]["permissions"]["strict_mode"] = False
|
838
|
+
|
839
|
+
return config
|
840
|
+
|
841
|
+
def _add_comments(self, json_str: str, config_type: str) -> str:
|
842
|
+
"""Add comments to JSON configuration."""
|
843
|
+
comments = self._get_comments_for_type(config_type)
|
844
|
+
|
845
|
+
# Add header comment
|
846
|
+
commented_config = f"""/**
|
847
|
+
* MCP Proxy Adapter Configuration
|
848
|
+
*
|
849
|
+
* This configuration file combines settings for both mcp_proxy_adapter
|
850
|
+
* and mcp_security_framework in a unified format.
|
851
|
+
*
|
852
|
+
* Configuration Type: {config_type.title()}
|
853
|
+
* Generated by: ConfigGenerator
|
854
|
+
*
|
855
|
+
* IMPORTANT: This is a template configuration. Please customize it
|
856
|
+
* according to your specific requirements and security needs.
|
857
|
+
*/
|
858
|
+
|
859
|
+
"""
|
860
|
+
|
861
|
+
# Add section comments
|
862
|
+
for section, comment in comments.items():
|
863
|
+
if section in json_str:
|
864
|
+
# Find the section and add comment before it
|
865
|
+
section_start = json_str.find(f'"{section}":')
|
866
|
+
if section_start != -1:
|
867
|
+
# Find the line start
|
868
|
+
line_start = json_str.rfind('\n', 0, section_start) + 1
|
869
|
+
json_str = (
|
870
|
+
json_str[:line_start] +
|
871
|
+
f" // {comment}\n" +
|
872
|
+
json_str[line_start:]
|
873
|
+
)
|
874
|
+
|
875
|
+
return commented_config + json_str
|
876
|
+
|
877
|
+
def _get_comments_for_type(self, config_type: str) -> Dict[str, str]:
|
878
|
+
"""Get comments for configuration sections."""
|
879
|
+
base_comments = {
|
880
|
+
"server": "Server configuration for FastAPI application",
|
881
|
+
"ssl": "SSL/TLS configuration for secure connections",
|
882
|
+
"security": "Security framework configuration (mcp_security_framework)",
|
883
|
+
"registration": "Proxy registration configuration for secure proxy discovery",
|
884
|
+
"logging": "Logging configuration for the application",
|
885
|
+
"commands": "Command management and discovery settings",
|
886
|
+
"hooks": "Application and command hooks configuration",
|
887
|
+
"protocols": "Protocol endpoints and settings"
|
888
|
+
}
|
889
|
+
|
890
|
+
if config_type == "minimal":
|
891
|
+
base_comments["security"] = "Security framework configuration (disabled for minimal setup)"
|
892
|
+
base_comments["registration"] = "Proxy registration configuration (disabled for minimal setup)"
|
893
|
+
elif config_type == "secure":
|
894
|
+
base_comments["security"] = "Security framework configuration (all features enabled)"
|
895
|
+
base_comments["registration"] = "Proxy registration configuration (certificate authentication enabled)"
|
896
|
+
elif config_type == "development":
|
897
|
+
base_comments["security"] = "Security framework configuration (development mode with relaxed settings)"
|
898
|
+
base_comments["registration"] = "Proxy registration configuration (token authentication for development)"
|
899
|
+
elif config_type in ["basic_http", "http_token"]:
|
900
|
+
base_comments["ssl"] = "SSL/TLS configuration (disabled for HTTP)"
|
901
|
+
base_comments["security"] = f"Security framework configuration ({config_type} mode)"
|
902
|
+
elif config_type in ["https", "https_token"]:
|
903
|
+
base_comments["ssl"] = "SSL/TLS configuration (enabled for HTTPS)"
|
904
|
+
base_comments["security"] = f"Security framework configuration ({config_type} mode)"
|
905
|
+
elif config_type == "mtls":
|
906
|
+
base_comments["ssl"] = "SSL/TLS configuration (enabled for mTLS with client certificate verification)"
|
907
|
+
base_comments["security"] = "Security framework configuration (mTLS mode with certificate authentication)"
|
908
|
+
elif config_type == "https_no_protocol_middleware":
|
909
|
+
base_comments["ssl"] = "SSL/TLS configuration (enabled for HTTPS without ProtocolMiddleware)"
|
910
|
+
base_comments["security"] = "Security framework configuration (HTTPS mode without ProtocolMiddleware)"
|
911
|
+
elif config_type == "mtls_no_protocol_middleware":
|
912
|
+
base_comments["ssl"] = "SSL/TLS configuration (enabled for mTLS without ProtocolMiddleware)"
|
913
|
+
base_comments["security"] = "Security framework configuration (mTLS mode without ProtocolMiddleware)"
|
914
|
+
elif config_type == "optional_ssl":
|
915
|
+
base_comments["ssl"] = "SSL/TLS configuration (optional, can be enabled/disabled)"
|
916
|
+
base_comments["security"] = "Security framework SSL configuration (mirrors main SSL)"
|
917
|
+
elif config_type == "optional_auth":
|
918
|
+
base_comments["ssl"] = "SSL/TLS configuration (disabled for optional auth)"
|
919
|
+
base_comments["security"] = "Security framework authentication configuration (optional, can be enabled/disabled)"
|
920
|
+
elif config_type == "optional_proxy_reg":
|
921
|
+
base_comments["ssl"] = "SSL/TLS configuration (disabled for optional proxy reg)"
|
922
|
+
base_comments["security"] = "Security framework proxy registration configuration (optional, can be enabled/disabled)"
|
923
|
+
elif config_type == "custom":
|
924
|
+
base_comments["ssl"] = "SSL/TLS configuration (configurable)"
|
925
|
+
base_comments["security"] = "Security framework configuration (configurable)"
|
926
|
+
base_comments["registration"] = "Proxy registration configuration (configurable)"
|
927
|
+
base_comments["protocols"] = "Protocol endpoints and settings (configurable)"
|
928
|
+
|
929
|
+
return base_comments
|
930
|
+
|
931
|
+
def generate_config_file(self, output_path: str, config_type: str = "full") -> None:
|
932
|
+
"""
|
933
|
+
Generate configuration file and save to disk.
|
934
|
+
|
935
|
+
Args:
|
936
|
+
output_path: Path to save the configuration file
|
937
|
+
config_type: Type of configuration to generate
|
938
|
+
"""
|
939
|
+
try:
|
940
|
+
# Get configuration without comments for file generation
|
941
|
+
config = self._get_config_by_type(config_type)
|
942
|
+
|
943
|
+
# Create directory if it doesn't exist
|
944
|
+
output_file = Path(output_path)
|
945
|
+
output_file.parent.mkdir(parents=True, exist_ok=True)
|
946
|
+
|
947
|
+
# Write configuration file as clean JSON
|
948
|
+
with open(output_file, 'w', encoding='utf-8') as f:
|
949
|
+
json.dump(config, f, indent=2, ensure_ascii=False)
|
950
|
+
|
951
|
+
logger.info(f"Configuration file generated: {output_path}")
|
952
|
+
logger.info(f"Configuration type: {config_type}")
|
953
|
+
|
954
|
+
except Exception as e:
|
955
|
+
logger.error(f"Failed to generate configuration file: {e}")
|
956
|
+
raise
|
957
|
+
|
958
|
+
def generate_all_configs(self, output_dir: str) -> None:
|
959
|
+
"""
|
960
|
+
Generate all configuration types.
|
961
|
+
|
962
|
+
Args:
|
963
|
+
output_dir: Directory to save configuration files
|
964
|
+
"""
|
965
|
+
config_types = [
|
966
|
+
"minimal", "development", "secure", "full",
|
967
|
+
"basic_http", "http_token", "https", "https_token", "mtls",
|
968
|
+
"https_no_protocol_middleware", "mtls_no_protocol_middleware",
|
969
|
+
"optional_ssl", "optional_auth", "optional_proxy_reg", "custom"
|
970
|
+
]
|
971
|
+
|
972
|
+
for config_type in config_types:
|
973
|
+
output_path = Path(output_dir) / f"config_{config_type}.json"
|
974
|
+
self.generate_config_file(str(output_path), config_type)
|
975
|
+
|
976
|
+
logger.info(f"Generated {len(config_types)} configuration files in {output_dir}")
|
977
|
+
|
978
|
+
|
979
|
+
def main():
|
980
|
+
"""Main function for command-line usage."""
|
981
|
+
import argparse
|
982
|
+
|
983
|
+
parser = argparse.ArgumentParser(description="Generate MCP Proxy Adapter configuration files")
|
984
|
+
parser.add_argument("--type",
|
985
|
+
choices=["minimal", "development", "secure", "full",
|
986
|
+
"basic_http", "http_token", "https", "https_token", "mtls",
|
987
|
+
"https_no_protocol_middleware", "mtls_no_protocol_middleware",
|
988
|
+
"optional_ssl", "optional_auth", "optional_proxy_reg", "custom"],
|
989
|
+
default="full", help="Configuration type to generate")
|
990
|
+
parser.add_argument("--output", default="./config.json",
|
991
|
+
help="Output file path")
|
992
|
+
parser.add_argument("--all", action="store_true",
|
993
|
+
help="Generate all configuration types")
|
994
|
+
parser.add_argument("--output-dir", default="./configs",
|
995
|
+
help="Output directory for all configs")
|
996
|
+
|
997
|
+
args = parser.parse_args()
|
998
|
+
|
999
|
+
generator = ConfigGenerator()
|
1000
|
+
|
1001
|
+
if args.all:
|
1002
|
+
generator.generate_all_configs(args.output_dir)
|
1003
|
+
else:
|
1004
|
+
generator.generate_config_file(args.output, args.type)
|
1005
|
+
|
1006
|
+
|
1007
|
+
if __name__ == "__main__":
|
1008
|
+
main()
|