Implement StreamableHTTP transport
Co-authored-by: Topher Bullock <topher.bullock@shopify.com>
This commit is contained in:
parent
04710ac472
commit
3e03a2af66
1 changed files with 1807 additions and 6 deletions
|
|
@ -2,32 +2,57 @@
|
|||
|
||||
module MCP
|
||||
class Transport
|
||||
class << self
|
||||
def register(name, transport_class)
|
||||
@transports ||= {}
|
||||
@transports[name] = transport_class
|
||||
end
|
||||
|
||||
def get(name)
|
||||
raise "Transport #{name} not found" unless @transports
|
||||
|
||||
@transports.fetch(name) { raise "Transport #{name} not found" }
|
||||
end
|
||||
end
|
||||
|
||||
# Initialize the transport with the server instance
|
||||
def initialize(server)
|
||||
@server = server
|
||||
end
|
||||
|
||||
# Send a response to the client
|
||||
def send_response(response)
|
||||
raise NotImplementedError, "Subclasses must implement send_response"
|
||||
end
|
||||
|
||||
# Open the transport connection
|
||||
def open
|
||||
raise NotImplementedError, "Subclasses must implement open"
|
||||
end
|
||||
|
||||
# Close the transport connection
|
||||
def close
|
||||
raise NotImplementedError, "Subclasses must implement close"
|
||||
end
|
||||
|
||||
private
|
||||
# Handle a JSON request
|
||||
# Returns a response that should be sent back to the client
|
||||
def handle_json_request(request)
|
||||
response = @server.handle_json(request)
|
||||
send_response(response) if response
|
||||
end
|
||||
|
||||
# Handle an incoming request
|
||||
# Returns a response that should be sent back to the client
|
||||
def handle_request(request)
|
||||
response = @server.handle(request)
|
||||
send_response(response) if response
|
||||
end
|
||||
|
||||
def handle_json_request(request)
|
||||
response = @server.handle_json(request)
|
||||
send_response(response) if response
|
||||
# Send a notification to the client
|
||||
# Returns true if the notification was sent successfully
|
||||
def send_notification(method, params = nil)
|
||||
raise NotImplementedError, "Subclasses must implement send_notification"
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
|||
Loading…
Reference in a new issue