Class: Textus::Surfaces::MCP::Server

Inherits:
Object
  • Object
show all
Includes:
Routing
Defined in:
lib/textus/surfaces/mcp/server.rb

Overview

Stdio JSON-RPC 2.0 server speaking MCP draft 2024-11-05. One line per message (NDJSON). Holds a single Session for the lifetime of stdin.

Constant Summary collapse

PROTOCOL_VERSION =
"2024-11-05"
SERVER_INFO =
{ "name" => "textus", "version" => Textus::VERSION }.freeze
MAX_LINE_BYTES =

1 MB — protects against OOM from oversized tool calls

1_048_576

Constants included from Routing

Routing::RESOURCE_METHODS, Routing::TOOL_METHODS

Instance Method Summary collapse

Methods included from Routing

#dispatch

Constructor Details

#initialize(store:, stdin: $stdin, stdout: $stdout, role: Textus::Role::DEFAULT) ⇒ Server

Returns a new instance of Server.



16
17
18
19
20
21
22
# File 'lib/textus/surfaces/mcp/server.rb', line 16

def initialize(store:, stdin: $stdin, stdout: $stdout, role: Textus::Role::DEFAULT)
  @store   = store
  @stdin   = stdin
  @stdout  = stdout
  @role    = role
  @session = nil
end

Instance Method Details

#runObject



24
25
26
27
28
29
30
31
# File 'lib/textus/surfaces/mcp/server.rb', line 24

def run
  @stdin.each_line do |line|
    line = line.strip
    next if line.empty?

    handle_line(line)
  end
end