@@ -108,8 +108,9 @@ def handle_post(request)
108
108
109
109
if body [ "method" ] == "initialize"
110
110
handle_initialization ( body_string , body )
111
- elsif body [ "method" ] == MCP ::Methods ::NOTIFICATIONS_INITIALIZED
112
- handle_notification_initialized
111
+ elsif notification_or_response? ( body )
112
+ # For notifications and responses only, return 202 Accepted
113
+ handle_notification_or_response
113
114
else
114
115
handle_regular_request ( body_string , session_id )
115
116
end
@@ -168,6 +169,10 @@ def parse_request_body(body_string)
168
169
[ 400 , { "Content-Type" => "application/json" } , [ { error : "Invalid JSON" } . to_json ] ]
169
170
end
170
171
172
+ def notification_or_response? ( body )
173
+ !( body [ "id" ] && body [ "method" ] )
174
+ end
175
+
171
176
def handle_initialization ( body_string , body )
172
177
session_id = SecureRandom . uuid
173
178
@@ -187,7 +192,7 @@ def handle_initialization(body_string, body)
187
192
[ 200 , headers , [ response ] ]
188
193
end
189
194
190
- def handle_notification_initialized
195
+ def handle_notification_or_response
191
196
[ 202 , { } , [ ] ]
192
197
end
193
198
0 commit comments