mcp-proxy-adapter 6.4.47__py3-none-any.whl → 6.6.0__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,16 +1,15 @@
1
1
  #!/usr/bin/env python3
2
2
  """
3
- Advanced Configuration Builder for MCP Proxy Adapter
4
- Creates configurations from scratch based on protocol, authentication, and other parameters.
3
+ Simplified Configuration Builder for MCP Proxy Adapter
5
4
 
6
5
  Author: Vasiliy Zdanovskiy
7
6
  email: vasilyvz@gmail.com
8
7
  """
8
+
9
9
  import json
10
10
  import uuid
11
- from pathlib import Path
12
- from typing import Dict, Any, List, Optional, Union
13
11
  from enum import Enum
12
+ from typing import Dict, List, Optional, Any
14
13
 
15
14
 
16
15
  class Protocol(Enum):
@@ -21,18 +20,17 @@ class Protocol(Enum):
21
20
 
22
21
 
23
22
  class AuthMethod(Enum):
24
- """Supported authentication methods."""
23
+ """Authentication methods."""
25
24
  NONE = "none"
26
25
  TOKEN = "token"
27
- BASIC = "basic"
26
+ TOKEN_ROLES = "token_roles"
28
27
 
29
28
 
30
29
  class ConfigBuilder:
31
- """Advanced configuration builder for MCP Proxy Adapter."""
30
+ """Simplified configuration builder."""
32
31
 
33
32
  def __init__(self):
34
33
  """Initialize the configuration builder."""
35
- self.config = {}
36
34
  self._reset_to_defaults()
37
35
 
38
36
  def _reset_to_defaults(self):
@@ -42,6 +40,7 @@ class ConfigBuilder:
42
40
  "server": {
43
41
  "host": "0.0.0.0",
44
42
  "port": 8000,
43
+ "protocol": "http",
45
44
  "debug": False,
46
45
  "log_level": "INFO"
47
46
  },
@@ -50,85 +49,24 @@ class ConfigBuilder:
50
49
  "file": None,
51
50
  "log_dir": "./logs",
52
51
  "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",
52
+ "max_size": 10,
56
53
  "backup_count": 5,
57
- "format": "%(asctime)s - %(name)s - %(levelname)s - %(message)s",
58
- "date_format": "%Y-%m-%d %H:%M:%S",
59
54
  "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"
55
+ "json_format": False
76
56
  },
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": {
57
+ "security": {
105
58
  "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"
59
+ "tokens": {
60
+ "admin": "admin-secret-key",
61
+ "user": "user-secret-key",
62
+ "readonly": "readonly-secret-key"
113
63
  },
114
- "heartbeat": {
115
- "enabled": True,
116
- "interval": 30,
117
- "timeout": 10
64
+ "roles": {
65
+ "admin": ["read", "write", "delete", "admin"],
66
+ "user": ["read", "write"],
67
+ "readonly": ["read"]
118
68
  },
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
- }
69
+ "roles_file": None
132
70
  },
133
71
  "debug": {
134
72
  "enabled": False,
@@ -136,205 +74,38 @@ class ConfigBuilder:
136
74
  "trace_requests": False,
137
75
  "trace_responses": False
138
76
  },
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
- },
77
+ "transport": {
78
+ "type": "http",
79
+ "port": None,
161
80
  "ssl": {
162
81
  "enabled": False,
163
82
  "cert_file": None,
164
83
  "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
84
+ "ca_cert": None,
85
+ "verify_client": False,
86
+ "client_cert_required": False,
87
+ "chk_hostname": False,
262
88
  },
263
- "auto_load": False,
264
- "validation_enabled": False
265
89
  }
266
90
  }
267
91
 
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
92
  def set_protocol(self, protocol: Protocol, cert_dir: str = "./certs", key_dir: str = "./keys"):
289
93
  """Set protocol configuration (HTTP, HTTPS, or mTLS)."""
94
+ self.config["server"]["protocol"] = protocol.value
95
+
290
96
  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
97
+ # HTTP - no SSL
98
+ pass
298
99
 
299
100
  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
101
+ # HTTPS - server SSL only
102
+ # SSL configuration will be handled by the server based on protocol
103
+ pass
315
104
 
316
105
  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
