mcp-proxy-adapter 6.3.4__py3-none-any.whl → 6.3.5__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 (129) hide show
  1. mcp_proxy_adapter/__init__.py +9 -5
  2. mcp_proxy_adapter/__main__.py +1 -1
  3. mcp_proxy_adapter/api/app.py +227 -176
  4. mcp_proxy_adapter/api/handlers.py +68 -60
  5. mcp_proxy_adapter/api/middleware/__init__.py +7 -5
  6. mcp_proxy_adapter/api/middleware/base.py +19 -16
  7. mcp_proxy_adapter/api/middleware/command_permission_middleware.py +44 -34
  8. mcp_proxy_adapter/api/middleware/error_handling.py +57 -67
  9. mcp_proxy_adapter/api/middleware/factory.py +50 -52
  10. mcp_proxy_adapter/api/middleware/logging.py +46 -30
  11. mcp_proxy_adapter/api/middleware/performance.py +19 -16
  12. mcp_proxy_adapter/api/middleware/protocol_middleware.py +80 -50
  13. mcp_proxy_adapter/api/middleware/transport_middleware.py +26 -24
  14. mcp_proxy_adapter/api/middleware/unified_security.py +70 -51
  15. mcp_proxy_adapter/api/middleware/user_info_middleware.py +43 -34
  16. mcp_proxy_adapter/api/schemas.py +69 -43
  17. mcp_proxy_adapter/api/tool_integration.py +83 -63
  18. mcp_proxy_adapter/api/tools.py +60 -50
  19. mcp_proxy_adapter/commands/__init__.py +15 -6
  20. mcp_proxy_adapter/commands/auth_validation_command.py +107 -110
  21. mcp_proxy_adapter/commands/base.py +108 -112
  22. mcp_proxy_adapter/commands/builtin_commands.py +28 -18
  23. mcp_proxy_adapter/commands/catalog_manager.py +394 -265
  24. mcp_proxy_adapter/commands/cert_monitor_command.py +222 -204
  25. mcp_proxy_adapter/commands/certificate_management_command.py +210 -213
  26. mcp_proxy_adapter/commands/command_registry.py +275 -226
  27. mcp_proxy_adapter/commands/config_command.py +48 -33
  28. mcp_proxy_adapter/commands/dependency_container.py +22 -23
  29. mcp_proxy_adapter/commands/dependency_manager.py +65 -56
  30. mcp_proxy_adapter/commands/echo_command.py +15 -15
  31. mcp_proxy_adapter/commands/health_command.py +31 -29
  32. mcp_proxy_adapter/commands/help_command.py +97 -61
  33. mcp_proxy_adapter/commands/hooks.py +65 -49
  34. mcp_proxy_adapter/commands/key_management_command.py +148 -147
  35. mcp_proxy_adapter/commands/load_command.py +58 -40
  36. mcp_proxy_adapter/commands/plugins_command.py +80 -54
  37. mcp_proxy_adapter/commands/protocol_management_command.py +60 -48
  38. mcp_proxy_adapter/commands/proxy_registration_command.py +107 -115
  39. mcp_proxy_adapter/commands/reload_command.py +43 -37
  40. mcp_proxy_adapter/commands/result.py +26 -33
  41. mcp_proxy_adapter/commands/role_test_command.py +26 -26
  42. mcp_proxy_adapter/commands/roles_management_command.py +176 -173
  43. mcp_proxy_adapter/commands/security_command.py +134 -122
  44. mcp_proxy_adapter/commands/settings_command.py +47 -56
  45. mcp_proxy_adapter/commands/ssl_setup_command.py +109 -129
  46. mcp_proxy_adapter/commands/token_management_command.py +129 -158
  47. mcp_proxy_adapter/commands/transport_management_command.py +41 -36
  48. mcp_proxy_adapter/commands/unload_command.py +42 -37
  49. mcp_proxy_adapter/config.py +36 -35
  50. mcp_proxy_adapter/core/__init__.py +19 -21
  51. mcp_proxy_adapter/core/app_factory.py +30 -9
  52. mcp_proxy_adapter/core/app_runner.py +81 -64
  53. mcp_proxy_adapter/core/auth_validator.py +176 -182
  54. mcp_proxy_adapter/core/certificate_utils.py +469 -426
  55. mcp_proxy_adapter/core/client.py +155 -126
  56. mcp_proxy_adapter/core/client_manager.py +60 -54
  57. mcp_proxy_adapter/core/client_security.py +108 -88
  58. mcp_proxy_adapter/core/config_converter.py +176 -143
  59. mcp_proxy_adapter/core/config_validator.py +12 -4
  60. mcp_proxy_adapter/core/crl_utils.py +21 -7
  61. mcp_proxy_adapter/core/errors.py +64 -20
  62. mcp_proxy_adapter/core/logging.py +34 -29
  63. mcp_proxy_adapter/core/mtls_asgi.py +29 -25
  64. mcp_proxy_adapter/core/mtls_asgi_app.py +66 -54
  65. mcp_proxy_adapter/core/protocol_manager.py +154 -104
  66. mcp_proxy_adapter/core/proxy_client.py +202 -144
  67. mcp_proxy_adapter/core/proxy_registration.py +7 -3
  68. mcp_proxy_adapter/core/role_utils.py +139 -125
  69. mcp_proxy_adapter/core/security_adapter.py +88 -77
  70. mcp_proxy_adapter/core/security_factory.py +50 -44
  71. mcp_proxy_adapter/core/security_integration.py +72 -24
  72. mcp_proxy_adapter/core/server_adapter.py +68 -64
  73. mcp_proxy_adapter/core/server_engine.py +71 -53
  74. mcp_proxy_adapter/core/settings.py +68 -58
  75. mcp_proxy_adapter/core/ssl_utils.py +69 -56
  76. mcp_proxy_adapter/core/transport_manager.py +72 -60
  77. mcp_proxy_adapter/core/unified_config_adapter.py +201 -150
  78. mcp_proxy_adapter/core/utils.py +4 -2
  79. mcp_proxy_adapter/custom_openapi.py +107 -99
  80. mcp_proxy_adapter/examples/basic_framework/main.py +9 -2
  81. mcp_proxy_adapter/examples/commands/__init__.py +1 -1
  82. mcp_proxy_adapter/examples/create_certificates_simple.py +182 -71
  83. mcp_proxy_adapter/examples/debug_request_state.py +38 -19
  84. mcp_proxy_adapter/examples/debug_role_chain.py +53 -20
  85. mcp_proxy_adapter/examples/demo_client.py +48 -36
  86. mcp_proxy_adapter/examples/examples/basic_framework/main.py +9 -2
  87. mcp_proxy_adapter/examples/examples/full_application/__init__.py +1 -0
  88. mcp_proxy_adapter/examples/examples/full_application/commands/custom_echo_command.py +22 -10
  89. mcp_proxy_adapter/examples/examples/full_application/commands/dynamic_calculator_command.py +24 -17
  90. mcp_proxy_adapter/examples/examples/full_application/hooks/application_hooks.py +16 -3
  91. mcp_proxy_adapter/examples/examples/full_application/hooks/builtin_command_hooks.py +13 -3
  92. mcp_proxy_adapter/examples/examples/full_application/main.py +27 -2
  93. mcp_proxy_adapter/examples/examples/full_application/proxy_endpoints.py +48 -14
  94. mcp_proxy_adapter/examples/full_application/__init__.py +1 -0
  95. mcp_proxy_adapter/examples/full_application/commands/custom_echo_command.py +22 -10
  96. mcp_proxy_adapter/examples/full_application/commands/dynamic_calculator_command.py +24 -17
  97. mcp_proxy_adapter/examples/full_application/hooks/application_hooks.py +16 -3
  98. mcp_proxy_adapter/examples/full_application/hooks/builtin_command_hooks.py +13 -3
  99. mcp_proxy_adapter/examples/full_application/main.py +27 -2
  100. mcp_proxy_adapter/examples/full_application/proxy_endpoints.py +48 -14
  101. mcp_proxy_adapter/examples/generate_all_certificates.py +198 -73
  102. mcp_proxy_adapter/examples/generate_certificates.py +31 -16
  103. mcp_proxy_adapter/examples/generate_certificates_and_tokens.py +220 -74
  104. mcp_proxy_adapter/examples/generate_test_configs.py +68 -91
  105. mcp_proxy_adapter/examples/proxy_registration_example.py +76 -75
  106. mcp_proxy_adapter/examples/run_example.py +23 -5
  107. mcp_proxy_adapter/examples/run_full_test_suite.py +109 -71
  108. mcp_proxy_adapter/examples/run_proxy_server.py +22 -9
  109. mcp_proxy_adapter/examples/run_security_tests.py +103 -41
  110. mcp_proxy_adapter/examples/run_security_tests_fixed.py +72 -36
  111. mcp_proxy_adapter/examples/scripts/config_generator.py +288 -187
  112. mcp_proxy_adapter/examples/scripts/create_certificates_simple.py +185 -72
  113. mcp_proxy_adapter/examples/scripts/generate_certificates_and_tokens.py +220 -74
  114. mcp_proxy_adapter/examples/security_test_client.py +196 -127
  115. mcp_proxy_adapter/examples/setup_test_environment.py +17 -29
  116. mcp_proxy_adapter/examples/test_config.py +19 -4
  117. mcp_proxy_adapter/examples/test_config_generator.py +23 -7
  118. mcp_proxy_adapter/examples/test_examples.py +84 -56
  119. mcp_proxy_adapter/examples/universal_client.py +119 -62
  120. mcp_proxy_adapter/openapi.py +108 -115
  121. mcp_proxy_adapter/utils/config_generator.py +429 -274
  122. mcp_proxy_adapter/version.py +1 -2
  123. {mcp_proxy_adapter-6.3.4.dist-info → mcp_proxy_adapter-6.3.5.dist-info}/METADATA +1 -1
  124. mcp_proxy_adapter-6.3.5.dist-info/RECORD +143 -0
  125. mcp_proxy_adapter-6.3.4.dist-info/RECORD +0 -143
  126. {mcp_proxy_adapter-6.3.4.dist-info → mcp_proxy_adapter-6.3.5.dist-info}/WHEEL +0 -0
  127. {mcp_proxy_adapter-6.3.4.dist-info → mcp_proxy_adapter-6.3.5.dist-info}/entry_points.txt +0 -0
  128. {mcp_proxy_adapter-6.3.4.dist-info → mcp_proxy_adapter-6.3.5.dist-info}/licenses/LICENSE +0 -0
  129. {mcp_proxy_adapter-6.3.4.dist-info → mcp_proxy_adapter-6.3.5.dist-info}/top_level.txt +0 -0
