-
Notifications
You must be signed in to change notification settings - Fork 3.3k
Expand file tree
/
Copy pathtest_meta.py
More file actions
65 lines (60 loc) · 1.65 KB
/
test_meta.py
File metadata and controls
65 lines (60 loc) · 1.65 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
62
63
64
65
import pytest
from mcp import types
@pytest.mark.parametrize(
argnames="key",
argvalues=[
# Simple keys without reserved prefix
"clientId",
"request-id",
"api_version",
"product-id",
"x-correlation-id",
"my-key",
"info",
"data-1",
"label-key",
# Keys with reserved prefix
"modelcontextprotocol.io/request-id",
"mcp.dev/debug-mode",
"api.modelcontextprotocol.org/api-version",
"tools.mcp.com/validation-status",
"my-company.mcp.io/internal-flag",
"modelcontextprotocol.io/a",
"mcp.dev/b-c",
# Keys with non-reserved prefix
"my-app.com/user-preferences",
"internal.api/tracking-id",
"org.example/resource-type",
"custom.domain/status",
],
)
def test_metadata_valid_keys(key: str):
"""
Asserts that valid metadata keys does not raise ValueErrors
"""
types.RequestParams.Meta(**{key: "value"})
@pytest.mark.parametrize(
argnames="key",
argvalues=[
# Invalid key names (without prefix)
"-leading-hyphen",
"trailing-hyphen-",
"with space",
"key/with/slash",
"no@special-chars",
"...",
# Invalid prefixes
"mcp.123/key",
"my.custom./key",
"my-app.com//key",
# Invalid combination of prefix and name
"mcp.dev/-invalid",
"org.example/invalid-name-",
],
)
def test_metadata_invalid_keys(key: str):
"""
Asserts that invalid metadata keys raise ValueErrors
"""
with pytest.raises(ValueError):
types.RequestParams.Meta(**{key: "value"})