Class: Sxn::MCP::Tools::Worktrees::AddWorktree

Inherits:
MCP::Tool
  • Object
show all
Defined in:
lib/sxn/mcp/tools/worktrees.rb

Overview

Add a worktree to a session

Class Method Summary collapse

Class Method Details

.call(project_name:, server_context:, branch: nil, session_name: nil, apply_rules: true) ⇒ Object



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
# File 'lib/sxn/mcp/tools/worktrees.rb', line 82

def call(project_name:, server_context:, branch: nil, session_name: nil, apply_rules: true)
  BaseTool.ensure_initialized!(server_context)

  BaseTool::ErrorMapping.wrap do
    worktree_manager = server_context[:worktree_manager]

    result = worktree_manager.add_worktree(
      project_name,
      branch,
      session_name: session_name
    )

    # Apply rules if requested
    rules_result = nil
    if apply_rules && server_context[:rules_manager]
      rules_result = apply_project_rules(
        server_context,
        project_name,
        result[:session]
      )
    end

    output = <<~RESULT
      Worktree created successfully:
      - Project: #{result[:project]}
      - Branch: #{result[:branch]}
      - Path: #{result[:path]}
      - Session: #{result[:session]}
    RESULT

    if rules_result
      output += "\nRules applied: #{rules_result[:applied_count]} rule(s)"
      output += "\nRule errors: #{rules_result[:errors].join(", ")}" unless rules_result[:errors].empty?
    end

    BaseTool.text_response(output.strip)
  end
end