Class: MCP::Transports::StdioTransport
- Inherits:
-
MCP::Transport
- Object
- MCP::Transport
- MCP::Transports::StdioTransport
- Defined in:
- lib/mcp/transports/stdio.rb
Instance Method Summary collapse
- #close ⇒ Object
-
#initialize(server) ⇒ StdioTransport
constructor
A new instance of StdioTransport.
- #open ⇒ Object
- #send_response(message) ⇒ Object
Constructor Details
#initialize(server) ⇒ StdioTransport
9 10 11 12 13 14 15 |
# File 'lib/mcp/transports/stdio.rb', line 9 def initialize(server) @server = server @open = false $stdin.set_encoding("UTF-8") $stdout.set_encoding("UTF-8") super end |
Instance Method Details
#close ⇒ Object
24 25 26 |
# File 'lib/mcp/transports/stdio.rb', line 24 def close @open = false end |
#open ⇒ Object
17 18 19 20 21 22 |
# File 'lib/mcp/transports/stdio.rb', line 17 def open @open = true while @open && (line = $stdin.gets) handle_json_request(line.strip) end end |
#send_response(message) ⇒ Object
28 29 30 31 32 |
# File 'lib/mcp/transports/stdio.rb', line 28 def send_response() = .is_a?(String) ? : JSON.generate() $stdout.puts() $stdout.flush end |