@williamzujkowski/live-coding-music-mcp 1.0.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.
Files changed (41) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +1735 -0
  3. package/dist/AudioAnalyzer.js +678 -0
  4. package/dist/PatternStore.js +169 -0
  5. package/dist/StrudelController.js +676 -0
  6. package/dist/__tests__/MusicTheory.test.js +245 -0
  7. package/dist/__tests__/PatternGenerator.test.js +337 -0
  8. package/dist/__tests__/PatternStore.test.js +153 -0
  9. package/dist/__tests__/utils/MockPlaywright.js +130 -0
  10. package/dist/index.js +21 -0
  11. package/dist/server/EnhancedMCPServer.js +654 -0
  12. package/dist/server/EnhancedMCPServerFixed.js +2506 -0
  13. package/dist/server/server.js +580 -0
  14. package/dist/server/tools/ai.js +530 -0
  15. package/dist/server/tools/analysis.js +132 -0
  16. package/dist/server/tools/capture.js +184 -0
  17. package/dist/server/tools/diagnostics.js +96 -0
  18. package/dist/server/tools/editor.js +128 -0
  19. package/dist/server/tools/generate.js +218 -0
  20. package/dist/server/tools/history.js +196 -0
  21. package/dist/server/tools/playback.js +41 -0
  22. package/dist/server/tools/session.js +115 -0
  23. package/dist/server/tools/storage.js +77 -0
  24. package/dist/server/tools/transform.js +399 -0
  25. package/dist/server/tools/types.js +9 -0
  26. package/dist/services/AudioCaptureService.js +279 -0
  27. package/dist/services/GeminiService.js +790 -0
  28. package/dist/services/MIDIExportService.js +412 -0
  29. package/dist/services/MusicTheory.js +186 -0
  30. package/dist/services/PatternGenerator.js +647 -0
  31. package/dist/services/SessionManager.js +316 -0
  32. package/dist/services/StrudelEngine.js +374 -0
  33. package/dist/services/__mocks__/StrudelEngine.js +157 -0
  34. package/dist/types/AudioAnalysis.js +4 -0
  35. package/dist/types/index.js +1 -0
  36. package/dist/utils/ErrorRecovery.js +248 -0
  37. package/dist/utils/InputValidator.js +281 -0
  38. package/dist/utils/Logger.js +19 -0
  39. package/dist/utils/PatternValidator.js +241 -0
  40. package/dist/utils/PerformanceMonitor.js +128 -0
  41. package/package.json +86 -0
