ruby-sdk/lib/mcp/content.rb
Koichi ITO ba7a08aa04 Add Content::EmbeddedResource class for embedded resource content type
The MCP spec defines an embedded resource content type, but the SDK had
no corresponding class. Add `Content::EmbeddedResource` that wraps a
resource object and serializes it via `to_h`.

https://modelcontextprotocol.io/specification/2025-11-25/server/tools#embedded-resources
2026-03-02 01:33:05 +09:00

59 lines
1.3 KiB
Ruby

# frozen_string_literal: true
module MCP
module Content
class Text
attr_reader :text, :annotations
def initialize(text, annotations: nil)
@text = text
@annotations = annotations
end
def to_h
{ text: text, annotations: annotations, type: "text" }.compact
end
end
class Image
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: "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
class EmbeddedResource
attr_reader :resource, :annotations
def initialize(resource, annotations: nil)
@resource = resource
@annotations = annotations
end
def to_h
{ resource: resource.to_h, annotations: annotations, type: "resource" }.compact
end
end
end
end