get_pattern
Retrieve the current music pattern code from Strudel for live coding, editing, or analysis in TidalCycles/Strudel environments.
Instructions
Get current pattern code
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
No arguments | |||
Implementation Reference
- Handler case in executeTool switch for the 'get_pattern' tool, delegating to getCurrentPatternSafe()case 'get_pattern': return await this.getCurrentPatternSafe();
- src/StrudelController.ts:180-205 (handler)Core handler logic in StrudelController.getCurrentPattern(): reads current pattern from Strudel.cc CodeMirror editor via Playwright, with cachingasync getCurrentPattern(): Promise<string> { if (!this._page) throw new Error('Browser not initialized. Run init tool first.'); // Return cached value if still valid const now = Date.now(); if (this.editorCache && (now - this.cacheTimestamp) < this.CACHE_TTL) { return this.editorCache; } const pattern = await this._page.evaluate(() => { const editor = document.querySelector('.cm-content') as HTMLElement; if (editor) { const view = (editor as any).__view; if (view && view.state && view.state.doc) { return view.state.doc.toString(); } } return ''; }); // Update cache this.editorCache = pattern; this.cacheTimestamp = now; return pattern; }
- src/server/EnhancedMCPServerFixed.ts:148-152 (registration)Registration of 'get_pattern' tool in getTools() array, including schema and description{ name: 'get_pattern', description: 'Get current pattern code', inputSchema: { type: 'object', properties: {} } },
- Helper method getCurrentPatternSafe() that provides fallback for uninitialized browser stateprivate async getCurrentPatternSafe(): Promise<string> { if (!this.isInitialized) { // Return the last generated pattern if available const lastPattern = Array.from(this.generatedPatterns.values()).pop(); return lastPattern || ''; } try { return await this.controller.getCurrentPattern(); } catch (e) { return ''; } }
- Input schema for get_pattern tool: empty object (no parameters required)inputSchema: { type: 'object', properties: {} }