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
@@ -1,96 +0,0 @@
1
- {
2
- "application": {
3
- "name": "Extended MCP Proxy Server with Custom Settings",
4
- "version": "2.1.0",
5
- "environment": "development",
6
- "description": "Advanced server with custom settings management"
7
- },
8
- "features": {
9
- "advanced_hooks": true,
10
- "custom_commands": true,
11
- "data_transformation": true,
12
- "command_interception": true,
13
- "performance_monitoring": true,
14
- "custom_settings_manager": true
15
- },
16
- "security": {
17
- "enable_authentication": false,
18
- "max_request_size": "15MB",
19
- "rate_limiting": {
20
- "enabled": true,
21
- "requests_per_minute": 200,
22
- "burst_limit": 50
23
- },
24
- "cors": {
25
- "enabled": true,
26
- "allowed_origins": ["*"],
27
- "allowed_methods": ["GET", "POST", "PUT", "DELETE"]
28
- }
29
- },
30
- "monitoring": {
31
- "enable_metrics": true,
32
- "metrics_interval": 30,
33
- "health_check_interval": 15,
34
- "log_level": "DEBUG",
35
- "performance_tracking": {
36
- "enabled": true,
37
- "track_response_times": true,
38
- "track_memory_usage": true
39
- }
40
- },
41
- "custom_commands": {
42
- "auto_echo": {
43
- "enabled": true,
44
- "max_length": 2000,
45
- "enable_formatting": true
46
- },
47
- "data_transform": {
48
- "enabled": true,
49
- "transform_types": ["uppercase", "lowercase", "reverse", "capitalize", "title"],
50
- "enable_custom_transforms": true
51
- },
52
- "intercept": {
53
- "enabled": true,
54
- "bypass_conditions": ["input_value == 0", "input_value < 0"],
55
- "intercept_all_commands": false
56
- },
57
- "manual_echo": {
58
- "enabled": true,
59
- "description": "Manually registered echo command with custom settings"
60
- }
61
- },
62
- "hooks": {
63
- "data_transform": {
64
- "enabled": true,
65
- "transform_types": ["uppercase", "lowercase", "reverse"],
66
- "apply_to_all_commands": false
67
- },
68
- "intercept": {
69
- "enabled": true,
70
- "bypass_conditions": ["input_value == 0"],
71
- "log_interceptions": true
72
- }
73
- },
74
- "database": {
75
- "enabled": false,
76
- "type": "sqlite",
77
- "connection_string": "sqlite:///custom_server.db",
78
- "pool_size": 10,
79
- "max_overflow": 20
80
- },
81
- "cache": {
82
- "enabled": true,
83
- "type": "memory",
84
- "ttl": 300,
85
- "max_size": 1000
86
- },
87
- "api": {
88
- "version": "v1",
89
- "prefix": "/api/v1",
90
- "documentation": {
91
- "enabled": true,
92
- "title": "Extended MCP Proxy API",
93
- "description": "Advanced API with custom settings support"
94
- }
95
- }
96
- }
@@ -1,241 +0,0 @@
1
- """
2
- Custom Settings Manager Example
3
-
4
- This module demonstrates how to create a custom settings manager
5
- that extends the framework's settings system with application-specific settings.
6
- """
7
-
8
- import json
9
- import os
10
- from typing import Dict, Any, Optional
11
- from mcp_proxy_adapter.core.settings import (
12
- add_custom_settings,
13
- get_custom_settings,
14
- get_custom_setting_value,
15
- set_custom_setting_value
16
- )
17
- from mcp_proxy_adapter.core.logging import get_logger
18
-
19
-
20
- class CustomSettingsManager:
21
- """
22
- Custom settings manager for the extended server example.
23
-
24
- This class demonstrates how to:
25
- 1. Load custom settings from JSON files
26
- 2. Add them to the framework's settings system
27
- 3. Provide convenient access methods
28
- 4. Handle settings validation and defaults
29
- """
30
-
31
- def __init__(self, config_file: str = "custom_settings.json"):
32
- """
33
- Initialize the custom settings manager.
34
-
35
- Args:
36
- config_file: Path to custom settings JSON file
37
- """
38
- self.config_file = config_file
39
- self.logger = get_logger("custom_settings_manager")
40
- self._load_custom_settings()
41
-
42
- def _load_custom_settings(self) -> None:
43
- """Load custom settings from JSON file."""
44
- try:
45
- if os.path.exists(self.config_file):
46
- with open(self.config_file, 'r', encoding='utf-8') as f:
47
- custom_settings = json.load(f)
48
-
49
- self.logger.info(f"📁 Loaded custom settings from: {self.config_file}")
50
- self.logger.debug(f"📋 Custom settings: {custom_settings}")
51
-
52
- # Add to framework's settings system
53
- add_custom_settings(custom_settings)
54
-
55
- else:
56
- self.logger.warning(f"⚠️ Custom settings file not found: {self.config_file}")
57
- self.logger.info("📝 Using default custom settings")
58
-
59
- # Use default settings
60
- default_settings = self._get_default_settings()
61
- add_custom_settings(default_settings)
62
-
63
- except Exception as e:
64
- self.logger.error(f"❌ Failed to load custom settings: {e}")
65
- self.logger.info("📝 Using default custom settings")
66
-
67
- # Use default settings on error
68
- default_settings = self._get_default_settings()
69
- add_custom_settings(default_settings)
70
-
71
- def _get_default_settings(self) -> Dict[str, Any]:
72
- """Get default custom settings."""
73
- return {
74
- "application": {
75
- "name": "Extended MCP Proxy Server",
76
- "version": "2.0.0",
77
- "environment": "development"
78
- },
79
- "features": {
80
- "advanced_hooks": True,
81
- "custom_commands": True,
82
- "data_transformation": True,
83
- "command_interception": True,
84
- "performance_monitoring": False
85
- },
86
- "security": {
87
- "enable_authentication": False,
88
- "max_request_size": "10MB",
89
- "rate_limiting": {
90
- "enabled": False,
91
- "requests_per_minute": 100
92
- }
93
- },
94
- "monitoring": {
95
- "enable_metrics": True,
96
- "metrics_interval": 60,
97
- "health_check_interval": 30
98
- },
99
- "custom_commands": {
100
- "auto_echo": {
101
- "enabled": True,
102
- "max_length": 1000
103
- },
104
- "data_transform": {
105
- "enabled": True,
106
- "transform_types": ["uppercase", "lowercase", "reverse"]
107
- },
108
- "intercept": {
109
- "enabled": True,
110
- "bypass_conditions": ["input_value == 0"]
111
- }
112
- }
113
- }
114
-
115
- def get_application_name(self) -> str:
116
- """Get application name."""
117
- return get_custom_setting_value("application.name", "Extended MCP Proxy Server")
118
-
119
- def get_application_version(self) -> str:
120
- """Get application version."""
121
- return get_custom_setting_value("application.version", "2.0.0")
122
-
123
- def get_environment(self) -> str:
124
- """Get application environment."""
125
- return get_custom_setting_value("application.environment", "development")
126
-
127
- def is_feature_enabled(self, feature_name: str) -> bool:
128
- """Check if a feature is enabled."""
129
- return get_custom_setting_value(f"features.{feature_name}", False)
130
-
131
- def get_security_setting(self, setting_name: str, default: Any = None) -> Any:
132
- """Get security setting."""
133
- return get_custom_setting_value(f"security.{setting_name}", default)
134
-
135
- def get_monitoring_setting(self, setting_name: str, default: Any = None) -> Any:
136
- """Get monitoring setting."""
137
- return get_custom_setting_value(f"monitoring.{setting_name}", default)
138
-
139
- def get_custom_command_setting(self, command_name: str, setting_name: str, default: Any = None) -> Any:
140
- """Get custom command setting."""
141
- return get_custom_setting_value(f"custom_commands.{command_name}.{setting_name}", default)
142
-
143
- def set_custom_setting(self, key: str, value: Any) -> None:
144
- """Set a custom setting."""
145
- set_custom_setting_value(key, value)
146
- self.logger.info(f"🔧 Set custom setting: {key} = {value}")
147
-
148
- def get_all_custom_settings(self) -> Dict[str, Any]:
149
- """Get all custom settings."""
150
- return get_custom_settings()
151
-
152
- def reload_settings(self) -> None:
153
- """Reload custom settings from file."""
154
- self.logger.info("🔄 Reloading custom settings...")
155
- self._load_custom_settings()
156
- self.logger.info("✅ Custom settings reloaded")
157
-
158
- def validate_settings(self) -> Dict[str, Any]:
159
- """
160
- Validate current settings and return validation results.
161
-
162
- Returns:
163
- Dictionary with validation results
164
- """
165
- validation_results = {
166
- "valid": True,
167
- "errors": [],
168
- "warnings": []
169
- }
170
-
171
- # Validate required settings
172
- required_settings = [
173
- "application.name",
174
- "application.version",
175
- "features.advanced_hooks"
176
- ]
177
-
178
- for setting in required_settings:
179
- if get_custom_setting_value(setting) is None:
180
- validation_results["valid"] = False
181
- validation_results["errors"].append(f"Missing required setting: {setting}")
182
-
183
- # Validate feature dependencies
184
- if self.is_feature_enabled("data_transformation"):
185
- if not self.is_feature_enabled("custom_commands"):
186
- validation_results["warnings"].append(
187
- "data_transformation requires custom_commands to be enabled"
188
- )
189
-
190
- # Validate security settings
191
- if self.get_security_setting("enable_authentication"):
192
- if not self.get_security_setting("rate_limiting.enabled"):
193
- validation_results["warnings"].append(
194
- "Authentication enabled but rate limiting is disabled"
195
- )
196
-
197
- return validation_results
198
-
199
- def print_settings_summary(self) -> None:
200
- """Print a summary of current settings."""
201
- self.logger.info("📊 Custom Settings Summary:")
202
- self.logger.info(f" Application: {self.get_application_name()} v{self.get_application_version()}")
203
- self.logger.info(f" Environment: {self.get_environment()}")
204
-
205
- # Features
206
- features = []
207
- for feature in ["advanced_hooks", "custom_commands", "data_transformation", "command_interception"]:
208
- if self.is_feature_enabled(feature):
209
- features.append(feature)
210
-
211
- self.logger.info(f" Enabled Features: {', '.join(features) if features else 'None'}")
212
-
213
- # Security
214
- auth_enabled = self.get_security_setting("enable_authentication", False)
215
- rate_limiting = self.get_security_setting("rate_limiting.enabled", False)
216
- self.logger.info(f" Security: Auth={auth_enabled}, Rate Limiting={rate_limiting}")
217
-
218
- # Monitoring
219
- metrics_enabled = self.get_monitoring_setting("enable_metrics", False)
220
- self.logger.info(f" Monitoring: Metrics={metrics_enabled}")
221
-
222
-
223
- # Convenience functions for easy access
224
- def get_app_name() -> str:
225
- """Get application name."""
226
- return get_custom_setting_value("application.name", "Extended MCP Proxy Server")
227
-
228
-
229
- def is_feature_enabled(feature_name: str) -> bool:
230
- """Check if a feature is enabled."""
231
- return get_custom_setting_value(f"features.{feature_name}", False)
232
-
233
-
234
- def get_security_setting(setting_name: str, default: Any = None) -> Any:
235
- """Get security setting."""
236
- return get_custom_setting_value(f"security.{setting_name}", default)
237
-
238
-
239
- def get_monitoring_setting(setting_name: str, default: Any = None) -> Any:
240
- """Get monitoring setting."""
241
- return get_custom_setting_value(f"monitoring.{setting_name}", default)
@@ -1,135 +0,0 @@
1
- """
2
- Data Transform Command Example
3
-
4
- A command that demonstrates advanced hooks with data transformation.
5
- """
6
-
7
- from typing import Dict, Any, Optional
8
- from mcp_proxy_adapter.commands.base import Command
9
- from mcp_proxy_adapter.commands.result import CommandResult
10
-
11
-
12
- class DataTransformResult(CommandResult):
13
- """
14
- Result of the data transform command execution.
15
- """
16
-
17
- def __init__(self, original_data: Dict[str, Any], transformed_data: Dict[str, Any],
18
- processing_info: Dict[str, Any]):
19
- """
20
- Initialize data transform command result.
21
-
22
- Args:
23
- original_data: Original input data
24
- transformed_data: Transformed output data
25
- processing_info: Information about processing steps
26
- """
27
- self.original_data = original_data
28
- self.transformed_data = transformed_data
29
- self.processing_info = processing_info
30
-
31
- def to_dict(self) -> Dict[str, Any]:
32
- """
33
- Convert result to dictionary.
34
-
35
- Returns:
36
- Dict[str, Any]: Result as dictionary
37
- """
38
- return {
39
- "original_data": self.original_data,
40
- "transformed_data": self.transformed_data,
41
- "processing_info": self.processing_info,
42
- "command_type": "data_transform"
43
- }
44
-
45
- @classmethod
46
- def get_schema(cls) -> Dict[str, Any]:
47
- """
48
- Get JSON schema for the result.
49
-
50
- Returns:
51
- Dict[str, Any]: JSON schema
52
- """
53
- return {
54
- "type": "object",
55
- "properties": {
56
- "original_data": {"type": "object"},
57
- "transformed_data": {"type": "object"},
58
- "processing_info": {"type": "object"},
59
- "command_type": {"type": "string"}
60
- }
61
- }
62
-
63
-
64
- class DataTransformCommand(Command):
65
- """
66
- Data transform command for demonstrating advanced hooks.
67
- """
68
-
69
- name = "data_transform"
70
- result_class = DataTransformResult
71
-
72
- async def execute(self, data: Optional[Dict[str, Any]] = None,
73
- transform_type: Optional[str] = None, **kwargs) -> DataTransformResult:
74
- """
75
- Execute data transform command.
76
-
77
- Args:
78
- data: Input data to transform
79
- transform_type: Type of transformation to apply
80
- **kwargs: Additional parameters
81
-
82
- Returns:
83
- DataTransformResult: Data transform command result
84
- """
85
- # Get original data (may be modified by hooks)
86
- original_data = data or {}
87
- transform_type = transform_type or "default"
88
-
89
- # Apply transformation based on type
90
- if transform_type == "uppercase":
91
- transformed_data = {k: str(v).upper() for k, v in original_data.items()}
92
- elif transform_type == "lowercase":
93
- transformed_data = {k: str(v).lower() for k, v in original_data.items()}
94
- elif transform_type == "reverse":
95
- transformed_data = {k: str(v)[::-1] for k, v in original_data.items()}
96
- else:
97
- transformed_data = original_data.copy()
98
-
99
- # Add processing info
100
- processing_info = {
101
- "transform_type": transform_type,
102
- "input_keys": list(original_data.keys()),
103
- "output_keys": list(transformed_data.keys()),
104
- "hook_enhanced": kwargs.get("hook_enhanced", False),
105
- "data_modified": kwargs.get("data_modified", False)
106
- }
107
-
108
- return DataTransformResult(
109
- original_data=original_data,
110
- transformed_data=transformed_data,
111
- processing_info=processing_info
112
- )
113
-
114
- @classmethod
115
- def get_schema(cls) -> Dict[str, Any]:
116
- """
117
- Get JSON schema for command parameters.
118
-
119
- Returns:
120
- Dict[str, Any]: JSON schema
121
- """
122
- return {
123
- "type": "object",
124
- "properties": {
125
- "data": {
126
- "type": "object",
127
- "description": "Input data to transform"
128
- },
129
- "transform_type": {
130
- "type": "string",
131
- "enum": ["uppercase", "lowercase", "reverse", "default"],
132
- "description": "Type of transformation to apply"
133
- }
134
- }
135
- }
@@ -1,122 +0,0 @@
1
- """
2
- Echo Command Example
3
-
4
- A simple echo command that returns the input message.
5
- """
6
-
7
- from typing import Dict, Any, Optional
8
- from datetime import datetime
9
- from mcp_proxy_adapter.commands.base import Command
10
- from mcp_proxy_adapter.commands.result import SuccessResult
11
-
12
-
13
- class EchoResult(SuccessResult):
14
- """
15
- Result of the echo command execution.
16
- """
17
-
18
- def __init__(self, message: str, timestamp: str):
19
- """
20
- Initialize echo command result.
21
-
22
- Args:
23
- message: The echoed message
24
- timestamp: Timestamp of execution
25
- """
26
- super().__init__(
27
- data={
28
- "message": message,
29
- "timestamp": timestamp,
30
- "echoed": True
31
- }
32
- )
33
-
34
- @classmethod
35
- def get_schema(cls) -> Dict[str, Any]:
36
- """
37
- Get JSON schema for result validation.
38
-
39
- Returns:
40
- Dict[str, Any]: JSON schema
41
- """
42
- return {
43
- "type": "object",
44
- "properties": {
45
- "data": {
46
- "type": "object",
47
- "properties": {
48
- "message": {"type": "string"},
49
- "timestamp": {"type": "string"},
50
- "echoed": {"type": "boolean"}
51
- },
52
- "required": ["message", "timestamp", "echoed"]
53
- }
54
- },
55
- "required": ["data"]
56
- }
57
-
58
-
59
- class EchoCommand(Command):
60
- """
61
- Echo command that returns the input message.
62
- """
63
-
64
- name = "echo"
65
- result_class = EchoResult
66
-
67
- async def execute(self, message: Optional[str] = None, **kwargs) -> EchoResult:
68
- """
69
- Execute echo command.
70
-
71
- Args:
72
- message: Message to echo (optional)
73
- **kwargs: Additional parameters
74
-
75
- Returns:
76
- EchoResult: Echo command result
77
- """
78
- # Use provided message or default
79
- if message is None:
80
- message = kwargs.get("text", "Hello, World!")
81
-
82
- # Check if hook added timestamp
83
- hook_timestamp = kwargs.get("hook_timestamp")
84
- if hook_timestamp:
85
- # Use hook timestamp if available
86
- timestamp = hook_timestamp
87
- else:
88
- # Get current timestamp
89
- timestamp = datetime.now().isoformat()
90
-
91
- # Add hook metadata to result
92
- result = EchoResult(message=message, timestamp=timestamp)
93
-
94
- # Add hook information if available
95
- if kwargs.get("hook_processed"):
96
- result.data["hook_processed"] = True
97
- result.data["hook_timestamp"] = hook_timestamp
98
-
99
- return result
100
-
101
- @classmethod
102
- def get_schema(cls) -> Dict[str, Any]:
103
- """
104
- Get JSON schema for command parameters.
105
-
106
- Returns:
107
- Dict[str, Any]: JSON schema
108
- """
109
- return {
110
- "type": "object",
111
- "properties": {
112
- "message": {
113
- "type": "string",
114
- "description": "Message to echo",
115
- "default": "Hello, World!"
116
- },
117
- "text": {
118
- "type": "string",
119
- "description": "Alternative parameter name for message"
120
- }
121
- }
122
- }