Module: Igniter::Extensions::Contracts::McpPack
- Defined in:
- lib/igniter/extensions/contracts/mcp_pack.rb
Class Method Summary collapse
- .call(tool_name, target: nil, **arguments, &block) ⇒ Object
- .creator_arguments(include_scope: false, include_root: false, require_name: false, require_root: false) ⇒ Object
- .creator_session_from(arguments, target:) ⇒ Object
- .dispatch(tool_name, target: nil, **arguments, &block) ⇒ Object
- .environment_from(target) ⇒ Object
- .install_into(kernel) ⇒ Object
- .manifest ⇒ Object
- .profile_from(target, optional: false) ⇒ Object
- .session_from(payload, target:) ⇒ Object
- .symbolize_keys(value) ⇒ Object
- .tool_catalog ⇒ Object
- .tool_definition(tool_name) ⇒ Object
- .tools ⇒ Object
Class Method Details
.call(tool_name, target: nil, **arguments, &block) ⇒ Object
141 142 143 144 145 146 147 148 149 |
# File 'lib/igniter/extensions/contracts/mcp_pack.rb', line 141 def call(tool_name, target: nil, **arguments, &block) definition = tool_definition(tool_name) payload = dispatch(definition.name, target: target, **arguments, &block) Mcp::ToolResult.new( tool_name: definition.name, payload: payload, mutating: definition.mutating ) end |
.creator_arguments(include_scope: false, include_root: false, require_name: false, require_root: false) ⇒ Object
259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 |
# File 'lib/igniter/extensions/contracts/mcp_pack.rb', line 259 def creator_arguments(include_scope: false, include_root: false, require_name: false, require_root: false) arguments = [ Mcp::ToolArgument.new(name: :name, type: :string, summary: "Pack name without the trailing _pack suffix.", required: require_name), Mcp::ToolArgument.new(name: :kind, type: :symbol, summary: "Explicit pack kind when not inferred.", enum: %i[feature operational bundle]), Mcp::ToolArgument.new(name: :namespace, type: :string, summary: "Ruby namespace for generated pack constants.", default: "MyCompany::IgniterPacks"), Mcp::ToolArgument.new(name: :profile, type: :symbol, summary: "Named creator profile.", enum: CreatorPack.available_profiles), Mcp::ToolArgument.new(name: :capabilities, type: :symbol_array, summary: "Capabilities used to infer or refine the profile."), Mcp::ToolArgument.new(name: :pack, type: :pack_reference, summary: "Custom pack module for audit-aware creator flows."), Mcp::ToolArgument.new(name: :mode, type: :symbol, summary: "Writer behavior when files already exist.", default: :skip_existing, enum: %i[skip_existing overwrite]) ] if include_scope arguments << Mcp::ToolArgument.new(name: :scope, type: :symbol, summary: "Target packaging scope.", required: false, enum: CreatorPack.available_scopes) end if include_root arguments << Mcp::ToolArgument.new(name: :root, type: :string, summary: "Filesystem root for generated files.", required: require_root) end if include_scope && require_root arguments.find { |argument| argument.name == :scope }&.tap do |argument| arguments[arguments.index(argument)] = Mcp::ToolArgument.new( name: :scope, type: :symbol, summary: "Target packaging scope.", required: true, enum: CreatorPack.available_scopes ) end end arguments end |
.creator_session_from(arguments, target:) ⇒ Object
298 299 300 301 302 303 304 305 306 307 308 309 310 311 |
# File 'lib/igniter/extensions/contracts/mcp_pack.rb', line 298 def creator_session_from(arguments, target:) Mcp::CreatorSession.new( name: arguments[:name], kind: arguments[:kind], namespace: arguments.fetch(:namespace, "MyCompany::IgniterPacks"), profile: arguments[:profile], capabilities: arguments[:capabilities], scope: arguments[:scope], root: arguments[:root], mode: arguments.fetch(:mode, :skip_existing), pack: arguments[:pack], target_profile: profile_from(target, optional: true) ) end |
.dispatch(tool_name, target: nil, **arguments, &block) ⇒ Object
156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 |
# File 'lib/igniter/extensions/contracts/mcp_pack.rb', line 156 def dispatch(tool_name, target: nil, **arguments, &block) case tool_name.to_sym when :inspect_profile profile_from(target).then { |profile| DebugPack.profile_snapshot(profile).to_h } when :inspect_pack profile = profile_from(target) DebugPack.pack_snapshot(arguments.fetch(:pack), profile: profile).to_h when :audit_pack DebugPack.audit(arguments.fetch(:pack), profile: profile_from(target, optional: true)).to_h when :debug_report environment = environment_from(target) DebugPack.report( environment, inputs: arguments[:inputs], compiled_graph: arguments[:compiled_graph], &block ).to_h when :creator_wizard CreatorPack.wizard( name: arguments[:name], kind: arguments[:kind], namespace: arguments.fetch(:namespace, "MyCompany::IgniterPacks"), profile: arguments[:profile], capabilities: arguments[:capabilities], scope: arguments[:scope], root: arguments[:root], mode: arguments.fetch(:mode, :skip_existing), pack: arguments[:pack], target_profile: profile_from(target, optional: true) ).to_h when :creator_session_start creator_session_from(arguments, target: target).to_h when :creator_session_apply session = session_from(arguments.fetch(:session) { arguments.fetch("session") }, target: target) session.apply(**symbolize_keys(arguments.fetch(:updates) { arguments.fetch("updates") })).to_h when :creator_session_workflow session_from(arguments.fetch(:session) { arguments.fetch("session") }, target: target).workflow_payload when :creator_session_write_plan session_from(arguments.fetch(:session) { arguments.fetch("session") }, target: target).write_plan_payload when :creator_session_write session_from(arguments.fetch(:session) { arguments.fetch("session") }, target: target).write_payload when :creator_workflow CreatorPack.workflow( name: arguments.fetch(:name), kind: arguments[:kind], namespace: arguments.fetch(:namespace, "MyCompany::IgniterPacks"), profile: arguments[:profile], capabilities: arguments[:capabilities], scope: arguments.fetch(:scope, :monorepo_package), pack: arguments[:pack], target_profile: profile_from(target, optional: true) ).to_h when :creator_write_plan CreatorPack.writer( name: arguments.fetch(:name), kind: arguments[:kind], namespace: arguments.fetch(:namespace, "MyCompany::IgniterPacks"), profile: arguments[:profile], capabilities: arguments[:capabilities], scope: arguments.fetch(:scope, :monorepo_package), pack: arguments[:pack], target_profile: profile_from(target, optional: true), root: arguments.fetch(:root), mode: arguments.fetch(:mode, :skip_existing) ).plan.to_h when :creator_write CreatorPack.write( name: arguments.fetch(:name), kind: arguments[:kind], namespace: arguments.fetch(:namespace, "MyCompany::IgniterPacks"), profile: arguments[:profile], capabilities: arguments[:capabilities], scope: arguments.fetch(:scope, :monorepo_package), pack: arguments[:pack], target_profile: profile_from(target, optional: true), root: arguments.fetch(:root), mode: arguments.fetch(:mode, :skip_existing) ).to_h else raise ArgumentError, "unsupported MCP tool #{tool_name.inspect}" end end |
.environment_from(target) ⇒ Object
253 254 255 256 257 |
# File 'lib/igniter/extensions/contracts/mcp_pack.rb', line 253 def environment_from(target) return target if target.respond_to?(:profile) && target.respond_to?(:execute) raise ArgumentError, "McpPack debug_report requires an environment target" end |
.install_into(kernel) ⇒ Object
22 23 24 |
# File 'lib/igniter/extensions/contracts/mcp_pack.rb', line 22 def install_into(kernel) kernel end |
.manifest ⇒ Object
14 15 16 17 18 19 20 |
# File 'lib/igniter/extensions/contracts/mcp_pack.rb', line 14 def manifest Igniter::Contracts::PackManifest.new( name: :extensions_mcp, requires_packs: [DebugPack, CreatorPack], metadata: { category: :tooling } ) end |
.profile_from(target, optional: false) ⇒ Object
239 240 241 242 243 244 245 246 247 248 249 250 251 |
# File 'lib/igniter/extensions/contracts/mcp_pack.rb', line 239 def profile_from(target, optional: false) profile = case target when nil nil else target.respond_to?(:profile) ? target.profile : target end return profile if optional || profile raise ArgumentError, "McpPack tool requires an environment or profile target" end |
.session_from(payload, target:) ⇒ Object
313 314 315 316 317 318 |
# File 'lib/igniter/extensions/contracts/mcp_pack.rb', line 313 def session_from(payload, target:) Mcp::CreatorSession.from_h( symbolize_keys(payload), target_profile: profile_from(target, optional: true) ) end |
.symbolize_keys(value) ⇒ Object
320 321 322 323 324 325 326 327 328 329 330 331 |
# File 'lib/igniter/extensions/contracts/mcp_pack.rb', line 320 def symbolize_keys(value) case value when Hash value.each_with_object({}) do |(key, nested), memo| memo[key.respond_to?(:to_sym) ? key.to_sym : key] = symbolize_keys(nested) end when Array value.map { |item| symbolize_keys(item) } else value end end |
.tool_catalog ⇒ Object
137 138 139 |
# File 'lib/igniter/extensions/contracts/mcp_pack.rb', line 137 def tool_catalog tools.map(&:to_h) end |
.tool_definition(tool_name) ⇒ Object
151 152 153 154 |
# File 'lib/igniter/extensions/contracts/mcp_pack.rb', line 151 def tool_definition(tool_name) tools.find { |definition| definition.name == tool_name.to_sym } || raise(ArgumentError, "unknown MCP tool #{tool_name.inspect}") end |
.tools ⇒ Object
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 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 |
# File 'lib/igniter/extensions/contracts/mcp_pack.rb', line 26 def tools @tools ||= [ Mcp::ToolDefinition.new( name: :inspect_profile, summary: "Return a structured profile snapshot.", target: :profile_or_environment ), Mcp::ToolDefinition.new( name: :inspect_pack, summary: "Return a structured installed-pack snapshot.", target: :profile_or_environment, arguments: [ Mcp::ToolArgument.new(name: :pack, type: :pack_reference, summary: "Installed pack name or pack module.", required: true) ] ), Mcp::ToolDefinition.new( name: :audit_pack, summary: "Audit a custom pack against creator/debug quality seams.", target: :optional_profile_or_environment, arguments: [ Mcp::ToolArgument.new(name: :pack, type: :pack_reference, summary: "Custom pack module to audit.", required: true) ] ), Mcp::ToolDefinition.new( name: :debug_report, summary: "Compile or execute and return a structured debug report.", target: :environment, arguments: [ Mcp::ToolArgument.new(name: :inputs, type: :map, summary: "Runtime inputs used for execution when a graph is available."), Mcp::ToolArgument.new(name: :compiled_graph, type: :compiled_graph, summary: "Previously compiled graph to execute instead of compiling a block.") ] ), Mcp::ToolDefinition.new( name: :creator_wizard, summary: "Build a stateful creator wizard payload.", target: :optional_profile_or_environment, arguments: creator_arguments(include_scope: true, include_root: true) ), Mcp::ToolDefinition.new( name: :creator_session_start, summary: "Create a serialized creator session payload.", target: :optional_profile_or_environment, arguments: creator_arguments(include_scope: true, include_root: true) ), Mcp::ToolDefinition.new( name: :creator_session_apply, summary: "Apply updates to a serialized creator session payload.", target: :optional_profile_or_environment, arguments: [ Mcp::ToolArgument.new(name: :session, type: :session_state, summary: "Previously serialized creator session payload.", required: true), Mcp::ToolArgument.new(name: :updates, type: :map, summary: "Partial wizard updates to merge into the session.", required: true) ] ), Mcp::ToolDefinition.new( name: :creator_session_workflow, summary: "Build workflow payload from a serialized creator session.", target: :optional_profile_or_environment, arguments: [ Mcp::ToolArgument.new(name: :session, type: :session_state, summary: "Previously serialized creator session payload.", required: true) ] ), Mcp::ToolDefinition.new( name: :creator_session_write_plan, summary: "Build writer plan payload from a serialized creator session.", target: :optional_profile_or_environment, arguments: [ Mcp::ToolArgument.new(name: :session, type: :session_state, summary: "Previously serialized creator session payload.", required: true) ] ), Mcp::ToolDefinition.new( name: :creator_session_write, summary: "Write scaffold files from a serialized creator session.", mutating: true, target: :optional_profile_or_environment, arguments: [ Mcp::ToolArgument.new(name: :session, type: :session_state, summary: "Previously serialized creator session payload.", required: true) ] ), Mcp::ToolDefinition.new( name: :creator_workflow, summary: "Build a creator workflow payload.", target: :optional_profile_or_environment, arguments: creator_arguments(include_scope: true) ), Mcp::ToolDefinition.new( name: :creator_write_plan, summary: "Build a creator writer plan payload.", target: :optional_profile_or_environment, arguments: creator_arguments(include_scope: true, include_root: true, require_name: true, require_root: true) ), Mcp::ToolDefinition.new( name: :creator_write, summary: "Write a creator scaffold to disk.", mutating: true, target: :optional_profile_or_environment, arguments: creator_arguments(include_scope: true, include_root: true, require_name: true, require_root: true) ) ].freeze end |