Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
5f5e72b
feat: add RFC 6570 URI template utility with bidirectional support
maxisbey Mar 26, 2026
e5ecf50
feat: add filesystem path safety primitives
maxisbey Mar 26, 2026
0018eea
feat: integrate UriTemplate into MCPServer resource templates
maxisbey Mar 26, 2026
5cbbc70
feat: wire ResourceSecurity into MCPServer configuration
maxisbey Mar 26, 2026
928698b
docs: add migration guide entry for resource template changes
maxisbey Mar 26, 2026
00a1336
refactor: accept plain set for ResourceSecurity.exempt_params
maxisbey Mar 26, 2026
a5afb98
docs: add resources guide covering templates, security, and low-level…
maxisbey Mar 26, 2026
2575042
feat: reject duplicate variable names in URI templates
maxisbey Mar 26, 2026
a463ed9
test: add adversarial security test cases for layered defense
maxisbey Mar 26, 2026
b278925
feat: add UriTemplate.is_template() static method
maxisbey Mar 26, 2026
3b8aadd
feat: add URI length guard to UriTemplate.match()
maxisbey Mar 26, 2026
3a786f3
test: add edge-case coverage for literal handling and anchoring
maxisbey Mar 26, 2026
c4f7db0
feat: reject null bytes in safe_join path components
maxisbey Mar 26, 2026
674783f
fix: decide template vs static purely on URI variables
maxisbey Mar 26, 2026
1987340
fix: correct ; operator matching and expansion per RFC 6570
maxisbey Mar 26, 2026
c1a1787
refactor: remove post-decode structural checks from UriTemplate.match
maxisbey Mar 26, 2026
93e742b
feat: lenient query param matching for {?var} and {&var}
maxisbey Mar 26, 2026
99c9cb0
fix: tighten parse-time validation and document matching limits
maxisbey Mar 26, 2026
80c7934
fix: preserve pct-triplets in reserved expansion; allow empty match c…
maxisbey Mar 26, 2026
278e5e7
refactor: use lists instead of tuples for variable-length sequences
maxisbey Mar 26, 2026
9473442
docs: trim migration guide to breaking changes only
maxisbey Mar 26, 2026
60d12e1
docs: clarify query leniency and fix exempt_params example
maxisbey Mar 26, 2026
2f7fd61
fix: reject template patterns causing O(n²) regex backtracking
maxisbey Mar 26, 2026
aed579c
docs: address reviewer feedback on migration guide and resources doc
maxisbey Mar 26, 2026
7891fd9
test: close coverage gaps in lenient-query branch and test handlers
maxisbey Mar 26, 2026
1500ca3
fix: correct lenient query matching for +, fragments, and standalone …
maxisbey Mar 26, 2026
4a45f59
docs: fix stale docstrings and export DEFAULT_MAX_* constants
maxisbey Mar 26, 2026
2bedd9d
test: move new resource tests to module level per repo convention
maxisbey Mar 26, 2026
dcfd67a
test: close coverage gaps in _parse_query and _split_query_tail fallb…
maxisbey Mar 26, 2026
a8f488e
fix: preserve empty list items in explode matching
maxisbey Mar 26, 2026
7c34c12
refactor: simplify explode split since regex guarantees leading separ…
maxisbey Mar 26, 2026
ed84090
fix: fall back to strict regex when path contains {#...} or literal #
maxisbey Mar 26, 2026
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
51 changes: 51 additions & 0 deletions docs/migration.md
Original file line number Diff line number Diff line change
Expand Up @@ -545,6 +545,57 @@ await client.read_resource("test://resource")
await client.read_resource(str(my_any_url))
```

### Resource templates: matching behavior changes

Resource template matching has been rewritten with RFC 6570 support.
Four behaviors have changed:

**Path-safety checks applied by default.** Extracted parameter values
containing `..` as a path component or looking like an absolute path
(`/etc/passwd`, `C:\Windows`) now cause the template to not match.
This is checked on the decoded value, so `..%2Fetc` and `%2E%2E` are
caught too. Note that `..` is only flagged as a standalone path
component, so values like `v1.0..v2.0` or `HEAD~3..HEAD` are unaffected.

If a parameter legitimately needs to receive absolute paths or
traversal sequences, exempt it:

```python
from mcp.server.mcpserver import ResourceSecurity

@mcp.resource(
"inspect://file/{+target}",
security=ResourceSecurity(exempt_params={"target"}),
)
def inspect_file(target: str) -> str: ...
```

**Template literals are regex-escaped.** Previously a `.` in your
template matched any character; now it matches only a literal dot.
`data://v1.0/{id}` no longer matches `data://v1X0/42`.

**Query parameters match leniently.** A template like
`search://{q}{?limit}` now matches `search://foo` (with `limit` absent
from the extracted params so your function default applies). Previously
this returned no match. If you relied on all query parameters being
required, add explicit checks in your handler.

**Malformed templates fail at decoration time.** Unclosed braces,
duplicate variable names, and unsupported syntax now raise
`InvalidUriTemplate` when the decorator runs, rather than silently
misbehaving at match time.

**Static URIs with Context-only handlers now error.** A non-template
URI paired with a handler that takes only a `Context` parameter
previously registered but was silently unreachable (the resource
could never be read). This now raises `ValueError` at decoration time.
Context injection for static resources is planned; until then, use a
template with at least one variable or access context through other
means.

See [Resources](server/resources.md) for the full template syntax,
security configuration, and filesystem safety utilities.

### Lowlevel `Server`: constructor parameters are now keyword-only

All parameters after `name` are now keyword-only. If you were passing `version` or other parameters positionally, use keyword arguments instead:
Expand Down
Loading
Loading