Class: MetadataContext

Inherits:
Object
  • Object
show all
Defined in:
lib/mcp/tool.rb

Overview

Context object for managing nested metadata collection

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeMetadataContext

Returns a new instance of MetadataContext.



107
108
109
110
# File 'lib/mcp/tool.rb', line 107

def initialize
  @metadata = {}
  @nesting_stack = []
end

Instance Attribute Details

#metadataObject (readonly)

Returns the value of attribute metadata.



112
113
114
# File 'lib/mcp/tool.rb', line 112

def 
  @metadata
end

Class Method Details

.currentObject

Class method to set/get current context for thread-safe access



134
135
136
# File 'lib/mcp/tool.rb', line 134

def self.current
  Thread.current[:metadata_context]
end

.with_context(context) ⇒ Object



138
139
140
141
142
143
144
# File 'lib/mcp/tool.rb', line 138

def self.with_context(context)
  old_context = Thread.current[:metadata_context]
  Thread.current[:metadata_context] = context
  yield
ensure
  Thread.current[:metadata_context] = old_context
end

Instance Method Details

#current_pathObject



129
130
131
# File 'lib/mcp/tool.rb', line 129

def current_path
  @nesting_stack.dup
end

#store(property_name, meta_key, value) ⇒ Object



114
115
116
117
118
119
120
# File 'lib/mcp/tool.rb', line 114

def store(property_name, meta_key, value)
  path = current_path + [property_name.to_s]
  full_path = path.join('.')

  @metadata[full_path] ||= {}
  @metadata[full_path][meta_key] = value
end

#with_nested(parent_property) ⇒ Object



122
123
124
125
126
127
# File 'lib/mcp/tool.rb', line 122

def with_nested(parent_property)
  @nesting_stack.push(parent_property.to_s)
  yield
ensure
  @nesting_stack.pop
end