mcp-proxy-adapter 6.4.43__py3-none-any.whl → 6.4.45__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 (33) hide show
  1. mcp_proxy_adapter/core/proxy_registration.py +100 -68
  2. mcp_proxy_adapter/examples/bugfix_certificate_config.py +284 -0
  3. mcp_proxy_adapter/examples/cert_manager_bugfix.py +203 -0
  4. mcp_proxy_adapter/examples/config_builder.py +574 -0
  5. mcp_proxy_adapter/examples/config_cli.py +283 -0
  6. mcp_proxy_adapter/examples/create_test_configs.py +169 -266
  7. mcp_proxy_adapter/examples/generate_certificates_bugfix.py +374 -0
  8. mcp_proxy_adapter/examples/generate_certificates_cli.py +406 -0
  9. mcp_proxy_adapter/examples/generate_certificates_fixed.py +313 -0
  10. mcp_proxy_adapter/examples/generate_certificates_framework.py +366 -0
  11. mcp_proxy_adapter/examples/generate_certificates_openssl.py +391 -0
  12. mcp_proxy_adapter/examples/required_certificates.py +210 -0
  13. mcp_proxy_adapter/examples/run_full_test_suite.py +117 -13
  14. mcp_proxy_adapter/examples/run_security_tests_fixed.py +41 -25
  15. mcp_proxy_adapter/examples/security_test_client.py +333 -86
  16. mcp_proxy_adapter/examples/test_config_builder.py +450 -0
  17. mcp_proxy_adapter/examples/update_config_certificates.py +136 -0
  18. mcp_proxy_adapter/version.py +1 -1
  19. {mcp_proxy_adapter-6.4.43.dist-info → mcp_proxy_adapter-6.4.45.dist-info}/METADATA +81 -1
  20. {mcp_proxy_adapter-6.4.43.dist-info → mcp_proxy_adapter-6.4.45.dist-info}/RECORD +23 -20
  21. mcp_proxy_adapter-6.4.45.dist-info/entry_points.txt +12 -0
  22. mcp_proxy_adapter/examples/create_certificates_simple.py +0 -661
  23. mcp_proxy_adapter/examples/generate_certificates.py +0 -192
  24. mcp_proxy_adapter/examples/generate_certificates_and_tokens.py +0 -515
  25. mcp_proxy_adapter/examples/generate_test_configs.py +0 -393
  26. mcp_proxy_adapter/examples/run_security_tests.py +0 -677
  27. mcp_proxy_adapter/examples/scripts/config_generator.py +0 -842
  28. mcp_proxy_adapter/examples/scripts/create_certificates_simple.py +0 -673
  29. mcp_proxy_adapter/examples/scripts/generate_certificates_and_tokens.py +0 -515
  30. mcp_proxy_adapter/examples/test_config_generator.py +0 -102
  31. mcp_proxy_adapter-6.4.43.dist-info/entry_points.txt +0 -2
  32. {mcp_proxy_adapter-6.4.43.dist-info → mcp_proxy_adapter-6.4.45.dist-info}/WHEEL +0 -0
  33. {mcp_proxy_adapter-6.4.43.dist-info → mcp_proxy_adapter-6.4.45.dist-info}/top_level.txt +0 -0
