mcp-proxy-adapter 4.1.1__py3-none-any.whl → 6.1.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.
Files changed (253) hide show
  1. mcp_proxy_adapter/__main__.py +12 -0
  2. mcp_proxy_adapter/api/app.py +254 -33
  3. mcp_proxy_adapter/api/handlers.py +32 -6
  4. mcp_proxy_adapter/api/middleware/__init__.py +36 -30
  5. mcp_proxy_adapter/api/middleware/command_permission_middleware.py +148 -0
  6. mcp_proxy_adapter/api/middleware/error_handling.py +9 -0
  7. mcp_proxy_adapter/api/middleware/factory.py +243 -0
  8. mcp_proxy_adapter/api/middleware/logging.py +32 -6
  9. mcp_proxy_adapter/api/middleware/protocol_middleware.py +135 -0
  10. mcp_proxy_adapter/api/middleware/transport_middleware.py +122 -0
  11. mcp_proxy_adapter/api/middleware/unified_security.py +152 -0
  12. mcp_proxy_adapter/api/middleware/user_info_middleware.py +83 -0
  13. mcp_proxy_adapter/commands/__init__.py +19 -4
  14. mcp_proxy_adapter/commands/auth_validation_command.py +408 -0
  15. mcp_proxy_adapter/commands/base.py +66 -32
  16. mcp_proxy_adapter/commands/builtin_commands.py +95 -0
  17. mcp_proxy_adapter/commands/catalog_manager.py +838 -0
  18. mcp_proxy_adapter/commands/cert_monitor_command.py +620 -0
  19. mcp_proxy_adapter/commands/certificate_management_command.py +608 -0
  20. mcp_proxy_adapter/commands/command_registry.py +711 -354
  21. mcp_proxy_adapter/commands/dependency_manager.py +245 -0
  22. mcp_proxy_adapter/commands/echo_command.py +81 -0
  23. mcp_proxy_adapter/commands/health_command.py +7 -0
  24. mcp_proxy_adapter/commands/help_command.py +21 -14
  25. mcp_proxy_adapter/commands/hooks.py +200 -167
  26. mcp_proxy_adapter/commands/key_management_command.py +506 -0
  27. mcp_proxy_adapter/commands/load_command.py +176 -0
  28. mcp_proxy_adapter/commands/plugins_command.py +235 -0
  29. mcp_proxy_adapter/commands/protocol_management_command.py +232 -0
  30. mcp_proxy_adapter/commands/proxy_registration_command.py +409 -0
  31. mcp_proxy_adapter/commands/reload_command.py +48 -50
  32. mcp_proxy_adapter/commands/result.py +1 -0
  33. mcp_proxy_adapter/commands/role_test_command.py +141 -0
  34. mcp_proxy_adapter/commands/roles_management_command.py +697 -0
  35. mcp_proxy_adapter/commands/security_command.py +488 -0
  36. mcp_proxy_adapter/commands/ssl_setup_command.py +483 -0
  37. mcp_proxy_adapter/commands/token_management_command.py +529 -0
  38. mcp_proxy_adapter/commands/transport_management_command.py +144 -0
  39. mcp_proxy_adapter/commands/unload_command.py +158 -0
  40. mcp_proxy_adapter/config.py +159 -2
  41. mcp_proxy_adapter/core/app_factory.py +326 -0
  42. mcp_proxy_adapter/core/auth_validator.py +606 -0
  43. mcp_proxy_adapter/core/certificate_utils.py +827 -0
  44. mcp_proxy_adapter/core/client_security.py +384 -0
  45. mcp_proxy_adapter/core/config_converter.py +405 -0
  46. mcp_proxy_adapter/core/config_validator.py +218 -0
  47. mcp_proxy_adapter/core/logging.py +19 -3
  48. mcp_proxy_adapter/core/mtls_asgi.py +156 -0
  49. mcp_proxy_adapter/core/mtls_asgi_app.py +187 -0
  50. mcp_proxy_adapter/core/protocol_manager.py +235 -0
  51. mcp_proxy_adapter/core/proxy_client.py +602 -0
  52. mcp_proxy_adapter/core/proxy_registration.py +522 -0
  53. mcp_proxy_adapter/core/role_utils.py +426 -0
  54. mcp_proxy_adapter/core/security_adapter.py +370 -0
  55. mcp_proxy_adapter/core/security_factory.py +239 -0
  56. mcp_proxy_adapter/core/security_integration.py +277 -0
  57. mcp_proxy_adapter/core/server_adapter.py +345 -0
  58. mcp_proxy_adapter/core/server_engine.py +364 -0
  59. mcp_proxy_adapter/core/settings.py +1 -0
  60. mcp_proxy_adapter/core/ssl_utils.py +233 -0
  61. mcp_proxy_adapter/core/transport_manager.py +292 -0
  62. mcp_proxy_adapter/core/unified_config_adapter.py +579 -0
  63. mcp_proxy_adapter/custom_openapi.py +22 -11
  64. mcp_proxy_adapter/examples/README.md +230 -97
  65. mcp_proxy_adapter/examples/README_EN.md +258 -0
  66. mcp_proxy_adapter/examples/SECURITY_TESTING.md +455 -0
  67. mcp_proxy_adapter/examples/__pycache__/security_configurations.cpython-312.pyc +0 -0
  68. mcp_proxy_adapter/examples/__pycache__/security_test_client.cpython-312.pyc +0 -0
  69. mcp_proxy_adapter/examples/basic_framework/configs/http_auth.json +37 -0
  70. mcp_proxy_adapter/examples/basic_framework/configs/http_simple.json +23 -0
  71. mcp_proxy_adapter/examples/basic_framework/configs/https_auth.json +39 -0
  72. mcp_proxy_adapter/examples/basic_framework/configs/https_simple.json +25 -0
  73. mcp_proxy_adapter/examples/basic_framework/configs/mtls_no_roles.json +39 -0
  74. mcp_proxy_adapter/examples/basic_framework/configs/mtls_with_roles.json +45 -0
  75. mcp_proxy_adapter/examples/basic_framework/main.py +63 -0
  76. mcp_proxy_adapter/examples/basic_framework/roles.json +21 -0
  77. mcp_proxy_adapter/examples/cert_config.json +9 -0
  78. mcp_proxy_adapter/examples/certs/admin.crt +32 -0
  79. mcp_proxy_adapter/examples/certs/admin.key +52 -0
  80. mcp_proxy_adapter/examples/certs/admin_cert.pem +21 -0
  81. mcp_proxy_adapter/examples/certs/admin_key.pem +28 -0
  82. mcp_proxy_adapter/examples/certs/ca_cert.pem +23 -0
  83. mcp_proxy_adapter/examples/certs/ca_cert.srl +1 -0
  84. mcp_proxy_adapter/examples/certs/ca_key.pem +28 -0
  85. mcp_proxy_adapter/examples/certs/cert_config.json +9 -0
  86. mcp_proxy_adapter/examples/certs/client.crt +32 -0
  87. mcp_proxy_adapter/examples/certs/client.key +52 -0
  88. mcp_proxy_adapter/examples/certs/client_admin.crt +32 -0
  89. mcp_proxy_adapter/examples/certs/client_admin.key +52 -0
  90. mcp_proxy_adapter/examples/certs/client_user.crt +32 -0
  91. mcp_proxy_adapter/examples/certs/client_user.key +52 -0
  92. mcp_proxy_adapter/examples/certs/guest_cert.pem +21 -0
  93. mcp_proxy_adapter/examples/certs/guest_key.pem +28 -0
  94. mcp_proxy_adapter/examples/certs/mcp_proxy_adapter_ca_ca.crt +23 -0
  95. mcp_proxy_adapter/examples/certs/proxy_cert.pem +21 -0
  96. mcp_proxy_adapter/examples/certs/proxy_key.pem +28 -0
  97. mcp_proxy_adapter/examples/certs/readonly.crt +32 -0
  98. mcp_proxy_adapter/examples/certs/readonly.key +52 -0
  99. mcp_proxy_adapter/examples/certs/readonly_cert.pem +21 -0
  100. mcp_proxy_adapter/examples/certs/readonly_key.pem +28 -0
  101. mcp_proxy_adapter/examples/certs/server.crt +32 -0
  102. mcp_proxy_adapter/examples/certs/server.key +52 -0
  103. mcp_proxy_adapter/examples/certs/server_cert.pem +32 -0
  104. mcp_proxy_adapter/examples/certs/server_key.pem +52 -0
  105. mcp_proxy_adapter/examples/certs/test_ca_ca.crt +20 -0
  106. mcp_proxy_adapter/examples/certs/user.crt +32 -0
  107. mcp_proxy_adapter/examples/certs/user.key +52 -0
  108. mcp_proxy_adapter/examples/certs/user_cert.pem +21 -0
  109. mcp_proxy_adapter/examples/certs/user_key.pem +28 -0
  110. mcp_proxy_adapter/examples/client_configs/api_key_client.json +13 -0
  111. mcp_proxy_adapter/examples/client_configs/basic_auth_client.json +13 -0
  112. mcp_proxy_adapter/examples/client_configs/certificate_client.json +22 -0
  113. mcp_proxy_adapter/examples/client_configs/jwt_client.json +15 -0
  114. mcp_proxy_adapter/examples/client_configs/no_auth_client.json +9 -0
  115. mcp_proxy_adapter/examples/commands/__init__.py +1 -0
  116. mcp_proxy_adapter/examples/create_certificates_simple.py +307 -0
  117. mcp_proxy_adapter/examples/debug_request_state.py +144 -0
  118. mcp_proxy_adapter/examples/debug_role_chain.py +205 -0
  119. mcp_proxy_adapter/examples/demo_client.py +341 -0
  120. mcp_proxy_adapter/examples/full_application/commands/custom_echo_command.py +99 -0
  121. mcp_proxy_adapter/examples/full_application/commands/dynamic_calculator_command.py +106 -0
  122. mcp_proxy_adapter/examples/full_application/configs/http_auth.json +37 -0
  123. mcp_proxy_adapter/examples/full_application/configs/http_simple.json +23 -0
  124. mcp_proxy_adapter/examples/full_application/configs/https_auth.json +39 -0
  125. mcp_proxy_adapter/examples/full_application/configs/https_simple.json +25 -0
  126. mcp_proxy_adapter/examples/full_application/configs/mtls_no_roles.json +39 -0
  127. mcp_proxy_adapter/examples/full_application/configs/mtls_with_roles.json +45 -0
  128. mcp_proxy_adapter/examples/full_application/hooks/application_hooks.py +97 -0
  129. mcp_proxy_adapter/examples/full_application/hooks/builtin_command_hooks.py +95 -0
  130. mcp_proxy_adapter/examples/full_application/main.py +138 -0
  131. mcp_proxy_adapter/examples/full_application/roles.json +21 -0
  132. mcp_proxy_adapter/examples/generate_all_certificates.py +429 -0
  133. mcp_proxy_adapter/examples/generate_certificates.py +121 -0
  134. mcp_proxy_adapter/examples/keys/ca_key.pem +28 -0
  135. mcp_proxy_adapter/examples/keys/mcp_proxy_adapter_ca_ca.key +28 -0
  136. mcp_proxy_adapter/examples/keys/test_ca_ca.key +28 -0
  137. mcp_proxy_adapter/examples/logs/mcp_proxy_adapter.log +220 -0
  138. mcp_proxy_adapter/examples/logs/mcp_proxy_adapter.log.1 +1 -0
  139. mcp_proxy_adapter/examples/logs/mcp_proxy_adapter.log.2 +1 -0
  140. mcp_proxy_adapter/examples/logs/mcp_proxy_adapter.log.3 +1 -0
  141. mcp_proxy_adapter/examples/logs/mcp_proxy_adapter.log.4 +1 -0
  142. mcp_proxy_adapter/examples/logs/mcp_proxy_adapter.log.5 +1 -0
  143. mcp_proxy_adapter/examples/logs/mcp_proxy_adapter_access.log +220 -0
  144. mcp_proxy_adapter/examples/logs/mcp_proxy_adapter_access.log.1 +1 -0
  145. mcp_proxy_adapter/examples/logs/mcp_proxy_adapter_access.log.2 +1 -0
  146. mcp_proxy_adapter/examples/logs/mcp_proxy_adapter_access.log.3 +1 -0
  147. mcp_proxy_adapter/examples/logs/mcp_proxy_adapter_access.log.4 +1 -0
  148. mcp_proxy_adapter/examples/logs/mcp_proxy_adapter_access.log.5 +1 -0
  149. mcp_proxy_adapter/examples/logs/mcp_proxy_adapter_error.log +2 -0
  150. mcp_proxy_adapter/examples/logs/mcp_proxy_adapter_error.log.1 +1 -0
  151. mcp_proxy_adapter/examples/logs/mcp_proxy_adapter_error.log.2 +1 -0
  152. mcp_proxy_adapter/examples/logs/mcp_proxy_adapter_error.log.3 +1 -0
  153. mcp_proxy_adapter/examples/logs/mcp_proxy_adapter_error.log.4 +1 -0
  154. mcp_proxy_adapter/examples/logs/mcp_proxy_adapter_error.log.5 +1 -0
  155. mcp_proxy_adapter/examples/proxy_registration_example.py +401 -0
  156. mcp_proxy_adapter/examples/roles.json +38 -0
  157. mcp_proxy_adapter/examples/run_example.py +81 -0
  158. mcp_proxy_adapter/examples/run_security_tests.py +326 -0
  159. mcp_proxy_adapter/examples/run_security_tests_fixed.py +300 -0
  160. mcp_proxy_adapter/examples/security_test_client.py +743 -0
  161. mcp_proxy_adapter/examples/server_configs/config_basic_http.json +204 -0
  162. mcp_proxy_adapter/examples/server_configs/config_http_token.json +238 -0
  163. mcp_proxy_adapter/examples/server_configs/config_https.json +215 -0
  164. mcp_proxy_adapter/examples/server_configs/config_https_token.json +231 -0
  165. mcp_proxy_adapter/examples/server_configs/config_mtls.json +215 -0
  166. mcp_proxy_adapter/examples/server_configs/config_proxy_registration.json +250 -0
  167. mcp_proxy_adapter/examples/server_configs/config_simple.json +46 -0
  168. mcp_proxy_adapter/examples/server_configs/roles.json +38 -0
  169. mcp_proxy_adapter/examples/test_examples.py +344 -0
  170. mcp_proxy_adapter/examples/universal_client.py +628 -0
  171. mcp_proxy_adapter/main.py +186 -0
  172. mcp_proxy_adapter/utils/config_generator.py +639 -0
  173. mcp_proxy_adapter/version.py +2 -1
  174. mcp_proxy_adapter-6.1.0.dist-info/METADATA +205 -0
  175. mcp_proxy_adapter-6.1.0.dist-info/RECORD +193 -0
  176. mcp_proxy_adapter-6.1.0.dist-info/entry_points.txt +2 -0
  177. {mcp_proxy_adapter-4.1.1.dist-info → mcp_proxy_adapter-6.1.0.dist-info}/licenses/LICENSE +2 -2
  178. mcp_proxy_adapter/api/middleware/auth.py +0 -146
  179. mcp_proxy_adapter/api/middleware/rate_limit.py +0 -152
  180. mcp_proxy_adapter/commands/reload_settings_command.py +0 -125
  181. mcp_proxy_adapter/examples/__init__.py +0 -7
  182. mcp_proxy_adapter/examples/basic_server/README.md +0 -60
  183. mcp_proxy_adapter/examples/basic_server/__init__.py +0 -7
  184. mcp_proxy_adapter/examples/basic_server/basic_custom_settings.json +0 -39
  185. mcp_proxy_adapter/examples/basic_server/config.json +0 -35
  186. mcp_proxy_adapter/examples/basic_server/custom_settings_example.py +0 -238
  187. mcp_proxy_adapter/examples/basic_server/server.py +0 -103
  188. mcp_proxy_adapter/examples/custom_commands/README.md +0 -127
  189. mcp_proxy_adapter/examples/custom_commands/__init__.py +0 -27
  190. mcp_proxy_adapter/examples/custom_commands/advanced_hooks.py +0 -250
  191. mcp_proxy_adapter/examples/custom_commands/auto_commands/__init__.py +0 -6
  192. mcp_proxy_adapter/examples/custom_commands/auto_commands/auto_echo_command.py +0 -103
  193. mcp_proxy_adapter/examples/custom_commands/auto_commands/auto_info_command.py +0 -111
  194. mcp_proxy_adapter/examples/custom_commands/config.json +0 -35
  195. mcp_proxy_adapter/examples/custom_commands/custom_health_command.py +0 -169
  196. mcp_proxy_adapter/examples/custom_commands/custom_help_command.py +0 -215
  197. mcp_proxy_adapter/examples/custom_commands/custom_openapi_generator.py +0 -76
  198. mcp_proxy_adapter/examples/custom_commands/custom_settings.json +0 -96
  199. mcp_proxy_adapter/examples/custom_commands/custom_settings_manager.py +0 -241
  200. mcp_proxy_adapter/examples/custom_commands/data_transform_command.py +0 -135
  201. mcp_proxy_adapter/examples/custom_commands/echo_command.py +0 -122
  202. mcp_proxy_adapter/examples/custom_commands/hooks.py +0 -230
  203. mcp_proxy_adapter/examples/custom_commands/intercept_command.py +0 -123
  204. mcp_proxy_adapter/examples/custom_commands/manual_echo_command.py +0 -103
  205. mcp_proxy_adapter/examples/custom_commands/server.py +0 -228
  206. mcp_proxy_adapter/examples/custom_commands/test_hooks.py +0 -176
  207. mcp_proxy_adapter/examples/deployment/README.md +0 -49
  208. mcp_proxy_adapter/examples/deployment/__init__.py +0 -7
  209. mcp_proxy_adapter/examples/deployment/config.development.json +0 -8
  210. mcp_proxy_adapter/examples/deployment/config.json +0 -29
  211. mcp_proxy_adapter/examples/deployment/config.production.json +0 -12
  212. mcp_proxy_adapter/examples/deployment/config.staging.json +0 -11
  213. mcp_proxy_adapter/examples/deployment/docker-compose.yml +0 -31
  214. mcp_proxy_adapter/examples/deployment/run.sh +0 -43
  215. mcp_proxy_adapter/examples/deployment/run_docker.sh +0 -84
  216. mcp_proxy_adapter/schemas/base_schema.json +0 -114
  217. mcp_proxy_adapter/schemas/openapi_schema.json +0 -314
  218. mcp_proxy_adapter/tests/__init__.py +0 -0
  219. mcp_proxy_adapter/tests/api/__init__.py +0 -3
  220. mcp_proxy_adapter/tests/api/test_cmd_endpoint.py +0 -115
  221. mcp_proxy_adapter/tests/api/test_custom_openapi.py +0 -617
  222. mcp_proxy_adapter/tests/api/test_handlers.py +0 -522
  223. mcp_proxy_adapter/tests/api/test_middleware.py +0 -340
  224. mcp_proxy_adapter/tests/api/test_schemas.py +0 -546
  225. mcp_proxy_adapter/tests/api/test_tool_integration.py +0 -531
  226. mcp_proxy_adapter/tests/commands/__init__.py +0 -3
  227. mcp_proxy_adapter/tests/commands/test_config_command.py +0 -211
  228. mcp_proxy_adapter/tests/commands/test_echo_command.py +0 -127
  229. mcp_proxy_adapter/tests/commands/test_help_command.py +0 -136
  230. mcp_proxy_adapter/tests/conftest.py +0 -131
  231. mcp_proxy_adapter/tests/functional/__init__.py +0 -3
  232. mcp_proxy_adapter/tests/functional/test_api.py +0 -253
  233. mcp_proxy_adapter/tests/integration/__init__.py +0 -3
  234. mcp_proxy_adapter/tests/integration/test_cmd_integration.py +0 -129
  235. mcp_proxy_adapter/tests/integration/test_integration.py +0 -255
  236. mcp_proxy_adapter/tests/performance/__init__.py +0 -3
  237. mcp_proxy_adapter/tests/performance/test_performance.py +0 -189
  238. mcp_proxy_adapter/tests/stubs/__init__.py +0 -10
  239. mcp_proxy_adapter/tests/stubs/echo_command.py +0 -104
  240. mcp_proxy_adapter/tests/test_api_endpoints.py +0 -271
  241. mcp_proxy_adapter/tests/test_api_handlers.py +0 -289
  242. mcp_proxy_adapter/tests/test_base_command.py +0 -123
  243. mcp_proxy_adapter/tests/test_batch_requests.py +0 -117
  244. mcp_proxy_adapter/tests/test_command_registry.py +0 -281
  245. mcp_proxy_adapter/tests/test_config.py +0 -127
  246. mcp_proxy_adapter/tests/test_utils.py +0 -65
  247. mcp_proxy_adapter/tests/unit/__init__.py +0 -3
  248. mcp_proxy_adapter/tests/unit/test_base_command.py +0 -436
  249. mcp_proxy_adapter/tests/unit/test_config.py +0 -217
  250. mcp_proxy_adapter-4.1.1.dist-info/METADATA +0 -200
  251. mcp_proxy_adapter-4.1.1.dist-info/RECORD +0 -110
  252. {mcp_proxy_adapter-4.1.1.dist-info → mcp_proxy_adapter-6.1.0.dist-info}/WHEEL +0 -0
  253. {mcp_proxy_adapter-4.1.1.dist-info → mcp_proxy_adapter-6.1.0.dist-info}/top_level.txt +0 -0
