Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions src/mcp/shared/uri_template.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions tests/shared/test_uri_template.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"}),
Expand Down
Loading