@@ -0,0 +1,574 @@
1
+ #!/usr/bin/env python3
2
+ """
3
+ Advanced Configuration Builder for MCP Proxy Adapter
4
+ Creates configurations from scratch based on protocol, authentication, and other parameters.
5
+
6
+ Author: Vasiliy Zdanovskiy
7
+ email: vasilyvz@gmail.com
8
+ """
9
+ import json
10
+ import uuid
11
+ from pathlib import Path
12
+ from typing import Dict, Any, List, Optional, Union
13
+ from enum import Enum
14
+
15
+
16
+ class Protocol(Enum):
17
+ """Supported protocols."""
18
+ HTTP = "http"
19
+ HTTPS = "https"
20
+ MTLS = "mtls"
21
+
22
+
23
+ class AuthMethod(Enum):
24
+ """Supported authentication methods."""
25
+ NONE = "none"
26
+ TOKEN = "token"
27
+ BASIC = "basic"
28
+
29
+
30
+ class ConfigBuilder:
31
+ """Advanced configuration builder for MCP Proxy Adapter."""
32
+
33
+ def __init__(self):
34
+ """Initialize the configuration builder."""
35
+ self.config = {}
36
+ self._reset_to_defaults()
37
+
38
+ def _reset_to_defaults(self):
39
+ """Reset configuration to default values."""
40
+ self.config = {
41
+ "uuid": str(uuid.uuid4()),
42
+ "server": {
43
+ "host": "0.0.0.0",
44
+ "port": 8000,
45
+ "debug": False,
46
+ "log_level": "INFO"
47
+ },
48
+ "logging": {
49
+ "level": "INFO",
50
+ "file": None,
51
+ "log_dir": "./logs",
52
+ "log_file": "mcp_proxy_adapter.log",
53
+ "error_log_file": "mcp_proxy_adapter_error.log",
54
+ "access_log_file": "mcp_proxy_adapter_access.log",
55
+ "max_file_size": "10MB",
56
+ "backup_count": 5,
57
+ "format": "%(asctime)s - %(name)s - %(levelname)s - %(message)s",
58
+ "date_format": "%Y-%m-%d %H:%M:%S",
59
+ "console_output": True,
60
+ "file_output": True
61
+ },
62
+ "commands": {
63
+ "auto_discovery": True,
64
+ "commands_directory": "./commands",
65
+ "catalog_directory": "./catalog",
66
+ "plugin_servers": [],
67
+ "auto_install_dependencies": True,
68
+ "enabled_commands": [
69
+ "health",
70
+ "echo",
71
+ "list",
72
+ "help"
73
+ ],
74
+ "disabled_commands": [],
75
+ "custom_commands_path": "./commands"
76
+ },
77
+ "ssl": {
78
+ "enabled": False,
79
+ "mode": "https_only",
80
+ "cert_file": None,
81
+ "key_file": None,
82
+ "ca_cert": None,
83
+ "verify_client": False,
84
+ "client_cert_required": False,
85
+ "cipher_suites": [
86
+ "TLS_AES_256_GCM_SHA384",
87
+ "TLS_CHACHA20_POLY1305_SHA256"
88
+ ],
89
+ "min_tls_version": "TLSv1.2",
90
+ "max_tls_version": None
91
+ },
92
+ "transport": {
93
+ "type": "http",
94
+ "port": None,
95
+ "ssl": {
96
+ "enabled": False,
97
+ "cert_file": None,
98
+ "key_file": None,
99
+ "ca_cert": None,
100
+ "verify_client": False,
101
+ "client_cert_required": False
102
+ }
103
+ },
104
+ "proxy_registration": {
105
+ "enabled": False,
106
+ "auth_method": "token",
107
+ "server_url": None,
108
+ "proxy_url": None,
109
+ "fallback_proxy_url": None,
110
+ "ssl": {
111
+ "ca_cert": None,
112
+ "verify_mode": "CERT_REQUIRED"
113
+ },
114
+ "heartbeat": {
115
+ "enabled": True,
116
+ "interval": 30,
117
+ "timeout": 10
118
+ },
119
+ "server_id": "mcp_proxy_adapter",
120
+ "server_name": "MCP Proxy Adapter",
121
+ "description": "MCP Proxy Adapter Server",
122
+ "version": "1.0.0",
123
+ "capabilities": ["jsonrpc", "rest", "health"],
124
+ "endpoints": {
125
+ "jsonrpc": "/api/jsonrpc",
126
+ "rest": "/cmd",
127
+ "health": "/health"
128
+ },
129
+ "auth": {
130
+ "token": None
131
+ }
132
+ },
133
+ "debug": {
134
+ "enabled": False,
135
+ "log_level": "DEBUG",
136
+ "trace_requests": False,
137
+ "trace_responses": False
138
+ },
139
+ "security": {
140
+ "framework": "mcp_security_framework",
141
+ "enabled": False,
142
+ "debug": False,
143
+ "environment": "dev",
144
+ "version": "1.0.0",
145
+ "auth": {
146
+ "enabled": False,
147
+ "methods": ["api_key"],
148
+ "api_keys": {},
149
+ "user_roles": {},
150
+ "jwt_secret": "",
151
+ "jwt_algorithm": "HS256",
152
+ "jwt_expiry_hours": 24,
153
+ "certificate_auth": False,
154
+ "certificate_roles_oid": "1.3.6.1.4.1.99999.1.1",
155
+ "certificate_permissions_oid": "1.3.6.1.4.1.99999.1.2",
156
+ "basic_auth": False,
157
+ "oauth2_config": None,
158
+ "public_paths": ["/health", "/docs", "/openapi.json"],
159
+ "security_headers": None
160
+ },
161
+ "ssl": {
162
+ "enabled": False,
163
+ "cert_file": None,
164
+ "key_file": None,
165
+ "ca_cert_file": None,
166
+ "client_cert_file": None,
167
+ "client_key_file": None,
168
+ "verify_mode": "CERT_NONE",
169
+ "min_tls_version": "TLSv1.2",
170
+ "max_tls_version": None,
171
+ "cipher_suite": None,
172
+ "check_hostname": True,
173
+ "check_expiry": True,
174
+ "expiry_warning_days": 30
175
+ },
176
+ "certificates": {
177
+ "enabled": False,
178
+ "ca_cert_path": None,
179
+ "ca_key_path": None,
180
+ "cert_storage_path": "./certs",
181
+ "key_storage_path": "./keys",
182
+ "default_validity_days": 365,
183
+ "key_size": 2048,
184
+ "hash_algorithm": "sha256",
185
+ "crl_enabled": False,
186
+ "crl_path": None,
187
+ "crl_url": None,
188
+ "crl_validity_days": 30,
189
+ "auto_renewal": False,
190
+ "renewal_threshold_days": 30
191
+ },
192
+ "permissions": {
193
+ "enabled": False,
194
+ "roles_file": None,
195
+ "default_role": "guest",
196
+ "admin_role": "admin",
197
+ "role_hierarchy": {},
198
+ "permission_cache_enabled": False,
199
+ "permission_cache_ttl": 300,
200
+ "wildcard_permissions": False,
201
+ "strict_mode": False,
202
+ "roles": None
203
+ },
204
+ "rate_limit": {
205
+ "enabled": False,
206
+ "default_requests_per_minute": 60,
207
+ "default_requests_per_hour": 1000,
208
+ "burst_limit": 2,
209
+ "window_size_seconds": 60,
210
+ "storage_backend": "memory",
211
+ "redis_config": None,
212
+ "cleanup_interval": 300,
213
+ "exempt_paths": ["/health", "/docs", "/openapi.json"],
214
+ "exempt_roles": ["admin"]
215
+ },
216
+ "logging": {
217
+ "enabled": True,
218
+ "level": "INFO",
219
+ "format": "%(asctime)s - %(name)s - %(levelname)s - %(message)s",
220
+ "date_format": "%Y-%m-%d %H:%M:%S",
221
+ "file_path": None,
222
+ "max_file_size": 10,
223
+ "backup_count": 5,
224
+ "console_output": True,
225
+ "json_format": False,
226
+ "include_timestamp": True,
227
+ "include_level": True,
228
+ "include_module": True
229
+ }
230
+ },
231
+ "protocols": {
232
+ "enabled": True,
233
+ "allowed_protocols": ["http"],
234
+ "default_protocol": "http",
235
+ "protocol_handlers": {
236
+ "http": {
237
+ "enabled": True,
238
+ "port": None,
239
+ "ssl": False
240
+ },
241
+ "https": {
242
+ "enabled": False,
243
+ "port": None,
244
+ "ssl": True
245
+ },
246
+ "mtls": {
247
+ "enabled": False,
248
+ "port": None,
249
+ "ssl": True,
250
+ "client_cert_required": True
251
+ }
252
+ }
253
+ },
254
+ "roles": {
255
+ "enabled": False,
256
+ "config_file": None,
257
+ "default_policy": {
258
+ "deny_by_default": False,
259
+ "require_role_match": False,
260
+ "case_sensitive": False,
261
+ "allow_wildcard": False
262
+ },
263
+ "auto_load": False,
264
+ "validation_enabled": False
265
+ }
266
+ }
267
+
268
+ def set_server(self, host: str = "0.0.0.0", port: int = 8000, debug: bool = False, log_level: str = "INFO"):
269
+ """Set server configuration."""
270
+ self.config["server"] = {
271
+ "host": host,
272
+ "port": port,
273
+ "debug": debug,
274
+ "log_level": log_level
275
+ }
276
+ return self
277
+
278
+ def set_logging(self, log_dir: str = "./logs", level: str = "INFO", console_output: bool = True, file_output: bool = True):
279
+ """Set logging configuration."""
280
+ self.config["logging"].update({
281
+ "level": level,
282
+ "log_dir": log_dir,
283
+ "console_output": console_output,
284
+ "file_output": file_output
285
+ })
286
+ return self
287
+
288
+ def set_protocol(self, protocol: Protocol, cert_dir: str = "./certs", key_dir: str = "./keys"):
289
+ """Set protocol configuration (HTTP, HTTPS, or mTLS)."""
290
+ if protocol == Protocol.HTTP:
291
+ self.config["ssl"]["enabled"] = False
292
+ self.config["security"]["ssl"]["enabled"] = False
293
+ self.config["protocols"]["allowed_protocols"] = ["http"]
294
+ self.config["protocols"]["default_protocol"] = "http"
295
+ self.config["protocols"]["protocol_handlers"]["http"]["enabled"] = True
296
+ self.config["protocols"]["protocol_handlers"]["https"]["enabled"] = False
297
+ self.config["protocols"]["protocol_handlers"]["mtls"]["enabled"] = False
298
+
299
+ elif protocol == Protocol.HTTPS:
300
+ self.config["ssl"]["enabled"] = True
301
+ self.config["ssl"]["cert_file"] = f"{cert_dir}/server_cert.pem"
302
+ self.config["ssl"]["key_file"] = f"{key_dir}/server_key.pem"
303
+ self.config["ssl"]["ca_cert"] = f"{cert_dir}/ca_cert.pem"
304
+
305
+ self.config["security"]["ssl"]["enabled"] = True
306
+ self.config["security"]["ssl"]["cert_file"] = f"{cert_dir}/server_cert.pem"
307
+ self.config["security"]["ssl"]["key_file"] = f"{key_dir}/server_key.pem"
308
+ self.config["security"]["ssl"]["ca_cert_file"] = f"{cert_dir}/ca_cert.pem"
309
+
310
+ self.config["protocols"]["allowed_protocols"] = ["https"]
311
+ self.config["protocols"]["default_protocol"] = "https"
312
+ self.config["protocols"]["protocol_handlers"]["http"]["enabled"] = False
313
+ self.config["protocols"]["protocol_handlers"]["https"]["enabled"] = True
314
+ self.config["protocols"]["protocol_handlers"]["mtls"]["enabled"] = False
315
+
316
+ elif protocol == Protocol.MTLS:
317
+ self.config["ssl"]["enabled"] = True
318
+ self.config["ssl"]["cert_file"] = f"{cert_dir}/server_cert.pem"
319
+ self.config["ssl"]["key_file"] = f"{key_dir}/server_key.pem"
320
+ self.config["ssl"]["ca_cert"] = f"{cert_dir}/ca_cert.pem"
321
+ self.config["ssl"]["verify_client"] = True
322
+ self.config["ssl"]["client_cert_required"] = True
323
+
324
+ self.config["security"]["ssl"]["enabled"] = True
325
+ self.config["security"]["ssl"]["cert_file"] = f"{cert_dir}/server_cert.pem"
326
+ self.config["security"]["ssl"]["key_file"] = f"{key_dir}/server_key.pem"
327
+ self.config["security"]["ssl"]["ca_cert_file"] = f"{cert_dir}/ca_cert.pem"
328
+ self.config["security"]["ssl"]["client_cert_file"] = f"{cert_dir}/admin_cert.pem"
329
+ self.config["security"]["ssl"]["client_key_file"] = f"{key_dir}/admin_key.pem"
330
+ self.config["security"]["ssl"]["verify_mode"] = "CERT_REQUIRED"
331
+
332
+ self.config["protocols"]["allowed_protocols"] = ["mtls"]
333
+ self.config["protocols"]["default_protocol"] = "mtls"
334
+ self.config["protocols"]["protocol_handlers"]["http"]["enabled"] = False
335
+ self.config["protocols"]["protocol_handlers"]["https"]["enabled"] = False
336
+ self.config["protocols"]["protocol_handlers"]["mtls"]["enabled"] = True
337
+ self.config["protocols"]["protocol_handlers"]["mtls"]["client_cert_required"] = True
338
+
339
+ return self
340
+
341
+ def set_auth(self, auth_method: AuthMethod, api_keys: Optional[Dict[str, str]] = None, roles: Optional[Dict[str, List[str]]] = None):
342
+ """Set authentication configuration."""
343
+ if auth_method == AuthMethod.NONE:
344
+ self.config["security"]["enabled"] = False
345
+ self.config["security"]["auth"]["enabled"] = False
346
+
347
+ elif auth_method == AuthMethod.TOKEN:
348
+ self.config["security"]["enabled"] = True
349
+ self.config["security"]["auth"]["enabled"] = True
350
+ self.config["security"]["auth"]["methods"] = ["api_key"]
351
+ self.config["security"]["auth"]["api_keys"] = api_keys or {
352
+ "admin": "admin-secret-key",
353
+ "user": "user-secret-key"
354
+ }
355
+
356
+ elif auth_method == AuthMethod.BASIC:
357
+ self.config["security"]["enabled"] = True
358
+ self.config["security"]["auth"]["enabled"] = True
359
+ self.config["security"]["auth"]["methods"] = ["basic_auth"]
360
+ self.config["security"]["auth"]["basic_auth"] = True
361
+
362
+ # Set roles if provided
363
+ if roles:
364
+ self.config["security"]["auth"]["user_roles"] = roles
365
+ self.config["roles"]["enabled"] = True
366
+ self.config["security"]["permissions"]["enabled"] = True
367
+
368
+ return self
369
+
370
+ def set_proxy_registration(self, enabled: bool = True, proxy_url: str = "https://127.0.0.1:20005",
371
+ server_id: str = "mcp_proxy_adapter", cert_dir: str = "./certs"):
372
+ """Set proxy registration configuration."""
373
+ self.config["proxy_registration"]["enabled"] = enabled
374
+ if enabled:
375
+ self.config["proxy_registration"]["server_url"] = f"{proxy_url}/register"
376
+ self.config["proxy_registration"]["proxy_url"] = proxy_url
377
+ self.config["proxy_registration"]["fallback_proxy_url"] = proxy_url.replace("https://", "http://")
378
+ self.config["proxy_registration"]["ssl"]["ca_cert"] = f"{cert_dir}/ca_cert.pem"
379
+ self.config["proxy_registration"]["server_id"] = server_id
380
+ self.config["proxy_registration"]["server_name"] = f"{server_id.title()} Server"
381
+ self.config["proxy_registration"]["description"] = f"Test server for {server_id}"
382
+
383
+ return self
384
+
385
+ def set_debug(self, enabled: bool = False, log_level: str = "DEBUG"):
386
+ """Set debug configuration."""
387
+ self.config["debug"]["enabled"] = enabled
388
+ self.config["debug"]["log_level"] = log_level
389
+ if enabled:
390
+ self.config["logging"]["level"] = log_level
391
+
392
+ return self
393
+
394
+ def set_commands(self, enabled_commands: Optional[List[str]] = None, disabled_commands: Optional[List[str]] = None):
395
+ """Set commands configuration."""
396
+ if enabled_commands:
397
+ self.config["commands"]["enabled_commands"] = enabled_commands
398
+ if disabled_commands:
399
+ self.config["commands"]["disabled_commands"] = disabled_commands
400
+
401
+ return self
402
+
403
+ def build(self) -> Dict[str, Any]:
404
+ """Build and return the final configuration."""
405
+ return self.config.copy()
406
+
407
+ def save(self, file_path: Union[str, Path]) -> Path:
408
+ """Save configuration to file."""
409
+ file_path = Path(file_path)
410
+ file_path.parent.mkdir(parents=True, exist_ok=True)
411
+
412
+ with open(file_path, 'w', encoding='utf-8') as f:
413
+ json.dump(self.config, f, indent=2, ensure_ascii=False)
414
+
415
+ return file_path
416
+
417
+ def reset(self):
418
+ """Reset configuration to defaults."""
419
+ self._reset_to_defaults()
420
+ return self
421
+
422
+
423
+ class ConfigFactory:
424
+ """Factory for creating common configuration combinations."""
425
+
426
+ @staticmethod
427
+ def create_http_simple(host: str = "0.0.0.0", port: int = 20020, log_dir: str = "./logs") -> Dict[str, Any]:
428
+ """Create simple HTTP configuration."""
429
+ return (ConfigBuilder()
430
+ .set_server(host=host, port=port)
431
+ .set_logging(log_dir=log_dir)
432
+ .set_protocol(Protocol.HTTP)
433
+ .set_auth(AuthMethod.NONE)
434
+ .set_proxy_registration(enabled=False)
435
+ .build())
436
+
437
+ @staticmethod
438
+ def create_http_token(host: str = "0.0.0.0", port: int = 20021, log_dir: str = "./logs",
439
+ api_keys: Optional[Dict[str, str]] = None) -> Dict[str, Any]:
440
+ """Create HTTP configuration with token authentication."""
441
+ return (ConfigBuilder()
442
+ .set_server(host=host, port=port)
443
+ .set_logging(log_dir=log_dir)
444
+ .set_protocol(Protocol.HTTP)
445
+ .set_auth(AuthMethod.TOKEN, api_keys=api_keys)
446
+ .set_proxy_registration(enabled=False)
447
+ .build())
448
+
449
+ @staticmethod
450
+ def create_https_simple(host: str = "0.0.0.0", port: int = 20022, log_dir: str = "./logs",
451
+ cert_dir: str = "./certs", key_dir: str = "./keys") -> Dict[str, Any]:
452
+ """Create simple HTTPS configuration."""
453
+ return (ConfigBuilder()
454
+ .set_server(host=host, port=port)
455
+ .set_logging(log_dir=log_dir)
456
+ .set_protocol(Protocol.HTTPS, cert_dir=cert_dir, key_dir=key_dir)
457
+ .set_auth(AuthMethod.NONE)
458
+ .set_proxy_registration(enabled=False)
459
+ .build())
460
+
461
+ @staticmethod
462
+ def create_https_token(host: str = "0.0.0.0", port: int = 20023, log_dir: str = "./logs",
463
+ cert_dir: str = "./certs", key_dir: str = "./keys",
464
+ api_keys: Optional[Dict[str, str]] = None) -> Dict[str, Any]:
465
+ """Create HTTPS configuration with token authentication."""
466
+ return (ConfigBuilder()
467
+ .set_server(host=host, port=port)
468
+ .set_logging(log_dir=log_dir)
469
+ .set_protocol(Protocol.HTTPS, cert_dir=cert_dir, key_dir=key_dir)
470
+ .set_auth(AuthMethod.TOKEN, api_keys=api_keys)
471
+ .set_proxy_registration(enabled=False)
472
+ .build())
473
+
474
+ @staticmethod
475
+ def create_mtls_simple(host: str = "0.0.0.0", port: int = 20024, log_dir: str = "./logs",
476
+ cert_dir: str = "./certs", key_dir: str = "./keys") -> Dict[str, Any]:
477
+ """Create simple mTLS configuration."""
478
+ return (ConfigBuilder()
479
+ .set_server(host=host, port=port)
480
+ .set_logging(log_dir=log_dir)
481
+ .set_protocol(Protocol.MTLS, cert_dir=cert_dir, key_dir=key_dir)
482
+ .set_auth(AuthMethod.NONE)
483
+ .set_proxy_registration(enabled=False)
484
+ .build())
485
+
486
+ @staticmethod
487
+ def create_mtls_with_roles(host: str = "0.0.0.0", port: int = 20025, log_dir: str = "./logs",
488
+ cert_dir: str = "./certs", key_dir: str = "./keys",
489
+ roles: Optional[Dict[str, List[str]]] = None) -> Dict[str, Any]:
490
+ """Create mTLS configuration with roles."""
491
+ default_roles = {
492
+ "admin": ["read", "write", "delete", "admin"],
493
+ "user": ["read", "write"],
494
+ "guest": ["read"]
495
+ }
496
+ return (ConfigBuilder()
497
+ .set_server(host=host, port=port)
498
+ .set_logging(log_dir=log_dir)
499
+ .set_protocol(Protocol.MTLS, cert_dir=cert_dir, key_dir=key_dir)
500
+ .set_auth(AuthMethod.NONE, roles=roles or default_roles)
501
+ .set_proxy_registration(enabled=False)
502
+ .build())
503
+
504
+ @staticmethod
505
+ def create_mtls_with_proxy(host: str = "0.0.0.0", port: int = 20026, log_dir: str = "./logs",
506
+ cert_dir: str = "./certs", key_dir: str = "./keys",
507
+ proxy_url: str = "https://127.0.0.1:20005",
508
+ server_id: str = "mcp_test_server") -> Dict[str, Any]:
509
+ """Create mTLS configuration with proxy registration."""
510
+ return (ConfigBuilder()
511
+ .set_server(host=host, port=port)
512
+ .set_logging(log_dir=log_dir)
513
+ .set_protocol(Protocol.MTLS, cert_dir=cert_dir, key_dir=key_dir)
514
+ .set_auth(AuthMethod.NONE)
515
+ .set_proxy_registration(enabled=True, proxy_url=proxy_url, server_id=server_id, cert_dir=cert_dir)
516
+ .build())
517
+
518
+ @staticmethod
519
+ def create_full_featured(host: str = "0.0.0.0", port: int = 20027, log_dir: str = "./logs",
520
+ cert_dir: str = "./certs", key_dir: str = "./keys",
521
+ proxy_url: str = "https://127.0.0.1:20005",
522
+ server_id: str = "mcp_full_server") -> Dict[str, Any]:
523
+ """Create full-featured configuration with all options enabled."""
524
+ roles = {
525
+ "admin": ["read", "write", "delete", "admin"],
526
+ "user": ["read", "write"],
527
+ "guest": ["read"]
528
+ }
529
+ api_keys = {
530
+ "admin": "admin-secret-key",
531
+ "user": "user-secret-key"
532
+ }
533
+ return (ConfigBuilder()
534
+ .set_server(host=host, port=port)
535
+ .set_logging(log_dir=log_dir)
536
+ .set_protocol(Protocol.MTLS, cert_dir=cert_dir, key_dir=key_dir)
537
+ .set_auth(AuthMethod.TOKEN, api_keys=api_keys, roles=roles)
538
+ .set_proxy_registration(enabled=True, proxy_url=proxy_url, server_id=server_id, cert_dir=cert_dir)
539
+ .set_debug(enabled=True)
540
+ .build())
541
+
542
+
543
+ def main():
544
+ """Example usage of the configuration builder."""
545
+ print("🔧 MCP Proxy Adapter Configuration Builder")
546
+ print("=" * 50)
547
+
548
+ # Create output directory
549
+ output_dir = Path("configs")
550
+ output_dir.mkdir(exist_ok=True)
551
+
552
+ # Generate all standard configurations
553
+ configs = [
554
+ ("http_simple", ConfigFactory.create_http_simple()),
555
+ ("http_token", ConfigFactory.create_http_token()),
556
+ ("https_simple", ConfigFactory.create_https_simple()),
557
+ ("https_token", ConfigFactory.create_https_token()),
558
+ ("mtls_simple", ConfigFactory.create_mtls_simple()),
559
+ ("mtls_with_roles", ConfigFactory.create_mtls_with_roles()),
560
+ ("mtls_with_proxy", ConfigFactory.create_mtls_with_proxy()),
561
+ ("full_featured", ConfigFactory.create_full_featured()),
562
+ ]
563
+
564
+ for name, config in configs:
565
+ config_path = output_dir / f"{name}.json"
566
+ with open(config_path, 'w', encoding='utf-8') as f:
567
+ json.dump(config, f, indent=2, ensure_ascii=False)
568
+ print(f"✅ Created {name}.json")
569
+
570
+ print(f"\n🎉 Generated {len(configs)} configurations in {output_dir}/")
571
+
572
+
573
+ if __name__ == "__main__":
574
+ main()