Class: Kreuzberg::MCPProxy::Server
- Inherits:
-
Object
- Object
- Kreuzberg::MCPProxy::Server
- Defined in:
- lib/kreuzberg/mcp_proxy.rb
Overview
MCP server instance
Instance Attribute Summary collapse
-
#pid ⇒ Object
readonly
Returns the value of attribute pid.
-
#transport ⇒ Object
readonly
Returns the value of attribute transport.
Instance Method Summary collapse
-
#initialize(transport: 'stdio') ⇒ Server
constructor
Initialize MCP server.
-
#read_message ⇒ Hash
Read a message from the server (stdio only).
-
#running? ⇒ Boolean
Check if server is running.
-
#send_message(message) ⇒ void
Send a message to the server (stdio only).
-
#start ⇒ Integer?
Start the MCP server.
-
#stop ⇒ void
Stop the server.
Constructor Details
#initialize(transport: 'stdio') ⇒ Server
Initialize MCP server
21 22 23 24 25 26 27 |
# File 'lib/kreuzberg/mcp_proxy.rb', line 21 def initialize(transport: 'stdio') @transport = transport @pid = nil @stdin = nil @stdout = nil @stderr = nil end |
Instance Attribute Details
#pid ⇒ Object (readonly)
Returns the value of attribute pid.
15 16 17 |
# File 'lib/kreuzberg/mcp_proxy.rb', line 15 def pid @pid end |
#transport ⇒ Object (readonly)
Returns the value of attribute transport.
15 16 17 |
# File 'lib/kreuzberg/mcp_proxy.rb', line 15 def transport @transport end |
Instance Method Details
#read_message ⇒ Hash
Read a message from the server (stdio only)
78 79 80 81 82 83 84 |
# File 'lib/kreuzberg/mcp_proxy.rb', line 78 def raise ServerError, 'Can only read messages in stdio mode' unless @transport == 'stdio' raise ServerError, 'Server not started' unless @stdout line = @stdout.gets JSON.parse(line) if line end |
#running? ⇒ Boolean
Check if server is running
90 91 92 93 94 95 96 97 |
# File 'lib/kreuzberg/mcp_proxy.rb', line 90 def running? return false unless @pid Process.kill(0, @pid) true rescue Errno::ESRCH, Errno::EPERM false end |
#send_message(message) ⇒ void
This method returns an undefined value.
Send a message to the server (stdio only)
66 67 68 69 70 71 72 |
# File 'lib/kreuzberg/mcp_proxy.rb', line 66 def () raise ServerError, 'Can only send messages in stdio mode' unless @transport == 'stdio' raise ServerError, 'Server not started' unless @stdin @stdin.puts(JSON.generate()) @stdin.flush end |
#start ⇒ Integer?
Start the MCP server
33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/kreuzberg/mcp_proxy.rb', line 33 def start binary = MCPProxy.find_mcp_binary case @transport when 'stdio' start_stdio(binary) when 'sse' start_sse(binary) else raise ServerError, "Unknown transport: #{@transport}" end end |
#stop ⇒ void
This method returns an undefined value.
Stop the server
50 51 52 53 54 55 56 57 58 59 |
# File 'lib/kreuzberg/mcp_proxy.rb', line 50 def stop return unless @pid Process.kill('TERM', @pid) Process.wait(@pid) rescue Errno::ESRCH, Errno::ECHILD # rubocop:disable Lint/SuppressedException ensure @pid = nil close_pipes end |