diff --git a/src/mcp/shared/uri_template.py b/src/mcp/shared/uri_template.py index 20d6fa9c2e..fa5e62e4f1 100644 --- a/src/mcp/shared/uri_template.py +++ b/src/mcp/shared/uri_template.py @@ -997,6 +997,12 @@ def _scan_suffix( stops = _STOP_CHARS[var.operator] prev = atoms[i - 1] if i > 0 else None + # A dotted variable immediately following a literal has an unambiguous + # boundary: the operator's dot is the separator. Keep additional dots in + # the value so expansions such as `file{.ext}` with `ext="tar.gz"` round-trip. + if var.operator == "." and isinstance(prev, _Lit) and (i < 2 or isinstance(atoms[i - 2], _Lit)): + stops = "/?#" + if atom.ifemp: # ;name or ;name=value. The preceding _Lit is ";name". # Try empty first: if the lit ends at pos the value is diff --git a/tests/shared/test_uri_template.py b/tests/shared/test_uri_template.py index cddbb82b0b..8d9ac67852 100644 --- a/tests/shared/test_uri_template.py +++ b/tests/shared/test_uri_template.py @@ -838,6 +838,7 @@ def test_match_explode_encoded_separator_in_segment(): ("file://docs/{+path}", {"path": "src/main.py"}), ("search{?q,lang}", {"q": "mcp", "lang": "en"}), ("file{.ext}", {"ext": "txt"}), + ("file{.ext}", {"ext": "tar.gz"}), ("/files{/path*}", {"path": ["a", "b", "c"]}), ("{var}", {"var": "hello world"}), ("item{;id}", {"id": "42"}),