106
+ # mTLS - server SSL + client certificates
107
+ # SSL configuration will be handled by the server based on protocol
108
+ pass
338
109
 
339
110
  return self
340
111
 
@@ -342,233 +113,176 @@ class ConfigBuilder:
342
113
  """Set authentication configuration."""
343
114
  if auth_method == AuthMethod.NONE:
344
115
  self.config["security"]["enabled"] = False
345
- self.config["security"]["auth"]["enabled"] = False
116
+ self.config["security"]["tokens"] = {}
117
+ self.config["security"]["roles"] = {}
118
+ self.config["security"]["roles_file"] = None
346
119
 
347
120
  elif auth_method == AuthMethod.TOKEN:
348
121
  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 {
122
+ self.config["security"]["tokens"] = api_keys or {
352
123
  "admin": "admin-secret-key",
353
124
  "user": "user-secret-key"
354
125
  }
126
+ self.config["security"]["roles"] = roles or {
127
+ "admin": ["read", "write", "delete", "admin"],
128
+ "user": ["read", "write"]
129
+ }
130
+ self.config["security"]["roles_file"] = None
355
131
 
356
- elif auth_method == AuthMethod.BASIC:
132
+ elif auth_method == AuthMethod.TOKEN_ROLES:
357
133
  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}"
134
+ self.config["security"]["tokens"] = api_keys or {
135
+ "admin": "admin-secret-key",
136
+ "user": "user-secret-key",
137
+ "readonly": "readonly-secret-key"
138
+ }
139
+ self.config["security"]["roles"] = roles or {
140
+ "admin": ["read", "write", "delete", "admin"],
141
+ "user": ["read", "write"],
142
+ "readonly": ["read"]
143
+ }
144
+ self.config["security"]["roles_file"] = "configs/roles.json"
382
145
 
383
146
  return self
384
147
 
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
-
148
+ def set_server(self, host: str = "0.0.0.0", port: int = 8000):
149
+ """Set server configuration."""
150
+ self.config["server"]["host"] = host
151
+ self.config["server"]["port"] = port
392
152
  return self
393
153
 
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
-
154
+ def set_roles_file(self, roles_file: str):
155
+ """Set roles file path."""
156
+ self.config["security"]["roles_file"] = roles_file
401
157
  return self
402
158
 
403
159
  def build(self) -> Dict[str, Any]:
404
- """Build and return the final configuration."""
160
+ """Build and return the configuration."""
405
161
  return self.config.copy()
406
162
 
407
- def save(self, file_path: Union[str, Path]) -> Path:
163
+ def save(self, file_path: str) -> None:
408
164
  """Save configuration to file."""
409
- file_path = Path(file_path)
410
- file_path.parent.mkdir(parents=True, exist_ok=True)
411
-
412
165
  with open(file_path, 'w', encoding='utf-8') as f:
413
166
  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
167
 
422
168
 
423
169
  class ConfigFactory:
424
- """Factory for creating common configuration combinations."""
170
+ """Factory for creating common configurations."""
171
+
172
+ @staticmethod
173
+ def create_http_config(port: int = 8000) -> Dict[str, Any]:
174
+ """Create HTTP configuration."""
175
+ return (ConfigBuilder()
176
+ .set_protocol(Protocol.HTTP)
177
+ .set_server(port=port)
178
+ .build())
425
179
 
426
180
  @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."""
181
+ def create_http_token_config(port: int = 8001) -> Dict[str, Any]:
182
+ """Create HTTP with token authentication configuration."""
429
183
  return (ConfigBuilder()
430
- .set_server(host=host, port=port)
431
- .set_logging(log_dir=log_dir)
432
184
  .set_protocol(Protocol.HTTP)
433
- .set_auth(AuthMethod.NONE)
434
- .set_proxy_registration(enabled=False)
185
+ .set_auth(AuthMethod.TOKEN)
186
+ .set_server(port=port)
435
187
  .build())
436
188
 
437
189
  @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."""
190
+ def create_http_token_roles_config(port: int = 8002) -> Dict[str, Any]:
191
+ """Create HTTP with token and roles configuration."""
441
192
  return (ConfigBuilder()
442
- .set_server(host=host, port=port)
443
- .set_logging(log_dir=log_dir)
444
193
  .set_protocol(Protocol.HTTP)
445
- .set_auth(AuthMethod.TOKEN, api_keys=api_keys)
446
- .set_proxy_registration(enabled=False)
194
+ .set_auth(AuthMethod.TOKEN_ROLES)
195
+ .set_server(port=port)
447
196
  .build())
