Class: MCP::Transport
- Inherits:
-
Object
- Object
- MCP::Transport
- Defined in:
- lib/mcp/transport.rb
Direct Known Subclasses
Server::Transports::StdioTransport, Server::Transports::StreamableHTTPTransport
Instance Method Summary collapse
-
#close ⇒ Object
Close the transport connection.
-
#handle_json_request(request) ⇒ Object
Handle a JSON request Returns a response that should be sent back to the client.
-
#handle_request(request) ⇒ Object
Handle an incoming request Returns a response that should be sent back to the client.
-
#initialize(server) ⇒ Transport
constructor
Initialize the transport with the server instance.
-
#open ⇒ Object
Open the transport connection.
-
#send_notification(method, params = nil) ⇒ Object
Send a notification to the client Returns true if the notification was sent successfully.
-
#send_response(response) ⇒ Object
Send a response to the client.
Constructor Details
#initialize(server) ⇒ Transport
Initialize the transport with the server instance
6 7 8 |
# File 'lib/mcp/transport.rb', line 6 def initialize(server) @server = server end |
Instance Method Details
#close ⇒ Object
Close the transport connection
21 22 23 |
# File 'lib/mcp/transport.rb', line 21 def close raise NotImplementedError, "Subclasses must implement close" end |
#handle_json_request(request) ⇒ Object
Handle a JSON request Returns a response that should be sent back to the client
27 28 29 30 |
# File 'lib/mcp/transport.rb', line 27 def handle_json_request(request) response = @server.handle_json(request) send_response(response) if response end |
#handle_request(request) ⇒ Object
Handle an incoming request Returns a response that should be sent back to the client
34 35 36 37 |
# File 'lib/mcp/transport.rb', line 34 def handle_request(request) response = @server.handle(request) send_response(response) if response end |
#open ⇒ Object
Open the transport connection
16 17 18 |
# File 'lib/mcp/transport.rb', line 16 def open raise NotImplementedError, "Subclasses must implement open" end |
#send_notification(method, params = nil) ⇒ Object
Send a notification to the client Returns true if the notification was sent successfully
41 42 43 |
# File 'lib/mcp/transport.rb', line 41 def send_notification(method, params = nil) raise NotImplementedError, "Subclasses must implement send_notification" end |
#send_response(response) ⇒ Object
Send a response to the client
11 12 13 |
# File 'lib/mcp/transport.rb', line 11 def send_response(response) raise NotImplementedError, "Subclasses must implement send_response" end |