From 37563e59bd6b2a3022e4d13f0f95db59444ef26e Mon Sep 17 00:00:00 2001 From: Koichi ITO Date: Fri, 27 Feb 2026 12:39:16 +0900 Subject: [PATCH] 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. --- lib/mcp/content.rb | 2 +- test/mcp/content_test.rb | 33 +++++++++++++++++++++++++++++++++ 2 files changed, 34 insertions(+), 1 deletion(-) create mode 100644 test/mcp/content_test.rb diff --git a/lib/mcp/content.rb b/lib/mcp/content.rb index 7ab984d6..872de329 100644 --- a/lib/mcp/content.rb +++ b/lib/mcp/content.rb @@ -25,7 +25,7 @@ def initialize(data, mime_type, annotations: nil) 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 diff --git a/test/mcp/content_test.rb b/test/mcp/content_test.rb new file mode 100644 index 00000000..46ac9021 --- /dev/null +++ b/test/mcp/content_test.rb @@ -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