mcp-proxy-adapter 4.1.1__py3-none-any.whl → 6.0.1__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- mcp_proxy_adapter/__main__.py +32 -0
- mcp_proxy_adapter/api/app.py +290 -33
- mcp_proxy_adapter/api/handlers.py +32 -6
- mcp_proxy_adapter/api/middleware/__init__.py +38 -32
- mcp_proxy_adapter/api/middleware/command_permission_middleware.py +148 -0
- mcp_proxy_adapter/api/middleware/error_handling.py +9 -0
- mcp_proxy_adapter/api/middleware/factory.py +243 -0
- mcp_proxy_adapter/api/middleware/logging.py +32 -6
- mcp_proxy_adapter/api/middleware/protocol_middleware.py +201 -0
- mcp_proxy_adapter/api/middleware/transport_middleware.py +122 -0
- mcp_proxy_adapter/api/middleware/unified_security.py +197 -0
- mcp_proxy_adapter/api/middleware/user_info_middleware.py +158 -0
- mcp_proxy_adapter/commands/__init__.py +19 -4
- mcp_proxy_adapter/commands/auth_validation_command.py +408 -0
- mcp_proxy_adapter/commands/base.py +66 -32
- mcp_proxy_adapter/commands/builtin_commands.py +95 -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 +711 -354
- mcp_proxy_adapter/commands/dependency_manager.py +245 -0
- mcp_proxy_adapter/commands/echo_command.py +81 -0
- mcp_proxy_adapter/commands/health_command.py +8 -1
- mcp_proxy_adapter/commands/help_command.py +21 -14
- 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 +409 -0
- mcp_proxy_adapter/commands/reload_command.py +48 -50
- mcp_proxy_adapter/commands/result.py +1 -0
- mcp_proxy_adapter/commands/role_test_command.py +141 -0
- mcp_proxy_adapter/commands/roles_management_command.py +697 -0
- mcp_proxy_adapter/commands/security_command.py +488 -0
- mcp_proxy_adapter/commands/ssl_setup_command.py +366 -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 +394 -14
- mcp_proxy_adapter/core/app_factory.py +410 -0
- mcp_proxy_adapter/core/app_runner.py +272 -0
- mcp_proxy_adapter/core/auth_validator.py +606 -0
- mcp_proxy_adapter/core/certificate_utils.py +1045 -0
- mcp_proxy_adapter/core/client.py +574 -0
- mcp_proxy_adapter/core/client_manager.py +284 -0
- mcp_proxy_adapter/core/client_security.py +384 -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 +19 -3
- mcp_proxy_adapter/core/mtls_asgi.py +156 -0
- mcp_proxy_adapter/core/mtls_asgi_app.py +187 -0
- mcp_proxy_adapter/core/protocol_manager.py +385 -0
- mcp_proxy_adapter/core/proxy_client.py +602 -0
- mcp_proxy_adapter/core/proxy_registration.py +522 -0
- mcp_proxy_adapter/core/role_utils.py +426 -0
- mcp_proxy_adapter/core/security_adapter.py +370 -0
- mcp_proxy_adapter/core/security_factory.py +239 -0
- mcp_proxy_adapter/core/security_integration.py +286 -0
- mcp_proxy_adapter/core/server_adapter.py +282 -0
- mcp_proxy_adapter/core/server_engine.py +270 -0
- mcp_proxy_adapter/core/settings.py +1 -0
- mcp_proxy_adapter/core/ssl_utils.py +234 -0
- mcp_proxy_adapter/core/transport_manager.py +292 -0
- mcp_proxy_adapter/core/unified_config_adapter.py +579 -0
- mcp_proxy_adapter/custom_openapi.py +22 -11
- mcp_proxy_adapter/examples/__init__.py +13 -4
- mcp_proxy_adapter/examples/basic_framework/__init__.py +9 -0
- mcp_proxy_adapter/examples/basic_framework/commands/__init__.py +4 -0
- mcp_proxy_adapter/examples/basic_framework/hooks/__init__.py +4 -0
- mcp_proxy_adapter/examples/basic_framework/main.py +44 -0
- mcp_proxy_adapter/examples/commands/__init__.py +5 -0
- mcp_proxy_adapter/examples/create_certificates_simple.py +550 -0
- mcp_proxy_adapter/examples/debug_request_state.py +112 -0
- mcp_proxy_adapter/examples/debug_role_chain.py +158 -0
- mcp_proxy_adapter/examples/demo_client.py +275 -0
- mcp_proxy_adapter/examples/examples/basic_framework/__init__.py +9 -0
- mcp_proxy_adapter/examples/examples/basic_framework/commands/__init__.py +4 -0
- mcp_proxy_adapter/examples/examples/basic_framework/hooks/__init__.py +4 -0
- mcp_proxy_adapter/examples/examples/basic_framework/main.py +44 -0
- mcp_proxy_adapter/examples/examples/full_application/__init__.py +12 -0
- mcp_proxy_adapter/examples/examples/full_application/commands/__init__.py +7 -0
- mcp_proxy_adapter/examples/examples/full_application/commands/custom_echo_command.py +80 -0
- mcp_proxy_adapter/examples/examples/full_application/commands/dynamic_calculator_command.py +90 -0
- mcp_proxy_adapter/examples/examples/full_application/hooks/__init__.py +7 -0
- mcp_proxy_adapter/examples/examples/full_application/hooks/application_hooks.py +75 -0
- mcp_proxy_adapter/examples/examples/full_application/hooks/builtin_command_hooks.py +71 -0
- mcp_proxy_adapter/examples/examples/full_application/main.py +173 -0
- mcp_proxy_adapter/examples/examples/full_application/proxy_endpoints.py +154 -0
- mcp_proxy_adapter/examples/full_application/__init__.py +12 -0
- mcp_proxy_adapter/examples/full_application/commands/__init__.py +7 -0
- mcp_proxy_adapter/examples/full_application/commands/custom_echo_command.py +80 -0
- mcp_proxy_adapter/examples/full_application/commands/dynamic_calculator_command.py +90 -0
- mcp_proxy_adapter/examples/full_application/hooks/__init__.py +7 -0
- mcp_proxy_adapter/examples/full_application/hooks/application_hooks.py +75 -0
- mcp_proxy_adapter/examples/full_application/hooks/builtin_command_hooks.py +71 -0
- mcp_proxy_adapter/examples/full_application/main.py +173 -0
- mcp_proxy_adapter/examples/full_application/proxy_endpoints.py +154 -0
- mcp_proxy_adapter/examples/generate_all_certificates.py +362 -0
- mcp_proxy_adapter/examples/generate_certificates.py +177 -0
- mcp_proxy_adapter/examples/generate_certificates_and_tokens.py +369 -0
- mcp_proxy_adapter/examples/generate_test_configs.py +331 -0
- mcp_proxy_adapter/examples/proxy_registration_example.py +334 -0
- mcp_proxy_adapter/examples/run_example.py +59 -0
- mcp_proxy_adapter/examples/run_full_test_suite.py +318 -0
- mcp_proxy_adapter/examples/run_proxy_server.py +146 -0
- mcp_proxy_adapter/examples/run_security_tests.py +544 -0
- mcp_proxy_adapter/examples/run_security_tests_fixed.py +247 -0
- mcp_proxy_adapter/examples/scripts/config_generator.py +740 -0
- mcp_proxy_adapter/examples/scripts/create_certificates_simple.py +560 -0
- mcp_proxy_adapter/examples/scripts/generate_certificates_and_tokens.py +369 -0
- mcp_proxy_adapter/examples/security_test_client.py +782 -0
- mcp_proxy_adapter/examples/setup_test_environment.py +328 -0
- mcp_proxy_adapter/examples/test_config.py +148 -0
- mcp_proxy_adapter/examples/test_config_generator.py +86 -0
- mcp_proxy_adapter/examples/test_examples.py +281 -0
- mcp_proxy_adapter/examples/universal_client.py +620 -0
- mcp_proxy_adapter/main.py +93 -0
- mcp_proxy_adapter/utils/config_generator.py +1008 -0
- mcp_proxy_adapter/version.py +5 -2
- mcp_proxy_adapter-6.0.1.dist-info/METADATA +679 -0
- mcp_proxy_adapter-6.0.1.dist-info/RECORD +140 -0
- mcp_proxy_adapter-6.0.1.dist-info/entry_points.txt +2 -0
- {mcp_proxy_adapter-4.1.1.dist-info → mcp_proxy_adapter-6.0.1.dist-info}/licenses/LICENSE +2 -2
- mcp_proxy_adapter/api/middleware/auth.py +0 -146
- mcp_proxy_adapter/api/middleware/rate_limit.py +0 -152
- mcp_proxy_adapter/commands/reload_settings_command.py +0 -125
- mcp_proxy_adapter/examples/README.md +0 -124
- mcp_proxy_adapter/examples/basic_server/README.md +0 -60
- mcp_proxy_adapter/examples/basic_server/__init__.py +0 -7
- mcp_proxy_adapter/examples/basic_server/basic_custom_settings.json +0 -39
- mcp_proxy_adapter/examples/basic_server/config.json +0 -35
- mcp_proxy_adapter/examples/basic_server/custom_settings_example.py +0 -238
- mcp_proxy_adapter/examples/basic_server/server.py +0 -103
- mcp_proxy_adapter/examples/custom_commands/README.md +0 -127
- mcp_proxy_adapter/examples/custom_commands/__init__.py +0 -27
- mcp_proxy_adapter/examples/custom_commands/advanced_hooks.py +0 -250
- mcp_proxy_adapter/examples/custom_commands/auto_commands/__init__.py +0 -6
- mcp_proxy_adapter/examples/custom_commands/auto_commands/auto_echo_command.py +0 -103
- mcp_proxy_adapter/examples/custom_commands/auto_commands/auto_info_command.py +0 -111
- mcp_proxy_adapter/examples/custom_commands/config.json +0 -35
- mcp_proxy_adapter/examples/custom_commands/custom_health_command.py +0 -169
- mcp_proxy_adapter/examples/custom_commands/custom_help_command.py +0 -215
- mcp_proxy_adapter/examples/custom_commands/custom_openapi_generator.py +0 -76
- mcp_proxy_adapter/examples/custom_commands/custom_settings.json +0 -96
- mcp_proxy_adapter/examples/custom_commands/custom_settings_manager.py +0 -241
- mcp_proxy_adapter/examples/custom_commands/data_transform_command.py +0 -135
- mcp_proxy_adapter/examples/custom_commands/echo_command.py +0 -122
- mcp_proxy_adapter/examples/custom_commands/hooks.py +0 -230
- mcp_proxy_adapter/examples/custom_commands/intercept_command.py +0 -123
- mcp_proxy_adapter/examples/custom_commands/manual_echo_command.py +0 -103
- mcp_proxy_adapter/examples/custom_commands/server.py +0 -228
- mcp_proxy_adapter/examples/custom_commands/test_hooks.py +0 -176
- mcp_proxy_adapter/examples/deployment/README.md +0 -49
- mcp_proxy_adapter/examples/deployment/__init__.py +0 -7
- mcp_proxy_adapter/examples/deployment/config.development.json +0 -8
- mcp_proxy_adapter/examples/deployment/config.json +0 -29
- mcp_proxy_adapter/examples/deployment/config.production.json +0 -12
- mcp_proxy_adapter/examples/deployment/config.staging.json +0 -11
- mcp_proxy_adapter/examples/deployment/docker-compose.yml +0 -31
- mcp_proxy_adapter/examples/deployment/run.sh +0 -43
- mcp_proxy_adapter/examples/deployment/run_docker.sh +0 -84
- mcp_proxy_adapter/schemas/base_schema.json +0 -114
- mcp_proxy_adapter/schemas/openapi_schema.json +0 -314
- mcp_proxy_adapter/tests/__init__.py +0 -0
- mcp_proxy_adapter/tests/api/__init__.py +0 -3
- mcp_proxy_adapter/tests/api/test_cmd_endpoint.py +0 -115
- mcp_proxy_adapter/tests/api/test_custom_openapi.py +0 -617
- mcp_proxy_adapter/tests/api/test_handlers.py +0 -522
- mcp_proxy_adapter/tests/api/test_middleware.py +0 -340
- mcp_proxy_adapter/tests/api/test_schemas.py +0 -546
- mcp_proxy_adapter/tests/api/test_tool_integration.py +0 -531
- mcp_proxy_adapter/tests/commands/__init__.py +0 -3
- mcp_proxy_adapter/tests/commands/test_config_command.py +0 -211
- mcp_proxy_adapter/tests/commands/test_echo_command.py +0 -127
- mcp_proxy_adapter/tests/commands/test_help_command.py +0 -136
- mcp_proxy_adapter/tests/conftest.py +0 -131
- mcp_proxy_adapter/tests/functional/__init__.py +0 -3
- mcp_proxy_adapter/tests/functional/test_api.py +0 -253
- mcp_proxy_adapter/tests/integration/__init__.py +0 -3
- mcp_proxy_adapter/tests/integration/test_cmd_integration.py +0 -129
- mcp_proxy_adapter/tests/integration/test_integration.py +0 -255
- mcp_proxy_adapter/tests/performance/__init__.py +0 -3
- mcp_proxy_adapter/tests/performance/test_performance.py +0 -189
- mcp_proxy_adapter/tests/stubs/__init__.py +0 -10
- mcp_proxy_adapter/tests/stubs/echo_command.py +0 -104
- mcp_proxy_adapter/tests/test_api_endpoints.py +0 -271
- mcp_proxy_adapter/tests/test_api_handlers.py +0 -289
- mcp_proxy_adapter/tests/test_base_command.py +0 -123
- mcp_proxy_adapter/tests/test_batch_requests.py +0 -117
- mcp_proxy_adapter/tests/test_command_registry.py +0 -281
- mcp_proxy_adapter/tests/test_config.py +0 -127
- mcp_proxy_adapter/tests/test_utils.py +0 -65
- mcp_proxy_adapter/tests/unit/__init__.py +0 -3
- mcp_proxy_adapter/tests/unit/test_base_command.py +0 -436
- mcp_proxy_adapter/tests/unit/test_config.py +0 -217
- mcp_proxy_adapter-4.1.1.dist-info/METADATA +0 -200
- mcp_proxy_adapter-4.1.1.dist-info/RECORD +0 -110
- {mcp_proxy_adapter-4.1.1.dist-info → mcp_proxy_adapter-6.0.1.dist-info}/WHEEL +0 -0
- {mcp_proxy_adapter-4.1.1.dist-info → mcp_proxy_adapter-6.0.1.dist-info}/top_level.txt +0 -0
@@ -1,127 +0,0 @@
|
|
1
|
-
# Custom Commands Server Example
|
2
|
-
|
3
|
-
This example demonstrates both auto-registration and manual registration of commands in the MCP Proxy Adapter framework.
|
4
|
-
|
5
|
-
## Registration Methods
|
6
|
-
|
7
|
-
### 1. Auto-Registration
|
8
|
-
|
9
|
-
Commands are automatically discovered and registered by the framework if they:
|
10
|
-
- Are located in packages that follow the naming convention
|
11
|
-
- Have class names ending with "Command"
|
12
|
-
- Inherit from the `Command` base class
|
13
|
-
|
14
|
-
**Location:** `auto_commands/` package
|
15
|
-
**Files:**
|
16
|
-
- `auto_echo_command.py` - AutoEchoCommand
|
17
|
-
- `auto_info_command.py` - AutoInfoCommand
|
18
|
-
|
19
|
-
**How it works:**
|
20
|
-
```python
|
21
|
-
# Framework automatically discovers commands in auto_commands/ package
|
22
|
-
registry.discover_commands("mcp_proxy_adapter.examples.custom_commands.auto_commands")
|
23
|
-
```
|
24
|
-
|
25
|
-
### 2. Manual Registration
|
26
|
-
|
27
|
-
Commands are explicitly registered in the server code using:
|
28
|
-
- `registry.register()` - for regular commands
|
29
|
-
- `registry.register_custom_command()` - for commands that override built-ins
|
30
|
-
|
31
|
-
**Location:** Main server file
|
32
|
-
**Files:**
|
33
|
-
- `echo_command.py` - EchoCommand
|
34
|
-
- `custom_help_command.py` - CustomHelpCommand
|
35
|
-
- `custom_health_command.py` - CustomHealthCommand
|
36
|
-
- `data_transform_command.py` - DataTransformCommand
|
37
|
-
- `intercept_command.py` - InterceptCommand
|
38
|
-
- `manual_echo_command.py` - ManualEchoCommand
|
39
|
-
|
40
|
-
**How it works:**
|
41
|
-
```python
|
42
|
-
# Explicit registration in server code
|
43
|
-
registry.register(EchoCommand)
|
44
|
-
registry.register_custom_command(CustomHelpCommand) # Overrides built-in
|
45
|
-
```
|
46
|
-
|
47
|
-
### 3. Built-in Commands
|
48
|
-
|
49
|
-
Framework provides default commands that are registered automatically:
|
50
|
-
- `help` - HelpCommand
|
51
|
-
- `health` - HealthCommand
|
52
|
-
|
53
|
-
These can be overridden by custom commands using `register_custom_command()`.
|
54
|
-
|
55
|
-
## Command Hierarchy
|
56
|
-
|
57
|
-
1. **Custom Commands** (highest priority) - registered with `register_custom_command()`
|
58
|
-
2. **Manually Registered Commands** - registered with `register()`
|
59
|
-
3. **Auto-Registered Commands** - discovered automatically
|
60
|
-
4. **Built-in Commands** (lowest priority) - framework defaults
|
61
|
-
|
62
|
-
## Testing Commands
|
63
|
-
|
64
|
-
### Auto-Registered Commands
|
65
|
-
```bash
|
66
|
-
# Test auto-registered echo
|
67
|
-
curl -X POST http://localhost:8000/cmd \
|
68
|
-
-H "Content-Type: application/json" \
|
69
|
-
-d '{"jsonrpc": "2.0", "method": "auto_echo", "params": {"message": "Hello!"}, "id": 1}'
|
70
|
-
|
71
|
-
# Test auto-registered info
|
72
|
-
curl -X POST http://localhost:8000/cmd \
|
73
|
-
-H "Content-Type: application/json" \
|
74
|
-
-d '{"jsonrpc": "2.0", "method": "auto_info", "params": {"topic": "test"}, "id": 2}'
|
75
|
-
```
|
76
|
-
|
77
|
-
### Manually Registered Commands
|
78
|
-
```bash
|
79
|
-
# Test manually registered echo
|
80
|
-
curl -X POST http://localhost:8000/cmd \
|
81
|
-
-H "Content-Type: application/json" \
|
82
|
-
-d '{"jsonrpc": "2.0", "method": "manual_echo", "params": {"message": "Hello!"}, "id": 3}'
|
83
|
-
|
84
|
-
# Test other manually registered commands
|
85
|
-
curl -X POST http://localhost:8000/cmd \
|
86
|
-
-H "Content-Type: application/json" \
|
87
|
-
-d '{"jsonrpc": "2.0", "method": "echo", "params": {"message": "Hello!"}, "id": 4}'
|
88
|
-
```
|
89
|
-
|
90
|
-
### Built-in Commands (or overridden)
|
91
|
-
```bash
|
92
|
-
# Test help command (custom or built-in)
|
93
|
-
curl -X POST http://localhost:8000/cmd \
|
94
|
-
-H "Content-Type: application/json" \
|
95
|
-
-d '{"jsonrpc": "2.0", "method": "help", "id": 5}'
|
96
|
-
|
97
|
-
# Test health command (custom or built-in)
|
98
|
-
curl -X POST http://localhost:8000/cmd \
|
99
|
-
-H "Content-Type: application/json" \
|
100
|
-
-d '{"jsonrpc": "2.0", "method": "health", "id": 6}'
|
101
|
-
```
|
102
|
-
|
103
|
-
## Features Demonstrated
|
104
|
-
|
105
|
-
### Auto-Registration
|
106
|
-
- ✅ Automatic command discovery
|
107
|
-
- ✅ Naming convention compliance
|
108
|
-
- ✅ Package-based organization
|
109
|
-
- ✅ Framework integration
|
110
|
-
|
111
|
-
### Manual Registration
|
112
|
-
- ✅ Explicit command registration
|
113
|
-
- ✅ Custom command overrides
|
114
|
-
- ✅ Priority management
|
115
|
-
- ✅ Dependency control
|
116
|
-
|
117
|
-
### Built-in Commands
|
118
|
-
- ✅ Framework defaults
|
119
|
-
- ✅ Override capability
|
120
|
-
- ✅ Fallback behavior
|
121
|
-
- ✅ Consistent API
|
122
|
-
|
123
|
-
### Advanced Features
|
124
|
-
- ✅ Command hierarchy
|
125
|
-
- ✅ Priority resolution
|
126
|
-
- ✅ Hook integration
|
127
|
-
- ✅ Error handling
|
@@ -1,27 +0,0 @@
|
|
1
|
-
"""
|
2
|
-
Custom Commands Example
|
3
|
-
|
4
|
-
An example of MCP Proxy Adapter server with custom commands:
|
5
|
-
- echo command
|
6
|
-
- custom help command
|
7
|
-
- custom health command
|
8
|
-
"""
|
9
|
-
|
10
|
-
__version__ = "1.0.0"
|
11
|
-
|
12
|
-
# Import all modules to make them available
|
13
|
-
from . import echo_command
|
14
|
-
from . import custom_help_command
|
15
|
-
from . import custom_health_command
|
16
|
-
from . import manual_echo_command
|
17
|
-
from . import intercept_command
|
18
|
-
from . import data_transform_command
|
19
|
-
from . import advanced_hooks
|
20
|
-
from . import hooks
|
21
|
-
from . import custom_settings_manager
|
22
|
-
from . import custom_openapi_generator
|
23
|
-
from . import server
|
24
|
-
|
25
|
-
# Import auto commands
|
26
|
-
from .auto_commands import auto_echo_command
|
27
|
-
from .auto_commands import auto_info_command
|
@@ -1,250 +0,0 @@
|
|
1
|
-
"""
|
2
|
-
Advanced Hooks Example
|
3
|
-
|
4
|
-
This module demonstrates advanced hook capabilities:
|
5
|
-
1. Data transformation hooks - modify input data before command execution and format output after
|
6
|
-
2. Interception hooks - completely bypass command execution based on conditions
|
7
|
-
"""
|
8
|
-
|
9
|
-
import time
|
10
|
-
import logging
|
11
|
-
from typing import Dict, Any
|
12
|
-
from datetime import datetime
|
13
|
-
|
14
|
-
from mcp_proxy_adapter.commands.hooks import HookContext, HookType
|
15
|
-
from mcp_proxy_adapter.commands.result import CommandResult
|
16
|
-
|
17
|
-
|
18
|
-
# Setup logging for advanced hooks
|
19
|
-
logger = logging.getLogger("mcp_proxy_adapter.examples.advanced_hooks")
|
20
|
-
|
21
|
-
|
22
|
-
def data_transform_before_hook(context: HookContext) -> None:
|
23
|
-
"""
|
24
|
-
Before hook for data_transform command - modifies input data.
|
25
|
-
|
26
|
-
Args:
|
27
|
-
context: Hook context with command information
|
28
|
-
"""
|
29
|
-
logger.info(f"🔄 Data transform before hook: {context.params}")
|
30
|
-
|
31
|
-
# Get original data
|
32
|
-
original_data = context.params.get("data", {})
|
33
|
-
|
34
|
-
# Transform data before command execution
|
35
|
-
transformed_data = {}
|
36
|
-
for key, value in original_data.items():
|
37
|
-
if isinstance(value, str):
|
38
|
-
# Add prefix and suffix to string values
|
39
|
-
transformed_data[f"pre_{key}_post"] = f"ENHANCED_{value}_PROCESSED"
|
40
|
-
elif isinstance(value, (int, float)):
|
41
|
-
# Multiply numeric values by 2
|
42
|
-
transformed_data[f"doubled_{key}"] = value * 2
|
43
|
-
else:
|
44
|
-
# Keep other types as is
|
45
|
-
transformed_data[key] = value
|
46
|
-
|
47
|
-
# Add metadata
|
48
|
-
transformed_data["_hook_modified"] = True
|
49
|
-
transformed_data["_modification_time"] = datetime.now().isoformat()
|
50
|
-
|
51
|
-
# Replace original data with transformed data
|
52
|
-
context.params["data"] = transformed_data
|
53
|
-
context.params["data_modified"] = True
|
54
|
-
|
55
|
-
logger.info(f"📊 Original data: {original_data}")
|
56
|
-
logger.info(f"🔄 Transformed data: {transformed_data}")
|
57
|
-
|
58
|
-
|
59
|
-
def data_transform_after_hook(context: HookContext) -> None:
|
60
|
-
"""
|
61
|
-
After hook for data_transform command - formats output data.
|
62
|
-
|
63
|
-
Args:
|
64
|
-
context: Hook context with command information
|
65
|
-
"""
|
66
|
-
logger.info(f"🔄 Data transform after hook: {context.result}")
|
67
|
-
|
68
|
-
if context.result and hasattr(context.result, 'transformed_data'):
|
69
|
-
# Get the transformed data from command result
|
70
|
-
transformed_data = context.result.transformed_data
|
71
|
-
|
72
|
-
# Apply additional formatting
|
73
|
-
formatted_data = {}
|
74
|
-
for key, value in transformed_data.items():
|
75
|
-
if isinstance(value, str):
|
76
|
-
# Add formatting to string values
|
77
|
-
formatted_data[f"formatted_{key}"] = f"✨ {value} ✨"
|
78
|
-
else:
|
79
|
-
formatted_data[key] = value
|
80
|
-
|
81
|
-
# Add formatting metadata
|
82
|
-
formatted_data["_formatted_by_hook"] = True
|
83
|
-
formatted_data["_formatting_time"] = datetime.now().isoformat()
|
84
|
-
|
85
|
-
# Update the result with formatted data
|
86
|
-
context.result.transformed_data = formatted_data
|
87
|
-
|
88
|
-
logger.info(f"✨ Formatted data: {formatted_data}")
|
89
|
-
|
90
|
-
|
91
|
-
def intercept_before_hook(context: HookContext) -> None:
|
92
|
-
"""
|
93
|
-
Before hook for intercept command - can completely bypass execution.
|
94
|
-
|
95
|
-
Args:
|
96
|
-
context: Hook context with command information
|
97
|
-
"""
|
98
|
-
logger.info(f"🚫 Intercept before hook: {context.params}")
|
99
|
-
|
100
|
-
# Check bypass flag
|
101
|
-
bypass_flag = context.params.get("bypass_flag", 1)
|
102
|
-
|
103
|
-
if bypass_flag == 0:
|
104
|
-
# Completely bypass command execution
|
105
|
-
logger.info(f"🚫 Intercepting command execution - bypass_flag = 0")
|
106
|
-
|
107
|
-
# Create a mock result without calling the actual command
|
108
|
-
from .intercept_command import InterceptResult
|
109
|
-
|
110
|
-
mock_result = InterceptResult(
|
111
|
-
message="Command intercepted by hook - not executed",
|
112
|
-
executed=False,
|
113
|
-
intercept_reason="bypass_flag = 0",
|
114
|
-
hook_data={
|
115
|
-
"intercepted_by": "intercept_before_hook",
|
116
|
-
"interception_time": datetime.now().isoformat(),
|
117
|
-
"original_params": context.params.copy()
|
118
|
-
}
|
119
|
-
)
|
120
|
-
|
121
|
-
# Set the result and stop standard processing
|
122
|
-
context.result = mock_result
|
123
|
-
context.standard_processing = False
|
124
|
-
|
125
|
-
logger.info(f"✅ Command intercepted successfully")
|
126
|
-
else:
|
127
|
-
# Allow normal execution
|
128
|
-
logger.info(f"✅ Allowing normal execution - bypass_flag = {bypass_flag}")
|
129
|
-
context.params["hook_processed"] = True
|
130
|
-
|
131
|
-
|
132
|
-
def intercept_after_hook(context: HookContext) -> None:
|
133
|
-
"""
|
134
|
-
After hook for intercept command.
|
135
|
-
|
136
|
-
Args:
|
137
|
-
context: Hook context with command information
|
138
|
-
"""
|
139
|
-
if context.standard_processing:
|
140
|
-
logger.info(f"✅ Intercept command executed normally")
|
141
|
-
else:
|
142
|
-
logger.info(f"🚫 Intercept command was intercepted by hook")
|
143
|
-
|
144
|
-
# Add execution metadata
|
145
|
-
if context.result and hasattr(context.result, 'hook_data'):
|
146
|
-
context.result.hook_data["after_hook_processed"] = True
|
147
|
-
context.result.hook_data["after_hook_time"] = datetime.now().isoformat()
|
148
|
-
|
149
|
-
|
150
|
-
def conditional_transform_hook(context: HookContext) -> None:
|
151
|
-
"""
|
152
|
-
Conditional transformation hook - applies different transformations based on data.
|
153
|
-
|
154
|
-
Args:
|
155
|
-
context: Hook context with command information
|
156
|
-
"""
|
157
|
-
if context.hook_type == HookType.BEFORE_EXECUTION:
|
158
|
-
logger.info(f"🎯 Conditional transform before hook: {context.command_name}")
|
159
|
-
|
160
|
-
# Check if this is a data_transform command
|
161
|
-
if context.command_name == "data_transform":
|
162
|
-
data = context.params.get("data", {})
|
163
|
-
transform_type = context.params.get("transform_type", "default")
|
164
|
-
|
165
|
-
# Apply conditional transformation based on data content
|
166
|
-
if "special" in str(data).lower():
|
167
|
-
logger.info(f"🎯 Special data detected - applying enhanced transformation")
|
168
|
-
context.params["transform_type"] = "uppercase"
|
169
|
-
context.params["_special_enhancement"] = True
|
170
|
-
elif "test" in str(data).lower():
|
171
|
-
logger.info(f"🎯 Test data detected - applying test transformation")
|
172
|
-
context.params["transform_type"] = "reverse"
|
173
|
-
context.params["_test_mode"] = True
|
174
|
-
|
175
|
-
elif context.hook_type == HookType.AFTER_EXECUTION:
|
176
|
-
logger.info(f"🎯 Conditional transform after hook: {context.command_name}")
|
177
|
-
|
178
|
-
# Add conditional metadata to result
|
179
|
-
if context.result and hasattr(context.result, 'processing_info'):
|
180
|
-
context.result.processing_info["conditional_processed"] = True
|
181
|
-
context.result.processing_info["conditional_time"] = datetime.now().isoformat()
|
182
|
-
|
183
|
-
|
184
|
-
def smart_intercept_hook(context: HookContext) -> None:
|
185
|
-
"""
|
186
|
-
Smart interception hook - intercepts based on multiple conditions.
|
187
|
-
|
188
|
-
Args:
|
189
|
-
context: Hook context with command information
|
190
|
-
"""
|
191
|
-
if context.hook_type == HookType.BEFORE_EXECUTION:
|
192
|
-
logger.info(f"🧠 Smart intercept before hook: {context.command_name}")
|
193
|
-
|
194
|
-
# Check multiple conditions for interception
|
195
|
-
action = context.params.get("action", "")
|
196
|
-
bypass_flag = context.params.get("bypass_flag", 1)
|
197
|
-
|
198
|
-
# Intercept if action is "blocked" or bypass_flag is 0
|
199
|
-
if action == "blocked" or bypass_flag == 0:
|
200
|
-
logger.info(f"🧠 Smart intercept: action='{action}', bypass_flag={bypass_flag}")
|
201
|
-
|
202
|
-
# Create intercepted result
|
203
|
-
from .intercept_command import InterceptResult
|
204
|
-
|
205
|
-
intercept_reason = "blocked_action" if action == "blocked" else "bypass_flag_zero"
|
206
|
-
|
207
|
-
mock_result = InterceptResult(
|
208
|
-
message=f"Command intercepted by smart hook - reason: {intercept_reason}",
|
209
|
-
executed=False,
|
210
|
-
intercept_reason=intercept_reason,
|
211
|
-
hook_data={
|
212
|
-
"intercepted_by": "smart_intercept_hook",
|
213
|
-
"interception_time": datetime.now().isoformat(),
|
214
|
-
"original_params": context.params.copy(),
|
215
|
-
"smart_analysis": True
|
216
|
-
}
|
217
|
-
)
|
218
|
-
|
219
|
-
# Set the result and stop standard processing
|
220
|
-
context.result = mock_result
|
221
|
-
context.standard_processing = False
|
222
|
-
|
223
|
-
logger.info(f"✅ Smart interception completed")
|
224
|
-
|
225
|
-
|
226
|
-
def register_advanced_hooks(hooks_manager) -> None:
|
227
|
-
"""
|
228
|
-
Register advanced hooks with the hooks manager.
|
229
|
-
|
230
|
-
Args:
|
231
|
-
hooks_manager: The hooks manager instance
|
232
|
-
"""
|
233
|
-
logger.info("🔧 Registering advanced hooks...")
|
234
|
-
|
235
|
-
# Register data transformation hooks
|
236
|
-
hooks_manager.register_before_hook("data_transform", data_transform_before_hook)
|
237
|
-
hooks_manager.register_after_hook("data_transform", data_transform_after_hook)
|
238
|
-
|
239
|
-
# Register interception hooks
|
240
|
-
hooks_manager.register_before_hook("intercept", intercept_before_hook)
|
241
|
-
hooks_manager.register_after_hook("intercept", intercept_after_hook)
|
242
|
-
|
243
|
-
# Register conditional hooks
|
244
|
-
hooks_manager.register_global_before_hook(conditional_transform_hook)
|
245
|
-
hooks_manager.register_global_after_hook(conditional_transform_hook)
|
246
|
-
|
247
|
-
# Register smart interception hooks
|
248
|
-
hooks_manager.register_global_before_hook(smart_intercept_hook)
|
249
|
-
|
250
|
-
logger.info("✅ Advanced hooks registered successfully")
|
@@ -1,103 +0,0 @@
|
|
1
|
-
"""
|
2
|
-
Auto-registered Echo Command
|
3
|
-
|
4
|
-
This command will be automatically discovered and registered by the framework.
|
5
|
-
"""
|
6
|
-
|
7
|
-
from typing import Dict, Any, Optional
|
8
|
-
from mcp_proxy_adapter.commands.base import Command
|
9
|
-
from mcp_proxy_adapter.commands.result import CommandResult
|
10
|
-
|
11
|
-
|
12
|
-
class AutoEchoResult(CommandResult):
|
13
|
-
"""
|
14
|
-
Result of the auto-registered echo command execution.
|
15
|
-
"""
|
16
|
-
|
17
|
-
def __init__(self, message: str, auto_registered: bool = True):
|
18
|
-
"""
|
19
|
-
Initialize auto echo command result.
|
20
|
-
|
21
|
-
Args:
|
22
|
-
message: Echoed message
|
23
|
-
auto_registered: Flag indicating this was auto-registered
|
24
|
-
"""
|
25
|
-
self.message = message
|
26
|
-
self.auto_registered = auto_registered
|
27
|
-
|
28
|
-
def to_dict(self) -> Dict[str, Any]:
|
29
|
-
"""
|
30
|
-
Convert result to dictionary.
|
31
|
-
|
32
|
-
Returns:
|
33
|
-
Dict[str, Any]: Result as dictionary
|
34
|
-
"""
|
35
|
-
return {
|
36
|
-
"message": self.message,
|
37
|
-
"auto_registered": self.auto_registered,
|
38
|
-
"command_type": "auto_echo"
|
39
|
-
}
|
40
|
-
|
41
|
-
@classmethod
|
42
|
-
def get_schema(cls) -> Dict[str, Any]:
|
43
|
-
"""
|
44
|
-
Get JSON schema for the result.
|
45
|
-
|
46
|
-
Returns:
|
47
|
-
Dict[str, Any]: JSON schema
|
48
|
-
"""
|
49
|
-
return {
|
50
|
-
"type": "object",
|
51
|
-
"properties": {
|
52
|
-
"message": {"type": "string"},
|
53
|
-
"auto_registered": {"type": "boolean"},
|
54
|
-
"command_type": {"type": "string"}
|
55
|
-
}
|
56
|
-
}
|
57
|
-
|
58
|
-
|
59
|
-
class AutoEchoCommand(Command):
|
60
|
-
"""
|
61
|
-
Auto-registered echo command.
|
62
|
-
"""
|
63
|
-
|
64
|
-
name = "auto_echo"
|
65
|
-
result_class = AutoEchoResult
|
66
|
-
|
67
|
-
async def execute(self, message: Optional[str] = None, **kwargs) -> AutoEchoResult:
|
68
|
-
"""
|
69
|
-
Execute auto-registered echo command.
|
70
|
-
|
71
|
-
Args:
|
72
|
-
message: Message to echo
|
73
|
-
**kwargs: Additional parameters
|
74
|
-
|
75
|
-
Returns:
|
76
|
-
AutoEchoResult: Auto echo command result
|
77
|
-
"""
|
78
|
-
if message is None:
|
79
|
-
message = "Hello from auto-registered command!"
|
80
|
-
|
81
|
-
return AutoEchoResult(
|
82
|
-
message=message,
|
83
|
-
auto_registered=True
|
84
|
-
)
|
85
|
-
|
86
|
-
@classmethod
|
87
|
-
def get_schema(cls) -> Dict[str, Any]:
|
88
|
-
"""
|
89
|
-
Get JSON schema for command parameters.
|
90
|
-
|
91
|
-
Returns:
|
92
|
-
Dict[str, Any]: JSON schema
|
93
|
-
"""
|
94
|
-
return {
|
95
|
-
"type": "object",
|
96
|
-
"properties": {
|
97
|
-
"message": {
|
98
|
-
"type": "string",
|
99
|
-
"description": "Message to echo",
|
100
|
-
"default": "Hello from auto-registered command!"
|
101
|
-
}
|
102
|
-
}
|
103
|
-
}
|
@@ -1,111 +0,0 @@
|
|
1
|
-
"""
|
2
|
-
Auto-registered Info Command
|
3
|
-
|
4
|
-
This command will be automatically discovered and registered by the framework.
|
5
|
-
"""
|
6
|
-
|
7
|
-
from typing import Dict, Any, Optional
|
8
|
-
from mcp_proxy_adapter.commands.base import Command
|
9
|
-
from mcp_proxy_adapter.commands.result import CommandResult
|
10
|
-
|
11
|
-
|
12
|
-
class AutoInfoResult(CommandResult):
|
13
|
-
"""
|
14
|
-
Result of the auto-registered info command execution.
|
15
|
-
"""
|
16
|
-
|
17
|
-
def __init__(self, info: Dict[str, Any], auto_registered: bool = True):
|
18
|
-
"""
|
19
|
-
Initialize auto info command result.
|
20
|
-
|
21
|
-
Args:
|
22
|
-
info: Information data
|
23
|
-
auto_registered: Flag indicating this was auto-registered
|
24
|
-
"""
|
25
|
-
self.info = info
|
26
|
-
self.auto_registered = auto_registered
|
27
|
-
|
28
|
-
def to_dict(self) -> Dict[str, Any]:
|
29
|
-
"""
|
30
|
-
Convert result to dictionary.
|
31
|
-
|
32
|
-
Returns:
|
33
|
-
Dict[str, Any]: Result as dictionary
|
34
|
-
"""
|
35
|
-
return {
|
36
|
-
"info": self.info,
|
37
|
-
"auto_registered": self.auto_registered,
|
38
|
-
"command_type": "auto_info"
|
39
|
-
}
|
40
|
-
|
41
|
-
@classmethod
|
42
|
-
def get_schema(cls) -> Dict[str, Any]:
|
43
|
-
"""
|
44
|
-
Get JSON schema for the result.
|
45
|
-
|
46
|
-
Returns:
|
47
|
-
Dict[str, Any]: JSON schema
|
48
|
-
"""
|
49
|
-
return {
|
50
|
-
"type": "object",
|
51
|
-
"properties": {
|
52
|
-
"info": {"type": "object"},
|
53
|
-
"auto_registered": {"type": "boolean"},
|
54
|
-
"command_type": {"type": "string"}
|
55
|
-
}
|
56
|
-
}
|
57
|
-
|
58
|
-
|
59
|
-
class AutoInfoCommand(Command):
|
60
|
-
"""
|
61
|
-
Auto-registered info command.
|
62
|
-
"""
|
63
|
-
|
64
|
-
name = "auto_info"
|
65
|
-
result_class = AutoInfoResult
|
66
|
-
|
67
|
-
async def execute(self, topic: Optional[str] = None, **kwargs) -> AutoInfoResult:
|
68
|
-
"""
|
69
|
-
Execute auto-registered info command.
|
70
|
-
|
71
|
-
Args:
|
72
|
-
topic: Information topic
|
73
|
-
**kwargs: Additional parameters
|
74
|
-
|
75
|
-
Returns:
|
76
|
-
AutoInfoResult: Auto info command result
|
77
|
-
"""
|
78
|
-
if topic is None:
|
79
|
-
topic = "general"
|
80
|
-
|
81
|
-
info_data = {
|
82
|
-
"topic": topic,
|
83
|
-
"auto_registered": True,
|
84
|
-
"discovery_method": "automatic",
|
85
|
-
"registration_time": "startup",
|
86
|
-
"command_type": "auto_info"
|
87
|
-
}
|
88
|
-
|
89
|
-
return AutoInfoResult(
|
90
|
-
info=info_data,
|
91
|
-
auto_registered=True
|
92
|
-
)
|
93
|
-
|
94
|
-
@classmethod
|
95
|
-
def get_schema(cls) -> Dict[str, Any]:
|
96
|
-
"""
|
97
|
-
Get JSON schema for command parameters.
|
98
|
-
|
99
|
-
Returns:
|
100
|
-
Dict[str, Any]: JSON schema
|
101
|
-
"""
|
102
|
-
return {
|
103
|
-
"type": "object",
|
104
|
-
"properties": {
|
105
|
-
"topic": {
|
106
|
-
"type": "string",
|
107
|
-
"description": "Information topic",
|
108
|
-
"default": "general"
|
109
|
-
}
|
110
|
-
}
|
111
|
-
}
|
@@ -1,35 +0,0 @@
|
|
1
|
-
{
|
2
|
-
"server": {
|
3
|
-
"host": "0.0.0.0",
|
4
|
-
"port": 8000,
|
5
|
-
"debug": true,
|
6
|
-
"log_level": "DEBUG"
|
7
|
-
},
|
8
|
-
"logging": {
|
9
|
-
"level": "DEBUG",
|
10
|
-
"log_dir": "./logs/custom_commands",
|
11
|
-
"log_file": "custom_commands.log",
|
12
|
-
"error_log_file": "custom_commands_error.log",
|
13
|
-
"access_log_file": "custom_commands_access.log",
|
14
|
-
"max_file_size": "5MB",
|
15
|
-
"backup_count": 3,
|
16
|
-
"format": "%(asctime)s - %(name)s - %(levelname)s - %(message)s",
|
17
|
-
"date_format": "%Y-%m-%d %H:%M:%S",
|
18
|
-
"console_output": true,
|
19
|
-
"file_output": true
|
20
|
-
},
|
21
|
-
"commands": {
|
22
|
-
"auto_discovery": true,
|
23
|
-
"discovery_path": "mcp_proxy_adapter.examples.custom_commands.auto_commands",
|
24
|
-
"custom_commands_path": null
|
25
|
-
},
|
26
|
-
"custom": {
|
27
|
-
"server_name": "Custom Commands MCP Proxy Server",
|
28
|
-
"description": "Example server with custom commands",
|
29
|
-
"features": {
|
30
|
-
"hooks_enabled": true,
|
31
|
-
"custom_commands_enabled": true,
|
32
|
-
"advanced_logging": true
|
33
|
-
}
|
34
|
-
}
|
35
|
-
}
|