Class: Whoosh::MCP::Protocol
- Inherits:
-
Object
- Object
- Whoosh::MCP::Protocol
- Defined in:
- lib/whoosh/mcp/protocol.rb
Defined Under Namespace
Classes: ParseError
Constant Summary collapse
- SPEC_VERSION =
"2025-03-26"
Class Method Summary collapse
- .encode(msg) ⇒ Object
- .error_response(id:, code:, message:, data: nil) ⇒ Object
- .parse(json) ⇒ Object
- .request(method, id:, params: nil) ⇒ Object
- .response(id:, result:) ⇒ Object
Class Method Details
.encode(msg) ⇒ Object
34 35 36 |
# File 'lib/whoosh/mcp/protocol.rb', line 34 def self.encode(msg) JSON.generate(msg) end |
.error_response(id:, code:, message:, data: nil) ⇒ Object
22 23 24 25 26 |
# File 'lib/whoosh/mcp/protocol.rb', line 22 def self.error_response(id:, code:, message:, data: nil) error = { code: code, message: } error[:data] = data if data { jsonrpc: "2.0", id: id, error: error } end |
.parse(json) ⇒ Object
28 29 30 31 32 |
# File 'lib/whoosh/mcp/protocol.rb', line 28 def self.parse(json) JSON.parse(json) rescue JSON::ParserError => e raise ParseError, "Invalid JSON: #{e.}" end |
.request(method, id:, params: nil) ⇒ Object
12 13 14 15 16 |
# File 'lib/whoosh/mcp/protocol.rb', line 12 def self.request(method, id:, params: nil) msg = { jsonrpc: "2.0", method: method, id: id } msg[:params] = params if params msg end |
.response(id:, result:) ⇒ Object
18 19 20 |
# File 'lib/whoosh/mcp/protocol.rb', line 18 def self.response(id:, result:) { jsonrpc: "2.0", id: id, result: result } end |