@@ -20,15 +20,15 @@ logger = logging.getLogger(__name__)
20
20
  class ConfigGenerator:
21
21
  """
22
22
  Configuration generator for unified mcp_proxy_adapter and mcp_security_framework configs.
23
-
23
+
24
24
  Generates comprehensive configuration files with detailed comments and examples
25
25
  for both the proxy adapter and security framework components.
26
26
  """
27
-
27
+
28
28
  def __init__(self):
29
29
  """Initialize configuration generator."""
30
30
  self.template_config = self._get_template_config()
31
-
31
+
32
32
  def _get_template_config(self) -> Dict[str, Any]:
33
33
  """Get template configuration with all available options."""
34
34
  return {
@@ -38,7 +38,7 @@ class ConfigGenerator:
38
38
  "debug": False,
39
39
  "log_level": "INFO",
40
40
  "workers": 1,
41
- "reload": False
41
+ "reload": False,
42
42
  },
43
43
  "ssl": {
44
44
  "enabled": False,
@@ -47,9 +47,12 @@ class ConfigGenerator:
47
47
  "ca_cert": None,
48
48
  "verify_client": False,
49
49
  "client_cert_required": False,
50
- "cipher_suites": ["TLS_AES_256_GCM_SHA384", "TLS_CHACHA20_POLY1305_SHA256"],
50
+ "cipher_suites": [
51
+ "TLS_AES_256_GCM_SHA384",
52
+ "TLS_CHACHA20_POLY1305_SHA256",
53
+ ],
51
54
  "min_tls_version": "TLSv1.2",
52
- "max_tls_version": "1.3"
55
+ "max_tls_version": "1.3",
53
56
  },
