Module: Coatepec::MCP::Response
- Defined in:
- lib/coatepec/mcp/response.rb
Overview
Builds the pretty-printed JSON {ok: true, data:, meta:} / {ok: false, error:} envelope that every Coatepec tool response wraps in a single
text content block.
Constant Summary collapse
- MAX_RESPONSE_BYTES =
Per-stream caps in Spec::Result bound stdout/stderr, but the fully assembled envelope (500 examples with long descriptions) can still exceed what an MCP client will accept, so cap it here -- the single place every tool response is built.
1024 * 1024
Class Method Summary collapse
Class Method Details
.error(err) ⇒ Object
27 28 29 30 31 32 33 |
# File 'lib/coatepec/mcp/response.rb', line 27 def error(err) payload = { ok: false, error: { code: err.code.to_s, message: err., details: err.details } } ::MCP::Tool::Response.new([{ type: "text", text: JSON.pretty_generate(payload) }], error: true) end |
.ok(data:, meta: {}) ⇒ Object
20 21 22 23 24 25 |
# File 'lib/coatepec/mcp/response.rb', line 20 def ok(data:, meta: {}) text = JSON.pretty_generate(ok: true, data: data, meta: ) return oversized_response if text.bytesize > MAX_RESPONSE_BYTES ::MCP::Tool::Response.new([{ type: "text", text: text }]) end |