@@ -108,8 +108,9 @@ def handle_post(request)
108108
109109 if body [ "method" ] == "initialize"
110110 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
113114 else
114115 handle_regular_request ( body_string , session_id )
115116 end
@@ -168,6 +169,10 @@ def parse_request_body(body_string)
168169 [ 400 , { "Content-Type" => "application/json" } , [ { error : "Invalid JSON" } . to_json ] ]
169170 end
170171
172+ def notification_or_response? ( body )
173+ !( body [ "id" ] && body [ "method" ] )
174+ end
175+
171176 def handle_initialization ( body_string , body )
172177 session_id = SecureRandom . uuid
173178
@@ -187,7 +192,7 @@ def handle_initialization(body_string, body)
187192 [ 200 , headers , [ response ] ]
188193 end
189194
190- def handle_notification_initialized
195+ def handle_notification_or_response
191196 [ 202 , { } , [ ] ]
192197 end
193198
0 commit comments