54
57
  "security": {
55
58
  "framework": "mcp_security_framework",
@@ -57,7 +60,6 @@ class ConfigGenerator:
57
60
  "debug": False,
58
61
  "environment": "dev",
59
62
  "version": "1.0.0",
60
-
61
63
  "ssl": {
62
64
  "enabled": False,
63
65
  "cert_file": None,
@@ -71,9 +73,8 @@ class ConfigGenerator:
71
73
  "cipher_suite": None,
72
74
  "check_hostname": True,
73
75
  "check_expiry": True,
74
- "expiry_warning_days": 30
76
+ "expiry_warning_days": 30,
75
77
  },
76
-
77
78
  "auth": {
78
79
  "enabled": False,
79
80
  "methods": [],
@@ -92,10 +93,9 @@ class ConfigGenerator:
92
93
  "X-Content-Type-Options": "nosniff",
93
94
  "X-Frame-Options": "DENY",
94
95
  "X-XSS-Protection": "1; mode=block",
95
- "Strict-Transport-Security": "max-age=31536000; includeSubDomains"
96
- }
96
+ "Strict-Transport-Security": "max-age=31536000; includeSubDomains",
97
+ },
97
98
  },
98
-
99
99
  "certificates": {
100
100
  "enabled": False,
101
101
  "ca_cert_path": None,
@@ -110,9 +110,8 @@ class ConfigGenerator:
110
110
  "crl_url": None,
111
111
  "crl_validity_days": 30,
112
112
  "auto_renewal": False,
113
- "renewal_threshold_days": 30
113
+ "renewal_threshold_days": 30,
114
114
  },
115
-
116
115
  "permissions": {
117
116
  "enabled": False,
118
117
  "roles_file": None,
@@ -123,9 +122,8 @@ class ConfigGenerator:
123
122
  "permission_cache_ttl": 300,
124
123
  "wildcard_permissions": False,
125
124
  "strict_mode": False,
126
- "roles": {}
125
+ "roles": {},
127
126
  },
128
-
129
127
  "rate_limit": {
130
128
  "enabled": False,
131
129
  "default_requests_per_minute": 60,
@@ -136,9 +134,8 @@ class ConfigGenerator:
136
134
  "redis_config": None,
137
135
  "cleanup_interval": 300,
138
136
  "exempt_paths": ["/health", "/docs", "/openapi.json"],
139
- "exempt_roles": ["admin"]
137
+ "exempt_roles": ["admin"],
140
138
  },
141
-
142
139
  "logging": {
143
140
  "enabled": True,
144
141
  "level": "INFO",
@@ -151,10 +148,9 @@ class ConfigGenerator:
151
148
  "json_format": False,
152
149
  "include_timestamp": True,
153
150
  "include_level": True,
154
- "include_module": True
155
- }
151
+ "include_module": True,
152
+ },
156
153
  },
157
-
158
154
  "registration": {
159
155
  "enabled": False,
160
156
  "server_url": "https://proxy-registry.example.com",
@@ -164,18 +160,18 @@ class ConfigGenerator:
164
160
  "cert_file": "mcp_proxy_adapter/examples/certs/proxy_client.crt",
165
161
  "key_file": "mcp_proxy_adapter/examples/keys/proxy_client.key",
166
162
  "ca_cert_file": "mcp_proxy_adapter/examples/certs/ca.crt",
167
- "verify_server": True
163
+ "verify_server": True,
168
164
  },
169
165
  "token": {
170
166
  "enabled": False,
171
167
  "token": "proxy_registration_token_123",
172
168
  "token_type": "bearer",
173
- "refresh_interval": 3600
169
+ "refresh_interval": 3600,
174
170
  },
175
171
  "api_key": {
176
172
  "enabled": False,
177
173
  "key": "proxy_api_key_456",
178
- "key_header": "X-Proxy-API-Key"
174
+ "key_header": "X-Proxy-API-Key",
179
175
  },
180
176
  "proxy_info": {
181
177
  "name": "mcp_proxy_adapter",
@@ -185,24 +181,23 @@ class ConfigGenerator:
185
181
  "endpoints": {
186
182
  "jsonrpc": "/api/jsonrpc",
187
183
  "rest": "/cmd",
188
- "health": "/health"
189
- }
184
+ "health": "/health",
185
+ },
190
186
  },
191
187
  "heartbeat": {
192
188
  "enabled": True,
193
189
  "interval": 300,
194
190
  "timeout": 30,
195
191
  "retry_attempts": 3,
196
- "retry_delay": 60
192
+ "retry_delay": 60,
197
193
  },
198
194
  "auto_discovery": {
199
195
  "enabled": False,
200
196
  "discovery_urls": [],
201
197
  "discovery_interval": 3600,
202
- "register_on_discovery": True
203
- }
198
+ "register_on_discovery": True,
199
+ },
204
200
  },
205
-
206
201
  "logging": {
207
202
  "level": "INFO",
208
203
  "console_output": True,
@@ -210,17 +205,15 @@ class ConfigGenerator:
210
205
  "file_path": None,
211
206
  "max_file_size": 10,
212
207
  "backup_count": 5,
213
- "format": "%(asctime)s - %(name)s - %(levelname)s - %(message)s"
208
+ "format": "%(asctime)s - %(name)s - %(levelname)s - %(message)s",
214
209
  },
215
-
216
210
  "commands": {
217
211
  "auto_discovery": True,
218
212
  "commands_directory": "./commands",
219
213
  "builtin_commands": ["echo", "health", "config"],
220
214
  "custom_commands": [],
221
- "command_timeout": 30
215
+ "command_timeout": 30,
222
216
  },
223
-
224
217
  "hooks": {
225
218
  "enabled": True,
226
219
  "application_hooks": {
@@ -228,7 +221,7 @@ class ConfigGenerator:
228
221
  "on_shutdown": [],
229
222
  "before_request": [],
230
223
  "after_request": [],
231
- "on_error": []
224
+ "on_error": [],
232
225
  },
233
226
  "command_hooks": {
234
227
  "before_echo_command": [],
@@ -236,22 +229,21 @@ class ConfigGenerator:
236
229
  "before_health_command": [],
237
230
  "after_health_command": [],
238
231
  "before_config_command": [],
239
- "after_config_command": []
240
- }
232
+ "after_config_command": [],
233
+ },
241
234
  },
