Commit Graph

41 Commits

Author SHA1 Message Date
Max Isbey 8b5ca8944a fix: ifemp round-trip + stale docstrings from linear-scan refactor
One logic fix and a sweep of stale references left over from the
regex-to-scan rewrite.

ifemp round-trip (_scan_prefix): the name-continuation guard rejected
the empty-value case when the template's next literal started with a
non-stop-char. api{;key}X{+rest} with key='' expands to api;keyX/tail
but matched None because 'X' after ;key was treated as a name
continuation. Now checks whether the next literal starts at the
current position before rejecting.

Doc/style cleanups:
- match() docstring: 'regex derived from the template' -> 'linear scan'
- _split_query_tail: 'strict regex' -> 'strict scan'
- test comments: 5x 'regex' -> 'scan'
- DEFAULT_RESOURCE_SECURITY: docstring now mentions null-byte rejection
- migration.md: describe client-visible 'Unknown resource' error rather
  than the internal ResourceSecurityError type
- _Atom type alias: remove unnecessary string quoting
- UriTemplate fields: list[...] not tuple[..., ...] — arbitrary-sized
  tuples are not a defence worth having
2026-03-27 21:02:59 +00:00
Max Isbey d3a0936da6 docs: trim migration guide to actual v1.x breaking changes
The previous matcher was a naive replace('{', '(?P<').replace('}',
'>[^/]+)') that threw re.error on any operator character. Removed
items describing constraints on features that did not exist in v1.x:

- 'At most one multi-segment variable': {+var}/{#var}/explode all
  threw re.error in v1.x, so nobody had a working template with one
  let alone two. Covered in resources.md.
- 'Query parameters match leniently': {?q} also threw re.error. The
  lenient-query feature is new, not a behavior change.

Also folded the structural-delimiter change into the literals item
and softened 'malformed templates' to note it's an error-timing
change (re.error at match time -> InvalidUriTemplate at decoration).
2026-03-27 20:22:45 +00:00
Max Isbey cd19eaae38 docs: update migration guide and resources doc for matcher changes
- migration.md: path-safety checks now raise ResourceSecurityError
  rather than silently falling through; null bytes are rejected by
  default; templates may have at most one multi-segment variable
- resources.md: add reject_null_bytes to the settings table; note
  that ResourceSecurity is a heuristic and safe_join remains the
  containment boundary
2026-03-27 20:02:47 +00:00
Max Isbey 19822fbbeb fix: reject {expr}{+var} adjacency to close ReDoS gap
The adjacency check rejected {+a}{b} but not the symmetric {a}{+b}.
Both produce overlapping greedy quantifiers; a 64KB crafted input
against prefix{a}{+b}.json takes ~23s to reject.

Added prev_path_expr tracking so {+var} immediately after any path
expression is rejected. {expr}{#var} remains allowed since the #
operator prepends a literal '#' that the preceding group's character
class excludes, giving a natural boundary.

Also adds the missing 'from typing import Any' to the three low-level
server examples in docs/server/resources.md.
2026-03-27 13:31:10 +00:00
Max Isbey c8712ff1eb docs: improve resources.md with spec link and concrete-URI examples
Added a link to the MCP resources specification after the intro.

Rewrote the multi-segment paths section to lead with the problem:
show a URI that fails with {name} before introducing {+name} as the
fix. Code comments align inputs with outputs for at-a-glance parsing.

Rewrote the query parameters section to lead with the two concrete
URIs a user would want to support (base and with-query), then show
how one template covers both.
2026-03-27 13:18:43 +00:00
Max Isbey dd505ea8b7 docs: add missing type annotations to resources.md examples
Bare dict return types are now parameterized (dict[str, str] or
dict[str, Any] as appropriate). Low-level handler examples now
include ServerRequestContext[Any] and PaginatedRequestParams types
for the ctx and params parameters, with the corresponding imports
added to each code block.
2026-03-27 13:07:33 +00:00
Max Isbey aed579c8a3 docs: address reviewer feedback on migration guide and resources doc
migration.md: added note that static URIs with Context-only handlers
now error at decoration time. The pattern was previously silently
unreachable (the resource registered but could never be read); now
it surfaces early. Duplicate-variable-names rejection was already
covered in the malformed-templates paragraph.

resources.md: clarified that the .. check is depth-based (rejects
values that would escape the starting directory, so a/../b passes).
Changed template reference table intro from 'what the SDK supports'
to 'the most common patterns' since the table intentionally omits
the rarely-used fragment and path-param operators.

test_uri_template.py: corrected the stray-} test comment. RFC 6570
section 2.1 strictly excludes } from literals; we accept it for
TypeScript SDK parity, not because the RFC is lenient.
2026-03-26 22:41:25 +00:00
Max Isbey 60d12e10ee docs: clarify query leniency and fix exempt_params example
Adds a sentence on lenient query matching (order-agnostic, extras
ignored, defaults apply) after the logs example.

Adds the component-based clarification for the .. check so users know
values like HEAD~3..HEAD and v1.0..v2.0 are unaffected.

Fixes the exempt_params motivating example in both resources.md and
migration.md. The previous git://diff/{+range} example used
HEAD~3..HEAD, which the component-based check already passes without
exemption. Replaced with inspect://file/{+target} receiving absolute
paths, which genuinely requires the opt-out.
2026-03-26 22:21:32 +00:00
Max Isbey 9473442435 docs: trim migration guide to breaking changes only
The resource template migration section was documenting new features
alongside behavior changes. Trimmed to the four actual breakages:
path-safety checks now applied by default, template literals regex-
escaped, lenient query matching, and parse-time validation. New
capabilities and best-practice guidance moved to the Resources doc
via a link at the end.
2026-03-26 22:06:52 +00:00
Max Isbey c1a1787286 refactor: remove post-decode structural checks from UriTemplate.match
UriTemplate.match() no longer rejects decoded values containing
characters like /, ?, #, &. It now faithfully returns whatever
expand() would have encoded, so match(expand(x)) == x holds for all
inputs.

The previous check broke round-trip for legitimate values (a&b
expanded to a%26b but match rejected it) and was inconsistent with
every other MCP SDK. The spec's own canonical example file:///{path}
requires multi-segment values; Kotlin and C# already decode without
rejection and document handler-side validation as the security
contract.

Path-safety validation remains in ResourceSecurity (configurable) and
safe_join (the gold-standard check). The %2F path-traversal attack
vector is still blocked: ..%2Fetc%2Fpasswd decodes to ../etc/passwd,
which contains_path_traversal rejects. Tests confirm this end-to-end.

This aligns us with Kotlin's documented model: decode once, pass to
handler, handler validates.
2026-03-26 21:16:22 +00:00
Max Isbey a5afb9892b docs: add resources guide covering templates, security, and low-level usage
Adds docs/server/resources.md as the first page under the planned
docs/server/ directory. Covers static resources, RFC 6570 template
patterns, the built-in security checks and how to relax them, the
safe_join pattern for filesystem handlers, and equivalent patterns for
low-level Server implementations.

Creates the docs/server/ nav section in mkdocs.yml.
2026-03-26 17:42:18 +00:00
Max Isbey 00a1336ee6 refactor: accept plain set for ResourceSecurity.exempt_params
Changes the type from frozenset[str] to collections.abc.Set[str] so
users can write exempt_params={"range"} instead of
exempt_params=frozenset({"range"}). The default factory stays
frozenset for immutability.
2026-03-26 17:42:18 +00:00
Max Isbey 928698b3eb docs: add migration guide entry for resource template changes
Documents the RFC 6570 support, security hardening defaults, and
opt-out configuration for the resource template rewrite. Grouped with
the existing resource URI section.
2026-03-26 17:42:18 +00:00
Jonathan Hefner 5388bea53a docs: generate hierarchical per-module API reference pages (#2103) 2026-03-18 18:15:17 +00:00
Max Isbey 20dd94632e feat(client): store InitializeResult as initialize_result (#2300) 2026-03-18 17:31:26 +00:00
Max Isbey abfb482246 refactor(examples): migrate all HTTP examples to streamable_http_app() (#2291) 2026-03-16 11:37:01 +00:00
Max Isbey cc22bf5464 refactor: remove request_ctx ContextVar, thread Context explicitly (#2203)
Co-authored-by: Marcelo Trylesinski <marcelotryle@gmail.com>
2026-03-04 13:23:02 +00:00
Max Isbey e82203bfc4 refactor: remove unused mcp.shared.progress module (#2080) 2026-02-18 13:10:02 +00:00
Max Isbey 0a22a9dc33 refactor: replace lowlevel Server decorators with on_* constructor kwargs (#1985) 2026-02-12 15:55:54 +00:00
Marcelo Trylesinski 4fc49c62bd feat: add ClientRequestContext type alias for client-side handlers (#1989) 2026-02-03 17:37:38 +01:00
Marcelo Trylesinski b1f7eec3cd refactor: split RequestContext between server and client (#1987) 2026-02-03 14:35:07 +01:00
Marcelo Trylesinski 21822053df Support different transports in Client (#1972) 2026-01-30 12:11:27 +00:00
Marcelo Trylesinski acba5478a9 refactor: McpError renamed to MCPError and flatten parameters (#1956)
Co-authored-by: Max Isbey <224885523+maxisbey@users.noreply.github.com>
2026-01-26 14:37:44 +01:00
Marcelo Trylesinski 65c614e48e Rename FastMCP to MCPServer (#1951) 2026-01-25 14:45:52 +01:00
Marcelo Trylesinski ce75b2d7d2 refactor: improve type docstrings and remove internal type exports (#1950) 2026-01-24 17:17:09 +01:00
Marcelo Trylesinski a1d330de9f Proper handle extra data in MCP objects (#1937) 2026-01-23 15:35:23 +01:00
Marcelo Trylesinski f0ab53e194 Add meta to Client methods (#1923) 2026-01-22 14:50:39 +01:00
Max Isbey 34e66a3812 refactor: move streamable HTTP app creation from FastMCP to lowlevel Server (#1899) 2026-01-19 18:48:04 +01:00
Marcelo Trylesinski 5fdd48a0d3 Completely drop RootModel from types module (#1910) 2026-01-19 14:29:15 +01:00
Felix Weinberger df039bf97c Add ergonomic Client class for testing MCP servers (#1870) 2026-01-16 15:49:26 +00:00
Marcelo Trylesinski 8adb5bdce8 refactor: move transport-specific parameters from FastMCP constructor to run() (#1898)
Co-authored-by: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-16 15:16:20 +00:00
Marcelo Trylesinski edf0950a6a Revert mount_path parameter from FastMCP (#1881) 2026-01-16 13:23:08 +00:00
Felix Weinberger cfb2909631 fix: change Resource URI fields from AnyUrl to str (#1863) 2026-01-16 09:58:57 +01:00
Marcelo Trylesinski 812a46ab97 Remove deprecated cursor parameter and ResourceReference (#1871) 2026-01-15 21:33:21 +01:00
Marcelo Trylesinski 024d7597fd Drop Content and args parameter in ClientSessionGroup.call_tool (#1866) 2026-01-15 16:24:53 +00:00
Marcelo Trylesinski f2b89ec83e docs: add migrations page (#1859) 2026-01-15 10:13:18 +00:00
Max Isbey c92bb2f7ff SEP-1686: Tasks (#1645) 2025-11-28 18:51:58 +00:00
adam jones fcffa14b5b docs: Update examples to use stateless HTTP with JSON responses (#1499)
Main branch checks / checks (push) Failing after 0s
2025-11-20 15:06:37 +00:00
Marcelo Trylesinski 814c9c024a Add documentation about testing (#1426) 2025-10-03 14:17:31 +00:00
Marcelo Trylesinski 89619a8604 Add documentation structure (#1425) 2025-10-03 13:17:08 +00:00
Marcelo Trylesinski 4e11f2890b Add mkdocs (#367) 2025-03-25 13:06:15 +01:00