class RubyLLM::MCP::Resource
A resource on an MCP server: a file, a record, or any data the server names with a URI. Pass one to a chat like any attachment, or save it.
readme = files.resource("file:///project/README.md") readme.content # => "# My Project..." readme.save("README.md") chat.ask "Summarize this", with: readme
Resources from MCP#resources are read from the server the first time their content is needed.
Attributes
What the resource is, or nil.
The _meta the server sent with the resource, as a Hash with String keys, empty when there is none. A resource read with MCP#resource has the _meta of its contents; one from MCP#resources has the _meta of the listing.
The MIME type the server reports, or nil.
The resource’s name.
A human-readable title, or nil.
The URI that identifies the resource on its server.
Public Instance Methods
Source
# File lib/ruby_llm/mcp/resource.rb, line 52 def content @content ||= if @data.key?('text') then @data['text'] elsif @data.key?('blob') then Base64.decode64(@data['blob']) else @mcp.resource(uri).content end end
Returns the resource’s content: text for text resources, bytes for binary ones.
Source
# File lib/ruby_llm/mcp/resource.rb, line 65 def save(path) File.binwrite(File.expand_path(path), to_blob) path end
Writes the content to path, expanding it first. Returns path.
Source
# File lib/ruby_llm/mcp/resource.rb, line 72 def to_attachment filename = Content.filename(uri) Attachment.new(StringIO.new(to_blob), filename: filename.empty? ? name : filename) end
Returns the resource as an Attachment, which is how chats take it through with:.
Source
# File lib/ruby_llm/mcp/resource.rb, line 60 def to_blob content.b end
Returns the content as a String of bytes.