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.
-
#send_request(method, params = nil) ⇒ Object
Send a JSON-RPC request to the client and wait for a response.
-
#send_response(response) ⇒ Object
Send a response to the client.
Constructor Details
#initialize(server) ⇒ Transport
Initialize the transport with the server instance
8 9 10 11 |
# File 'lib/mcp/transport.rb', line 8 def initialize(server) @server = server server.transport = self end |
Instance Method Details
#close ⇒ Object
Close the transport connection
24 25 26 |
# File 'lib/mcp/transport.rb', line 24 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
30 31 32 33 |
# File 'lib/mcp/transport.rb', line 30 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
37 38 39 40 |
# File 'lib/mcp/transport.rb', line 37 def handle_request(request) response = @server.handle(request) send_response(response) if response end |
#open ⇒ Object
Open the transport connection
19 20 21 |
# File 'lib/mcp/transport.rb', line 19 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.
44 45 46 |
# File 'lib/mcp/transport.rb', line 44 def send_notification(method, params = nil) raise NotImplementedError, "Subclasses must implement send_notification" end |
#send_request(method, params = nil) ⇒ Object
Send a JSON-RPC request to the client and wait for a response.
49 50 51 |
# File 'lib/mcp/transport.rb', line 49 def send_request(method, params = nil) raise NotImplementedError, "Subclasses must implement send_request" end |
#send_response(response) ⇒ Object
Send a response to the client
14 15 16 |
# File 'lib/mcp/transport.rb', line 14 def send_response(response) raise NotImplementedError, "Subclasses must implement send_response" end |