mcp-proxy-adapter 6.3.3__py3-none-any.whl → 6.3.5__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.
- mcp_proxy_adapter/__init__.py +9 -5
- mcp_proxy_adapter/__main__.py +1 -1
- mcp_proxy_adapter/api/app.py +227 -176
- mcp_proxy_adapter/api/handlers.py +68 -60
- mcp_proxy_adapter/api/middleware/__init__.py +7 -5
- mcp_proxy_adapter/api/middleware/base.py +19 -16
- mcp_proxy_adapter/api/middleware/command_permission_middleware.py +44 -34
- mcp_proxy_adapter/api/middleware/error_handling.py +57 -67
- mcp_proxy_adapter/api/middleware/factory.py +50 -52
- mcp_proxy_adapter/api/middleware/logging.py +46 -30
- mcp_proxy_adapter/api/middleware/performance.py +19 -16
- mcp_proxy_adapter/api/middleware/protocol_middleware.py +80 -50
- mcp_proxy_adapter/api/middleware/transport_middleware.py +26 -24
- mcp_proxy_adapter/api/middleware/unified_security.py +70 -51
- mcp_proxy_adapter/api/middleware/user_info_middleware.py +43 -34
- mcp_proxy_adapter/api/schemas.py +69 -43
- mcp_proxy_adapter/api/tool_integration.py +83 -63
- mcp_proxy_adapter/api/tools.py +60 -50
- mcp_proxy_adapter/commands/__init__.py +15 -6
- mcp_proxy_adapter/commands/auth_validation_command.py +107 -110
- mcp_proxy_adapter/commands/base.py +108 -112
- mcp_proxy_adapter/commands/builtin_commands.py +28 -18
- mcp_proxy_adapter/commands/catalog_manager.py +394 -265
- mcp_proxy_adapter/commands/cert_monitor_command.py +222 -204
- mcp_proxy_adapter/commands/certificate_management_command.py +210 -213
- mcp_proxy_adapter/commands/command_registry.py +275 -226
- mcp_proxy_adapter/commands/config_command.py +48 -33
- mcp_proxy_adapter/commands/dependency_container.py +22 -23
- mcp_proxy_adapter/commands/dependency_manager.py +65 -56
- mcp_proxy_adapter/commands/echo_command.py +15 -15
- mcp_proxy_adapter/commands/health_command.py +31 -29
- mcp_proxy_adapter/commands/help_command.py +97 -61
- mcp_proxy_adapter/commands/hooks.py +65 -49
- mcp_proxy_adapter/commands/key_management_command.py +148 -147
- mcp_proxy_adapter/commands/load_command.py +58 -40
- mcp_proxy_adapter/commands/plugins_command.py +80 -54
- mcp_proxy_adapter/commands/protocol_management_command.py +60 -48
- mcp_proxy_adapter/commands/proxy_registration_command.py +107 -115
- mcp_proxy_adapter/commands/reload_command.py +43 -37
- mcp_proxy_adapter/commands/result.py +26 -33
- mcp_proxy_adapter/commands/role_test_command.py +26 -26
- mcp_proxy_adapter/commands/roles_management_command.py +176 -173
- mcp_proxy_adapter/commands/security_command.py +134 -122
- mcp_proxy_adapter/commands/settings_command.py +47 -56
- mcp_proxy_adapter/commands/ssl_setup_command.py +109 -129
- mcp_proxy_adapter/commands/token_management_command.py +129 -158
- mcp_proxy_adapter/commands/transport_management_command.py +41 -36
- mcp_proxy_adapter/commands/unload_command.py +42 -37
- mcp_proxy_adapter/config.py +36 -35
- mcp_proxy_adapter/core/__init__.py +19 -21
- mcp_proxy_adapter/core/app_factory.py +30 -9
- mcp_proxy_adapter/core/app_runner.py +81 -64
- mcp_proxy_adapter/core/auth_validator.py +176 -182
- mcp_proxy_adapter/core/certificate_utils.py +469 -426
- mcp_proxy_adapter/core/client.py +155 -126
- mcp_proxy_adapter/core/client_manager.py +60 -54
- mcp_proxy_adapter/core/client_security.py +108 -88
- mcp_proxy_adapter/core/config_converter.py +176 -143
- mcp_proxy_adapter/core/config_validator.py +12 -4
- mcp_proxy_adapter/core/crl_utils.py +21 -7
- mcp_proxy_adapter/core/errors.py +64 -20
- mcp_proxy_adapter/core/logging.py +34 -29
- mcp_proxy_adapter/core/mtls_asgi.py +29 -25
- mcp_proxy_adapter/core/mtls_asgi_app.py +66 -54
- mcp_proxy_adapter/core/protocol_manager.py +154 -104
- mcp_proxy_adapter/core/proxy_client.py +202 -144
- mcp_proxy_adapter/core/proxy_registration.py +12 -2
- mcp_proxy_adapter/core/role_utils.py +139 -125
- mcp_proxy_adapter/core/security_adapter.py +88 -77
- mcp_proxy_adapter/core/security_factory.py +50 -44
- mcp_proxy_adapter/core/security_integration.py +72 -24
- mcp_proxy_adapter/core/server_adapter.py +68 -64
- mcp_proxy_adapter/core/server_engine.py +71 -53
- mcp_proxy_adapter/core/settings.py +68 -58
- mcp_proxy_adapter/core/ssl_utils.py +69 -56
- mcp_proxy_adapter/core/transport_manager.py +72 -60
- mcp_proxy_adapter/core/unified_config_adapter.py +201 -150
- mcp_proxy_adapter/core/utils.py +4 -2
- mcp_proxy_adapter/custom_openapi.py +107 -99
- mcp_proxy_adapter/examples/basic_framework/main.py +9 -2
- mcp_proxy_adapter/examples/commands/__init__.py +1 -1
- mcp_proxy_adapter/examples/create_certificates_simple.py +182 -71
- mcp_proxy_adapter/examples/debug_request_state.py +38 -19
- mcp_proxy_adapter/examples/debug_role_chain.py +53 -20
- mcp_proxy_adapter/examples/demo_client.py +48 -36
- mcp_proxy_adapter/examples/examples/basic_framework/main.py +9 -2
- mcp_proxy_adapter/examples/examples/full_application/__init__.py +1 -0
- mcp_proxy_adapter/examples/examples/full_application/commands/custom_echo_command.py +22 -10
- mcp_proxy_adapter/examples/examples/full_application/commands/dynamic_calculator_command.py +24 -17
- mcp_proxy_adapter/examples/examples/full_application/hooks/application_hooks.py +16 -3
- mcp_proxy_adapter/examples/examples/full_application/hooks/builtin_command_hooks.py +13 -3
- mcp_proxy_adapter/examples/examples/full_application/main.py +27 -2
- mcp_proxy_adapter/examples/examples/full_application/proxy_endpoints.py +48 -14
- mcp_proxy_adapter/examples/full_application/__init__.py +1 -0
- mcp_proxy_adapter/examples/full_application/commands/custom_echo_command.py +22 -10
- mcp_proxy_adapter/examples/full_application/commands/dynamic_calculator_command.py +24 -17
- mcp_proxy_adapter/examples/full_application/hooks/application_hooks.py +16 -3
- mcp_proxy_adapter/examples/full_application/hooks/builtin_command_hooks.py +13 -3
- mcp_proxy_adapter/examples/full_application/main.py +27 -2
- mcp_proxy_adapter/examples/full_application/proxy_endpoints.py +48 -14
- mcp_proxy_adapter/examples/generate_all_certificates.py +198 -73
- mcp_proxy_adapter/examples/generate_certificates.py +31 -16
- mcp_proxy_adapter/examples/generate_certificates_and_tokens.py +220 -74
- mcp_proxy_adapter/examples/generate_test_configs.py +68 -91
- mcp_proxy_adapter/examples/proxy_registration_example.py +76 -75
- mcp_proxy_adapter/examples/run_example.py +23 -5
- mcp_proxy_adapter/examples/run_full_test_suite.py +109 -71
- mcp_proxy_adapter/examples/run_proxy_server.py +22 -9
- mcp_proxy_adapter/examples/run_security_tests.py +103 -41
- mcp_proxy_adapter/examples/run_security_tests_fixed.py +72 -36
- mcp_proxy_adapter/examples/scripts/config_generator.py +288 -187
- mcp_proxy_adapter/examples/scripts/create_certificates_simple.py +185 -72
- mcp_proxy_adapter/examples/scripts/generate_certificates_and_tokens.py +220 -74
- mcp_proxy_adapter/examples/security_test_client.py +196 -127
- mcp_proxy_adapter/examples/setup_test_environment.py +17 -29
- mcp_proxy_adapter/examples/test_config.py +19 -4
- mcp_proxy_adapter/examples/test_config_generator.py +23 -7
- mcp_proxy_adapter/examples/test_examples.py +84 -56
- mcp_proxy_adapter/examples/universal_client.py +119 -62
- mcp_proxy_adapter/openapi.py +108 -115
- mcp_proxy_adapter/utils/config_generator.py +429 -274
- mcp_proxy_adapter/version.py +1 -2
- {mcp_proxy_adapter-6.3.3.dist-info → mcp_proxy_adapter-6.3.5.dist-info}/METADATA +1 -1
- mcp_proxy_adapter-6.3.5.dist-info/RECORD +143 -0
- mcp_proxy_adapter-6.3.3.dist-info/RECORD +0 -143
- {mcp_proxy_adapter-6.3.3.dist-info → mcp_proxy_adapter-6.3.5.dist-info}/WHEEL +0 -0
- {mcp_proxy_adapter-6.3.3.dist-info → mcp_proxy_adapter-6.3.5.dist-info}/entry_points.txt +0 -0
- {mcp_proxy_adapter-6.3.3.dist-info → mcp_proxy_adapter-6.3.5.dist-info}/licenses/LICENSE +0 -0
- {mcp_proxy_adapter-6.3.3.dist-info → mcp_proxy_adapter-6.3.5.dist-info}/top_level.txt +0 -0
@@ -13,6 +13,7 @@ from mcp_proxy_adapter.core.logging import logger
|
|
13
13
|
|
14
14
|
class HookType(Enum):
|
15
15
|
"""Types of hooks that can be registered."""
|
16
|
+
|
16
17
|
CUSTOM_COMMANDS = "custom_commands"
|
17
18
|
BEFORE_INIT = "before_init"
|
18
19
|
AFTER_INIT = "after_init"
|
@@ -25,6 +26,7 @@ class HookType(Enum):
|
|
25
26
|
@dataclass
|
26
27
|
class HookContext:
|
27
28
|
"""Context object passed to hook functions."""
|
29
|
+
|
28
30
|
hook_type: HookType
|
29
31
|
command_name: Optional[str] = None
|
30
32
|
params: Optional[Dict[str, Any]] = None
|
@@ -32,7 +34,7 @@ class HookContext:
|
|
32
34
|
registry: Optional[Any] = None
|
33
35
|
metadata: Optional[Dict[str, Any]] = None
|
34
36
|
standard_processing: bool = True
|
35
|
-
|
37
|
+
|
36
38
|
def __post_init__(self):
|
37
39
|
"""Initialize metadata if not provided."""
|
38
40
|
if self.metadata is None:
|
@@ -43,7 +45,7 @@ class CommandHooks:
|
|
43
45
|
"""
|
44
46
|
Hook system for command registration.
|
45
47
|
"""
|
46
|
-
|
48
|
+
|
47
49
|
def __init__(self):
|
48
50
|
"""
|
49
51
|
Initialize command hooks.
|
@@ -53,177 +55,191 @@ class CommandHooks:
|
|
53
55
|
self._after_init_hooks: List[Callable] = []
|
54
56
|
self._before_command_hooks: List[Callable] = []
|
55
57
|
self._after_command_hooks: List[Callable] = []
|
56
|
-
|
58
|
+
|
57
59
|
def register_custom_commands_hook(self, hook_func: Callable) -> None:
|
58
60
|
"""
|
59
61
|
Register a hook function for custom commands registration.
|
60
|
-
|
62
|
+
|
61
63
|
Args:
|
62
64
|
hook_func: Function that registers custom commands.
|
63
65
|
Should accept registry as parameter.
|
64
66
|
"""
|
65
67
|
self._custom_commands_hooks.append(hook_func)
|
66
68
|
logger.debug(f"Registered custom commands hook: {hook_func.__name__}")
|
67
|
-
|
69
|
+
|
68
70
|
def register_before_init_hook(self, hook_func: Callable) -> None:
|
69
71
|
"""
|
70
72
|
Register a hook function to be called before system initialization.
|
71
|
-
|
73
|
+
|
72
74
|
Args:
|
73
75
|
hook_func: Function to call before initialization.
|
74
76
|
"""
|
75
77
|
self._before_init_hooks.append(hook_func)
|
76
78
|
logger.debug(f"Registered before init hook: {hook_func.__name__}")
|
77
|
-
|
79
|
+
|
78
80
|
def register_after_init_hook(self, hook_func: Callable) -> None:
|
79
81
|
"""
|
80
82
|
Register a hook function to be called after system initialization.
|
81
|
-
|
83
|
+
|
82
84
|
Args:
|
83
85
|
hook_func: Function to call after initialization.
|
84
86
|
"""
|
85
87
|
self._after_init_hooks.append(hook_func)
|
86
88
|
logger.debug(f"Registered after init hook: {hook_func.__name__}")
|
87
|
-
|
89
|
+
|
88
90
|
def register_before_command_hook(self, hook_func: Callable) -> None:
|
89
91
|
"""
|
90
92
|
Register a hook function to be called before command execution.
|
91
|
-
|
93
|
+
|
92
94
|
Args:
|
93
95
|
hook_func: Function to call before command execution.
|
94
96
|
Should accept command_name and params as parameters.
|
95
97
|
"""
|
96
98
|
self._before_command_hooks.append(hook_func)
|
97
99
|
logger.debug(f"Registered before command hook: {hook_func.__name__}")
|
98
|
-
|
100
|
+
|
99
101
|
def register_after_command_hook(self, hook_func: Callable) -> None:
|
100
102
|
"""
|
101
103
|
Register a hook function to be called after command execution.
|
102
|
-
|
104
|
+
|
103
105
|
Args:
|
104
106
|
hook_func: Function to call after command execution.
|
105
107
|
Should accept command_name, params, and result as parameters.
|
106
108
|
"""
|
107
109
|
self._after_command_hooks.append(hook_func)
|
108
110
|
logger.debug(f"Registered after command hook: {hook_func.__name__}")
|
109
|
-
|
111
|
+
|
110
112
|
def execute_custom_commands_hooks(self, registry) -> int:
|
111
113
|
"""
|
112
114
|
Execute all registered custom commands hooks.
|
113
|
-
|
115
|
+
|
114
116
|
Args:
|
115
117
|
registry: Command registry instance.
|
116
|
-
|
118
|
+
|
117
119
|
Returns:
|
118
120
|
Number of hooks executed.
|
119
121
|
"""
|
120
122
|
logger.debug("Executing custom commands hooks...")
|
121
123
|
hooks_executed = 0
|
122
|
-
|
124
|
+
|
123
125
|
for hook_func in self._custom_commands_hooks:
|
124
126
|
try:
|
125
127
|
hook_func(registry)
|
126
128
|
hooks_executed += 1
|
127
129
|
logger.debug(f"Executed custom commands hook: {hook_func.__name__}")
|
128
130
|
except Exception as e:
|
129
|
-
logger.error(
|
130
|
-
|
131
|
+
logger.error(
|
132
|
+
f"Failed to execute custom commands hook {hook_func.__name__}: {e}"
|
133
|
+
)
|
134
|
+
|
131
135
|
logger.info(f"Executed {hooks_executed} custom commands hooks")
|
132
136
|
return hooks_executed
|
133
|
-
|
137
|
+
|
134
138
|
def execute_before_init_hooks(self) -> int:
|
135
139
|
"""
|
136
140
|
Execute all registered before initialization hooks.
|
137
|
-
|
141
|
+
|
138
142
|
Returns:
|
139
143
|
Number of hooks executed.
|
140
144
|
"""
|
141
145
|
logger.debug("Executing before init hooks...")
|
142
146
|
hooks_executed = 0
|
143
|
-
|
147
|
+
|
144
148
|
for hook_func in self._before_init_hooks:
|
145
149
|
try:
|
146
150
|
hook_func()
|
147
151
|
hooks_executed += 1
|
148
152
|
logger.debug(f"Executed before init hook: {hook_func.__name__}")
|
149
153
|
except Exception as e:
|
150
|
-
logger.error(
|
151
|
-
|
154
|
+
logger.error(
|
155
|
+
f"Failed to execute before init hook {hook_func.__name__}: {e}"
|
156
|
+
)
|
157
|
+
|
152
158
|
logger.debug(f"Executed {hooks_executed} before init hooks")
|
153
159
|
return hooks_executed
|
154
|
-
|
160
|
+
|
155
161
|
def execute_after_init_hooks(self) -> int:
|
156
162
|
"""
|
157
163
|
Execute all registered after initialization hooks.
|
158
|
-
|
164
|
+
|
159
165
|
Returns:
|
160
166
|
Number of hooks executed.
|
161
167
|
"""
|
162
168
|
logger.debug("Executing after init hooks...")
|
163
169
|
hooks_executed = 0
|
164
|
-
|
170
|
+
|
165
171
|
for hook_func in self._after_init_hooks:
|
166
172
|
try:
|
167
173
|
hook_func()
|
168
174
|
hooks_executed += 1
|
169
175
|
logger.debug(f"Executed after init hook: {hook_func.__name__}")
|
170
176
|
except Exception as e:
|
171
|
-
logger.error(
|
172
|
-
|
177
|
+
logger.error(
|
178
|
+
f"Failed to execute after init hook {hook_func.__name__}: {e}"
|
179
|
+
)
|
180
|
+
|
173
181
|
logger.debug(f"Executed {hooks_executed} after init hooks")
|
174
182
|
return hooks_executed
|
175
|
-
|
176
|
-
def execute_before_command_hooks(
|
183
|
+
|
184
|
+
def execute_before_command_hooks(
|
185
|
+
self, command_name: str, params: Dict[str, Any]
|
186
|
+
) -> int:
|
177
187
|
"""
|
178
188
|
Execute all registered before command execution hooks.
|
179
|
-
|
189
|
+
|
180
190
|
Args:
|
181
191
|
command_name: Name of the command being executed
|
182
192
|
params: Command parameters
|
183
|
-
|
193
|
+
|
184
194
|
Returns:
|
185
195
|
Number of hooks executed.
|
186
196
|
"""
|
187
197
|
logger.debug(f"Executing before command hooks for: {command_name}")
|
188
198
|
hooks_executed = 0
|
189
|
-
|
199
|
+
|
190
200
|
for hook_func in self._before_command_hooks:
|
191
201
|
try:
|
192
202
|
hook_func(command_name, params)
|
193
203
|
hooks_executed += 1
|
194
204
|
logger.debug(f"Executed before command hook: {hook_func.__name__}")
|
195
205
|
except Exception as e:
|
196
|
-
logger.error(
|
197
|
-
|
206
|
+
logger.error(
|
207
|
+
f"Failed to execute before command hook {hook_func.__name__}: {e}"
|
208
|
+
)
|
209
|
+
|
198
210
|
logger.debug(f"Executed {hooks_executed} before command hooks")
|
199
211
|
return hooks_executed
|
200
|
-
|
201
|
-
def execute_after_command_hooks(
|
212
|
+
|
213
|
+
def execute_after_command_hooks(
|
214
|
+
self, command_name: str, params: Dict[str, Any], result: Any
|
215
|
+
) -> int:
|
202
216
|
"""
|
203
217
|
Execute all registered after command execution hooks.
|
204
|
-
|
218
|
+
|
205
219
|
Args:
|
206
220
|
command_name: Name of the command that was executed
|
207
221
|
params: Command parameters that were used
|
208
222
|
result: Command execution result
|
209
|
-
|
223
|
+
|
210
224
|
Returns:
|
211
225
|
Number of hooks executed.
|
212
226
|
"""
|
213
227
|
logger.debug(f"Executing after command hooks for: {command_name}")
|
214
228
|
hooks_executed = 0
|
215
|
-
|
229
|
+
|
216
230
|
for hook_func in self._after_command_hooks:
|
217
231
|
try:
|
218
232
|
hook_func(command_name, params, result)
|
219
233
|
hooks_executed += 1
|
220
234
|
logger.debug(f"Executed after command hook: {hook_func.__name__}")
|
221
235
|
except Exception as e:
|
222
|
-
logger.error(
|
223
|
-
|
236
|
+
logger.error(
|
237
|
+
f"Failed to execute after command hook {hook_func.__name__}: {e}"
|
238
|
+
)
|
239
|
+
|
224
240
|
logger.debug(f"Executed {hooks_executed} after command hooks")
|
225
241
|
return hooks_executed
|
226
|
-
|
242
|
+
|
227
243
|
def clear_hooks(self) -> None:
|
228
244
|
"""
|
229
245
|
Clear all registered hooks.
|
@@ -243,7 +259,7 @@ hooks = CommandHooks()
|
|
243
259
|
def register_custom_commands_hook(hook_func: Callable) -> None:
|
244
260
|
"""
|
245
261
|
Register a hook function for custom commands registration.
|
246
|
-
|
262
|
+
|
247
263
|
Args:
|
248
264
|
hook_func: Function that registers custom commands.
|
249
265
|
Should accept registry as parameter.
|
@@ -254,7 +270,7 @@ def register_custom_commands_hook(hook_func: Callable) -> None:
|
|
254
270
|
def register_before_init_hook(hook_func: Callable) -> None:
|
255
271
|
"""
|
256
272
|
Register a hook function to be called before system initialization.
|
257
|
-
|
273
|
+
|
258
274
|
Args:
|
259
275
|
hook_func: Function to call before initialization.
|
260
276
|
"""
|
@@ -264,7 +280,7 @@ def register_before_init_hook(hook_func: Callable) -> None:
|
|
264
280
|
def register_after_init_hook(hook_func: Callable) -> None:
|
265
281
|
"""
|
266
282
|
Register a hook function to be called after system initialization.
|
267
|
-
|
283
|
+
|
268
284
|
Args:
|
269
285
|
hook_func: Function to call after initialization.
|
270
286
|
"""
|
@@ -274,7 +290,7 @@ def register_after_init_hook(hook_func: Callable) -> None:
|
|
274
290
|
def register_before_command_hook(hook_func: Callable) -> None:
|
275
291
|
"""
|
276
292
|
Register a hook function to be called before command execution.
|
277
|
-
|
293
|
+
|
278
294
|
Args:
|
279
295
|
hook_func: Function to call before command execution.
|
280
296
|
Should accept command_name and params as parameters.
|
@@ -285,9 +301,9 @@ def register_before_command_hook(hook_func: Callable) -> None:
|
|
285
301
|
def register_after_command_hook(hook_func: Callable) -> None:
|
286
302
|
"""
|
287
303
|
Register a hook function to be called after command execution.
|
288
|
-
|
304
|
+
|
289
305
|
Args:
|
290
306
|
hook_func: Function to call after command execution.
|
291
307
|
Should accept command_name, params, and result as parameters.
|
292
308
|
"""
|
293
|
-
hooks.register_after_command_hook(hook_func)
|
309
|
+
hooks.register_after_command_hook(hook_func)
|