sxn 0.3.0 → 0.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +16 -13
- data/Gemfile.lock +6 -1
- data/bin/sxn-mcp +58 -0
- data/docs/MCP_IMPLEMENTATION.md +425 -0
- data/lib/sxn/CLI.rb +7 -0
- data/lib/sxn/commands/mcp.rb +219 -0
- data/lib/sxn/commands/sessions.rb +1 -4
- data/lib/sxn/commands/templates.rb +1 -5
- data/lib/sxn/commands.rb +1 -0
- data/lib/sxn/mcp/prompts/workflow_prompts.rb +107 -0
- data/lib/sxn/mcp/resources/session_resources.rb +145 -0
- data/lib/sxn/mcp/server.rb +127 -0
- data/lib/sxn/mcp/tools/base_tool.rb +96 -0
- data/lib/sxn/mcp/tools/projects.rb +144 -0
- data/lib/sxn/mcp/tools/rules.rb +108 -0
- data/lib/sxn/mcp/tools/sessions.rb +375 -0
- data/lib/sxn/mcp/tools/templates.rb +119 -0
- data/lib/sxn/mcp/tools/worktrees.rb +168 -0
- data/lib/sxn/mcp.rb +20 -0
- data/lib/sxn/version.rb +1 -1
- data/lib/sxn.rb +1 -0
- data/sxn.gemspec +86 -0
- data/test.txt +1 -0
- metadata +31 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 18c432e0aba5fd629beff742c41347cb97feede6e7bf9dfa907b8009c9ec6c03
|
|
4
|
+
data.tar.gz: 571a53c506eec48fbeecd78ce515f1e8b4d1bcec7e2daf72529e34c87e5686b5
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 6546d482da2b04f1186a08d3b7c10780e86e8b5caf08578d3d23ed2cdf7fe0031816e7e9447c835395dab5fda9f19f4f8487f28a883e0386572d109133a0131d
|
|
7
|
+
data.tar.gz: 7fad5c531582afe4f1e82109567ea152fc4ced391e4478a6c4d7e7e4f18b0b7790e37a6e99b8a5383217c21574b8e4b3b781efa8f36ff2936b18f6b4e8e4088b
|
data/CHANGELOG.md
CHANGED
|
@@ -5,19 +5,24 @@ All notable changes to this project will be documented in this file.
|
|
|
5
5
|
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
|
|
6
6
|
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
|
7
7
|
|
|
8
|
-
## [0.
|
|
8
|
+
## [0.4.0] - 2025-12-17
|
|
9
9
|
|
|
10
10
|
### Added
|
|
11
|
-
-
|
|
12
|
-
-
|
|
13
|
-
-
|
|
14
|
-
-
|
|
15
|
-
-
|
|
16
|
-
-
|
|
17
|
-
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
-
|
|
11
|
+
- **MCP Server**: Model Context Protocol server for AI assistant integration
|
|
12
|
+
- Enables Claude Code and other AI assistants to manage sessions programmatically
|
|
13
|
+
- STDIO and HTTP transport support
|
|
14
|
+
- Session management tools: create, list, get, delete, archive, activate, swap
|
|
15
|
+
- Worktree management tools: list, add, remove
|
|
16
|
+
- Project management tools: list, add, get
|
|
17
|
+
- Template and rules tools for automation
|
|
18
|
+
- Guided workflow prompts for session creation
|
|
19
|
+
- Dynamic resources for session data access
|
|
20
|
+
- New CLI command: `sxn mcp start` to launch the MCP server
|
|
21
|
+
- New binary: `sxn-mcp` for direct MCP server execution
|
|
22
|
+
- `--template` option for `sxn sessions add` command
|
|
23
|
+
|
|
24
|
+
### Documentation
|
|
25
|
+
- Added MCP_IMPLEMENTATION.md with architecture and usage details
|
|
21
26
|
|
|
22
27
|
## [0.2.5] - 2025-11-30
|
|
23
28
|
|
|
@@ -115,8 +120,6 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
115
120
|
- Initial placeholder release
|
|
116
121
|
- Basic gem structure
|
|
117
122
|
|
|
118
|
-
[0.3.0]: https://github.com/idl3/sxn/compare/v0.2.5...v0.3.0
|
|
119
|
-
[0.2.5]: https://github.com/idl3/sxn/compare/v0.2.4...v0.2.5
|
|
120
123
|
[0.2.4]: https://github.com/idl3/sxn/compare/v0.2.3...v0.2.4
|
|
121
124
|
[0.2.3]: https://github.com/idl3/sxn/compare/v0.2.1...v0.2.3
|
|
122
125
|
[0.2.1]: https://github.com/idl3/sxn/compare/v0.2.0...v0.2.1
|
data/Gemfile.lock
CHANGED
|
@@ -1,13 +1,14 @@
|
|
|
1
1
|
PATH
|
|
2
2
|
remote: .
|
|
3
3
|
specs:
|
|
4
|
-
sxn (0.
|
|
4
|
+
sxn (0.4.0)
|
|
5
5
|
async (~> 2.0)
|
|
6
6
|
bcrypt (~> 3.1)
|
|
7
7
|
dry-configurable (~> 1.0)
|
|
8
8
|
json-schema (~> 4.0)
|
|
9
9
|
liquid (~> 5.4)
|
|
10
10
|
listen (~> 3.8)
|
|
11
|
+
mcp (~> 0.4)
|
|
11
12
|
openssl (>= 3.0)
|
|
12
13
|
ostruct
|
|
13
14
|
parallel (~> 1.23)
|
|
@@ -127,6 +128,7 @@ GEM
|
|
|
127
128
|
json (2.13.2)
|
|
128
129
|
json-schema (4.3.1)
|
|
129
130
|
addressable (>= 2.8)
|
|
131
|
+
json_rpc_handler (0.1.1)
|
|
130
132
|
language_server-protocol (3.17.0.5)
|
|
131
133
|
lint_roller (1.1.0)
|
|
132
134
|
liquid (5.8.7)
|
|
@@ -136,6 +138,9 @@ GEM
|
|
|
136
138
|
rb-fsevent (~> 0.10, >= 0.10.3)
|
|
137
139
|
rb-inotify (~> 0.9, >= 0.9.10)
|
|
138
140
|
logger (1.7.0)
|
|
141
|
+
mcp (0.4.0)
|
|
142
|
+
json-schema (>= 4.1)
|
|
143
|
+
json_rpc_handler (~> 0.1)
|
|
139
144
|
memory_profiler (1.1.0)
|
|
140
145
|
metrics (0.13.0)
|
|
141
146
|
mini_mime (1.1.5)
|
data/bin/sxn-mcp
ADDED
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
#!/usr/bin/env ruby
|
|
2
|
+
# frozen_string_literal: true
|
|
3
|
+
|
|
4
|
+
require "bundler/setup"
|
|
5
|
+
require "sxn"
|
|
6
|
+
require "sxn/mcp"
|
|
7
|
+
|
|
8
|
+
# Parse command line options
|
|
9
|
+
require "optparse"
|
|
10
|
+
|
|
11
|
+
options = {}
|
|
12
|
+
OptionParser.new do |opts|
|
|
13
|
+
opts.banner = "Usage: sxn-mcp [options]"
|
|
14
|
+
|
|
15
|
+
opts.on("-w", "--workspace PATH", "Workspace path (default: auto-discover)") do |path|
|
|
16
|
+
options[:workspace] = path
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
opts.on("-t", "--transport TYPE", "Transport type: stdio (default), http") do |type|
|
|
20
|
+
options[:transport] = type
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
opts.on("-p", "--port PORT", Integer, "HTTP port (default: 3000)") do |port|
|
|
24
|
+
options[:port] = port
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
opts.on("-v", "--version", "Show version") do
|
|
28
|
+
puts "sxn-mcp #{Sxn::VERSION}"
|
|
29
|
+
exit
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
opts.on("-h", "--help", "Show help") do
|
|
33
|
+
puts opts
|
|
34
|
+
exit
|
|
35
|
+
end
|
|
36
|
+
end.parse!
|
|
37
|
+
|
|
38
|
+
# Create and run server
|
|
39
|
+
begin
|
|
40
|
+
server = Sxn::MCP::Server.new(workspace_path: options[:workspace])
|
|
41
|
+
|
|
42
|
+
case options[:transport]
|
|
43
|
+
when "http"
|
|
44
|
+
port = options[:port] || 3000
|
|
45
|
+
warn "Starting sxn MCP server on http://localhost:#{port}"
|
|
46
|
+
server.run_http(port: port)
|
|
47
|
+
else
|
|
48
|
+
# Default to stdio transport
|
|
49
|
+
server.run_stdio
|
|
50
|
+
end
|
|
51
|
+
rescue Interrupt
|
|
52
|
+
# Clean exit on Ctrl+C
|
|
53
|
+
exit 0
|
|
54
|
+
rescue StandardError => e
|
|
55
|
+
warn "Error: #{e.message}"
|
|
56
|
+
warn e.backtrace.first(5).join("\n") if ENV["SXN_DEBUG"]
|
|
57
|
+
exit 1
|
|
58
|
+
end
|
|
@@ -0,0 +1,425 @@
|
|
|
1
|
+
# SXN MCP Server & Claude Code Plugin Implementation Plan
|
|
2
|
+
|
|
3
|
+
## Overview
|
|
4
|
+
|
|
5
|
+
Build an MCP (Model Context Protocol) server for sxn that enables Claude Code to manage development sessions, worktrees, templates, and rules. Then enhance with a Claude Code plugin for richer UX.
|
|
6
|
+
|
|
7
|
+
## Architecture
|
|
8
|
+
|
|
9
|
+
### Phase 1: MCP Server (`sxn-mcp`)
|
|
10
|
+
A standalone MCP server using the official Ruby SDK that exposes sxn operations as tools, resources, and prompts.
|
|
11
|
+
|
|
12
|
+
### Phase 2: Claude Code Plugin
|
|
13
|
+
A plugin that bundles the MCP server with slash commands, hooks, and skills for enhanced Claude Code integration.
|
|
14
|
+
|
|
15
|
+
---
|
|
16
|
+
|
|
17
|
+
## Phase 1: MCP Server Implementation
|
|
18
|
+
|
|
19
|
+
### Dependencies
|
|
20
|
+
|
|
21
|
+
Add to `sxn.gemspec`:
|
|
22
|
+
```ruby
|
|
23
|
+
spec.add_dependency "mcp", "~> 0.4" # Official Anthropic/Shopify Ruby SDK
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
Note: `async` (~2.0) and `json-schema` (~4.0) already present in gemspec.
|
|
27
|
+
|
|
28
|
+
### File Structure
|
|
29
|
+
|
|
30
|
+
```
|
|
31
|
+
lib/sxn/
|
|
32
|
+
├── mcp/
|
|
33
|
+
│ ├── server.rb # Main MCP server class
|
|
34
|
+
│ ├── tools/
|
|
35
|
+
│ │ ├── base_tool.rb # Shared tool functionality + error mapping
|
|
36
|
+
│ │ ├── sessions.rb # Session CRUD tools
|
|
37
|
+
│ │ ├── worktrees.rb # Worktree management tools
|
|
38
|
+
│ │ ├── projects.rb # Project management tools
|
|
39
|
+
│ │ ├── templates.rb # Template tools
|
|
40
|
+
│ │ └── rules.rb # Rules tools
|
|
41
|
+
│ ├── resources/
|
|
42
|
+
│ │ └── session_resources.rb # Read-only context resources
|
|
43
|
+
│ └── prompts/
|
|
44
|
+
│ └── workflow_prompts.rb # User-initiated workflow prompts
|
|
45
|
+
├── mcp.rb # Module loader
|
|
46
|
+
bin/
|
|
47
|
+
└── sxn-mcp # Executable for MCP server
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
### MCP Tools
|
|
51
|
+
|
|
52
|
+
#### Session Tools
|
|
53
|
+
| Tool | Description |
|
|
54
|
+
|------|-------------|
|
|
55
|
+
| `sxn_sessions_list` | List sessions with optional status filter |
|
|
56
|
+
| `sxn_sessions_create` | Create session with auto-detection, optional template |
|
|
57
|
+
| `sxn_sessions_get` | Get detailed session info |
|
|
58
|
+
| `sxn_sessions_delete` | Delete session (with force option) |
|
|
59
|
+
| `sxn_sessions_archive` | Archive a session |
|
|
60
|
+
| `sxn_sessions_activate` | Activate an archived session |
|
|
61
|
+
| `sxn_sessions_swap` | Switch session + return navigation info (hybrid cd approach) |
|
|
62
|
+
|
|
63
|
+
#### Worktree Tools
|
|
64
|
+
| Tool | Description |
|
|
65
|
+
|------|-------------|
|
|
66
|
+
| `sxn_worktrees_list` | List worktrees in session |
|
|
67
|
+
| `sxn_worktrees_add` | Add worktree with auto rule application |
|
|
68
|
+
| `sxn_worktrees_remove` | Remove worktree from session |
|
|
69
|
+
|
|
70
|
+
#### Project Tools
|
|
71
|
+
| Tool | Description |
|
|
72
|
+
|------|-------------|
|
|
73
|
+
| `sxn_projects_list` | List registered projects |
|
|
74
|
+
| `sxn_projects_add` | Register new project (auto-detect type) |
|
|
75
|
+
| `sxn_projects_get` | Get project details |
|
|
76
|
+
|
|
77
|
+
#### Template Tools
|
|
78
|
+
| Tool | Description |
|
|
79
|
+
|------|-------------|
|
|
80
|
+
| `sxn_templates_list` | List available templates |
|
|
81
|
+
| `sxn_templates_apply` | Apply template to session |
|
|
82
|
+
|
|
83
|
+
#### Rules Tools
|
|
84
|
+
| Tool | Description |
|
|
85
|
+
|------|-------------|
|
|
86
|
+
| `sxn_rules_list` | List rules for project |
|
|
87
|
+
| `sxn_rules_apply` | Apply rules to worktree |
|
|
88
|
+
|
|
89
|
+
### MCP Resources (Read-only Context)
|
|
90
|
+
|
|
91
|
+
| URI | Description |
|
|
92
|
+
|-----|-------------|
|
|
93
|
+
| `sxn://session/current` | Current session info + worktrees |
|
|
94
|
+
| `sxn://sessions` | All sessions summary |
|
|
95
|
+
| `sxn://projects` | Registered projects |
|
|
96
|
+
|
|
97
|
+
### MCP Prompts (User-initiated Workflows)
|
|
98
|
+
|
|
99
|
+
| Prompt | Description |
|
|
100
|
+
|--------|-------------|
|
|
101
|
+
| `new-session` | Guided session creation workflow |
|
|
102
|
+
| `multi-repo-setup` | Set up multi-repo development environment |
|
|
103
|
+
|
|
104
|
+
### Session Swap: Hybrid Directory Approach
|
|
105
|
+
|
|
106
|
+
The `sxn_sessions_swap` tool implements the hybrid approach:
|
|
107
|
+
|
|
108
|
+
```ruby
|
|
109
|
+
# Returns structured response with navigation strategy
|
|
110
|
+
{
|
|
111
|
+
session: { name: "feature-xyz", path: "/path/to/session" },
|
|
112
|
+
worktrees: [{ project: "api", path: "/path/to/session/api" }],
|
|
113
|
+
navigation: {
|
|
114
|
+
strategy: "bash_cd" | "new_instance",
|
|
115
|
+
bash_command: "cd /path/to/session", # If within allowed dirs
|
|
116
|
+
shell_command: "claude --cwd /path/to/session", # If new instance needed
|
|
117
|
+
reason: "Session is child of current directory" | "Session outside working directory"
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
```
|
|
121
|
+
|
|
122
|
+
Claude Code will:
|
|
123
|
+
1. Try `cd` via Bash tool if session is within allowed directories
|
|
124
|
+
2. If outside, suggest user run `claude --cwd <path>` for new instance
|
|
125
|
+
|
|
126
|
+
### Server Implementation
|
|
127
|
+
|
|
128
|
+
```ruby
|
|
129
|
+
# lib/sxn/mcp/server.rb
|
|
130
|
+
module Sxn
|
|
131
|
+
module MCP
|
|
132
|
+
class Server
|
|
133
|
+
def initialize(workspace_path: nil)
|
|
134
|
+
@workspace_path = workspace_path || ENV['SXN_WORKSPACE'] || discover_workspace
|
|
135
|
+
@config_manager = Sxn::Core::ConfigManager.new(@workspace_path)
|
|
136
|
+
@server = build_mcp_server
|
|
137
|
+
end
|
|
138
|
+
|
|
139
|
+
def run_stdio
|
|
140
|
+
transport = ::MCP::Server::Transports::StdioTransport.new(@server)
|
|
141
|
+
transport.open
|
|
142
|
+
end
|
|
143
|
+
|
|
144
|
+
private
|
|
145
|
+
|
|
146
|
+
def build_mcp_server
|
|
147
|
+
::MCP::Server.new(
|
|
148
|
+
name: "sxn",
|
|
149
|
+
version: Sxn::VERSION,
|
|
150
|
+
tools: registered_tools,
|
|
151
|
+
resources: registered_resources,
|
|
152
|
+
prompts: registered_prompts,
|
|
153
|
+
server_context: build_context
|
|
154
|
+
)
|
|
155
|
+
end
|
|
156
|
+
|
|
157
|
+
def build_context
|
|
158
|
+
{
|
|
159
|
+
config_manager: @config_manager,
|
|
160
|
+
session_manager: Sxn::Core::SessionManager.new(@config_manager),
|
|
161
|
+
project_manager: Sxn::Core::ProjectManager.new(@config_manager),
|
|
162
|
+
worktree_manager: Sxn::Core::WorktreeManager.new(@config_manager),
|
|
163
|
+
template_manager: Sxn::Core::TemplateManager.new(@config_manager),
|
|
164
|
+
rules_manager: Sxn::Core::RulesManager.new(@config_manager),
|
|
165
|
+
workspace_path: @workspace_path
|
|
166
|
+
}
|
|
167
|
+
end
|
|
168
|
+
end
|
|
169
|
+
end
|
|
170
|
+
end
|
|
171
|
+
```
|
|
172
|
+
|
|
173
|
+
### Error Mapping
|
|
174
|
+
|
|
175
|
+
Map sxn errors to MCP protocol errors:
|
|
176
|
+
|
|
177
|
+
```ruby
|
|
178
|
+
# lib/sxn/mcp/tools/base_tool.rb
|
|
179
|
+
module Sxn::MCP::Tools
|
|
180
|
+
module ErrorMapping
|
|
181
|
+
SXN_TO_MCP = {
|
|
182
|
+
Sxn::SessionNotFoundError => ::MCP::Tool::ExecutionError,
|
|
183
|
+
Sxn::ProjectNotFoundError => ::MCP::Tool::ExecutionError,
|
|
184
|
+
Sxn::MCPValidationError => ::MCP::InvalidArgumentError,
|
|
185
|
+
Sxn::ValidationError => ::MCP::InvalidArgumentError
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
def self.wrap
|
|
189
|
+
yield
|
|
190
|
+
rescue Sxn::Error => e
|
|
191
|
+
mcp_error = SXN_TO_MCP[e.class] || ::MCP::Tool::ExecutionError
|
|
192
|
+
raise mcp_error, e.message
|
|
193
|
+
end
|
|
194
|
+
end
|
|
195
|
+
end
|
|
196
|
+
```
|
|
197
|
+
|
|
198
|
+
### Installation & Configuration
|
|
199
|
+
|
|
200
|
+
**CLI Installation:**
|
|
201
|
+
```bash
|
|
202
|
+
claude mcp add --transport stdio sxn -- sxn-mcp
|
|
203
|
+
```
|
|
204
|
+
|
|
205
|
+
**Project `.mcp.json`:**
|
|
206
|
+
```json
|
|
207
|
+
{
|
|
208
|
+
"mcpServers": {
|
|
209
|
+
"sxn": {
|
|
210
|
+
"command": "sxn-mcp",
|
|
211
|
+
"args": [],
|
|
212
|
+
"env": {
|
|
213
|
+
"SXN_WORKSPACE": "${PWD}"
|
|
214
|
+
}
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
}
|
|
218
|
+
```
|
|
219
|
+
|
|
220
|
+
---
|
|
221
|
+
|
|
222
|
+
## Phase 2: Claude Code Plugin
|
|
223
|
+
|
|
224
|
+
### Plugin Structure
|
|
225
|
+
|
|
226
|
+
```
|
|
227
|
+
sxn-claude-plugin/
|
|
228
|
+
├── .claude-plugin/
|
|
229
|
+
│ └── plugin.json # Plugin manifest
|
|
230
|
+
├── commands/
|
|
231
|
+
│ ├── start.md # /sxn:start - create session
|
|
232
|
+
│ ├── use.md # /sxn:use - switch session
|
|
233
|
+
│ ├── status.md # /sxn:status - current session info
|
|
234
|
+
│ └── worktree.md # /sxn:worktree - add worktree
|
|
235
|
+
├── agents/
|
|
236
|
+
│ └── session-setup.md # Subagent for guided setup
|
|
237
|
+
├── skills/
|
|
238
|
+
│ └── session-management.md # Auto-activate for session tasks
|
|
239
|
+
├── hooks/
|
|
240
|
+
│ └── hooks.json # Auto-detect sxn workspaces
|
|
241
|
+
└── .mcp.json # MCP server config
|
|
242
|
+
```
|
|
243
|
+
|
|
244
|
+
### Plugin Manifest
|
|
245
|
+
|
|
246
|
+
```json
|
|
247
|
+
{
|
|
248
|
+
"name": "sxn",
|
|
249
|
+
"version": "0.1.0",
|
|
250
|
+
"description": "Session management for multi-repository development",
|
|
251
|
+
"author": "Ernest",
|
|
252
|
+
"repository": "https://github.com/ernest/sxn"
|
|
253
|
+
}
|
|
254
|
+
```
|
|
255
|
+
|
|
256
|
+
### Slash Commands
|
|
257
|
+
|
|
258
|
+
**`/sxn:start` (commands/start.md):**
|
|
259
|
+
```markdown
|
|
260
|
+
Create a new sxn development session.
|
|
261
|
+
|
|
262
|
+
Arguments: $ARGUMENTS
|
|
263
|
+
|
|
264
|
+
Use the sxn MCP server to:
|
|
265
|
+
1. If no name provided, suggest a name based on context
|
|
266
|
+
2. Create session with sxn_sessions_create
|
|
267
|
+
3. Optionally apply template if specified
|
|
268
|
+
4. Add worktrees for requested projects
|
|
269
|
+
5. Navigate to session directory
|
|
270
|
+
```
|
|
271
|
+
|
|
272
|
+
**`/sxn:use` (commands/use.md):**
|
|
273
|
+
```markdown
|
|
274
|
+
Switch to an existing sxn session.
|
|
275
|
+
|
|
276
|
+
Arguments: $ARGUMENTS
|
|
277
|
+
|
|
278
|
+
1. Call sxn_sessions_swap with the session name
|
|
279
|
+
2. Follow navigation strategy (bash cd or suggest new instance)
|
|
280
|
+
3. Show session status after switch
|
|
281
|
+
```
|
|
282
|
+
|
|
283
|
+
### Hooks
|
|
284
|
+
|
|
285
|
+
**`hooks/hooks.json`:**
|
|
286
|
+
```json
|
|
287
|
+
{
|
|
288
|
+
"hooks": [
|
|
289
|
+
{
|
|
290
|
+
"event": "on_session_start",
|
|
291
|
+
"command": "sxn-detect-workspace",
|
|
292
|
+
"description": "Auto-detect sxn workspace on session start"
|
|
293
|
+
}
|
|
294
|
+
]
|
|
295
|
+
}
|
|
296
|
+
```
|
|
297
|
+
|
|
298
|
+
### Distribution
|
|
299
|
+
|
|
300
|
+
Plugin can be installed via:
|
|
301
|
+
```bash
|
|
302
|
+
claude plugin install /path/to/sxn-claude-plugin
|
|
303
|
+
# or from npm/registry once published
|
|
304
|
+
claude plugin install sxn
|
|
305
|
+
```
|
|
306
|
+
|
|
307
|
+
---
|
|
308
|
+
|
|
309
|
+
## Implementation Order
|
|
310
|
+
|
|
311
|
+
### Step 1: MCP Server Core
|
|
312
|
+
1. Add `mcp` gem dependency to gemspec
|
|
313
|
+
2. Create `lib/sxn/mcp.rb` module loader
|
|
314
|
+
3. Implement `lib/sxn/mcp/server.rb`
|
|
315
|
+
4. Create `bin/sxn-mcp` executable
|
|
316
|
+
5. Implement `lib/sxn/mcp/tools/base_tool.rb` with error mapping
|
|
317
|
+
|
|
318
|
+
### Step 2: Session Tools
|
|
319
|
+
1. `sxn_sessions_list`
|
|
320
|
+
2. `sxn_sessions_create`
|
|
321
|
+
3. `sxn_sessions_get`
|
|
322
|
+
4. `sxn_sessions_delete`
|
|
323
|
+
5. `sxn_sessions_archive`
|
|
324
|
+
6. `sxn_sessions_activate`
|
|
325
|
+
7. `sxn_sessions_swap` (with hybrid cd approach)
|
|
326
|
+
|
|
327
|
+
### Step 3: Worktree & Project Tools
|
|
328
|
+
1. `sxn_worktrees_list`
|
|
329
|
+
2. `sxn_worktrees_add`
|
|
330
|
+
3. `sxn_worktrees_remove`
|
|
331
|
+
4. `sxn_projects_list`
|
|
332
|
+
5. `sxn_projects_add`
|
|
333
|
+
6. `sxn_projects_get`
|
|
334
|
+
|
|
335
|
+
### Step 4: Template & Rules Tools
|
|
336
|
+
1. `sxn_templates_list`
|
|
337
|
+
2. `sxn_templates_apply`
|
|
338
|
+
3. `sxn_rules_list`
|
|
339
|
+
4. `sxn_rules_apply`
|
|
340
|
+
|
|
341
|
+
### Step 5: Resources & Prompts
|
|
342
|
+
1. `sxn://session/current` resource
|
|
343
|
+
2. `sxn://sessions` resource
|
|
344
|
+
3. `sxn://projects` resource
|
|
345
|
+
4. `new-session` prompt
|
|
346
|
+
5. `multi-repo-setup` prompt
|
|
347
|
+
|
|
348
|
+
### Step 6: Tests
|
|
349
|
+
1. Unit tests for each tool
|
|
350
|
+
2. Integration tests with mock MCP client
|
|
351
|
+
3. Use existing test patterns from `spec/unit/`
|
|
352
|
+
|
|
353
|
+
### Step 7: Claude Code Plugin
|
|
354
|
+
1. Create plugin directory structure
|
|
355
|
+
2. Write slash command definitions
|
|
356
|
+
3. Implement hooks
|
|
357
|
+
4. Create session-management skill
|
|
358
|
+
5. Test plugin installation
|
|
359
|
+
|
|
360
|
+
---
|
|
361
|
+
|
|
362
|
+
## Critical Files to Modify
|
|
363
|
+
|
|
364
|
+
| File | Changes |
|
|
365
|
+
|------|---------|
|
|
366
|
+
| `sxn.gemspec` | Add `mcp` gem dependency |
|
|
367
|
+
| `lib/sxn.rb` | Add `require_relative "sxn/mcp"` |
|
|
368
|
+
| `lib/sxn/errors.rb` | Already has MCPError classes (use them) |
|
|
369
|
+
| `lib/sxn/core/session_manager.rb` | Reference for session operations |
|
|
370
|
+
| `lib/sxn/core/worktree_manager.rb` | Reference for worktree operations |
|
|
371
|
+
| `lib/sxn/core/project_manager.rb` | Reference for project operations |
|
|
372
|
+
| `lib/sxn/core/template_manager.rb` | Reference for template operations |
|
|
373
|
+
| `lib/sxn/core/rules_manager.rb` | Reference for rules operations |
|
|
374
|
+
|
|
375
|
+
## New Files to Create
|
|
376
|
+
|
|
377
|
+
| File | Purpose |
|
|
378
|
+
|------|---------|
|
|
379
|
+
| `lib/sxn/mcp.rb` | Module loader |
|
|
380
|
+
| `lib/sxn/mcp/server.rb` | Main MCP server |
|
|
381
|
+
| `lib/sxn/mcp/tools/*.rb` | Tool implementations |
|
|
382
|
+
| `lib/sxn/mcp/resources/*.rb` | Resource implementations |
|
|
383
|
+
| `lib/sxn/mcp/prompts/*.rb` | Prompt implementations |
|
|
384
|
+
| `bin/sxn-mcp` | Executable |
|
|
385
|
+
| `spec/unit/mcp/**/*_spec.rb` | Tests |
|
|
386
|
+
|
|
387
|
+
---
|
|
388
|
+
|
|
389
|
+
## Usage Examples
|
|
390
|
+
|
|
391
|
+
### From Claude Code (after MCP server installed)
|
|
392
|
+
|
|
393
|
+
```
|
|
394
|
+
User: Create a new session for the user-auth feature
|
|
395
|
+
|
|
396
|
+
Claude: I'll create a new session for you.
|
|
397
|
+
[calls sxn_sessions_create with name: "user-auth"]
|
|
398
|
+
|
|
399
|
+
Session "user-auth" created at /path/to/sxn-sessions/user-auth
|
|
400
|
+
|
|
401
|
+
Would you like me to add worktrees for specific projects?
|
|
402
|
+
```
|
|
403
|
+
|
|
404
|
+
```
|
|
405
|
+
User: Switch to my api-refactor session
|
|
406
|
+
|
|
407
|
+
Claude: I'll switch to that session.
|
|
408
|
+
[calls sxn_sessions_swap with name: "api-refactor"]
|
|
409
|
+
|
|
410
|
+
Switched to session "api-refactor".
|
|
411
|
+
[calls cd /path/to/sxn-sessions/api-refactor via Bash]
|
|
412
|
+
|
|
413
|
+
Now working in the api-refactor session. This session has worktrees for:
|
|
414
|
+
- api-service (branch: api-refactor)
|
|
415
|
+
- shared-libs (branch: api-refactor)
|
|
416
|
+
```
|
|
417
|
+
|
|
418
|
+
### With Plugin Slash Commands
|
|
419
|
+
|
|
420
|
+
```
|
|
421
|
+
/sxn:start user-auth --template backend-services
|
|
422
|
+
/sxn:use api-refactor
|
|
423
|
+
/sxn:status
|
|
424
|
+
/sxn:worktree add frontend-app
|
|
425
|
+
```
|
data/lib/sxn/CLI.rb
CHANGED
|
@@ -225,6 +225,13 @@ module Sxn
|
|
|
225
225
|
handle_error(e)
|
|
226
226
|
end
|
|
227
227
|
|
|
228
|
+
desc "mcp SUBCOMMAND", "Manage MCP server for Claude Code"
|
|
229
|
+
def mcp(subcommand = nil, *args)
|
|
230
|
+
Commands::MCP.start([subcommand, *args].compact)
|
|
231
|
+
rescue Sxn::Error => e
|
|
232
|
+
handle_error(e)
|
|
233
|
+
end
|
|
234
|
+
|
|
228
235
|
desc "status", "Show overall sxn status"
|
|
229
236
|
def status
|
|
230
237
|
show_status
|