Class: RosettAi::Mcp::Resources::BehaviourResource

Inherits:
Object
  • Object
show all
Defined in:
lib/rosett_ai/mcp/resources/behaviour_resource.rb

Overview

MCP resource provider for rai behaviour files.

Exposes behaviour YAML files as MCP resources with 3-tier lookup: project > XDG user > packaged. Supports tier query parameter to request a specific tier.

URIs: rosett-ai://behaviour/name rosett-ai://behaviour/name?tier=xdg

Author:

  • hugo

  • claude

Constant Summary collapse

URI_PREFIX =
'rosett-ai://behaviour/'
TIER_DIRS =
{
  'project' => -> { RosettAi.conf_root.join('conf', 'behaviour') },
  'xdg' => -> { RosettAi.paths.rai_conf_dir.join('behaviour') },
  'packaged' => -> { RosettAi.paths.packaged_conf_dir.join('behaviour') }
}.freeze

Instance Method Summary collapse

Instance Method Details

#listArray<Hash>

Lists all available behaviour resources across all tiers.

Returns:

  • (Array<Hash>)

    resource entries with :uri, :name, :description



32
33
34
35
36
37
38
39
40
41
# File 'lib/rosett_ai/mcp/resources/behaviour_resource.rb', line 32

def list
  names = Set.new
  tier_dirs.each_value do |dir|
    next unless dir.directory?

    dir.glob('*.yml').each { |path| names << path.basename('.yml').to_s }
  end

  names.sort.map { |name| resource_entry(name) }
end

#read(name) ⇒ Hash?

Reads a specific behaviour resource via 3-tier lookup.

Parameters:

  • name (String)

    behaviour name, optionally with ?tier= query

Returns:

  • (Hash, nil)

    resource content with :uri, :content, :mime_type



47
48
49
50
51
52
53
54
55
56
57
58
# File 'lib/rosett_ai/mcp/resources/behaviour_resource.rb', line 47

def read(name)
  base_name, tier = parse_name_and_tier(name)
  path = tier ? find_in_tier(base_name, tier) : find_first(base_name)
  return nil unless path&.exist?

  {
    uri: "#{URI_PREFIX}#{base_name}",
    content: File.read(path),
    mime_type: 'application/x-yaml',
    tier: tier || detected_tier(path)
  }
end