Merge pull request #241 from koic/fix_content_image_to_h
Fix `Content::Image#to_h` to return `mimeType` (camelCase) per MCP spec
This commit is contained in:
commit
c62902b1e8
2 changed files with 34 additions and 1 deletions
|
|
@ -25,7 +25,7 @@ module MCP
|
|||
end
|
||||
|
||||
def to_h
|
||||
{ data: data, mime_type: mime_type, annotations: annotations, type: "image" }.compact
|
||||
{ data: data, mimeType: mime_type, annotations: annotations, type: "image" }.compact
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
|||
33
test/mcp/content_test.rb
Normal file
33
test/mcp/content_test.rb
Normal file
|
|
@ -0,0 +1,33 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
require "test_helper"
|
||||
|
||||
module MCP
|
||||
module Content
|
||||
class ImageTest < ActiveSupport::TestCase
|
||||
test "#to_h returns mimeType (camelCase) per MCP spec" do
|
||||
image = Image.new("base64data", "image/png")
|
||||
result = image.to_h
|
||||
|
||||
assert_equal "image/png", result[:mimeType]
|
||||
refute result.key?(:mime_type), "Expected camelCase mimeType, got snake_case mime_type"
|
||||
assert_equal "image", result[:type]
|
||||
assert_equal "base64data", result[:data]
|
||||
end
|
||||
|
||||
test "#to_h with annotations" do
|
||||
image = Image.new("base64data", "image/png", annotations: { role: "thumbnail" })
|
||||
result = image.to_h
|
||||
|
||||
assert_equal({ role: "thumbnail" }, result[:annotations])
|
||||
end
|
||||
|
||||
test "#to_h without annotations omits the key" do
|
||||
image = Image.new("base64data", "image/png")
|
||||
result = image.to_h
|
||||
|
||||
refute result.key?(:annotations)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
Loading…
Reference in a new issue