Skip to content

Commit 2fc4f5e

Browse files
authored
Merge pull request #243 from koic/add_content_audio
Add `Content::Audio` class for audio content type
2 parents 29a3290 + cbb81a8 commit 2fc4f5e

File tree

2 files changed

+39
-0
lines changed

2 files changed

+39
-0
lines changed

lib/mcp/content.rb

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,5 +28,19 @@ def to_h
2828
{ data: data, mimeType: mime_type, annotations: annotations, type: "image" }.compact
2929
end
3030
end
31+
32+
class Audio
33+
attr_reader :data, :mime_type, :annotations
34+
35+
def initialize(data, mime_type, annotations: nil)
36+
@data = data
37+
@mime_type = mime_type
38+
@annotations = annotations
39+
end
40+
41+
def to_h
42+
{ data: data, mimeType: mime_type, annotations: annotations, type: "audio" }.compact
43+
end
44+
end
3145
end
3246
end

test/mcp/content_test.rb

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,5 +29,30 @@ class ImageTest < ActiveSupport::TestCase
2929
refute result.key?(:annotations)
3030
end
3131
end
32+
33+
class AudioTest < ActiveSupport::TestCase
34+
test "#to_h returns correct format per MCP spec" do
35+
audio = Audio.new("base64data", "audio/wav")
36+
result = audio.to_h
37+
38+
assert_equal "audio", result[:type]
39+
assert_equal "base64data", result[:data]
40+
assert_equal "audio/wav", result[:mimeType]
41+
end
42+
43+
test "#to_h with annotations" do
44+
audio = Audio.new("base64data", "audio/wav", annotations: { role: "recording" })
45+
result = audio.to_h
46+
47+
assert_equal({ role: "recording" }, result[:annotations])
48+
end
49+
50+
test "#to_h without annotations omits the key" do
51+
audio = Audio.new("base64data", "audio/wav")
52+
result = audio.to_h
53+
54+
refute result.key?(:annotations)
55+
end
56+
end
3257
end
3358
end

0 commit comments

Comments
 (0)