mcp-proxy-adapter 6.1.1__py3-none-any.whl → 6.2.1__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 (146) hide show
  1. mcp_proxy_adapter/__main__.py +27 -7
  2. mcp_proxy_adapter/api/app.py +18 -7
  3. mcp_proxy_adapter/commands/ssl_setup_command.py +234 -351
  4. mcp_proxy_adapter/core/app_factory.py +87 -3
  5. mcp_proxy_adapter/core/app_runner.py +272 -0
  6. mcp_proxy_adapter/core/certificate_utils.py +291 -73
  7. mcp_proxy_adapter/core/client.py +574 -0
  8. mcp_proxy_adapter/core/client_manager.py +284 -0
  9. mcp_proxy_adapter/core/server_adapter.py +17 -80
  10. mcp_proxy_adapter/core/server_engine.py +5 -99
  11. mcp_proxy_adapter/core/ssl_utils.py +13 -12
  12. mcp_proxy_adapter/core/transport_manager.py +5 -5
  13. mcp_proxy_adapter/examples/__init__.py +16 -0
  14. mcp_proxy_adapter/examples/basic_framework/__init__.py +7 -0
  15. mcp_proxy_adapter/examples/basic_framework/commands/__init__.py +4 -0
  16. mcp_proxy_adapter/examples/basic_framework/hooks/__init__.py +4 -0
  17. mcp_proxy_adapter/examples/basic_framework/main.py +21 -40
  18. mcp_proxy_adapter/examples/commands/__init__.py +5 -1
  19. mcp_proxy_adapter/examples/create_certificates_simple.py +260 -75
  20. mcp_proxy_adapter/examples/debug_request_state.py +4 -36
  21. mcp_proxy_adapter/examples/debug_role_chain.py +2 -49
  22. mcp_proxy_adapter/examples/demo_client.py +0 -66
  23. mcp_proxy_adapter/examples/full_application/__init__.py +11 -0
  24. mcp_proxy_adapter/examples/full_application/commands/__init__.py +7 -0
  25. mcp_proxy_adapter/examples/full_application/commands/custom_echo_command.py +0 -19
  26. mcp_proxy_adapter/examples/full_application/commands/dynamic_calculator_command.py +0 -16
  27. mcp_proxy_adapter/examples/full_application/hooks/__init__.py +7 -0
  28. mcp_proxy_adapter/examples/full_application/hooks/application_hooks.py +0 -22
  29. mcp_proxy_adapter/examples/full_application/hooks/builtin_command_hooks.py +0 -24
  30. mcp_proxy_adapter/examples/full_application/main.py +65 -44
  31. mcp_proxy_adapter/examples/full_application/proxy_endpoints.py +154 -0
  32. mcp_proxy_adapter/examples/generate_all_certificates.py +0 -67
  33. mcp_proxy_adapter/examples/generate_certificates.py +0 -15
  34. mcp_proxy_adapter/examples/generate_certificates_and_tokens.py +369 -0
  35. mcp_proxy_adapter/examples/generate_test_configs.py +204 -0
  36. mcp_proxy_adapter/examples/proxy_registration_example.py +3 -70
  37. mcp_proxy_adapter/examples/run_example.py +1 -23
  38. mcp_proxy_adapter/examples/run_security_tests.py +2 -60
  39. mcp_proxy_adapter/examples/run_security_tests_fixed.py +0 -53
  40. mcp_proxy_adapter/examples/security_test_client.py +18 -123
  41. mcp_proxy_adapter/examples/setup_test_environment.py +179 -0
  42. mcp_proxy_adapter/examples/test_config.py +148 -0
  43. mcp_proxy_adapter/examples/test_config_generator.py +1 -25
  44. mcp_proxy_adapter/examples/test_examples.py +4 -67
  45. mcp_proxy_adapter/examples/universal_client.py +154 -162
  46. mcp_proxy_adapter/main.py +51 -161
  47. mcp_proxy_adapter/version.py +1 -1
  48. mcp_proxy_adapter-6.2.1.dist-info/METADATA +676 -0
  49. mcp_proxy_adapter-6.2.1.dist-info/RECORD +119 -0
  50. mcp_proxy_adapter/docs/EN/TROUBLESHOOTING.md +0 -285
  51. mcp_proxy_adapter/docs/RU/TROUBLESHOOTING.md +0 -285
  52. mcp_proxy_adapter/examples/README.md +0 -257
  53. mcp_proxy_adapter/examples/README_EN.md +0 -258
  54. mcp_proxy_adapter/examples/SECURITY_TESTING.md +0 -455
  55. mcp_proxy_adapter/examples/basic_framework/configs/http_auth.json +0 -37
  56. mcp_proxy_adapter/examples/basic_framework/configs/http_simple.json +0 -23
  57. mcp_proxy_adapter/examples/basic_framework/configs/https_auth.json +0 -43
  58. mcp_proxy_adapter/examples/basic_framework/configs/https_no_protocol_middleware.json +0 -36
  59. mcp_proxy_adapter/examples/basic_framework/configs/https_simple.json +0 -29
  60. mcp_proxy_adapter/examples/basic_framework/configs/mtls_no_protocol_middleware.json +0 -34
  61. mcp_proxy_adapter/examples/basic_framework/configs/mtls_no_roles.json +0 -39
  62. mcp_proxy_adapter/examples/basic_framework/configs/mtls_simple.json +0 -35
  63. mcp_proxy_adapter/examples/basic_framework/configs/mtls_with_roles.json +0 -45
  64. mcp_proxy_adapter/examples/basic_framework/roles.json +0 -21
  65. mcp_proxy_adapter/examples/cert_config.json +0 -9
  66. mcp_proxy_adapter/examples/certs/admin.crt +0 -32
  67. mcp_proxy_adapter/examples/certs/admin.key +0 -52
  68. mcp_proxy_adapter/examples/certs/admin_cert.pem +0 -21
  69. mcp_proxy_adapter/examples/certs/admin_key.pem +0 -28
  70. mcp_proxy_adapter/examples/certs/ca_cert.pem +0 -23
  71. mcp_proxy_adapter/examples/certs/ca_cert.srl +0 -1
  72. mcp_proxy_adapter/examples/certs/ca_key.pem +0 -28
  73. mcp_proxy_adapter/examples/certs/cert_config.json +0 -9
  74. mcp_proxy_adapter/examples/certs/client.crt +0 -32
  75. mcp_proxy_adapter/examples/certs/client.key +0 -52
  76. mcp_proxy_adapter/examples/certs/client_admin.crt +0 -32
  77. mcp_proxy_adapter/examples/certs/client_admin.key +0 -52
  78. mcp_proxy_adapter/examples/certs/client_user.crt +0 -32
  79. mcp_proxy_adapter/examples/certs/client_user.key +0 -52
  80. mcp_proxy_adapter/examples/certs/guest_cert.pem +0 -21
  81. mcp_proxy_adapter/examples/certs/guest_key.pem +0 -28
  82. mcp_proxy_adapter/examples/certs/mcp_proxy_adapter_ca_ca.crt +0 -23
  83. mcp_proxy_adapter/examples/certs/proxy_cert.pem +0 -21
  84. mcp_proxy_adapter/examples/certs/proxy_key.pem +0 -28
  85. mcp_proxy_adapter/examples/certs/readonly.crt +0 -32
  86. mcp_proxy_adapter/examples/certs/readonly.key +0 -52
  87. mcp_proxy_adapter/examples/certs/readonly_cert.pem +0 -21
  88. mcp_proxy_adapter/examples/certs/readonly_key.pem +0 -28
  89. mcp_proxy_adapter/examples/certs/server.crt +0 -32
  90. mcp_proxy_adapter/examples/certs/server.key +0 -52
  91. mcp_proxy_adapter/examples/certs/server_cert.pem +0 -32
  92. mcp_proxy_adapter/examples/certs/server_key.pem +0 -52
  93. mcp_proxy_adapter/examples/certs/test_ca_ca.crt +0 -20
  94. mcp_proxy_adapter/examples/certs/user.crt +0 -32
  95. mcp_proxy_adapter/examples/certs/user.key +0 -52
  96. mcp_proxy_adapter/examples/certs/user_cert.pem +0 -21
  97. mcp_proxy_adapter/examples/certs/user_key.pem +0 -28
  98. mcp_proxy_adapter/examples/client_configs/api_key_client.json +0 -13
  99. mcp_proxy_adapter/examples/client_configs/basic_auth_client.json +0 -13
  100. mcp_proxy_adapter/examples/client_configs/certificate_client.json +0 -22
  101. mcp_proxy_adapter/examples/client_configs/jwt_client.json +0 -15
  102. mcp_proxy_adapter/examples/client_configs/no_auth_client.json +0 -9
  103. mcp_proxy_adapter/examples/full_application/configs/http_auth.json +0 -37
  104. mcp_proxy_adapter/examples/full_application/configs/http_simple.json +0 -23
  105. mcp_proxy_adapter/examples/full_application/configs/https_auth.json +0 -39
  106. mcp_proxy_adapter/examples/full_application/configs/https_simple.json +0 -25
  107. mcp_proxy_adapter/examples/full_application/configs/mtls_no_roles.json +0 -39
  108. mcp_proxy_adapter/examples/full_application/configs/mtls_with_roles.json +0 -45
  109. mcp_proxy_adapter/examples/full_application/roles.json +0 -21
  110. mcp_proxy_adapter/examples/keys/ca_key.pem +0 -28
  111. mcp_proxy_adapter/examples/keys/mcp_proxy_adapter_ca_ca.key +0 -28
  112. mcp_proxy_adapter/examples/keys/test_ca_ca.key +0 -28
  113. mcp_proxy_adapter/examples/logs/mcp_proxy_adapter.log +0 -220
  114. mcp_proxy_adapter/examples/logs/mcp_proxy_adapter.log.1 +0 -1
  115. mcp_proxy_adapter/examples/logs/mcp_proxy_adapter.log.2 +0 -1
  116. mcp_proxy_adapter/examples/logs/mcp_proxy_adapter.log.3 +0 -1
  117. mcp_proxy_adapter/examples/logs/mcp_proxy_adapter.log.4 +0 -1
  118. mcp_proxy_adapter/examples/logs/mcp_proxy_adapter.log.5 +0 -1
  119. mcp_proxy_adapter/examples/logs/mcp_proxy_adapter_access.log +0 -220
  120. mcp_proxy_adapter/examples/logs/mcp_proxy_adapter_access.log.1 +0 -1
  121. mcp_proxy_adapter/examples/logs/mcp_proxy_adapter_access.log.2 +0 -1
  122. mcp_proxy_adapter/examples/logs/mcp_proxy_adapter_access.log.3 +0 -1
  123. mcp_proxy_adapter/examples/logs/mcp_proxy_adapter_access.log.4 +0 -1
  124. mcp_proxy_adapter/examples/logs/mcp_proxy_adapter_access.log.5 +0 -1
  125. mcp_proxy_adapter/examples/logs/mcp_proxy_adapter_error.log +0 -2
  126. mcp_proxy_adapter/examples/logs/mcp_proxy_adapter_error.log.1 +0 -1
  127. mcp_proxy_adapter/examples/logs/mcp_proxy_adapter_error.log.2 +0 -1
  128. mcp_proxy_adapter/examples/logs/mcp_proxy_adapter_error.log.3 +0 -1
  129. mcp_proxy_adapter/examples/logs/mcp_proxy_adapter_error.log.4 +0 -1
  130. mcp_proxy_adapter/examples/logs/mcp_proxy_adapter_error.log.5 +0 -1
  131. mcp_proxy_adapter/examples/roles.json +0 -38
  132. mcp_proxy_adapter/examples/server_configs/config_basic_http.json +0 -204
  133. mcp_proxy_adapter/examples/server_configs/config_http_token.json +0 -238
  134. mcp_proxy_adapter/examples/server_configs/config_https.json +0 -215
  135. mcp_proxy_adapter/examples/server_configs/config_https_token.json +0 -231
  136. mcp_proxy_adapter/examples/server_configs/config_mtls.json +0 -215
  137. mcp_proxy_adapter/examples/server_configs/config_proxy_registration.json +0 -250
  138. mcp_proxy_adapter/examples/server_configs/config_simple.json +0 -46
  139. mcp_proxy_adapter/examples/server_configs/roles.json +0 -38
  140. mcp_proxy_adapter/utils/config_generator.py +0 -727
  141. mcp_proxy_adapter-6.1.1.dist-info/METADATA +0 -205
  142. mcp_proxy_adapter-6.1.1.dist-info/RECORD +0 -197
  143. mcp_proxy_adapter-6.1.1.dist-info/entry_points.txt +0 -2
  144. mcp_proxy_adapter-6.1.1.dist-info/licenses/LICENSE +0 -21
  145. {mcp_proxy_adapter-6.1.1.dist-info → mcp_proxy_adapter-6.2.1.dist-info}/WHEEL +0 -0
  146. {mcp_proxy_adapter-6.1.1.dist-info → mcp_proxy_adapter-6.2.1.dist-info}/top_level.txt +0 -0
