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.
Files changed (200) hide show
  1. mcp_proxy_adapter/__main__.py +32 -0
  2. mcp_proxy_adapter/api/app.py +290 -33
  3. mcp_proxy_adapter/api/handlers.py +32 -6
  4. mcp_proxy_adapter/api/middleware/__init__.py +38 -32
  5. mcp_proxy_adapter/api/middleware/command_permission_middleware.py +148 -0
  6. mcp_proxy_adapter/api/middleware/error_handling.py +9 -0
  7. mcp_proxy_adapter/api/middleware/factory.py +243 -0
  8. mcp_proxy_adapter/api/middleware/logging.py +32 -6
  9. mcp_proxy_adapter/api/middleware/protocol_middleware.py +201 -0
  10. mcp_proxy_adapter/api/middleware/transport_middleware.py +122 -0
  11. mcp_proxy_adapter/api/middleware/unified_security.py +197 -0
  12. mcp_proxy_adapter/api/middleware/user_info_middleware.py +158 -0
  13. mcp_proxy_adapter/commands/__init__.py +19 -4
  14. mcp_proxy_adapter/commands/auth_validation_command.py +408 -0
  15. mcp_proxy_adapter/commands/base.py +66 -32
  16. mcp_proxy_adapter/commands/builtin_commands.py +95 -0
  17. mcp_proxy_adapter/commands/catalog_manager.py +838 -0
  18. mcp_proxy_adapter/commands/cert_monitor_command.py +620 -0
  19. mcp_proxy_adapter/commands/certificate_management_command.py +608 -0
  20. mcp_proxy_adapter/commands/command_registry.py +711 -354
  21. mcp_proxy_adapter/commands/dependency_manager.py +245 -0
  22. mcp_proxy_adapter/commands/echo_command.py +81 -0
  23. mcp_proxy_adapter/commands/health_command.py +8 -1
  24. mcp_proxy_adapter/commands/help_command.py +21 -14
  25. mcp_proxy_adapter/commands/hooks.py +200 -167
  26. mcp_proxy_adapter/commands/key_management_command.py +506 -0
  27. mcp_proxy_adapter/commands/load_command.py +176 -0
  28. mcp_proxy_adapter/commands/plugins_command.py +235 -0
  29. mcp_proxy_adapter/commands/protocol_management_command.py +232 -0
  30. mcp_proxy_adapter/commands/proxy_registration_command.py +409 -0
  31. mcp_proxy_adapter/commands/reload_command.py +48 -50
  32. mcp_proxy_adapter/commands/result.py +1 -0
  33. mcp_proxy_adapter/commands/role_test_command.py +141 -0
  34. mcp_proxy_adapter/commands/roles_management_command.py +697 -0
  35. mcp_proxy_adapter/commands/security_command.py +488 -0
  36. mcp_proxy_adapter/commands/ssl_setup_command.py +366 -0
  37. mcp_proxy_adapter/commands/token_management_command.py +529 -0
  38. mcp_proxy_adapter/commands/transport_management_command.py +144 -0
  39. mcp_proxy_adapter/commands/unload_command.py +158 -0
  40. mcp_proxy_adapter/config.py +394 -14
  41. mcp_proxy_adapter/core/app_factory.py +410 -0
  42. mcp_proxy_adapter/core/app_runner.py +272 -0
  43. mcp_proxy_adapter/core/auth_validator.py +606 -0
  44. mcp_proxy_adapter/core/certificate_utils.py +1045 -0
  45. mcp_proxy_adapter/core/client.py +574 -0
  46. mcp_proxy_adapter/core/client_manager.py +284 -0
  47. mcp_proxy_adapter/core/client_security.py +384 -0
  48. mcp_proxy_adapter/core/config_converter.py +405 -0
  49. mcp_proxy_adapter/core/config_validator.py +218 -0
  50. mcp_proxy_adapter/core/logging.py +19 -3
  51. mcp_proxy_adapter/core/mtls_asgi.py +156 -0
  52. mcp_proxy_adapter/core/mtls_asgi_app.py +187 -0
  53. mcp_proxy_adapter/core/protocol_manager.py +385 -0
  54. mcp_proxy_adapter/core/proxy_client.py +602 -0
  55. mcp_proxy_adapter/core/proxy_registration.py +522 -0
  56. mcp_proxy_adapter/core/role_utils.py +426 -0
  57. mcp_proxy_adapter/core/security_adapter.py +370 -0
  58. mcp_proxy_adapter/core/security_factory.py +239 -0
  59. mcp_proxy_adapter/core/security_integration.py +286 -0
  60. mcp_proxy_adapter/core/server_adapter.py +282 -0
  61. mcp_proxy_adapter/core/server_engine.py +270 -0
  62. mcp_proxy_adapter/core/settings.py +1 -0
  63. mcp_proxy_adapter/core/ssl_utils.py +234 -0
  64. mcp_proxy_adapter/core/transport_manager.py +292 -0
  65. mcp_proxy_adapter/core/unified_config_adapter.py +579 -0
  66. mcp_proxy_adapter/custom_openapi.py +22 -11
  67. mcp_proxy_adapter/examples/__init__.py +13 -4
  68. mcp_proxy_adapter/examples/basic_framework/__init__.py +9 -0
  69. mcp_proxy_adapter/examples/basic_framework/commands/__init__.py +4 -0
  70. mcp_proxy_adapter/examples/basic_framework/hooks/__init__.py +4 -0
  71. mcp_proxy_adapter/examples/basic_framework/main.py +44 -0
  72. mcp_proxy_adapter/examples/commands/__init__.py +5 -0
  73. mcp_proxy_adapter/examples/create_certificates_simple.py +550 -0
  74. mcp_proxy_adapter/examples/debug_request_state.py +112 -0
  75. mcp_proxy_adapter/examples/debug_role_chain.py +158 -0
  76. mcp_proxy_adapter/examples/demo_client.py +275 -0
  77. mcp_proxy_adapter/examples/examples/basic_framework/__init__.py +9 -0
  78. mcp_proxy_adapter/examples/examples/basic_framework/commands/__init__.py +4 -0
  79. mcp_proxy_adapter/examples/examples/basic_framework/hooks/__init__.py +4 -0
  80. mcp_proxy_adapter/examples/examples/basic_framework/main.py +44 -0
  81. mcp_proxy_adapter/examples/examples/full_application/__init__.py +12 -0
  82. mcp_proxy_adapter/examples/examples/full_application/commands/__init__.py +7 -0
  83. mcp_proxy_adapter/examples/examples/full_application/commands/custom_echo_command.py +80 -0
  84. mcp_proxy_adapter/examples/examples/full_application/commands/dynamic_calculator_command.py +90 -0
  85. mcp_proxy_adapter/examples/examples/full_application/hooks/__init__.py +7 -0
  86. mcp_proxy_adapter/examples/examples/full_application/hooks/application_hooks.py +75 -0
  87. mcp_proxy_adapter/examples/examples/full_application/hooks/builtin_command_hooks.py +71 -0
  88. mcp_proxy_adapter/examples/examples/full_application/main.py +173 -0
  89. mcp_proxy_adapter/examples/examples/full_application/proxy_endpoints.py +154 -0
  90. mcp_proxy_adapter/examples/full_application/__init__.py +12 -0
  91. mcp_proxy_adapter/examples/full_application/commands/__init__.py +7 -0
  92. mcp_proxy_adapter/examples/full_application/commands/custom_echo_command.py +80 -0
  93. mcp_proxy_adapter/examples/full_application/commands/dynamic_calculator_command.py +90 -0
  94. mcp_proxy_adapter/examples/full_application/hooks/__init__.py +7 -0
  95. mcp_proxy_adapter/examples/full_application/hooks/application_hooks.py +75 -0
  96. mcp_proxy_adapter/examples/full_application/hooks/builtin_command_hooks.py +71 -0
  97. mcp_proxy_adapter/examples/full_application/main.py +173 -0
  98. mcp_proxy_adapter/examples/full_application/proxy_endpoints.py +154 -0
  99. mcp_proxy_adapter/examples/generate_all_certificates.py +362 -0
  100. mcp_proxy_adapter/examples/generate_certificates.py +177 -0
  101. mcp_proxy_adapter/examples/generate_certificates_and_tokens.py +369 -0
  102. mcp_proxy_adapter/examples/generate_test_configs.py +331 -0
  103. mcp_proxy_adapter/examples/proxy_registration_example.py +334 -0
  104. mcp_proxy_adapter/examples/run_example.py +59 -0
  105. mcp_proxy_adapter/examples/run_full_test_suite.py +318 -0
  106. mcp_proxy_adapter/examples/run_proxy_server.py +146 -0
  107. mcp_proxy_adapter/examples/run_security_tests.py +544 -0
  108. mcp_proxy_adapter/examples/run_security_tests_fixed.py +247 -0
  109. mcp_proxy_adapter/examples/scripts/config_generator.py +740 -0
  110. mcp_proxy_adapter/examples/scripts/create_certificates_simple.py +560 -0
  111. mcp_proxy_adapter/examples/scripts/generate_certificates_and_tokens.py +369 -0
  112. mcp_proxy_adapter/examples/security_test_client.py +782 -0
  113. mcp_proxy_adapter/examples/setup_test_environment.py +328 -0
  114. mcp_proxy_adapter/examples/test_config.py +148 -0
  115. mcp_proxy_adapter/examples/test_config_generator.py +86 -0
  116. mcp_proxy_adapter/examples/test_examples.py +281 -0
  117. mcp_proxy_adapter/examples/universal_client.py +620 -0
  118. mcp_proxy_adapter/main.py +93 -0
  119. mcp_proxy_adapter/utils/config_generator.py +1008 -0
  120. mcp_proxy_adapter/version.py +5 -2
  121. mcp_proxy_adapter-6.0.1.dist-info/METADATA +679 -0
  122. mcp_proxy_adapter-6.0.1.dist-info/RECORD +140 -0
  123. mcp_proxy_adapter-6.0.1.dist-info/entry_points.txt +2 -0
  124. {mcp_proxy_adapter-4.1.1.dist-info → mcp_proxy_adapter-6.0.1.dist-info}/licenses/LICENSE +2 -2
  125. mcp_proxy_adapter/api/middleware/auth.py +0 -146
  126. mcp_proxy_adapter/api/middleware/rate_limit.py +0 -152
  127. mcp_proxy_adapter/commands/reload_settings_command.py +0 -125
  128. mcp_proxy_adapter/examples/README.md +0 -124
  129. mcp_proxy_adapter/examples/basic_server/README.md +0 -60
  130. mcp_proxy_adapter/examples/basic_server/__init__.py +0 -7
  131. mcp_proxy_adapter/examples/basic_server/basic_custom_settings.json +0 -39
  132. mcp_proxy_adapter/examples/basic_server/config.json +0 -35
  133. mcp_proxy_adapter/examples/basic_server/custom_settings_example.py +0 -238
  134. mcp_proxy_adapter/examples/basic_server/server.py +0 -103
  135. mcp_proxy_adapter/examples/custom_commands/README.md +0 -127
  136. mcp_proxy_adapter/examples/custom_commands/__init__.py +0 -27
  137. mcp_proxy_adapter/examples/custom_commands/advanced_hooks.py +0 -250
  138. mcp_proxy_adapter/examples/custom_commands/auto_commands/__init__.py +0 -6
  139. mcp_proxy_adapter/examples/custom_commands/auto_commands/auto_echo_command.py +0 -103
  140. mcp_proxy_adapter/examples/custom_commands/auto_commands/auto_info_command.py +0 -111
  141. mcp_proxy_adapter/examples/custom_commands/config.json +0 -35
  142. mcp_proxy_adapter/examples/custom_commands/custom_health_command.py +0 -169
  143. mcp_proxy_adapter/examples/custom_commands/custom_help_command.py +0 -215
  144. mcp_proxy_adapter/examples/custom_commands/custom_openapi_generator.py +0 -76
  145. mcp_proxy_adapter/examples/custom_commands/custom_settings.json +0 -96
  146. mcp_proxy_adapter/examples/custom_commands/custom_settings_manager.py +0 -241
  147. mcp_proxy_adapter/examples/custom_commands/data_transform_command.py +0 -135
  148. mcp_proxy_adapter/examples/custom_commands/echo_command.py +0 -122
  149. mcp_proxy_adapter/examples/custom_commands/hooks.py +0 -230
  150. mcp_proxy_adapter/examples/custom_commands/intercept_command.py +0 -123
  151. mcp_proxy_adapter/examples/custom_commands/manual_echo_command.py +0 -103
  152. mcp_proxy_adapter/examples/custom_commands/server.py +0 -228
  153. mcp_proxy_adapter/examples/custom_commands/test_hooks.py +0 -176
  154. mcp_proxy_adapter/examples/deployment/README.md +0 -49
  155. mcp_proxy_adapter/examples/deployment/__init__.py +0 -7
  156. mcp_proxy_adapter/examples/deployment/config.development.json +0 -8
  157. mcp_proxy_adapter/examples/deployment/config.json +0 -29
  158. mcp_proxy_adapter/examples/deployment/config.production.json +0 -12
  159. mcp_proxy_adapter/examples/deployment/config.staging.json +0 -11
  160. mcp_proxy_adapter/examples/deployment/docker-compose.yml +0 -31
  161. mcp_proxy_adapter/examples/deployment/run.sh +0 -43
  162. mcp_proxy_adapter/examples/deployment/run_docker.sh +0 -84
  163. mcp_proxy_adapter/schemas/base_schema.json +0 -114
  164. mcp_proxy_adapter/schemas/openapi_schema.json +0 -314
  165. mcp_proxy_adapter/tests/__init__.py +0 -0
  166. mcp_proxy_adapter/tests/api/__init__.py +0 -3
  167. mcp_proxy_adapter/tests/api/test_cmd_endpoint.py +0 -115
  168. mcp_proxy_adapter/tests/api/test_custom_openapi.py +0 -617
  169. mcp_proxy_adapter/tests/api/test_handlers.py +0 -522
  170. mcp_proxy_adapter/tests/api/test_middleware.py +0 -340
  171. mcp_proxy_adapter/tests/api/test_schemas.py +0 -546
  172. mcp_proxy_adapter/tests/api/test_tool_integration.py +0 -531
  173. mcp_proxy_adapter/tests/commands/__init__.py +0 -3
  174. mcp_proxy_adapter/tests/commands/test_config_command.py +0 -211
  175. mcp_proxy_adapter/tests/commands/test_echo_command.py +0 -127
  176. mcp_proxy_adapter/tests/commands/test_help_command.py +0 -136
  177. mcp_proxy_adapter/tests/conftest.py +0 -131
  178. mcp_proxy_adapter/tests/functional/__init__.py +0 -3
  179. mcp_proxy_adapter/tests/functional/test_api.py +0 -253
  180. mcp_proxy_adapter/tests/integration/__init__.py +0 -3
  181. mcp_proxy_adapter/tests/integration/test_cmd_integration.py +0 -129
  182. mcp_proxy_adapter/tests/integration/test_integration.py +0 -255
  183. mcp_proxy_adapter/tests/performance/__init__.py +0 -3
  184. mcp_proxy_adapter/tests/performance/test_performance.py +0 -189
  185. mcp_proxy_adapter/tests/stubs/__init__.py +0 -10
  186. mcp_proxy_adapter/tests/stubs/echo_command.py +0 -104
  187. mcp_proxy_adapter/tests/test_api_endpoints.py +0 -271
  188. mcp_proxy_adapter/tests/test_api_handlers.py +0 -289
  189. mcp_proxy_adapter/tests/test_base_command.py +0 -123
  190. mcp_proxy_adapter/tests/test_batch_requests.py +0 -117
  191. mcp_proxy_adapter/tests/test_command_registry.py +0 -281
  192. mcp_proxy_adapter/tests/test_config.py +0 -127
  193. mcp_proxy_adapter/tests/test_utils.py +0 -65
  194. mcp_proxy_adapter/tests/unit/__init__.py +0 -3
  195. mcp_proxy_adapter/tests/unit/test_base_command.py +0 -436
  196. mcp_proxy_adapter/tests/unit/test_config.py +0 -217
  197. mcp_proxy_adapter-4.1.1.dist-info/METADATA +0 -200
  198. mcp_proxy_adapter-4.1.1.dist-info/RECORD +0 -110
  199. {mcp_proxy_adapter-4.1.1.dist-info → mcp_proxy_adapter-6.0.1.dist-info}/WHEEL +0 -0
  200. {mcp_proxy_adapter-4.1.1.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()