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