mcp-proxy-adapter 4.1.1__py3-none-any.whl → 6.0.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- mcp_proxy_adapter/__main__.py +12 -0
- mcp_proxy_adapter/api/app.py +138 -11
- mcp_proxy_adapter/api/handlers.py +16 -1
- mcp_proxy_adapter/api/middleware/__init__.py +30 -29
- mcp_proxy_adapter/api/middleware/auth_adapter.py +235 -0
- mcp_proxy_adapter/api/middleware/error_handling.py +9 -0
- mcp_proxy_adapter/api/middleware/factory.py +219 -0
- mcp_proxy_adapter/api/middleware/logging.py +32 -6
- mcp_proxy_adapter/api/middleware/mtls_adapter.py +305 -0
- mcp_proxy_adapter/api/middleware/mtls_middleware.py +296 -0
- mcp_proxy_adapter/api/middleware/protocol_middleware.py +135 -0
- mcp_proxy_adapter/api/middleware/rate_limit_adapter.py +241 -0
- mcp_proxy_adapter/api/middleware/roles_adapter.py +365 -0
- mcp_proxy_adapter/api/middleware/roles_middleware.py +381 -0
- mcp_proxy_adapter/api/middleware/security.py +376 -0
- mcp_proxy_adapter/api/middleware/token_auth_middleware.py +261 -0
- mcp_proxy_adapter/api/middleware/transport_middleware.py +122 -0
- mcp_proxy_adapter/commands/__init__.py +13 -4
- mcp_proxy_adapter/commands/auth_validation_command.py +408 -0
- mcp_proxy_adapter/commands/base.py +61 -30
- mcp_proxy_adapter/commands/builtin_commands.py +89 -0
- mcp_proxy_adapter/commands/catalog_manager.py +838 -0
- mcp_proxy_adapter/commands/cert_monitor_command.py +620 -0
- mcp_proxy_adapter/commands/certificate_management_command.py +608 -0
- mcp_proxy_adapter/commands/command_registry.py +703 -354
- mcp_proxy_adapter/commands/dependency_manager.py +245 -0
- mcp_proxy_adapter/commands/health_command.py +7 -0
- mcp_proxy_adapter/commands/hooks.py +200 -167
- mcp_proxy_adapter/commands/key_management_command.py +506 -0
- mcp_proxy_adapter/commands/load_command.py +176 -0
- mcp_proxy_adapter/commands/plugins_command.py +235 -0
- mcp_proxy_adapter/commands/protocol_management_command.py +232 -0
- mcp_proxy_adapter/commands/proxy_registration_command.py +268 -0
- mcp_proxy_adapter/commands/reload_command.py +48 -50
- mcp_proxy_adapter/commands/result.py +1 -0
- mcp_proxy_adapter/commands/roles_management_command.py +697 -0
- mcp_proxy_adapter/commands/ssl_setup_command.py +483 -0
- mcp_proxy_adapter/commands/token_management_command.py +529 -0
- mcp_proxy_adapter/commands/transport_management_command.py +144 -0
- mcp_proxy_adapter/commands/unload_command.py +158 -0
- mcp_proxy_adapter/config.py +99 -2
- mcp_proxy_adapter/core/auth_validator.py +606 -0
- mcp_proxy_adapter/core/certificate_utils.py +827 -0
- mcp_proxy_adapter/core/config_converter.py +405 -0
- mcp_proxy_adapter/core/config_validator.py +218 -0
- mcp_proxy_adapter/core/logging.py +11 -0
- mcp_proxy_adapter/core/protocol_manager.py +226 -0
- mcp_proxy_adapter/core/proxy_registration.py +270 -0
- mcp_proxy_adapter/core/role_utils.py +426 -0
- mcp_proxy_adapter/core/security_adapter.py +373 -0
- mcp_proxy_adapter/core/security_factory.py +239 -0
- mcp_proxy_adapter/core/settings.py +1 -0
- mcp_proxy_adapter/core/ssl_utils.py +233 -0
- mcp_proxy_adapter/core/transport_manager.py +292 -0
- mcp_proxy_adapter/custom_openapi.py +22 -11
- mcp_proxy_adapter/examples/basic_server/config.json +58 -23
- mcp_proxy_adapter/examples/basic_server/config_all_protocols.json +54 -0
- mcp_proxy_adapter/examples/basic_server/config_http.json +70 -0
- mcp_proxy_adapter/examples/basic_server/config_http_only.json +52 -0
- mcp_proxy_adapter/examples/basic_server/config_https.json +58 -0
- mcp_proxy_adapter/examples/basic_server/config_mtls.json +58 -0
- mcp_proxy_adapter/examples/basic_server/config_ssl.json +46 -0
- mcp_proxy_adapter/examples/basic_server/server.py +12 -1
- mcp_proxy_adapter/examples/custom_commands/__init__.py +1 -1
- mcp_proxy_adapter/examples/custom_commands/advanced_hooks.py +339 -23
- mcp_proxy_adapter/examples/custom_commands/auto_commands/test_command.py +105 -0
- mcp_proxy_adapter/examples/custom_commands/catalog/commands/test_command.py +129 -0
- mcp_proxy_adapter/examples/custom_commands/config.json +101 -18
- mcp_proxy_adapter/examples/custom_commands/config_all_protocols.json +46 -0
- mcp_proxy_adapter/examples/custom_commands/config_https_only.json +46 -0
- mcp_proxy_adapter/examples/custom_commands/config_https_transport.json +33 -0
- mcp_proxy_adapter/examples/custom_commands/config_mtls_only.json +46 -0
- mcp_proxy_adapter/examples/custom_commands/config_mtls_transport.json +33 -0
- mcp_proxy_adapter/examples/custom_commands/config_single_transport.json +33 -0
- mcp_proxy_adapter/examples/custom_commands/full_help_response.json +1 -0
- mcp_proxy_adapter/examples/custom_commands/generated_openapi.json +629 -0
- mcp_proxy_adapter/examples/custom_commands/get_openapi.py +103 -0
- mcp_proxy_adapter/examples/custom_commands/loadable_commands/test_ignored.py +129 -0
- mcp_proxy_adapter/examples/custom_commands/proxy_connection_manager.py +278 -0
- mcp_proxy_adapter/examples/custom_commands/server.py +92 -68
- mcp_proxy_adapter/examples/custom_commands/simple_openapi_server.py +75 -0
- mcp_proxy_adapter/examples/custom_commands/start_server_with_proxy_manager.py +299 -0
- mcp_proxy_adapter/examples/custom_commands/start_server_with_registration.py +278 -0
- mcp_proxy_adapter/examples/custom_commands/test_openapi.py +27 -0
- mcp_proxy_adapter/examples/custom_commands/test_registry.py +23 -0
- mcp_proxy_adapter/examples/custom_commands/test_simple.py +19 -0
- mcp_proxy_adapter/examples/custom_project_example/README.md +103 -0
- mcp_proxy_adapter/examples/custom_project_example/README_EN.md +103 -0
- mcp_proxy_adapter/examples/simple_custom_commands/README.md +149 -0
- mcp_proxy_adapter/examples/simple_custom_commands/README_EN.md +149 -0
- mcp_proxy_adapter/main.py +175 -0
- mcp_proxy_adapter/schemas/roles_schema.json +162 -0
- mcp_proxy_adapter/tests/unit/test_config.py +53 -0
- mcp_proxy_adapter/version.py +1 -1
- {mcp_proxy_adapter-4.1.1.dist-info → mcp_proxy_adapter-6.0.0.dist-info}/METADATA +2 -1
- mcp_proxy_adapter-6.0.0.dist-info/RECORD +179 -0
- mcp_proxy_adapter/commands/reload_settings_command.py +0 -125
- mcp_proxy_adapter-4.1.1.dist-info/RECORD +0 -110
- {mcp_proxy_adapter-4.1.1.dist-info → mcp_proxy_adapter-6.0.0.dist-info}/WHEEL +0 -0
- {mcp_proxy_adapter-4.1.1.dist-info → mcp_proxy_adapter-6.0.0.dist-info}/licenses/LICENSE +0 -0
- {mcp_proxy_adapter-4.1.1.dist-info → mcp_proxy_adapter-6.0.0.dist-info}/top_level.txt +0 -0
@@ -1,260 +1,293 @@
|
|
1
1
|
"""
|
2
|
-
Module for command
|
2
|
+
Module for command registration hooks.
|
3
3
|
|
4
|
-
This module provides a hook system
|
5
|
-
|
4
|
+
This module provides a hook system for registering custom commands
|
5
|
+
that will be called during system initialization.
|
6
6
|
"""
|
7
7
|
|
8
|
-
from typing import
|
9
|
-
from dataclasses import dataclass
|
8
|
+
from typing import Callable, List, Optional, Dict, Any, Union
|
10
9
|
from enum import Enum
|
11
|
-
|
10
|
+
from dataclasses import dataclass
|
12
11
|
from mcp_proxy_adapter.core.logging import logger
|
13
12
|
|
14
13
|
|
15
14
|
class HookType(Enum):
|
16
|
-
"""Types of hooks."""
|
15
|
+
"""Types of hooks that can be registered."""
|
16
|
+
CUSTOM_COMMANDS = "custom_commands"
|
17
|
+
BEFORE_INIT = "before_init"
|
18
|
+
AFTER_INIT = "after_init"
|
19
|
+
BEFORE_COMMAND = "before_command"
|
20
|
+
AFTER_COMMAND = "after_command"
|
17
21
|
BEFORE_EXECUTION = "before_execution"
|
18
22
|
AFTER_EXECUTION = "after_execution"
|
19
23
|
|
20
24
|
|
21
25
|
@dataclass
|
22
26
|
class HookContext:
|
23
|
-
"""Context passed to hook functions."""
|
24
|
-
command_name: str
|
25
|
-
params: Dict[str, Any]
|
27
|
+
"""Context object passed to hook functions."""
|
26
28
|
hook_type: HookType
|
27
|
-
|
29
|
+
command_name: Optional[str] = None
|
30
|
+
params: Optional[Dict[str, Any]] = None
|
28
31
|
result: Optional[Any] = None
|
32
|
+
registry: Optional[Any] = None
|
33
|
+
metadata: Optional[Dict[str, Any]] = None
|
34
|
+
standard_processing: bool = True
|
35
|
+
|
36
|
+
def __post_init__(self):
|
37
|
+
"""Initialize metadata if not provided."""
|
38
|
+
if self.metadata is None:
|
39
|
+
self.metadata = {}
|
29
40
|
|
30
41
|
|
31
42
|
class CommandHooks:
|
32
43
|
"""
|
33
|
-
|
44
|
+
Hook system for command registration.
|
34
45
|
"""
|
35
46
|
|
36
47
|
def __init__(self):
|
37
|
-
"""
|
38
|
-
|
39
|
-
|
40
|
-
self.
|
41
|
-
self.
|
48
|
+
"""
|
49
|
+
Initialize command hooks.
|
50
|
+
"""
|
51
|
+
self._custom_commands_hooks: List[Callable] = []
|
52
|
+
self._before_init_hooks: List[Callable] = []
|
53
|
+
self._after_init_hooks: List[Callable] = []
|
54
|
+
self._before_command_hooks: List[Callable] = []
|
55
|
+
self._after_command_hooks: List[Callable] = []
|
42
56
|
|
43
|
-
def
|
57
|
+
def register_custom_commands_hook(self, hook_func: Callable) -> None:
|
44
58
|
"""
|
45
|
-
Register a hook
|
59
|
+
Register a hook function for custom commands registration.
|
46
60
|
|
47
61
|
Args:
|
48
|
-
|
49
|
-
|
62
|
+
hook_func: Function that registers custom commands.
|
63
|
+
Should accept registry as parameter.
|
50
64
|
"""
|
51
|
-
|
52
|
-
|
53
|
-
self._before_hooks[command_name].append(hook)
|
54
|
-
logger.debug(f"Registered before hook for command: {command_name}")
|
65
|
+
self._custom_commands_hooks.append(hook_func)
|
66
|
+
logger.debug(f"Registered custom commands hook: {hook_func.__name__}")
|
55
67
|
|
56
|
-
def
|
68
|
+
def register_before_init_hook(self, hook_func: Callable) -> None:
|
57
69
|
"""
|
58
|
-
Register a hook to be
|
70
|
+
Register a hook function to be called before system initialization.
|
59
71
|
|
60
72
|
Args:
|
61
|
-
|
62
|
-
hook: Hook function that takes HookContext as parameter
|
73
|
+
hook_func: Function to call before initialization.
|
63
74
|
"""
|
64
|
-
|
65
|
-
|
66
|
-
self._after_hooks[command_name].append(hook)
|
67
|
-
logger.debug(f"Registered after hook for command: {command_name}")
|
75
|
+
self._before_init_hooks.append(hook_func)
|
76
|
+
logger.debug(f"Registered before init hook: {hook_func.__name__}")
|
68
77
|
|
69
|
-
def
|
78
|
+
def register_after_init_hook(self, hook_func: Callable) -> None:
|
70
79
|
"""
|
71
|
-
Register a
|
80
|
+
Register a hook function to be called after system initialization.
|
72
81
|
|
73
82
|
Args:
|
74
|
-
|
83
|
+
hook_func: Function to call after initialization.
|
75
84
|
"""
|
76
|
-
self.
|
77
|
-
logger.debug("Registered
|
85
|
+
self._after_init_hooks.append(hook_func)
|
86
|
+
logger.debug(f"Registered after init hook: {hook_func.__name__}")
|
78
87
|
|
79
|
-
def
|
88
|
+
def register_before_command_hook(self, hook_func: Callable) -> None:
|
80
89
|
"""
|
81
|
-
Register a
|
90
|
+
Register a hook function to be called before command execution.
|
82
91
|
|
83
92
|
Args:
|
84
|
-
|
93
|
+
hook_func: Function to call before command execution.
|
94
|
+
Should accept command_name and params as parameters.
|
85
95
|
"""
|
86
|
-
self.
|
87
|
-
logger.debug("Registered
|
96
|
+
self._before_command_hooks.append(hook_func)
|
97
|
+
logger.debug(f"Registered before command hook: {hook_func.__name__}")
|
88
98
|
|
89
|
-
def
|
99
|
+
def register_after_command_hook(self, hook_func: Callable) -> None:
|
90
100
|
"""
|
91
|
-
|
101
|
+
Register a hook function to be called after command execution.
|
92
102
|
|
93
103
|
Args:
|
94
|
-
|
95
|
-
|
104
|
+
hook_func: Function to call after command execution.
|
105
|
+
Should accept command_name, params, and result as parameters.
|
96
106
|
"""
|
97
|
-
|
98
|
-
|
99
|
-
self._before_hooks[command_name].remove(hook)
|
100
|
-
logger.debug(f"Unregistered before hook for command: {command_name}")
|
101
|
-
# Remove the command key if no hooks remain
|
102
|
-
if not self._before_hooks[command_name]:
|
103
|
-
del self._before_hooks[command_name]
|
104
|
-
except ValueError:
|
105
|
-
logger.warning(f"Hook not found for command: {command_name}")
|
107
|
+
self._after_command_hooks.append(hook_func)
|
108
|
+
logger.debug(f"Registered after command hook: {hook_func.__name__}")
|
106
109
|
|
107
|
-
def
|
110
|
+
def execute_custom_commands_hooks(self, registry) -> int:
|
108
111
|
"""
|
109
|
-
|
112
|
+
Execute all registered custom commands hooks.
|
110
113
|
|
111
114
|
Args:
|
112
|
-
|
113
|
-
|
115
|
+
registry: Command registry instance.
|
116
|
+
|
117
|
+
Returns:
|
118
|
+
Number of hooks executed.
|
114
119
|
"""
|
115
|
-
|
120
|
+
logger.debug("Executing custom commands hooks...")
|
121
|
+
hooks_executed = 0
|
122
|
+
|
123
|
+
for hook_func in self._custom_commands_hooks:
|
116
124
|
try:
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
125
|
+
hook_func(registry)
|
126
|
+
hooks_executed += 1
|
127
|
+
logger.debug(f"Executed custom commands hook: {hook_func.__name__}")
|
128
|
+
except Exception as e:
|
129
|
+
logger.error(f"Failed to execute custom commands hook {hook_func.__name__}: {e}")
|
130
|
+
|
131
|
+
logger.info(f"Executed {hooks_executed} custom commands hooks")
|
132
|
+
return hooks_executed
|
124
133
|
|
125
|
-
def
|
134
|
+
def execute_before_init_hooks(self) -> int:
|
126
135
|
"""
|
127
|
-
|
136
|
+
Execute all registered before initialization hooks.
|
128
137
|
|
129
|
-
|
130
|
-
|
138
|
+
Returns:
|
139
|
+
Number of hooks executed.
|
131
140
|
"""
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
141
|
+
logger.debug("Executing before init hooks...")
|
142
|
+
hooks_executed = 0
|
143
|
+
|
144
|
+
for hook_func in self._before_init_hooks:
|
145
|
+
try:
|
146
|
+
hook_func()
|
147
|
+
hooks_executed += 1
|
148
|
+
logger.debug(f"Executed before init hook: {hook_func.__name__}")
|
149
|
+
except Exception as e:
|
150
|
+
logger.error(f"Failed to execute before init hook {hook_func.__name__}: {e}")
|
151
|
+
|
152
|
+
logger.debug(f"Executed {hooks_executed} before init hooks")
|
153
|
+
return hooks_executed
|
137
154
|
|
138
|
-
def
|
155
|
+
def execute_after_init_hooks(self) -> int:
|
139
156
|
"""
|
140
|
-
|
157
|
+
Execute all registered after initialization hooks.
|
141
158
|
|
142
|
-
|
143
|
-
|
159
|
+
Returns:
|
160
|
+
Number of hooks executed.
|
144
161
|
"""
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
162
|
+
logger.debug("Executing after init hooks...")
|
163
|
+
hooks_executed = 0
|
164
|
+
|
165
|
+
for hook_func in self._after_init_hooks:
|
166
|
+
try:
|
167
|
+
hook_func()
|
168
|
+
hooks_executed += 1
|
169
|
+
logger.debug(f"Executed after init hook: {hook_func.__name__}")
|
170
|
+
except Exception as e:
|
171
|
+
logger.error(f"Failed to execute after init hook {hook_func.__name__}: {e}")
|
172
|
+
|
173
|
+
logger.debug(f"Executed {hooks_executed} after init hooks")
|
174
|
+
return hooks_executed
|
150
175
|
|
151
|
-
def
|
176
|
+
def execute_before_command_hooks(self, command_name: str, params: Dict[str, Any]) -> int:
|
152
177
|
"""
|
153
|
-
Execute all before
|
178
|
+
Execute all registered before command execution hooks.
|
154
179
|
|
155
180
|
Args:
|
156
|
-
command_name: Name of the command
|
181
|
+
command_name: Name of the command being executed
|
157
182
|
params: Command parameters
|
158
183
|
|
159
184
|
Returns:
|
160
|
-
|
185
|
+
Number of hooks executed.
|
161
186
|
"""
|
162
|
-
|
163
|
-
|
164
|
-
params=params,
|
165
|
-
hook_type=HookType.BEFORE_EXECUTION
|
166
|
-
)
|
187
|
+
logger.debug(f"Executing before command hooks for: {command_name}")
|
188
|
+
hooks_executed = 0
|
167
189
|
|
168
|
-
|
169
|
-
for hook in self._global_before_hooks:
|
190
|
+
for hook_func in self._before_command_hooks:
|
170
191
|
try:
|
171
|
-
|
192
|
+
hook_func(command_name, params)
|
193
|
+
hooks_executed += 1
|
194
|
+
logger.debug(f"Executed before command hook: {hook_func.__name__}")
|
172
195
|
except Exception as e:
|
173
|
-
logger.error(f"
|
196
|
+
logger.error(f"Failed to execute before command hook {hook_func.__name__}: {e}")
|
174
197
|
|
175
|
-
|
176
|
-
|
177
|
-
for hook in self._before_hooks[command_name]:
|
178
|
-
try:
|
179
|
-
hook(context)
|
180
|
-
except Exception as e:
|
181
|
-
logger.error(f"Error in before hook for command {command_name}: {e}")
|
182
|
-
|
183
|
-
return context
|
198
|
+
logger.debug(f"Executed {hooks_executed} before command hooks")
|
199
|
+
return hooks_executed
|
184
200
|
|
185
|
-
def
|
201
|
+
def execute_after_command_hooks(self, command_name: str, params: Dict[str, Any], result: Any) -> int:
|
186
202
|
"""
|
187
|
-
Execute all after
|
203
|
+
Execute all registered after command execution hooks.
|
188
204
|
|
189
205
|
Args:
|
190
|
-
command_name: Name of the command
|
191
|
-
params: Command parameters
|
206
|
+
command_name: Name of the command that was executed
|
207
|
+
params: Command parameters that were used
|
192
208
|
result: Command execution result
|
193
209
|
|
194
210
|
Returns:
|
195
|
-
|
211
|
+
Number of hooks executed.
|
196
212
|
"""
|
197
|
-
|
198
|
-
|
199
|
-
params=params,
|
200
|
-
hook_type=HookType.AFTER_EXECUTION,
|
201
|
-
result=result
|
202
|
-
)
|
213
|
+
logger.debug(f"Executing after command hooks for: {command_name}")
|
214
|
+
hooks_executed = 0
|
203
215
|
|
204
|
-
|
205
|
-
if command_name in self._after_hooks:
|
206
|
-
for hook in self._after_hooks[command_name]:
|
207
|
-
try:
|
208
|
-
hook(context)
|
209
|
-
except Exception as e:
|
210
|
-
logger.error(f"Error in after hook for command {command_name}: {e}")
|
211
|
-
|
212
|
-
# Execute global after hooks
|
213
|
-
for hook in self._global_after_hooks:
|
216
|
+
for hook_func in self._after_command_hooks:
|
214
217
|
try:
|
215
|
-
|
218
|
+
hook_func(command_name, params, result)
|
219
|
+
hooks_executed += 1
|
220
|
+
logger.debug(f"Executed after command hook: {hook_func.__name__}")
|
216
221
|
except Exception as e:
|
217
|
-
logger.error(f"
|
222
|
+
logger.error(f"Failed to execute after command hook {hook_func.__name__}: {e}")
|
218
223
|
|
219
|
-
|
224
|
+
logger.debug(f"Executed {hooks_executed} after command hooks")
|
225
|
+
return hooks_executed
|
220
226
|
|
221
|
-
def clear_hooks(self
|
227
|
+
def clear_hooks(self) -> None:
|
222
228
|
"""
|
223
|
-
Clear all
|
224
|
-
|
225
|
-
Args:
|
226
|
-
command_name: If provided, clear hooks only for this command.
|
227
|
-
If None, clear all hooks.
|
229
|
+
Clear all registered hooks.
|
228
230
|
"""
|
229
|
-
|
230
|
-
|
231
|
-
|
232
|
-
|
233
|
-
|
234
|
-
|
235
|
-
logger.debug("Cleared all hooks")
|
236
|
-
else:
|
237
|
-
# Clear hooks for specific command
|
238
|
-
if command_name in self._before_hooks:
|
239
|
-
del self._before_hooks[command_name]
|
240
|
-
if command_name in self._after_hooks:
|
241
|
-
del self._after_hooks[command_name]
|
242
|
-
logger.debug(f"Cleared hooks for command: {command_name}")
|
243
|
-
|
244
|
-
def get_hook_info(self) -> Dict[str, Any]:
|
245
|
-
"""
|
246
|
-
Get information about registered hooks.
|
247
|
-
|
248
|
-
Returns:
|
249
|
-
Dictionary with hook information
|
250
|
-
"""
|
251
|
-
return {
|
252
|
-
"before_hooks": {cmd: len(hooks) for cmd, hooks in self._before_hooks.items()},
|
253
|
-
"after_hooks": {cmd: len(hooks) for cmd, hooks in self._after_hooks.items()},
|
254
|
-
"global_before_hooks": len(self._global_before_hooks),
|
255
|
-
"global_after_hooks": len(self._global_after_hooks)
|
256
|
-
}
|
231
|
+
self._custom_commands_hooks.clear()
|
232
|
+
self._before_init_hooks.clear()
|
233
|
+
self._after_init_hooks.clear()
|
234
|
+
self._before_command_hooks.clear()
|
235
|
+
self._after_command_hooks.clear()
|
236
|
+
logger.debug("Cleared all hooks")
|
257
237
|
|
258
238
|
|
259
239
|
# Global hooks instance
|
260
|
-
hooks = CommandHooks()
|
240
|
+
hooks = CommandHooks()
|
241
|
+
|
242
|
+
|
243
|
+
def register_custom_commands_hook(hook_func: Callable) -> None:
|
244
|
+
"""
|
245
|
+
Register a hook function for custom commands registration.
|
246
|
+
|
247
|
+
Args:
|
248
|
+
hook_func: Function that registers custom commands.
|
249
|
+
Should accept registry as parameter.
|
250
|
+
"""
|
251
|
+
hooks.register_custom_commands_hook(hook_func)
|
252
|
+
|
253
|
+
|
254
|
+
def register_before_init_hook(hook_func: Callable) -> None:
|
255
|
+
"""
|
256
|
+
Register a hook function to be called before system initialization.
|
257
|
+
|
258
|
+
Args:
|
259
|
+
hook_func: Function to call before initialization.
|
260
|
+
"""
|
261
|
+
hooks.register_before_init_hook(hook_func)
|
262
|
+
|
263
|
+
|
264
|
+
def register_after_init_hook(hook_func: Callable) -> None:
|
265
|
+
"""
|
266
|
+
Register a hook function to be called after system initialization.
|
267
|
+
|
268
|
+
Args:
|
269
|
+
hook_func: Function to call after initialization.
|
270
|
+
"""
|
271
|
+
hooks.register_after_init_hook(hook_func)
|
272
|
+
|
273
|
+
|
274
|
+
def register_before_command_hook(hook_func: Callable) -> None:
|
275
|
+
"""
|
276
|
+
Register a hook function to be called before command execution.
|
277
|
+
|
278
|
+
Args:
|
279
|
+
hook_func: Function to call before command execution.
|
280
|
+
Should accept command_name and params as parameters.
|
281
|
+
"""
|
282
|
+
hooks.register_before_command_hook(hook_func)
|
283
|
+
|
284
|
+
|
285
|
+
def register_after_command_hook(hook_func: Callable) -> None:
|
286
|
+
"""
|
287
|
+
Register a hook function to be called after command execution.
|
288
|
+
|
289
|
+
Args:
|
290
|
+
hook_func: Function to call after command execution.
|
291
|
+
Should accept command_name, params, and result as parameters.
|
292
|
+
"""
|
293
|
+
hooks.register_after_command_hook(hook_func)
|