242
-
243
235
  "protocols": {
244
236
  "enabled": True,
245
237
  "allowed_protocols": ["http", "https"],
246
238
  "default_protocol": "http",
247
- "strict_mode": False
248
- }
239
+ "strict_mode": False,
240
+ },
249
241
  }
250
-
242
+
251
243
  def generate_config_with_comments(self, config_type: str = "full") -> str:
252
244
  """
253
245
  Generate configuration with detailed comments.
254
-
246
+
255
247
  Args:
256
248
  config_type: Type of configuration to generate
257
249
  - "full": Complete configuration with all options
@@ -263,24 +255,24 @@ class ConfigGenerator:
263
255
  - "https": HTTPS configuration
264
256
  - "https_token": HTTPS with token authentication
265
257
  - "mtls": mTLS configuration
266
-
258
+
267
259
  Returns:
268
260
  JSON configuration string with comments
269
261
  """
270
262
  config = self._get_config_by_type(config_type)
271
-
263
+
272
264
  # Convert to JSON with comments
273
265
  json_str = json.dumps(config, indent=2, ensure_ascii=False)
274
-
266
+
275
267
  # Add comments
276
268
  commented_config = self._add_comments(json_str, config_type)
277
-
269
+
278
270
  return commented_config
279
-
271
+
280
272
  def _get_config_by_type(self, config_type: str) -> Dict[str, Any]:
281
273
  """Get configuration based on type."""
282
274
  base_config = self.template_config.copy()
283
-
275
+
284
276
  if config_type == "minimal":
285
277
  return self._get_minimal_config(base_config)
286
278
  elif config_type == "secure":
@@ -303,30 +295,30 @@ class ConfigGenerator:
303
295
  return self._get_mtls_no_protocol_middleware_config(base_config)
304
296
  else: # full
305
297
  return base_config
306
-
298
+
307
299
  def _get_minimal_config(self, base_config: Dict[str, Any]) -> Dict[str, Any]:
308
300
  """Get minimal working configuration."""
309
301
  config = base_config.copy()
310
-
302
+
311
303
  # Disable security for minimal config
312
304
  config["security"]["enabled"] = False
313
305
  config["security"]["auth"]["enabled"] = False
314
306
  config["security"]["permissions"]["enabled"] = False
315
307
  config["security"]["rate_limit"]["enabled"] = False
316
-
308
+
317
309
  # Disable registration for minimal config
318
310
  config["registration"]["enabled"] = False
319
-
311
+
320
312
  # Keep only essential settings
321
313
  config["server"]["port"] = 8000
322
314
  config["server"]["debug"] = False
323
-
315
+
324
316
  return config
325
-
317
+
326
318
  def _get_basic_http_config(self, base_config: Dict[str, Any]) -> Dict[str, Any]:
327
319
  """Get basic HTTP configuration."""
328
320
  config = base_config.copy()
329
-
321
+
330
322
  # Basic HTTP settings
331
323
  config["server"]["port"] = 8000
332
324
  config["ssl"]["enabled"] = False
@@ -346,17 +338,20 @@ class ConfigGenerator:
346
338
  config["registration"]["server_url"] = "http://127.0.0.1:3004/proxy"
347
339
  config["registration"]["proxy_info"]["name"] = "mcp_example_server"
348
340
  config["registration"]["proxy_info"]["capabilities"] = [
349
- "jsonrpc", "rest", "security", "proxy_registration"
341
+ "jsonrpc",
342
+ "rest",
343
+ "security",
344
+ "proxy_registration",
350
345
  ]
351
346
  config["registration"]["heartbeat"]["enabled"] = True
352
347
  config["registration"]["heartbeat"]["interval"] = 30
353
-
348
+
354
349
  return config
355
-
350
+
356
351
  def _get_http_token_config(self, base_config: Dict[str, Any]) -> Dict[str, Any]:
357
352
  """Get HTTP with token authentication configuration."""
358
353
  config = base_config.copy()
359
-
354
+
360
355
  # HTTP with token auth
361
356
  config["server"]["port"] = 8001
362
357
  config["ssl"]["enabled"] = False
@@ -367,89 +362,105 @@ class ConfigGenerator:
367
362
  "test-token-123": {
368
363
  "roles": ["admin"],
369
364
  "permissions": ["*"],
370
- "expires": None
365
+ "expires": None,
371
366
  },
372
367
  "user-token-456": {
373
368
  "roles": ["user"],
374
369
  "permissions": ["read", "execute"],
375
- "expires": None
376
- }
370
+ "expires": None,
371
+ },
377
372
  }
378
373
  config["security"]["permissions"]["enabled"] = True
379
- config["security"]["permissions"]["roles_file"] = "mcp_proxy_adapter/examples/server_configs/roles.json"
374
+ config["security"]["permissions"][
375
+ "roles_file"
376
+ ] = "mcp_proxy_adapter/examples/server_configs/roles.json"
380
377
  config["protocols"]["enabled"] = True
381
378
  config["protocols"]["allowed_protocols"] = ["http"]
382
379
  config["protocols"]["default_protocol"] = "http"
383
-
380
+
384
381
  return config
385
-
382
+
386
383
  def _get_https_config(self, base_config: Dict[str, Any]) -> Dict[str, Any]:
387
384
  """Get HTTPS configuration."""
388
385
  config = base_config.copy()
389
-
386
+
390
387
  # HTTPS settings
391
388
  config["server"]["port"] = 8443
392
389
  config["ssl"]["enabled"] = True
393
390
  config["ssl"]["cert_file"] = "mcp_proxy_adapter/examples/certs/server_cert.pem"
394
391
  config["ssl"]["key_file"] = "mcp_proxy_adapter/examples/certs/server_key.pem"
395
392
  config["ssl"]["ca_cert"] = "mcp_proxy_adapter/examples/certs/ca_cert.pem"
396
-
393
+
397
394
  config["security"]["ssl"]["enabled"] = True