@@ -1,727 +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
- from pathlib import Path
14
- from typing import Dict, Any, Optional
15
-
16
- # Use standard logging instead of project logger to avoid circular imports
17
- logger = logging.getLogger(__name__)
18
-
19
-
20
- class ConfigGenerator:
21
- """
22
- Configuration generator for unified mcp_proxy_adapter and mcp_security_framework configs.
23
-
24
- Generates comprehensive configuration files with detailed comments and examples
25
- for both the proxy adapter and security framework components.
26
- """
27
-
28
- def __init__(self):
29
- """Initialize configuration generator."""
30
- self.template_config = self._get_template_config()
31
-
32
- def _get_template_config(self) -> Dict[str, Any]:
33
- """Get template configuration with all available options."""
34
- return {
35
- "server": {
36
- "host": "0.0.0.0",
37
- "port": 8000,
38
- "debug": False,
39
- "log_level": "INFO",
40
- "workers": 1,
41
- "reload": False
42
- },
43
- "ssl": {
44
- "enabled": False,
45
- "cert_file": None,
46
- "key_file": None,
47
- "ca_cert": None,
48
- "verify_client": False,
49
- "client_cert_required": False,
50
- "cipher_suites": ["TLS_AES_256_GCM_SHA384", "TLS_CHACHA20_POLY1305_SHA256"],
51
- "min_tls_version": "TLSv1.2",
52
- "max_tls_version": "1.3"
53
- },
54
- "security": {
55
- "framework": "mcp_security_framework",
56
- "enabled": True,
57
- "debug": False,
58
- "environment": "dev",
59
- "version": "1.0.0",
60
-
61
- "ssl": {
62
- "enabled": False,
63
- "cert_file": None,
64
- "key_file": None,
65
- "ca_cert_file": None,
66
- "client_cert_file": None,
67
- "client_key_file": None,
68
- "verify_mode": "CERT_REQUIRED",
69
- "min_tls_version": "TLSv1.2",
70
- "max_tls_version": None,
71
- "cipher_suite": None,
72
- "check_hostname": True,
73
- "check_expiry": True,
74
- "expiry_warning_days": 30
75
- },
76
-
77
- "auth": {
78
- "enabled": False,
79
- "methods": [],
80
- "api_keys": {},
81
- "user_roles": {},
82
- "jwt_secret": None,
83
- "jwt_algorithm": "HS256",
84
- "jwt_expiry_hours": 24,
85
- "certificate_auth": False,
86
- "certificate_roles_oid": "1.3.6.1.4.1.99999.1.1",
87
- "certificate_permissions_oid": "1.3.6.1.4.1.99999.1.2",
88
- "basic_auth": False,
89
- "oauth2_config": None,
90
- "public_paths": ["/health", "/docs", "/openapi.json"],
91
- "security_headers": {
92
- "X-Content-Type-Options": "nosniff",
93
- "X-Frame-Options": "DENY",
94
- "X-XSS-Protection": "1; mode=block",
95
- "Strict-Transport-Security": "max-age=31536000; includeSubDomains"
96
- }
97
- },
98
-
99
- "certificates": {
100
- "enabled": False,
101
- "ca_cert_path": None,
102
- "ca_key_path": None,
103
- "cert_storage_path": "mcp_proxy_adapter/examples/certs",
104
- "key_storage_path": "mcp_proxy_adapter/examples/keys",
105
- "default_validity_days": 365,
106
- "key_size": 2048,
107
- "hash_algorithm": "sha256",
108
- "crl_enabled": False,
109
- "crl_path": None,
110
- "crl_validity_days": 30,
111
- "auto_renewal": False,
112
- "renewal_threshold_days": 30
113
- },
114
-
115
- "permissions": {
116
- "enabled": False,
117
- "roles_file": None,
118
- "default_role": "guest",
119
- "admin_role": "admin",
120
- "role_hierarchy": {},
121
- "permission_cache_enabled": False,
122
- "permission_cache_ttl": 300,
123
- "wildcard_permissions": False,
124
- "strict_mode": False,
125
- "roles": {}
126
- },
127
-
128
- "rate_limit": {
129
- "enabled": False,
130
- "default_requests_per_minute": 60,
131
- "default_requests_per_hour": 1000,
132
- "burst_limit": 2,
133
- "window_size_seconds": 60,
134
- "storage_backend": "memory",
135
- "redis_config": None,
136
- "cleanup_interval": 300,
137
- "exempt_paths": ["/health", "/docs", "/openapi.json"],
138
- "exempt_roles": ["admin"]
139
- },
140
-
141
- "logging": {
142
- "enabled": True,
143
- "level": "INFO",
144
- "format": "%(asctime)s - %(name)s - %(levelname)s - %(message)s",
145
- "date_format": "%Y-%m-%d %H:%M:%S",
146
- "file_path": "./logs/security.log",
147
- "max_file_size": 10,
148
- "backup_count": 5,
149
- "console_output": True,
150
- "json_format": False,
151
- "include_timestamp": True,
152
- "include_level": True,
153
- "include_module": True
154
- }
155
- },
156
-
157
- "registration": {
158
- "enabled": False,
159
- "server_url": "https://proxy-registry.example.com",
160
- "auth_method": "certificate",
161
- "certificate": {
162
- "enabled": False,
163
- "cert_file": "mcp_proxy_adapter/examples/certs/proxy_client.crt",
164
- "key_file": "mcp_proxy_adapter/examples/keys/proxy_client.key",
165
- "ca_cert_file": "mcp_proxy_adapter/examples/certs/ca.crt",
166
- "verify_server": True
167
- },
168
- "token": {
169
- "enabled": False,
170
- "token": "proxy_registration_token_123",
171
- "token_type": "bearer",
172
- "refresh_interval": 3600
173
- },
174
- "api_key": {
175
- "enabled": False,
176
- "key": "proxy_api_key_456",
177
- "key_header": "X-Proxy-API-Key"
178
- },
179
- "proxy_info": {
180
- "name": "mcp_proxy_adapter",
181
- "version": "1.0.0",
182
- "description": "MCP Proxy Adapter with security framework",
183
- "capabilities": ["jsonrpc", "rest", "security", "certificates"],
184
- "endpoints": {
185
- "jsonrpc": "/api/jsonrpc",
186
- "rest": "/cmd",
187
- "health": "/health"
188
- }
189
- },
190
- "heartbeat": {
191
- "enabled": True,
192
- "interval": 300,
193
- "timeout": 30,
194
- "retry_attempts": 3,
195
- "retry_delay": 60
196
- },
197
- "auto_discovery": {
198
- "enabled": False,
199
- "discovery_urls": [],
200
- "discovery_interval": 3600,
201
- "register_on_discovery": True
202
- }
203
- },
204
-
205
- "logging": {
206
- "level": "INFO",
207
- "console_output": True,
208
- "file_output": False,
209
- "file_path": None,
210
- "max_file_size": 10,
211
- "backup_count": 5,
212
- "format": "%(asctime)s - %(name)s - %(levelname)s - %(message)s"
213
- },
214
-
215
- "commands": {
216
- "auto_discovery": True,
217
- "commands_directory": "./commands",
218
- "builtin_commands": ["echo", "health", "config"],
219
- "custom_commands": [],
220
- "command_timeout": 30
221
- },
222
-
223
- "hooks": {
224
- "enabled": True,
225
- "application_hooks": {
226
- "on_startup": [],
227
- "on_shutdown": [],
228
- "before_request": [],
229
- "after_request": [],
230
- "on_error": []
231
- },
232
- "command_hooks": {
233
- "before_echo_command": [],
234
- "after_echo_command": [],
235
- "before_health_command": [],
236
- "after_health_command": [],
237
- "before_config_command": [],
238
- "after_config_command": []
239
- }
240
- },
241
-
242
- "protocols": {
243
- "enabled": True,
244
- "allowed_protocols": ["http", "https"],
245
- "default_protocol": "http",
246
- "strict_mode": False
247
- }
248
- }
249
-
250
- def generate_config_with_comments(self, config_type: str = "full") -> str:
251
- """
252
- Generate configuration with detailed comments.
253
-
254
- Args:
255
- config_type: Type of configuration to generate
256
- - "full": Complete configuration with all options
257
- - "minimal": Minimal working configuration
258
- - "secure": Secure configuration with all security features
259
- - "development": Development configuration with debug enabled
260
- - "basic_http": Basic HTTP configuration
261
- - "http_token": HTTP with token authentication
262
- - "https": HTTPS configuration
263
- - "https_token": HTTPS with token authentication
264
- - "mtls": mTLS configuration
265
-
266
- Returns:
267
- JSON configuration string with comments
268
- """
269
- config = self._get_config_by_type(config_type)
270
-
271
- # Convert to JSON with comments
272
- json_str = json.dumps(config, indent=2, ensure_ascii=False)
273
-
274
- # Add comments
275
- commented_config = self._add_comments(json_str, config_type)
276
-
277
- return commented_config
278
-
279
- def _get_config_by_type(self, config_type: str) -> Dict[str, Any]:
280
- """Get configuration based on type."""
281
- base_config = self.template_config.copy()
282
-
283
- if config_type == "minimal":
284
- return self._get_minimal_config(base_config)
285
- elif config_type == "secure":
286
- return self._get_secure_config(base_config)
287
- elif config_type == "development":
288
- return self._get_development_config(base_config)
289
- elif config_type == "basic_http":
290
- return self._get_basic_http_config(base_config)
291
- elif config_type == "http_token":
292
- return self._get_http_token_config(base_config)
293
- elif config_type == "https":
294
- return self._get_https_config(base_config)
295
- elif config_type == "https_token":
296
- return self._get_https_token_config(base_config)
297
- elif config_type == "https_no_protocol_middleware":
298
- return self._get_https_no_protocol_middleware_config(base_config)
299
- elif config_type == "mtls":
300
- return self._get_mtls_config(base_config)
301
- elif config_type == "mtls_no_protocol_middleware":
302
- return self._get_mtls_no_protocol_middleware_config(base_config)
303
- else: # full
304
- return base_config
305
-
306
- def _get_minimal_config(self, base_config: Dict[str, Any]) -> Dict[str, Any]:
307
- """Get minimal working configuration."""
308
- config = base_config.copy()
309
-
310
- # Disable security for minimal config
311
- config["security"]["enabled"] = False
312
- config["security"]["auth"]["enabled"] = False
313
- config["security"]["permissions"]["enabled"] = False
314
- config["security"]["rate_limit"]["enabled"] = False
315
-
316
- # Disable registration for minimal config
317
- config["registration"]["enabled"] = False
318
-
319
- # Keep only essential settings
320
- config["server"]["port"] = 8000
321
- config["server"]["debug"] = False
322
-
323
- return config
324
-
325
- def _get_basic_http_config(self, base_config: Dict[str, Any]) -> Dict[str, Any]:
326
- """Get basic HTTP configuration."""
327
- config = base_config.copy()
328
-
329
- # Basic HTTP settings
330
- config["server"]["port"] = 8000
331
- config["ssl"]["enabled"] = False
332
- config["security"]["ssl"]["enabled"] = False
333
- config["security"]["auth"]["enabled"] = False
334
- config["security"]["permissions"]["enabled"] = False
335
- config["security"]["permissions"]["roles_file"] = None
336
- config["protocols"]["enabled"] = True
337
- config["protocols"]["allowed_protocols"] = ["http"]
338
- config["protocols"]["default_protocol"] = "http"
339
-
340
- return config
341
-
342
- def _get_http_token_config(self, base_config: Dict[str, Any]) -> Dict[str, Any]:
343
- """Get HTTP with token authentication configuration."""
344
- config = base_config.copy()
345
-
346
- # HTTP with token auth
347
- config["server"]["port"] = 8001
348
- config["ssl"]["enabled"] = False
349
- config["security"]["ssl"]["enabled"] = False
350
- config["security"]["auth"]["enabled"] = True
351
- config["security"]["auth"]["methods"] = ["api_key"]
352
- config["security"]["auth"]["api_keys"] = {
353
- "test-token-123": {
354
- "roles": ["admin"],
355
- "permissions": ["*"],
356
- "expires": None
357
- },
358
- "user-token-456": {
359
- "roles": ["user"],
360
- "permissions": ["read", "execute"],
361
- "expires": None
362
- }
363
- }
364
- config["security"]["permissions"]["enabled"] = True
365
- config["security"]["permissions"]["roles_file"] = "mcp_proxy_adapter/examples/server_configs/roles.json"
366
- config["protocols"]["enabled"] = True
367
- config["protocols"]["allowed_protocols"] = ["http"]
368
- config["protocols"]["default_protocol"] = "http"
369
-
370
- return config
371
-
372
- def _get_https_config(self, base_config: Dict[str, Any]) -> Dict[str, Any]:
373
- """Get HTTPS configuration."""
374
- config = base_config.copy()
375
-
376
- # HTTPS settings
377
- config["server"]["port"] = 8443
378
- config["ssl"]["enabled"] = True
379
- config["ssl"]["cert_file"] = "mcp_proxy_adapter/examples/certs/server_cert.pem"
380
- config["ssl"]["key_file"] = "mcp_proxy_adapter/examples/certs/server_key.pem"
381
- config["ssl"]["ca_cert"] = "mcp_proxy_adapter/examples/certs/ca_cert.pem"
382
-
383
- config["security"]["ssl"]["enabled"] = True
384
- config["security"]["ssl"]["cert_file"] = "mcp_proxy_adapter/examples/certs/server_cert.pem"
385
- config["security"]["ssl"]["key_file"] = "mcp_proxy_adapter/examples/certs/server_key.pem"
386
- config["security"]["ssl"]["ca_cert_file"] = "mcp_proxy_adapter/examples/certs/ca_cert.pem"
387
-
388
- config["security"]["auth"]["enabled"] = False
389
- config["security"]["permissions"]["enabled"] = False
390
- config["security"]["permissions"]["roles_file"] = None
391
- config["protocols"]["enabled"] = True
392
- config["protocols"]["allowed_protocols"] = ["http", "https"]
393
- config["protocols"]["default_protocol"] = "https"
394
-
395
- return config
396
-
397
- def _get_https_token_config(self, base_config: Dict[str, Any]) -> Dict[str, Any]:
398
- """Get HTTPS with token authentication configuration."""
399
- config = base_config.copy()
400
-
401
- # HTTPS with token auth
402
- config["server"]["port"] = 8444
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"]["cert_file"] = "mcp_proxy_adapter/examples/certs/server_cert.pem"
410
- config["security"]["ssl"]["key_file"] = "mcp_proxy_adapter/examples/certs/server_key.pem"
411
- config["security"]["ssl"]["ca_cert_file"] = "mcp_proxy_adapter/examples/certs/ca_cert.pem"
412
-
413
- config["security"]["auth"]["enabled"] = True
414
- config["security"]["auth"]["methods"] = ["api_key"]
415
- config["security"]["auth"]["api_keys"] = {
416
- "test-token-123": {
417
- "roles": ["admin"],
418
- "permissions": ["*"],
419
- "expires": None
420
- },
421
- "user-token-456": {
422
- "roles": ["user"],
423
- "permissions": ["read", "execute"],
424
- "expires": None
425
- }
426
- }
427
- config["security"]["permissions"]["enabled"] = True
428
- config["security"]["permissions"]["roles_file"] = "mcp_proxy_adapter/examples/server_configs/roles.json"
429
- config["protocols"]["enabled"] = True
430
- config["protocols"]["allowed_protocols"] = ["http", "https"]
431
- config["protocols"]["default_protocol"] = "https"
432
-
433
- return config
434
-
435
- def _get_mtls_config(self, base_config: Dict[str, Any]) -> Dict[str, Any]:
436
- """Get mTLS configuration."""
437
- config = base_config.copy()
438
-
439
- # mTLS settings
440
- config["server"]["port"] = 8445
441
- config["ssl"]["enabled"] = True
442
- config["ssl"]["cert_file"] = "mcp_proxy_adapter/examples/certs/server_cert.pem"
443
- config["ssl"]["key_file"] = "mcp_proxy_adapter/examples/certs/server_key.pem"
444
- config["ssl"]["ca_cert"] = "mcp_proxy_adapter/examples/certs/ca_cert.pem"
445
- config["ssl"]["verify_client"] = True
446
- config["ssl"]["client_cert_required"] = True
447
-
448
- config["security"]["ssl"]["enabled"] = True
449
- config["security"]["ssl"]["cert_file"] = "mcp_proxy_adapter/examples/certs/server_cert.pem"
450
- config["security"]["ssl"]["key_file"] = "mcp_proxy_adapter/examples/certs/server_key.pem"
451
- config["security"]["ssl"]["ca_cert_file"] = "mcp_proxy_adapter/examples/certs/ca_cert.pem"
452
- config["security"]["ssl"]["client_cert_file"] = "mcp_proxy_adapter/examples/certs/client_cert.pem"
453
- config["security"]["ssl"]["client_key_file"] = "mcp_proxy_adapter/examples/certs/client_key.pem"
454
- config["security"]["ssl"]["verify_mode"] = "CERT_REQUIRED"
455
-
456
- config["security"]["auth"]["enabled"] = True
457
- config["security"]["auth"]["methods"] = ["certificate"]
458
- config["security"]["auth"]["certificate_auth"] = True
459
- config["security"]["permissions"]["enabled"] = True
460
- config["security"]["permissions"]["roles_file"] = "mcp_proxy_adapter/examples/server_configs/roles.json"
461
- config["protocols"]["enabled"] = True
462
- config["protocols"]["allowed_protocols"] = ["https", "mtls"]
463
- config["protocols"]["default_protocol"] = "https"
464
-
465
- return config
466
-
467
- def _get_https_no_protocol_middleware_config(self, base_config: Dict[str, Any]) -> Dict[str, Any]:
468
- """Get HTTPS configuration without ProtocolMiddleware."""
469
- config = base_config.copy()
470
-
471
- # HTTPS settings
472
- config["server"]["port"] = 8445
473
- config["ssl"]["enabled"] = True
474
- config["ssl"]["cert_file"] = "mcp_proxy_adapter/examples/certs/server_cert.pem"
475
- config["ssl"]["key_file"] = "mcp_proxy_adapter/examples/certs/server_key.pem"
476
- config["ssl"]["ca_cert"] = "mcp_proxy_adapter/examples/certs/ca_cert.pem"
477
-
478
- config["security"]["ssl"]["enabled"] = True
479
- config["security"]["ssl"]["cert_file"] = "mcp_proxy_adapter/examples/certs/server_cert.pem"
480
- config["security"]["ssl"]["key_file"] = "mcp_proxy_adapter/examples/certs/server_key.pem"
481
- config["security"]["ssl"]["ca_cert_file"] = "mcp_proxy_adapter/examples/certs/ca_cert.pem"
482
-
483
- config["security"]["auth"]["enabled"] = True
484
- config["security"]["auth"]["methods"] = ["api_key"]
485
- config["security"]["auth"]["api_keys"] = {
486
- "test-token-123": {
487
- "roles": ["admin"],
488
- "permissions": ["*"],
489
- "expires": None
490
- },
491
- "user-token-456": {
492
- "roles": ["user"],
493
- "permissions": ["read", "execute"],
494
- "expires": None
495
- }
496
- }
497
- config["security"]["permissions"]["enabled"] = True
498
- config["security"]["permissions"]["roles_file"] = "mcp_proxy_adapter/examples/server_configs/roles.json"
499
- config["protocols"]["enabled"] = False # Disable ProtocolMiddleware
500
-
501
- return config
502
-
503
- def _get_mtls_no_protocol_middleware_config(self, base_config: Dict[str, Any]) -> Dict[str, Any]:
504
- """Get mTLS configuration without ProtocolMiddleware."""
505
- config = base_config.copy()
506
-
507
- # mTLS settings
508
- config["server"]["port"] = 8447
509
- config["ssl"]["enabled"] = True
510
- config["ssl"]["cert_file"] = "mcp_proxy_adapter/examples/certs/server_cert.pem"
511
- config["ssl"]["key_file"] = "mcp_proxy_adapter/examples/certs/server_key.pem"
512
- config["ssl"]["ca_cert"] = "mcp_proxy_adapter/examples/certs/ca_cert.pem"
513
- config["ssl"]["verify_client"] = True
514
- config["ssl"]["client_cert_required"] = True
515
-
516
- config["security"]["ssl"]["enabled"] = True
517
- config["security"]["ssl"]["cert_file"] = "mcp_proxy_adapter/examples/certs/server_cert.pem"
518
- config["security"]["ssl"]["key_file"] = "mcp_proxy_adapter/examples/certs/server_key.pem"
519
- config["security"]["ssl"]["ca_cert_file"] = "mcp_proxy_adapter/examples/certs/ca_cert.pem"
520
- config["security"]["ssl"]["client_cert_file"] = "mcp_proxy_adapter/examples/certs/client_cert.pem"
521
- config["security"]["ssl"]["client_key_file"] = "mcp_proxy_adapter/examples/certs/client_key.pem"
522
- config["security"]["ssl"]["verify_mode"] = "CERT_REQUIRED"
523
-
524
- config["security"]["auth"]["enabled"] = True
525
- config["security"]["auth"]["methods"] = ["certificate"]
526
- config["security"]["auth"]["certificate_auth"] = True
527
- config["security"]["permissions"]["enabled"] = True
528
- config["security"]["permissions"]["roles_file"] = "mcp_proxy_adapter/examples/server_configs/roles.json"
529
- config["protocols"]["enabled"] = False # Disable ProtocolMiddleware
530
-
531
- return config
532
-
533
- def _get_secure_config(self, base_config: Dict[str, Any]) -> Dict[str, Any]:
534
- """Get secure configuration with all security features enabled."""
535
- config = base_config.copy()
536
-
537
- # Enable all security features
538
- config["security"]["enabled"] = True
539
- config["security"]["ssl"]["enabled"] = True
540
- config["security"]["auth"]["enabled"] = True
541
- config["security"]["permissions"]["enabled"] = True
542
- config["security"]["rate_limit"]["enabled"] = True
543
-
544
- # Enable registration with certificate auth
545
- config["registration"]["enabled"] = True
546
- config["registration"]["auth_method"] = "certificate"
547
- config["registration"]["certificate"]["enabled"] = True
548
-
549
- # Set secure defaults
550
- config["security"]["ssl"]["min_tls_version"] = "TLSv1.2"
551
- config["security"]["auth"]["methods"] = ["api_key", "jwt"]
552
- config["security"]["permissions"]["strict_mode"] = True
553
- config["security"]["rate_limit"]["burst_limit"] = 1
554
-
555
- return config
556
-
557
- def _get_development_config(self, base_config: Dict[str, Any]) -> Dict[str, Any]:
558
- """Get development configuration with debug enabled."""
559
- config = base_config.copy()
560
-
561
- # Enable debug features
562
- config["server"]["debug"] = True
563
- config["security"]["debug"] = True
564
- config["logging"]["level"] = "DEBUG"
565
-
566
- # Enable registration with token auth for development
567
- config["registration"]["enabled"] = True
568
- config["registration"]["auth_method"] = "token"
569
- config["registration"]["token"]["enabled"] = True
570
-
571
- # Relax security for development
572
- config["security"]["rate_limit"]["default_requests_per_minute"] = 1000
573
- config["security"]["permissions"]["strict_mode"] = False
574
-
575
- return config
576
-
577
- def _add_comments(self, json_str: str, config_type: str) -> str:
578
- """Add comments to JSON configuration."""
579
- comments = self._get_comments_for_type(config_type)
580
-
581
- # Add header comment
582
- commented_config = f"""/**
583
- * MCP Proxy Adapter Configuration
584
- *
585
- * This configuration file combines settings for both mcp_proxy_adapter
586
- * and mcp_security_framework in a unified format.
587
- *
588
- * Configuration Type: {config_type.title()}
589
- * Generated by: ConfigGenerator
590
- *
591
- * IMPORTANT: This is a template configuration. Please customize it
592
- * according to your specific requirements and security needs.
593
- */
594
-
595
- """
596
-
597
- # Add section comments
598
- for section, comment in comments.items():
599
- if section in json_str:
600
- # Find the section and add comment before it
601
- section_start = json_str.find(f'"{section}":')
602
- if section_start != -1:
603
- # Find the line start
604
- line_start = json_str.rfind('\n', 0, section_start) + 1
605
- json_str = (
606
- json_str[:line_start] +
607
- f" // {comment}\n" +
608
- json_str[line_start:]
609
- )
610
-
611
- return commented_config + json_str
612
-
613
- def _get_comments_for_type(self, config_type: str) -> Dict[str, str]:
614
- """Get comments for configuration sections."""
615
- base_comments = {
616
- "server": "Server configuration for FastAPI application",
617
- "ssl": "SSL/TLS configuration for secure connections",
618
- "security": "Security framework configuration (mcp_security_framework)",
619
- "registration": "Proxy registration configuration for secure proxy discovery",
620
- "logging": "Logging configuration for the application",
621
- "commands": "Command management and discovery settings",
622
- "hooks": "Application and command hooks configuration",
623
- "protocols": "Protocol endpoints and settings"
624
- }
625
-
626
- if config_type == "minimal":
627
- base_comments["security"] = "Security framework configuration (disabled for minimal setup)"
628
- base_comments["registration"] = "Proxy registration configuration (disabled for minimal setup)"
629
- elif config_type == "secure":
630
- base_comments["security"] = "Security framework configuration (all features enabled)"
631
- base_comments["registration"] = "Proxy registration configuration (certificate authentication enabled)"
632
- elif config_type == "development":
633
- base_comments["security"] = "Security framework configuration (development mode with relaxed settings)"
634
- base_comments["registration"] = "Proxy registration configuration (token authentication for development)"
635
- elif config_type in ["basic_http", "http_token"]:
636
- base_comments["ssl"] = "SSL/TLS configuration (disabled for HTTP)"
637
- base_comments["security"] = f"Security framework configuration ({config_type} mode)"
638
- elif config_type in ["https", "https_token"]:
639
- base_comments["ssl"] = "SSL/TLS configuration (enabled for HTTPS)"
640
- base_comments["security"] = f"Security framework configuration ({config_type} mode)"
641
- elif config_type == "mtls":
642
- base_comments["ssl"] = "SSL/TLS configuration (enabled for mTLS with client certificate verification)"
643
- base_comments["security"] = "Security framework configuration (mTLS mode with certificate authentication)"
644
- elif config_type == "https_no_protocol_middleware":
645
- base_comments["ssl"] = "SSL/TLS configuration (enabled for HTTPS without ProtocolMiddleware)"
646
- base_comments["security"] = "Security framework configuration (HTTPS mode without ProtocolMiddleware)"
647
- elif config_type == "mtls_no_protocol_middleware":
648
- base_comments["ssl"] = "SSL/TLS configuration (enabled for mTLS without ProtocolMiddleware)"
649
- base_comments["security"] = "Security framework configuration (mTLS mode without ProtocolMiddleware)"
650
-
651
- return base_comments
652
-
653
- def generate_config_file(self, output_path: str, config_type: str = "full") -> None:
654
- """
655
- Generate configuration file and save to disk.
656
-
657
- Args:
658
- output_path: Path to save the configuration file
659
- config_type: Type of configuration to generate
660
- """
661
- try:
662
- config_content = self.generate_config_with_comments(config_type)
663
-
664
- # Create directory if it doesn't exist
665
- output_file = Path(output_path)
666
- output_file.parent.mkdir(parents=True, exist_ok=True)
667
-
668
- # Write configuration file
669
- with open(output_file, 'w', encoding='utf-8') as f:
670
- f.write(config_content)
671
-
672
- logger.info(f"Configuration file generated: {output_path}")
673
- logger.info(f"Configuration type: {config_type}")
674
-
675
- except Exception as e:
676
- logger.error(f"Failed to generate configuration file: {e}")
677
- raise
678
-
679
- def generate_all_configs(self, output_dir: str) -> None:
680
- """
681
- Generate all configuration types.
682
-
683
- Args:
684
- output_dir: Directory to save configuration files
685
- """
686
- config_types = [
687
- "minimal", "development", "secure", "full",
688
- "basic_http", "http_token", "https", "https_token", "mtls",
689
- "https_no_protocol_middleware", "mtls_no_protocol_middleware"
690
- ]
691
-
692
- for config_type in config_types:
693
- output_path = Path(output_dir) / f"config_{config_type}.json"
694
- self.generate_config_file(str(output_path), config_type)
695
-
696
- logger.info(f"Generated {len(config_types)} configuration files in {output_dir}")
697
-
698
-
699
- def main():
700
- """Main function for command-line usage."""
701
- import argparse
702
-
703
- parser = argparse.ArgumentParser(description="Generate MCP Proxy Adapter configuration files")
704
- parser.add_argument("--type",
705
- choices=["minimal", "development", "secure", "full",
706
- "basic_http", "http_token", "https", "https_token", "mtls",
707
- "https_no_protocol_middleware", "mtls_no_protocol_middleware"],
708
- default="full", help="Configuration type to generate")
709
- parser.add_argument("--output", default="./config.json",
710
- help="Output file path")
711
- parser.add_argument("--all", action="store_true",
712
- help="Generate all configuration types")
713
- parser.add_argument("--output-dir", default="./configs",
714
- help="Output directory for all configs")
715
-
716
- args = parser.parse_args()
717
-
718
- generator = ConfigGenerator()
719
-
720
- if args.all:
721
- generator.generate_all_configs(args.output_dir)
722
- else:
723
- generator.generate_config_file(args.output, args.type)
724
-
725
-
726
- if __name__ == "__main__":
727
- main()