Support structuredContent in tool response (#147)
This commit is contained in:
parent
99b57a3cc2
commit
f7cf080cc0
1 changed files with 75 additions and 3 deletions
|
|
@ -38,6 +38,19 @@ module MCP
|
|||
refute response.error?
|
||||
end
|
||||
|
||||
test "#initialize with content and structuredContent" do
|
||||
content = [{
|
||||
type: "text",
|
||||
text: "{\"code\":401,\"message\":\"Unauthorized\"}",
|
||||
}]
|
||||
structured_content = { code: 401, message: "Unauthorized" }
|
||||
response = Response.new(content, structured_content: structured_content)
|
||||
|
||||
assert_equal content, response.content
|
||||
assert_equal structured_content, response.structured_content
|
||||
refute response.error?
|
||||
end
|
||||
|
||||
test "#error? for a standard response" do
|
||||
response = Response.new(nil, error: false)
|
||||
refute response.error?
|
||||
|
|
@ -72,6 +85,32 @@ module MCP
|
|||
assert_equal content, actual[:content]
|
||||
assert actual[:isError]
|
||||
end
|
||||
|
||||
test "#to_h for a standard response with content and structured content" do
|
||||
content = [{
|
||||
type: "text",
|
||||
text: "{\"code\":401,\"message\":\"Unauthorized\"}",
|
||||
}]
|
||||
structured_content = { code: 401, message: "Unauthorized" }
|
||||
response = Response.new(content, structured_content: structured_content)
|
||||
actual = response.to_h
|
||||
|
||||
assert_equal [:content, :isError, :structuredContent].sort, actual.keys.sort
|
||||
assert_equal content, actual[:content]
|
||||
assert_equal structured_content, actual[:structuredContent]
|
||||
refute actual[:isError]
|
||||
end
|
||||
|
||||
test "#to_h for a standard response with structured content only" do
|
||||
structured_content = { code: 401, message: "Unauthorized" }
|
||||
response = Response.new(structured_content: structured_content)
|
||||
actual = response.to_h
|
||||
|
||||
assert_equal [:isError, :structuredContent].sort, actual.keys.sort
|
||||
assert_nil actual[:content]
|
||||
assert_equal structured_content, actual[:structuredContent]
|
||||
refute actual[:isError]
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
|||
Loading…
Reference in a new issue