398
- config["security"]["ssl"]["cert_file"] = "mcp_proxy_adapter/examples/certs/server_cert.pem"
399
- config["security"]["ssl"]["key_file"] = "mcp_proxy_adapter/examples/certs/server_key.pem"
400
- config["security"]["ssl"]["ca_cert_file"] = "mcp_proxy_adapter/examples/certs/ca_cert.pem"
401
-
395
+ config["security"]["ssl"][
396
+ "cert_file"
397
+ ] = "mcp_proxy_adapter/examples/certs/server_cert.pem"
398
+ config["security"]["ssl"][
399
+ "key_file"
400
+ ] = "mcp_proxy_adapter/examples/certs/server_key.pem"
401
+ config["security"]["ssl"][
402
+ "ca_cert_file"
403
+ ] = "mcp_proxy_adapter/examples/certs/ca_cert.pem"
404
+
402
405
  config["security"]["auth"]["enabled"] = False
403
406
  config["security"]["permissions"]["enabled"] = False
404
407
  config["security"]["permissions"]["roles_file"] = None
405
408
  config["protocols"]["enabled"] = True
406
409
  config["protocols"]["allowed_protocols"] = ["http", "https"]
407
410
  config["protocols"]["default_protocol"] = "https"
408
-
411
+
409
412
  return config
410
-
413
+
411
414
  def _get_https_token_config(self, base_config: Dict[str, Any]) -> Dict[str, Any]:
412
415
  """Get HTTPS with token authentication configuration."""
413
416
  config = base_config.copy()
414
-
417
+
415
418
  # HTTPS with token auth
416
419
  config["server"]["port"] = 8444
417
420
  config["ssl"]["enabled"] = True
418
421
  config["ssl"]["cert_file"] = "mcp_proxy_adapter/examples/certs/server_cert.pem"
419
422
  config["ssl"]["key_file"] = "mcp_proxy_adapter/examples/certs/server_key.pem"
420
423
  config["ssl"]["ca_cert"] = "mcp_proxy_adapter/examples/certs/ca_cert.pem"
421
-
424
+
422
425
  config["security"]["ssl"]["enabled"] = True
423
- config["security"]["ssl"]["cert_file"] = "mcp_proxy_adapter/examples/certs/server_cert.pem"
424
- config["security"]["ssl"]["key_file"] = "mcp_proxy_adapter/examples/certs/server_key.pem"
425
- config["security"]["ssl"]["ca_cert_file"] = "mcp_proxy_adapter/examples/certs/ca_cert.pem"
426
-
426
+ config["security"]["ssl"][
427
+ "cert_file"
428
+ ] = "mcp_proxy_adapter/examples/certs/server_cert.pem"
429
+ config["security"]["ssl"][
430
+ "key_file"
431
+ ] = "mcp_proxy_adapter/examples/certs/server_key.pem"
432
+ config["security"]["ssl"][
433
+ "ca_cert_file"
434
+ ] = "mcp_proxy_adapter/examples/certs/ca_cert.pem"
435
+
427
436
  config["security"]["auth"]["enabled"] = True
428
437
  config["security"]["auth"]["methods"] = ["api_key"]
429
438
  config["security"]["auth"]["api_keys"] = {
430
439
  "test-token-123": {
431
440
  "roles": ["admin"],
432
441
  "permissions": ["*"],
433
- "expires": None
442
+ "expires": None,
434
443
  },
435
444
  "user-token-456": {
436
445
  "roles": ["user"],
437
446
  "permissions": ["read", "execute"],
438
- "expires": None
439
- }
447
+ "expires": None,
448
+ },
440
449
  }
441
450
  config["security"]["permissions"]["enabled"] = True
442
- config["security"]["permissions"]["roles_file"] = "mcp_proxy_adapter/examples/server_configs/roles.json"
451
+ config["security"]["permissions"][
452
+ "roles_file"
453
+ ] = "mcp_proxy_adapter/examples/server_configs/roles.json"
443
454
  config["protocols"]["enabled"] = True
444
455
  config["protocols"]["allowed_protocols"] = ["http", "https"]
445
456
  config["protocols"]["default_protocol"] = "https"
446
-
457
+
447
458
  return config
448
-
459
+
449
460
  def _get_mtls_config(self, base_config: Dict[str, Any]) -> Dict[str, Any]:
450
461
  """Get mTLS configuration."""
451
462
  config = base_config.copy()
452
-
463
+
453
464
  # mTLS settings
454
465
  config["server"]["port"] = 8445
455
466
  config["ssl"]["enabled"] = True
@@ -458,66 +469,90 @@ class ConfigGenerator:
458
469
  config["ssl"]["ca_cert"] = "mcp_proxy_adapter/examples/certs/ca_cert.pem"
459
470
  config["ssl"]["verify_client"] = True
460
471
  config["ssl"]["client_cert_required"] = True
461
-
472
+
462
473
  config["security"]["ssl"]["enabled"] = True
463
- config["security"]["ssl"]["cert_file"] = "mcp_proxy_adapter/examples/certs/server_cert.pem"
464
- config["security"]["ssl"]["key_file"] = "mcp_proxy_adapter/examples/certs/server_key.pem"
465
- config["security"]["ssl"]["ca_cert_file"] = "mcp_proxy_adapter/examples/certs/ca_cert.pem"
466
- config["security"]["ssl"]["client_cert_file"] = "mcp_proxy_adapter/examples/certs/client_cert.pem"
467
- config["security"]["ssl"]["client_key_file"] = "mcp_proxy_adapter/examples/certs/client_key.pem"
474
+ config["security"]["ssl"][
475
+ "cert_file"
476
+ ] = "mcp_proxy_adapter/examples/certs/server_cert.pem"
477
+ config["security"]["ssl"][
478
+ "key_file"
479
+ ] = "mcp_proxy_adapter/examples/certs/server_key.pem"
480
+ config["security"]["ssl"][
481
+ "ca_cert_file"
482
+ ] = "mcp_proxy_adapter/examples/certs/ca_cert.pem"
483
+ config["security"]["ssl"][
484
+ "client_cert_file"
485
+ ] = "mcp_proxy_adapter/examples/certs/client_cert.pem"
486
+ config["security"]["ssl"][
487
+ "client_key_file"
488
+ ] = "mcp_proxy_adapter/examples/certs/client_key.pem"
468
489
  config["security"]["ssl"]["verify_mode"] = "CERT_REQUIRED"
469
-
490
+
470
491
  config["security"]["auth"]["enabled"] = True
471
492
  config["security"]["auth"]["methods"] = ["certificate"]