package/README.md ADDED
@@ -0,0 +1,1735 @@
1
+ # live-coding-music-mcp
2
+
3
+ > 🎵 MCP server for AI-assisted live-coding music via [strudel.cc](https://strudel.cc/)
4
+ >
5
+ > **Unofficial fan project.** Not affiliated with, or endorsed by, the [Strudel project](https://codeberg.org/uzu/strudel). This adapter exists to make live-coding music accessible to beginners who want to try pattern-based music without learning the whole ecosystem first.
6
+ >
7
+ > **Status:** Beta | 77% test coverage | Published to npm | Actively developed
8
+
9
+ <a href="https://glama.ai/mcp/servers/@williamzujkowski/live-coding-music-mcp">
10
+ <img width="380" height="200" src="https://glama.ai/mcp/servers/@williamzujkowski/live-coding-music-mcp/badge" alt="live-coding-music-mcp server" />
11
+ </a>
12
+
13
+ [![CI](https://github.com/williamzujkowski/live-coding-music-mcp/actions/workflows/ci.yml/badge.svg)](https://github.com/williamzujkowski/live-coding-music-mcp/actions)
14
+ [![npm version](https://img.shields.io/npm/v/@williamzujkowski/live-coding-music-mcp.svg)](https://www.npmjs.com/package/@williamzujkowski/live-coding-music-mcp)
15
+ [![Nerq Trust](https://nerq.ai/badge/live-coding-music-mcp)](https://nerq.ai/kya/live-coding-music-mcp)
16
+ [![Tools](https://img.shields.io/badge/tools-66-green.svg)]()
17
+ [![License](https://img.shields.io/badge/license-MIT-blue.svg)](LICENSE)
18
+
19
+ A Model Context Protocol (MCP) server that drives [Strudel.cc](https://strudel.cc/) from Claude for AI-assisted live-coding music, pattern generation, and algorithmic composition.
20
+
21
+ **Current State: Beta.** The core workflow (init → generate → write → play → analyze) works reliably with real audio output and has 1470 passing tests covering 77% of statements. CI is hardened with OpenSSF Scorecard, SHA-pinned actions, CODEOWNERS, and Dependabot. Known coverage gaps exist (notably `AudioCaptureService` at 33% and `AudioAnalyzer` branch coverage at 48%) — see [open issues](https://github.com/williamzujkowski/live-coding-music-mcp/issues) for the full list.
22
+
23
+ **What "Beta" means here:**
24
+ - Tool schemas are stable within minor versions; breaking changes require a major bump
25
+ - Single-browser-session limitation (multi-session tracked in [#108](https://github.com/williamzujkowski/live-coding-music-mcp/issues/108))
26
+ - Upstream `@strudel/*` dependencies pinned to known-good versions; Dependabot bumps gated on CI
27
+ - Expect hands-on iteration for non-standard patterns — report rough edges, they get fixed
28
+
29
+ ## Table of Contents
30
+
31
+ - [Features](#features)
32
+ - [Installation](#installation)
33
+ - [Quick Reference](#quick-reference)
34
+ - [Quick Start](#quick-start)
35
+ - [Available Tools](#available-tools)
36
+ - [Usage Examples](#usage-examples)
37
+ - [Architecture](#architecture)
38
+ - [Advanced Usage](#advanced-usage)
39
+ - [Configuration](#configuration)
40
+ - [Security](#security)
41
+ - [Troubleshooting](#troubleshooting)
42
+ - [Development](#development)
43
+ - [Contributing](#contributing)
44
+
45
+ ## Features
46
+
47
+ ### 🎹 Complete Music Control
48
+ - **65 MCP Tools**: Comprehensive suite for music creation and manipulation
49
+ - **Real Browser Automation**: Direct control of Strudel.cc through Playwright
50
+ - **Live Audio Analysis**: Real-time frequency analysis via Web Audio API
51
+ - **Pattern Generation**: AI-powered creation across 8+ music genres
52
+ - **Music Theory Engine**: Scales, chords, progressions, euclidean rhythms
53
+ - **Session Management**: Save, load, undo/redo with pattern storage
54
+
55
+ ### 🔧 Testing & Development Status
56
+ - ✅ **Test Suite**: Comprehensive test coverage across unit, integration, and validation tests
57
+ - ✅ **Code Coverage**: Actively tracked via CI
58
+ - ✅ **Browser Integration**: Works with live Strudel.cc website
59
+ - ✅ **Audio Analysis**: Real-time FFT analysis functional
60
+ - ✅ **Pattern Generation**: Core music generation features working
61
+ - ✅ **OIDC Publishing**: Secure npm publishing with provenance attestation
62
+
63
+ **Not Production-Ready:** This is experimental software under active development. Use for exploration and experimentation. Expect breaking changes, bugs, and incomplete features. See [CONTRIBUTING.md](CONTRIBUTING.md) to help improve it.
64
+
65
+ ### 🎼 Example Patterns
66
+
67
+ Explore 17 curated example patterns across 10 genres in [`patterns/examples/`](patterns/examples/):
68
+
69
+ - **Techno**: Hard techno, minimal techno
70
+ - **House**: Deep house, tech house
71
+ - **Drum & Bass**: Liquid, neurofunk
72
+ - **Ambient**: Dark ambient, drone
73
+ - **Trap**: Modern trap, cloud trap
74
+ - **Jungle**: Classic jungle, ragga jungle
75
+ - **Jazz**: Bebop, modal jazz
76
+ - **Intelligent DnB**: Atmospheric, liquid, LTJ Bukem style
77
+ - **Trip Hop**: Portishead, Massive Attack, Flying Lotus style
78
+ - **Boom Bap**: DJ Premier, Alchemist, golden era hip hop
79
+
80
+ Each example includes pattern code, BPM, key, and description. See [`patterns/examples/README.md`](patterns/examples/README.md) for details.
81
+
82
+ ## Migrating from `@williamzujkowski/strudel-mcp-server`
83
+
84
+ This project was renamed from `@williamzujkowski/strudel-mcp-server` to `@williamzujkowski/live-coding-music-mcp` to make the unofficial fan-project status unambiguous (see [#97](https://github.com/williamzujkowski/live-coding-music-mcp/issues/97)). The old package is deprecated on npm.
85
+
86
+ **If you were using the old package:**
87
+
88
+ ```bash
89
+ # Remove old
90
+ npm uninstall -g @williamzujkowski/strudel-mcp-server
91
+
92
+ # Install new
93
+ npm install -g @williamzujkowski/live-coding-music-mcp
94
+ ```
95
+
96
+ **Update your MCP client config.** The `bin` name changed from `strudel-mcp` to `live-coding-music-mcp`:
97
+
98
+ ```jsonc
99
+ // BEFORE
100
+ {
101
+ "mcpServers": {
102
+ "strudel": { "command": "strudel-mcp" }
103
+ }
104
+ }
105
+
106
+ // AFTER
107
+ {
108
+ "mcpServers": {
109
+ "live-coding-music": { "command": "live-coding-music-mcp" }
110
+ }
111
+ }
112
+ ```
113
+
114
+ The MCP server's internal identity string also changed from `strudel-mcp-enhanced` to `live-coding-music-mcp`. If you have a client that keys on that string (logs, allowlists, permission policies), update it accordingly.
115
+
116
+ All tool names and schemas are unchanged.
117
+
118
+ ## Installation
119
+
120
+ ### Prerequisites
121
+
122
+ | Requirement | Version | Notes |
123
+ |-------------|---------|-------|
124
+ | Node.js | 22.x+ | LTS required |
125
+ | npm | 10+ | Comes with Node.js |
126
+ | Chromium | Latest | Auto-installed by Playwright |
127
+ | Audio output | Any | Required for playback (speakers/headphones) |
128
+
129
+ **Optional:** Docker for containerized deployment.
130
+
131
+ ### From npm
132
+ ```bash
133
+ npm install -g @williamzujkowski/live-coding-music-mcp
134
+
135
+ # Install browser (required once)
136
+ npx playwright install chromium
137
+ ```
138
+
139
+ ### From Source
140
+ ```bash
141
+ # Clone repository
142
+ git clone https://github.com/williamzujkowski/live-coding-music-mcp.git
143
+ cd live-coding-music-mcp
144
+
145
+ # Install dependencies
146
+ npm install
147
+
148
+ # Install Chromium for browser automation
149
+ npx playwright install chromium
150
+
151
+ # Build the project
152
+ npm run build
153
+ ```
154
+
155
+ ## Quick Reference
156
+
157
+ Common commands for immediate use:
158
+
159
+ | Action | Command |
160
+ |--------|---------|
161
+ | Initialize browser | `init` |
162
+ | Create techno beat | `generate_pattern` with `style: "techno"` |
163
+ | Play pattern | `play` |
164
+ | Stop playback | `stop` |
165
+ | Get current pattern | `get_pattern` |
166
+ | Analyze audio | `analyze` |
167
+ | Save pattern | `save` with `name: "my-pattern"` |
168
+ | Undo last change | `undo` |
169
+
170
+ **One-shot workflow:**
171
+ ```
172
+ compose with style: "dnb", key: "Am", bpm: 174, auto_play: true
173
+ ```
174
+
175
+ ## Quick Start
176
+
177
+ ### 1. Add to Claude
178
+ ```bash
179
+ # If installed globally
180
+ claude mcp add strudel live-coding-music-mcp
181
+
182
+ # If built from source
183
+ claude mcp add strudel node /path/to/live-coding-music-mcp/dist/index.js
184
+ ```
185
+
186
+ ### 2. Start Using
187
+ ```bash
188
+ claude chat
189
+ ```
190
+
191
+ Then ask Claude:
192
+ - "Initialize Strudel and create a techno beat"
193
+ - "Generate a jazz chord progression in F major"
194
+ - "Create a drum & bass pattern at 174 BPM"
195
+
196
+ ## Available Tools
197
+
198
+ <!-- TOOLS:START -->
199
+
200
+ **66 tools** across 15 categories:
201
+
202
+ <details><summary><strong>Setup</strong> (1)</summary>
203
+
204
+ | Tool | Description |
205
+ |------|-------------|
206
+ | `init` | Initialize Strudel in browser |
207
+
208
+ </details>
209
+
210
+ <details><summary><strong>Pattern Editing</strong> (5)</summary>
211
+
212
+ | Tool | Description |
213
+ |------|-------------|
214
+ | `write` | Write pattern to editor with optional auto-play and validation |
215
+ | `append` | Append code to current pattern |
216
+ | `insert` | Insert code at specific line |
217
+ | `replace` | Replace pattern section |
218
+ | `get_pattern` | Get current pattern code |
219
+
220
+ </details>
221
+
222
+ <details><summary><strong>Playback</strong> (6)</summary>
223
+
224
+ | Tool | Description |
225
+ |------|-------------|
226
+ | `status` | Get current browser and playback status (quick state check) |
227
+ | `clear` | Clear the editor |
228
+ | `play` | Start playing pattern |
229
+ | `pause` | Pause playback |
230
+ | `stop` | Stop playback |
231
+ | `set_tempo` | Set BPM |
232
+
233
+ </details>
234
+
235
+ <details><summary><strong>Storage</strong> (3)</summary>
236
+
237
+ | Tool | Description |
238
+ |------|-------------|
239
+ | `save` | Save pattern with metadata |
240
+ | `load` | Load saved pattern |
241
+ | `list` | List saved patterns |
242
+
243
+ </details>
244
+
245
+ <details><summary><strong>History</strong> (4)</summary>
246
+
247
+ | Tool | Description |
248
+ |------|-------------|
249
+ | `undo` | Undo last action |
250
+ | `redo` | Redo action |
251
+ | `list_history` | List recent pattern history with timestamps and previews |
252
+ | `restore_history` | Restore a previous pattern from history by ID |
253
+
254
+ </details>
255
+
256
+ <details><summary><strong>Generation</strong> (8)</summary>
257
+
258
+ | Tool | Description |
259
+ |------|-------------|
260
+ | `compose` | Generate, write, and play a complete pattern in one step. Auto-initializes browser if needed. |
261
+ | `generate_pattern` | Generate complete pattern from style with optional auto-play |
262
+ | `generate_drums` | Generate drum pattern |
263
+ | `generate_bassline` | Generate bassline |
264
+ | `generate_melody` | Generate melody from scale |
265
+ | `generate_polyrhythm` | Generate polyrhythm |
266
+ | `generate_fill` | Generate drum fill |
267
+ | `generate_variation` | Create pattern variations |
268
+
269
+ </details>
270
+
271
+ <details><summary><strong>Music Theory</strong> (4)</summary>
272
+
273
+ | Tool | Description |
274
+ |------|-------------|
275
+ | `generate_scale` | Generate scale notes |
276
+ | `generate_chord_progression` | Generate chord progression |
277
+ | `generate_euclidean` | Generate Euclidean rhythm |
278
+ | `apply_scale` | Apply scale to notes |
279
+
280
+ </details>
281
+
282
+ <details><summary><strong>Transform</strong> (9)</summary>
283
+
284
+ | Tool | Description |
285
+ |------|-------------|
286
+ | `transpose` | Transpose notes by semitones |
287
+ | `reverse` | Reverse pattern |
288
+ | `stretch` | Time stretch pattern |
289
+ | `quantize` | Quantize to grid |
290
+ | `humanize` | Add human timing variation |
291
+ | `add_effect` | Add effect to pattern |
292
+ | `remove_effect` | Remove effect |
293
+ | `add_swing` | Add swing to pattern |
294
+ | `set_energy` | Adjust the overall energy level of the current pattern on a 0-10 scale. 0: minimal/ambient, 1-2: sparse, 3-4: light/relaxed, 5-6: normal/moderate, 7-8: driving/intense, 9-10: maximum. Auto-plays after applying energy level. |
295
+
296
+ </details>
297
+
298
+ <details><summary><strong>AI</strong> (4)</summary>
299
+
300
+ | Tool | Description |
301
+ |------|-------------|
302
+ | `get_pattern_feedback` | Get AI-powered creative feedback on the current pattern using Google Gemini. Analyzes pattern structure and optionally audio. |
303
+ | `jam_with` | AI generates a complementary layer to jam with your pattern. Analyzes current pattern to detect tempo, key, and existing layers, then generates a matching layer that fits musically. |
304
+ | `shift_mood` | Transform current pattern to match a different emotional mood by adjusting tempo, effects, and note choices. Moods: dark, euphoric, melancholic, aggressive, dreamy, peaceful, energetic. |
305
+ | `refine` | Incrementally refine the current pattern with simple directional commands. Supports: faster/slower (tempo), louder/quieter (gain), brighter/darker (filter cutoff), "more reverb"/drier (reverb). Auto-plays after applying refinement. |
306
+
307
+ </details>
308
+
309
+ <details><summary><strong>Analysis</strong> (7)</summary>
310
+
311
+ | Tool | Description |
312
+ |------|-------------|
313
+ | `analyze` | Complete audio analysis |
314
+ | `analyze_spectrum` | FFT spectrum analysis |
315
+ | `analyze_rhythm` | Rhythm analysis |
316
+ | `detect_tempo` | BPM detection |
317
+ | `detect_key` | Key detection |
318
+ | `validate_pattern_runtime` | Validate pattern with runtime error checking (monitors Strudel console for errors) |
319
+ | `compare_patterns` | Compare two patterns from history showing differences |
320
+
321
+ </details>
322
+
323
+ <details><summary><strong>Session</strong> (4)</summary>
324
+
325
+ | Tool | Description |
326
+ |------|-------------|
327
+ | `create_session` | Create a new isolated Strudel browser session. Sessions share one browser but have isolated contexts. |
328
+ | `destroy_session` | Close and destroy a Strudel session, releasing its resources. |
329
+ | `list_sessions` | List all active Strudel sessions with their metadata. |
330
+ | `switch_session` | Change the default session used by other tools. |
331
+
332
+ </details>
333
+
334
+ <details><summary><strong>Export</strong> (2)</summary>
335
+
336
+ | Tool | Description |
337
+ |------|-------------|
338
+ | `export_midi` | Export current pattern to MIDI file. Parses note(), n(), and chord() functions. |
339
+ | `screenshot` | Take a screenshot of the current Strudel editor state |
340
+
341
+ </details>
342
+
343
+ <details><summary><strong>Audio</strong> (3)</summary>
344
+
345
+ | Tool | Description |
346
+ |------|-------------|
347
+ | `start_audio_capture` | Start capturing audio from Strudel output. Audio must be playing for capture to work. |
348
+ | `stop_audio_capture` | Stop audio capture and return the recorded audio as base64-encoded data. |
349
+ | `capture_audio_sample` | Capture a fixed-duration audio sample from Strudel output. Audio must be playing. |
350
+
351
+ </details>
352
+
353
+ <details><summary><strong>Debug</strong> (5)</summary>
354
+
355
+ | Tool | Description |
356
+ |------|-------------|
357
+ | `show_browser` | Bring browser window to foreground for visual feedback |
358
+ | `performance_report` | Get performance metrics and bottlenecks |
359
+ | `memory_usage` | Get current memory usage statistics |
360
+ | `diagnostics` | Get detailed browser diagnostics including cache, errors, and performance |
361
+ | `show_errors` | Display captured console errors and warnings from Strudel |
362
+
363
+ </details>
364
+
365
+ <details><summary><strong>Other</strong> (1)</summary>
366
+
367
+ | Tool | Description |
368
+ |------|-------------|
369
+ | `suggest_pattern_from_audio` | Analyze the currently playing audio and suggest a complementary Strudel pattern using Gemini AI. Extracts tempo, key, and spectral features locally, then uses AI to generate a matching pattern. Returns pattern text (not auto-executed). |
370
+
371
+ </details>
372
+
373
+ _Auto-generated from source. 66 tools registered._
374
+
375
+ <!-- TOOLS:END -->
376
+
377
+ ## Usage Examples
378
+
379
+ ### Basic Pattern Creation
380
+
381
+ **Create a Simple Beat**
382
+ ```
383
+ You: Initialize Strudel and create a simple techno beat
384
+
385
+ Claude: [Initializes browser]
386
+ [Generates and writes pattern]
387
+ [Starts playback]
388
+
389
+ Pattern created:
390
+ setcpm(130)
391
+ stack(
392
+ s("bd*4"),
393
+ s("~ cp ~ cp"),
394
+ s("hh*8").gain(0.4)
395
+ ).gain(0.8)
396
+ ```
397
+
398
+ **Generate a Bassline**
399
+ ```
400
+ You: Add a techno bassline in C
401
+
402
+ Claude: [Generates bassline]
403
+ [Appends to current pattern]
404
+
405
+ Added: note("c2 c2 c2 c2").s("sawtooth").cutoff(800)
406
+ ```
407
+
408
+ ### Advanced Music Generation
409
+
410
+ **Jazz Composition**
411
+ ```
412
+ You: Create a jazz progression in F major with a walking bass
413
+
414
+ Claude: Generated progression: "Gm7" "C7" "Fmaj7"
415
+
416
+ Pattern:
417
+ stack(
418
+ note("Gm7" "C7" "Fmaj7").struct("1 ~ ~ ~").s("piano"),
419
+ note("g2 c2 f2").s("sine").gain(0.7)
420
+ )
421
+ ```
422
+
423
+ **Drum & Bass Track**
424
+ ```
425
+ You: Generate a complete drum & bass track at 174 BPM
426
+
427
+ Claude: [Creates multi-layer pattern with drums, bass, and pads]
428
+
429
+ // dnb pattern in C at 174 BPM
430
+ setcpm(174)
431
+ stack(
432
+ // Drums
433
+ s("bd ~ ~ [bd bd] ~ ~ bd ~, ~ ~ cp ~ ~ cp ~ ~").fast(2),
434
+
435
+ // Bass
436
+ note("c1 ~ ~ c2 ~ c1 ~ ~").s("square").cutoff(400),
437
+
438
+ // Pads (atmospheric)
439
+ note("c3 eb3 g3 bb3").s("sawtooth")
440
+ .attack(2).release(4).room(0.8).gain(0.6)
441
+ )
442
+ ```
443
+
444
+ ### Real-Time Manipulation
445
+
446
+ **Live Audio Analysis**
447
+ ```
448
+ You: Analyze what's playing and show me the frequency breakdown
449
+
450
+ Claude: Audio Analysis Results:
451
+ {
452
+ "connected": true,
453
+ "features": {
454
+ "average": 78.5,
455
+ "peak": 180,
456
+ "peakFrequency": 120,
457
+ "bass": 145,
458
+ "mid": 82,
459
+ "treble": 45,
460
+ "isPlaying": true,
461
+ "brightness": "balanced"
462
+ }
463
+ }
464
+
465
+ Strong bass presence detected - typical for techno/house patterns.
466
+ ```
467
+
468
+ **Pattern Variations**
469
+ ```
470
+ You: Create a glitchy variation of the current pattern
471
+
472
+ Claude: [Applies glitch transformation]
473
+
474
+ Added: .sometimes(x => x.chop(8).rev).rarely(x => x.speed(-1))
475
+ ```
476
+
477
+ ### Multi-Track Composition
478
+
479
+ **Layered Ambient Track**
480
+ ```
481
+ You: Create an ambient soundscape with multiple layers
482
+
483
+ Claude: [Generates complex multi-layer pattern]
484
+
485
+ setcpm(90)
486
+ stack(
487
+ // Deep bass drone
488
+ note("c1").s("sine").attack(4).release(8).gain(0.5),
489
+
490
+ // Texture pad
491
+ note("c3 eb3 g3").s("sawtooth")
492
+ .attack(2).release(6).room(0.9).gain(0.4),
493
+
494
+ // Sparse percussion
495
+ s("bd ~ ~ ~, ~ ~ ~ hh:8").room(0.9).gain(0.3),
496
+
497
+ // Melodic sparkles
498
+ note("c5 g5 eb5 bb5").struct("~ 1 ~ 1 ~ ~ 1 ~")
499
+ .s("triangle").delay(0.5).room(0.8).gain(0.3)
500
+ )
501
+ ```
502
+
503
+ ### Session Management
504
+
505
+ **Save and Load Patterns**
506
+ ```
507
+ You: Save this pattern as "techno-groove-1" with tags "techno" and "experimental"
508
+
509
+ Claude: Pattern saved as "techno-groove-1"
510
+
511
+ ---
512
+
513
+ You: List all my techno patterns
514
+
515
+ Claude: Saved patterns with tag "techno":
516
+ • techno-groove-1 [techno, experimental] - 2025-10-23T19:30:00.000Z
517
+ • acid-bassline [techno, acid] - 2025-10-23T18:15:00.000Z
518
+
519
+ ---
520
+
521
+ You: Load "acid-bassline"
522
+
523
+ Claude: Loaded pattern "acid-bassline"
524
+ [Pattern written to editor]
525
+ ```
526
+
527
+ ### Music Theory Applications
528
+
529
+ **Generate Euclidean Rhythms**
530
+ ```
531
+ You: Create a 5/8 euclidean rhythm with kick drum
532
+
533
+ Claude: Generated Euclidean rhythm (5/8)
534
+
535
+ Pattern: s("bd").struct("1 ~ 1 ~ 1 1 ~ 1")
536
+ ```
537
+
538
+ **Complex Polyrhythms**
539
+ ```
540
+ You: Generate a polyrhythm with kick (4/16), snare (7/16), and hi-hat (3/16)
541
+
542
+ Claude: Generated polyrhythm
543
+
544
+ stack(
545
+ s("bd").euclid(4, 16),
546
+ s("cp").euclid(7, 16),
547
+ s("hh").euclid(3, 16)
548
+ )
549
+ ```
550
+
551
+ ### Integration with LLM Agents
552
+
553
+ **AI-Assisted Composition**
554
+ ```
555
+ You: Analyze the mood of my current pattern and suggest complementary elements
556
+
557
+ Claude: [Analyzes pattern structure and audio features]
558
+
559
+ Your pattern has:
560
+ - Energetic rhythm (130 BPM)
561
+ - Strong bass presence
562
+ - Minimal melodic content
563
+
564
+ Suggestions:
565
+ 1. Add arpeggiated synth for movement
566
+ 2. Include occasional breaks/fills
567
+ 3. Layer atmospheric pad for depth
568
+
569
+ Would you like me to add any of these?
570
+
571
+ You: Add an arpeggiated synth in C minor
572
+
573
+ Claude: [Generates and adds]
574
+
575
+ note("c4 eb4 g4 bb4 c5").struct("1 1 1 1 1 1 1 1")
576
+ .s("triangle").delay(0.25).room(0.3).gain(0.5)
577
+ ```
578
+
579
+ ## Testing
580
+
581
+ All tools have been tested with real Strudel.cc interaction:
582
+
583
+ ```bash
584
+ # Run integration tests
585
+ npm run test:integration
586
+
587
+ # Run browser tests
588
+ node tests/strudel-integration.js
589
+
590
+ # Run npm test to see current pass/fail/skip counts
591
+ ```
592
+
593
+ ## Configuration
594
+
595
+ ### config.json
596
+ ```json
597
+ {
598
+ "headless": false, // Set true for background operation
599
+ "strudel_url": "https://strudel.cc/",
600
+ "patterns_dir": "./patterns",
601
+ "audio_analysis": {
602
+ "fft_size": 2048,
603
+ "smoothing": 0.8
604
+ }
605
+ }
606
+ ```
607
+
608
+ ## Architecture
609
+
610
+ ### System Overview
611
+
612
+ The Strudel MCP Server is built with a modular architecture that separates concerns and enables robust music generation:
613
+
614
+ ```
615
+ ┌─────────────────────────────────────────────────────────────┐
616
+ │ Claude AI │
617
+ │ (MCP Client) │
618
+ └───────────────────────┬─────────────────────────────────────┘
619
+ │ MCP Protocol (stdio)
620
+ │
621
+ ┌───────────────────────▼─────────────────────────────────────┐
622
+ │ StrudelMCPServer │
623
+ │ ┌────────────────────────────────────────────────────────┐ │
624
+ │ │ Tool Request Handler │ │
625
+ │ │ - Validates inputs │ │
626
+ │ │ - Routes to appropriate service │ │
627
+ │ │ - Handles errors gracefully │ │
628
+ │ └────────────────────────────────────────────────────────┘ │
629
+ └───────┬────────────┬────────────┬───────────┬──────────────┘
630
+ │ │ │ │
631
+ ┌────▼────┐ ┌───▼────┐ ┌───▼────┐ ┌──▼──────┐
632
+ │ Strudel │ │ Music │ │Pattern │ │ Pattern │
633
+ │Controller│ │ Theory │ │Generator│ │ Store │
634
+ └────┬────┘ └────────┘ └────────┘ └─────────┘
635
+ │
636
+ ┌────▼────────────────────────────┐
637
+ │ Playwright Browser │
638
+ │ ┌──────────────────────────┐ │
639
+ │ │ Strudel.cc Website │ │
640
+ │ │ ┌────────────────────┐ │ │
641
+ │ │ │ CodeMirror Editor │ │ │
642
+ │ │ └────────────────────┘ │ │
643
+ │ │ ┌────────────────────┐ │ │
644
+ │ │ │ Audio Context │ │ │
645
+ │ │ │ + Web Audio API │ │ │
646
+ │ │ └────────┬───────────┘ │ │
647
+ │ └───────────┼──────────────┘ │
648
+ └──────────────┼──────────────────┘
649
+ │
650
+ ┌───────▼────────┐
651
+ │ Audio Analyzer │
652
+ │ - FFT Analysis│
653
+ │ - Frequency │
654
+ │ - Spectral │
655
+ └────────────────┘
656
+ ```
657
+
658
+ ### Core Components
659
+
660
+ #### 1. **StrudelMCPServer** (`src/server/server.ts`)
661
+
662
+ Main MCP server implementation handling:
663
+ - **65 Tool Definitions**: Complete API surface for music control
664
+ - **Request Routing**: Directs tool calls to appropriate handlers
665
+ - **State Management**: Tracks initialization, undo/redo stacks, pattern cache
666
+ - **Error Handling**: Graceful degradation and informative error messages
667
+ - **Lazy Initialization**: Browser starts only when needed
668
+
669
+ Key Features:
670
+ ```typescript
671
+ - Pattern caching before browser init
672
+ - Undo/redo stack management
673
+ - Session history tracking
674
+ - Generated pattern storage
675
+ - Safe fallback mechanisms
676
+ ```
677
+
678
+ #### 2. **StrudelController** (`src/StrudelController.ts`)
679
+
680
+ Browser automation layer using Playwright:
681
+ - **Browser Management**: Chromium instance lifecycle
682
+ - **Editor Control**: CodeMirror manipulation via DOM
683
+ - **Playback Control**: Keyboard shortcuts for play/stop
684
+ - **Performance Optimizations**:
685
+ - Editor content caching (100ms TTL)
686
+ - Direct CodeMirror API access
687
+ - Resource blocking (images, fonts)
688
+ - Fast DOM content loading
689
+
690
+ ```typescript
691
+ // Example: Optimized pattern writing
692
+ async writePattern(pattern: string) {
693
+ await this.page.evaluate((newPattern) => {
694
+ const editor = document.querySelector('.cm-content');
695
+ const view = editor.__view;
696
+ view.dispatch({
697
+ changes: { from: 0, to: view.state.doc.length, insert: newPattern }
698
+ });
699
+ }, pattern);
700
+ }
701
+ ```
702
+
703
+ #### 3. **AudioAnalyzer** (`src/AudioAnalyzer.ts`)
704
+
705
+ Real-time audio analysis via Web Audio API injection:
706
+ - **FFT Analysis**: 1024-point FFT for spectral data
707
+ - **Frequency Bands**: Bass, low-mid, mid, high-mid, treble
708
+ - **Analysis Caching**: 50ms TTL for performance
709
+ - **Features Extracted**:
710
+ - Average amplitude
711
+ - Peak frequency
712
+ - Spectral centroid
713
+ - Playing state detection
714
+ - Frequency distribution
715
+
716
+ ```typescript
717
+ Features provided:
718
+ - average: Overall amplitude (0-255)
719
+ - peak: Maximum amplitude
720
+ - peakFrequency: Dominant frequency in Hz
721
+ - bass/mid/treble: Band-specific amplitudes
722
+ - brightness: Timbral classification
723
+ - isPlaying: Boolean playback state
724
+ ```
725
+
726
+ #### 4. **MusicTheory** (`src/services/MusicTheory.ts`)
727
+
728
+ Music theory engine providing:
729
+ - **15+ Scales**: Major, minor, modes, pentatonic, blues, whole-tone
730
+ - **Chord Progressions**: Pop, jazz, blues, rock, folk, EDM
731
+ - **Euclidean Rhythms**: Mathematical rhythm generation
732
+ - **Arpeggio Generation**: Multiple patterns (up, down, random)
733
+ - **Note Transposition**: Semitone-based pitch shifting
734
+
735
+ Supported scales:
736
+ ```typescript
737
+ major, minor, dorian, phrygian, lydian, mixolydian,
738
+ aeolian, locrian, pentatonic, blues, chromatic,
739
+ wholetone, harmonic_minor, melodic_minor
740
+ ```
741
+
742
+ #### 5. **PatternGenerator** (`src/services/PatternGenerator.ts`)
743
+
744
+ AI-powered pattern creation:
745
+ - **Genre Templates**: Techno, house, DnB, trap, ambient, jazz, intelligent_dnb, trip_hop, boom_bap
746
+ - **Drum Patterns**: 4 complexity levels per genre
747
+ - **Basslines**: 8 different styles
748
+ - **Melody Generation**: Scale-based with musical intervals
749
+ - **Variations**: Subtle, moderate, extreme, glitch, evolving
750
+ - **Fills**: 1-4 bar drum fills
751
+
752
+ Example generation:
753
+ ```typescript
754
+ generateCompletePattern('techno', 'C', 130)
755
+ → Multi-layer pattern with drums, bass, chords, melody
756
+ ```
757
+
758
+ #### 6. **PatternStore** (`src/PatternStore.ts`)
759
+
760
+ Persistent pattern storage:
761
+ - **JSON-based**: Simple file storage
762
+ - **Metadata**: Name, tags, timestamp, audio features
763
+ - **Tag Filtering**: Organize by genre, mood, project
764
+ - **Sorted Retrieval**: Most recent first
765
+
766
+ ### Directory Structure
767
+
768
+ ```
769
+ live-coding-music-mcp/
770
+ ├── src/
771
+ │ ├── server/
772
+ │ │ └── server.ts # MCP server
773
+ │ ├── services/
774
+ │ │ ├── MusicTheory.ts # Theory engine
775
+ │ │ └── PatternGenerator.ts # Pattern creation
776
+ │ ├── utils/
777
+ │ │ └── Logger.ts # Logging utility
778
+ │ ├── types/
779
+ │ │ └── index.ts # TypeScript types
780
+ │ ├── StrudelController.ts # Browser automation
781
+ │ ├── AudioAnalyzer.ts # Audio analysis
782
+ │ ├── PatternStore.ts # Pattern persistence
783
+ │ └── index.ts # Entry point
784
+ ├── tests/
785
+ │ ├── browser-test.js # Browser integration
786
+ │ ├── integration.test.js # Integration tests
787
+ │ ├── manual-test.js # Manual testing
788
+ │ ├── mcp-tools.test.ts # MCP tool tests
789
+ │ └── strudel-integration.js # Full integration
790
+ ├── patterns/ # Saved patterns
791
+ ├── config.json # Server configuration
792
+ ├── package.json # Dependencies
793
+ └── tsconfig.json # TypeScript config
794
+ ```
795
+
796
+ ### Data Flow
797
+
798
+ 1. **Tool Invocation**
799
+ ```
800
+ Claude → MCP Protocol → StrudelMCPServer
801
+ ```
802
+
803
+ 2. **Pattern Generation** (without browser)
804
+ ```
805
+ Server → PatternGenerator → MusicTheory → Pattern String
806
+ ```
807
+
808
+ 3. **Pattern Execution** (with browser)
809
+ ```
810
+ Server → StrudelController → Playwright → Strudel.cc
811
+ ```
812
+
813
+ 4. **Audio Analysis**
814
+ ```
815
+ Strudel.cc → Web Audio API → AudioAnalyzer → Feature Data
816
+ ```
817
+
818
+ ### Performance Characteristics
819
+
820
+ | Operation | Latency | Notes |
821
+ |-----------|---------|-------|
822
+ | Pattern Generation | <100ms | Pure computation |
823
+ | Browser Init | ~3s | One-time cost |
824
+ | Pattern Write | ~50ms | With caching |
825
+ | Play/Stop | ~100ms | Keyboard shortcuts |
826
+ | Audio Analysis | ~20ms | With 50ms cache |
827
+ | Pattern Save | ~10ms | File I/O |
828
+
829
+ ### Optimization Strategies
830
+
831
+ 1. **Caching**
832
+ - Editor content: 100ms TTL
833
+ - Audio analysis: 50ms TTL
834
+ - Generated patterns: Until browser init
835
+
836
+ 2. **Resource Blocking**
837
+ - Images, fonts, media blocked
838
+ - Only load essential JavaScript/CSS
839
+
840
+ 3. **Direct API Access**
841
+ - CodeMirror view manipulation
842
+ - Keyboard shortcuts over button clicks
843
+
844
+ 4. **Lazy Loading**
845
+ - Browser starts only when needed
846
+ - Services initialized on-demand
847
+
848
+ ## Pattern Examples
849
+
850
+ ### Minimal Techno (Verified Working)
851
+ ```javascript
852
+ setcpm(130)
853
+ stack(
854
+ s("bd*4").gain(0.9),
855
+ s("~ cp ~ cp").room(0.2),
856
+ s("hh*16").gain(0.4).pan(sine.range(-0.5, 0.5)),
857
+ note("c2 c2 eb2 c2").s("sawtooth").cutoff(800)
858
+ ).swing(0.05)
859
+ ```
860
+
861
+ ### Drum & Bass (Verified Working)
862
+ ```javascript
863
+ setcpm(174)
864
+ stack(
865
+ s("bd ~ ~ [bd bd] ~ ~ bd ~, ~ ~ sn:3 ~ ~ sn:3 ~ ~").fast(2),
866
+ s("hh*16").gain(0.5),
867
+ note("e1 ~ ~ e2 ~ e1 ~ ~").s("sine:2").lpf(200)
868
+ )
869
+ ```
870
+
871
+ ### Generated Jazz Progression
872
+ ```javascript
873
+ // Jazz ii-V-I in F
874
+ stack(
875
+ note("Gm7" "C7" "Fmaj7").struct("1 ~ ~ ~").s("piano"),
876
+ note("g2 c2 f2").s("sine").gain(0.7)
877
+ )
878
+ ```
879
+
880
+ ## Docker Support
881
+
882
+ ```bash
883
+ # Build image
884
+ docker build -t live-coding-music-mcp .
885
+
886
+ # Run container
887
+ docker run -it --rm live-coding-music-mcp
888
+
889
+ # Or use docker-compose
890
+ docker-compose up
891
+ ```
892
+
893
+ ## Development
894
+
895
+ ### Setup Development Environment
896
+
897
+ ```bash
898
+ # Clone the repository
899
+ git clone https://github.com/williamzujkowski/live-coding-music-mcp.git
900
+ cd live-coding-music-mcp
901
+
902
+ # Install dependencies
903
+ npm install
904
+
905
+ # Install Playwright browsers
906
+ npx playwright install chromium
907
+
908
+ # Build the project
909
+ npm run build
910
+ ```
911
+
912
+ ### Available Scripts
913
+
914
+ ```bash
915
+ # Development mode with hot reload
916
+ npm run dev
917
+
918
+ # Build TypeScript to dist/
919
+ npm run build
920
+
921
+ # Start production server
922
+ npm start
923
+
924
+ # Run all tests
925
+ npm test
926
+
927
+ # Run integration tests with real browser
928
+ npm run test:integration
929
+
930
+ # Run browser-specific tests
931
+ npm run test:browser
932
+
933
+ # Validate MCP protocol compliance
934
+ npm run validate
935
+
936
+ # Lint code
937
+ npm run lint
938
+
939
+ # Format code
940
+ npm run format
941
+
942
+ # Clean build artifacts
943
+ npm clean
944
+ ```
945
+
946
+ ### Publishing to npm
947
+
948
+ See [NPM_PUBLISHING.md](NPM_PUBLISHING.md) for complete publishing instructions.
949
+
950
+ **Quick publish via GitHub Release:**
951
+ ```bash
952
+ npm version patch # or minor, major
953
+ git push && git push --tags
954
+ gh release create v$(node -p "require('./package.json').version") --generate-notes
955
+ ```
956
+
957
+ The package uses OIDC trusted publishing with provenance attestation for supply chain security.
958
+
959
+ ### Project Structure
960
+
961
+ ```
962
+ src/
963
+ ├── server/
964
+ │ └── server.ts # MCP server
965
+ │
966
+ ├── services/
967
+ │ ├── MusicTheory.ts # Music theory engine
968
+ │ │ - 15+ scales (major, minor, modes, etc.)
969
+ │ │ - Chord progressions (jazz, pop, blues, etc.)
970
+ │ │ - Euclidean rhythm generation
971
+ │ │ - Arpeggio generation
972
+ │ │
973
+ │ └── PatternGenerator.ts # Pattern creation service
974
+ │ - Genre-specific drum patterns
975
+ │ - Bassline generation
976
+ │ - Melody composition
977
+ │ - Pattern variations
978
+ │ - Complete track generation
979
+ │
980
+ ├── utils/
981
+ │ ├── Logger.ts # Logging utility
982
+ │ ├── PerformanceMonitor.ts # Performance tracking
983
+ │ ├── PatternValidator.ts # Pattern syntax validation
984
+ │ └── ErrorRecovery.ts # Error handling & recovery
985
+ │
986
+ ├── types/
987
+ │ └── index.ts # TypeScript type definitions
988
+ │
989
+ ├── StrudelController.ts # Browser automation
990
+ │ - Chromium management via Playwright
991
+ │ - CodeMirror editor manipulation
992
+ │ - Playback control
993
+ │ - Pattern validation
994
+ │ - Error recovery
995
+ │
996
+ ├── AudioAnalyzer.ts # Real-time audio analysis
997
+ │ - Web Audio API injection
998
+ │ - FFT spectral analysis
999
+ │ - Frequency band detection
1000
+ │ - Playing state monitoring
1001
+ │
1002
+ ├── PatternStore.ts # Pattern persistence
1003
+ │ - JSON-based storage
1004
+ │ - Tag-based organization
1005
+ │ - Metadata tracking
1006
+ │ - List caching
1007
+ │
1008
+ └── index.ts # Application entry point
1009
+ ```
1010
+
1011
+ ### Adding New Tools
1012
+
1013
+ To add a new MCP tool:
1014
+
1015
+ 1. **Define the tool** in `getTools()` method:
1016
+ ```typescript
1017
+ {
1018
+ name: 'my_new_tool',
1019
+ description: 'Description of what it does',
1020
+ inputSchema: {
1021
+ type: 'object',
1022
+ properties: {
1023
+ param1: { type: 'string', description: 'Parameter description' },
1024
+ param2: { type: 'number', description: 'Numeric parameter' }
1025
+ },
1026
+ required: ['param1']
1027
+ }
1028
+ }
1029
+ ```
1030
+
1031
+ 2. **Implement the handler** in `executeTool()` switch statement:
1032
+ ```typescript
1033
+ case 'my_new_tool':
1034
+ // Your implementation here
1035
+ return await this.someService.doSomething(args.param1, args.param2);
1036
+ ```
1037
+
1038
+ 3. **Add necessary service methods** if needed:
1039
+ ```typescript
1040
+ // In appropriate service file
1041
+ async doSomething(param1: string, param2?: number): Promise<string> {
1042
+ // Implementation
1043
+ return `Result: ${param1}`;
1044
+ }
1045
+ ```
1046
+
1047
+ 4. **Test the tool**:
1048
+ ```bash
1049
+ # Build
1050
+ npm run build
1051
+
1052
+ # Test via MCP
1053
+ echo '{"jsonrpc":"2.0","method":"tools/call","params":{"name":"my_new_tool","arguments":{"param1":"test"}},"id":2}' | node dist/index.js
1054
+ ```
1055
+
1056
+ ### Testing Strategy
1057
+
1058
+ #### 1. Unit Tests
1059
+ ```bash
1060
+ # Run with Jest
1061
+ npm test
1062
+
1063
+ # Watch mode
1064
+ npm run test:watch
1065
+ ```
1066
+
1067
+ #### 2. Integration Tests
1068
+ ```bash
1069
+ # Full integration with real browser
1070
+ npm run test:integration
1071
+
1072
+ # This tests:
1073
+ # - Browser initialization
1074
+ # - Pattern generation
1075
+ # - Audio analysis
1076
+ # - Pattern storage
1077
+ # - All 65 tools
1078
+ ```
1079
+
1080
+ #### 3. Manual Testing
1081
+ ```bash
1082
+ # Development mode
1083
+ npm run dev
1084
+
1085
+ # In another terminal
1086
+ claude mcp add strudel-dev node $(pwd)/dist/index.js
1087
+ claude chat
1088
+
1089
+ # Then interact with Claude
1090
+ ```
1091
+
1092
+ ### Code Quality
1093
+
1094
+ **TypeScript Configuration**
1095
+ ```json
1096
+ // tsconfig.json
1097
+ {
1098
+ "compilerOptions": {
1099
+ "strict": true, // Strict type checking
1100
+ "esModuleInterop": true, // Better module compatibility
1101
+ "target": "ES2020", // Modern JavaScript
1102
+ "module": "ES2020", // ES modules
1103
+ "moduleResolution": "node"
1104
+ }
1105
+ }
1106
+ ```
1107
+
1108
+ **Linting & Formatting**
1109
+ ```bash
1110
+ # ESLint
1111
+ npm run lint
1112
+
1113
+ # Prettier
1114
+ npm run format
1115
+
1116
+ # Pre-commit hooks recommended
1117
+ ```
1118
+
1119
+ ### Debugging
1120
+
1121
+ **Enable Debug Logging**
1122
+ ```bash
1123
+ # Set DEBUG environment variable
1124
+ DEBUG=strudel:* npm start
1125
+
1126
+ # Or specific modules
1127
+ DEBUG=strudel:controller npm start
1128
+ DEBUG=strudel:audio npm start
1129
+ ```
1130
+
1131
+ **VS Code Launch Configuration**
1132
+ ```json
1133
+ {
1134
+ "type": "node",
1135
+ "request": "launch",
1136
+ "name": "Debug MCP Server",
1137
+ "program": "${workspaceFolder}/dist/index.js",
1138
+ "preLaunchTask": "npm: build",
1139
+ "console": "integratedTerminal",
1140
+ "env": {
1141
+ "DEBUG": "strudel:*"
1142
+ }
1143
+ }
1144
+ ```
1145
+
1146
+ **Playwright Debugging**
1147
+ ```typescript
1148
+ // In StrudelController.ts
1149
+ this.browser = await chromium.launch({
1150
+ headless: false, // See the browser
1151
+ devtools: true, // Open DevTools
1152
+ slowMo: 100 // Slow down actions
1153
+ });
1154
+ ```
1155
+
1156
+ ### Performance Monitoring
1157
+
1158
+ The server includes built-in performance monitoring:
1159
+
1160
+ ```typescript
1161
+ // Access performance metrics
1162
+ You: Show me performance metrics
1163
+
1164
+ Claude: Performance Report:
1165
+ {
1166
+ "averageLatency": {
1167
+ "init": "3.2s",
1168
+ "write": "52ms",
1169
+ "play": "105ms",
1170
+ "analyze": "18ms"
1171
+ },
1172
+ "cacheHitRate": "85%",
1173
+ "totalOperations": 1247,
1174
+ "bottlenecks": [
1175
+ {"tool": "init", "avgTime": 3200, "calls": 1},
1176
+ {"tool": "write", "avgTime": 52, "calls": 156}
1177
+ ]
1178
+ }
1179
+ ```
1180
+
1181
+ ### Contributing Guidelines
1182
+
1183
+ 1. **Fork the repository**
1184
+ ```bash
1185
+ git clone https://github.com/YOUR_USERNAME/live-coding-music-mcp.git
1186
+ ```
1187
+
1188
+ 2. **Create a feature branch**
1189
+ ```bash
1190
+ git checkout -b feature/my-new-feature
1191
+ ```
1192
+
1193
+ 3. **Make your changes**
1194
+ - Follow existing code style
1195
+ - Add tests for new features
1196
+ - Update documentation
1197
+ - Ensure all tests pass
1198
+
1199
+ 4. **Commit with meaningful messages**
1200
+ ```bash
1201
+ git commit -m "feat: Add support for custom scale generation"
1202
+ ```
1203
+
1204
+ Follow [Conventional Commits](https://www.conventionalcommits.org/):
1205
+ - `feat:` New feature
1206
+ - `fix:` Bug fix
1207
+ - `docs:` Documentation changes
1208
+ - `refactor:` Code refactoring
1209
+ - `test:` Adding tests
1210
+ - `chore:` Maintenance tasks
1211
+
1212
+ 5. **Push and create PR**
1213
+ ```bash
1214
+ git push origin feature/my-new-feature
1215
+ ```
1216
+
1217
+ Then create a Pull Request on GitHub with:
1218
+ - Clear description of changes
1219
+ - Link to related issues
1220
+ - Screenshots/examples if relevant
1221
+
1222
+ ### Release Process
1223
+
1224
+ ```bash
1225
+ # 1. Update version in package.json
1226
+ npm version patch # or minor/major
1227
+
1228
+ # 2. Update CHANGELOG.md
1229
+ # Add entry for new version
1230
+
1231
+ # 3. Build and test
1232
+ npm run build
1233
+ npm test
1234
+ npm run test:integration
1235
+
1236
+ # 4. Commit version bump
1237
+ git add .
1238
+ git commit -m "chore: Bump version to X.Y.Z"
1239
+
1240
+ # 5. Create git tag
1241
+ git tag vX.Y.Z
1242
+
1243
+ # 6. Push to GitHub
1244
+ git push origin main --tags
1245
+
1246
+ # 7. Publish to npm (if you have access)
1247
+ npm publish --access public
1248
+
1249
+ # 8. Create GitHub release
1250
+ gh release create vX.Y.Z --generate-notes
1251
+ ```
1252
+
1253
+ ### Docker Development
1254
+
1255
+ ```bash
1256
+ # Build development image
1257
+ docker build -t live-coding-music-mcp:dev .
1258
+
1259
+ # Run with volume mount for hot reload
1260
+ docker run -it --rm \
1261
+ -v $(pwd)/src:/app/src \
1262
+ -v $(pwd)/patterns:/app/patterns \
1263
+ live-coding-music-mcp:dev
1264
+
1265
+ # Run tests in container
1266
+ docker run -it --rm live-coding-music-mcp:dev npm test
1267
+ ```
1268
+
1269
+ ### Environment Variables
1270
+
1271
+ ```bash
1272
+ # Logging level
1273
+ LOG_LEVEL=debug # debug, info, warn, error
1274
+
1275
+ # Performance monitoring
1276
+ ENABLE_PERF_MONITORING=true
1277
+
1278
+ # Pattern storage
1279
+ PATTERNS_DIR=./patterns
1280
+
1281
+ # Browser configuration
1282
+ HEADLESS=false
1283
+ BROWSER_TIMEOUT=15000
1284
+
1285
+ # Audio analysis
1286
+ FFT_SIZE=1024
1287
+ SMOOTHING=0.8
1288
+ ```
1289
+
1290
+ ## Performance
1291
+
1292
+ - **Pattern Generation**: <100ms
1293
+ - **Browser Initialization**: ~3 seconds
1294
+ - **Pattern Writing**: Instant
1295
+ - **Playback Start**: ~500ms
1296
+ - **Audio Analysis**: Real-time
1297
+ - **Memory Usage**: <150MB
1298
+
1299
+ ## Advanced Usage
1300
+
1301
+ ### Custom Music Theory
1302
+
1303
+ **Create Custom Scales**
1304
+ ```typescript
1305
+ // The MusicTheory service supports 15+ built-in scales
1306
+ // You can request any combination:
1307
+
1308
+ You: Generate a lydian scale starting on D
1309
+
1310
+ Claude: D lydian scale: D, E, F#, G#, A, B, C#
1311
+ ```
1312
+
1313
+ **Complex Chord Progressions**
1314
+ ```typescript
1315
+ You: Create a jazz ii-V-I progression in Bb with extended voicings
1316
+
1317
+ Claude: Generated jazz progression in Bb: "Cm7" "F7" "Bbmaj7"
1318
+
1319
+ Pattern:
1320
+ note("Cm7" "F7" "Bbmaj7")
1321
+ .struct("1 ~ ~ ~")
1322
+ .s("sawtooth")
1323
+ .add(note("7")) // Add 7th extensions
1324
+ .room(0.4)
1325
+ ```
1326
+
1327
+ ### Advanced Rhythm Techniques
1328
+
1329
+ **Euclidean Patterns**
1330
+ ```
1331
+ You: Create a complex polyrhythm using euclidean patterns:
1332
+ - Bass drum: 7 hits in 16 steps
1333
+ - Snare: 5 hits in 16 steps
1334
+ - Hi-hat: 11 hits in 16 steps
1335
+
1336
+ Claude: [Generates mathematically perfect polyrhythm]
1337
+
1338
+ stack(
1339
+ s("bd").euclid(7, 16),
1340
+ s("cp").euclid(5, 16),
1341
+ s("hh").euclid(11, 16)
1342
+ )
1343
+ ```
1344
+
1345
+ **Generative Variations**
1346
+ ```
1347
+ You: Create 3 variations of my current pattern: subtle, moderate, and glitchy
1348
+
1349
+ Claude: [Generates three variants]
1350
+
1351
+ Version 1 (subtle):
1352
+ original.sometimes(x => x.fast(2))
1353
+
1354
+ Version 2 (moderate):
1355
+ original.every(4, x => x.rev).sometimes(x => x.fast(2))
1356
+
1357
+ Version 3 (glitchy):
1358
+ original.sometimes(x => x.chop(8).rev).rarely(x => x.speed(-1))
1359
+ ```
1360
+
1361
+ ### Performance Optimization Tips
1362
+
1363
+ **Pattern Caching**
1364
+ ```
1365
+ // The server caches patterns intelligently:
1366
+ // - Generated patterns stored before browser init
1367
+ // - Editor content cached for 100ms
1368
+ // - Audio analysis cached for 50ms
1369
+
1370
+ // For fastest performance:
1371
+ 1. Generate patterns before initializing browser
1372
+ 2. Initialize once and reuse the session
1373
+ 3. Batch multiple changes together
1374
+ ```
1375
+
1376
+ **Headless Mode**
1377
+ ```json
1378
+ // In config.json:
1379
+ {
1380
+ "headless": true, // Faster, no GUI
1381
+ "strudel_url": "https://strudel.cc/",
1382
+ "patterns_dir": "./patterns"
1383
+ }
1384
+ ```
1385
+
1386
+ ### Integration Patterns
1387
+
1388
+ **Workflow Automation**
1389
+ ```
1390
+ You: Create a complete track:
1391
+ 1. Start with techno drums at 130 BPM
1392
+ 2. Add acid bassline in E
1393
+ 3. Layer ambient pads
1394
+ 4. Save as "track-001" with tags "techno", "acid", "experimental"
1395
+
1396
+ Claude: [Executes full workflow]
1397
+ [Initializes browser]
1398
+ [Generates drum pattern]
1399
+ [Adds bassline]
1400
+ [Layers pads]
1401
+ [Saves with metadata]
1402
+
1403
+ Complete! Pattern saved as "track-001"
1404
+ ```
1405
+
1406
+ **Audio-Reactive Composition**
1407
+ ```
1408
+ You: Monitor the audio and suggest adjustments based on frequency balance
1409
+
1410
+ Claude: [Analyzes current playback]
1411
+
1412
+ Analysis shows:
1413
+ - Bass: 180 (strong)
1414
+ - Mid: 45 (weak)
1415
+ - Treble: 30 (weak)
1416
+
1417
+ Recommendations:
1418
+ 1. Reduce bass gain by 20%
1419
+ 2. Add mid-range melodic content
1420
+ 3. Include hi-hat pattern for treble
1421
+
1422
+ Apply changes? [Yes/No]
1423
+ ```
1424
+
1425
+ ### Advanced Pattern Manipulation
1426
+
1427
+ **Dynamic Transformations**
1428
+ ```
1429
+ You: Apply these transformations in sequence:
1430
+ 1. Transpose up 3 semitones
1431
+ 2. Add 10% humanization
1432
+ 3. Apply reverb with 0.6 room size
1433
+ 4. Every 4th cycle, reverse the pattern
1434
+
1435
+ Claude: [Applies transformations]
1436
+
1437
+ Final pattern:
1438
+ [original]
1439
+ .transpose(3)
1440
+ .nudge(rand.range(-0.1, 0.1))
1441
+ .room(0.6)
1442
+ .every(4, x => x.rev)
1443
+ ```
1444
+
1445
+ **Conditional Logic**
1446
+ ```
1447
+ You: Create a pattern that evolves:
1448
+ - Bars 1-4: Simple kick pattern
1449
+ - Bars 5-8: Add snare
1450
+ - Bars 9-16: Add full drum kit
1451
+ - Then loop with variations
1452
+
1453
+ Claude: [Generates evolving pattern]
1454
+
1455
+ s("bd*4")
1456
+ .struct("1 ~ ~ ~")
1457
+ .mask("<1 1 1 1 0 0 0 0>/4") // First 4 bars
1458
+ .stack(
1459
+ s("~ cp ~ cp")
1460
+ .mask("<0 0 0 0 1 1 1 1>/8") // Bars 5-8
1461
+ )
1462
+ // Full complexity from bar 9
1463
+ .every(8, x => x.sometimes(y => y.fast(2)))
1464
+ ```
1465
+
1466
+ ## 🔒 Security
1467
+
1468
+ ### Pattern Validation
1469
+
1470
+ All patterns are validated before execution:
1471
+ - **Dangerous gain levels** (>2.0) are flagged
1472
+ - **Eval blocks** are rejected
1473
+ - **Path traversal** attacks are blocked in PatternStore
1474
+
1475
+ ### Browser Sandboxing
1476
+
1477
+ - Playwright runs Chromium in sandbox mode
1478
+ - No access to local filesystem from browser context
1479
+ - Resource blocking prevents loading external content
1480
+
1481
+ ### Known Limitations
1482
+
1483
+ - **No authentication**: The MCP server trusts all incoming requests
1484
+ - **Local only**: Designed for local development, not network deployment
1485
+ - **Pattern execution**: Patterns execute in browser context with audio access
1486
+
1487
+ ### Reporting Security Issues
1488
+
1489
+ Found a vulnerability? Please [open a security issue](https://github.com/williamzujkowski/live-coding-music-mcp/security/advisories/new) or email the maintainer directly. Do not disclose publicly until patched.
1490
+
1491
+ ## 🐛 Troubleshooting
1492
+
1493
+ ### Common Issues
1494
+
1495
+ #### Browser doesn't open
1496
+ **Symptom**: `Error: Browser not initialized` or Chromium launch fails
1497
+
1498
+ **Solutions**:
1499
+ ```bash
1500
+ # Install Chromium for Playwright
1501
+ npx playwright install chromium
1502
+
1503
+ # If that fails, try installing all browsers
1504
+ npx playwright install
1505
+
1506
+ # Check Playwright installation
1507
+ npx playwright --version
1508
+
1509
+ # For Linux, install dependencies
1510
+ sudo npx playwright install-deps chromium
1511
+ ```
1512
+
1513
+ #### Audio analysis returns "not connected"
1514
+ **Symptom**: Audio analysis shows `connected: false`
1515
+
1516
+ **Solutions**:
1517
+ 1. Ensure pattern is playing first:
1518
+ ```
1519
+ You: Play the pattern, wait 2 seconds, then analyze
1520
+ ```
1521
+
1522
+ 2. Reinitialize the browser:
1523
+ ```
1524
+ You: Stop, close the browser, reinitialize, and try again
1525
+ ```
1526
+
1527
+ 3. Check audio context activation:
1528
+ - Audio contexts require user interaction on some systems
1529
+ - The browser window must be visible (not headless) for first run
1530
+
1531
+ #### Pattern syntax errors
1532
+ **Symptom**: Pattern doesn't play or shows errors in console
1533
+
1534
+ **Solutions**:
1535
+ ```
1536
+ Common issues:
1537
+ 1. Missing quotes: s(bd*4) → s("bd*4")
1538
+ 2. Unmatched parentheses: stack(s("bd")) → stack(s("bd")))
1539
+ 3. Invalid note names: note("h2") → note("c2")
1540
+
1541
+ Test with minimal pattern first:
1542
+ s("bd*4")
1543
+
1544
+ Then build complexity gradually.
1545
+ ```
1546
+
1547
+ #### MCP connection issues
1548
+ **Symptom**: Claude can't find the server or tools
1549
+
1550
+ **Solutions**:
1551
+ ```bash
1552
+ # Verify server is built
1553
+ npm run build
1554
+
1555
+ # Check if server responds
1556
+ echo '{"jsonrpc":"2.0","method":"tools/list","id":1}' | node dist/index.js
1557
+
1558
+ # Should return JSON with 65 tools
1559
+
1560
+ # Reinstall MCP server in Claude
1561
+ claude mcp remove strudel
1562
+ claude mcp add strudel node $(pwd)/dist/index.js
1563
+
1564
+ # Restart Claude
1565
+ claude chat
1566
+ ```
1567
+
1568
+ #### Performance issues / Slow response
1569
+ **Symptom**: Operations take longer than expected
1570
+
1571
+ **Solutions**:
1572
+ 1. **Enable caching** (default, but verify):
1573
+ - Editor caching: 100ms TTL
1574
+ - Audio analysis: 50ms TTL
1575
+
1576
+ 2. **Use headless mode** for faster operation:
1577
+ ```json
1578
+ // config.json
1579
+ { "headless": true }
1580
+ ```
1581
+
1582
+ 3. **Batch operations**:
1583
+ ```
1584
+ Instead of:
1585
+ - Add drums
1586
+ - Add bass
1587
+ - Add melody
1588
+
1589
+ Do:
1590
+ - Generate complete pattern with drums, bass, and melody
1591
+ ```
1592
+
1593
+ 4. **Reduce browser overhead**:
1594
+ - Close other browser instances
1595
+ - Disable browser DevTools
1596
+ - Use resource blocking (enabled by default)
1597
+
1598
+ #### Patterns not saving
1599
+ **Symptom**: `save` command fails or patterns don't persist
1600
+
1601
+ **Solutions**:
1602
+ ```bash
1603
+ # Check patterns directory exists
1604
+ ls -la ./patterns
1605
+
1606
+ # Create manually if needed
1607
+ mkdir -p ./patterns
1608
+
1609
+ # Verify write permissions
1610
+ touch ./patterns/test.json
1611
+ rm ./patterns/test.json
1612
+
1613
+ # Check for invalid pattern names
1614
+ # Valid: "techno-beat-1", "my_pattern", "track001"
1615
+ # Invalid: "pattern/with/slashes", "name:with:colons"
1616
+ ```
1617
+
1618
+ ### Platform-Specific Issues
1619
+
1620
+ #### macOS
1621
+ ```bash
1622
+ # Keyboard shortcut uses Meta (Cmd) key
1623
+ # Already handled by ControlOrMeta
1624
+
1625
+ # If Chromium crashes on M1/M2:
1626
+ npx playwright install chromium --with-deps
1627
+ ```
1628
+
1629
+ #### Linux
1630
+ ```bash
1631
+ # Install system dependencies
1632
+ sudo npx playwright install-deps chromium
1633
+
1634
+ # If running in Docker/headless environment:
1635
+ # Ensure config.json has headless: true
1636
+ ```
1637
+
1638
+ #### Windows
1639
+ ```bash
1640
+ # Use PowerShell or Git Bash
1641
+ # Paths should use forward slashes in config.json
1642
+
1643
+ # If Chromium doesn't launch:
1644
+ npx playwright install chromium
1645
+ ```
1646
+
1647
+ ### Debugging Tips
1648
+
1649
+ **Enable Verbose Logging**
1650
+ ```bash
1651
+ # Set environment variable
1652
+ DEBUG=* node dist/index.js
1653
+
1654
+ # Or in Claude:
1655
+ You: Enable detailed logging for the next operation
1656
+ ```
1657
+
1658
+ **Check Browser State**
1659
+ ```
1660
+ You: Show me the current browser initialization state
1661
+ and any cached patterns
1662
+
1663
+ Claude: Browser state:
1664
+ - Initialized: true
1665
+ - Cached patterns: 2
1666
+ - Undo stack depth: 5
1667
+ - Last operation: write_pattern (2.5s ago)
1668
+ ```
1669
+
1670
+ **Validate Pattern Syntax**
1671
+ ```
1672
+ You: Before playing, validate this pattern syntax:
1673
+ s("bd*4, ~ cp ~ cp")
1674
+
1675
+ Claude: [Checks syntax]
1676
+ Valid Strudel pattern.
1677
+ Ready to play.
1678
+ ```
1679
+
1680
+ ### Getting Help
1681
+
1682
+ If you encounter issues not covered here:
1683
+
1684
+ 1. **Check existing issues**: [GitHub Issues](https://github.com/williamzujkowski/live-coding-music-mcp/issues)
1685
+ 2. **Run integration tests**: `npm run test:integration`
1686
+ 3. **Enable debug mode**: `DEBUG=* npm start`
1687
+ 4. **Consult Strudel docs**: [Strudel.cc documentation](https://strudel.cc/learn)
1688
+ 5. **Create new issue**: Include error messages, OS, Node version, and steps to reproduce
1689
+
1690
+ ## 🤝 Contributing
1691
+
1692
+ **We need your help!** This project is actively developed and welcomes contributions of all kinds:
1693
+
1694
+ ### Ways to Contribute
1695
+ - **Report Bugs**: Found an issue? [Open a bug report](https://github.com/williamzujkowski/live-coding-music-mcp/issues/new)
1696
+ - **Suggest Features**: Have ideas? [Create a feature request](https://github.com/williamzujkowski/live-coding-music-mcp/issues/new)
1697
+ - **Improve Docs**: Fix typos, add examples, clarify confusing sections
1698
+ - **Write Tests**: Help us improve test coverage
1699
+ - **Fix Issues**: Check [open issues](https://github.com/williamzujkowski/live-coding-music-mcp/issues) for bugs to fix
1700
+ - **Add Features**: Implement new tools or improve existing ones
1701
+
1702
+ ### Quick Start for Contributors
1703
+ 1. Fork the repository
1704
+ 2. Create a feature branch (`git checkout -b feature/amazing-feature`)
1705
+ 3. Make your changes and add tests
1706
+ 4. Ensure tests pass (`npm test`)
1707
+ 5. Commit with clear messages (`git commit -m 'fix: resolve audio analysis bug'`)
1708
+ 6. Push to your fork (`git push origin feature/amazing-feature`)
1709
+ 7. Open a Pull Request
1710
+
1711
+ **First time contributor?** Look for issues labeled `good-first-issue` or `help-wanted`.
1712
+
1713
+ ### Feedback Welcome
1714
+ - Questions? Open a [Discussion](https://github.com/williamzujkowski/live-coding-music-mcp/discussions)
1715
+ - Found something confusing? Tell us!
1716
+ - Have a use case we haven't considered? Share it!
1717
+
1718
+ We review PRs promptly and welcome contributors of all skill levels. See [DEVELOPMENT.md](DEVELOPMENT.md) for detailed setup instructions.
1719
+
1720
+ ## 📄 License
1721
+
1722
+ MIT License - see [LICENSE](LICENSE) file
1723
+
1724
+ ## 🙏 Acknowledgments
1725
+
1726
+ - [Strudel.cc](https://strudel.cc) - Amazing live coding environment
1727
+ - [TidalCycles](https://tidalcycles.org) - Pattern language inspiration
1728
+ - [Anthropic](https://anthropic.com) - Claude AI and MCP protocol
1729
+ - [Playwright](https://playwright.dev) - Reliable browser automation
1730
+
1731
+ ---
1732
+
1733
+ **v2.4.0** - Open Source | Experimental | [Report Issues](https://github.com/williamzujkowski/live-coding-music-mcp/issues) | [Contribute](https://github.com/williamzujkowski/live-coding-music-mcp/pulls)
1734
+
1735
+ *This project is under active development. Core features work, but expect bugs and breaking changes. Not recommended for production use.*