Repository navigation
Commit 739dd55
committed
Refuse
## Motivation and Context
A `subscriptions/listen` request whose id, or one of whose honored resource URIs, is a string holding bytes that
are not valid UTF-8 parses, since the JSON parser accepts such bytes, but cannot be written back as JSON.
The transport answered 200, registered the stream, and then failed to encode the acknowledgement that echoes both;
`JSON::GeneratorError` is not among the write errors the stream handles, so the registered entry was never removed
and kept one of the `max_listen_subscriptions` slots until the transport closed.
The acknowledgement is now encoded before the stream is committed to. An id that cannot be encoded is refused with
HTTP 400 and JSON-RPC `-32600`, the error carrying a null id since the id itself cannot be written;
an honored filter that cannot be encoded is refused with HTTP 400 and `-32602`. Neither registers a stream.
## How Has This Been Tested?
New tests in `test/mcp/server/transports/streamable_http_transport_test.rb` send a listen request whose id and
one whose resource URI hold an invalid byte, and check the 400 and that no stream is registered.
Against the previous library both answer 200.
Two more send the invalid URI to a server without the `subscribe` capability, which acknowledges without it,
and to a transport at its stream cap, which answers 503 first.
## Breaking Changes
None.subscriptions/listen requests that cannot be encoded1 parent 14dbb20 commit 739dd55
2 files changed
Lines changed: 120 additions & 11 deletions
File tree
- lib/mcp/server/transports
- test/mcp/server/transports
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
904 | 904 | | |
905 | 905 | | |
906 | 906 | | |
| 907 | + | |
| 908 | + | |
| 909 | + | |
| 910 | + | |
| 911 | + | |
| 912 | + | |
| 913 | + | |
| 914 | + | |
907 | 915 | | |
908 | 916 | | |
909 | 917 | | |
| |||
946 | 954 | | |
947 | 955 | | |
948 | 956 | | |
949 | | - | |
| 957 | + | |
| 958 | + | |
| 959 | + | |
| 960 | + | |
| 961 | + | |
| 962 | + | |
| 963 | + | |
| 964 | + | |
| 965 | + | |
| 966 | + | |
| 967 | + | |
| 968 | + | |
| 969 | + | |
| 970 | + | |
| 971 | + | |
| 972 | + | |
| 973 | + | |
| 974 | + | |
| 975 | + | |
| 976 | + | |
| 977 | + | |
| 978 | + | |
| 979 | + | |
| 980 | + | |
| 981 | + | |
| 982 | + | |
| 983 | + | |
| 984 | + | |
| 985 | + | |
| 986 | + | |
| 987 | + | |
| 988 | + | |
| 989 | + | |
| 990 | + | |
| 991 | + | |
| 992 | + | |
| 993 | + | |
950 | 994 | | |
951 | 995 | | |
952 | 996 | | |
| |||
1005 | 1049 | | |
1006 | 1050 | | |
1007 | 1051 | | |
1008 | | - | |
| 1052 | + | |
1009 | 1053 | | |
1010 | 1054 | | |
1011 | 1055 | | |
| |||
1029 | 1073 | | |
1030 | 1074 | | |
1031 | 1075 | | |
1032 | | - | |
1033 | | - | |
1034 | | - | |
1035 | | - | |
1036 | | - | |
1037 | | - | |
1038 | | - | |
1039 | | - | |
1040 | | - | |
1041 | 1076 | | |
1042 | 1077 | | |
1043 | 1078 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
6564 | 6564 | | |
6565 | 6565 | | |
6566 | 6566 | | |
| 6567 | + | |
| 6568 | + | |
| 6569 | + | |
| 6570 | + | |
| 6571 | + | |
| 6572 | + | |
| 6573 | + | |
| 6574 | + | |
| 6575 | + | |
| 6576 | + | |
| 6577 | + | |
| 6578 | + | |
| 6579 | + | |
| 6580 | + | |
| 6581 | + | |
| 6582 | + | |
| 6583 | + | |
| 6584 | + | |
| 6585 | + | |
| 6586 | + | |
| 6587 | + | |
| 6588 | + | |
| 6589 | + | |
| 6590 | + | |
| 6591 | + | |
| 6592 | + | |
| 6593 | + | |
| 6594 | + | |
| 6595 | + | |
| 6596 | + | |
| 6597 | + | |
| 6598 | + | |
| 6599 | + | |
| 6600 | + | |
| 6601 | + | |
| 6602 | + | |
| 6603 | + | |
| 6604 | + | |
| 6605 | + | |
| 6606 | + | |
| 6607 | + | |
| 6608 | + | |
| 6609 | + | |
| 6610 | + | |
| 6611 | + | |
| 6612 | + | |
| 6613 | + | |
| 6614 | + | |
| 6615 | + | |
| 6616 | + | |
| 6617 | + | |
| 6618 | + | |
| 6619 | + | |
| 6620 | + | |
| 6621 | + | |
| 6622 | + | |
| 6623 | + | |
| 6624 | + | |
| 6625 | + | |
| 6626 | + | |
| 6627 | + | |
| 6628 | + | |
| 6629 | + | |
| 6630 | + | |
| 6631 | + | |
| 6632 | + | |
| 6633 | + | |
| 6634 | + | |
| 6635 | + | |
| 6636 | + | |
| 6637 | + | |
| 6638 | + | |
| 6639 | + | |
| 6640 | + | |
6567 | 6641 | | |
6568 | 6642 | | |
6569 | 6643 | | |
| |||
0 commit comments