mcp-proxy-adapter 6.2.18__py3-none-any.whl → 6.2.22__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.
@@ -0,0 +1,740 @@
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
+
266
+ Returns:
267
+ JSON configuration string with comments
268
+ """
269
+ config = self._get_config_by_type(config_type)
270
+
271
+ # Convert to JSON with comments
272
+ json_str = json.dumps(config, indent=2, ensure_ascii=False)
273
+
274
+ # Add comments
275
+ commented_config = self._add_comments(json_str, config_type)
276
+
277
+ return commented_config
278
+
279
+ def _get_config_by_type(self, config_type: str) -> Dict[str, Any]:
280
+ """Get configuration based on type."""
281
+ base_config = self.template_config.copy()
282
+
283
+ if config_type == "minimal":
284
+ return self._get_minimal_config(base_config)
285
+ elif config_type == "secure":
286
+ return self._get_secure_config(base_config)
287
+ elif config_type == "development":
288
+ return self._get_development_config(base_config)
289
+ elif config_type == "basic_http":
290
+ return self._get_basic_http_config(base_config)
291
+ elif config_type == "http_token":
292
+ return self._get_http_token_config(base_config)
293
+ elif config_type == "https":
294
+ return self._get_https_config(base_config)
295
+ elif config_type == "https_token":
296
+ return self._get_https_token_config(base_config)
297
+ elif config_type == "https_no_protocol_middleware":
298
+ return self._get_https_no_protocol_middleware_config(base_config)
299
+ elif config_type == "mtls":
300
+ return self._get_mtls_config(base_config)
301
+ elif config_type == "mtls_no_protocol_middleware":
302
+ return self._get_mtls_no_protocol_middleware_config(base_config)
303
+ else: # full
304
+ return base_config
305
+
306
+ def _get_minimal_config(self, base_config: Dict[str, Any]) -> Dict[str, Any]:
307
+ """Get minimal working configuration."""
308
+ config = base_config.copy()
309
+
310
+ # Disable security for minimal config
311
+ config["security"]["enabled"] = False
312
+ config["security"]["auth"]["enabled"] = False
313
+ config["security"]["permissions"]["enabled"] = False
314
+ config["security"]["rate_limit"]["enabled"] = False
315
+
316
+ # Disable registration for minimal config
317
+ config["registration"]["enabled"] = False
318
+
319
+ # Keep only essential settings
320
+ config["server"]["port"] = 8000
321
+ config["server"]["debug"] = False
322
+
323
+ return config
324
+
325
+ def _get_basic_http_config(self, base_config: Dict[str, Any]) -> Dict[str, Any]:
326
+ """Get basic HTTP configuration."""
327
+ config = base_config.copy()
328
+
329
+ # Basic HTTP settings
330
+ config["server"]["port"] = 8000
331
+ config["ssl"]["enabled"] = False
332
+ config["security"]["ssl"]["enabled"] = False
333
+ config["security"]["auth"]["enabled"] = False
334
+ config["security"]["permissions"]["enabled"] = False
335
+ config["security"]["permissions"]["roles_file"] = None
336
+ config["protocols"]["enabled"] = True
337
+ config["protocols"]["allowed_protocols"] = ["http"]
338
+ config["protocols"]["default_protocol"] = "http"
339
+
340
+ # Enable local proxy registration by default for examples
341
+ config["registration"]["enabled"] = True
342
+ config["registration"]["auth_method"] = "token"
343
+ config["registration"]["token"]["enabled"] = True
344
+ config["registration"]["token"]["token"] = "proxy_registration_token_123"
345
+ config["registration"]["server_url"] = "http://127.0.0.1:3004/proxy"
346
+ config["registration"]["proxy_info"]["name"] = "mcp_example_server"
347
+ config["registration"]["proxy_info"]["capabilities"] = [
348
+ "jsonrpc", "rest", "security", "proxy_registration"
349
+ ]
350
+ config["registration"]["heartbeat"]["enabled"] = True
351
+ config["registration"]["heartbeat"]["interval"] = 30
352
+
353
+ return config
354
+
355
+ def _get_http_token_config(self, base_config: Dict[str, Any]) -> Dict[str, Any]:
356
+ """Get HTTP with token authentication configuration."""
357
+ config = base_config.copy()
358
+
359
+ # HTTP with token auth
360
+ config["server"]["port"] = 8001
361
+ config["ssl"]["enabled"] = False
362
+ config["security"]["ssl"]["enabled"] = False
363
+ config["security"]["auth"]["enabled"] = True
364
+ config["security"]["auth"]["methods"] = ["api_key"]
365
+ config["security"]["auth"]["api_keys"] = {
366
+ "test-token-123": {
367
+ "roles": ["admin"],
368
+ "permissions": ["*"],
369
+ "expires": None
370
+ },
371
+ "user-token-456": {
372
+ "roles": ["user"],
373
+ "permissions": ["read", "execute"],
374
+ "expires": None
375
+ }
376
+ }
377
+ config["security"]["permissions"]["enabled"] = True
378
+ config["security"]["permissions"]["roles_file"] = "mcp_proxy_adapter/examples/server_configs/roles.json"
379
+ config["protocols"]["enabled"] = True
380
+ config["protocols"]["allowed_protocols"] = ["http"]
381
+ config["protocols"]["default_protocol"] = "http"
382
+
383
+ return config
384
+
385
+ def _get_https_config(self, base_config: Dict[str, Any]) -> Dict[str, Any]:
386
+ """Get HTTPS configuration."""
387
+ config = base_config.copy()
388
+
389
+ # HTTPS settings
390
+ config["server"]["port"] = 8443
391
+ config["ssl"]["enabled"] = True
392
+ config["ssl"]["cert_file"] = "mcp_proxy_adapter/examples/certs/server_cert.pem"
393
+ config["ssl"]["key_file"] = "mcp_proxy_adapter/examples/certs/server_key.pem"
394
+ config["ssl"]["ca_cert"] = "mcp_proxy_adapter/examples/certs/ca_cert.pem"
395
+
396
+ config["security"]["ssl"]["enabled"] = True
397
+ config["security"]["ssl"]["cert_file"] = "mcp_proxy_adapter/examples/certs/server_cert.pem"
398
+ config["security"]["ssl"]["key_file"] = "mcp_proxy_adapter/examples/certs/server_key.pem"
399
+ config["security"]["ssl"]["ca_cert_file"] = "mcp_proxy_adapter/examples/certs/ca_cert.pem"
400
+
401
+ config["security"]["auth"]["enabled"] = False
402
+ config["security"]["permissions"]["enabled"] = False
403
+ config["security"]["permissions"]["roles_file"] = None
404
+ config["protocols"]["enabled"] = True
405
+ config["protocols"]["allowed_protocols"] = ["http", "https"]
406
+ config["protocols"]["default_protocol"] = "https"
407
+
408
+ return config
409
+
410
+ def _get_https_token_config(self, base_config: Dict[str, Any]) -> Dict[str, Any]:
411
+ """Get HTTPS with token authentication configuration."""
412
+ config = base_config.copy()
413
+
414
+ # HTTPS with token auth
415
+ config["server"]["port"] = 8444
416
+ config["ssl"]["enabled"] = True
417
+ config["ssl"]["cert_file"] = "mcp_proxy_adapter/examples/certs/server_cert.pem"
418
+ config["ssl"]["key_file"] = "mcp_proxy_adapter/examples/certs/server_key.pem"
419
+ config["ssl"]["ca_cert"] = "mcp_proxy_adapter/examples/certs/ca_cert.pem"
420
+
421
+ config["security"]["ssl"]["enabled"] = True
422
+ config["security"]["ssl"]["cert_file"] = "mcp_proxy_adapter/examples/certs/server_cert.pem"
423
+ config["security"]["ssl"]["key_file"] = "mcp_proxy_adapter/examples/certs/server_key.pem"
424
+ config["security"]["ssl"]["ca_cert_file"] = "mcp_proxy_adapter/examples/certs/ca_cert.pem"
425
+
426
+ config["security"]["auth"]["enabled"] = True
427
+ config["security"]["auth"]["methods"] = ["api_key"]
428
+ config["security"]["auth"]["api_keys"] = {
429
+ "test-token-123": {
430
+ "roles": ["admin"],
431
+ "permissions": ["*"],
432
+ "expires": None
433
+ },
434
+ "user-token-456": {
435
+ "roles": ["user"],
436
+ "permissions": ["read", "execute"],
437
+ "expires": None
438
+ }
439
+ }
440
+ config["security"]["permissions"]["enabled"] = True
441
+ config["security"]["permissions"]["roles_file"] = "mcp_proxy_adapter/examples/server_configs/roles.json"
442
+ config["protocols"]["enabled"] = True
443
+ config["protocols"]["allowed_protocols"] = ["http", "https"]
444
+ config["protocols"]["default_protocol"] = "https"
445
+
446
+ return config
447
+
448
+ def _get_mtls_config(self, base_config: Dict[str, Any]) -> Dict[str, Any]:
449
+ """Get mTLS configuration."""
450
+ config = base_config.copy()
451
+
452
+ # mTLS settings
453
+ config["server"]["port"] = 8445
454
+ config["ssl"]["enabled"] = True
455
+ config["ssl"]["cert_file"] = "mcp_proxy_adapter/examples/certs/server_cert.pem"
456
+ config["ssl"]["key_file"] = "mcp_proxy_adapter/examples/certs/server_key.pem"
457
+ config["ssl"]["ca_cert"] = "mcp_proxy_adapter/examples/certs/ca_cert.pem"
458
+ config["ssl"]["verify_client"] = True
459
+ config["ssl"]["client_cert_required"] = True
460
+
461
+ config["security"]["ssl"]["enabled"] = True
462
+ config["security"]["ssl"]["cert_file"] = "mcp_proxy_adapter/examples/certs/server_cert.pem"
463
+ config["security"]["ssl"]["key_file"] = "mcp_proxy_adapter/examples/certs/server_key.pem"
464
+ config["security"]["ssl"]["ca_cert_file"] = "mcp_proxy_adapter/examples/certs/ca_cert.pem"
465
+ config["security"]["ssl"]["client_cert_file"] = "mcp_proxy_adapter/examples/certs/client_cert.pem"
466
+ config["security"]["ssl"]["client_key_file"] = "mcp_proxy_adapter/examples/certs/client_key.pem"
467
+ config["security"]["ssl"]["verify_mode"] = "CERT_REQUIRED"
468
+
469
+ config["security"]["auth"]["enabled"] = True
470
+ config["security"]["auth"]["methods"] = ["certificate"]
471
+ config["security"]["auth"]["certificate_auth"] = True
472
+ config["security"]["permissions"]["enabled"] = True
473
+ config["security"]["permissions"]["roles_file"] = "mcp_proxy_adapter/examples/server_configs/roles.json"
474
+ config["protocols"]["enabled"] = True
475
+ config["protocols"]["allowed_protocols"] = ["https", "mtls"]
476
+ config["protocols"]["default_protocol"] = "https"
477
+
478
+ return config
479
+
480
+ def _get_https_no_protocol_middleware_config(self, base_config: Dict[str, Any]) -> Dict[str, Any]:
481
+ """Get HTTPS configuration without ProtocolMiddleware."""
482
+ config = base_config.copy()
483
+
484
+ # HTTPS settings
485
+ config["server"]["port"] = 8445
486
+ config["ssl"]["enabled"] = True
487
+ config["ssl"]["cert_file"] = "mcp_proxy_adapter/examples/certs/server_cert.pem"
488
+ config["ssl"]["key_file"] = "mcp_proxy_adapter/examples/certs/server_key.pem"
489
+ config["ssl"]["ca_cert"] = "mcp_proxy_adapter/examples/certs/ca_cert.pem"
490
+
491
+ config["security"]["ssl"]["enabled"] = True
492
+ config["security"]["ssl"]["cert_file"] = "mcp_proxy_adapter/examples/certs/server_cert.pem"
493
+ config["security"]["ssl"]["key_file"] = "mcp_proxy_adapter/examples/certs/server_key.pem"
494
+ config["security"]["ssl"]["ca_cert_file"] = "mcp_proxy_adapter/examples/certs/ca_cert.pem"
495
+
496
+ config["security"]["auth"]["enabled"] = True
497
+ config["security"]["auth"]["methods"] = ["api_key"]
498
+ config["security"]["auth"]["api_keys"] = {
499
+ "test-token-123": {
500
+ "roles": ["admin"],
501
+ "permissions": ["*"],
502
+ "expires": None
503
+ },
504
+ "user-token-456": {
505
+ "roles": ["user"],
506
+ "permissions": ["read", "execute"],
507
+ "expires": None
508
+ }
509
+ }
510
+ config["security"]["permissions"]["enabled"] = True
511
+ config["security"]["permissions"]["roles_file"] = "mcp_proxy_adapter/examples/server_configs/roles.json"
512
+ config["protocols"]["enabled"] = False # Disable ProtocolMiddleware
513
+
514
+ return config
515
+
516
+ def _get_mtls_no_protocol_middleware_config(self, base_config: Dict[str, Any]) -> Dict[str, Any]:
517
+ """Get mTLS configuration without ProtocolMiddleware."""
518
+ config = base_config.copy()
519
+
520
+ # mTLS settings
521
+ config["server"]["port"] = 8447
522
+ config["ssl"]["enabled"] = True
523
+ config["ssl"]["cert_file"] = "mcp_proxy_adapter/examples/certs/server_cert.pem"
524
+ config["ssl"]["key_file"] = "mcp_proxy_adapter/examples/certs/server_key.pem"
525
+ config["ssl"]["ca_cert"] = "mcp_proxy_adapter/examples/certs/ca_cert.pem"
526
+ config["ssl"]["verify_client"] = True
527
+ config["ssl"]["client_cert_required"] = True
528
+
529
+ config["security"]["ssl"]["enabled"] = True
530
+ config["security"]["ssl"]["cert_file"] = "mcp_proxy_adapter/examples/certs/server_cert.pem"
531
+ config["security"]["ssl"]["key_file"] = "mcp_proxy_adapter/examples/certs/server_key.pem"
532
+ config["security"]["ssl"]["ca_cert_file"] = "mcp_proxy_adapter/examples/certs/ca_cert.pem"
533
+ config["security"]["ssl"]["client_cert_file"] = "mcp_proxy_adapter/examples/certs/client_cert.pem"
534
+ config["security"]["ssl"]["client_key_file"] = "mcp_proxy_adapter/examples/certs/client_key.pem"
535
+ config["security"]["ssl"]["verify_mode"] = "CERT_REQUIRED"
536
+
537
+ config["security"]["auth"]["enabled"] = True
538
+ config["security"]["auth"]["methods"] = ["certificate"]
539
+ config["security"]["auth"]["certificate_auth"] = True
540
+ config["security"]["permissions"]["enabled"] = True
541
+ config["security"]["permissions"]["roles_file"] = "mcp_proxy_adapter/examples/server_configs/roles.json"
542
+ config["protocols"]["enabled"] = False # Disable ProtocolMiddleware
543
+
544
+ return config
545
+
546
+ def _get_secure_config(self, base_config: Dict[str, Any]) -> Dict[str, Any]:
547
+ """Get secure configuration with all security features enabled."""
548
+ config = base_config.copy()
549
+
550
+ # Enable all security features
551
+ config["security"]["enabled"] = True
552
+ config["security"]["ssl"]["enabled"] = True
553
+ config["security"]["auth"]["enabled"] = True
554
+ config["security"]["permissions"]["enabled"] = True
555
+ config["security"]["rate_limit"]["enabled"] = True
556
+
557
+ # Enable registration with certificate auth
558
+ config["registration"]["enabled"] = True
559
+ config["registration"]["auth_method"] = "certificate"
560
+ config["registration"]["certificate"]["enabled"] = True
561
+
562
+ # Set secure defaults
563
+ config["security"]["ssl"]["min_tls_version"] = "TLSv1.2"
564
+ config["security"]["auth"]["methods"] = ["api_key", "jwt"]
565
+ config["security"]["permissions"]["strict_mode"] = True
566
+ config["security"]["rate_limit"]["burst_limit"] = 1
567
+
568
+ return config
569
+
570
+ def _get_development_config(self, base_config: Dict[str, Any]) -> Dict[str, Any]:
571
+ """Get development configuration with debug enabled."""
572
+ config = base_config.copy()
573
+
574
+ # Enable debug features
575
+ config["server"]["debug"] = True
576
+ config["security"]["debug"] = True
577
+ config["logging"]["level"] = "DEBUG"
578
+
579
+ # Enable registration with token auth for development
580
+ config["registration"]["enabled"] = True
581
+ config["registration"]["auth_method"] = "token"
582
+ config["registration"]["token"]["enabled"] = True
583
+
584
+ # Relax security for development
585
+ config["security"]["rate_limit"]["default_requests_per_minute"] = 1000
586
+ config["security"]["permissions"]["strict_mode"] = False
587
+
588
+ return config
589
+
590
+ def _add_comments(self, json_str: str, config_type: str) -> str:
591
+ """Add comments to JSON configuration."""
592
+ comments = self._get_comments_for_type(config_type)
593
+
594
+ # Add header comment
595
+ commented_config = f"""/**
596
+ * MCP Proxy Adapter Configuration
597
+ *
598
+ * This configuration file combines settings for both mcp_proxy_adapter
599
+ * and mcp_security_framework in a unified format.
600
+ *
601
+ * Configuration Type: {config_type.title()}
602
+ * Generated by: ConfigGenerator
603
+ *
604
+ * IMPORTANT: This is a template configuration. Please customize it
605
+ * according to your specific requirements and security needs.
606
+ */
607
+
608
+ """
609
+
610
+ # Add section comments
611
+ for section, comment in comments.items():
612
+ if section in json_str:
613
+ # Find the section and add comment before it
614
+ section_start = json_str.find(f'"{section}":')
615
+ if section_start != -1:
616
+ # Find the line start
617
+ line_start = json_str.rfind('\n', 0, section_start) + 1
618
+ json_str = (
619
+ json_str[:line_start] +
620
+ f" // {comment}\n" +
621
+ json_str[line_start:]
622
+ )
623
+
624
+ return commented_config + json_str
625
+
626
+ def _get_comments_for_type(self, config_type: str) -> Dict[str, str]:
627
+ """Get comments for configuration sections."""
628
+ base_comments = {
629
+ "server": "Server configuration for FastAPI application",
630
+ "ssl": "SSL/TLS configuration for secure connections",
631
+ "security": "Security framework configuration (mcp_security_framework)",
632
+ "registration": "Proxy registration configuration for secure proxy discovery",
633
+ "logging": "Logging configuration for the application",
634
+ "commands": "Command management and discovery settings",
635
+ "hooks": "Application and command hooks configuration",
636
+ "protocols": "Protocol endpoints and settings"
637
+ }
638
+
639
+ if config_type == "minimal":
640
+ base_comments["security"] = "Security framework configuration (disabled for minimal setup)"
641
+ base_comments["registration"] = "Proxy registration configuration (disabled for minimal setup)"
642
+ elif config_type == "secure":
643
+ base_comments["security"] = "Security framework configuration (all features enabled)"
644
+ base_comments["registration"] = "Proxy registration configuration (certificate authentication enabled)"
645
+ elif config_type == "development":
646
+ base_comments["security"] = "Security framework configuration (development mode with relaxed settings)"
647
+ base_comments["registration"] = "Proxy registration configuration (token authentication for development)"
648
+ elif config_type in ["basic_http", "http_token"]:
649
+ base_comments["ssl"] = "SSL/TLS configuration (disabled for HTTP)"
650
+ base_comments["security"] = f"Security framework configuration ({config_type} mode)"
651
+ elif config_type in ["https", "https_token"]:
652
+ base_comments["ssl"] = "SSL/TLS configuration (enabled for HTTPS)"
653
+ base_comments["security"] = f"Security framework configuration ({config_type} mode)"
654
+ elif config_type == "mtls":
655
+ base_comments["ssl"] = "SSL/TLS configuration (enabled for mTLS with client certificate verification)"
656
+ base_comments["security"] = "Security framework configuration (mTLS mode with certificate authentication)"
657
+ elif config_type == "https_no_protocol_middleware":
658
+ base_comments["ssl"] = "SSL/TLS configuration (enabled for HTTPS without ProtocolMiddleware)"
659
+ base_comments["security"] = "Security framework configuration (HTTPS mode without ProtocolMiddleware)"
660
+ elif config_type == "mtls_no_protocol_middleware":
661
+ base_comments["ssl"] = "SSL/TLS configuration (enabled for mTLS without ProtocolMiddleware)"
662
+ base_comments["security"] = "Security framework configuration (mTLS mode without ProtocolMiddleware)"
663
+
664
+ return base_comments
665
+
666
+ def generate_config_file(self, output_path: str, config_type: str = "full") -> None:
667
+ """
668
+ Generate configuration file and save to disk.
669
+
670
+ Args:
671
+ output_path: Path to save the configuration file
672
+ config_type: Type of configuration to generate
673
+ """
674
+ try:
675
+ config_content = self.generate_config_with_comments(config_type)
676
+
677
+ # Create directory if it doesn't exist
678
+ output_file = Path(output_path)
679
+ output_file.parent.mkdir(parents=True, exist_ok=True)
680
+
681
+ # Write configuration file
682
+ with open(output_file, 'w', encoding='utf-8') as f:
683
+ f.write(config_content)
684
+
685
+ logger.info(f"Configuration file generated: {output_path}")
686
+ logger.info(f"Configuration type: {config_type}")
687
+
688
+ except Exception as e:
689
+ logger.error(f"Failed to generate configuration file: {e}")
690
+ raise
691
+
692
+ def generate_all_configs(self, output_dir: str) -> None:
693
+ """
694
+ Generate all configuration types.
695
+
696
+ Args:
697
+ output_dir: Directory to save configuration files
698
+ """
699
+ config_types = [
700
+ "minimal", "development", "secure", "full",
701
+ "basic_http", "http_token", "https", "https_token", "mtls",
702
+ "https_no_protocol_middleware", "mtls_no_protocol_middleware"
703
+ ]
704
+
705
+ for config_type in config_types:
706
+ output_path = Path(output_dir) / f"config_{config_type}.json"
707
+ self.generate_config_file(str(output_path), config_type)
708
+
709
+ logger.info(f"Generated {len(config_types)} configuration files in {output_dir}")
710
+
711
+
712
+ def main():
713
+ """Main function for command-line usage."""
714
+ import argparse
715
+
716
+ parser = argparse.ArgumentParser(description="Generate MCP Proxy Adapter configuration files")
717
+ parser.add_argument("--type",
718
+ choices=["minimal", "development", "secure", "full",
719
+ "basic_http", "http_token", "https", "https_token", "mtls",
720
+ "https_no_protocol_middleware", "mtls_no_protocol_middleware"],
721
+ default="full", help="Configuration type to generate")
722
+ parser.add_argument("--output", default="./config.json",
723
+ help="Output file path")
724
+ parser.add_argument("--all", action="store_true",
725
+ help="Generate all configuration types")
726
+ parser.add_argument("--output-dir", default="./configs",
727
+ help="Output directory for all configs")
728
+
729
+ args = parser.parse_args()
730
+
731
+ generator = ConfigGenerator()
732
+
733
+ if args.all:
734
+ generator.generate_all_configs(args.output_dir)
735
+ else:
736
+ generator.generate_config_file(args.output, args.type)
737
+
738
+
739
+ if __name__ == "__main__":
740
+ main()