π The fast, Pythonic way to build MCP servers and clients.
fix: decode JSON Pointer tokens (Generated with Codex) (#5407)
Hua.Tccdbc81240e3
diff --git a/fastmcp_slim/fastmcp/utilities/json_schema_type.py b/fastmcp_slim/fastmcp/utilities/json_schema_type.pyindex 5107b78ed..b35aaa2e7 100644--- a/fastmcp_slim/fastmcp/utilities/json_schema_type.py+++ b/fastmcp_slim/fastmcp/utilities/json_schema_type.py@@ -403,6 +403,7 @@ def _resolve_ref(ref: str, schemas: Mapping[str, Any]) -> Mapping[str, Any]:path = ref.replace("#/", "").split("/")current = schemasfor part in path:+ part = part.replace("~1", "/").replace("~0", "~")current = current.get(part, {})return currentdiff --git a/tests/utilities/json_schema_type/test_advanced.py b/tests/utilities/json_schema_type/test_advanced.pyindex 01f4900ee..6dbf08733 100644--- a/tests/utilities/json_schema_type/test_advanced.py+++ b/tests/utilities/json_schema_type/test_advanced.py@@ -1,7 +1,7 @@"""Advanced JSON schema type conversion features."""from dataclasses import Field-from typing import Union+from typing import Any, Unionimport pytestfrom pydantic import BaseModel, TypeAdapter, ValidationError@@ -81,6 +81,25 @@ class TestDefaultValues:assert result.user.settings.theme == "system"+ "definition, token",+ [("plain", "plain"), ("a/b", "a~1b"), ("a~b", "a~0b"), ("a~1b", "a~01b")],+)+def test_escaped_reference_tokens(definition: str, token: str):+ schema = {+ "type": "object",+ "properties": {"value": {"$ref": f"#/$defs/{token}"}},+ "required": ["value"],+ "$defs": {definition: {"type": "integer", "minimum": 1}},+ }+ adapter: TypeAdapter[Any] = TypeAdapter(json_schema_to_type(schema))+ value = adapter.validate_python({"value": "7"}).value+ assert value == 7+ assert isinstance(value, int)+ with pytest.raises(ValidationError):+ adapter.validate_python({"value": 0})++class TestCircularReferences:"""Test suite for circular reference handling."""