Module: Sxn::MCP::Tools::BaseTool
- Defined in:
- lib/sxn/mcp/tools/base_tool.rb
Overview
Base module for MCP tools with shared error handling
Defined Under Namespace
Modules: ErrorMapping
Class Method Summary collapse
-
.ensure_initialized!(server_context) ⇒ Object
Helper to check if sxn is initialized.
-
.error_response(message) ⇒ Object
Helper to build an error response.
-
.json_response(data, summary: nil) ⇒ Object
Helper to build a JSON response.
-
.not_initialized_response ⇒ Object
Helper to return error response for uninitialized sxn.
-
.text_response(text) ⇒ Object
Helper to build a successful text response.
Class Method Details
.ensure_initialized!(server_context) ⇒ Object
Helper to check if sxn is initialized
65 66 67 68 69 |
# File 'lib/sxn/mcp/tools/base_tool.rb', line 65 def self.ensure_initialized!(server_context) return true if server_context[:config_manager] false end |
.error_response(message) ⇒ Object
Helper to build an error response
90 91 92 |
# File 'lib/sxn/mcp/tools/base_tool.rb', line 90 def self.error_response() ErrorMapping.error_response() end |
.json_response(data, summary: nil) ⇒ Object
Helper to build a JSON response
82 83 84 85 86 87 |
# File 'lib/sxn/mcp/tools/base_tool.rb', line 82 def self.json_response(data, summary: nil) content = [] content << { type: "text", text: summary } if summary content << { type: "text", text: JSON.pretty_generate(data) } ::MCP::Tool::Response.new(content) end |
.not_initialized_response ⇒ Object
Helper to return error response for uninitialized sxn
72 73 74 |
# File 'lib/sxn/mcp/tools/base_tool.rb', line 72 def self.not_initialized_response ErrorMapping.error_response("sxn not initialized in this workspace. Run 'sxn init' first.") end |
.text_response(text) ⇒ Object
Helper to build a successful text response
77 78 79 |
# File 'lib/sxn/mcp/tools/base_tool.rb', line 77 def self.text_response(text) ::MCP::Tool::Response.new([{ type: "text", text: text }]) end |