Skip to content

Commit f9aa92b

Browse files
committed
revert: remove frozenset coercion in ResourceSecurity.__post_init__
Passing a mutable set to a frozen dataclass and expecting hash() to work is a caller error, not something the SDK needs to defend against.
1 parent d3a0936 commit f9aa92b

File tree

2 files changed

+0
-13
lines changed

2 files changed

+0
-13
lines changed

src/mcp/server/mcpserver/resources/templates.py

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -54,11 +54,6 @@ def git_diff(range: str) -> str: ...
5454
exempt_params: Set[str] = field(default_factory=frozenset[str])
5555
"""Parameter names to skip all checks for."""
5656

57-
def __post_init__(self) -> None:
58-
# Coerce to frozenset so the dataclass stays hashable even if
59-
# callers pass a regular set.
60-
object.__setattr__(self, "exempt_params", frozenset(self.exempt_params))
61-
6257
def validate(self, params: Mapping[str, str | list[str]]) -> str | None:
6358
"""Check all parameter values against the configured policy.
6459

tests/server/mcpserver/resources/test_resource_template.py

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -89,14 +89,6 @@ def test_matches_null_byte_check_can_be_disabled():
8989
assert t.matches("file://docs/key%00.txt") == {"name": "key\x00.txt"}
9090

9191

92-
def test_resource_security_hashable_with_regular_set():
93-
# Frozen dataclass auto-generates __hash__ from all fields, so a
94-
# mutable set would make the instance unhashable. __post_init__
95-
# coerces to frozenset.
96-
policy = ResourceSecurity(exempt_params={"a", "b"})
97-
assert hash(policy) == hash(ResourceSecurity(exempt_params=frozenset({"a", "b"})))
98-
99-
10092
def test_security_rejection_does_not_fall_through_to_next_template():
10193
# A strict template's security rejection must halt iteration, not
10294
# fall through to a later permissive template. Previously matches()

0 commit comments

Comments
 (0)