mcp-proxy-adapter 6.0.0__py3-none-any.whl → 6.1.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 (264) hide show
  1. mcp_proxy_adapter/api/app.py +174 -80
  2. mcp_proxy_adapter/api/handlers.py +16 -5
  3. mcp_proxy_adapter/api/middleware/__init__.py +9 -4
  4. mcp_proxy_adapter/api/middleware/command_permission_middleware.py +148 -0
  5. mcp_proxy_adapter/api/middleware/factory.py +36 -12
  6. mcp_proxy_adapter/api/middleware/protocol_middleware.py +32 -13
  7. mcp_proxy_adapter/api/middleware/unified_security.py +160 -0
  8. mcp_proxy_adapter/api/middleware/user_info_middleware.py +83 -0
  9. mcp_proxy_adapter/commands/__init__.py +7 -1
  10. mcp_proxy_adapter/commands/base.py +7 -4
  11. mcp_proxy_adapter/commands/builtin_commands.py +8 -2
  12. mcp_proxy_adapter/commands/command_registry.py +8 -0
  13. mcp_proxy_adapter/commands/echo_command.py +81 -0
  14. mcp_proxy_adapter/commands/help_command.py +21 -14
  15. mcp_proxy_adapter/commands/proxy_registration_command.py +326 -185
  16. mcp_proxy_adapter/commands/role_test_command.py +141 -0
  17. mcp_proxy_adapter/commands/security_command.py +488 -0
  18. mcp_proxy_adapter/commands/ssl_setup_command.py +2 -2
  19. mcp_proxy_adapter/commands/token_management_command.py +1 -1
  20. mcp_proxy_adapter/config.py +81 -21
  21. mcp_proxy_adapter/core/app_factory.py +326 -0
  22. mcp_proxy_adapter/core/client_security.py +384 -0
  23. mcp_proxy_adapter/core/logging.py +8 -3
  24. mcp_proxy_adapter/core/mtls_asgi.py +156 -0
  25. mcp_proxy_adapter/core/mtls_asgi_app.py +187 -0
  26. mcp_proxy_adapter/core/protocol_manager.py +139 -8
  27. mcp_proxy_adapter/core/proxy_client.py +602 -0
  28. mcp_proxy_adapter/core/proxy_registration.py +299 -47
  29. mcp_proxy_adapter/core/security_adapter.py +12 -15
  30. mcp_proxy_adapter/core/security_integration.py +285 -0
  31. mcp_proxy_adapter/core/server_adapter.py +345 -0
  32. mcp_proxy_adapter/core/server_engine.py +364 -0
  33. mcp_proxy_adapter/core/unified_config_adapter.py +579 -0
  34. mcp_proxy_adapter/docs/EN/TROUBLESHOOTING.md +285 -0
  35. mcp_proxy_adapter/docs/RU/TROUBLESHOOTING.md +285 -0
  36. mcp_proxy_adapter/examples/README.md +230 -97
  37. mcp_proxy_adapter/examples/README_EN.md +258 -0
  38. mcp_proxy_adapter/examples/SECURITY_TESTING.md +455 -0
  39. mcp_proxy_adapter/examples/basic_framework/configs/http_auth.json +37 -0
  40. mcp_proxy_adapter/examples/basic_framework/configs/http_simple.json +23 -0
  41. mcp_proxy_adapter/examples/basic_framework/configs/https_auth.json +43 -0
  42. mcp_proxy_adapter/examples/basic_framework/configs/https_no_protocol_middleware.json +36 -0
  43. mcp_proxy_adapter/examples/basic_framework/configs/https_simple.json +29 -0
  44. mcp_proxy_adapter/examples/basic_framework/configs/mtls_no_protocol_middleware.json +34 -0
  45. mcp_proxy_adapter/examples/basic_framework/configs/mtls_no_roles.json +39 -0
  46. mcp_proxy_adapter/examples/basic_framework/configs/mtls_simple.json +35 -0
  47. mcp_proxy_adapter/examples/basic_framework/configs/mtls_with_roles.json +45 -0
  48. mcp_proxy_adapter/examples/basic_framework/main.py +63 -0
  49. mcp_proxy_adapter/examples/basic_framework/roles.json +21 -0
  50. mcp_proxy_adapter/examples/cert_config.json +9 -0
  51. mcp_proxy_adapter/examples/certs/admin.crt +32 -0
  52. mcp_proxy_adapter/examples/certs/admin.key +52 -0
  53. mcp_proxy_adapter/examples/certs/admin_cert.pem +21 -0
  54. mcp_proxy_adapter/examples/certs/admin_key.pem +28 -0
  55. mcp_proxy_adapter/examples/certs/ca_cert.pem +23 -0
  56. mcp_proxy_adapter/examples/certs/ca_cert.srl +1 -0
  57. mcp_proxy_adapter/examples/certs/ca_key.pem +28 -0
  58. mcp_proxy_adapter/examples/certs/cert_config.json +9 -0
  59. mcp_proxy_adapter/examples/certs/client.crt +32 -0
  60. mcp_proxy_adapter/examples/certs/client.key +52 -0
  61. mcp_proxy_adapter/examples/certs/client_admin.crt +32 -0
  62. mcp_proxy_adapter/examples/certs/client_admin.key +52 -0
  63. mcp_proxy_adapter/examples/certs/client_user.crt +32 -0
  64. mcp_proxy_adapter/examples/certs/client_user.key +52 -0
  65. mcp_proxy_adapter/examples/certs/guest_cert.pem +21 -0
  66. mcp_proxy_adapter/examples/certs/guest_key.pem +28 -0
  67. mcp_proxy_adapter/examples/certs/mcp_proxy_adapter_ca_ca.crt +23 -0
  68. mcp_proxy_adapter/examples/certs/proxy_cert.pem +21 -0
  69. mcp_proxy_adapter/examples/certs/proxy_key.pem +28 -0
  70. mcp_proxy_adapter/examples/certs/readonly.crt +32 -0
  71. mcp_proxy_adapter/examples/certs/readonly.key +52 -0
  72. mcp_proxy_adapter/examples/certs/readonly_cert.pem +21 -0
  73. mcp_proxy_adapter/examples/certs/readonly_key.pem +28 -0
  74. mcp_proxy_adapter/examples/certs/server.crt +32 -0
  75. mcp_proxy_adapter/examples/certs/server.key +52 -0
  76. mcp_proxy_adapter/examples/certs/server_cert.pem +32 -0
  77. mcp_proxy_adapter/examples/certs/server_key.pem +52 -0
  78. mcp_proxy_adapter/examples/certs/test_ca_ca.crt +20 -0
  79. mcp_proxy_adapter/examples/certs/user.crt +32 -0
  80. mcp_proxy_adapter/examples/certs/user.key +52 -0
  81. mcp_proxy_adapter/examples/certs/user_cert.pem +21 -0
  82. mcp_proxy_adapter/examples/certs/user_key.pem +28 -0
  83. mcp_proxy_adapter/examples/client_configs/api_key_client.json +13 -0
  84. mcp_proxy_adapter/examples/client_configs/basic_auth_client.json +13 -0
  85. mcp_proxy_adapter/examples/client_configs/certificate_client.json +22 -0
  86. mcp_proxy_adapter/examples/client_configs/jwt_client.json +15 -0
  87. mcp_proxy_adapter/examples/client_configs/no_auth_client.json +9 -0
  88. mcp_proxy_adapter/examples/commands/__init__.py +1 -0
  89. mcp_proxy_adapter/examples/create_certificates_simple.py +307 -0
  90. mcp_proxy_adapter/examples/debug_request_state.py +144 -0
  91. mcp_proxy_adapter/examples/debug_role_chain.py +205 -0
  92. mcp_proxy_adapter/examples/demo_client.py +341 -0
  93. mcp_proxy_adapter/examples/full_application/commands/custom_echo_command.py +99 -0
  94. mcp_proxy_adapter/examples/full_application/commands/dynamic_calculator_command.py +106 -0
  95. mcp_proxy_adapter/examples/full_application/configs/http_auth.json +37 -0
  96. mcp_proxy_adapter/examples/full_application/configs/http_simple.json +23 -0
  97. mcp_proxy_adapter/examples/full_application/configs/https_auth.json +39 -0
  98. mcp_proxy_adapter/examples/full_application/configs/https_simple.json +25 -0
  99. mcp_proxy_adapter/examples/full_application/configs/mtls_no_roles.json +39 -0
  100. mcp_proxy_adapter/examples/full_application/configs/mtls_with_roles.json +45 -0
  101. mcp_proxy_adapter/examples/full_application/hooks/application_hooks.py +97 -0
  102. mcp_proxy_adapter/examples/full_application/hooks/builtin_command_hooks.py +95 -0
  103. mcp_proxy_adapter/examples/full_application/main.py +138 -0
  104. mcp_proxy_adapter/examples/full_application/roles.json +21 -0
  105. mcp_proxy_adapter/examples/generate_all_certificates.py +429 -0
  106. mcp_proxy_adapter/examples/generate_certificates.py +121 -0
  107. mcp_proxy_adapter/examples/keys/ca_key.pem +28 -0
  108. mcp_proxy_adapter/examples/keys/mcp_proxy_adapter_ca_ca.key +28 -0
  109. mcp_proxy_adapter/examples/keys/test_ca_ca.key +28 -0
  110. mcp_proxy_adapter/examples/logs/mcp_proxy_adapter.log +220 -0
  111. mcp_proxy_adapter/examples/logs/mcp_proxy_adapter.log.1 +1 -0
  112. mcp_proxy_adapter/examples/logs/mcp_proxy_adapter.log.2 +1 -0
  113. mcp_proxy_adapter/examples/logs/mcp_proxy_adapter.log.3 +1 -0
  114. mcp_proxy_adapter/examples/logs/mcp_proxy_adapter.log.4 +1 -0
  115. mcp_proxy_adapter/examples/logs/mcp_proxy_adapter.log.5 +1 -0
  116. mcp_proxy_adapter/examples/logs/mcp_proxy_adapter_access.log +220 -0
  117. mcp_proxy_adapter/examples/logs/mcp_proxy_adapter_access.log.1 +1 -0
  118. mcp_proxy_adapter/examples/logs/mcp_proxy_adapter_access.log.2 +1 -0
  119. mcp_proxy_adapter/examples/logs/mcp_proxy_adapter_access.log.3 +1 -0
  120. mcp_proxy_adapter/examples/logs/mcp_proxy_adapter_access.log.4 +1 -0
  121. mcp_proxy_adapter/examples/logs/mcp_proxy_adapter_access.log.5 +1 -0
  122. mcp_proxy_adapter/examples/logs/mcp_proxy_adapter_error.log +2 -0
  123. mcp_proxy_adapter/examples/logs/mcp_proxy_adapter_error.log.1 +1 -0
  124. mcp_proxy_adapter/examples/logs/mcp_proxy_adapter_error.log.2 +1 -0
  125. mcp_proxy_adapter/examples/logs/mcp_proxy_adapter_error.log.3 +1 -0
  126. mcp_proxy_adapter/examples/logs/mcp_proxy_adapter_error.log.4 +1 -0
  127. mcp_proxy_adapter/examples/logs/mcp_proxy_adapter_error.log.5 +1 -0
  128. mcp_proxy_adapter/examples/proxy_registration_example.py +401 -0
  129. mcp_proxy_adapter/examples/roles.json +38 -0
  130. mcp_proxy_adapter/examples/run_example.py +81 -0
  131. mcp_proxy_adapter/examples/run_security_tests.py +326 -0
  132. mcp_proxy_adapter/examples/run_security_tests_fixed.py +300 -0
  133. mcp_proxy_adapter/examples/security_test_client.py +743 -0
  134. mcp_proxy_adapter/examples/server_configs/config_basic_http.json +204 -0
  135. mcp_proxy_adapter/examples/server_configs/config_http_token.json +238 -0
  136. mcp_proxy_adapter/examples/server_configs/config_https.json +215 -0
  137. mcp_proxy_adapter/examples/server_configs/config_https_token.json +231 -0
  138. mcp_proxy_adapter/examples/server_configs/config_mtls.json +215 -0
  139. mcp_proxy_adapter/examples/server_configs/config_proxy_registration.json +250 -0
  140. mcp_proxy_adapter/examples/server_configs/config_simple.json +46 -0
  141. mcp_proxy_adapter/examples/server_configs/roles.json +38 -0
  142. mcp_proxy_adapter/examples/test_config_generator.py +110 -0
  143. mcp_proxy_adapter/examples/test_examples.py +344 -0
  144. mcp_proxy_adapter/examples/universal_client.py +628 -0
  145. mcp_proxy_adapter/main.py +21 -10
  146. mcp_proxy_adapter/utils/config_generator.py +727 -0
  147. mcp_proxy_adapter/version.py +5 -2
  148. mcp_proxy_adapter-6.1.1.dist-info/METADATA +205 -0
  149. mcp_proxy_adapter-6.1.1.dist-info/RECORD +197 -0
  150. mcp_proxy_adapter-6.1.1.dist-info/entry_points.txt +2 -0
  151. {mcp_proxy_adapter-6.0.0.dist-info → mcp_proxy_adapter-6.1.1.dist-info}/licenses/LICENSE +2 -2
  152. mcp_proxy_adapter/api/middleware/auth.py +0 -146
  153. mcp_proxy_adapter/api/middleware/auth_adapter.py +0 -235
  154. mcp_proxy_adapter/api/middleware/mtls_adapter.py +0 -305
  155. mcp_proxy_adapter/api/middleware/mtls_middleware.py +0 -296
  156. mcp_proxy_adapter/api/middleware/rate_limit.py +0 -152
  157. mcp_proxy_adapter/api/middleware/rate_limit_adapter.py +0 -241
  158. mcp_proxy_adapter/api/middleware/roles_adapter.py +0 -365
  159. mcp_proxy_adapter/api/middleware/roles_middleware.py +0 -381
  160. mcp_proxy_adapter/api/middleware/security.py +0 -376
  161. mcp_proxy_adapter/api/middleware/token_auth_middleware.py +0 -261
  162. mcp_proxy_adapter/examples/__init__.py +0 -7
  163. mcp_proxy_adapter/examples/basic_server/README.md +0 -60
  164. mcp_proxy_adapter/examples/basic_server/__init__.py +0 -7
  165. mcp_proxy_adapter/examples/basic_server/basic_custom_settings.json +0 -39
  166. mcp_proxy_adapter/examples/basic_server/config.json +0 -70
  167. mcp_proxy_adapter/examples/basic_server/config_all_protocols.json +0 -54
  168. mcp_proxy_adapter/examples/basic_server/config_http.json +0 -70
  169. mcp_proxy_adapter/examples/basic_server/config_http_only.json +0 -52
  170. mcp_proxy_adapter/examples/basic_server/config_https.json +0 -58
  171. mcp_proxy_adapter/examples/basic_server/config_mtls.json +0 -58
  172. mcp_proxy_adapter/examples/basic_server/config_ssl.json +0 -46
  173. mcp_proxy_adapter/examples/basic_server/custom_settings_example.py +0 -238
  174. mcp_proxy_adapter/examples/basic_server/server.py +0 -114
  175. mcp_proxy_adapter/examples/custom_commands/README.md +0 -127
  176. mcp_proxy_adapter/examples/custom_commands/__init__.py +0 -27
  177. mcp_proxy_adapter/examples/custom_commands/advanced_hooks.py +0 -566
  178. mcp_proxy_adapter/examples/custom_commands/auto_commands/__init__.py +0 -6
  179. mcp_proxy_adapter/examples/custom_commands/auto_commands/auto_echo_command.py +0 -103
  180. mcp_proxy_adapter/examples/custom_commands/auto_commands/auto_info_command.py +0 -111
  181. mcp_proxy_adapter/examples/custom_commands/auto_commands/test_command.py +0 -105
  182. mcp_proxy_adapter/examples/custom_commands/catalog/commands/test_command.py +0 -129
  183. mcp_proxy_adapter/examples/custom_commands/config.json +0 -118
  184. mcp_proxy_adapter/examples/custom_commands/config_all_protocols.json +0 -46
  185. mcp_proxy_adapter/examples/custom_commands/config_https_only.json +0 -46
  186. mcp_proxy_adapter/examples/custom_commands/config_https_transport.json +0 -33
  187. mcp_proxy_adapter/examples/custom_commands/config_mtls_only.json +0 -46
  188. mcp_proxy_adapter/examples/custom_commands/config_mtls_transport.json +0 -33
  189. mcp_proxy_adapter/examples/custom_commands/config_single_transport.json +0 -33
  190. mcp_proxy_adapter/examples/custom_commands/custom_health_command.py +0 -169
  191. mcp_proxy_adapter/examples/custom_commands/custom_help_command.py +0 -215
  192. mcp_proxy_adapter/examples/custom_commands/custom_openapi_generator.py +0 -76
  193. mcp_proxy_adapter/examples/custom_commands/custom_settings.json +0 -96
  194. mcp_proxy_adapter/examples/custom_commands/custom_settings_manager.py +0 -241
  195. mcp_proxy_adapter/examples/custom_commands/data_transform_command.py +0 -135
  196. mcp_proxy_adapter/examples/custom_commands/echo_command.py +0 -122
  197. mcp_proxy_adapter/examples/custom_commands/full_help_response.json +0 -1
  198. mcp_proxy_adapter/examples/custom_commands/generated_openapi.json +0 -629
  199. mcp_proxy_adapter/examples/custom_commands/get_openapi.py +0 -103
  200. mcp_proxy_adapter/examples/custom_commands/hooks.py +0 -230
  201. mcp_proxy_adapter/examples/custom_commands/intercept_command.py +0 -123
  202. mcp_proxy_adapter/examples/custom_commands/loadable_commands/test_ignored.py +0 -129
  203. mcp_proxy_adapter/examples/custom_commands/manual_echo_command.py +0 -103
  204. mcp_proxy_adapter/examples/custom_commands/proxy_connection_manager.py +0 -278
  205. mcp_proxy_adapter/examples/custom_commands/server.py +0 -252
  206. mcp_proxy_adapter/examples/custom_commands/simple_openapi_server.py +0 -75
  207. mcp_proxy_adapter/examples/custom_commands/start_server_with_proxy_manager.py +0 -299
  208. mcp_proxy_adapter/examples/custom_commands/start_server_with_registration.py +0 -278
  209. mcp_proxy_adapter/examples/custom_commands/test_hooks.py +0 -176
  210. mcp_proxy_adapter/examples/custom_commands/test_openapi.py +0 -27
  211. mcp_proxy_adapter/examples/custom_commands/test_registry.py +0 -23
  212. mcp_proxy_adapter/examples/custom_commands/test_simple.py +0 -19
  213. mcp_proxy_adapter/examples/custom_project_example/README.md +0 -103
  214. mcp_proxy_adapter/examples/custom_project_example/README_EN.md +0 -103
  215. mcp_proxy_adapter/examples/deployment/README.md +0 -49
  216. mcp_proxy_adapter/examples/deployment/__init__.py +0 -7
  217. mcp_proxy_adapter/examples/deployment/config.development.json +0 -8
  218. mcp_proxy_adapter/examples/deployment/config.json +0 -29
  219. mcp_proxy_adapter/examples/deployment/config.production.json +0 -12
  220. mcp_proxy_adapter/examples/deployment/config.staging.json +0 -11
  221. mcp_proxy_adapter/examples/deployment/docker-compose.yml +0 -31
  222. mcp_proxy_adapter/examples/deployment/run.sh +0 -43
  223. mcp_proxy_adapter/examples/deployment/run_docker.sh +0 -84
  224. mcp_proxy_adapter/examples/simple_custom_commands/README.md +0 -149
  225. mcp_proxy_adapter/examples/simple_custom_commands/README_EN.md +0 -149
  226. mcp_proxy_adapter/schemas/base_schema.json +0 -114
  227. mcp_proxy_adapter/schemas/openapi_schema.json +0 -314
  228. mcp_proxy_adapter/schemas/roles_schema.json +0 -162
  229. mcp_proxy_adapter/tests/__init__.py +0 -0
  230. mcp_proxy_adapter/tests/api/__init__.py +0 -3
  231. mcp_proxy_adapter/tests/api/test_cmd_endpoint.py +0 -115
  232. mcp_proxy_adapter/tests/api/test_custom_openapi.py +0 -617
  233. mcp_proxy_adapter/tests/api/test_handlers.py +0 -522
  234. mcp_proxy_adapter/tests/api/test_middleware.py +0 -340
  235. mcp_proxy_adapter/tests/api/test_schemas.py +0 -546
  236. mcp_proxy_adapter/tests/api/test_tool_integration.py +0 -531
  237. mcp_proxy_adapter/tests/commands/__init__.py +0 -3
  238. mcp_proxy_adapter/tests/commands/test_config_command.py +0 -211
  239. mcp_proxy_adapter/tests/commands/test_echo_command.py +0 -127
  240. mcp_proxy_adapter/tests/commands/test_help_command.py +0 -136
  241. mcp_proxy_adapter/tests/conftest.py +0 -131
  242. mcp_proxy_adapter/tests/functional/__init__.py +0 -3
  243. mcp_proxy_adapter/tests/functional/test_api.py +0 -253
  244. mcp_proxy_adapter/tests/integration/__init__.py +0 -3
  245. mcp_proxy_adapter/tests/integration/test_cmd_integration.py +0 -129
  246. mcp_proxy_adapter/tests/integration/test_integration.py +0 -255
  247. mcp_proxy_adapter/tests/performance/__init__.py +0 -3
  248. mcp_proxy_adapter/tests/performance/test_performance.py +0 -189
  249. mcp_proxy_adapter/tests/stubs/__init__.py +0 -10
  250. mcp_proxy_adapter/tests/stubs/echo_command.py +0 -104
  251. mcp_proxy_adapter/tests/test_api_endpoints.py +0 -271
  252. mcp_proxy_adapter/tests/test_api_handlers.py +0 -289
  253. mcp_proxy_adapter/tests/test_base_command.py +0 -123
  254. mcp_proxy_adapter/tests/test_batch_requests.py +0 -117
  255. mcp_proxy_adapter/tests/test_command_registry.py +0 -281
  256. mcp_proxy_adapter/tests/test_config.py +0 -127
  257. mcp_proxy_adapter/tests/test_utils.py +0 -65
  258. mcp_proxy_adapter/tests/unit/__init__.py +0 -3
  259. mcp_proxy_adapter/tests/unit/test_base_command.py +0 -436
  260. mcp_proxy_adapter/tests/unit/test_config.py +0 -270
  261. mcp_proxy_adapter-6.0.0.dist-info/METADATA +0 -201
  262. mcp_proxy_adapter-6.0.0.dist-info/RECORD +0 -179
  263. {mcp_proxy_adapter-6.0.0.dist-info → mcp_proxy_adapter-6.1.1.dist-info}/WHEEL +0 -0
  264. {mcp_proxy_adapter-6.0.0.dist-info → mcp_proxy_adapter-6.1.1.dist-info}/top_level.txt +0 -0
