Rename to MCP when handling exceptions in Streamable HTTP transport

The reason for the change is that a NameError occurs when a POST request is made while the stream is closed because ModelContextProtocol is undefined.

I have also added test cases to check the behaviour when IOError and Errno::EPIPE occurs.
This commit is contained in:
dak2 2025-06-15 14:50:47 +09:00
commit dc38c9f84a

View file

@ -106,7 +106,7 @@ module MCP
handle_regular_request(body_string, session_id)
end
rescue StandardError => e
ModelContextProtocol.configuration.exception_reporter.call(e, { request: body_string })
MCP.configuration.exception_reporter.call(e, { request: body_string })
[500, { "Content-Type" => "application/json" }, [{ error: "Internal server error" }.to_json]]
end
@ -204,7 +204,7 @@ module MCP
send_to_stream(stream, message)
[200, { "Content-Type" => "application/json" }, [{ accepted: true }.to_json]]
rescue IOError, Errno::EPIPE => e
ModelContextProtocol.configuration.exception_reporter.call(
MCP.configuration.exception_reporter.call(
e,
{ session_id: session_id, error: "Stream closed during response" },
)