mcp-proxy-adapter-dev 8.11.16__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 (644) hide show
  1. mcp_proxy_adapter/__init__.py +73 -0
  2. mcp_proxy_adapter/__main__.py +13 -0
  3. mcp_proxy_adapter/api/__init__.py +38 -0
  4. mcp_proxy_adapter/api/app.py +64 -0
  5. mcp_proxy_adapter/api/command_session_service.py +455 -0
  6. mcp_proxy_adapter/api/core/__init__.py +19 -0
  7. mcp_proxy_adapter/api/core/app_factory.py +215 -0
  8. mcp_proxy_adapter/api/core/app_factory_certificates.py +159 -0
  9. mcp_proxy_adapter/api/core/app_factory_config.py +75 -0
  10. mcp_proxy_adapter/api/core/app_factory_routes.py +345 -0
  11. mcp_proxy_adapter/api/core/app_factory_validators.py +165 -0
  12. mcp_proxy_adapter/api/core/lifespan_manager/__init__.py +52 -0
  13. mcp_proxy_adapter/api/core/lifespan_manager/manager.py +354 -0
  14. mcp_proxy_adapter/api/core/lifespan_manager/queue_config.py +37 -0
  15. mcp_proxy_adapter/api/core/lifespan_manager/signal_registration.py +74 -0
  16. mcp_proxy_adapter/api/core/registration/__init__.py +24 -0
  17. mcp_proxy_adapter/api/core/registration/config_parsers.py +247 -0
  18. mcp_proxy_adapter/api/core/registration/context_builder.py +130 -0
  19. mcp_proxy_adapter/api/core/registration/helpers.py +36 -0
  20. mcp_proxy_adapter/api/core/registration/metadata_builders.py +117 -0
  21. mcp_proxy_adapter/api/core/registration/models.py +42 -0
  22. mcp_proxy_adapter/api/core/registration/resolvers.py +195 -0
  23. mcp_proxy_adapter/api/core/registration/url_builders.py +122 -0
  24. mcp_proxy_adapter/api/core/registration_context.py +30 -0
  25. mcp_proxy_adapter/api/core/registration_manager/__init__.py +31 -0
  26. mcp_proxy_adapter/api/core/registration_manager/helpers.py +307 -0
  27. mcp_proxy_adapter/api/core/registration_manager/manager.py +584 -0
  28. mcp_proxy_adapter/api/core/registration_manager/status.py +152 -0
  29. mcp_proxy_adapter/api/core/registration_tasks.py +387 -0
  30. mcp_proxy_adapter/api/core/ssl_context_factory.py +99 -0
  31. mcp_proxy_adapter/api/execute_async_contract.py +124 -0
  32. mcp_proxy_adapter/api/handlers/__init__.py +335 -0
  33. mcp_proxy_adapter/api/handlers/command_execution.py +709 -0
  34. mcp_proxy_adapter/api/handlers/health.py +157 -0
  35. mcp_proxy_adapter/api/handlers/jsonrpc.py +207 -0
  36. mcp_proxy_adapter/api/handlers/transfer_notify.py +313 -0
  37. mcp_proxy_adapter/api/handlers/transfer_sessions.py +287 -0
  38. mcp_proxy_adapter/api/handlers_async.py +233 -0
  39. mcp_proxy_adapter/api/health_provider.py +44 -0
  40. mcp_proxy_adapter/api/jsonrpc_job_lifecycle.py +165 -0
  41. mcp_proxy_adapter/api/jsonrpc_job_status.py +94 -0
  42. mcp_proxy_adapter/api/middleware/__init__.py +14 -0
  43. mcp_proxy_adapter/api/middleware/command_permission_middleware.py +73 -0
  44. mcp_proxy_adapter/api/middleware/request_logging.py +153 -0
  45. mcp_proxy_adapter/api/middleware/unified_security.py +367 -0
  46. mcp_proxy_adapter/api/openapi/__init__.py +18 -0
  47. mcp_proxy_adapter/api/openapi/command_integration.py +107 -0
  48. mcp_proxy_adapter/api/openapi/openapi_generator.py +138 -0
  49. mcp_proxy_adapter/api/openapi/openapi_registry.py +55 -0
  50. mcp_proxy_adapter/api/public_downloads.py +68 -0
  51. mcp_proxy_adapter/api/schemas.py +290 -0
  52. mcp_proxy_adapter/api/tool_integration.py +124 -0
  53. mcp_proxy_adapter/api/tools.py +244 -0
  54. mcp_proxy_adapter/api/transfer_session_service.py +329 -0
  55. mcp_proxy_adapter/api/ws_endpoint.py +653 -0
  56. mcp_proxy_adapter/api/ws_identity.py +111 -0
  57. mcp_proxy_adapter/cli/__init__.py +12 -0
  58. mcp_proxy_adapter/cli/commands/__init__.py +14 -0
  59. mcp_proxy_adapter/cli/commands/client.py +137 -0
  60. mcp_proxy_adapter/cli/commands/config_docs/__init__.py +23 -0
  61. mcp_proxy_adapter/cli/commands/config_docs/cli.py +63 -0
  62. mcp_proxy_adapter/cli/commands/config_docs/declared_settings.py +45 -0
  63. mcp_proxy_adapter/cli/commands/config_docs/render.py +58 -0
  64. mcp_proxy_adapter/cli/commands/config_docs/sections/__init__.py +61 -0
  65. mcp_proxy_adapter/cli/commands/config_docs/sections/_chunk.py +19 -0
  66. mcp_proxy_adapter/cli/commands/config_docs/sections/authentication.py +127 -0
  67. mcp_proxy_adapter/cli/commands/config_docs/sections/best_practices.py +166 -0
  68. mcp_proxy_adapter/cli/commands/config_docs/sections/common_patterns.py +154 -0
  69. mcp_proxy_adapter/cli/commands/config_docs/sections/overview.py +135 -0
  70. mcp_proxy_adapter/cli/commands/config_docs/sections/queue_manager.py +140 -0
  71. mcp_proxy_adapter/cli/commands/config_docs/sections/registration.py +212 -0
  72. mcp_proxy_adapter/cli/commands/config_docs/sections/server.py +193 -0
  73. mcp_proxy_adapter/cli/commands/config_docs/sections/troubleshooting.py +215 -0
  74. mcp_proxy_adapter/cli/commands/config_generate.py +95 -0
  75. mcp_proxy_adapter/cli/commands/config_generate_parts/__init__.py +1 -0
  76. mcp_proxy_adapter/cli/commands/config_generate_parts/arguments.py +44 -0
  77. mcp_proxy_adapter/cli/commands/config_generate_parts/arguments_core.py +141 -0
  78. mcp_proxy_adapter/cli/commands/config_generate_parts/arguments_queue.py +140 -0
  79. mcp_proxy_adapter/cli/commands/config_generate_parts/arguments_validation.py +142 -0
  80. mcp_proxy_adapter/cli/commands/config_generate_parts/generation.py +365 -0
  81. mcp_proxy_adapter/cli/commands/config_generate_parts/parsing.py +122 -0
  82. mcp_proxy_adapter/cli/commands/config_validate.py +154 -0
  83. mcp_proxy_adapter/cli/commands/info.py +297 -0
  84. mcp_proxy_adapter/cli/commands/server.py +361 -0
  85. mcp_proxy_adapter/cli/commands/sets.py +165 -0
  86. mcp_proxy_adapter/cli/commands/standalone_entry.py +25 -0
  87. mcp_proxy_adapter/cli/commands/testconfig.py +205 -0
  88. mcp_proxy_adapter/cli/examples/__init__.py +9 -0
  89. mcp_proxy_adapter/cli/main.py +75 -0
  90. mcp_proxy_adapter/cli/parser.py +244 -0
  91. mcp_proxy_adapter/cli/validators.py +389 -0
  92. mcp_proxy_adapter/client/jsonrpc_client/__init__.py +139 -0
  93. mcp_proxy_adapter/client/jsonrpc_client/client.py +257 -0
  94. mcp_proxy_adapter/client/jsonrpc_client/command_api.py +369 -0
  95. mcp_proxy_adapter/client/jsonrpc_client/command_api_bases/__init__.py +1 -0
  96. mcp_proxy_adapter/client/jsonrpc_client/command_api_bases/async_base.py +241 -0
  97. mcp_proxy_adapter/client/jsonrpc_client/command_api_bases/basic_base.py +150 -0
  98. mcp_proxy_adapter/client/jsonrpc_client/command_api_bases/catalog_base.py +178 -0
  99. mcp_proxy_adapter/client/jsonrpc_client/command_api_bases/constants.py +38 -0
  100. mcp_proxy_adapter/client/jsonrpc_client/command_api_bases/helpers.py +66 -0
  101. mcp_proxy_adapter/client/jsonrpc_client/command_api_bases/queue_base.py +137 -0
  102. mcp_proxy_adapter/client/jsonrpc_client/exceptions/__init__.py +70 -0
  103. mcp_proxy_adapter/client/jsonrpc_client/exceptions/base.py +102 -0
  104. mcp_proxy_adapter/client/jsonrpc_client/exceptions/classification.py +143 -0
  105. mcp_proxy_adapter/client/jsonrpc_client/exceptions/request_errors.py +169 -0
  106. mcp_proxy_adapter/client/jsonrpc_client/exceptions/schema_errors.py +90 -0
  107. mcp_proxy_adapter/client/jsonrpc_client/exceptions/transfer_errors.py +48 -0
  108. mcp_proxy_adapter/client/jsonrpc_client/exceptions/transport_errors.py +153 -0
  109. mcp_proxy_adapter/client/jsonrpc_client/execution_status_observer.py +66 -0
  110. mcp_proxy_adapter/client/jsonrpc_client/job_event_registry.py +322 -0
  111. mcp_proxy_adapter/client/jsonrpc_client/job_tracking_mixin.py +206 -0
  112. mcp_proxy_adapter/client/jsonrpc_client/job_tracking_types.py +135 -0
  113. mcp_proxy_adapter/client/jsonrpc_client/openapi_validator.py +127 -0
  114. mcp_proxy_adapter/client/jsonrpc_client/operation_state.py +221 -0
  115. mcp_proxy_adapter/client/jsonrpc_client/proxy_api.py +93 -0
  116. mcp_proxy_adapter/client/jsonrpc_client/proxy_api_bases/__init__.py +1 -0
  117. mcp_proxy_adapter/client/jsonrpc_client/proxy_api_bases/client_base.py +117 -0
  118. mcp_proxy_adapter/client/jsonrpc_client/proxy_api_bases/lifecycle_base.py +222 -0
  119. mcp_proxy_adapter/client/jsonrpc_client/proxy_api_bases/register_base.py +230 -0
  120. mcp_proxy_adapter/client/jsonrpc_client/proxy_api_bases/uuid_base.py +95 -0
  121. mcp_proxy_adapter/client/jsonrpc_client/queue_api.py +302 -0
  122. mcp_proxy_adapter/client/jsonrpc_client/queue_status.py +192 -0
  123. mcp_proxy_adapter/client/jsonrpc_client/schema_generator.py +143 -0
  124. mcp_proxy_adapter/client/jsonrpc_client/schema_generator_bases/__init__.py +1 -0
  125. mcp_proxy_adapter/client/jsonrpc_client/schema_generator_bases/models.py +45 -0
  126. mcp_proxy_adapter/client/jsonrpc_client/schema_generator_bases/parse_base.py +215 -0
  127. mcp_proxy_adapter/client/jsonrpc_client/schema_generator_bases/validate_base.py +181 -0
  128. mcp_proxy_adapter/client/jsonrpc_client/transfer_integrity.py +57 -0
  129. mcp_proxy_adapter/client/jsonrpc_client/transport/__init__.py +161 -0
  130. mcp_proxy_adapter/client/jsonrpc_client/transport/constants.py +30 -0
  131. mcp_proxy_adapter/client/jsonrpc_client/transport/helpers.py +118 -0
  132. mcp_proxy_adapter/client/jsonrpc_client/transport/http_base.py +325 -0
  133. mcp_proxy_adapter/client/jsonrpc_client/transport/rpc_base.py +311 -0
  134. mcp_proxy_adapter/client/jsonrpc_client/transport/tls_base.py +295 -0
  135. mcp_proxy_adapter/client/jsonrpc_client/transport/transfer_base.py +282 -0
  136. mcp_proxy_adapter/client/jsonrpc_client/ws_command_session.py +230 -0
  137. mcp_proxy_adapter/client/jsonrpc_client/ws_command_session_bases/__init__.py +1 -0
  138. mcp_proxy_adapter/client/jsonrpc_client/ws_command_session_bases/core_base.py +154 -0
  139. mcp_proxy_adapter/client/jsonrpc_client/ws_command_session_bases/helpers.py +72 -0
  140. mcp_proxy_adapter/client/jsonrpc_client/ws_command_session_bases/wait_base.py +279 -0
  141. mcp_proxy_adapter/client/jsonrpc_client/ws_job_status.py +337 -0
  142. mcp_proxy_adapter/client/jsonrpc_client/ws_job_status_parts/__init__.py +1 -0
  143. mcp_proxy_adapter/client/jsonrpc_client/ws_job_status_parts/channel.py +159 -0
  144. mcp_proxy_adapter/client/jsonrpc_client/ws_job_status_parts/command_channel.py +154 -0
  145. mcp_proxy_adapter/client/jsonrpc_client/ws_job_status_parts/helpers.py +76 -0
  146. mcp_proxy_adapter/client/proxy.py +124 -0
  147. mcp_proxy_adapter/commands/__init__.py +27 -0
  148. mcp_proxy_adapter/commands/base.py +998 -0
  149. mcp_proxy_adapter/commands/builtin_commands.py +186 -0
  150. mcp_proxy_adapter/commands/command_help_info.py +101 -0
  151. mcp_proxy_adapter/commands/command_registry/__init__.py +55 -0
  152. mcp_proxy_adapter/commands/command_registry/builtins_part.py +206 -0
  153. mcp_proxy_adapter/commands/command_registry/facade.py +310 -0
  154. mcp_proxy_adapter/commands/command_registry/lifecycle_part.py +232 -0
  155. mcp_proxy_adapter/commands/command_registry/loader.py +145 -0
  156. mcp_proxy_adapter/commands/command_registry/mutations_part.py +228 -0
  157. mcp_proxy_adapter/commands/command_registry/part_base.py +59 -0
  158. mcp_proxy_adapter/commands/command_registry/queries_part.py +304 -0
  159. mcp_proxy_adapter/commands/config_command.py +208 -0
  160. mcp_proxy_adapter/commands/dependency_container.py +35 -0
  161. mcp_proxy_adapter/commands/echo_command.py +97 -0
  162. mcp_proxy_adapter/commands/health_command.py +162 -0
  163. mcp_proxy_adapter/commands/help_command.py +296 -0
  164. mcp_proxy_adapter/commands/hooks.py +590 -0
  165. mcp_proxy_adapter/commands/job_metadata.py +26 -0
  166. mcp_proxy_adapter/commands/load_command.py +134 -0
  167. mcp_proxy_adapter/commands/nested_validation.py +185 -0
  168. mcp_proxy_adapter/commands/plugins_command.py +250 -0
  169. mcp_proxy_adapter/commands/proxy_registration_command.py +475 -0
  170. mcp_proxy_adapter/commands/queue/__init__.py +83 -0
  171. mcp_proxy_adapter/commands/queue/add_job_command.py +358 -0
  172. mcp_proxy_adapter/commands/queue/command_execution_diagnostics.py +100 -0
  173. mcp_proxy_adapter/commands/queue/delete_job_command.py +92 -0
  174. mcp_proxy_adapter/commands/queue/get_logs_command.py +90 -0
  175. mcp_proxy_adapter/commands/queue/get_status_command.py +105 -0
  176. mcp_proxy_adapter/commands/queue/health_command.py +44 -0
  177. mcp_proxy_adapter/commands/queue/job_domain_errors.py +117 -0
  178. mcp_proxy_adapter/commands/queue/job_params.py +163 -0
  179. mcp_proxy_adapter/commands/queue/jobs/__init__.py +41 -0
  180. mcp_proxy_adapter/commands/queue/jobs/basic_jobs.py +205 -0
  181. mcp_proxy_adapter/commands/queue/jobs/command_execution_job.py +198 -0
  182. mcp_proxy_adapter/commands/queue/jobs/command_restore_base.py +48 -0
  183. mcp_proxy_adapter/commands/queue/jobs/command_run_base.py +389 -0
  184. mcp_proxy_adapter/commands/queue/jobs/job_helpers.py +80 -0
  185. mcp_proxy_adapter/commands/queue/jobs/long_jobs.py +257 -0
  186. mcp_proxy_adapter/commands/queue/list_jobs_command.py +127 -0
  187. mcp_proxy_adapter/commands/queue/start_job_command.py +97 -0
  188. mcp_proxy_adapter/commands/queue/stop_job_command.py +107 -0
  189. mcp_proxy_adapter/commands/queue_commands.py +49 -0
  190. mcp_proxy_adapter/commands/registration_status_command.py +83 -0
  191. mcp_proxy_adapter/commands/reload_command.py +183 -0
  192. mcp_proxy_adapter/commands/result.py +201 -0
  193. mcp_proxy_adapter/commands/result_helpers.py +43 -0
  194. mcp_proxy_adapter/commands/role_test_command.py +119 -0
  195. mcp_proxy_adapter/commands/roles_management_command/__init__.py +58 -0
  196. mcp_proxy_adapter/commands/roles_management_command/actions_part.py +400 -0
  197. mcp_proxy_adapter/commands/roles_management_command/dispatch_part.py +239 -0
  198. mcp_proxy_adapter/commands/roles_management_command/facade.py +233 -0
  199. mcp_proxy_adapter/commands/roles_management_command/part_base.py +61 -0
  200. mcp_proxy_adapter/commands/roles_management_command/results.py +105 -0
  201. mcp_proxy_adapter/commands/roles_management_command/storage_part.py +181 -0
  202. mcp_proxy_adapter/commands/schema_helpers.py +45 -0
  203. mcp_proxy_adapter/commands/settings_command.py +205 -0
  204. mcp_proxy_adapter/commands/transfer_command_support.py +83 -0
  205. mcp_proxy_adapter/commands/transfer_download_begin_command.py +245 -0
  206. mcp_proxy_adapter/commands/transfer_download_status_command.py +121 -0
  207. mcp_proxy_adapter/commands/transfer_schema_support.py +96 -0
  208. mcp_proxy_adapter/commands/transfer_upload_begin_command.py +254 -0
  209. mcp_proxy_adapter/commands/transfer_upload_complete_command.py +161 -0
  210. mcp_proxy_adapter/commands/transfer_upload_status_command.py +122 -0
  211. mcp_proxy_adapter/commands/transport_management_command.py +144 -0
  212. mcp_proxy_adapter/commands/unload_command.py +109 -0
  213. mcp_proxy_adapter/config.py +30 -0
  214. mcp_proxy_adapter/core/__init__.py +8 -0
  215. mcp_proxy_adapter/core/app_factory/__init__.py +17 -0
  216. mcp_proxy_adapter/core/app_factory/app_creator.py +66 -0
  217. mcp_proxy_adapter/core/app_factory/config_loader.py +125 -0
  218. mcp_proxy_adapter/core/app_factory/factory.py +158 -0
  219. mcp_proxy_adapter/core/app_factory/server_runner.py +152 -0
  220. mcp_proxy_adapter/core/app_factory/ssl_config.py +194 -0
  221. mcp_proxy_adapter/core/app_factory/validators.py +57 -0
  222. mcp_proxy_adapter/core/async_context.py +28 -0
  223. mcp_proxy_adapter/core/auth/__init__.py +18 -0
  224. mcp_proxy_adapter/core/auth/certificate_validator.py +239 -0
  225. mcp_proxy_adapter/core/auth/models.py +47 -0
  226. mcp_proxy_adapter/core/auth/mtls_validator.py +84 -0
  227. mcp_proxy_adapter/core/auth/token_validator.py +114 -0
  228. mcp_proxy_adapter/core/auth_validator.py +137 -0
  229. mcp_proxy_adapter/core/certificate/__init__.py +20 -0
  230. mcp_proxy_adapter/core/certificate/certificate_validator/__init__.py +55 -0
  231. mcp_proxy_adapter/core/certificate/certificate_validator/facade.py +340 -0
  232. mcp_proxy_adapter/core/certificate/certificate_validator/info_part.py +130 -0
  233. mcp_proxy_adapter/core/certificate/certificate_validator/key_part.py +146 -0
  234. mcp_proxy_adapter/core/certificate/certificate_validator/part_base.py +65 -0
  235. mcp_proxy_adapter/core/certificate/certificate_validator/revocation_part.py +112 -0
  236. mcp_proxy_adapter/core/client/__init__.py +11 -0
  237. mcp_proxy_adapter/core/client/auth_handler.py +120 -0
  238. mcp_proxy_adapter/core/client/client.py +314 -0
  239. mcp_proxy_adapter/core/client/factory.py +110 -0
  240. mcp_proxy_adapter/core/client/request_handler.py +122 -0
  241. mcp_proxy_adapter/core/client/ssl_handler.py +105 -0
  242. mcp_proxy_adapter/core/client_manager.py +281 -0
  243. mcp_proxy_adapter/core/client_security/__init__.py +53 -0
  244. mcp_proxy_adapter/core/client_security/auth_part.py +227 -0
  245. mcp_proxy_adapter/core/client_security/cert_part.py +124 -0
  246. mcp_proxy_adapter/core/client_security/facade.py +181 -0
  247. mcp_proxy_adapter/core/client_security/part_base.py +62 -0
  248. mcp_proxy_adapter/core/client_security/ssl_part.py +275 -0
  249. mcp_proxy_adapter/core/config/__init__.py +29 -0
  250. mcp_proxy_adapter/core/config/config.py +963 -0
  251. mcp_proxy_adapter/core/config/config_factory.py +16 -0
  252. mcp_proxy_adapter/core/config/config_graph.py +250 -0
  253. mcp_proxy_adapter/core/config/config_loader.py +70 -0
  254. mcp_proxy_adapter/core/config/env_placeholders.py +52 -0
  255. mcp_proxy_adapter/core/config/feature_manager.py +109 -0
  256. mcp_proxy_adapter/core/config/orchestration_section.py +119 -0
  257. mcp_proxy_adapter/core/config/reload_violations.py +269 -0
  258. mcp_proxy_adapter/core/config/section_validators.py +190 -0
  259. mcp_proxy_adapter/core/config/settings_declaration.py +255 -0
  260. mcp_proxy_adapter/core/config/simple_config.py +893 -0
  261. mcp_proxy_adapter/core/config/simple_config_generator.py +917 -0
  262. mcp_proxy_adapter/core/config/simple_config_validator.py +333 -0
  263. mcp_proxy_adapter/core/config/validators/__init__.py +29 -0
  264. mcp_proxy_adapter/core/config/validators/auth_validator.py +146 -0
  265. mcp_proxy_adapter/core/config/validators/base_validator.py +102 -0
  266. mcp_proxy_adapter/core/config/validators/certificate_validator_helper.py +114 -0
  267. mcp_proxy_adapter/core/config/validators/client_validator.py +131 -0
  268. mcp_proxy_adapter/core/config/validators/job_push_validator.py +55 -0
  269. mcp_proxy_adapter/core/config/validators/queue_manager_validator.py +133 -0
  270. mcp_proxy_adapter/core/config/validators/registration_validator.py +366 -0
  271. mcp_proxy_adapter/core/config/validators/server_validation_validator.py +154 -0
  272. mcp_proxy_adapter/core/config/validators/server_validator.py +326 -0
  273. mcp_proxy_adapter/core/config/validators/ssl_validator.py +221 -0
  274. mcp_proxy_adapter/core/config/websocket_validator.py +99 -0
  275. mcp_proxy_adapter/core/config_validator.py +29 -0
  276. mcp_proxy_adapter/core/constants.py +201 -0
  277. mcp_proxy_adapter/core/crl_utils.py +338 -0
  278. mcp_proxy_adapter/core/date_utils.py +119 -0
  279. mcp_proxy_adapter/core/delivery/__init__.py +35 -0
  280. mcp_proxy_adapter/core/delivery/contracts.py +57 -0
  281. mcp_proxy_adapter/core/delivery/exceptions.py +19 -0
  282. mcp_proxy_adapter/core/delivery/terminal_replay_store.py +129 -0
  283. mcp_proxy_adapter/core/delivery/ws_delivery_manager.py +117 -0
  284. mcp_proxy_adapter/core/domain_errors.py +189 -0
  285. mcp_proxy_adapter/core/error_handling.py +98 -0
  286. mcp_proxy_adapter/core/errors/__init__.py +259 -0
  287. mcp_proxy_adapter/core/errors/config_errors.py +142 -0
  288. mcp_proxy_adapter/core/file_utils.py +94 -0
  289. mcp_proxy_adapter/core/job_manager.py +115 -0
  290. mcp_proxy_adapter/core/job_push/__init__.py +124 -0
  291. mcp_proxy_adapter/core/job_push/caller_loss.py +89 -0
  292. mcp_proxy_adapter/core/job_push/engine.py +282 -0
  293. mcp_proxy_adapter/core/job_push/events/__init__.py +111 -0
  294. mcp_proxy_adapter/core/job_push/events/builders.py +282 -0
  295. mcp_proxy_adapter/core/job_push/events/command_session_payloads.py +50 -0
  296. mcp_proxy_adapter/core/job_push/events/delivery_payloads.py +52 -0
  297. mcp_proxy_adapter/core/job_push/events/event_names.py +163 -0
  298. mcp_proxy_adapter/core/job_push/events/job_payloads.py +83 -0
  299. mcp_proxy_adapter/core/job_push/events/transfer_payloads.py +72 -0
  300. mcp_proxy_adapter/core/job_push/execute_async_deliver_guard.py +55 -0
  301. mcp_proxy_adapter/core/job_push/finish_signal.py +91 -0
  302. mcp_proxy_adapter/core/job_push/hooks.py +53 -0
  303. mcp_proxy_adapter/core/job_push/job_status_accumulator.py +376 -0
  304. mcp_proxy_adapter/core/job_push/lifespan_wiring.py +252 -0
  305. mcp_proxy_adapter/core/job_push/notifier.py +139 -0
  306. mcp_proxy_adapter/core/job_push/notifier_policy.py +38 -0
  307. mcp_proxy_adapter/core/job_push/queue_custom_push.py +67 -0
  308. mcp_proxy_adapter/core/job_push/subscriptions.py +160 -0
  309. mcp_proxy_adapter/core/job_push/transfer_correlation.py +47 -0
  310. mcp_proxy_adapter/core/job_push/transfer_push.py +135 -0
  311. mcp_proxy_adapter/core/json_utils.py +81 -0
  312. mcp_proxy_adapter/core/logging/__init__.py +42 -0
  313. mcp_proxy_adapter/core/logging/formatters.py +55 -0
  314. mcp_proxy_adapter/core/logging/global_logger.py +41 -0
  315. mcp_proxy_adapter/core/logging/request_logger.py +50 -0
  316. mcp_proxy_adapter/core/logging/setup.py +190 -0
  317. mcp_proxy_adapter/core/logging/worker.py +107 -0
  318. mcp_proxy_adapter/core/mtls_asgi_app.py +216 -0
  319. mcp_proxy_adapter/core/mtls_server.py +180 -0
  320. mcp_proxy_adapter/core/orchestration/__init__.py +90 -0
  321. mcp_proxy_adapter/core/orchestration/candidate_validator.py +196 -0
  322. mcp_proxy_adapter/core/orchestration/catalog_builder.py +136 -0
  323. mcp_proxy_adapter/core/orchestration/catalog_snapshot.py +115 -0
  324. mcp_proxy_adapter/core/orchestration/command_record.py +43 -0
  325. mcp_proxy_adapter/core/orchestration/discovery_client.py +229 -0
  326. mcp_proxy_adapter/core/orchestration/orchestration_api.py +273 -0
  327. mcp_proxy_adapter/core/orchestration/orchestration_config.py +146 -0
  328. mcp_proxy_adapter/core/orchestration/orchestration_errors.py +305 -0
  329. mcp_proxy_adapter/core/orchestration/orchestration_lifespan.py +199 -0
  330. mcp_proxy_adapter/core/orchestration/parameter_graph.py +106 -0
  331. mcp_proxy_adapter/core/orchestration/polling_loop.py +281 -0
  332. mcp_proxy_adapter/core/orchestration/server_record.py +37 -0
  333. mcp_proxy_adapter/core/orchestration/snapshot_holder.py +90 -0
  334. mcp_proxy_adapter/core/orchestration/tool_context_exposure.py +83 -0
  335. mcp_proxy_adapter/core/orchestration/tool_context_snapshot.py +164 -0
  336. mcp_proxy_adapter/core/path_utils.py +220 -0
  337. mcp_proxy_adapter/core/protocol_manager.py +260 -0
  338. mcp_proxy_adapter/core/proxy/__init__.py +62 -0
  339. mcp_proxy_adapter/core/proxy/auth_manager.py +110 -0
  340. mcp_proxy_adapter/core/proxy_client.py +252 -0
  341. mcp_proxy_adapter/core/proxy_registration.py +55 -0
  342. mcp_proxy_adapter/core/role_utils.py +166 -0
  343. mcp_proxy_adapter/core/server_adapter.py +302 -0
  344. mcp_proxy_adapter/core/server_engine.py +384 -0
  345. mcp_proxy_adapter/core/settings.py +299 -0
  346. mcp_proxy_adapter/core/signal_handler.py +136 -0
  347. mcp_proxy_adapter/core/ssl_utils.py +482 -0
  348. mcp_proxy_adapter/core/transport_manager.py +168 -0
  349. mcp_proxy_adapter/core/utils.py +74 -0
  350. mcp_proxy_adapter/core/validation/__init__.py +21 -0
  351. mcp_proxy_adapter/core/validation/config_validator.py +256 -0
  352. mcp_proxy_adapter/core/validation/file_validator.py +229 -0
  353. mcp_proxy_adapter/core/validation/protocol_validator.py +322 -0
  354. mcp_proxy_adapter/core/validation/proxy_registration_validator.py +268 -0
  355. mcp_proxy_adapter/core/validation/security_validator.py +300 -0
  356. mcp_proxy_adapter/core/validation/validation_result.py +34 -0
  357. mcp_proxy_adapter/core/validation/validator_support.py +64 -0
  358. mcp_proxy_adapter/core/validation_utils.py +160 -0
  359. mcp_proxy_adapter/core/ws_timeouts.py +88 -0
  360. mcp_proxy_adapter/custom_openapi.py +93 -0
  361. mcp_proxy_adapter/examples/PROTOCOL_EXAMPLES.md +79 -0
  362. mcp_proxy_adapter/examples/README.md +272 -0
  363. mcp_proxy_adapter/examples/README_EN.md +258 -0
  364. mcp_proxy_adapter/examples/SECURITY_TESTING.md +455 -0
  365. mcp_proxy_adapter/examples/__init__.py +16 -0
  366. mcp_proxy_adapter/examples/basic_framework/__init__.py +9 -0
  367. mcp_proxy_adapter/examples/basic_framework/commands/__init__.py +4 -0
  368. mcp_proxy_adapter/examples/basic_framework/configs/http_auth.json +21 -0
  369. mcp_proxy_adapter/examples/basic_framework/configs/http_simple.json +21 -0
  370. mcp_proxy_adapter/examples/basic_framework/configs/https_auth.json +21 -0
  371. mcp_proxy_adapter/examples/basic_framework/configs/https_no_protocol_middleware.json +21 -0
  372. mcp_proxy_adapter/examples/basic_framework/configs/https_simple.json +21 -0
  373. mcp_proxy_adapter/examples/basic_framework/configs/mtls_no_protocol_middleware.json +21 -0
  374. mcp_proxy_adapter/examples/basic_framework/configs/mtls_no_roles.json +21 -0
  375. mcp_proxy_adapter/examples/basic_framework/configs/mtls_simple.json +21 -0
  376. mcp_proxy_adapter/examples/basic_framework/configs/mtls_with_registration.json +73 -0
  377. mcp_proxy_adapter/examples/basic_framework/configs/mtls_with_roles.json +21 -0
  378. mcp_proxy_adapter/examples/basic_framework/hooks/__init__.py +4 -0
  379. mcp_proxy_adapter/examples/basic_framework/main.py +123 -0
  380. mcp_proxy_adapter/examples/basic_framework/roles.json +1 -0
  381. mcp_proxy_adapter/examples/bug_report_security_framework.md +141 -0
  382. mcp_proxy_adapter/examples/cert_config.json +1 -0
  383. mcp_proxy_adapter/examples/certs/cert_config.json +1 -0
  384. mcp_proxy_adapter/examples/check_config.py +71 -0
  385. mcp_proxy_adapter/examples/check_config_split_parts/__init__.py +3 -0
  386. mcp_proxy_adapter/examples/check_config_split_parts/checker.py +247 -0
  387. mcp_proxy_adapter/examples/check_config_split_parts/cli.py +68 -0
  388. mcp_proxy_adapter/examples/check_config_split_parts/commands.py +102 -0
  389. mcp_proxy_adapter/examples/cli_config_examples/__init__.py +8 -0
  390. mcp_proxy_adapter/examples/cli_config_examples/examples_configs/http.json +69 -0
  391. mcp_proxy_adapter/examples/cli_config_examples/examples_configs/https_token_roles.json +84 -0
  392. mcp_proxy_adapter/examples/cli_config_examples/examples_configs/mtls_roles.json +84 -0
  393. mcp_proxy_adapter/examples/cli_config_examples/http_basic.py +97 -0
  394. mcp_proxy_adapter/examples/cli_config_examples/https_token.py +128 -0
  395. mcp_proxy_adapter/examples/cli_config_examples/mtls_roles.py +140 -0
  396. mcp_proxy_adapter/examples/client_configs/api_key_client.json +1 -0
  397. mcp_proxy_adapter/examples/client_configs/basic_auth_client.json +1 -0
  398. mcp_proxy_adapter/examples/client_configs/certificate_client.json +1 -0
  399. mcp_proxy_adapter/examples/client_configs/jwt_client.json +1 -0
  400. mcp_proxy_adapter/examples/client_configs/no_auth_client.json +1 -0
  401. mcp_proxy_adapter/examples/client_usage_example.py +216 -0
  402. mcp_proxy_adapter/examples/commands/__init__.py +5 -0
  403. mcp_proxy_adapter/examples/comprehensive/__init__.py +10 -0
  404. mcp_proxy_adapter/examples/comprehensive/run.py +906 -0
  405. mcp_proxy_adapter/examples/comprehensive_config.json +10 -0
  406. mcp_proxy_adapter/examples/config.json +10 -0
  407. mcp_proxy_adapter/examples/config_builder.py +272 -0
  408. mcp_proxy_adapter/examples/config_cli.py +340 -0
  409. mcp_proxy_adapter/examples/config_factory.py +325 -0
  410. mcp_proxy_adapter/examples/configs/full_featured.json +10 -0
  411. mcp_proxy_adapter/examples/configs/http_auth.json +10 -0
  412. mcp_proxy_adapter/examples/configs/http_simple.json +10 -0
  413. mcp_proxy_adapter/examples/configs/http_token.json +10 -0
  414. mcp_proxy_adapter/examples/configs/https_auth.json +10 -0
  415. mcp_proxy_adapter/examples/configs/https_simple.json +10 -0
  416. mcp_proxy_adapter/examples/configs/https_token.json +10 -0
  417. mcp_proxy_adapter/examples/configs/mtls_no_roles.json +10 -0
  418. mcp_proxy_adapter/examples/configs/mtls_simple.json +10 -0
  419. mcp_proxy_adapter/examples/configs/mtls_with_proxy.json +10 -0
  420. mcp_proxy_adapter/examples/configs/mtls_with_roles.json +10 -0
  421. mcp_proxy_adapter/examples/configs/roles.json +1 -0
  422. mcp_proxy_adapter/examples/create_test_configs.py +216 -0
  423. mcp_proxy_adapter/examples/debug_role_chain.py +192 -0
  424. mcp_proxy_adapter/examples/demo_client.py +339 -0
  425. mcp_proxy_adapter/examples/examples_correct/http_example.json +10 -0
  426. mcp_proxy_adapter/examples/full_application/__init__.py +11 -0
  427. mcp_proxy_adapter/examples/full_application/commands/__init__.py +32 -0
  428. mcp_proxy_adapter/examples/full_application/commands/custom_echo_command.py +75 -0
  429. mcp_proxy_adapter/examples/full_application/commands/dynamic_calculator_command.py +101 -0
  430. mcp_proxy_adapter/examples/full_application/commands/embed_job_status_command.py +133 -0
  431. mcp_proxy_adapter/examples/full_application/commands/embed_queue_command.py +153 -0
  432. mcp_proxy_adapter/examples/full_application/commands/long_running_command.py +175 -0
  433. mcp_proxy_adapter/examples/full_application/commands/slow_start_long_task_command.py +172 -0
  434. mcp_proxy_adapter/examples/full_application/configs/http_basic.json +73 -0
  435. mcp_proxy_adapter/examples/full_application/configs/http_basic_smart_assistant_proxy3004.json +67 -0
  436. mcp_proxy_adapter/examples/full_application/configs/http_no_registration.json +72 -0
  437. mcp_proxy_adapter/examples/full_application/configs/http_token.json +69 -0
  438. mcp_proxy_adapter/examples/full_application/configs/http_token_roles.json +81 -0
  439. mcp_proxy_adapter/examples/full_application/configs/http_token_roles_smart_assistant_proxy3004.json +81 -0
  440. mcp_proxy_adapter/examples/full_application/configs/http_token_smart_assistant_proxy3004.json +69 -0
  441. mcp_proxy_adapter/examples/full_application/configs/https_basic.json +74 -0
  442. mcp_proxy_adapter/examples/full_application/configs/https_basic_smart_assistant_proxy3004.json +81 -0
  443. mcp_proxy_adapter/examples/full_application/configs/https_token.json +76 -0
  444. mcp_proxy_adapter/examples/full_application/configs/https_token_roles.json +88 -0
  445. mcp_proxy_adapter/examples/full_application/configs/https_token_roles_smart_assistant_proxy3004.json +95 -0
  446. mcp_proxy_adapter/examples/full_application/configs/https_token_smart_assistant_proxy3004.json +83 -0
  447. mcp_proxy_adapter/examples/full_application/configs/mtls_no_roles.json +78 -0
  448. mcp_proxy_adapter/examples/full_application/configs/mtls_no_roles_correct.json +76 -0
  449. mcp_proxy_adapter/examples/full_application/configs/mtls_no_roles_smart_assistant_proxy3004.json +83 -0
  450. mcp_proxy_adapter/examples/full_application/configs/mtls_no_security.json +77 -0
  451. mcp_proxy_adapter/examples/full_application/configs/mtls_with_roles.json +82 -0
  452. mcp_proxy_adapter/examples/full_application/configs/mtls_with_roles_correct.json +88 -0
  453. mcp_proxy_adapter/examples/full_application/configs/mtls_with_roles_smart_assistant_proxy3004.json +95 -0
  454. mcp_proxy_adapter/examples/full_application/configs/mtls_ws_repro.json +76 -0
  455. mcp_proxy_adapter/examples/full_application/configs/proxy_server.json +64 -0
  456. mcp_proxy_adapter/examples/full_application/configs/proxy_server_https.json +63 -0
  457. mcp_proxy_adapter/examples/full_application/configs/proxy_server_mtls.json +63 -0
  458. mcp_proxy_adapter/examples/full_application/example_support.py +45 -0
  459. mcp_proxy_adapter/examples/full_application/hooks/__init__.py +4 -0
  460. mcp_proxy_adapter/examples/full_application/hooks/application_hooks.py +51 -0
  461. mcp_proxy_adapter/examples/full_application/hooks/builtin_command_hooks.py +46 -0
  462. mcp_proxy_adapter/examples/full_application/main.py +95 -0
  463. mcp_proxy_adapter/examples/full_application/main_modules/__init__.py +1 -0
  464. mcp_proxy_adapter/examples/full_application/main_modules/registration.py +122 -0
  465. mcp_proxy_adapter/examples/full_application/main_modules/runner.py +310 -0
  466. mcp_proxy_adapter/examples/full_application/proxy_commands/__init__.py +113 -0
  467. mcp_proxy_adapter/examples/full_application/proxy_commands/_shared.py +8 -0
  468. mcp_proxy_adapter/examples/full_application/proxy_commands/lifecycle_commands.py +196 -0
  469. mcp_proxy_adapter/examples/full_application/proxy_commands/register_command.py +254 -0
  470. mcp_proxy_adapter/examples/full_application/proxy_commands/registry_state.py +8 -0
  471. mcp_proxy_adapter/examples/full_application/proxy_commands/results.py +142 -0
  472. mcp_proxy_adapter/examples/full_application/proxy_endpoints.py +162 -0
  473. mcp_proxy_adapter/examples/full_application/proxy_schemas.py +91 -0
  474. mcp_proxy_adapter/examples/full_application/roles.json +1 -0
  475. mcp_proxy_adapter/examples/full_application/test_client.py +341 -0
  476. mcp_proxy_adapter/examples/full_application/test_minimal_server.py +57 -0
  477. mcp_proxy_adapter/examples/full_application/test_queue_and_descriptions.py +283 -0
  478. mcp_proxy_adapter/examples/full_application/test_server.py +221 -0
  479. mcp_proxy_adapter/examples/full_application/test_simple_server.py +141 -0
  480. mcp_proxy_adapter/examples/generate_all_certificates.py +74 -0
  481. mcp_proxy_adapter/examples/generate_config.py +44 -0
  482. mcp_proxy_adapter/examples/generate_config_parts/__init__.py +3 -0
  483. mcp_proxy_adapter/examples/generate_config_parts/builders.py +234 -0
  484. mcp_proxy_adapter/examples/generate_config_parts/cli.py +260 -0
  485. mcp_proxy_adapter/examples/generate_config_parts/outputs.py +137 -0
  486. mcp_proxy_adapter/examples/generator_validator_compatibility_report.md +127 -0
  487. mcp_proxy_adapter/examples/http_proxy_example.json +17 -0
  488. mcp_proxy_adapter/examples/https_proxy_example.json +17 -0
  489. mcp_proxy_adapter/examples/job_tracking_demo.py +235 -0
  490. mcp_proxy_adapter/examples/proxy_server_support.py +384 -0
  491. mcp_proxy_adapter/examples/queue_demo_simple.py +37 -0
  492. mcp_proxy_adapter/examples/queue_demo_simple_parts/__init__.py +3 -0
  493. mcp_proxy_adapter/examples/queue_demo_simple_parts/_shared.py +8 -0
  494. mcp_proxy_adapter/examples/queue_demo_simple_parts/demo.py +213 -0
  495. mcp_proxy_adapter/examples/queue_demo_simple_parts/mock_commands.py +130 -0
  496. mcp_proxy_adapter/examples/queue_demo_simple_parts/mock_manager.py +272 -0
  497. mcp_proxy_adapter/examples/queue_example_support.py +36 -0
  498. mcp_proxy_adapter/examples/queue_fire_and_forget_example.py +370 -0
  499. mcp_proxy_adapter/examples/queue_server_demo.py +73 -0
  500. mcp_proxy_adapter/examples/queue_server_example.py +76 -0
  501. mcp_proxy_adapter/examples/queue_server_simple.py +251 -0
  502. mcp_proxy_adapter/examples/required_certificates.py +216 -0
  503. mcp_proxy_adapter/examples/run_example.py +119 -0
  504. mcp_proxy_adapter/examples/run_full_test_suite.py +674 -0
  505. mcp_proxy_adapter/examples/run_proxy_server.py +118 -0
  506. mcp_proxy_adapter/examples/run_security_tests_fixed.py +876 -0
  507. mcp_proxy_adapter/examples/security_test/__init__.py +18 -0
  508. mcp_proxy_adapter/examples/security_test/auth_manager.py +49 -0
  509. mcp_proxy_adapter/examples/security_test/ssl_context_manager.py +144 -0
  510. mcp_proxy_adapter/examples/security_test/test_client.py +218 -0
  511. mcp_proxy_adapter/examples/security_test/test_result.py +23 -0
  512. mcp_proxy_adapter/examples/security_test_client.py +103 -0
  513. mcp_proxy_adapter/examples/server_configs/config_basic_http.json +16 -0
  514. mcp_proxy_adapter/examples/server_configs/config_http_token.json +16 -0
  515. mcp_proxy_adapter/examples/server_configs/config_https.json +16 -0
  516. mcp_proxy_adapter/examples/server_configs/config_https_token.json +16 -0
  517. mcp_proxy_adapter/examples/server_configs/config_mtls.json +16 -0
  518. mcp_proxy_adapter/examples/server_configs/config_proxy_registration.json +15 -0
  519. mcp_proxy_adapter/examples/server_configs/config_simple.json +9 -0
  520. mcp_proxy_adapter/examples/server_configs/http_simple.json +14 -0
  521. mcp_proxy_adapter/examples/server_configs/http_token.json +14 -0
  522. mcp_proxy_adapter/examples/server_configs/https_simple.json +14 -0
  523. mcp_proxy_adapter/examples/server_configs/https_token.json +14 -0
  524. mcp_proxy_adapter/examples/server_configs/mtls_no_roles.json +8 -0
  525. mcp_proxy_adapter/examples/server_configs/mtls_test.json +8 -0
  526. mcp_proxy_adapter/examples/server_configs/mtls_with_roles.json +14 -0
  527. mcp_proxy_adapter/examples/server_configs/roles.json +1 -0
  528. mcp_proxy_adapter/examples/setup/__init__.py +48 -0
  529. mcp_proxy_adapter/examples/setup/certificate_manager.py +384 -0
  530. mcp_proxy_adapter/examples/setup/config_generator.py +6 -0
  531. mcp_proxy_adapter/examples/setup/config_validator.py +140 -0
  532. mcp_proxy_adapter/examples/setup/environment_setup.py +143 -0
  533. mcp_proxy_adapter/examples/setup/test_files_generator.py +6 -0
  534. mcp_proxy_adapter/examples/setup/test_runner.py +143 -0
  535. mcp_proxy_adapter/examples/setup_test_environment.py +233 -0
  536. mcp_proxy_adapter/examples/simple_http_example.json +17 -0
  537. mcp_proxy_adapter/examples/simple_https_example.json +17 -0
  538. mcp_proxy_adapter/examples/simple_protocol_test.py +167 -0
  539. mcp_proxy_adapter/examples/test_client/README.md +166 -0
  540. mcp_proxy_adapter/examples/test_client/__init__.py +7 -0
  541. mcp_proxy_adapter/examples/test_client/main.py +102 -0
  542. mcp_proxy_adapter/examples/test_client/main_split_parts/__init__.py +1 -0
  543. mcp_proxy_adapter/examples/test_client/main_split_parts/helpers.py +83 -0
  544. mcp_proxy_adapter/examples/test_client/main_split_parts/runner.py +115 -0
  545. mcp_proxy_adapter/examples/test_client/main_split_parts/scenarios.py +195 -0
  546. mcp_proxy_adapter/examples/test_config.py +183 -0
  547. mcp_proxy_adapter/examples/test_configs/custom_https.json +10 -0
  548. mcp_proxy_adapter/examples/test_configs/http_simple.json +10 -0
  549. mcp_proxy_adapter/examples/test_examples.py +361 -0
  550. mcp_proxy_adapter/examples/test_mcp_server.py +249 -0
  551. mcp_proxy_adapter/examples/test_protocol_examples.py +373 -0
  552. mcp_proxy_adapter/examples/test_proxy/README.md +70 -0
  553. mcp_proxy_adapter/examples/test_proxy/__init__.py +7 -0
  554. mcp_proxy_adapter/examples/test_proxy/main.py +106 -0
  555. mcp_proxy_adapter/examples/test_server/README.md +58 -0
  556. mcp_proxy_adapter/examples/test_server/__init__.py +7 -0
  557. mcp_proxy_adapter/examples/test_server/main.py +349 -0
  558. mcp_proxy_adapter/examples/transparent_queue_commands.py +281 -0
  559. mcp_proxy_adapter/examples/transparent_queue_e1_sync_call.py +102 -0
  560. mcp_proxy_adapter/examples/transparent_queue_e2_event_stream.py +134 -0
  561. mcp_proxy_adapter/examples/transparent_queue_e3_ws_timeouts.py +341 -0
  562. mcp_proxy_adapter/examples/transparent_queue_e4_ws_fallback.py +159 -0
  563. mcp_proxy_adapter/examples/transparent_queue_e5_inner_failure.py +189 -0
  564. mcp_proxy_adapter/examples/transparent_queue_e6_atomic_state.py +203 -0
  565. mcp_proxy_adapter/examples/transparent_queue_e7_caller_loss.py +63 -0
  566. mcp_proxy_adapter/examples/transparent_queue_e7_split2/__init__.py +3 -0
  567. mcp_proxy_adapter/examples/transparent_queue_e7_split2/cases.py +335 -0
  568. mcp_proxy_adapter/examples/transparent_queue_e7_split2/helpers.py +66 -0
  569. mcp_proxy_adapter/examples/transparent_queue_support.py +377 -0
  570. mcp_proxy_adapter/examples/unified_error_handling_example.py +127 -0
  571. mcp_proxy_adapter/examples/unified_error_handling_split_parts/__init__.py +3 -0
  572. mcp_proxy_adapter/examples/unified_error_handling_split_parts/demos.py +180 -0
  573. mcp_proxy_adapter/examples/unified_error_handling_split_parts/runner.py +109 -0
  574. mcp_proxy_adapter/examples/unified_error_handling_split_parts/support.py +79 -0
  575. mcp_proxy_adapter/examples/unified_error_handling_texts.py +17 -0
  576. mcp_proxy_adapter/examples/universal_client.py +215 -0
  577. mcp_proxy_adapter/examples/universal_client_split_parts/__init__.py +3 -0
  578. mcp_proxy_adapter/examples/universal_client_split_parts/configs.py +104 -0
  579. mcp_proxy_adapter/examples/universal_client_split_parts/demos.py +144 -0
  580. mcp_proxy_adapter/examples/update_config_certificates.py +156 -0
  581. mcp_proxy_adapter/examples/validate_generator_compatibility_simple.py +60 -0
  582. mcp_proxy_adapter/examples/websocket_examples/__init__.py +8 -0
  583. mcp_proxy_adapter/examples/websocket_examples/client_bidirectional_websocket.py +100 -0
  584. mcp_proxy_adapter/examples/websocket_examples/client_websocket_job_status.py +103 -0
  585. mcp_proxy_adapter/examples/websocket_examples/run_ws_test_server.py +157 -0
  586. mcp_proxy_adapter/examples/ws_examples/__init__.py +6 -0
  587. mcp_proxy_adapter/examples/ws_examples/http_basic_ws.py +68 -0
  588. mcp_proxy_adapter/examples/ws_examples/http_token_roles_ws.py +66 -0
  589. mcp_proxy_adapter/examples/ws_examples/http_token_ws.py +80 -0
  590. mcp_proxy_adapter/examples/ws_examples/https_basic_ws.py +61 -0
  591. mcp_proxy_adapter/examples/ws_examples/https_token_roles_ws.py +67 -0
  592. mcp_proxy_adapter/examples/ws_examples/https_token_ws.py +64 -0
  593. mcp_proxy_adapter/examples/ws_examples/mtls_basic_ws.py +94 -0
  594. mcp_proxy_adapter/examples/ws_examples/mtls_roles_ws.py +88 -0
  595. mcp_proxy_adapter/examples/ws_examples/ws_example_runner.py +233 -0
  596. mcp_proxy_adapter/integrations/__init__.py +31 -0
  597. mcp_proxy_adapter/integrations/queuemgr_integration/__init__.py +124 -0
  598. mcp_proxy_adapter/integrations/queuemgr_integration/_compat.py +60 -0
  599. mcp_proxy_adapter/integrations/queuemgr_integration/_health.py +299 -0
  600. mcp_proxy_adapter/integrations/queuemgr_integration/_limits.py +70 -0
  601. mcp_proxy_adapter/integrations/queuemgr_integration/_process_reap.py +232 -0
  602. mcp_proxy_adapter/integrations/queuemgr_integration/_result_builders.py +119 -0
  603. mcp_proxy_adapter/integrations/queuemgr_integration/_status_helpers.py +167 -0
  604. mcp_proxy_adapter/integrations/queuemgr_integration/global_manager.py +174 -0
  605. mcp_proxy_adapter/integrations/queuemgr_integration/job_types/__init__.py +375 -0
  606. mcp_proxy_adapter/integrations/queuemgr_integration/job_types/value_types.py +97 -0
  607. mcp_proxy_adapter/integrations/queuemgr_integration/job_types/worker_probe.py +29 -0
  608. mcp_proxy_adapter/integrations/queuemgr_integration/manager/__init__.py +52 -0
  609. mcp_proxy_adapter/integrations/queuemgr_integration/manager/fallback_base.py +240 -0
  610. mcp_proxy_adapter/integrations/queuemgr_integration/manager/fallback_stop_base.py +179 -0
  611. mcp_proxy_adapter/integrations/queuemgr_integration/manager/health_base.py +460 -0
  612. mcp_proxy_adapter/integrations/queuemgr_integration/manager/integration.py +189 -0
  613. mcp_proxy_adapter/integrations/queuemgr_integration/manager/job_start_base.py +333 -0
  614. mcp_proxy_adapter/integrations/queuemgr_integration/manager/job_stop_base.py +274 -0
  615. mcp_proxy_adapter/integrations/queuemgr_integration/manager/lifecycle_base.py +393 -0
  616. mcp_proxy_adapter/integrations/queuemgr_integration/manager/query_base.py +269 -0
  617. mcp_proxy_adapter/integrations/queuemgr_registration.py +66 -0
  618. mcp_proxy_adapter/integrations/queuemgr_version.py +39 -0
  619. mcp_proxy_adapter/main.py +385 -0
  620. mcp_proxy_adapter/main_ssl_paths.py +29 -0
  621. mcp_proxy_adapter/py.typed +0 -0
  622. mcp_proxy_adapter/schemas/base_schema.json +114 -0
  623. mcp_proxy_adapter/schemas/openapi_schema.json +269 -0
  624. mcp_proxy_adapter/schemas/roles.json +37 -0
  625. mcp_proxy_adapter/schemas/roles_schema.json +162 -0
  626. mcp_proxy_adapter/transfer/__init__.py +56 -0
  627. mcp_proxy_adapter/transfer/checksums.py +81 -0
  628. mcp_proxy_adapter/transfer/client_downloader/__init__.py +37 -0
  629. mcp_proxy_adapter/transfer/client_downloader/download_support.py +109 -0
  630. mcp_proxy_adapter/transfer/client_downloader/downloader.py +300 -0
  631. mcp_proxy_adapter/transfer/client_uploader.py +278 -0
  632. mcp_proxy_adapter/transfer/compression.py +127 -0
  633. mcp_proxy_adapter/transfer/errors.py +253 -0
  634. mcp_proxy_adapter/transfer/json_coerce.py +32 -0
  635. mcp_proxy_adapter/transfer/models.py +337 -0
  636. mcp_proxy_adapter/transfer/path_confinement.py +69 -0
  637. mcp_proxy_adapter/transfer/progress_percent.py +25 -0
  638. mcp_proxy_adapter/transfer/server_store.py +878 -0
  639. mcp_proxy_adapter/version.py +8 -0
  640. mcp_proxy_adapter_dev-8.11.16.dist-info/METADATA +1666 -0
  641. mcp_proxy_adapter_dev-8.11.16.dist-info/RECORD +644 -0
  642. mcp_proxy_adapter_dev-8.11.16.dist-info/WHEEL +5 -0
  643. mcp_proxy_adapter_dev-8.11.16.dist-info/entry_points.txt +12 -0
  644. mcp_proxy_adapter_dev-8.11.16.dist-info/top_level.txt +1 -0
