Class: FastMcp::Transports::StdioTransport
- Inherits:
-
BaseTransport
- Object
- BaseTransport
- FastMcp::Transports::StdioTransport
- Defined in:
- lib/mcp/transports/stdio_transport.rb
Overview
STDIO transport for MCP This transport uses standard input/output for communication
Instance Attribute Summary
Attributes inherited from BaseTransport
Instance Method Summary collapse
-
#initialize(server, logger: nil) ⇒ StdioTransport
constructor
A new instance of StdioTransport.
-
#send_message(message) ⇒ Object
Send a message to the client.
-
#start ⇒ Object
Start the transport.
-
#stop ⇒ Object
Stop the transport.
Methods inherited from BaseTransport
Constructor Details
#initialize(server, logger: nil) ⇒ StdioTransport
Returns a new instance of StdioTransport.
10 11 12 13 |
# File 'lib/mcp/transports/stdio_transport.rb', line 10 def initialize(server, logger: nil) super @running = false end |
Instance Method Details
#send_message(message) ⇒ Object
Send a message to the client
39 40 41 42 43 44 |
# File 'lib/mcp/transports/stdio_transport.rb', line 39 def () = .is_a?(String) ? : JSON.generate() $stdout.puts() $stdout.flush end |
#start ⇒ Object
Start the transport
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/mcp/transports/stdio_transport.rb', line 16 def start @logger.info('Starting STDIO transport') @running = true # Process input from stdin while @running && (line = $stdin.gets) begin (line.strip) rescue StandardError => e @logger.error("Error processing message: #{e.message}") @logger.error(e.backtrace.join("\n")) send_error(-32_000, "Internal error: #{e.message}") end end end |
#stop ⇒ Object
Stop the transport
33 34 35 36 |
# File 'lib/mcp/transports/stdio_transport.rb', line 33 def stop @logger.info('Stopping STDIO transport') @running = false end |