mcp-proxy-adapter 6.3.4__py3-none-any.whl → 6.3.5__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- mcp_proxy_adapter/__init__.py +9 -5
- mcp_proxy_adapter/__main__.py +1 -1
- mcp_proxy_adapter/api/app.py +227 -176
- mcp_proxy_adapter/api/handlers.py +68 -60
- mcp_proxy_adapter/api/middleware/__init__.py +7 -5
- mcp_proxy_adapter/api/middleware/base.py +19 -16
- mcp_proxy_adapter/api/middleware/command_permission_middleware.py +44 -34
- mcp_proxy_adapter/api/middleware/error_handling.py +57 -67
- mcp_proxy_adapter/api/middleware/factory.py +50 -52
- mcp_proxy_adapter/api/middleware/logging.py +46 -30
- mcp_proxy_adapter/api/middleware/performance.py +19 -16
- mcp_proxy_adapter/api/middleware/protocol_middleware.py +80 -50
- mcp_proxy_adapter/api/middleware/transport_middleware.py +26 -24
- mcp_proxy_adapter/api/middleware/unified_security.py +70 -51
- mcp_proxy_adapter/api/middleware/user_info_middleware.py +43 -34
- mcp_proxy_adapter/api/schemas.py +69 -43
- mcp_proxy_adapter/api/tool_integration.py +83 -63
- mcp_proxy_adapter/api/tools.py +60 -50
- mcp_proxy_adapter/commands/__init__.py +15 -6
- mcp_proxy_adapter/commands/auth_validation_command.py +107 -110
- mcp_proxy_adapter/commands/base.py +108 -112
- mcp_proxy_adapter/commands/builtin_commands.py +28 -18
- mcp_proxy_adapter/commands/catalog_manager.py +394 -265
- mcp_proxy_adapter/commands/cert_monitor_command.py +222 -204
- mcp_proxy_adapter/commands/certificate_management_command.py +210 -213
- mcp_proxy_adapter/commands/command_registry.py +275 -226
- mcp_proxy_adapter/commands/config_command.py +48 -33
- mcp_proxy_adapter/commands/dependency_container.py +22 -23
- mcp_proxy_adapter/commands/dependency_manager.py +65 -56
- mcp_proxy_adapter/commands/echo_command.py +15 -15
- mcp_proxy_adapter/commands/health_command.py +31 -29
- mcp_proxy_adapter/commands/help_command.py +97 -61
- mcp_proxy_adapter/commands/hooks.py +65 -49
- mcp_proxy_adapter/commands/key_management_command.py +148 -147
- mcp_proxy_adapter/commands/load_command.py +58 -40
- mcp_proxy_adapter/commands/plugins_command.py +80 -54
- mcp_proxy_adapter/commands/protocol_management_command.py +60 -48
- mcp_proxy_adapter/commands/proxy_registration_command.py +107 -115
- mcp_proxy_adapter/commands/reload_command.py +43 -37
- mcp_proxy_adapter/commands/result.py +26 -33
- mcp_proxy_adapter/commands/role_test_command.py +26 -26
- mcp_proxy_adapter/commands/roles_management_command.py +176 -173
- mcp_proxy_adapter/commands/security_command.py +134 -122
- mcp_proxy_adapter/commands/settings_command.py +47 -56
- mcp_proxy_adapter/commands/ssl_setup_command.py +109 -129
- mcp_proxy_adapter/commands/token_management_command.py +129 -158
- mcp_proxy_adapter/commands/transport_management_command.py +41 -36
- mcp_proxy_adapter/commands/unload_command.py +42 -37
- mcp_proxy_adapter/config.py +36 -35
- mcp_proxy_adapter/core/__init__.py +19 -21
- mcp_proxy_adapter/core/app_factory.py +30 -9
- mcp_proxy_adapter/core/app_runner.py +81 -64
- mcp_proxy_adapter/core/auth_validator.py +176 -182
- mcp_proxy_adapter/core/certificate_utils.py +469 -426
- mcp_proxy_adapter/core/client.py +155 -126
- mcp_proxy_adapter/core/client_manager.py +60 -54
- mcp_proxy_adapter/core/client_security.py +108 -88
- mcp_proxy_adapter/core/config_converter.py +176 -143
- mcp_proxy_adapter/core/config_validator.py +12 -4
- mcp_proxy_adapter/core/crl_utils.py +21 -7
- mcp_proxy_adapter/core/errors.py +64 -20
- mcp_proxy_adapter/core/logging.py +34 -29
- mcp_proxy_adapter/core/mtls_asgi.py +29 -25
- mcp_proxy_adapter/core/mtls_asgi_app.py +66 -54
- mcp_proxy_adapter/core/protocol_manager.py +154 -104
- mcp_proxy_adapter/core/proxy_client.py +202 -144
- mcp_proxy_adapter/core/proxy_registration.py +7 -3
- mcp_proxy_adapter/core/role_utils.py +139 -125
- mcp_proxy_adapter/core/security_adapter.py +88 -77
- mcp_proxy_adapter/core/security_factory.py +50 -44
- mcp_proxy_adapter/core/security_integration.py +72 -24
- mcp_proxy_adapter/core/server_adapter.py +68 -64
- mcp_proxy_adapter/core/server_engine.py +71 -53
- mcp_proxy_adapter/core/settings.py +68 -58
- mcp_proxy_adapter/core/ssl_utils.py +69 -56
- mcp_proxy_adapter/core/transport_manager.py +72 -60
- mcp_proxy_adapter/core/unified_config_adapter.py +201 -150
- mcp_proxy_adapter/core/utils.py +4 -2
- mcp_proxy_adapter/custom_openapi.py +107 -99
- mcp_proxy_adapter/examples/basic_framework/main.py +9 -2
- mcp_proxy_adapter/examples/commands/__init__.py +1 -1
- mcp_proxy_adapter/examples/create_certificates_simple.py +182 -71
- mcp_proxy_adapter/examples/debug_request_state.py +38 -19
- mcp_proxy_adapter/examples/debug_role_chain.py +53 -20
- mcp_proxy_adapter/examples/demo_client.py +48 -36
- mcp_proxy_adapter/examples/examples/basic_framework/main.py +9 -2
- mcp_proxy_adapter/examples/examples/full_application/__init__.py +1 -0
- mcp_proxy_adapter/examples/examples/full_application/commands/custom_echo_command.py +22 -10
- mcp_proxy_adapter/examples/examples/full_application/commands/dynamic_calculator_command.py +24 -17
- mcp_proxy_adapter/examples/examples/full_application/hooks/application_hooks.py +16 -3
- mcp_proxy_adapter/examples/examples/full_application/hooks/builtin_command_hooks.py +13 -3
- mcp_proxy_adapter/examples/examples/full_application/main.py +27 -2
- mcp_proxy_adapter/examples/examples/full_application/proxy_endpoints.py +48 -14
- mcp_proxy_adapter/examples/full_application/__init__.py +1 -0
- mcp_proxy_adapter/examples/full_application/commands/custom_echo_command.py +22 -10
- mcp_proxy_adapter/examples/full_application/commands/dynamic_calculator_command.py +24 -17
- mcp_proxy_adapter/examples/full_application/hooks/application_hooks.py +16 -3
- mcp_proxy_adapter/examples/full_application/hooks/builtin_command_hooks.py +13 -3
- mcp_proxy_adapter/examples/full_application/main.py +27 -2
- mcp_proxy_adapter/examples/full_application/proxy_endpoints.py +48 -14
- mcp_proxy_adapter/examples/generate_all_certificates.py +198 -73
- mcp_proxy_adapter/examples/generate_certificates.py +31 -16
- mcp_proxy_adapter/examples/generate_certificates_and_tokens.py +220 -74
- mcp_proxy_adapter/examples/generate_test_configs.py +68 -91
- mcp_proxy_adapter/examples/proxy_registration_example.py +76 -75
- mcp_proxy_adapter/examples/run_example.py +23 -5
- mcp_proxy_adapter/examples/run_full_test_suite.py +109 -71
- mcp_proxy_adapter/examples/run_proxy_server.py +22 -9
- mcp_proxy_adapter/examples/run_security_tests.py +103 -41
- mcp_proxy_adapter/examples/run_security_tests_fixed.py +72 -36
- mcp_proxy_adapter/examples/scripts/config_generator.py +288 -187
- mcp_proxy_adapter/examples/scripts/create_certificates_simple.py +185 -72
- mcp_proxy_adapter/examples/scripts/generate_certificates_and_tokens.py +220 -74
- mcp_proxy_adapter/examples/security_test_client.py +196 -127
- mcp_proxy_adapter/examples/setup_test_environment.py +17 -29
- mcp_proxy_adapter/examples/test_config.py +19 -4
- mcp_proxy_adapter/examples/test_config_generator.py +23 -7
- mcp_proxy_adapter/examples/test_examples.py +84 -56
- mcp_proxy_adapter/examples/universal_client.py +119 -62
- mcp_proxy_adapter/openapi.py +108 -115
- mcp_proxy_adapter/utils/config_generator.py +429 -274
- mcp_proxy_adapter/version.py +1 -2
- {mcp_proxy_adapter-6.3.4.dist-info → mcp_proxy_adapter-6.3.5.dist-info}/METADATA +1 -1
- mcp_proxy_adapter-6.3.5.dist-info/RECORD +143 -0
- mcp_proxy_adapter-6.3.4.dist-info/RECORD +0 -143
- {mcp_proxy_adapter-6.3.4.dist-info → mcp_proxy_adapter-6.3.5.dist-info}/WHEEL +0 -0
- {mcp_proxy_adapter-6.3.4.dist-info → mcp_proxy_adapter-6.3.5.dist-info}/entry_points.txt +0 -0
- {mcp_proxy_adapter-6.3.4.dist-info → mcp_proxy_adapter-6.3.5.dist-info}/licenses/LICENSE +0 -0
- {mcp_proxy_adapter-6.3.4.dist-info → mcp_proxy_adapter-6.3.5.dist-info}/top_level.txt +0 -0
mcp_proxy_adapter/api/tools.py
CHANGED
@@ -19,46 +19,48 @@ logger = logging.getLogger(__name__)
|
|
19
19
|
class TSTCommandExecutor:
|
20
20
|
"""
|
21
21
|
Инструмент для выполнения команд через JSON-RPC протокол на сервере проекта.
|
22
|
-
|
22
|
+
|
23
23
|
Этот класс предоставляет функциональность для выполнения команд микросервиса
|
24
24
|
через внешний интерфейс TST (Tool-System-Transport).
|
25
25
|
"""
|
26
|
-
|
26
|
+
|
27
27
|
name = "tst_execute_command"
|
28
28
|
description = "Выполняет команду через JSON-RPC протокол."
|
29
|
-
|
29
|
+
|
30
30
|
@classmethod
|
31
|
-
async def execute(
|
31
|
+
async def execute(
|
32
|
+
cls, command: str, params: Optional[Dict[str, Any]] = None
|
33
|
+
) -> Dict[str, Any]:
|
32
34
|
"""
|
33
35
|
Выполняет команду с указанными параметрами.
|
34
|
-
|
36
|
+
|
35
37
|
Args:
|
36
38
|
command: Имя команды для выполнения
|
37
39
|
params: Параметры команды (опционально)
|
38
|
-
|
40
|
+
|
39
41
|
Returns:
|
40
42
|
Результат выполнения команды
|
41
|
-
|
43
|
+
|
42
44
|
Raises:
|
43
45
|
NotFoundError: Если команда не найдена
|
44
46
|
InvalidParamsError: Если переданы некорректные параметры
|
45
47
|
"""
|
46
48
|
if not params:
|
47
49
|
params = {}
|
48
|
-
|
50
|
+
|
49
51
|
logger.info(f"Executing command via TST: {command}, params: {params}")
|
50
|
-
|
52
|
+
|
51
53
|
try:
|
52
54
|
# Проверяем существование команды
|
53
55
|
if not registry.command_exists_with_priority(command):
|
54
56
|
raise NotFoundError(f"Команда '{command}' не найдена")
|
55
|
-
|
57
|
+
|
56
58
|
# Получаем класс команды
|
57
59
|
command_class = registry.get_command_with_priority(command)
|
58
|
-
|
60
|
+
|
59
61
|
# Выполняем команду
|
60
62
|
result = await command_class.execute(**params)
|
61
|
-
|
63
|
+
|
62
64
|
# Возвращаем результат
|
63
65
|
return result.to_dict()
|
64
66
|
except NotFoundError as e:
|
@@ -67,79 +69,87 @@ class TSTCommandExecutor:
|
|
67
69
|
except Exception as e:
|
68
70
|
logger.exception(f"Error executing command {command}: {e}")
|
69
71
|
raise
|
70
|
-
|
72
|
+
|
71
73
|
@classmethod
|
72
74
|
def get_schema(cls) -> Dict[str, Any]:
|
73
75
|
"""
|
74
76
|
Возвращает схему инструмента в формате OpenAPI.
|
75
|
-
|
77
|
+
|
76
78
|
Returns:
|
77
79
|
Словарь со схемой инструмента
|
78
80
|
"""
|
79
81
|
return ToolIntegration.generate_tool_schema(cls.name, registry, cls.description)
|
80
|
-
|
82
|
+
|
81
83
|
@classmethod
|
82
84
|
def get_description(cls, format: str = "json") -> Union[Dict[str, Any], str]:
|
83
85
|
"""
|
84
86
|
Возвращает полное описание инструмента в указанном формате.
|
85
|
-
|
87
|
+
|
86
88
|
Args:
|
87
89
|
format: Формат описания (json, markdown, html)
|
88
|
-
|
90
|
+
|
89
91
|
Returns:
|
90
92
|
Описание инструмента в указанном формате
|
91
93
|
"""
|
92
94
|
if format.lower() == "json":
|
93
95
|
# Получаем базовое описание инструмента
|
94
|
-
base_description = ToolIntegration.generate_tool_schema(
|
95
|
-
|
96
|
+
base_description = ToolIntegration.generate_tool_schema(
|
97
|
+
cls.name, registry, cls.description
|
98
|
+
)
|
99
|
+
|
96
100
|
# Добавляем дополнительную информацию
|
97
101
|
base_description["examples"] = cls._generate_examples()
|
98
102
|
base_description["error_codes"] = cls._generate_error_codes()
|
99
|
-
|
103
|
+
|
100
104
|
return base_description
|
101
105
|
elif format.lower() in ["markdown", "text", "html"]:
|
102
|
-
return ToolIntegration.generate_tool_documentation(
|
106
|
+
return ToolIntegration.generate_tool_documentation(
|
107
|
+
cls.name, registry, format
|
108
|
+
)
|
103
109
|
else:
|
104
110
|
# По умолчанию возвращаем JSON формат
|
105
|
-
return ToolIntegration.generate_tool_schema(
|
106
|
-
|
111
|
+
return ToolIntegration.generate_tool_schema(
|
112
|
+
cls.name, registry, cls.description
|
113
|
+
)
|
114
|
+
|
107
115
|
@classmethod
|
108
116
|
def _generate_examples(cls) -> List[Dict[str, Any]]:
|
109
117
|
"""
|
110
118
|
Генерирует примеры использования инструмента.
|
111
|
-
|
119
|
+
|
112
120
|
Returns:
|
113
121
|
Список примеров использования
|
114
122
|
"""
|
115
123
|
examples = []
|
116
|
-
|
124
|
+
|
117
125
|
# Получаем метаданные всех команд
|
118
126
|
all_metadata = registry.get_all_metadata()
|
119
|
-
|
127
|
+
|
120
128
|
# Добавляем по одному примеру для каждой команды
|
121
129
|
for cmd_name, metadata in all_metadata.items():
|
122
130
|
if metadata.get("examples"):
|
123
131
|
# Берем первый пример из метаданных
|
124
132
|
example = metadata["examples"][0]
|
125
|
-
|
133
|
+
|
126
134
|
# Формируем пример использования инструмента
|
127
|
-
examples.append(
|
128
|
-
|
129
|
-
|
130
|
-
"
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
135
|
+
examples.append(
|
136
|
+
{
|
137
|
+
"command": cls.name,
|
138
|
+
"params": {
|
139
|
+
"command": example.get("command", cmd_name),
|
140
|
+
"params": example.get("params", {}),
|
141
|
+
},
|
142
|
+
"description": f"Выполнение команды {cmd_name}",
|
143
|
+
}
|
144
|
+
)
|
145
|
+
|
136
146
|
return examples
|
137
|
-
|
147
|
+
|
138
148
|
@classmethod
|
139
149
|
def _generate_error_codes(cls) -> Dict[str, str]:
|
140
150
|
"""
|
141
151
|
Генерирует словарь возможных кодов ошибок.
|
142
|
-
|
152
|
+
|
143
153
|
Returns:
|
144
154
|
Словарь с кодами ошибок и их описаниями
|
145
155
|
"""
|
@@ -148,27 +158,27 @@ class TSTCommandExecutor:
|
|
148
158
|
"-32601": "Команда не найдена",
|
149
159
|
"-32602": "Некорректные параметры",
|
150
160
|
"-32603": "Внутренняя ошибка",
|
151
|
-
"-32000": "Ошибка выполнения команды"
|
161
|
+
"-32000": "Ошибка выполнения команды",
|
152
162
|
}
|
153
163
|
|
154
164
|
|
155
165
|
# Экспортируем доступные инструменты API
|
156
|
-
available_tools = {
|
157
|
-
TSTCommandExecutor.name: TSTCommandExecutor
|
158
|
-
}
|
166
|
+
available_tools = {TSTCommandExecutor.name: TSTCommandExecutor}
|
159
167
|
|
160
168
|
|
161
|
-
def get_tool_description(
|
169
|
+
def get_tool_description(
|
170
|
+
tool_name: str, format: str = "json"
|
171
|
+
) -> Union[Dict[str, Any], str]:
|
162
172
|
"""
|
163
173
|
Получает описание инструмента API по имени.
|
164
|
-
|
174
|
+
|
165
175
|
Args:
|
166
176
|
tool_name: Имя инструмента API
|
167
177
|
format: Формат описания (json, markdown, html)
|
168
|
-
|
178
|
+
|
169
179
|
Returns:
|
170
180
|
Описание инструмента в указанном формате
|
171
|
-
|
181
|
+
|
172
182
|
Raises:
|
173
183
|
NotFoundError: Если инструмент не найден
|
174
184
|
"""
|
@@ -181,18 +191,18 @@ def get_tool_description(tool_name: str, format: str = "json") -> Union[Dict[str
|
|
181
191
|
async def execute_tool(tool_name: str, **params) -> Dict[str, Any]:
|
182
192
|
"""
|
183
193
|
Выполняет инструмент API с указанными параметрами.
|
184
|
-
|
194
|
+
|
185
195
|
Args:
|
186
196
|
tool_name: Имя инструмента API
|
187
197
|
**params: Параметры инструмента
|
188
|
-
|
198
|
+
|
189
199
|
Returns:
|
190
200
|
Результат выполнения инструмента
|
191
|
-
|
201
|
+
|
192
202
|
Raises:
|
193
203
|
NotFoundError: Если инструмент не найден
|
194
204
|
"""
|
195
205
|
if tool_name in available_tools:
|
196
206
|
return await available_tools[tool_name].execute(**params)
|
197
207
|
else:
|
198
|
-
raise NotFoundError(f"Инструмент '{tool_name}' не найден")
|
208
|
+
raise NotFoundError(f"Инструмент '{tool_name}' не найден")
|
@@ -4,22 +4,31 @@ Commands module initialization file.
|
|
4
4
|
|
5
5
|
from mcp_proxy_adapter.commands.base import Command
|
6
6
|
from mcp_proxy_adapter.commands.command_registry import registry, CommandRegistry
|
7
|
-
from mcp_proxy_adapter.commands.dependency_container import
|
7
|
+
from mcp_proxy_adapter.commands.dependency_container import (
|
8
|
+
container,
|
9
|
+
DependencyContainer,
|
10
|
+
)
|
8
11
|
from mcp_proxy_adapter.commands.result import CommandResult, SuccessResult, ErrorResult
|
9
12
|
from mcp_proxy_adapter.commands.auth_validation_command import AuthValidationCommand
|
10
13
|
from mcp_proxy_adapter.commands.ssl_setup_command import SSLSetupCommand
|
11
|
-
from mcp_proxy_adapter.commands.certificate_management_command import
|
14
|
+
from mcp_proxy_adapter.commands.certificate_management_command import (
|
15
|
+
CertificateManagementCommand,
|
16
|
+
)
|
12
17
|
from mcp_proxy_adapter.commands.key_management_command import KeyManagementCommand
|
13
18
|
from mcp_proxy_adapter.commands.cert_monitor_command import CertMonitorCommand
|
14
|
-
from mcp_proxy_adapter.commands.transport_management_command import
|
19
|
+
from mcp_proxy_adapter.commands.transport_management_command import (
|
20
|
+
TransportManagementCommand,
|
21
|
+
)
|
15
22
|
from mcp_proxy_adapter.commands.role_test_command import RoleTestCommand
|
16
23
|
from mcp_proxy_adapter.commands.echo_command import EchoCommand
|
17
|
-
from mcp_proxy_adapter.commands.proxy_registration_command import
|
24
|
+
from mcp_proxy_adapter.commands.proxy_registration_command import (
|
25
|
+
ProxyRegistrationCommand,
|
26
|
+
)
|
18
27
|
|
19
28
|
__all__ = [
|
20
29
|
"Command",
|
21
30
|
"CommandResult",
|
22
|
-
"SuccessResult",
|
31
|
+
"SuccessResult",
|
23
32
|
"ErrorResult",
|
24
33
|
"registry",
|
25
34
|
"CommandRegistry",
|
@@ -33,5 +42,5 @@ __all__ = [
|
|
33
42
|
"TransportManagementCommand",
|
34
43
|
"RoleTestCommand",
|
35
44
|
"EchoCommand",
|
36
|
-
"ProxyRegistrationCommand"
|
45
|
+
"ProxyRegistrationCommand",
|
37
46
|
]
|