Class: MCP::Tool::Response

Inherits:
Object
  • Object
show all
Defined in:
lib/mcp/tool/response.rb

Constant Summary collapse

NOT_GIVEN =
Object.new.freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(content = nil, deprecated_error = NOT_GIVEN, error: false, structured_content: nil, meta: nil) ⇒ Response

Returns a new instance of Response.



10
11
12
13
14
15
16
17
18
19
20
# File 'lib/mcp/tool/response.rb', line 10

def initialize(content = nil, deprecated_error = NOT_GIVEN, error: false, structured_content: nil, meta: nil)
  if deprecated_error != NOT_GIVEN
    warn("Passing `error` with the 2nd argument of `Response.new` is deprecated. Use keyword argument like `Response.new(content, error: error)` instead.", uplevel: 1)
    error = deprecated_error
  end

  @content = content || []
  @error = error
  @structured_content = structured_content
  @meta = meta
end

Instance Attribute Details

#contentObject (readonly)

Returns the value of attribute content.



8
9
10
# File 'lib/mcp/tool/response.rb', line 8

def content
  @content
end

#metaObject (readonly)

Returns the value of attribute meta.



8
9
10
# File 'lib/mcp/tool/response.rb', line 8

def meta
  @meta
end

#structured_contentObject (readonly)

Returns the value of attribute structured_content.



8
9
10
# File 'lib/mcp/tool/response.rb', line 8

def structured_content
  @structured_content
end

Instance Method Details

#error?Boolean

Returns:

  • (Boolean)


22
23
24
# File 'lib/mcp/tool/response.rb', line 22

def error?
  !!@error
end

#to_hObject



26
27
28
# File 'lib/mcp/tool/response.rb', line 26

def to_h
  { content: content, isError: error?, structuredContent: @structured_content, _meta: meta }.compact
end