Skip to content

Commit 37563e5

Browse files
committed
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.
1 parent 5b04089 commit 37563e5

File tree

2 files changed

+34
-1
lines changed

2 files changed

+34
-1
lines changed

lib/mcp/content.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ def initialize(data, mime_type, annotations: nil)
2525
end
2626

2727
def to_h
28-
{ data: data, mime_type: mime_type, annotations: annotations, type: "image" }.compact
28+
{ data: data, mimeType: mime_type, annotations: annotations, type: "image" }.compact
2929
end
3030
end
3131
end

test/mcp/content_test.rb

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
# frozen_string_literal: true
2+
3+
require "test_helper"
4+
5+
module MCP
6+
module Content
7+
class ImageTest < ActiveSupport::TestCase
8+
test "#to_h returns mimeType (camelCase) per MCP spec" do
9+
image = Image.new("base64data", "image/png")
10+
result = image.to_h
11+
12+
assert_equal "image/png", result[:mimeType]
13+
refute result.key?(:mime_type), "Expected camelCase mimeType, got snake_case mime_type"
14+
assert_equal "image", result[:type]
15+
assert_equal "base64data", result[:data]
16+
end
17+
18+
test "#to_h with annotations" do
19+
image = Image.new("base64data", "image/png", annotations: { role: "thumbnail" })
20+
result = image.to_h
21+
22+
assert_equal({ role: "thumbnail" }, result[:annotations])
23+
end
24+
25+
test "#to_h without annotations omits the key" do
26+
image = Image.new("base64data", "image/png")
27+
result = image.to_h
28+
29+
refute result.key?(:annotations)
30+
end
31+
end
32+
end
33+
end

0 commit comments

Comments
 (0)