472
493
  config["security"]["auth"]["certificate_auth"] = True
473
494
  config["security"]["permissions"]["enabled"] = True
474
- config["security"]["permissions"]["roles_file"] = "mcp_proxy_adapter/examples/server_configs/roles.json"
495
+ config["security"]["permissions"][
496
+ "roles_file"
497
+ ] = "mcp_proxy_adapter/examples/server_configs/roles.json"
475
498
  config["protocols"]["enabled"] = True
476
499
  config["protocols"]["allowed_protocols"] = ["https", "mtls"]
477
500
  config["protocols"]["default_protocol"] = "https"
478
-
501
+
479
502
  return config
480
-
481
- def _get_https_no_protocol_middleware_config(self, base_config: Dict[str, Any]) -> Dict[str, Any]:
503
+
504
+ def _get_https_no_protocol_middleware_config(
505
+ self, base_config: Dict[str, Any]
506
+ ) -> Dict[str, Any]:
482
507
  """Get HTTPS configuration without ProtocolMiddleware."""
483
508
  config = base_config.copy()
484
-
509
+
485
510
  # HTTPS settings
486
511
  config["server"]["port"] = 8445
487
512
  config["ssl"]["enabled"] = True
488
513
  config["ssl"]["cert_file"] = "mcp_proxy_adapter/examples/certs/server_cert.pem"
489
514
  config["ssl"]["key_file"] = "mcp_proxy_adapter/examples/certs/server_key.pem"
490
515
  config["ssl"]["ca_cert"] = "mcp_proxy_adapter/examples/certs/ca_cert.pem"
491
-
516
+
492
517
  config["security"]["ssl"]["enabled"] = True
493
- config["security"]["ssl"]["cert_file"] = "mcp_proxy_adapter/examples/certs/server_cert.pem"
494
- config["security"]["ssl"]["key_file"] = "mcp_proxy_adapter/examples/certs/server_key.pem"
495
- config["security"]["ssl"]["ca_cert_file"] = "mcp_proxy_adapter/examples/certs/ca_cert.pem"
496
-
518
+ config["security"]["ssl"][
519
+ "cert_file"
520
+ ] = "mcp_proxy_adapter/examples/certs/server_cert.pem"
521
+ config["security"]["ssl"][
522
+ "key_file"
523
+ ] = "mcp_proxy_adapter/examples/certs/server_key.pem"
524
+ config["security"]["ssl"][
525
+ "ca_cert_file"
526
+ ] = "mcp_proxy_adapter/examples/certs/ca_cert.pem"
527
+
497
528
  config["security"]["auth"]["enabled"] = True
498
529
  config["security"]["auth"]["methods"] = ["api_key"]
499
530
  config["security"]["auth"]["api_keys"] = {
500
531
  "test-token-123": {
501
532
  "roles": ["admin"],
502
533
  "permissions": ["*"],
503
- "expires": None
534
+ "expires": None,
504
535
  },
505
536
  "user-token-456": {
506
537
  "roles": ["user"],
507
538
  "permissions": ["read", "execute"],
508
- "expires": None
509
- }
539
+ "expires": None,
540
+ },
510
541
  }
511
542
  config["security"]["permissions"]["enabled"] = True
512
- config["security"]["permissions"]["roles_file"] = "mcp_proxy_adapter/examples/server_configs/roles.json"
543
+ config["security"]["permissions"][
544
+ "roles_file"
545
+ ] = "mcp_proxy_adapter/examples/server_configs/roles.json"
513
546
  config["protocols"]["enabled"] = False # Disable ProtocolMiddleware
514
-
547
+
515
548
  return config
516
-
517
- def _get_mtls_no_protocol_middleware_config(self, base_config: Dict[str, Any]) -> Dict[str, Any]:
549
+
550
+ def _get_mtls_no_protocol_middleware_config(
551
+ self, base_config: Dict[str, Any]
552
+ ) -> Dict[str, Any]:
518
553
  """Get mTLS configuration without ProtocolMiddleware."""
519
554
  config = base_config.copy()
520
-
555
+
521
556
  # mTLS settings
522
557
  config["server"]["port"] = 8447
523
558
  config["ssl"]["enabled"] = True
@@ -526,72 +561,84 @@ class ConfigGenerator:
526
561
  config["ssl"]["ca_cert"] = "mcp_proxy_adapter/examples/certs/ca_cert.pem"
527
562
  config["ssl"]["verify_client"] = True
528
563
  config["ssl"]["client_cert_required"] = True
529
-
564
+
530
565
  config["security"]["ssl"]["enabled"] = True
531
- config["security"]["ssl"]["cert_file"] = "mcp_proxy_adapter/examples/certs/server_cert.pem"
532
- config["security"]["ssl"]["key_file"] = "mcp_proxy_adapter/examples/certs/server_key.pem"
533
- config["security"]["ssl"]["ca_cert_file"] = "mcp_proxy_adapter/examples/certs/ca_cert.pem"
534
- config["security"]["ssl"]["client_cert_file"] = "mcp_proxy_adapter/examples/certs/client_cert.pem"
535
- config["security"]["ssl"]["client_key_file"] = "mcp_proxy_adapter/examples/certs/client_key.pem"
566
+ config["security"]["ssl"][
567
+ "cert_file"
568
+ ] = "mcp_proxy_adapter/examples/certs/server_cert.pem"
569
+ config["security"]["ssl"][
570
+ "key_file"
571
+ ] = "mcp_proxy_adapter/examples/certs/server_key.pem"
572
+ config["security"]["ssl"][
573
+ "ca_cert_file"
574
+ ] = "mcp_proxy_adapter/examples/certs/ca_cert.pem"
575
+ config["security"]["ssl"][
576
+ "client_cert_file"
577
+ ] = "mcp_proxy_adapter/examples/certs/client_cert.pem"
578
+ config["security"]["ssl"][
579
+ "client_key_file"
580
+ ] = "mcp_proxy_adapter/examples/certs/client_key.pem"
536
581
  config["security"]["ssl"]["verify_mode"] = "CERT_REQUIRED"
537
-
582
+
538
583
  config["security"]["auth"]["enabled"] = True
539
584
  config["security"]["auth"]["methods"] = ["certificate"]
