elemctl 0.53.0__tar.gz → 0.53.1__tar.gz
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.
- {elemctl-0.53.0 → elemctl-0.53.1}/PKG-INFO +1 -1
- {elemctl-0.53.0 → elemctl-0.53.1}/docs/changelog.md +10 -0
- {elemctl-0.53.0 → elemctl-0.53.1}/docs/changelog.ru.md +11 -0
- {elemctl-0.53.0 → elemctl-0.53.1}/src/elemctl/__init__.py +1 -1
- {elemctl-0.53.0 → elemctl-0.53.1}/src/elemctl/i18n.py +34 -0
- {elemctl-0.53.0 → elemctl-0.53.1}/src/elemctl/mcp_server.py +152 -0
- {elemctl-0.53.0 → elemctl-0.53.1}/src/elemctl.egg-info/PKG-INFO +1 -1
- {elemctl-0.53.0 → elemctl-0.53.1}/tests/test_mcp.py +262 -0
- {elemctl-0.53.0 → elemctl-0.53.1}/.env.example +0 -0
- {elemctl-0.53.0 → elemctl-0.53.1}/LICENSE +0 -0
- {elemctl-0.53.0 → elemctl-0.53.1}/MANIFEST.in +0 -0
- {elemctl-0.53.0 → elemctl-0.53.1}/NOTICE +0 -0
- {elemctl-0.53.0 → elemctl-0.53.1}/ORIGIN.md +0 -0
- {elemctl-0.53.0 → elemctl-0.53.1}/README.md +0 -0
- {elemctl-0.53.0 → elemctl-0.53.1}/docs/SPEC.md +0 -0
- {elemctl-0.53.0 → elemctl-0.53.1}/docs/SPEC.ru.md +0 -0
- {elemctl-0.53.0 → elemctl-0.53.1}/docs/cli.md +0 -0
- {elemctl-0.53.0 → elemctl-0.53.1}/docs/cli.ru.md +0 -0
- {elemctl-0.53.0 → elemctl-0.53.1}/docs/config.md +0 -0
- {elemctl-0.53.0 → elemctl-0.53.1}/docs/config.ru.md +0 -0
- {elemctl-0.53.0 → elemctl-0.53.1}/docs/index.md +0 -0
- {elemctl-0.53.0 → elemctl-0.53.1}/docs/index.ru.md +0 -0
- {elemctl-0.53.0 → elemctl-0.53.1}/docs/library.md +0 -0
- {elemctl-0.53.0 → elemctl-0.53.1}/docs/library.ru.md +0 -0
- {elemctl-0.53.0 → elemctl-0.53.1}/docs/mcp.md +0 -0
- {elemctl-0.53.0 → elemctl-0.53.1}/docs/mcp.ru.md +0 -0
- {elemctl-0.53.0 → elemctl-0.53.1}/docs/platform.md +0 -0
- {elemctl-0.53.0 → elemctl-0.53.1}/docs/platform.ru.md +0 -0
- {elemctl-0.53.0 → elemctl-0.53.1}/pyproject.toml +0 -0
- {elemctl-0.53.0 → elemctl-0.53.1}/setup.cfg +0 -0
- {elemctl-0.53.0 → elemctl-0.53.1}/src/elemctl/__main__.py +0 -0
- {elemctl-0.53.0 → elemctl-0.53.1}/src/elemctl/auth.py +0 -0
- {elemctl-0.53.0 → elemctl-0.53.1}/src/elemctl/build.py +0 -0
- {elemctl-0.53.0 → elemctl-0.53.1}/src/elemctl/cli.py +0 -0
- {elemctl-0.53.0 → elemctl-0.53.1}/src/elemctl/client.py +0 -0
- {elemctl-0.53.0 → elemctl-0.53.1}/src/elemctl/config.py +0 -0
- {elemctl-0.53.0 → elemctl-0.53.1}/src/elemctl/deploy.py +0 -0
- {elemctl-0.53.0 → elemctl-0.53.1}/src/elemctl/errors.py +0 -0
- {elemctl-0.53.0 → elemctl-0.53.1}/src/elemctl/plugins.py +0 -0
- {elemctl-0.53.0 → elemctl-0.53.1}/src/elemctl/probe.py +0 -0
- {elemctl-0.53.0 → elemctl-0.53.1}/src/elemctl/registry.py +0 -0
- {elemctl-0.53.0 → elemctl-0.53.1}/src/elemctl/schema.py +0 -0
- {elemctl-0.53.0 → elemctl-0.53.1}/src/elemctl/selfupdate.py +0 -0
- {elemctl-0.53.0 → elemctl-0.53.1}/src/elemctl/transport.py +0 -0
- {elemctl-0.53.0 → elemctl-0.53.1}/src/elemctl/versions.py +0 -0
- {elemctl-0.53.0 → elemctl-0.53.1}/src/elemctl.egg-info/SOURCES.txt +0 -0
- {elemctl-0.53.0 → elemctl-0.53.1}/src/elemctl.egg-info/dependency_links.txt +0 -0
- {elemctl-0.53.0 → elemctl-0.53.1}/src/elemctl.egg-info/entry_points.txt +0 -0
- {elemctl-0.53.0 → elemctl-0.53.1}/src/elemctl.egg-info/requires.txt +0 -0
- {elemctl-0.53.0 → elemctl-0.53.1}/src/elemctl.egg-info/top_level.txt +0 -0
- {elemctl-0.53.0 → elemctl-0.53.1}/tests/test_app_export.py +0 -0
- {elemctl-0.53.0 → elemctl-0.53.1}/tests/test_app_users.py +0 -0
- {elemctl-0.53.0 → elemctl-0.53.1}/tests/test_build.py +0 -0
- {elemctl-0.53.0 → elemctl-0.53.1}/tests/test_build_project.py +0 -0
- {elemctl-0.53.0 → elemctl-0.53.1}/tests/test_changelog_link.py +0 -0
- {elemctl-0.53.0 → elemctl-0.53.1}/tests/test_cli.py +0 -0
- {elemctl-0.53.0 → elemctl-0.53.1}/tests/test_cli_docs.py +0 -0
- {elemctl-0.53.0 → elemctl-0.53.1}/tests/test_client.py +0 -0
- {elemctl-0.53.0 → elemctl-0.53.1}/tests/test_config.py +0 -0
- {elemctl-0.53.0 → elemctl-0.53.1}/tests/test_conventions.py +0 -0
- {elemctl-0.53.0 → elemctl-0.53.1}/tests/test_deploy.py +0 -0
- {elemctl-0.53.0 → elemctl-0.53.1}/tests/test_docs_coverage.py +0 -0
- {elemctl-0.53.0 → elemctl-0.53.1}/tests/test_extension_export.py +0 -0
- {elemctl-0.53.0 → elemctl-0.53.1}/tests/test_extension_verify.py +0 -0
- {elemctl-0.53.0 → elemctl-0.53.1}/tests/test_extract_adapter.py +0 -0
- {elemctl-0.53.0 → elemctl-0.53.1}/tests/test_i18n.py +0 -0
- {elemctl-0.53.0 → elemctl-0.53.1}/tests/test_numbering_jumps.py +0 -0
- {elemctl-0.53.0 → elemctl-0.53.1}/tests/test_plugins.py +0 -0
- {elemctl-0.53.0 → elemctl-0.53.1}/tests/test_probe.py +0 -0
- {elemctl-0.53.0 → elemctl-0.53.1}/tests/test_probe_cleanup.py +0 -0
- {elemctl-0.53.0 → elemctl-0.53.1}/tests/test_rebuild_docs.py +0 -0
- {elemctl-0.53.0 → elemctl-0.53.1}/tests/test_registry.py +0 -0
- {elemctl-0.53.0 → elemctl-0.53.1}/tests/test_release_notes.py +0 -0
- {elemctl-0.53.0 → elemctl-0.53.1}/tests/test_schema.py +0 -0
- {elemctl-0.53.0 → elemctl-0.53.1}/tests/test_selfupdate.py +0 -0
- {elemctl-0.53.0 → elemctl-0.53.1}/tests/test_selfupdate_latest.py +0 -0
- {elemctl-0.53.0 → elemctl-0.53.1}/tests/test_server_starting.py +0 -0
- {elemctl-0.53.0 → elemctl-0.53.1}/tests/test_token_access.py +0 -0
- {elemctl-0.53.0 → elemctl-0.53.1}/tests/test_transport.py +0 -0
- {elemctl-0.53.0 → elemctl-0.53.1}/tests/test_user_lists.py +0 -0
- {elemctl-0.53.0 → elemctl-0.53.1}/tests/test_versions.py +0 -0
- {elemctl-0.53.0 → elemctl-0.53.1}/tests/test_workflows.py +0 -0
- {elemctl-0.53.0 → elemctl-0.53.1}/tools/extract_adapter.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: elemctl
|
|
3
|
-
Version: 0.53.
|
|
3
|
+
Version: 0.53.1
|
|
4
4
|
Summary: CLI, MCP server and library for managing 1C:Element applications through Console API v2: builds from source, deployment with verification and temporary compilation probes
|
|
5
5
|
Author: KeyFire
|
|
6
6
|
License-Expression: MIT
|
|
@@ -22,6 +22,16 @@ Run `python scripts/changelog-link.py <number>` to add the link and rebuild
|
|
|
22
22
|
the generated site pages. This updates both language editions and their mirrors
|
|
23
23
|
together.
|
|
24
24
|
|
|
25
|
+
## 2026-12-02 – 0.53.1
|
|
26
|
+
|
|
27
|
+
### Fixed
|
|
28
|
+
|
|
29
|
+
- **Reject unknown parameters in MCP tool calls.** Previously, the MCP server dropped
|
|
30
|
+
unrecognized keys and ran the handler with defaults, so a mistyped parameter failed later
|
|
31
|
+
without pointing to the cause. Now the server checks keys for core and plugin tools before
|
|
32
|
+
running the handler, naming unknown parameters, suggesting close matches and listing allowed
|
|
33
|
+
parameters. ([#64](https://github.com/keyfire/elemctl/pull/64))
|
|
34
|
+
|
|
25
35
|
## 2026-11-07 – 0.53.0
|
|
26
36
|
|
|
27
37
|
### Added
|
|
@@ -22,6 +22,17 @@ sidebar:
|
|
|
22
22
|
сгенерированные страницы сайта. Запускайте ее вместо ручного добавления ссылки,
|
|
23
23
|
чтобы одновременно обновить обе языковые версии и их зеркала.
|
|
24
24
|
|
|
25
|
+
## 02.12.2026 – 0.53.1
|
|
26
|
+
|
|
27
|
+
### Исправлено
|
|
28
|
+
|
|
29
|
+
- **Отклонять неизвестные параметры в вызовах инструментов MCP.** Раньше MCP-сервер
|
|
30
|
+
отбрасывал лишние ключи и запускал обработчик со значениями по умолчанию, из-за чего
|
|
31
|
+
ошибка возникала уже внутри команды без указания причины. Теперь сервер проверяет ключи
|
|
32
|
+
для инструментов ядра и плагинов до запуска обработчика, называет лишние параметры,
|
|
33
|
+
подсказывает близкие имена и выводит список допустимых параметров.
|
|
34
|
+
([#64](https://github.com/keyfire/elemctl/pull/64))
|
|
35
|
+
|
|
25
36
|
## 07.11.2026 – 0.53.0
|
|
26
37
|
|
|
27
38
|
### Добавлено
|
|
@@ -751,6 +751,40 @@ MESSAGES = {
|
|
|
751
751
|
"ru": 'для MCP-сервера нужен extra: pip install "elemctl[mcp]"',
|
|
752
752
|
"en": 'the MCP server needs the extra: pip install "elemctl[mcp]"',
|
|
753
753
|
},
|
|
754
|
+
"mcp.unknown-arg": {
|
|
755
|
+
"ru": "инструмент '{tool}' не принимает параметр '{unknown}'. "
|
|
756
|
+
"Допустимые параметры: {allowed}",
|
|
757
|
+
"en": "tool '{tool}' does not accept parameter '{unknown}'. "
|
|
758
|
+
"Allowed parameters: {allowed}",
|
|
759
|
+
},
|
|
760
|
+
"mcp.unknown-arg-hint": {
|
|
761
|
+
"ru": "инструмент '{tool}' не принимает параметр '{unknown}'. "
|
|
762
|
+
"Возможно, имелся в виду '{suggestion}'. Допустимые параметры: {allowed}",
|
|
763
|
+
"en": "tool '{tool}' does not accept parameter '{unknown}'. "
|
|
764
|
+
"Did you mean '{suggestion}'? Allowed parameters: {allowed}",
|
|
765
|
+
},
|
|
766
|
+
"mcp.unknown-args": {
|
|
767
|
+
"ru": "инструмент '{tool}' не принимает параметры: {unknown}. "
|
|
768
|
+
"Допустимые параметры: {allowed}",
|
|
769
|
+
"en": "tool '{tool}' does not accept parameters: {unknown}. "
|
|
770
|
+
"Allowed parameters: {allowed}",
|
|
771
|
+
},
|
|
772
|
+
"mcp.unknown-args-hint": {
|
|
773
|
+
"ru": "инструмент '{tool}' не принимает параметры: {unknown}. "
|
|
774
|
+
"Возможные замены: {suggestions}. Допустимые параметры: {allowed}",
|
|
775
|
+
"en": "tool '{tool}' does not accept parameters: {unknown}. "
|
|
776
|
+
"Possible matches: {suggestions}. Allowed parameters: {allowed}",
|
|
777
|
+
},
|
|
778
|
+
"mcp.no-params-arg": {
|
|
779
|
+
"ru": "инструмент '{tool}' не принимает параметров; "
|
|
780
|
+
"передан неизвестный параметр '{unknown}'",
|
|
781
|
+
"en": "tool '{tool}' takes no parameters; unknown parameter '{unknown}'",
|
|
782
|
+
},
|
|
783
|
+
"mcp.no-params-args": {
|
|
784
|
+
"ru": "инструмент '{tool}' не принимает параметров; "
|
|
785
|
+
"переданы неизвестные параметры: {unknown}",
|
|
786
|
+
"en": "tool '{tool}' takes no parameters; unknown parameters: {unknown}",
|
|
787
|
+
},
|
|
754
788
|
# -- plugins.py ---------------------------------------------------------------
|
|
755
789
|
"plugins.entry-point-failed": {
|
|
756
790
|
"ru": "точка расширения '{name}' группы {group} не загрузилась ({value}): {error}",
|
|
@@ -7,6 +7,7 @@ the optional extra "elemctl[mcp]" (the mcp package, either major version).
|
|
|
7
7
|
|
|
8
8
|
from __future__ import annotations
|
|
9
9
|
|
|
10
|
+
import difflib
|
|
10
11
|
import inspect
|
|
11
12
|
import os
|
|
12
13
|
import sys
|
|
@@ -43,6 +44,14 @@ except ImportError:
|
|
|
43
44
|
'the MCP server needs the extra: pip install "elemctl[mcp]"'
|
|
44
45
|
) from error
|
|
45
46
|
|
|
47
|
+
try:
|
|
48
|
+
from mcp.server.mcpserver.exceptions import ToolError as _McpToolError
|
|
49
|
+
except ImportError:
|
|
50
|
+
try:
|
|
51
|
+
from mcp.server.fastmcp.exceptions import ToolError as _McpToolError
|
|
52
|
+
except ImportError:
|
|
53
|
+
_McpToolError = None
|
|
54
|
+
|
|
46
55
|
from . import __version__, i18n, plugins
|
|
47
56
|
from .build import build_assembly, inspect_assembly
|
|
48
57
|
from .client import (
|
|
@@ -73,6 +82,13 @@ from .errors import ApiError, ElemctlError, PluginError
|
|
|
73
82
|
from .probe import cleanup_probe, cleanup_probes, probe_project
|
|
74
83
|
from .versions import newest_first
|
|
75
84
|
|
|
85
|
+
if isinstance(_McpToolError, type) and issubclass(_McpToolError, Exception):
|
|
86
|
+
class _InvalidToolArgumentsError(ElemctlError, _McpToolError):
|
|
87
|
+
"""Raised when an MCP tool receives keys absent from its input schema."""
|
|
88
|
+
else:
|
|
89
|
+
class _InvalidToolArgumentsError(ElemctlError):
|
|
90
|
+
"""Raised when an MCP tool receives keys absent from its input schema."""
|
|
91
|
+
|
|
76
92
|
INSTRUCTIONS = (
|
|
77
93
|
(
|
|
78
94
|
"Инструменты управления сервером 1С:Элемент через Console API v2. При ошибке применения "
|
|
@@ -1040,6 +1056,7 @@ def create_server(config=None, *, overrides=None, env_file=None):
|
|
|
1040
1056
|
return client(env_file).merge_branch(branch_id) or {"merged": True, "branch-id": branch_id}
|
|
1041
1057
|
|
|
1042
1058
|
add_plugin_tools(server, client)
|
|
1059
|
+
_install_strict_arguments(server)
|
|
1043
1060
|
return server
|
|
1044
1061
|
|
|
1045
1062
|
|
|
@@ -1124,6 +1141,141 @@ def _plugin_tool(command, client_for_env):
|
|
|
1124
1141
|
return tool
|
|
1125
1142
|
|
|
1126
1143
|
|
|
1144
|
+
def _tool_allowed_parameters(tool) -> tuple[str, ...] | None:
|
|
1145
|
+
"""Allowed parameter names declared in a registered tool's input schema.
|
|
1146
|
+
|
|
1147
|
+
Returns a tuple of names (empty for a zero-parameter tool), or None when the
|
|
1148
|
+
tool exposes no closed object schema (for example, additionalProperties=True).
|
|
1149
|
+
"""
|
|
1150
|
+
schema = getattr(tool, "parameters", None)
|
|
1151
|
+
if schema is None:
|
|
1152
|
+
schema = tool_input_schema(tool)
|
|
1153
|
+
if not isinstance(schema, dict):
|
|
1154
|
+
return None
|
|
1155
|
+
if schema.get("additionalProperties") is True:
|
|
1156
|
+
return None
|
|
1157
|
+
properties = schema.get("properties")
|
|
1158
|
+
if isinstance(properties, dict):
|
|
1159
|
+
return tuple(properties)
|
|
1160
|
+
return None
|
|
1161
|
+
|
|
1162
|
+
|
|
1163
|
+
def _suggest_parameter(name: str, allowed: tuple[str, ...]) -> str | None:
|
|
1164
|
+
"""Closest allowed parameter name for a mistyped key, or None."""
|
|
1165
|
+
if not allowed:
|
|
1166
|
+
return None
|
|
1167
|
+
matches = difflib.get_close_matches(name, allowed, n=1, cutoff=0.6)
|
|
1168
|
+
if matches:
|
|
1169
|
+
return matches[0]
|
|
1170
|
+
normalized_key = name.lower().replace("-", "_")
|
|
1171
|
+
by_norm: dict[str, str] = {}
|
|
1172
|
+
for candidate in allowed:
|
|
1173
|
+
by_norm.setdefault(candidate.lower().replace("-", "_"), candidate)
|
|
1174
|
+
norm_matches = difflib.get_close_matches(normalized_key, list(by_norm), n=1, cutoff=0.6)
|
|
1175
|
+
return by_norm[norm_matches[0]] if norm_matches else None
|
|
1176
|
+
|
|
1177
|
+
|
|
1178
|
+
def _validate_tool_arguments(
|
|
1179
|
+
tool_name: str, arguments: dict, allowed: tuple[str, ...] | None
|
|
1180
|
+
) -> None:
|
|
1181
|
+
"""Reject keys absent from the tool's schema before the handler runs.
|
|
1182
|
+
|
|
1183
|
+
Pydantic models generated by the mcp package ignore unknown fields by default,
|
|
1184
|
+
so a mistyped parameter name silently fell back to its default and failed
|
|
1185
|
+
later inside the command with an unrelated error.
|
|
1186
|
+
"""
|
|
1187
|
+
if allowed is None:
|
|
1188
|
+
return
|
|
1189
|
+
allowed_set = set(allowed)
|
|
1190
|
+
unknown = sorted(key for key in arguments if key not in allowed_set)
|
|
1191
|
+
if not unknown:
|
|
1192
|
+
return
|
|
1193
|
+
if not allowed:
|
|
1194
|
+
if len(unknown) == 1:
|
|
1195
|
+
message = i18n.t("mcp.no-params-arg", tool=tool_name, unknown=unknown[0])
|
|
1196
|
+
else:
|
|
1197
|
+
message = i18n.t("mcp.no-params-args", tool=tool_name, unknown=", ".join(unknown))
|
|
1198
|
+
raise _InvalidToolArgumentsError(message)
|
|
1199
|
+
|
|
1200
|
+
allowed_list = ", ".join(allowed)
|
|
1201
|
+
if len(unknown) == 1:
|
|
1202
|
+
suggestion = _suggest_parameter(unknown[0], allowed)
|
|
1203
|
+
if suggestion:
|
|
1204
|
+
message = i18n.t(
|
|
1205
|
+
"mcp.unknown-arg-hint",
|
|
1206
|
+
tool=tool_name,
|
|
1207
|
+
unknown=unknown[0],
|
|
1208
|
+
suggestion=suggestion,
|
|
1209
|
+
allowed=allowed_list,
|
|
1210
|
+
)
|
|
1211
|
+
else:
|
|
1212
|
+
message = i18n.t(
|
|
1213
|
+
"mcp.unknown-arg",
|
|
1214
|
+
tool=tool_name,
|
|
1215
|
+
unknown=unknown[0],
|
|
1216
|
+
allowed=allowed_list,
|
|
1217
|
+
)
|
|
1218
|
+
else:
|
|
1219
|
+
hints = [
|
|
1220
|
+
(bad, good)
|
|
1221
|
+
for bad in unknown
|
|
1222
|
+
if (good := _suggest_parameter(bad, allowed)) is not None
|
|
1223
|
+
]
|
|
1224
|
+
if hints:
|
|
1225
|
+
suggestions = ", ".join(f"{bad} -> {good}" for bad, good in hints)
|
|
1226
|
+
message = i18n.t(
|
|
1227
|
+
"mcp.unknown-args-hint",
|
|
1228
|
+
tool=tool_name,
|
|
1229
|
+
unknown=", ".join(unknown),
|
|
1230
|
+
suggestions=suggestions,
|
|
1231
|
+
allowed=allowed_list,
|
|
1232
|
+
)
|
|
1233
|
+
else:
|
|
1234
|
+
message = i18n.t(
|
|
1235
|
+
"mcp.unknown-args",
|
|
1236
|
+
tool=tool_name,
|
|
1237
|
+
unknown=", ".join(unknown),
|
|
1238
|
+
allowed=allowed_list,
|
|
1239
|
+
)
|
|
1240
|
+
raise _InvalidToolArgumentsError(message)
|
|
1241
|
+
|
|
1242
|
+
|
|
1243
|
+
def _lookup_tool(manager, name: str):
|
|
1244
|
+
"""Find a registered tool on the server's tool manager by name, or None."""
|
|
1245
|
+
getter = getattr(manager, "get_tool", None)
|
|
1246
|
+
if callable(getter):
|
|
1247
|
+
return getter(name)
|
|
1248
|
+
lister = getattr(manager, "list_tools", None)
|
|
1249
|
+
if callable(lister):
|
|
1250
|
+
for tool in lister():
|
|
1251
|
+
if getattr(tool, "name", None) == name:
|
|
1252
|
+
return tool
|
|
1253
|
+
return None
|
|
1254
|
+
|
|
1255
|
+
|
|
1256
|
+
def _install_strict_arguments(server) -> None:
|
|
1257
|
+
"""Wrap tool dispatch so unknown parameter names are rejected before validation.
|
|
1258
|
+
|
|
1259
|
+
Intercepting _tool_manager.call_tool covers both direct server.call_tool()
|
|
1260
|
+
invocations and protocol CallToolRequest handlers on both majors of the mcp
|
|
1261
|
+
package, for core tools and plugin tools alike. Test doubles without a tool
|
|
1262
|
+
manager are left untouched.
|
|
1263
|
+
"""
|
|
1264
|
+
manager = getattr(server, "_tool_manager", None)
|
|
1265
|
+
original = getattr(manager, "call_tool", None)
|
|
1266
|
+
if not callable(original):
|
|
1267
|
+
return
|
|
1268
|
+
|
|
1269
|
+
async def strict_call_tool(name: str, arguments=None, *args, **kwargs):
|
|
1270
|
+
if isinstance(arguments, dict) and arguments:
|
|
1271
|
+
tool = _lookup_tool(manager, name)
|
|
1272
|
+
if tool is not None:
|
|
1273
|
+
_validate_tool_arguments(name, arguments, _tool_allowed_parameters(tool))
|
|
1274
|
+
return await original(name, arguments, *args, **kwargs)
|
|
1275
|
+
|
|
1276
|
+
manager.call_tool = strict_call_tool
|
|
1277
|
+
|
|
1278
|
+
|
|
1127
1279
|
def _registered_tool_names(server):
|
|
1128
1280
|
"""The names of the tools already registered on the server.
|
|
1129
1281
|
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: elemctl
|
|
3
|
-
Version: 0.53.
|
|
3
|
+
Version: 0.53.1
|
|
4
4
|
Summary: CLI, MCP server and library for managing 1C:Element applications through Console API v2: builds from source, deployment with verification and temporary compilation probes
|
|
5
5
|
Author: KeyFire
|
|
6
6
|
License-Expression: MIT
|
|
@@ -1790,3 +1790,265 @@ def test_mcp_deploy_checks_the_expected_target_before_building(monkeypatch, tmp_
|
|
|
1790
1790
|
message = _root_elemctl_error_message(excinfo.value)
|
|
1791
1791
|
assert "uri" in message and "https://app.test/other" in message
|
|
1792
1792
|
assert target.upload_kwargs is None and target.apply_calls == []
|
|
1793
|
+
|
|
1794
|
+
|
|
1795
|
+
# --- Strict validation of unknown tool arguments ------------------------------------------
|
|
1796
|
+
|
|
1797
|
+
|
|
1798
|
+
@pytest.mark.parametrize("lang, hint_marker, allowed_marker", [
|
|
1799
|
+
("ru", "Возможно, имелся в виду 'app_id'", "Допустимые параметры: app_id, env_file"),
|
|
1800
|
+
("en", "Did you mean 'app_id'?", "Allowed parameters: app_id, env_file"),
|
|
1801
|
+
])
|
|
1802
|
+
def test_core_tool_rejects_mistyped_argument_with_suggestion(
|
|
1803
|
+
monkeypatch, lang, hint_marker, allowed_marker
|
|
1804
|
+
):
|
|
1805
|
+
from elemctl import i18n
|
|
1806
|
+
|
|
1807
|
+
called = []
|
|
1808
|
+
|
|
1809
|
+
class FakeClient:
|
|
1810
|
+
def resolve_app_id(self, app_id):
|
|
1811
|
+
called.append(app_id)
|
|
1812
|
+
return app_id
|
|
1813
|
+
|
|
1814
|
+
server = _server_on(monkeypatch, FakeClient())
|
|
1815
|
+
i18n.set_lang(lang)
|
|
1816
|
+
try:
|
|
1817
|
+
with pytest.raises(Exception) as excinfo:
|
|
1818
|
+
asyncio.run(server.call_tool("get_app", {"app-id": "crm-dev"}))
|
|
1819
|
+
finally:
|
|
1820
|
+
i18n.set_lang("ru")
|
|
1821
|
+
|
|
1822
|
+
message = _root_elemctl_error_message(excinfo.value)
|
|
1823
|
+
assert "get_app" in message
|
|
1824
|
+
assert "'app-id'" in message
|
|
1825
|
+
assert hint_marker in message
|
|
1826
|
+
assert allowed_marker in message
|
|
1827
|
+
assert called == []
|
|
1828
|
+
|
|
1829
|
+
|
|
1830
|
+
@pytest.mark.parametrize("lang, not_accepted, allowed_marker, absent_hint", [
|
|
1831
|
+
("ru", "не принимает параметр 'completely_foreign'", "Допустимые параметры:", "имелся в виду"),
|
|
1832
|
+
("en", "does not accept parameter 'completely_foreign'", "Allowed parameters:", "Did you mean"),
|
|
1833
|
+
])
|
|
1834
|
+
def test_core_tool_rejects_unrelated_unknown_argument_without_suggestion(
|
|
1835
|
+
monkeypatch, lang, not_accepted, allowed_marker, absent_hint
|
|
1836
|
+
):
|
|
1837
|
+
from elemctl import i18n
|
|
1838
|
+
|
|
1839
|
+
called = []
|
|
1840
|
+
|
|
1841
|
+
class FakeClient:
|
|
1842
|
+
def list_apps_counted(self, **kwargs):
|
|
1843
|
+
called.append(kwargs)
|
|
1844
|
+
return {"items": [], "total": 0, "live": 0, "shown": 0}
|
|
1845
|
+
|
|
1846
|
+
server = _server_on(monkeypatch, FakeClient())
|
|
1847
|
+
i18n.set_lang(lang)
|
|
1848
|
+
try:
|
|
1849
|
+
with pytest.raises(Exception) as excinfo:
|
|
1850
|
+
asyncio.run(server.call_tool("list_apps", {"completely_foreign": True}))
|
|
1851
|
+
finally:
|
|
1852
|
+
i18n.set_lang("ru")
|
|
1853
|
+
|
|
1854
|
+
message = _root_elemctl_error_message(excinfo.value)
|
|
1855
|
+
assert "list_apps" in message
|
|
1856
|
+
assert not_accepted in message
|
|
1857
|
+
assert allowed_marker in message
|
|
1858
|
+
assert "include_deleted" in message
|
|
1859
|
+
assert absent_hint not in message
|
|
1860
|
+
assert called == []
|
|
1861
|
+
|
|
1862
|
+
|
|
1863
|
+
@pytest.mark.parametrize("lang, expected_single, expected_multi", [
|
|
1864
|
+
(
|
|
1865
|
+
"ru",
|
|
1866
|
+
"инструмент 'debug_adapter' не принимает параметров; передан неизвестный параметр 'extra'",
|
|
1867
|
+
"инструмент 'debug_adapter' не принимает параметров; переданы неизвестные параметры: alpha, beta",
|
|
1868
|
+
),
|
|
1869
|
+
(
|
|
1870
|
+
"en",
|
|
1871
|
+
"tool 'debug_adapter' takes no parameters; unknown parameter 'extra'",
|
|
1872
|
+
"tool 'debug_adapter' takes no parameters; unknown parameters: alpha, beta",
|
|
1873
|
+
),
|
|
1874
|
+
])
|
|
1875
|
+
def test_zero_parameter_tool_rejects_any_argument(lang, expected_single, expected_multi):
|
|
1876
|
+
from elemctl import i18n
|
|
1877
|
+
|
|
1878
|
+
server = create_server()
|
|
1879
|
+
i18n.set_lang(lang)
|
|
1880
|
+
try:
|
|
1881
|
+
with pytest.raises(Exception) as single_exc:
|
|
1882
|
+
asyncio.run(server.call_tool("debug_adapter", {"extra": "value"}))
|
|
1883
|
+
with pytest.raises(Exception) as multi_exc:
|
|
1884
|
+
asyncio.run(server.call_tool("debug_adapter", {"beta": 2, "alpha": 1}))
|
|
1885
|
+
finally:
|
|
1886
|
+
i18n.set_lang("ru")
|
|
1887
|
+
|
|
1888
|
+
assert _root_elemctl_error_message(single_exc.value) == expected_single
|
|
1889
|
+
assert _root_elemctl_error_message(multi_exc.value) == expected_multi
|
|
1890
|
+
|
|
1891
|
+
|
|
1892
|
+
@pytest.mark.parametrize("lang, hint_marker, allowed_marker", [
|
|
1893
|
+
("ru", "Возможно, имелся в виду 'page'", "Допустимые параметры: page, format, env_file"),
|
|
1894
|
+
("en", "Did you mean 'page'?", "Allowed parameters: page, format, env_file"),
|
|
1895
|
+
])
|
|
1896
|
+
def test_plugin_tool_rejects_mistyped_argument_before_handler(
|
|
1897
|
+
monkeypatch, lang, hint_marker, allowed_marker
|
|
1898
|
+
):
|
|
1899
|
+
"""A plugin tool receiving page_id instead of page stops before the handler runs."""
|
|
1900
|
+
from elemctl import i18n, plugins
|
|
1901
|
+
|
|
1902
|
+
called = []
|
|
1903
|
+
|
|
1904
|
+
def handler(context, page=None, format="text"):
|
|
1905
|
+
called.append((page, format))
|
|
1906
|
+
return {"page": page, "format": format}
|
|
1907
|
+
|
|
1908
|
+
server = _server_with(monkeypatch, _plugin_command(
|
|
1909
|
+
name="wiki-get",
|
|
1910
|
+
arguments=[
|
|
1911
|
+
plugins.Argument("page", required=True, cli_alias="--page"),
|
|
1912
|
+
plugins.Argument("--format", default="text"),
|
|
1913
|
+
],
|
|
1914
|
+
handler=handler,
|
|
1915
|
+
))
|
|
1916
|
+
i18n.set_lang(lang)
|
|
1917
|
+
try:
|
|
1918
|
+
with pytest.raises(Exception) as excinfo:
|
|
1919
|
+
asyncio.run(server.call_tool("wiki_get", {"page_id": "123"}))
|
|
1920
|
+
finally:
|
|
1921
|
+
i18n.set_lang("ru")
|
|
1922
|
+
|
|
1923
|
+
message = _root_elemctl_error_message(excinfo.value)
|
|
1924
|
+
assert "wiki_get" in message
|
|
1925
|
+
assert "'page_id'" in message
|
|
1926
|
+
assert hint_marker in message
|
|
1927
|
+
assert allowed_marker in message
|
|
1928
|
+
assert called == []
|
|
1929
|
+
|
|
1930
|
+
|
|
1931
|
+
@pytest.mark.parametrize("lang, header_marker, hints_marker, allowed_marker", [
|
|
1932
|
+
("ru", "не принимает параметры: page_id, zzz", "Возможные замены: page_id -> page", "Допустимые параметры: page, env_file"),
|
|
1933
|
+
("en", "does not accept parameters: page_id, zzz", "Possible matches: page_id -> page", "Allowed parameters: page, env_file"),
|
|
1934
|
+
])
|
|
1935
|
+
def test_plugin_tool_rejects_multiple_unknown_arguments_with_partial_hints(
|
|
1936
|
+
monkeypatch, lang, header_marker, hints_marker, allowed_marker
|
|
1937
|
+
):
|
|
1938
|
+
from elemctl import i18n, plugins
|
|
1939
|
+
|
|
1940
|
+
called = []
|
|
1941
|
+
server = _server_with(monkeypatch, _plugin_command(
|
|
1942
|
+
name="wiki-get",
|
|
1943
|
+
arguments=[plugins.Argument("page", required=True, cli_alias="--page")],
|
|
1944
|
+
handler=lambda context, page=None: called.append(page) or {"page": page},
|
|
1945
|
+
))
|
|
1946
|
+
i18n.set_lang(lang)
|
|
1947
|
+
try:
|
|
1948
|
+
with pytest.raises(Exception) as excinfo:
|
|
1949
|
+
asyncio.run(server.call_tool("wiki_get", {"zzz": "x", "page_id": "123"}))
|
|
1950
|
+
finally:
|
|
1951
|
+
i18n.set_lang("ru")
|
|
1952
|
+
|
|
1953
|
+
message = _root_elemctl_error_message(excinfo.value)
|
|
1954
|
+
assert header_marker in message
|
|
1955
|
+
assert hints_marker in message
|
|
1956
|
+
assert allowed_marker in message
|
|
1957
|
+
assert called == []
|
|
1958
|
+
|
|
1959
|
+
|
|
1960
|
+
@pytest.mark.parametrize("lang, header_marker, absent_hint", [
|
|
1961
|
+
("ru", "не принимает параметры: alpha, beta", "Возможные замены"),
|
|
1962
|
+
("en", "does not accept parameters: alpha, beta", "Possible matches"),
|
|
1963
|
+
])
|
|
1964
|
+
def test_plugin_tool_rejects_multiple_unrelated_arguments_without_hints(
|
|
1965
|
+
monkeypatch, lang, header_marker, absent_hint
|
|
1966
|
+
):
|
|
1967
|
+
from elemctl import i18n, plugins
|
|
1968
|
+
|
|
1969
|
+
server = _server_with(monkeypatch, _plugin_command(
|
|
1970
|
+
name="wiki-get",
|
|
1971
|
+
arguments=[plugins.Argument("page", required=True)],
|
|
1972
|
+
handler=lambda context, page=None: {"page": page},
|
|
1973
|
+
))
|
|
1974
|
+
i18n.set_lang(lang)
|
|
1975
|
+
try:
|
|
1976
|
+
with pytest.raises(Exception) as excinfo:
|
|
1977
|
+
asyncio.run(server.call_tool("wiki_get", {"beta": 2, "alpha": 1}))
|
|
1978
|
+
finally:
|
|
1979
|
+
i18n.set_lang("ru")
|
|
1980
|
+
|
|
1981
|
+
message = _root_elemctl_error_message(excinfo.value)
|
|
1982
|
+
assert header_marker in message
|
|
1983
|
+
assert absent_hint not in message
|
|
1984
|
+
|
|
1985
|
+
|
|
1986
|
+
def test_valid_calls_with_core_and_plugin_schema_options_still_succeed(monkeypatch):
|
|
1987
|
+
"""Valid parameters, including plugin options with aliases and multiple values, pass."""
|
|
1988
|
+
from elemctl import plugins
|
|
1989
|
+
|
|
1990
|
+
class FakeClient:
|
|
1991
|
+
config = None
|
|
1992
|
+
|
|
1993
|
+
def resolve_app_id(self, app_id):
|
|
1994
|
+
return app_id
|
|
1995
|
+
|
|
1996
|
+
def get_app(self, app_id):
|
|
1997
|
+
return {"id": app_id, "name": "crm-dev", "status": "Running"}
|
|
1998
|
+
|
|
1999
|
+
def list_assemblies(self, project_id):
|
|
2000
|
+
return []
|
|
2001
|
+
|
|
2002
|
+
server = _server_on(monkeypatch, FakeClient())
|
|
2003
|
+
core_result = asyncio.run(server.call_tool("get_app", {"app_id": "app-1", "env_file": ""}))
|
|
2004
|
+
core_payload = json.loads(call_result_content(core_result)[0].text)
|
|
2005
|
+
assert core_payload["id"] == "app-1"
|
|
2006
|
+
|
|
2007
|
+
plugin_server = _server_with(monkeypatch, _plugin_command(
|
|
2008
|
+
name="wiki-export",
|
|
2009
|
+
arguments=[
|
|
2010
|
+
plugins.Argument("page", required=True, cli_alias="--page"),
|
|
2011
|
+
plugins.Argument("--out", default="", cli_prefix_alias="--report"),
|
|
2012
|
+
plugins.Argument("--tag", multiple=True),
|
|
2013
|
+
],
|
|
2014
|
+
handler=lambda context, **values: values,
|
|
2015
|
+
))
|
|
2016
|
+
plugin_result = asyncio.run(plugin_server.call_tool(
|
|
2017
|
+
"wiki_export", {"page": "123", "out": "report.md", "tag": ["a", "b"], "env_file": ""}
|
|
2018
|
+
))
|
|
2019
|
+
plugin_payload = json.loads(call_result_content(plugin_result)[0].text)
|
|
2020
|
+
assert plugin_payload == {"page": "123", "out": "report.md", "tag": ["a", "b"], "log": []}
|
|
2021
|
+
|
|
2022
|
+
|
|
2023
|
+
def test_unknown_tool_name_still_reports_unknown_tool():
|
|
2024
|
+
server = create_server()
|
|
2025
|
+
with pytest.raises(Exception, match="no_such_tool"):
|
|
2026
|
+
asyncio.run(server.call_tool("no_such_tool", {"anything": 1}))
|
|
2027
|
+
|
|
2028
|
+
|
|
2029
|
+
def test_protocol_call_tool_returns_error_result_for_unknown_argument(monkeypatch):
|
|
2030
|
+
"""Over the MCP protocol, an unknown argument returns an error result with our message."""
|
|
2031
|
+
import mcp.types as mcp_types
|
|
2032
|
+
|
|
2033
|
+
from elemctl import plugins
|
|
2034
|
+
|
|
2035
|
+
server = _server_with(monkeypatch, _plugin_command(
|
|
2036
|
+
name="wiki-get",
|
|
2037
|
+
arguments=[plugins.Argument("page", required=True, cli_alias="--page")],
|
|
2038
|
+
handler=lambda context, page=None: {"page": page},
|
|
2039
|
+
))
|
|
2040
|
+
lowlevel = getattr(server, "_mcp_server", None)
|
|
2041
|
+
handlers = getattr(lowlevel, "request_handlers", None) or {}
|
|
2042
|
+
handler = handlers.get(mcp_types.CallToolRequest)
|
|
2043
|
+
if handler is None:
|
|
2044
|
+
pytest.skip("lowlevel CallToolRequest handler is not exposed on this mcp version")
|
|
2045
|
+
|
|
2046
|
+
req = mcp_types.CallToolRequest(
|
|
2047
|
+
method="tools/call",
|
|
2048
|
+
params=mcp_types.CallToolRequestParams(name="wiki_get", arguments={"page_id": "123"}),
|
|
2049
|
+
)
|
|
2050
|
+
response = asyncio.run(handler(req))
|
|
2051
|
+
result = getattr(response, "root", response)
|
|
2052
|
+
assert getattr(result, "isError", getattr(result, "is_error", False)) is True
|
|
2053
|
+
text = call_result_content(result)[0].text
|
|
2054
|
+
assert "page_id" in text and "page" in text
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|