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
|
# File 'lib/legion/mcp/resources/extension_info.rb', line 29
def read(uri)
log.info('Starting legion.mcp.resources.extension_info.read')
name = uri.sub('legion://extensions/', '')
return [] if name.empty?
unless data_connected?
return [{ uri: uri, mimeType: 'application/json',
text: Legion::JSON.dump({ error: 'legion-data is not connected' }) }]
end
ext = Legion::Data::Model::Extension.where(name: name).first
unless ext
return [{ uri: uri, mimeType: 'application/json',
text: Legion::JSON.dump({ error: "Extension '#{name}' not found" }) }]
end
runners = Legion::Data::Model::Runner.where(extension_id: ext.values[:id]).all
result = ext.values.merge(
runners: runners.map do |r|
functions = Legion::Data::Model::Function.where(runner_id: r.values[:id]).all
r.values.merge(functions: functions.map(&:values))
end
)
[{ uri: uri, mimeType: 'application/json', text: Legion::JSON.dump(result) }]
rescue StandardError => e
handle_exception(e, level: :warn, operation: 'legion.mcp.resources.extension_info.read')
log.warn("ExtensionInfo#read failed: #{e.message}")
[{ uri: uri, mimeType: 'application/json',
text: Legion::JSON.dump({ error: "Failed to read extension: #{e.message}" }) }]
end
|