-
Notifications
You must be signed in to change notification settings - Fork 110
Expand file tree
/
Copy pathresource.rb
More file actions
68 lines (57 loc) · 1.49 KB
/
resource.rb
File metadata and controls
68 lines (57 loc) · 1.49 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
# frozen_string_literal: true
module MCP
class Resource < Primitive
class << self
attr_reader :uri_value
attr_reader :mime_type_value
def to_h
super.merge(
uri: uri_value,
mimeType: mime_type_value,
).compact
end
def contents
raise NotImplementedError, "Subclasses must implement contents"
end
def inherited(subclass)
super
subclass.instance_variable_set(:@uri_value, nil)
subclass.instance_variable_set(:@mime_type_value, nil)
end
alias_method :resource_name, :primitive_name
def uri(value = NOT_SET)
if value == NOT_SET
@uri_value
else
@uri_value = value
end
end
def mime_type(value = NOT_SET)
if value == NOT_SET
@mime_type_value
else
@mime_type_value = value
end
end
def define(uri: nil, name: nil, title: nil, description: nil, icons: [], mime_type: nil, meta: nil, &block)
super(name: name, title: title, description: description, icons: icons, meta: meta) do
uri(uri)
mime_type(mime_type)
class_exec(&block) if block
end
end
end
attr_reader :uri, :mime_type
def initialize(uri:, mime_type: nil, **kwargs)
super(**kwargs)
@uri = uri
@mime_type = mime_type
end
def to_h
super.merge(
uri: uri,
mimeType: mime_type,
).compact
end
end
end