540
585
  config["security"]["auth"]["certificate_auth"] = True
541
586
  config["security"]["permissions"]["enabled"] = True
542
- config["security"]["permissions"]["roles_file"] = "mcp_proxy_adapter/examples/server_configs/roles.json"
587
+ config["security"]["permissions"][
588
+ "roles_file"
589
+ ] = "mcp_proxy_adapter/examples/server_configs/roles.json"
543
590
  config["protocols"]["enabled"] = False # Disable ProtocolMiddleware
544
-
591
+
545
592
  return config
546
-
593
+
547
594
  def _get_secure_config(self, base_config: Dict[str, Any]) -> Dict[str, Any]:
548
595
  """Get secure configuration with all security features enabled."""
549
596
  config = base_config.copy()
550
-
597
+
551
598
  # Enable all security features
552
599
  config["security"]["enabled"] = True
553
600
  config["security"]["ssl"]["enabled"] = True
554
601
  config["security"]["auth"]["enabled"] = True
555
602
  config["security"]["permissions"]["enabled"] = True
556
603
  config["security"]["rate_limit"]["enabled"] = True
557
-
604
+
558
605
  # Enable registration with certificate auth
559
606
  config["registration"]["enabled"] = True
560
607
  config["registration"]["auth_method"] = "certificate"
561
608
  config["registration"]["certificate"]["enabled"] = True
562
-
609
+
563
610
  # Set secure defaults
564
611
  config["security"]["ssl"]["min_tls_version"] = "TLSv1.2"
565
612
  config["security"]["auth"]["methods"] = ["api_key", "jwt"]
566
613
  config["security"]["permissions"]["strict_mode"] = True
567
614
  config["security"]["rate_limit"]["burst_limit"] = 1
568
-
615
+
569
616
  return config
570
-
617
+
571
618
  def _get_development_config(self, base_config: Dict[str, Any]) -> Dict[str, Any]:
572
619
  """Get development configuration with debug enabled."""
573
620
  config = base_config.copy()
574
-
621
+
575
622
  # Enable debug features
576
623
  config["server"]["debug"] = True
577
624
  config["security"]["debug"] = True
578
625
  config["logging"]["level"] = "DEBUG"
579
-
626
+
580
627
  # Enable registration with token auth for development
581
628
  config["registration"]["enabled"] = True
582
629
  config["registration"]["auth_method"] = "token"
583
630
  config["registration"]["token"]["enabled"] = True
584
-
631
+
585
632
  # Relax security for development
586
633
  config["security"]["rate_limit"]["default_requests_per_minute"] = 1000
587
634
  config["security"]["permissions"]["strict_mode"] = False
588
-
635
+
589
636
  return config
590
-
637
+
591
638
  def _add_comments(self, json_str: str, config_type: str) -> str:
592
639
  """Add comments to JSON configuration."""
593
640
  comments = self._get_comments_for_type(config_type)
594
-
641
+
595
642
  # Add header comment
596
643
  commented_config = f"""/**
597
644
  * MCP Proxy Adapter Configuration
@@ -607,7 +654,7 @@ class ConfigGenerator:
607
654
  */
608
655
 
609
656
  """
610
-
657
+
611
658
  # Add section comments
612
659
  for section, comment in comments.items():
613
660
  if section in json_str:
@@ -615,15 +662,15 @@ class ConfigGenerator:
615
662
  section_start = json_str.find(f'"{section}":')
616
663
  if section_start != -1:
617
664
  # Find the line start
618
- line_start = json_str.rfind('\n', 0, section_start) + 1
665
+ line_start = json_str.rfind("\n", 0, section_start) + 1
619
666
  json_str = (
620
- json_str[:line_start] +
621
- f" // {comment}\n" +
622
- json_str[line_start:]
667
+ json_str[:line_start]
668
+ + f" // {comment}\n"
669
+ + json_str[line_start:]
623
670
  )
624
-
671
+
625
672
  return commented_config + json_str
626
-
673
+
627
674
  def _get_comments_for_type(self, config_type: str) -> Dict[str, str]:
628
675
  """Get comments for configuration sections."""
629
676
  base_comments = {
@@ -634,103 +681,157 @@ class ConfigGenerator:
634
681
  "logging": "Logging configuration for the application",
635
682
  "commands": "Command management and discovery settings",
636
683
  "hooks": "Application and command hooks configuration",
637
- "protocols": "Protocol endpoints and settings"
684
+ "protocols": "Protocol endpoints and settings",
638
685
  }
639
-
686
+
640
687
  if config_type == "minimal":
641
- base_comments["security"] = "Security framework configuration (disabled for minimal setup)"
642
- base_comments["registration"] = "Proxy registration configuration (disabled for minimal setup)"
688
+ base_comments["security"] = (
689
+ "Security framework configuration (disabled for minimal setup)"
690
+ )
691
+ base_comments["registration"] = (
692
+ "Proxy registration configuration (disabled for minimal setup)"
693
+ )
643
694
  elif config_type == "secure":
644
- base_comments["security"] = "Security framework configuration (all features enabled)"
645
- base_comments["registration"] = "Proxy registration configuration (certificate authentication enabled)"
695
+ base_comments["security"] = (
696
+ "Security framework configuration (all features enabled)"
697
+ )
698
+ base_comments["registration"] = (
699
+ "Proxy registration configuration (certificate authentication enabled)"
700
+ )
646
701
  elif config_type == "development":
647
- base_comments["security"] = "Security framework configuration (development mode with relaxed settings)"
648
- base_comments["registration"] = "Proxy registration configuration (token authentication for development)"
702
+ base_comments["security"] = (
703
+ "Security framework configuration (development mode with relaxed settings)"
704
+ )
705
+ base_comments["registration"] = (
706
+ "Proxy registration configuration (token authentication for development)"
707
+ )
649
708
  elif config_type in ["basic_http", "http_token"]:
650
709
  base_comments["ssl"] = "SSL/TLS configuration (disabled for HTTP)"
651
- base_comments["security"] = f"Security framework configuration ({config_type} mode)"
710
+ base_comments["security"] = (
711
+ f"Security framework configuration ({config_type} mode)"
712
+ )
652
713
  elif config_type in ["https", "https_token"]:
653
714
  base_comments["ssl"] = "SSL/TLS configuration (enabled for HTTPS)"
