From 0cc6505b01341114e20c797da73cf752446ae406 Mon Sep 17 00:00:00 2001 From: William Easton Date: Tue, 14 Apr 2026 10:04:07 -0500 Subject: [PATCH] Guard against query params clobbering path params MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 🤖 Generated with Claude Code Co-Authored-By: Claude Opus 4.6 (1M context) --- src/fastmcp/resources/template.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/fastmcp/resources/template.py b/src/fastmcp/resources/template.py index 5c4553ad1..3422ef233 100644 --- a/src/fastmcp/resources/template.py +++ b/src/fastmcp/resources/template.py @@ -110,7 +110,10 @@ def match_uri_template(uri: str, uri_template: str) -> dict[str, str] | None: if name in parsed_query: # Take first value if multiple provided. # Normalize hyphens to underscores to match Python param names. - params[name.replace("-", "_")] = parsed_query[name][0] + # Don't overwrite path params that were already extracted. + key = name.replace("-", "_") + if key not in params: + params[key] = parsed_query[name][0] return params