Merge pull request #257 from koic/return_404_for_invalid_session_id
Return 404 for invalid session ID in `handle_regular_request`
This commit is contained in:
commit
8823bd34ef
2 changed files with 20 additions and 1 deletions
|
|
@ -261,7 +261,7 @@ module MCP
|
||||||
unless @stateless
|
unless @stateless
|
||||||
# If session ID is provided, but not in the sessions hash, return an error
|
# If session ID is provided, but not in the sessions hash, return an error
|
||||||
if session_id && !@sessions.key?(session_id)
|
if session_id && !@sessions.key?(session_id)
|
||||||
return [400, { "Content-Type" => "application/json" }, [{ error: "Invalid session ID" }.to_json]]
|
return session_not_found_response
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -287,6 +287,25 @@ module MCP
|
||||||
assert_equal "Session not found", body["error"]
|
assert_equal "Session not found", body["error"]
|
||||||
end
|
end
|
||||||
|
|
||||||
|
test "handles POST request with invalid session ID" do
|
||||||
|
request = create_rack_request(
|
||||||
|
"POST",
|
||||||
|
"/",
|
||||||
|
{
|
||||||
|
"CONTENT_TYPE" => "application/json",
|
||||||
|
"HTTP_MCP_SESSION_ID" => "invalid_id",
|
||||||
|
},
|
||||||
|
{ jsonrpc: "2.0", method: "ping", id: "456" }.to_json,
|
||||||
|
)
|
||||||
|
|
||||||
|
response = @transport.handle_request(request)
|
||||||
|
assert_equal 404, response[0]
|
||||||
|
assert_equal({ "Content-Type" => "application/json" }, response[1])
|
||||||
|
|
||||||
|
body = JSON.parse(response[2][0])
|
||||||
|
assert_equal "Session not found", body["error"]
|
||||||
|
end
|
||||||
|
|
||||||
test "handles DELETE request with valid session ID" do
|
test "handles DELETE request with valid session ID" do
|
||||||
# First create a session with initialize
|
# First create a session with initialize
|
||||||
init_request = create_rack_request(
|
init_request = create_rack_request(
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue