Skip to content

Clarify non-exploded list matching in URI-template documentation and tests #3861

Open
1152405245hwc-coder/python-sdk
#1

Description

@xianmgb-cmyk

Would you welcome a documentation-and-tests-only contribution clarifying the difference between list expansion and inverse matching?

During source-based investigation on main at 77001c96, I observed:

from mcp.shared.uri_template import UriTemplate

t = UriTemplate.parse("items{/ids}")
uri = t.expand({"ids": ["a", "b"]})

print(uri)                         # items/a,b
print(t.match(uri))                # {'ids': 'a,b'}
print(t.expand(t.match(uri)))      # items/a%2Cb

The simple form items/{ids} does not match its list expansion. The documented exploded form items{/ids*} preserves list boundaries, including an encoded comma within one item.

I am not proposing automatic comma splitting or a runtime change. Matching cannot generally infer whether a comma represents list structure or scalar content, and RFC 6570 specifies expansion rather than a general inverse.

The proposed change would:

  • Add a short explanation and examples to docs/servers/uri-templates.md, recommending exploded templates for list-valued handlers.
  • Add three tests characterizing current non-exploded matching limits and protecting scalar-comma and exploded-list behavior.
  • Clarify that the existing inversion property test generates lists only for exploded variables, so it does not cover every value accepted by expand().

A local patch is prepared; nothing has been submitted. The final version passes all 310 URI-template tests, file-scoped Pyright, Ruff lint and formatting. A preceding candidate passed the full suite: 6,228 passed, 16 skipped and one existing xfail. Global Pyright was not clean on Windows, and documentation build/Markdown lint have not been validated.

This came from synthetic investigation, not a production incident. AI assistance was used for investigation, implementation, testing and drafting.

Would this clarification fit the intended contract? I would wait for agreement on scope and the required issue assignment before opening a PR.

Activity

  1. added
    documentation
    on Nov 14, 2026
  2. 1152405245hwc-coder commented on Nov 30, 2026

    @1152405245hwc-coder

    I implemented the documentation-and-tests-only clarification described in this issue, with no runtime change to matching or expansion.

    It adds a short explanation and examples in docs/servers/uri-templates.md (recommending exploded templates such as {/ids*} for list-valued handlers), three tests for the current non-exploded matching limits plus the scalar-comma and exploded-list cases, and a note that the existing inversion property test draws lists only for exploded variables.

    The work is in #3951. I'm happy to adjust if this doesn't match the intended contract.

  3. xianmgb-cmyk commented on Nov 30, 2026

    @xianmgb-cmyk
    Author

    Thanks @1152405245hwc-coder for taking this forward. I reviewed both changed files in #3951 against the scope of #3861 and the URI-template implementation at 77001c96. The documentation-and-tests-only approach matches the proposal, including the encoded scalar comma, the exploded list with a comma inside an item, and the limitation of the property-test generator.

    Two small wording changes would make the contract more precise:

    • Qualify the general statement that match() returns a comma-joined value as one string (also in the later summary): when a match succeeds, it returns a scalar for a non-exploded variable; depending on the operator, matching can instead fail. In particular, items/{ids} rejects items/a,b. The stop at the raw comma occurs during matching, not expansion (the second new test's docstring has the same wording issue). Both cases are consistent with _STOP_CHARS at the pinned base.
    • The ambiguity rationale could distinguish raw separators from encoded scalar content. For the path example, scalar "a,b" expands to a%2Cb, whereas ["a", "b"] expands to a,b. A genuine collision is possible with reserved expansion ({+ids}), where a scalar comma can remain literal. RFC 6570 does not specify a general inverse, so I agree that automatic splitting should remain out of scope.

    These are editorial refinements, not a request to change runtime behavior. The practical concern is making the routing contract clear for handlers expecting list[str]. I appreciate that you preserved the original scope and added the regression cases.

    This is a source/diff review, not an independent rerun of your 333 tests. AI assistance was used in preparing this review. I'll leave the assignment/reopening decision to the maintainers.

  4. 1152405245hwc-coder commented on Dec 1, 2026

    @1152405245hwc-coder

    Thanks @xianmgb-cmyk. I've applied both wording changes on the same branch (ceed081f).

    The docs now say a successful match returns a scalar for a non-exploded variable, and that matching can fail depending on the operator. items/{ids} expanded with ["a", "b"] is items/a,b and does not match; the stop at the raw comma is during matching, not expansion. The second test's docstring said the same thing and is corrected.

    The ambiguity section now distinguishes a raw list separator from encoded scalar content. On a path segment, ["a", "b"] expands to a,b and "a,b" expands to a%2Cb. Reserved {+ids} is where they collide, because the comma stays literal; a test pins that both expand to a,b and matching returns the scalar. RFC 6570 still has no general inverse, so the SDK does not split the value back into a list.

    Happy to adjust further. I'll leave assignment and reopening of #3951 to the maintainers.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    documentation

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions