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:
Koichi ITO 2026-03-01 17:16:25 +09:00 • committed by GitHub
commit c62902b1e8
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 34 additions and 1 deletions

View file

@ -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
View 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