@@ -4,7 +4,7 @@ module ActionMCP
44 # Represents a resource with its metadata.
55 # Used by resources/list to describe concrete resources.
66 class Resource
7- attr_reader :uri , :name , :title , :description , :mime_type , :size , :annotations
7+ attr_reader :uri , :name , :title , :description , :mime_type , :size , :annotations , :meta
88
99 # @param uri [String] The URI of the resource
1010 # @param name [String] Display name of the resource
@@ -13,14 +13,25 @@ class Resource
1313 # @param mime_type [String, nil] MIME type of the resource content
1414 # @param size [Integer, nil] Size of the resource in bytes
1515 # @param annotations [Hash, nil] Optional annotations
16- def initialize ( uri :, name :, title : nil , description : nil , mime_type : nil , size : nil , annotations : nil )
16+ # @param meta [Hash, #to_hash, #to_h, nil] Optional extension metadata. Emitted on the wire as `_meta`.
17+ def initialize ( uri :, name :, title : nil , description : nil , mime_type : nil , size : nil , annotations : nil , meta : nil )
1718 @uri = uri
1819 @name = name
1920 @title = title
2021 @description = description
2122 @mime_type = mime_type
2223 @size = size
2324 @annotations = annotations
25+ @meta =
26+ if meta . nil?
27+ nil
28+ elsif meta . respond_to? ( :to_hash )
29+ meta . to_hash
30+ elsif meta . respond_to? ( :to_h )
31+ meta . to_h
32+ else
33+ raise ArgumentError , "meta must respond to :to_hash or :to_h, got: #{ meta . class } "
34+ end
2435 freeze
2536 end
2637
@@ -35,6 +46,7 @@ def to_h
3546 hash [ :mimeType ] = mime_type if mime_type
3647 hash [ :size ] = size if size
3748 hash [ :annotations ] = annotations if annotations
49+ hash [ :_meta ] = meta if meta && !meta . empty?
3850 hash
3951 end
4052
@@ -46,12 +58,12 @@ def ==(other)
4658 other . is_a? ( Resource ) && uri == other . uri && name == other . name &&
4759 title == other . title && description == other . description &&
4860 mime_type == other . mime_type && size == other . size &&
49- annotations == other . annotations
61+ annotations == other . annotations && meta == other . meta
5062 end
5163 alias eql? ==
5264
5365 def hash
54- [ uri , name , title , description , mime_type , size , annotations ] . hash
66+ [ uri , name , title , description , mime_type , size , annotations , meta ] . hash
5567 end
5668 end
5769end
0 commit comments