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