@@ -0,0 +1,201 @@
1
+ """
2
+ Default constants for WebSocket, timeout, and polling configuration.
3
+
4
+ Author: Vasiliy Zdanovskiy
5
+ email: vasilyvz@gmail.com
6
+
7
+ All timeout values are in seconds.
8
+ A value of 0 means "no timeout" (wait indefinitely).
9
+ """
10
+
11
+ import os
12
+ from typing import Any, Mapping, Optional
13
+
14
+ # Default ceiling for ``CommandExecutionJob`` when it runs the asyncio loop inside
15
+ # ``ThreadPoolExecutor`` (nested event loop path). ``0`` or negative = wait forever.
16
+ _DEFAULT_QUEUE_JOB_THREAD_FUTURE_TIMEOUT_SEC: float = 86400.0
17
+
18
+
19
+ # ---------------------------------------------------------------------------
20
+ # WebSocket defaults
21
+ # ---------------------------------------------------------------------------
22
+
23
+ WS_HEARTBEAT_INTERVAL: float = 30.0
24
+ """WebSocket heartbeat (ping/pong) interval in seconds. 0 = disabled."""
25
+
26
+ WS_RECEIVE_TIMEOUT: float = 60.0
27
+ """WebSocket receive timeout in seconds. 0 = no timeout."""
28
+
29
+ WS_RECEIVE_TIMEOUT_BUFFER: float = 5.0
30
+ """Extra seconds added to receive_timeout for aiohttp ws_connect."""
31
+
32
+ WS_SUBSCRIBE_SETTLE_DELAY: float = 0.5
33
+ """Delay (seconds) after WS subscribe task creation before sending RPC."""
34
+
35
+ WS_JOB_WAIT_TIMEOUT: float = 60.0
36
+ """Default timeout for waiting for job completion via WebSocket. 0 = no timeout."""
37
+
38
+ WS_TERMINAL_POLL_INTERVAL: float = 2.0
39
+ """Safety-net status-poll cadence while waiting for a terminal WS event."""
40
+
41
+ WS_CLOSE_TIMEOUT: float = 5.0
42
+ """Bounded WebSocket close handshake (seconds). 0 = no timeout."""
43
+
44
+ WS_CANCEL_GRACE_SECONDS: float = 0.5
45
+ """Grace (seconds) a cancelled task/receive gets before it is abandoned or force-marked."""
46
+
47
+ WS_ON_TIMEOUT: str = "cancel"
48
+ """Client policy when its job wait expires: ``cancel`` (default) or ``detach``."""
49
+
50
+ WS_ON_CALLER_LOSS: str = "cancel"
51
+ """Server policy when a caller vanishes unannounced: ``cancel`` (default) or ``detach``."""
52
+
53
+ # ---------------------------------------------------------------------------
54
+ # Command execution defaults
55
+ # ---------------------------------------------------------------------------
56
+
57
+ SYNC_COMMAND_TIMEOUT: float = 20.0
58
+ """Timeout for synchronous command execution via JSON-RPC handler. 0 = no timeout.
59
+
60
+ Default is below ``WS_HEARTBEAT_INTERVAL`` so a slow sync call can fall back to
61
+ the job queue before a typical WebSocket heartbeat window.
62
+ """
63
+
64
+ ASYNC_COMMAND_TIMEOUT: float = 300.0
65
+ """Timeout for asynchronous command execution (delivered via WS push). 0 = no timeout."""
66
+
67
+ # ---------------------------------------------------------------------------
68
+ # Job push defaults
69
+ # ---------------------------------------------------------------------------
70
+
71
+ JOB_PUSH_POLL_INTERVAL: float = 0.1
72
+ """Interval between poll loop iterations for subscribed job_ids (seconds).
73
+
74
+ This is the ONLY mechanism that discovers a queued job's terminal status
75
+ and forwards it to WS command-session/queue-job subscribers (see
76
+ ``_job_push_poll_loop`` in ``core/job_push/lifespan_wiring.py``) - it is
77
+ not event-driven. A job's completion becomes visible only on the poll
78
+ loop's NEXT tick after it occurs, and since job submission is never
79
+ synchronized to the loop's phase, the common case needs the tick AFTER
80
+ NEXT (the loop's first check after submission routinely still sees a
81
+ non-terminal status, e.g. because ``queue_manager.start_job()`` has not
82
+ finished yet). That makes every WS-delivered terminal event wait roughly
83
+ ``2 * JOB_PUSH_POLL_INTERVAL`` regardless of how fast the wrapped command
84
+ itself runs - confirmed live as bug ba99fad9-469b-420f-82a0-4f72ccb5b9d0:
85
+ with the former default of 1.0s, even a no-op ``echo`` command-session
86
+ call took a median of ~2000ms end-to-end. Keep this low (see
87
+ ``test_job_push_poll_interval_stays_low``, bound 0.25s) - raising it
88
+ directly reintroduces that fixed dispatch wait.
89
+ """
90
+
91
+ TRANSFER_SESSION_EXPIRY_POLL_INTERVAL: float = 60.0
92
+ """Interval between TTL scans for transfer sessions (seconds)."""
93
+
94
+ # ---------------------------------------------------------------------------
95
+ # Internal helpers
96
+ # ---------------------------------------------------------------------------
97
+
98
+ _INFINITE_TIMEOUT_SECONDS: float = 21_600_000.0
99
+ """Fallback for APIs that require a positive float (6000 hours ≈ 250 days)."""
100
+
101
+
102
+ def resolve_timeout(value: float) -> Optional[float]:
103
+ """Convert timeout: 0 (or negative) → ``None`` (no timeout), positive → seconds.
104
+
105
+ Use for APIs that accept ``Optional[float]`` (e.g. ``asyncio.wait_for``,
106
+ aiohttp ``heartbeat``, ``receive_timeout``).
107
+ """
108
+ return None if value <= 0 else value
109
+
110
+
111
+ def resolve_timeout_strict(value: float) -> float:
112
+ """Convert timeout: 0 (or negative) → very large value, positive → seconds.
113
+
114
+ Use when the API requires a positive ``float`` and does not accept ``None``.
115
+ The fallback is ``_INFINITE_TIMEOUT_SECONDS`` (6 000 hours).
116
+ """
117
+ return _INFINITE_TIMEOUT_SECONDS if value <= 0 else value
118
+
119
+
120
+ def resolve_queue_job_thread_future_timeout_seconds() -> Optional[float]:
121
+ """Timeout for ``Future.result`` in ``CommandExecutionJob`` thread-pool path.
122
+
123
+ Environment (first wins): ``SVO_QUEUE_JOB_EXEC_TIMEOUT_SEC``,
124
+ ``MCP_PROXY_ADAPTER_QUEUE_JOB_EXEC_TIMEOUT_SEC``. Unset defaults to
125
+ ``_DEFAULT_QUEUE_JOB_THREAD_FUTURE_TIMEOUT_SEC`` (24 hours).
126
+
127
+ ``0`` or a negative value means no limit (``None`` passed to ``Future.result``).
128
+ Invalid values fall back to the default positive timeout.
129
+ """
130
+ raw = os.environ.get("SVO_QUEUE_JOB_EXEC_TIMEOUT_SEC")
131
+ if raw is None:
132
+ raw = os.environ.get("MCP_PROXY_ADAPTER_QUEUE_JOB_EXEC_TIMEOUT_SEC")
133
+ if raw is None or raw == "":
134
+ return _DEFAULT_QUEUE_JOB_THREAD_FUTURE_TIMEOUT_SEC
135
+ try:
136
+ v = float(raw)
137
+ except (TypeError, ValueError):
138
+ return _DEFAULT_QUEUE_JOB_THREAD_FUTURE_TIMEOUT_SEC
139
+ if v <= 0:
140
+ return None
141
+ return v
142
+
143
+
144
+ #: websocket config key -> name of the module constant holding its default.
145
+ _WS_KEY_TO_CONSTANT = {
146
+ "heartbeat_interval": "WS_HEARTBEAT_INTERVAL",
147
+ "receive_timeout": "WS_RECEIVE_TIMEOUT",
148
+ "receive_timeout_buffer": "WS_RECEIVE_TIMEOUT_BUFFER",
149
+ "subscribe_settle_delay": "WS_SUBSCRIBE_SETTLE_DELAY",
150
+ "job_wait_timeout": "WS_JOB_WAIT_TIMEOUT",
151
+ "terminal_poll_interval": "WS_TERMINAL_POLL_INTERVAL",
152
+ "close_timeout": "WS_CLOSE_TIMEOUT",
153
+ "cancel_grace_seconds": "WS_CANCEL_GRACE_SECONDS",
154
+ }
155
+
156
+
157
+ def _checked_timeout(name: str, value: Any, level: str) -> Optional[float]:
158
+ """Validate one chain value: number, not bool, not negative; 0 -> ``None``."""
159
+ if isinstance(value, bool) or not isinstance(value, (int, float)):
160
+ raise TypeError(
161
+ f"websocket timeout {name!r} ({level}) must be a number, got {value!r}"
162
+ )
163
+ if value < 0:
164
+ raise ValueError(
165
+ f"websocket timeout {name!r} ({level}) must be >= 0, got {value!r}"
166
+ )
167
+ return None if value == 0 else float(value)
168
+
169
+
170
+ def ws_timeout_level(
171
+ name: str, per_call: Any, config: Optional[Mapping[str, Any]]
172
+ ) -> str:
173
+ """Return the chain level that supplies ``name``: per_call, config or default."""
174
+ if per_call is not None:
175
+ return "per_call"
176
+ section = config.get("websocket") if isinstance(config, Mapping) else None
177
+ if isinstance(section, Mapping) and name in section:
178
+ return "config"
179
+ return "default"
180
+
181
+
182
+ def resolve_ws_timeout(
183
+ name: str, per_call: Any, config: Optional[Mapping[str, Any]] = None
184
+ ) -> Optional[float]:
185
+ """Resolve one websocket timeout: per-call, then config, then the constant.
186
+
187
+ ``config`` is a mapping whose ``websocket`` section carries the keys (or
188
+ ``None``). ``0`` means no timeout and resolves to ``None`` at the per-call
189
+ and config levels; a negative value raises ``ValueError``. The constant
190
+ level is read from this module at call time and is never zero-converted.
191
+ """
192
+ if name not in _WS_KEY_TO_CONSTANT:
193
+ raise KeyError(f"unknown websocket timeout key {name!r}")
194
+ level = ws_timeout_level(name, per_call, config)
195
+ if level == "per_call":
196
+ return _checked_timeout(name, per_call, level)
197
+ if level == "config":
198
+ section = config["websocket"] # type: ignore[index]
199
+ return _checked_timeout(name, section[name], level)
200
+ default = globals()[_WS_KEY_TO_CONSTANT[name]]
201
+ return None if default == 0 else float(default)
@@ -0,0 +1,338 @@
1
+ """
2
+ CRL Utilities Module
3
+
4
+ This module provides utilities for working with Certificate Revocation Lists (CRL).
5
+ Supports both file-based and URL-based CRL sources.
6
+
7
+ URL-based retrieval delegates to the framework's stdlib-only CRL client
8
+ (``mcp_security_framework.utils.crl_client.fetch_crl``): a configurable
9
+ per-call timeout, retry-with-backoff on transient HTTP failures, and
10
+ scheme-enforcement on both the initial URL and any HTTP redirect target
11
+ (refusing hops to e.g. ``file://`` or ``ftp://``).
12
+
13
+ Author: Vasiliy Zdanovskiy
14
+ email: vasilyvz@gmail.com
15
+ Version: 1.1.0
16
+ """
17
+
18
+ import logging
19
+ import os
20
+ import tempfile
21
+ from pathlib import Path
22
+ from typing import Any, Dict, Optional, Union, cast
23
+
24
+ from mcp_security_framework.utils.cert_utils import (
25
+ get_crl_info,
26
+ is_certificate_revoked,
27
+ is_crl_valid,
28
+ validate_certificate_against_crl,
29
+ )
30
+ from mcp_security_framework.utils.crl_client import CRLFetchError, fetch_crl
31
+
32
+ logger = logging.getLogger(__name__)
33
+
34
+
35
+ class CRLManager:
36
+ """
37
+ Manager for Certificate Revocation Lists (CRL).
38
+
39
+ Supports both file-based and URL-based CRL sources.
40
+ Automatically downloads CRL from URLs and caches them locally.
41
+ """
42
+
43
+ def __init__(self, config: Dict[str, Any]):
44
+ """
45
+ Initialize CRL manager.
46
+
47
+ Args:
48
+ config: Configuration dictionary containing CRL settings
49
+ """
50
+ self.config = config
51
+ self.crl_enabled = config.get("crl_enabled", False)
52
+
53
+ # Only analyze CRL paths if certificates are enabled
54
+ certificates_enabled = config.get("certificates_enabled", True)
55
+ if certificates_enabled and self.crl_enabled:
56
+ self.crl_path = config.get("crl_path")
57
+ self.crl_url = config.get("crl_url")
58
+ self.crl_validity_days = config.get("crl_validity_days", 30)
59
+ # Per-request timeout (seconds) for CRL URL fetches, passed
60
+ # explicitly as `timeout=` to fetch_crl() on every call -- see
61
+ # _get_crl_from_url(). This is the single source of truth for
62
+ # the fetch budget.
63
+ self.crl_timeout: float = config.get("crl_timeout", 30)
64
+ else:
65
+ # Don't analyze CRL paths if certificates are disabled
66
+ self.crl_path = None
67
+ self.crl_url = None
68
+ self.crl_validity_days = 30
69
+ self.crl_timeout = 30
70
+
71
+ # Cache for downloaded CRL files
72
+ self._crl_cache: Dict[str, str] = {}
73
+
74
+ logger.info(
75
+ f"CRL Manager initialized - enabled: {self.crl_enabled}, certificates_enabled: {certificates_enabled}"
76
+ )
77
+
78
+ def get_crl_data(self) -> Optional[Union[str, bytes, Path]]:
79
+ """
80
+ Get CRL data from configured source.
81
+
82
+ Returns:
83
+ CRL data as string, bytes, or Path, or None if not available
84
+
85
+ Raises:
86
+ ValueError: If CRL is enabled but no source is configured
87
+ FileNotFoundError: If CRL file is not found
88
+ CRLFetchError: If CRL download fails
89
+ """
90
+ if not self.crl_enabled:
91
+ logger.debug("CRL is disabled, skipping CRL check")
92
+ return None
93
+
94
+ # Check if CRL URL is configured
95
+ if self.crl_url:
96
+ return self._get_crl_from_url()
97
+
98
+ # Check if CRL file path is configured
99
+ if self.crl_path:
100
+ return self._get_crl_from_file()
101
+
102
+ # If CRL is enabled but no source is configured, this is an error
103
+ if self.crl_enabled:
104
+ raise ValueError(
105
+ "CRL is enabled but neither crl_path nor crl_url is configured"
106
+ )
107
+
108
+ return None
109
+
110
+ def _get_crl_from_url(self) -> str:
111
+ """
112
+ Download CRL from URL.
113
+
114
+ Returns:
115
+ Path to downloaded CRL file
116
+
117
+ Raises:
118
+ CRLFetchError: If download fails (network error, non-retryable
119
+ HTTP status, retries exhausted, response too large, or a
120
+ disallowed URL/redirect scheme).
121
+ ValueError: If downloaded data is not valid CRL
122
+ """
123
+ if not self.crl_url:
124
+ # Only reachable if this private method is called directly,
125
+ # bypassing get_crl_data()'s own `if self.crl_url:` guard - kept
126
+ # as a defensive, honestly-typed narrowing rather than silently
127
+ # handing `None` to fetch_crl().
128
+ raise ValueError("CRL is enabled but crl_url is not configured")
129
+
130
+ try:
131
+ logger.info(f"Downloading CRL from URL: {self.crl_url}")
132
+
133
+ # Fetch via the framework's stdlib-only CRL client
134
+ # (mcp_security_framework.utils.crl_client.fetch_crl). It:
135
+ # - honours our configured timeout as a real per-call budget
136
+ # (self.crl_timeout, passed explicitly below -- unlike
137
+ # requests.Session, which has no native `timeout` attribute
138
+ # and silently ignores one stashed on the instance);
139
+ # - retries transient failures (429/500/502/503/504) with the
140
+ # same total=3/backoff_factor=1 policy this manager used to
141
+ # configure by hand via urllib3.util.retry.Retry;
142
+ # - additionally refuses HTTP redirects to a disallowed scheme
143
+ # (e.g. a CRL Distribution Point -- attacker-controlled
144
+ # certificate data -- redirecting to file:// or ftp://),
145
+ # a security control our hand-rolled requests.Session
146
+ # plumbing did not have.
147
+ crl_bytes = fetch_crl(self.crl_url, timeout=self.crl_timeout)
148
+
149
+ # Save to temporary file
150
+ with tempfile.NamedTemporaryFile(
151
+ mode="wb", suffix=".crl", delete=False
152
+ ) as temp_file:
153
+ temp_file.write(crl_bytes)
154
+ temp_file_path = temp_file.name
155
+
156
+ # Validate CRL format
157
+ try:
158
+ is_crl_valid(temp_file_path)
159
+ logger.info(
160
+ f"CRL downloaded and validated successfully from {self.crl_url}"
161
+ )
162
+ except Exception as e:
163
+ os.unlink(temp_file_path)
164
+ raise ValueError(f"Downloaded CRL is not valid: {e}")
165
+
166
+ # Cache the file path
167
+ self._crl_cache[self.crl_url] = temp_file_path
168
+
169
+ return temp_file_path
170
+
171
+ except CRLFetchError as e:
172
+ logger.error(f"Failed to download CRL from {self.crl_url}: {e}")
173
+ raise
174
+ except Exception as e:
175
+ logger.error(f"CRL download failed: {e}")
176
+ raise
177
+
178
+ def _get_crl_from_file(self) -> str:
179
+ """
180
+ Get CRL from file path.
181
+
182
+ Returns:
183
+ Path to CRL file
184
+
185
+ Raises:
186
+ FileNotFoundError: If CRL file is not found
187
+ ValueError: If CRL file is not valid
188
+ """
189
+ if not self.crl_path:
190
+ # Only reachable if this private method is called directly,
191
+ # bypassing get_crl_data()'s own `if self.crl_path:` guard - kept
192
+ # as a defensive, honestly-typed narrowing rather than silently
193
+ # handing `None` to os.path.exists().
194
+ raise ValueError("CRL is enabled but crl_path is not configured")
195
+
196
+ if not os.path.exists(self.crl_path):
197
+ raise FileNotFoundError(f"CRL file not found: {self.crl_path}")
198
+
199
+ # Validate CRL format
200
+ try:
201
+ is_crl_valid(self.crl_path)
202
+ logger.info(f"CRL file validated successfully: {self.crl_path}")
203
+ except Exception as e:
204
+ raise ValueError(f"CRL file is not valid: {e}")
205
+
206
+ return cast(str, self.crl_path)
207
+
208
+ def is_certificate_revoked(self, cert_path: str) -> bool:
209
+ """
210
+ Check if certificate is revoked according to CRL.
211
+
212
+ Args:
213
+ cert_path: Path to certificate file
214
+
215
+ Returns:
216
+ True if certificate is revoked, False otherwise
217
+
218
+ Raises:
219
+ ValueError: If CRL is enabled but not available
220
+ FileNotFoundError: If certificate file is not found
221
+ """
222
+ if not self.crl_enabled:
223
+ return False
224
+
225
+ try:
226
+ crl_data = self.get_crl_data()
227
+ if not crl_data:
228
+ logger.warning("CRL is enabled but no CRL data is available")
229
+ return False
230
+
231
+ is_revoked = bool(is_certificate_revoked(cert_path, crl_data))
232
+
233
+ if is_revoked:
234
+ logger.warning(f"Certificate is revoked according to CRL: {cert_path}")
235
+ else:
236
+ logger.debug(
237
+ f"Certificate is not revoked according to CRL: {cert_path}"
238
+ )
239
+
240
+ return is_revoked
241
+
242
+ except Exception as e:
243
+ logger.error(f"CRL check failed for certificate {cert_path}: {e}")
244
+ # For security, consider certificate invalid if CRL check fails
245
+ return True
246
+
247
+ def validate_certificate_against_crl(self, cert_path: str) -> Dict[str, Any]:
248
+ """
249
+ Validate certificate against CRL and return detailed status.
250
+
251
+ Args:
252
+ cert_path: Path to certificate file
253
+
254
+ Returns:
255
+ Dictionary containing validation results
256
+
257
+ Raises:
258
+ ValueError: If CRL is enabled but not available
259
+ FileNotFoundError: If certificate file is not found
260
+ """
261
+ if not self.crl_enabled:
262
+ return {
263
+ "is_revoked": False,
264
+ "crl_checked": False,
265
+ "crl_source": None,
266
+ "message": "CRL check is disabled",
267
+ }
268
+
269
+ try:
270
+ crl_data = self.get_crl_data()
271
+ if not crl_data:
272
+ logger.warning("CRL is enabled but no CRL data is available")
273
+ return {
274
+ "is_revoked": True, # For security, consider invalid if CRL unavailable
275
+ "crl_checked": False,
276
+ "crl_source": None,
277
+ "message": "CRL is enabled but not available",
278
+ }
279
+
280
+ # Get CRL source info
281
+ crl_source = self.crl_url if self.crl_url else self.crl_path
282
+
283
+ # Validate certificate against CRL
284
+ result = cast(
285
+ Dict[str, Any], validate_certificate_against_crl(cert_path, crl_data)
286
+ )
287
+
288
+ result["crl_checked"] = True
289
+ result["crl_source"] = crl_source
290
+
291
+ return result
292
+
293
+ except Exception as e:
294
+ logger.error(f"CRL validation failed for certificate {cert_path}: {e}")
295
+ # For security, consider certificate invalid if CRL validation fails
296
+ return {
297
+ "is_revoked": True,
298
+ "crl_checked": False,
299
+ "crl_source": self.crl_url if self.crl_url else self.crl_path,
300
+ "message": f"CRL validation failed: {e}",
301
+ }
302
+
303
+ def get_crl_info(self) -> Optional[Dict[str, Any]]:
304
+ """
305
+ Get information about the configured CRL.
306
+
307
+ Returns:
308
+ Dictionary containing CRL information, or None if CRL is not available
309
+ """
310
+ if not self.crl_enabled:
311
+ return None
312
+
313
+ try:
314
+ crl_data = self.get_crl_data()
315
+ if not crl_data:
316
+ return None
317
+
318
+ return cast(Dict[str, Any], get_crl_info(crl_data))
319
+
320
+ except Exception as e:
321
+ logger.error(f"Failed to get CRL info: {e}")
322
+ return None
323
+
324
+ def cleanup_cache(self) -> None:
325
+ """Clean up temporary CRL files."""
326
+ for url, temp_path in self._crl_cache.items():
327
+ try:
328
+ if os.path.exists(temp_path):
329
+ os.unlink(temp_path)
330
+ logger.debug(f"Cleaned up temporary CRL file: {temp_path}")
331
+ except Exception as e:
332
+ logger.warning(f"Failed to cleanup temporary CRL file {temp_path}: {e}")
333
+
334
+ self._crl_cache.clear()
335
+
336
+ def __del__(self) -> None:
337
+ """Cleanup when object is destroyed."""
338
+ self.cleanup_cache()
@@ -0,0 +1,119 @@
1
+ """
2
+ Author: Vasiliy Zdanovskiy
3
+ email: vasilyvz@gmail.com
4
+
5
+ Date utilities for certificate expiry date operations.
6
+ """
7
+
8
+ from datetime import datetime, timezone
9
+ from typing import Optional, Tuple
10
+
11
+
12
+ def parse_certificate_expiry_date(
13
+ expiry_date: str,
14
+ ) -> Tuple[Optional[datetime], Optional[str]]:
15
+ """
16
+ Parse certificate expiry date string to datetime.
17
+
18
+ Args:
19
+ expiry_date: Expiry date string (ISO format)
20
+
21
+ Returns:
22
+ Tuple of (datetime, error_message)
23
+ """
24
+ try:
25
+ # Handle both Z and +00:00 timezone formats
26
+ normalized_date = expiry_date.replace("Z", "+00:00")
27
+ expiry_datetime = datetime.fromisoformat(normalized_date)
28
+ return expiry_datetime, None
29
+ except ValueError as e:
30
+ return None, f"Invalid expiry date format: {str(e)}"
31
+ except Exception as e:
32
+ return None, f"Failed to parse expiry date: {str(e)}"
33
+
34
+
35
+ def calculate_days_until_expiry(
36
+ expiry_date: str,
37
+ ) -> Tuple[Optional[int], Optional[str]]:
38
+ """
39
+ Calculate days until certificate expiry.
40
+
41
+ Args:
42
+ expiry_date: Expiry date string (ISO format)
43
+
44
+ Returns:
45
+ Tuple of (days_until_expiry, error_message)
46
+ """
47
+ expiry_datetime, error = parse_certificate_expiry_date(expiry_date)
48
+ if error:
49
+ return None, error
50
+
51
+ if expiry_datetime is None:
52
+ return None, "Failed to parse expiry date"
53
+
54
+ try:
55
+ # Use timezone-aware datetime for calculation
56
+ now = datetime.now(
57
+ expiry_datetime.tzinfo if expiry_datetime.tzinfo else timezone.utc
58
+ )
59
+ if expiry_datetime.tzinfo is None:
60
+ expiry_datetime = expiry_datetime.replace(tzinfo=timezone.utc)
61
+
62
+ days_until_expiry = (expiry_datetime - now).days
63
+ return days_until_expiry, None
64
+ except Exception as e:
65
+ return None, f"Failed to calculate days until expiry: {str(e)}"
66
+
67
+
68
+ def is_certificate_expired(expiry_date: str) -> Tuple[Optional[bool], Optional[str]]:
69
+ """
70
+ Check if certificate is expired.
71
+
72
+ Args:
73
+ expiry_date: Expiry date string (ISO format)
74
+
75
+ Returns:
76
+ Tuple of (is_expired, error_message)
77
+ """
78
+ days_until_expiry, error = calculate_days_until_expiry(expiry_date)
79
+ if error:
80
+ return None, error
81
+
82
+ if days_until_expiry is None:
83
+ return None, "Failed to calculate days until expiry"
84
+
85
+ return days_until_expiry < 0, None
86
+
87
+
88
+ def determine_expiry_status(
89
+ expiry_date: str,
90
+ warning_days: int = 30,
91
+ critical_days: int = 7,
92
+ ) -> Tuple[Optional[str], Optional[int], Optional[str]]:
93
+ """
94
+ Determine certificate expiry status based on thresholds.
95
+
96
+ Args:
97
+ expiry_date: Expiry date string (ISO format)
98
+ warning_days: Days before expiry to start warning
99
+ critical_days: Days before expiry for critical status
100
+
101
+ Returns:
102
+ Tuple of (status, days_until_expiry, error_message)
103
+ Status can be: "expired", "critical", "warning", "healthy"
104
+ """
105
+ days_until_expiry, error = calculate_days_until_expiry(expiry_date)
106
+ if error:
107
+ return None, None, error
108
+
109
+ if days_until_expiry is None:
110
+ return None, None, "Failed to calculate days until expiry"
111
+
112
+ if days_until_expiry < 0:
113
+ return "expired", days_until_expiry, None
114
+ elif days_until_expiry <= critical_days:
115
+ return "critical", days_until_expiry, None
116
+ elif days_until_expiry <= warning_days:
117
+ return "warning", days_until_expiry, None
118
+ else:
119
+ return "healthy", days_until_expiry, None
@@ -0,0 +1,35 @@
1
+ """Delivery: contracts, exceptions, ws_id, terminal replay, delivery fan-out.
2
+
3
+ Author: Vasiliy Zdanovskiy
4
+ email: vasilyvz@gmail.com
5
+ """
6
+
7
+ from mcp_proxy_adapter.core.delivery.contracts import (
8
+ DeliveryContract,
9
+ DeliveryMode,
10
+ ExecutionAcceptancePayload,
11
+ WsDeliveryTerminalPayload,
12
+ WsSubscribePayload,
13
+ )
14
+ from mcp_proxy_adapter.core.delivery.exceptions import (
15
+ ExecutionDeliveryIdentityCollisionError,
16
+ InvalidDeliveryContractError,
17
+ InvalidSubscriptionCategoryError,
18
+ )
19
+ from mcp_proxy_adapter.core.delivery.terminal_replay_store import (
20
+ TerminalReplayStore,
21
+ )
22
+ from mcp_proxy_adapter.core.delivery.ws_delivery_manager import WsDeliveryManager
23
+
24
+ __all__ = [
25
+ "DeliveryContract",
26
+ "DeliveryMode",
27
+ "ExecutionAcceptancePayload",
28
+ "ExecutionDeliveryIdentityCollisionError",
29
+ "InvalidDeliveryContractError",
30
+ "InvalidSubscriptionCategoryError",
31
+ "TerminalReplayStore",
32
+ "WsDeliveryManager",
33
+ "WsDeliveryTerminalPayload",
34
+ "WsSubscribePayload",
35
+ ]