-
-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Expand file tree
/
Copy pathtest_mcp_client_sanitization.py
More file actions
61 lines (49 loc) · 1.6 KB
/
test_mcp_client_sanitization.py
File metadata and controls
61 lines (49 loc) · 1.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
from astrbot.core.agent.mcp_client import _sanitize_mcp_arguments
def test_sanitize_mcp_arguments_drops_empty_optional_object_fields():
schema = {
"type": "object",
"properties": {
"name": {"type": "string"},
"area": {"type": "string"},
"floor": {"type": "string"},
"domain": {"type": "array", "items": {"type": "string"}},
"device_class": {"type": "array", "items": {"type": "string"}},
},
"required": ["name"],
}
value = {
"name": "demo",
"area": "",
"floor": "",
"domain": ["light"],
"device_class": [],
}
assert _sanitize_mcp_arguments(value, schema) == {
"name": "demo",
"domain": ["light"],
}
def test_sanitize_mcp_arguments_preserves_required_empty_values():
schema = {
"type": "object",
"properties": {
"name": {"type": "string"},
"tags": {"type": "array", "items": {"type": "string"}},
"metadata": {
"type": "object",
"properties": {
"note": {"type": "string"},
},
},
},
"required": ["name", "tags", "metadata"],
}
value = {
"name": "",
"tags": [],
"metadata": {},
}
assert _sanitize_mcp_arguments(value, schema) == value
def test_sanitize_mcp_arguments_preserves_list_positions():
schema = {"type": "array", "items": {"type": "string"}}
value = ["alpha", "", "omega"]
assert _sanitize_mcp_arguments(value, schema) == ["alpha", "", "omega"]