Fix Content::Image#to_h to return mimeType (camelCase) per MCP spec

This is a fix for a similar bug that remained, as in #235.

`Content::Image#to_h` returned `mime_type` (snake_case), but the MCP spec
requires `mimeType` (camelCase) for the MIME type field in image content.
This commit is contained in:
Koichi ITO 2026-02-27 12:39:16 +09:00
commit 37563e59bd
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