654
- base_comments["security"] = f"Security framework configuration ({config_type} mode)"
715
+ base_comments["security"] = (
716
+ f"Security framework configuration ({config_type} mode)"
717
+ )
655
718
  elif config_type == "mtls":
656
- base_comments["ssl"] = "SSL/TLS configuration (enabled for mTLS with client certificate verification)"
657
- base_comments["security"] = "Security framework configuration (mTLS mode with certificate authentication)"
719
+ base_comments["ssl"] = (
720
+ "SSL/TLS configuration (enabled for mTLS with client certificate verification)"
721
+ )
722
+ base_comments["security"] = (
723
+ "Security framework configuration (mTLS mode with certificate authentication)"
724
+ )
658
725
  elif config_type == "https_no_protocol_middleware":
659
- base_comments["ssl"] = "SSL/TLS configuration (enabled for HTTPS without ProtocolMiddleware)"
660
- base_comments["security"] = "Security framework configuration (HTTPS mode without ProtocolMiddleware)"
726
+ base_comments["ssl"] = (
727
+ "SSL/TLS configuration (enabled for HTTPS without ProtocolMiddleware)"
728
+ )
729
+ base_comments["security"] = (
730
+ "Security framework configuration (HTTPS mode without ProtocolMiddleware)"
731
+ )
661
732
  elif config_type == "mtls_no_protocol_middleware":
662
- base_comments["ssl"] = "SSL/TLS configuration (enabled for mTLS without ProtocolMiddleware)"
663
- base_comments["security"] = "Security framework configuration (mTLS mode without ProtocolMiddleware)"
664
-
733
+ base_comments["ssl"] = (
734
+ "SSL/TLS configuration (enabled for mTLS without ProtocolMiddleware)"
735
+ )
736
+ base_comments["security"] = (
737
+ "Security framework configuration (mTLS mode without ProtocolMiddleware)"
738
+ )
739
+
665
740
  return base_comments
666
-
741
+
667
742
  def generate_config_file(self, output_path: str, config_type: str = "full") -> None:
668
743
  """
669
744
  Generate configuration file and save to disk.
670
-
745
+
671
746
  Args:
672
747
  output_path: Path to save the configuration file
673
748
  config_type: Type of configuration to generate
674
749
  """
675
750
  try:
676
751
  config_content = self.generate_config_with_comments(config_type)
677
-
752
+
678
753
  # Create directory if it doesn't exist
679
754
  output_file = Path(output_path)
680
755
  output_file.parent.mkdir(parents=True, exist_ok=True)
681
-
756
+
682
757
  # Write configuration file
683
- with open(output_file, 'w', encoding='utf-8') as f:
758
+ with open(output_file, "w", encoding="utf-8") as f:
684
759
  f.write(config_content)
685
-
760
+
686
761
  logger.info(f"Configuration file generated: {output_path}")
687
762
  logger.info(f"Configuration type: {config_type}")
688
-
763
+
689
764
  except Exception as e:
690
765
  logger.error(f"Failed to generate configuration file: {e}")
691
766
  raise
692
-
767
+
693
768
  def generate_all_configs(self, output_dir: str) -> None:
694
769
  """
695
770
  Generate all configuration types.
696
-
771
+
697
772
  Args:
698
773
  output_dir: Directory to save configuration files
699
774
  """
700
775
  config_types = [
701
- "minimal", "development", "secure", "full",
702
- "basic_http", "http_token", "https", "https_token", "mtls",
703
- "https_no_protocol_middleware", "mtls_no_protocol_middleware"
776
+ "minimal",
777
+ "development",
778
+ "secure",
779
+ "full",
780
+ "basic_http",
781
+ "http_token",
782
+ "https",
783
+ "https_token",
784
+ "mtls",
785
+ "https_no_protocol_middleware",
786
+ "mtls_no_protocol_middleware",
704
787
  ]
705
-
788
+
706
789
  for config_type in config_types:
707
790
  output_path = Path(output_dir) / f"config_{config_type}.json"
708
791
  self.generate_config_file(str(output_path), config_type)
709
-
710
- logger.info(f"Generated {len(config_types)} configuration files in {output_dir}")
792
+
793
+ logger.info(
794
+ f"Generated {len(config_types)} configuration files in {output_dir}"
795
+ )
711
796
 
712
797
 
713
798
  def main():
714
799
  """Main function for command-line usage."""
715
800
  import argparse
716
-
717
- parser = argparse.ArgumentParser(description="Generate MCP Proxy Adapter configuration files")
718
- parser.add_argument("--type",
719
- choices=["minimal", "development", "secure", "full",
720
- "basic_http", "http_token", "https", "https_token", "mtls",
721
- "https_no_protocol_middleware", "mtls_no_protocol_middleware"],
722
- default="full", help="Configuration type to generate")
723
- parser.add_argument("--output", default="./config.json",
724
- help="Output file path")
725
- parser.add_argument("--all", action="store_true",
726
- help="Generate all configuration types")
727
- parser.add_argument("--output-dir", default="./configs",
728
- help="Output directory for all configs")
729
-
801
+
802
+ parser = argparse.ArgumentParser(
803
+ description="Generate MCP Proxy Adapter configuration files"
804
+ )
805
+ parser.add_argument(
806
+ "--type",
807
+ choices=[
808
+ "minimal",
809
+ "development",
810
+ "secure",
811
+ "full",
812
+ "basic_http",
813
+ "http_token",
814
+ "https",
815
+ "https_token",
816
+ "mtls",
817
+ "https_no_protocol_middleware",
818
+ "mtls_no_protocol_middleware",
819
+ ],
820
+ default="full",
821
+ help="Configuration type to generate",
822
+ )
823
+ parser.add_argument("--output", default="./config.json", help="Output file path")
824
+ parser.add_argument(
825
+ "--all", action="store_true", help="Generate all configuration types"
826
+ )
827
+ parser.add_argument(
828
+ "--output-dir", default="./configs", help="Output directory for all configs"
829
+ )
830
+
730
831
  args = parser.parse_args()
731
-
832
+
732
833
  generator = ConfigGenerator()
733
-
834
+
734
835
  if args.all:
735
836
  generator.generate_all_configs(args.output_dir)
736
837
  else: