mirror of
https://github.com/PrefectHQ/fastmcp.git
synced 2026-10-12 07:53:19 +02:00
* resources: keep each template's compiled pattern on the template #5248 made the shared build_regex cache unbounded on the premise that its keys were server-defined. They are not: a proxy caches the template strings its backend sends, so a backend whose templates change grew the cache for the life of the process (25000 entries after 1000 list-and-read cycles, ~1.5MB per read with long non-ASCII literals). A ResourceTemplate now keeps its own compiled pattern, keyed on its uri_template so a model_copy with a new template rebuilds it, and the pattern is freed with the template. The shared cache is bounded again and only serves direct match_uri_template callers. The pattern is read from the private-attribute dict directly because pydantic's private-attribute access costs ~0.3us on a path every read walks. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01KfHgVhbYEhBCC5eSeqGiuG * resources: share a wrapped template's pattern and honor _list_query_params overrides Review of the previous commit found that mounts wrap every template on every list, so each wrapper compiled its pattern again; above 4096 templates the bounded shared cache thrashed on reads that fall back to walking the list. A wrapper now takes the source template's compiled pattern. Reading _list_query_params straight from the private dict also bypassed a model_copy update of it and a subclass property, so it is read as an attribute again, only when the URI carries a query. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01KfHgVhbYEhBCC5eSeqGiuG --------- Co-authored-by: Claude Opus 5.5 (1M context) <noreply@anthropic.com> |
||
|---|---|---|
| .. | ||
| __init__.py | ||
| test_file_resources.py | ||
| test_function_resources.py | ||
| test_resource_security.py | ||
| test_resource_template.py | ||
| test_resource_template_meta.py | ||
| test_resource_template_query_params.py | ||
| test_resources.py | ||
| test_standalone_decorator.py | ||