Repository navigation
Commit 243c19a
committed
Accept any 2xx acknowledgement of a notification in the HTTP client
## Motivation and Context
`MCP::Client::HTTP` treats only `202 Accepted` as the acknowledgement of a notification.
Any other status goes through the response body resolution, which requires a JSON or SSE content type,
so a server that answers `notifications/initialized` with an empty 200 and no `Content-Type` fails `connect` with
`Unsupported Content-Type: nil` (issue #598). The spec has the server answer a notification with 202 and no body,
so such a server is out of spec, but a notification awaits no response, and the TypeScript and Python clients check
the content type of a response only for a request: any 2xx acknowledges a notification, whatever the body.
The transport now accepts any 2xx without a JSON or SSE body the same way. A notification answered with
such a 2xx is acknowledged with `nil`, and an SSE stream that ends without a response acknowledges it too,
with no reconnection, since there is no response to resume for. A JSON or SSE body answering a notification is
handed over as before, a 3xx keeps its handling, and a request answered with a 2xx other than 202 and without
a JSON or SSE body still fails with `unsupported_media_type`. `send_notification`, which `MCP::Client#cancel` uses,
never checked the response; `connect` keeps sending `notifications/initialized` through `send_request`
so the 401 and 404 handling applies to it.
Fixes #598.
## How Has This Been Tested?
New tests in `test/mcp/client/http_test.rb`: `connect` succeeds when the notification is acknowledged with
an empty 200, a 204, or a `text/plain` 200; a notification answered with an SSE stream carrying no response
returns `nil` without reconnecting; a notification answered with a 302 still raises on both paths;
a request answered without a JSON or SSE body still raises.
Against the previous library the first raises `Unsupported Content-Type: nil` and the second reconnects.
## Breaking Changes
None.1 parent a391d32 commit 243c19a
2 files changed
Lines changed: 89 additions & 4 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
400 | 400 | | |
401 | 401 | | |
402 | 402 | | |
| 403 | + | |
403 | 404 | | |
404 | 405 | | |
405 | 406 | | |
| |||
427 | 428 | | |
428 | 429 | | |
429 | 430 | | |
430 | | - | |
| 431 | + | |
431 | 432 | | |
432 | 433 | | |
433 | 434 | | |
434 | | - | |
| 435 | + | |
435 | 436 | | |
436 | 437 | | |
437 | 438 | | |
| |||
1106 | 1107 | | |
1107 | 1108 | | |
1108 | 1109 | | |
1109 | | - | |
1110 | | - | |
| 1110 | + | |
| 1111 | + | |
| 1112 | + | |
| 1113 | + | |
| 1114 | + | |
1111 | 1115 | | |
1112 | 1116 | | |
1113 | 1117 | | |
| |||
1125 | 1129 | | |
1126 | 1130 | | |
1127 | 1131 | | |
| 1132 | + | |
| 1133 | + | |
| 1134 | + | |
1128 | 1135 | | |
1129 | 1136 | | |
1130 | 1137 | | |
| |||
1141 | 1148 | | |
1142 | 1149 | | |
1143 | 1150 | | |
| 1151 | + | |
| 1152 | + | |
1144 | 1153 | | |
1145 | 1154 | | |
1146 | 1155 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2739 | 2739 | | |
2740 | 2740 | | |
2741 | 2741 | | |
| 2742 | + | |
| 2743 | + | |
| 2744 | + | |
| 2745 | + | |
| 2746 | + | |
| 2747 | + | |
| 2748 | + | |
| 2749 | + | |
| 2750 | + | |
| 2751 | + | |
| 2752 | + | |
| 2753 | + | |
| 2754 | + | |
| 2755 | + | |
| 2756 | + | |
| 2757 | + | |
| 2758 | + | |
| 2759 | + | |
| 2760 | + | |
| 2761 | + | |
| 2762 | + | |
| 2763 | + | |
| 2764 | + | |
| 2765 | + | |
| 2766 | + | |
| 2767 | + | |
| 2768 | + | |
| 2769 | + | |
| 2770 | + | |
| 2771 | + | |
| 2772 | + | |
| 2773 | + | |
| 2774 | + | |
| 2775 | + | |
| 2776 | + | |
| 2777 | + | |
| 2778 | + | |
| 2779 | + | |
| 2780 | + | |
| 2781 | + | |
| 2782 | + | |
| 2783 | + | |
| 2784 | + | |
| 2785 | + | |
| 2786 | + | |
| 2787 | + | |
| 2788 | + | |
| 2789 | + | |
| 2790 | + | |
| 2791 | + | |
| 2792 | + | |
| 2793 | + | |
| 2794 | + | |
| 2795 | + | |
| 2796 | + | |
| 2797 | + | |
| 2798 | + | |
| 2799 | + | |
| 2800 | + | |
| 2801 | + | |
| 2802 | + | |
| 2803 | + | |
| 2804 | + | |
| 2805 | + | |
| 2806 | + | |
| 2807 | + | |
| 2808 | + | |
| 2809 | + | |
| 2810 | + | |
| 2811 | + | |
| 2812 | + | |
| 2813 | + | |
| 2814 | + | |
| 2815 | + | |
| 2816 | + | |
| 2817 | + | |
2742 | 2818 | | |
2743 | 2819 | | |
2744 | 2820 | | |
| |||
0 commit comments