@@ -0,0 +1,639 @@
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 == "mtls":
298
+ return self._get_mtls_config(base_config)
299
+ else: # full
300
+ return base_config
301
+
302
+ def _get_minimal_config(self, base_config: Dict[str, Any]) -> Dict[str, Any]:
303
+ """Get minimal working configuration."""
304
+ config = base_config.copy()
305
+
306
+ # Disable security for minimal config
307
+ config["security"]["enabled"] = False
308
+ config["security"]["auth"]["enabled"] = False
309
+ config["security"]["permissions"]["enabled"] = False
310
+ config["security"]["rate_limit"]["enabled"] = False
311
+
312
+ # Disable registration for minimal config
313
+ config["registration"]["enabled"] = False
314
+
315
+ # Keep only essential settings
316
+ config["server"]["port"] = 8000
317
+ config["server"]["debug"] = False
318
+
319
+ return config
320
+
321
+ def _get_basic_http_config(self, base_config: Dict[str, Any]) -> Dict[str, Any]:
322
+ """Get basic HTTP configuration."""
323
+ config = base_config.copy()
324
+
325
+ # Basic HTTP settings
326
+ config["server"]["port"] = 8000
327
+ config["ssl"]["enabled"] = False
328
+ config["security"]["ssl"]["enabled"] = False
329
+ config["security"]["auth"]["enabled"] = False
330
+ config["security"]["permissions"]["enabled"] = False
331
+ config["security"]["permissions"]["roles_file"] = None
332
+ config["protocols"]["default_protocol"] = "http"
333
+
334
+ return config
335
+
336
+ def _get_http_token_config(self, base_config: Dict[str, Any]) -> Dict[str, Any]:
337
+ """Get HTTP with token authentication configuration."""
338
+ config = base_config.copy()
339
+
340
+ # HTTP with token auth
341
+ config["server"]["port"] = 8001
342
+ config["ssl"]["enabled"] = False
343
+ config["security"]["ssl"]["enabled"] = False
344
+ config["security"]["auth"]["enabled"] = True
345
+ config["security"]["auth"]["methods"] = ["api_key"]
346
+ config["security"]["auth"]["api_keys"] = {
347
+ "test-token-123": {
348
+ "roles": ["admin"],
349
+ "permissions": ["*"],
350
+ "expires": None
351
+ },
352
+ "user-token-456": {
353
+ "roles": ["user"],
354
+ "permissions": ["read", "execute"],
355
+ "expires": None
356
+ }
357
+ }
358
+ config["security"]["permissions"]["enabled"] = True
359
+ config["security"]["permissions"]["roles_file"] = "mcp_proxy_adapter/examples/server_configs/roles.json"
360
+ config["protocols"]["default_protocol"] = "http"
361
+
362
+ return config
363
+
364
+ def _get_https_config(self, base_config: Dict[str, Any]) -> Dict[str, Any]:
365
+ """Get HTTPS configuration."""
366
+ config = base_config.copy()
367
+
368
+ # HTTPS settings
369
+ config["server"]["port"] = 8443
370
+ config["ssl"]["enabled"] = True
371
+ config["ssl"]["cert_file"] = "mcp_proxy_adapter/examples/certs/server_cert.pem"
372
+ config["ssl"]["key_file"] = "mcp_proxy_adapter/examples/certs/server_key.pem"
373
+ config["ssl"]["ca_cert"] = "mcp_proxy_adapter/examples/certs/ca_cert.pem"
374
+
375
+ config["security"]["ssl"]["enabled"] = True
376
+ config["security"]["ssl"]["cert_file"] = "mcp_proxy_adapter/examples/certs/server_cert.pem"
377
+ config["security"]["ssl"]["key_file"] = "mcp_proxy_adapter/examples/certs/server_key.pem"
378
+ config["security"]["ssl"]["ca_cert_file"] = "mcp_proxy_adapter/examples/certs/ca_cert.pem"
379
+
380
+ config["security"]["auth"]["enabled"] = False
381
+ config["security"]["permissions"]["enabled"] = False
382
+ config["security"]["permissions"]["roles_file"] = None
383
+ config["protocols"]["default_protocol"] = "https"
384
+
385
+ return config
386
+
387
+ def _get_https_token_config(self, base_config: Dict[str, Any]) -> Dict[str, Any]:
388
+ """Get HTTPS with token authentication configuration."""
389
+ config = base_config.copy()
390
+
391
+ # HTTPS with token auth
392
+ config["server"]["port"] = 8444
393
+ config["ssl"]["enabled"] = True
394
+ config["ssl"]["cert_file"] = "mcp_proxy_adapter/examples/certs/server_cert.pem"
395
+ config["ssl"]["key_file"] = "mcp_proxy_adapter/examples/certs/server_key.pem"
396
+ config["ssl"]["ca_cert"] = "mcp_proxy_adapter/examples/certs/ca_cert.pem"
397
+
398
+ config["security"]["ssl"]["enabled"] = True
399
+ config["security"]["ssl"]["cert_file"] = "mcp_proxy_adapter/examples/certs/server_cert.pem"
400
+ config["security"]["ssl"]["key_file"] = "mcp_proxy_adapter/examples/certs/server_key.pem"
401
+ config["security"]["ssl"]["ca_cert_file"] = "mcp_proxy_adapter/examples/certs/ca_cert.pem"
402
+
403
+ config["security"]["auth"]["enabled"] = True
404
+ config["security"]["auth"]["methods"] = ["api_key"]
405
+ config["security"]["auth"]["api_keys"] = {
406
+ "test-token-123": {
407
+ "roles": ["admin"],
408
+ "permissions": ["*"],
409
+ "expires": None
410
+ },
411
+ "user-token-456": {
412
+ "roles": ["user"],
413
+ "permissions": ["read", "execute"],
414
+ "expires": None
415
+ }
416
+ }
417
+ config["security"]["permissions"]["enabled"] = True
418
+ config["security"]["permissions"]["roles_file"] = "mcp_proxy_adapter/examples/server_configs/roles.json"
419
+ config["protocols"]["default_protocol"] = "https"
420
+
421
+ return config
422
+
423
+ def _get_mtls_config(self, base_config: Dict[str, Any]) -> Dict[str, Any]:
424
+ """Get mTLS configuration."""
425
+ config = base_config.copy()
426
+
427
+ # mTLS settings
428
+ config["server"]["port"] = 8445
429
+ config["ssl"]["enabled"] = True
430
+ config["ssl"]["cert_file"] = "mcp_proxy_adapter/examples/certs/server_cert.pem"
431
+ config["ssl"]["key_file"] = "mcp_proxy_adapter/examples/certs/server_key.pem"
432
+ config["ssl"]["ca_cert"] = "mcp_proxy_adapter/examples/certs/ca_cert.pem"
433
+ config["ssl"]["verify_client"] = True
434
+ config["ssl"]["client_cert_required"] = True
435
+
436
+ config["security"]["ssl"]["enabled"] = True
437
+ config["security"]["ssl"]["cert_file"] = "mcp_proxy_adapter/examples/certs/server_cert.pem"
438
+ config["security"]["ssl"]["key_file"] = "mcp_proxy_adapter/examples/certs/server_key.pem"
439
+ config["security"]["ssl"]["ca_cert_file"] = "mcp_proxy_adapter/examples/certs/ca_cert.pem"
440
+ config["security"]["ssl"]["client_cert_file"] = "mcp_proxy_adapter/examples/certs/client_cert.pem"
441
+ config["security"]["ssl"]["client_key_file"] = "mcp_proxy_adapter/examples/certs/client_key.pem"
442
+ config["security"]["ssl"]["verify_mode"] = "CERT_REQUIRED"
443
+
444
+ config["security"]["auth"]["enabled"] = True
445
+ config["security"]["auth"]["methods"] = ["certificate"]
446
+ config["security"]["auth"]["certificate_auth"] = True
447
+ config["security"]["permissions"]["enabled"] = True
448
+ config["security"]["permissions"]["roles_file"] = "mcp_proxy_adapter/examples/server_configs/roles.json"
449
+ config["protocols"]["default_protocol"] = "https"
450
+
451
+ return config
452
+
453
+ def _get_secure_config(self, base_config: Dict[str, Any]) -> Dict[str, Any]:
454
+ """Get secure configuration with all security features enabled."""
455
+ config = base_config.copy()
456
+
457
+ # Enable all security features
458
+ config["security"]["enabled"] = True
459
+ config["security"]["ssl"]["enabled"] = True
460
+ config["security"]["auth"]["enabled"] = True
461
+ config["security"]["permissions"]["enabled"] = True
462
+ config["security"]["rate_limit"]["enabled"] = True
463
+
464
+ # Enable registration with certificate auth
465
+ config["registration"]["enabled"] = True
466
+ config["registration"]["auth_method"] = "certificate"
467
+ config["registration"]["certificate"]["enabled"] = True
468
+
469
+ # Set secure defaults
470
+ config["security"]["ssl"]["min_tls_version"] = "TLSv1.2"
471
+ config["security"]["auth"]["methods"] = ["api_key", "jwt"]
472
+ config["security"]["permissions"]["strict_mode"] = True
473
+ config["security"]["rate_limit"]["burst_limit"] = 1
474
+
475
+ return config
476
+
477
+ def _get_development_config(self, base_config: Dict[str, Any]) -> Dict[str, Any]:
478
+ """Get development configuration with debug enabled."""
479
+ config = base_config.copy()
480
+
481
+ # Enable debug features
482
+ config["server"]["debug"] = True
483
+ config["security"]["debug"] = True
484
+ config["logging"]["level"] = "DEBUG"
485
+
486
+ # Enable registration with token auth for development
487
+ config["registration"]["enabled"] = True
488
+ config["registration"]["auth_method"] = "token"
489
+ config["registration"]["token"]["enabled"] = True
490
+
491
+ # Relax security for development
492
+ config["security"]["rate_limit"]["default_requests_per_minute"] = 1000
493
+ config["security"]["permissions"]["strict_mode"] = False
494
+
495
+ return config
496
+
497
+ def _add_comments(self, json_str: str, config_type: str) -> str:
498
+ """Add comments to JSON configuration."""
499
+ comments = self._get_comments_for_type(config_type)
500
+
501
+ # Add header comment
502
+ commented_config = f"""/**
503
+ * MCP Proxy Adapter Configuration
504
+ *
505
+ * This configuration file combines settings for both mcp_proxy_adapter
506
+ * and mcp_security_framework in a unified format.
507
+ *
508
+ * Configuration Type: {config_type.title()}
509
+ * Generated by: ConfigGenerator
510
+ *
511
+ * IMPORTANT: This is a template configuration. Please customize it
512
+ * according to your specific requirements and security needs.
513
+ */
514
+
515
+ """
516
+
517
+ # Add section comments
518
+ for section, comment in comments.items():
519
+ if section in json_str:
520
+ # Find the section and add comment before it
521
+ section_start = json_str.find(f'"{section}":')
522
+ if section_start != -1:
523
+ # Find the line start
524
+ line_start = json_str.rfind('\n', 0, section_start) + 1
525
+ json_str = (
526
+ json_str[:line_start] +
527
+ f" // {comment}\n" +
528
+ json_str[line_start:]
529
+ )
530
+
531
+ return commented_config + json_str
532
+
533
+ def _get_comments_for_type(self, config_type: str) -> Dict[str, str]:
534
+ """Get comments for configuration sections."""
535
+ base_comments = {
536
+ "server": "Server configuration for FastAPI application",
537
+ "ssl": "SSL/TLS configuration for secure connections",
538
+ "security": "Security framework configuration (mcp_security_framework)",
539
+ "registration": "Proxy registration configuration for secure proxy discovery",
540
+ "logging": "Logging configuration for the application",
541
+ "commands": "Command management and discovery settings",
542
+ "hooks": "Application and command hooks configuration",
543
+ "protocols": "Protocol endpoints and settings"
544
+ }
545
+
546
+ if config_type == "minimal":
547
+ base_comments["security"] = "Security framework configuration (disabled for minimal setup)"
548
+ base_comments["registration"] = "Proxy registration configuration (disabled for minimal setup)"
549
+ elif config_type == "secure":
550
+ base_comments["security"] = "Security framework configuration (all features enabled)"
551
+ base_comments["registration"] = "Proxy registration configuration (certificate authentication enabled)"
552
+ elif config_type == "development":
553
+ base_comments["security"] = "Security framework configuration (development mode with relaxed settings)"
554
+ base_comments["registration"] = "Proxy registration configuration (token authentication for development)"
555
+ elif config_type in ["basic_http", "http_token"]:
556
+ base_comments["ssl"] = "SSL/TLS configuration (disabled for HTTP)"
557
+ base_comments["security"] = f"Security framework configuration ({config_type} mode)"
558
+ elif config_type in ["https", "https_token"]:
559
+ base_comments["ssl"] = "SSL/TLS configuration (enabled for HTTPS)"
560
+ base_comments["security"] = f"Security framework configuration ({config_type} mode)"
561
+ elif config_type == "mtls":
562
+ base_comments["ssl"] = "SSL/TLS configuration (enabled for mTLS with client certificate verification)"
563
+ base_comments["security"] = "Security framework configuration (mTLS mode with certificate authentication)"
564
+
565
+ return base_comments
566
+
567
+ def generate_config_file(self, output_path: str, config_type: str = "full") -> None:
568
+ """
569
+ Generate configuration file and save to disk.
570
+
571
+ Args:
572
+ output_path: Path to save the configuration file
573
+ config_type: Type of configuration to generate
574
+ """
575
+ try:
576
+ config_content = self.generate_config_with_comments(config_type)
577
+
578
+ # Create directory if it doesn't exist
579
+ output_file = Path(output_path)
580
+ output_file.parent.mkdir(parents=True, exist_ok=True)
581
+
582
+ # Write configuration file
583
+ with open(output_file, 'w', encoding='utf-8') as f:
584
+ f.write(config_content)
585
+
586
+ logger.info(f"Configuration file generated: {output_path}")
587
+ logger.info(f"Configuration type: {config_type}")
588
+
589
+ except Exception as e:
590
+ logger.error(f"Failed to generate configuration file: {e}")
591
+ raise
592
+
593
+ def generate_all_configs(self, output_dir: str) -> None:
594
+ """
595
+ Generate all configuration types.
596
+
597
+ Args:
598
+ output_dir: Directory to save configuration files
599
+ """
600
+ config_types = [
601
+ "minimal", "development", "secure", "full",
602
+ "basic_http", "http_token", "https", "https_token", "mtls"
603
+ ]
604
+
605
+ for config_type in config_types:
606
+ output_path = Path(output_dir) / f"config_{config_type}.json"
607
+ self.generate_config_file(str(output_path), config_type)
608
+
609
+ logger.info(f"Generated {len(config_types)} configuration files in {output_dir}")
610
+
611
+
612
+ def main():
613
+ """Main function for command-line usage."""
614
+ import argparse
615
+
616
+ parser = argparse.ArgumentParser(description="Generate MCP Proxy Adapter configuration files")
617
+ parser.add_argument("--type",
618
+ choices=["minimal", "development", "secure", "full",
619
+ "basic_http", "http_token", "https", "https_token", "mtls"],
620
+ default="full", help="Configuration type to generate")
621
+ parser.add_argument("--output", default="./config.json",
622
+ help="Output file path")
623
+ parser.add_argument("--all", action="store_true",
624
+ help="Generate all configuration types")
625
+ parser.add_argument("--output-dir", default="./configs",
626
+ help="Output directory for all configs")
627
+
628
+ args = parser.parse_args()
629
+
630
+ generator = ConfigGenerator()
631
+
632
+ if args.all:
633
+ generator.generate_all_configs(args.output_dir)
634
+ else:
635
+ generator.generate_config_file(args.output, args.type)
636
+
637
+
638
+ if __name__ == "__main__":
639
+ main()
@@ -1,3 +1,4 @@
1
1
  """Version information for MCP Microservice."""
2
2
 
3
- __version__ = "4.1.1"
3
+ __version__ = "6.1.0"
4
+