448
197
 
449
198
  @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."""
199
+ def create_https_config(port: int = 8003) -> Dict[str, Any]:
200
+ """Create HTTPS configuration."""
453
201
  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)
202
+ .set_protocol(Protocol.HTTPS)
203
+ .set_server(port=port)
459
204
  .build())
460
205
 
461
206
  @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."""
207
+ def create_https_token_config(port: int = 8004) -> Dict[str, Any]:
208
+ """Create HTTPS with token authentication configuration."""
466
209
  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)
210
+ .set_protocol(Protocol.HTTPS)
211
+ .set_auth(AuthMethod.TOKEN)
212
+ .set_server(port=port)
472
213
  .build())
473
214
 
474
215
  @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."""
216
+ def create_https_token_roles_config(port: int = 8005) -> Dict[str, Any]:
217
+ """Create HTTPS with token and roles configuration."""
478
218
  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)
219
+ .set_protocol(Protocol.HTTPS)
220
+ .set_auth(AuthMethod.TOKEN_ROLES)
221
+ .set_server(port=port)
484
222
  .build())
485
223
 
486
224
  @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
- }
225
+ def create_mtls_config(port: int = 8006) -> Dict[str, Any]:
226
+ """Create mTLS configuration."""
496
227
  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)
228
+ .set_protocol(Protocol.MTLS)
229
+ .set_server(port=port)
502
230
  .build())
503
231
 
504
232
  @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."""
233
+ def create_mtls_token_config(port: int = 8007) -> Dict[str, Any]:
234
+ """Create mTLS with token authentication configuration."""
510
235
  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)
236
+ .set_protocol(Protocol.MTLS)
237
+ .set_auth(AuthMethod.TOKEN)
238
+ .set_server(port=port)
516
239
  .build())
517
240
 
518
241
  @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
- }
242
+ def create_mtls_token_roles_config(port: int = 8008) -> Dict[str, Any]:
243
+ """Create mTLS with token and roles configuration."""
533
244
  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)
245
+ .set_protocol(Protocol.MTLS)
246
+ .set_auth(AuthMethod.TOKEN_ROLES)
247
+ .set_server(port=port)
540
248
  .build())
541
249
 
542
250
 
543
- def main():
544
- """Example usage of the configuration builder."""
545
- print("🔧 MCP Proxy Adapter Configuration Builder")
546
- print("=" * 50)
251
+ def create_config_from_flags(protocol: str, token: bool = False, roles: bool = False, port: int = 8000) -> Dict[str, Any]:
252
+ """
253
+ Create configuration from command line flags.
254
+
255
+ Args:
256
+ protocol: Protocol type (http, https, mtls)
257
+ token: Enable token authentication
258
+ roles: Enable role-based access control
259
+ port: Server port
260
+
261
+ Returns:
262
+ Configuration dictionary
263
+ """
264
+ protocol_map = {
265
+ "http": Protocol.HTTP,
266
+ "https": Protocol.HTTPS,
267
+ "mtls": Protocol.MTLS
268
+ }
547
269
 
548
- # Create output directory
549
- output_dir = Path("configs")
550
- output_dir.mkdir(exist_ok=True)
270
+ if protocol not in protocol_map:
271
+ raise ValueError(f"Unsupported protocol: {protocol}")
551
272
 
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
- ]
273
+ builder = ConfigBuilder().set_protocol(protocol_map[protocol]).set_server(port=port)
563
274
 
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")
275
+ if roles:
276
+ builder.set_auth(AuthMethod.TOKEN_ROLES)
277
+ elif token:
278
+ builder.set_auth(AuthMethod.TOKEN)
279
+ else:
280
+ builder.set_auth(AuthMethod.NONE)
569
281
 
570
- print(f"\n🎉 Generated {len(configs)} configurations in {output_dir}/")
282
+ return builder.build()
571
283
 
572
284
 
573
285
  if __name__ == "__main__":
574
- main()
286
+ # Example usage
287
+ config = create_config_from_flags("http", token=True, port=8001)
288
+ print(json.dumps(config, indent=2))