Commit 674783f
committed
fix: decide template vs static purely on URI variables
The @resource() decorator now classifies resources based solely on
whether the URI contains template variables, not on whether the
handler has parameters.
Previously, a handler taking only a Context parameter on a
non-template URI would register as a zero-variable template. The
template matched with an empty dict, which the walrus check in
resource_manager treated as falsy, making the resource permanently
unreachable. This has never worked.
Now such a handler errors at decoration time with a clear message
noting that Context injection for static resources is planned but not
yet supported. Handlers with non-Context parameters on non-template
URIs also get a clearer error than the old 'Mismatch' message.
Also changes the resource_manager walrus check to compare against
None explicitly, as defense-in-depth against any future case where
matches() legitimately returns an empty dict.1 parent c4f7db0 commit 674783f
File tree
3 files changed
+44
-12
lines changed- src/mcp/server/mcpserver
- resources
- tests/server/mcpserver
3 files changed
+44
-12
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
93 | 93 | | |
94 | 94 | | |
95 | 95 | | |
96 | | - | |
| 96 | + | |
97 | 97 | | |
98 | 98 | | |
99 | 99 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
702 | 702 | | |
703 | 703 | | |
704 | 704 | | |
705 | | - | |
706 | 705 | | |
707 | | - | |
708 | | - | |
709 | | - | |
710 | | - | |
711 | | - | |
712 | | - | |
713 | | - | |
714 | | - | |
715 | | - | |
| 706 | + | |
| 707 | + | |
716 | 708 | | |
| 709 | + | |
| 710 | + | |
| 711 | + | |
717 | 712 | | |
718 | 713 | | |
719 | 714 | | |
| |||
733 | 728 | | |
734 | 729 | | |
735 | 730 | | |
| 731 | + | |
| 732 | + | |
| 733 | + | |
| 734 | + | |
| 735 | + | |
| 736 | + | |
| 737 | + | |
| 738 | + | |
| 739 | + | |
| 740 | + | |
| 741 | + | |
| 742 | + | |
| 743 | + | |
| 744 | + | |
736 | 745 | | |
737 | 746 | | |
738 | 747 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
851 | 851 | | |
852 | 852 | | |
853 | 853 | | |
854 | | - | |
| 854 | + | |
855 | 855 | | |
856 | 856 | | |
857 | 857 | | |
| |||
1192 | 1192 | | |
1193 | 1193 | | |
1194 | 1194 | | |
| 1195 | + | |
| 1196 | + | |
| 1197 | + | |
| 1198 | + | |
| 1199 | + | |
| 1200 | + | |
| 1201 | + | |
| 1202 | + | |
| 1203 | + | |
| 1204 | + | |
| 1205 | + | |
| 1206 | + | |
| 1207 | + | |
| 1208 | + | |
| 1209 | + | |
| 1210 | + | |
| 1211 | + | |
| 1212 | + | |
| 1213 | + | |
| 1214 | + | |
| 1215 | + | |
| 1216 | + | |
| 1217 | + | |
1195 | 1218 | | |
1196 | 1219 | | |
1197 | 1220 | | |
| |||
0 commit comments