@@ -1,299 +0,0 @@
1
- #!/usr/bin/env python3
2
- """
3
- Server startup script with Proxy Connection Manager.
4
-
5
- This script starts the server and manages proxy connection with regular
6
- health checks and automatic re-registration.
7
- """
8
-
9
- import asyncio
10
- import time
11
- import sys
12
- import os
13
- import uvicorn
14
- import threading
15
- import signal
16
- from pathlib import Path
17
-
18
- # Add parent directories to path
19
- sys.path.append(os.path.join(os.path.dirname(__file__), '..', '..', '..'))
20
-
21
- from mcp_proxy_adapter import create_app
22
- from mcp_proxy_adapter.core.logging import get_logger, setup_logging
23
- from mcp_proxy_adapter.core.settings import (
24
- Settings,
25
- get_server_host,
26
- get_server_port,
27
- get_server_debug,
28
- get_setting,
29
- get_custom_setting_value
30
- )
31
- from mcp_proxy_adapter.core.ssl_utils import SSLUtils
32
- from mcp_proxy_adapter.core.transport_manager import transport_manager
33
- from custom_settings_manager import CustomSettingsManager, get_app_name, is_feature_enabled
34
-
35
- # Import custom commands and hooks
36
- from custom_help_command import CustomHelpCommand
37
- from custom_health_command import CustomHealthCommand
38
- from data_transform_command import DataTransformCommand
39
- from intercept_command import InterceptCommand
40
- from advanced_hooks import register_advanced_hooks
41
-
42
- # Import auto-registered commands
43
- from auto_commands.auto_echo_command import AutoEchoCommand
44
- from auto_commands.auto_info_command import AutoInfoCommand
45
-
46
- # Import manual registration example
47
- from manual_echo_command import ManualEchoCommand
48
-
49
- # Import echo command
50
- from echo_command import EchoCommand
51
-
52
- # Import custom OpenAPI generator
53
- from custom_openapi_generator import custom_openapi_generator
54
-
55
- # Import command registry for manual registration
56
- from mcp_proxy_adapter.commands.command_registry import registry
57
- from mcp_proxy_adapter.config import config
58
- from mcp_proxy_adapter.commands.hooks import register_custom_commands_hook
59
-
60
- # Import proxy connection manager
61
- from proxy_connection_manager import start_proxy_manager, stop_proxy_manager, get_proxy_manager_status
62
-
63
-
64
- def custom_commands_hook(registry):
65
- """Hook function for registering custom commands."""
66
- logger = get_logger("custom_commands")
67
- logger.info("Registering custom commands via hook...")
68
-
69
- # Get custom commands configuration from custom settings
70
- custom_commands_config = get_custom_setting_value("custom_commands", {})
71
-
72
- # Register echo command (only if not already registered)
73
- if not registry.command_exists("echo"):
74
- registry.register_custom(EchoCommand)
75
- logger.info("Registered: echo command")
76
- else:
77
- logger.debug("Command 'echo' is already registered, skipping")
78
-
79
- # Register custom help command (will override built-in)
80
- if custom_commands_config.get("help", {}).get("enabled", True):
81
- registry.register_custom(CustomHelpCommand)
82
- logger.info("Registered: custom help command")
83
-
84
- # Register custom health command (will override built-in)
85
- if custom_commands_config.get("health", {}).get("enabled", True):
86
- registry.register_custom(CustomHealthCommand)
87
- logger.info("Registered: custom health command")
88
-
89
- # Register advanced demonstration commands
90
- if custom_commands_config.get("data_transform", {}).get("enabled", True):
91
- registry.register_custom(DataTransformCommand)
92
- logger.info("Registered: data_transform command")
93
-
94
- if custom_commands_config.get("intercept", {}).get("enabled", True):
95
- registry.register_custom(InterceptCommand)
96
- logger.info("Registered: intercept command")
97
-
98
-
99
- def setup_hooks():
100
- """Setup hooks for command processing."""
101
- logger = get_logger("custom_commands")
102
- logger.info("Setting up hooks...")
103
-
104
- # Register custom commands hook
105
- register_custom_commands_hook(custom_commands_hook)
106
-
107
- # Note: Advanced hooks are not compatible with current API
108
- # They will be registered automatically by the command registry
109
- logger.info("Basic hooks setup completed")
110
-
111
-
112
- async def initialize_commands():
113
- """
114
- Initialize commands using the unified system initialization logic.
115
- This function is used both at startup and during reload.
116
-
117
- Returns:
118
- Number of commands discovered.
119
- """
120
- # Use the unified reload method from registry
121
- result = await registry.reload_system()
122
- return result["total_commands"]
123
-
124
-
125
- def start_server():
126
- """Start the server in a separate thread."""
127
- # Initialize settings
128
- settings = Settings()
129
- server_settings = settings.get_server_settings()
130
- logging_settings = settings.get_logging_settings()
131
- commands_settings = settings.get_commands_settings()
132
-
133
- # Setup logging - pass only the level, not the entire dict
134
- setup_logging(logging_settings.get('level', 'INFO'))
135
- logger = get_logger("server_startup")
136
-
137
- # Load transport configuration
138
- if not transport_manager.load_config(config.config_data):
139
- logger.error("Failed to load transport configuration")
140
- return
141
-
142
- # Validate transport configuration
143
- if not transport_manager.validate_config():
144
- logger.error("Transport configuration validation failed")
145
- return
146
-
147
- # Print server header and description
148
- print("=" * 80)
149
- print("🔧 ADVANCED MCP PROXY ADAPTER SERVER WITH PROXY MANAGER")
150
- print("=" * 80)
151
- print("📋 Description:")
152
- print(f" {get_app_name()} - Advanced server with proxy connection management")
153
- print()
154
-
155
- # Get transport info
156
- transport_info = transport_manager.get_transport_info()
157
-
158
- print("⚙️ Configuration:")
159
- print(f" • Server: {server_settings['host']}:{transport_manager.get_port()}")
160
- print(f" • Transport: {transport_info['type']}")
161
- print(f" • Debug: {server_settings['debug']}")
162
- print(f" • Log Level: {logging_settings.get('level', 'INFO')}")
163
- print(f" • Log Directory: {logging_settings.get('log_dir', './logs')}")
164
- print(f" • Auto Discovery: {commands_settings['auto_discovery']}")
165
- print(f" • SSL Enabled: {transport_info['ssl_enabled']}")
166
- if transport_info['ssl_enabled']:
167
- ssl_config = transport_info['ssl_config']
168
- print(f" • SSL Cert: {ssl_config.get('cert_file', 'Not specified')}")
169
- print(f" • Client Verification: {ssl_config.get('verify_client', False)}")
170
- print()
171
- print("🔧 Available Commands:")
172
- print(" • help - Custom help command (overrides built-in)")
173
- print(" • health - Custom health command (overrides built-in)")
174
- print(" • config - Built-in config command")
175
- print(" • reload - Built-in reload command")
176
- print(" • settings - Built-in settings command")
177
- print(" • load - Built-in load command")
178
- print(" • unload - Built-in unload command")
179
- print(" • plugins - Built-in plugins command")
180
- print(" • echo - Custom echo command")
181
- print(" • data_transform - Data transformation command")
182
- print(" • intercept - Command interception example")
183
- print(" • manual_echo - Manually registered echo command")
184
- print(" • test - Remote command (loaded from plugin server)")
185
- print()
186
- print("🎯 Features:")
187
- print(" • Advanced JSON-RPC API")
188
- print(" • Custom commands with hooks")
189
- print(" • Data transformation hooks")
190
- print(" • Command interception hooks")
191
- print(" • Auto-registration and manual registration")
192
- print(" • Custom OpenAPI schema generation")
193
- print(" • Configuration-driven settings")
194
- print(" • Custom settings management")
195
- print(" • 🔄 Proxy Connection Manager with health monitoring")
196
- print(" • 🔄 Automatic re-registration on proxy failure")
197
- print("=" * 80)
198
- print()
199
-
200
- logger.info("Starting Advanced Custom Commands MCP Proxy Adapter Server with Proxy Manager...")
201
- logger.info(f"Server configuration: {server_settings}")
202
- logger.info(f"Logging configuration: {logging_settings}")
203
- logger.info(f"Commands configuration: {commands_settings}")
204
- logger.info(f"Transport configuration: {transport_info}")
205
-
206
- # Setup hooks for command processing
207
- setup_hooks()
208
-
209
- # Initialize commands
210
- asyncio.run(initialize_commands())
211
-
212
- # Create application with settings from configuration
213
- app = create_app(
214
- title=get_app_name(),
215
- description="Advanced MCP Proxy Adapter server with proxy connection management, demonstrating hook capabilities including data transformation, command interception, conditional processing, and smart interception hooks. Features custom commands with enhanced functionality, comprehensive settings management, and robust proxy connection handling.",
216
- version="2.2.0"
217
- )
218
-
219
- # Get uvicorn configuration from transport manager
220
- uvicorn_config = transport_manager.get_uvicorn_config()
221
- uvicorn_config["host"] = server_settings['host']
222
- uvicorn_config["log_level"] = server_settings['log_level'].lower()
223
-
224
- logger.info(f"Starting server with uvicorn config: {uvicorn_config}")
225
-
226
- # Run the server with configuration settings
227
- uvicorn.run(
228
- app,
229
- **uvicorn_config
230
- )
231
-
232
-
233
- async def start_proxy_manager_after_server():
234
- """
235
- Start proxy manager after server is fully started and listening.
236
- """
237
- logger = get_logger("proxy_manager_startup")
238
-
239
- # Wait a bit for server to fully start
240
- await asyncio.sleep(5)
241
-
242
- logger.info("🚀 Starting Proxy Connection Manager after server startup")
243
-
244
- # Start proxy manager
245
- await start_proxy_manager()
246
-
247
- logger.info("✅ Proxy Connection Manager started successfully")
248
-
249
-
250
- def signal_handler(signum, frame):
251
- """Handle shutdown signals."""
252
- print(f"\n🛑 Received signal {signum}, shutting down gracefully...")
253
-
254
- # Stop proxy manager
255
- asyncio.run(stop_proxy_manager())
256
-
257
- print("✅ Graceful shutdown completed")
258
- sys.exit(0)
259
-
260
-
261
- def main():
262
- """Main function to start server and proxy manager."""
263
- # Setup signal handlers for graceful shutdown
264
- signal.signal(signal.SIGINT, signal_handler)
265
- signal.signal(signal.SIGTERM, signal_handler)
266
-
267
- # Start server in a separate thread
268
- server_thread = threading.Thread(target=start_server, daemon=True)
269
- server_thread.start()
270
-
271
- # Wait for server to start
272
- time.sleep(8)
273
-
274
- # Start proxy manager after server is ready
275
- asyncio.run(start_proxy_manager_after_server())
276
-
277
- # Keep main thread alive and monitor status
278
- try:
279
- while True:
280
- # Get proxy manager status
281
- status = get_proxy_manager_status()
282
-
283
- if status["is_running"]:
284
- time_since = status.get("time_since_registration", 0)
285
- if time_since is not None:
286
- print(f"📊 Proxy Status: Registered {time_since:.0f}s ago, "
287
- f"attempts: {status['registration_count']}, "
288
- f"failed: {status['failed_attempts']}")
289
-
290
- time.sleep(30) # Print status every 30 seconds
291
-
292
- except KeyboardInterrupt:
293
- print("\n🛑 Server shutdown requested")
294
- asyncio.run(stop_proxy_manager())
295
- sys.exit(0)
296
-
297
-
298
- if __name__ == "__main__":
299
- main()
@@ -1,278 +0,0 @@
1
- #!/usr/bin/env python3
2
- """
3
- Server startup script with proper registration sequence.
4
- First starts the server, then registers with proxy after server is ready.
5
- """
6
-
7
- import asyncio
8
- import time
9
- import sys
10
- import os
11
- import uvicorn
12
- import threading
13
- from pathlib import Path
14
-
15
- # Add parent directories to path
16
- sys.path.append(os.path.join(os.path.dirname(__file__), '..', '..', '..'))
17
-
18
- from mcp_proxy_adapter import create_app
19
- from mcp_proxy_adapter.core.logging import get_logger, setup_logging
20
- from mcp_proxy_adapter.core.settings import (
21
- Settings,
22
- get_server_host,
23
- get_server_port,
24
- get_server_debug,
25
- get_setting,
26
- get_custom_setting_value
27
- )
28
- from mcp_proxy_adapter.core.ssl_utils import SSLUtils
29
- from mcp_proxy_adapter.core.transport_manager import transport_manager
30
- from mcp_proxy_adapter.core.proxy_registration import register_with_proxy
31
- from custom_settings_manager import CustomSettingsManager, get_app_name, is_feature_enabled
32
-
33
- # Import custom commands and hooks
34
- from custom_help_command import CustomHelpCommand
35
- from custom_health_command import CustomHealthCommand
36
- from data_transform_command import DataTransformCommand
37
- from intercept_command import InterceptCommand
38
- from advanced_hooks import register_advanced_hooks
39
-
40
- # Import auto-registered commands
41
- from auto_commands.auto_echo_command import AutoEchoCommand
42
- from auto_commands.auto_info_command import AutoInfoCommand
43
-
44
- # Import manual registration example
45
- from manual_echo_command import ManualEchoCommand
46
-
47
- # Import echo command
48
- from echo_command import EchoCommand
49
-
50
- # Import custom OpenAPI generator
51
- from custom_openapi_generator import custom_openapi_generator
52
-
53
- # Import command registry for manual registration
54
- from mcp_proxy_adapter.commands.command_registry import registry
55
- from mcp_proxy_adapter.config import config
56
- from mcp_proxy_adapter.commands.hooks import register_custom_commands_hook
57
-
58
-
59
- def custom_commands_hook(registry):
60
- """Hook function for registering custom commands."""
61
- logger = get_logger("custom_commands")
62
- logger.info("Registering custom commands via hook...")
63
-
64
- # Get custom commands configuration from custom settings
65
- custom_commands_config = get_custom_setting_value("custom_commands", {})
66
-
67
- # Register echo command (only if not already registered)
68
- if not registry.command_exists("echo"):
69
- registry.register_custom(EchoCommand)
70
- logger.info("Registered: echo command")
71
- else:
72
- logger.debug("Command 'echo' is already registered, skipping")
73
-
74
- # Register custom help command (will override built-in)
75
- if custom_commands_config.get("help", {}).get("enabled", True):
76
- registry.register_custom(CustomHelpCommand)
77
- logger.info("Registered: custom help command")
78
-
79
- # Register custom health command (will override built-in)
80
- if custom_commands_config.get("health", {}).get("enabled", True):
81
- registry.register_custom(CustomHealthCommand)
82
- logger.info("Registered: custom health command")
83
-
84
- # Register advanced demonstration commands
85
- if custom_commands_config.get("data_transform", {}).get("enabled", True):
86
- registry.register_custom(DataTransformCommand)
87
- logger.info("Registered: data_transform command")
88
-
89
- if custom_commands_config.get("intercept", {}).get("enabled", True):
90
- registry.register_custom(InterceptCommand)
91
- logger.info("Registered: intercept command")
92
-
93
-
94
- def setup_hooks():
95
- """Setup hooks for command processing."""
96
- logger = get_logger("custom_commands")
97
- logger.info("Setting up hooks...")
98
-
99
- # Register custom commands hook
100
- register_custom_commands_hook(custom_commands_hook)
101
-
102
- # Note: Advanced hooks are not compatible with current API
103
- # They will be registered automatically by the command registry
104
- logger.info("Basic hooks setup completed")
105
-
106
-
107
- async def initialize_commands():
108
- """
109
- Initialize commands using the unified system initialization logic.
110
- This function is used both at startup and during reload.
111
-
112
- Returns:
113
- Number of commands discovered.
114
- """
115
- # Use the unified reload method from registry
116
- result = await registry.reload_system()
117
- return result["total_commands"]
118
-
119
-
120
- async def register_with_proxy_after_startup():
121
- """
122
- Register with proxy after server is fully started and listening.
123
- """
124
- logger = get_logger("proxy_registration")
125
-
126
- # Wait a bit for server to fully start
127
- await asyncio.sleep(3)
128
-
129
- # Get server configuration
130
- server_config = config.get("server", {})
131
- server_host = server_config.get("host", "0.0.0.0")
132
- server_port = server_config.get("port", 8000)
133
-
134
- # Use localhost for external access if host is 0.0.0.0
135
- if server_host == "0.0.0.0":
136
- server_host = "localhost"
137
-
138
- server_url = f"http://{server_host}:{server_port}"
139
-
140
- logger.info(f"Attempting to register server with proxy at {server_url}")
141
-
142
- # Attempt registration
143
- registration_success = await register_with_proxy(server_url)
144
- if registration_success:
145
- logger.info("✅ Successfully registered with proxy after server startup")
146
- else:
147
- logger.warning("⚠️ Failed to register with proxy after server startup")
148
-
149
-
150
- def start_server():
151
- """Start the server in a separate thread."""
152
- # Initialize settings
153
- settings = Settings()
154
- server_settings = settings.get_server_settings()
155
- logging_settings = settings.get_logging_settings()
156
- commands_settings = settings.get_commands_settings()
157
-
158
- # Setup logging - pass only the level, not the entire dict
159
- setup_logging(logging_settings.get('level', 'INFO'))
160
- logger = get_logger("server_startup")
161
-
162
- # Load transport configuration
163
- if not transport_manager.load_config(config.config_data):
164
- logger.error("Failed to load transport configuration")
165
- return
166
-
167
- # Validate transport configuration
168
- if not transport_manager.validate_config():
169
- logger.error("Transport configuration validation failed")
170
- return
171
-
172
- # Print server header and description
173
- print("=" * 80)
174
- print("🔧 ADVANCED MCP PROXY ADAPTER SERVER WITH HOOKS")
175
- print("=" * 80)
176
- print("📋 Description:")
177
- print(f" {get_app_name()} - Advanced server with custom settings management")
178
- print()
179
-
180
- # Get transport info
181
- transport_info = transport_manager.get_transport_info()
182
-
183
- print("⚙️ Configuration:")
184
- print(f" • Server: {server_settings['host']}:{transport_manager.get_port()}")
185
- print(f" • Transport: {transport_info['type']}")
186
- print(f" • Debug: {server_settings['debug']}")
187
- print(f" • Log Level: {logging_settings.get('level', 'INFO')}")
188
- print(f" • Log Directory: {logging_settings.get('log_dir', './logs')}")
189
- print(f" • Auto Discovery: {commands_settings['auto_discovery']}")
190
- print(f" • SSL Enabled: {transport_info['ssl_enabled']}")
191
- if transport_info['ssl_enabled']:
192
- ssl_config = transport_info['ssl_config']
193
- print(f" • SSL Cert: {ssl_config.get('cert_file', 'Not specified')}")
194
- print(f" • Client Verification: {ssl_config.get('verify_client', False)}")
195
- print()
196
- print("🔧 Available Commands:")
197
- print(" • help - Custom help command (overrides built-in)")
198
- print(" • health - Custom health command (overrides built-in)")
199
- print(" • config - Built-in config command")
200
- print(" • reload - Built-in reload command")
201
- print(" • settings - Built-in settings command")
202
- print(" • load - Built-in load command")
203
- print(" • unload - Built-in unload command")
204
- print(" • plugins - Built-in plugins command")
205
- print(" • echo - Custom echo command")
206
- print(" • data_transform - Data transformation command")
207
- print(" • intercept - Command interception example")
208
- print(" • manual_echo - Manually registered echo command")
209
- print(" • test - Remote command (loaded from plugin server)")
210
- print()
211
- print("🎯 Features:")
212
- print(" • Advanced JSON-RPC API")
213
- print(" • Custom commands with hooks")
214
- print(" • Data transformation hooks")
215
- print(" • Command interception hooks")
216
- print(" • Auto-registration and manual registration")
217
- print(" • Custom OpenAPI schema generation")
218
- print(" • Configuration-driven settings")
219
- print(" • Custom settings management")
220
- print("=" * 80)
221
- print()
222
-
223
- logger.info("Starting Advanced Custom Commands MCP Proxy Adapter Server with Hooks...")
224
- logger.info(f"Server configuration: {server_settings}")
225
- logger.info(f"Logging configuration: {logging_settings}")
226
- logger.info(f"Commands configuration: {commands_settings}")
227
- logger.info(f"Transport configuration: {transport_info}")
228
-
229
- # Setup hooks for command processing
230
- setup_hooks()
231
-
232
- # Initialize commands
233
- asyncio.run(initialize_commands())
234
-
235
- # Create application with settings from configuration
236
- app = create_app(
237
- title=get_app_name(),
238
- description="Advanced MCP Proxy Adapter server with custom settings management, demonstrating hook capabilities including data transformation, command interception, conditional processing, and smart interception hooks. Features custom commands with enhanced functionality and comprehensive settings management.",
239
- version="2.1.0"
240
- )
241
-
242
- # Get uvicorn configuration from transport manager
243
- uvicorn_config = transport_manager.get_uvicorn_config()
244
- uvicorn_config["host"] = server_settings['host']
245
- uvicorn_config["log_level"] = server_settings['log_level'].lower()
246
-
247
- logger.info(f"Starting server with uvicorn config: {uvicorn_config}")
248
-
249
- # Run the server with configuration settings
250
- uvicorn.run(
251
- app,
252
- **uvicorn_config
253
- )
254
-
255
-
256
- def main():
257
- """Main function to start server and register with proxy."""
258
- # Start server in a separate thread
259
- server_thread = threading.Thread(target=start_server, daemon=True)
260
- server_thread.start()
261
-
262
- # Wait for server to start
263
- time.sleep(5)
264
-
265
- # Register with proxy after server is ready
266
- asyncio.run(register_with_proxy_after_startup())
267
-
268
- # Keep main thread alive
269
- try:
270
- while True:
271
- time.sleep(1)
272
- except KeyboardInterrupt:
273
- print("\n🛑 Server shutdown requested")
274
- sys.exit(0)
275
-
276
-
277
- if __name__ == "__main__":
278
- main()