Skip to content

Commit 58cd68a

Browse files
committed
fix: Update test mock to work with lazy jsonschema import
The lazy import change caused the test's `bypass_server_output_validation()` to inadvertently mock the client's validation as well. This updates the mock to selectively bypass only server-side validation by checking the call stack.
1 parent ca5cb68 commit 58cd68a

File tree

1 file changed

+19
-3
lines changed

1 file changed

+19
-3
lines changed

tests/client/test_output_schema_validation.py

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,25 @@ def bypass_server_output_validation():
1919
This simulates a malicious or non-compliant server that doesn't validate
2020
its outputs, allowing us to test client-side validation.
2121
"""
22-
# Patch jsonschema.validate in the server module to disable all validation
23-
with patch("mcp.server.lowlevel.server.jsonschema.validate"):
24-
# The mock will simply return None (do nothing) for all validation calls
22+
import jsonschema
23+
24+
# Save the original validate function
25+
original_validate = jsonschema.validate
26+
27+
# Create a mock that tracks which module is calling it
28+
def selective_mock(instance: Any = None, schema: Any = None, *args: Any, **kwargs: Any) -> None:
29+
import inspect
30+
31+
# Check the call stack to see where this is being called from
32+
for frame_info in inspect.stack():
33+
# If called from the server module, skip validation
34+
# TODO: fix this as it's a rather gross workaround and will eventually break
35+
if "mcp/server/lowlevel/server.py" in frame_info.filename:
36+
return None
37+
# Otherwise, use the real validation (for client-side)
38+
return original_validate(instance=instance, schema=schema, *args, **kwargs)
39+
40+
with patch("jsonschema.validate", selective_mock):
2541
yield
2642

2743

0 commit comments

Comments
 (0)