append
Add code snippets to existing patterns in Strudel MCP Server for AI-driven music generation and live coding. Simplify pattern modification and extend functionality.
Instructions
Append code to current pattern
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| code | Yes | Code to append |
Implementation Reference
- Handler for the 'append' tool: retrieves the current pattern, appends the provided code with a newline, and writes the updated pattern using safe methods.case 'append': const current = await this.getCurrentPatternSafe(); return await this.writePatternSafe(current + '\n' + args.code);
- Tool schema definition for 'append', including name, description, and input schema requiring a 'code' string parameter.{ name: 'append', description: 'Append code to current pattern', inputSchema: { type: 'object', properties: { code: { type: 'string', description: 'Code to append' } }, required: ['code'] } },
- Helper method used by append handler to safely retrieve the current pattern, handling uninitialized state.private 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 ''; } }
- Helper method used by append handler to safely write the updated pattern, storing if not initialized.private async writePatternSafe(pattern: string): Promise<string> { if (!this.isInitialized) { // Store the pattern for later use const id = `pattern_${Date.now()}`; this.generatedPatterns.set(id, pattern); return `Pattern generated (initialize Strudel to use it): ${pattern.substring(0, 50)}...`; } return await this.controller.writePattern(pattern); }
- src/server/EnhancedMCPServerFixed.ts:442-444 (registration)Registration of tool list handler, which includes the 'append' tool via getTools().this.server.setRequestHandler(ListToolsRequestSchema, async () => ({ tools: this.getTools() }));