Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions lib/mcp/content.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,5 +28,19 @@ def to_h
{ data: data, mimeType: mime_type, annotations: annotations, type: "image" }.compact
end
end

class Audio
attr_reader :data, :mime_type, :annotations

def initialize(data, mime_type, annotations: nil)
@data = data
@mime_type = mime_type
@annotations = annotations
end

def to_h
{ data: data, mimeType: mime_type, annotations: annotations, type: "audio" }.compact
end
end
end
end
25 changes: 25 additions & 0 deletions test/mcp/content_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,5 +29,30 @@ class ImageTest < ActiveSupport::TestCase
refute result.key?(:annotations)
end
end

class AudioTest < ActiveSupport::TestCase
test "#to_h returns correct format per MCP spec" do
audio = Audio.new("base64data", "audio/wav")
result = audio.to_h

assert_equal "audio", result[:type]
assert_equal "base64data", result[:data]
assert_equal "audio/wav", result[:mimeType]
end

test "#to_h with annotations" do
audio = Audio.new("base64data", "audio/wav", annotations: { role: "recording" })
result = audio.to_h

assert_equal({ role: "recording" }, result[:annotations])
end

test "#to_h without annotations omits the key" do
audio = Audio.new("base64data", "audio/wav")
result = audio.to_h

refute result.key?(:annotations)
end
end
end
end