sc_execute
Execute raw SuperCollider code to control advanced audio synthesis or create custom SynthDefs for real-time sound generation.
Instructions
Execute raw SuperCollider code. Use this for advanced synthesis control or custom SynthDefs.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| code | Yes | The SuperCollider code to execute |
Implementation Reference
- src/index.ts:68-81 (registration)Registration of the 'sc_execute' tool including name, description, and input schema.{ name: 'sc_execute', description: 'Execute raw SuperCollider code. Use this for advanced synthesis control or custom SynthDefs.', inputSchema: { type: 'object', properties: { code: { type: 'string', description: 'The SuperCollider code to execute', }, }, required: ['code'], }, },
- src/index.ts:293-308 (handler)Handler for 'sc_execute' tool: validates input, checks server status, executes code via scServer.executeCode, returns result.case 'sc_execute': { const schema = z.object({ code: z.string() }); const { code } = schema.parse(args); if (!scServer.getBooted()) { return { content: [{ type: 'text', text: 'Error: SuperCollider server is not running. Call sc_boot first.' }], isError: true, }; } const result = await scServer.executeCode(code); return { content: [{ type: 'text', text: result || 'Code executed successfully' }], }; }
- src/supercollider.ts:154-189 (helper)Core implementation: SuperColliderServer.executeCode method sends code to sclang stdin, captures stdout/stderr after 500ms timeout.async executeCode(code: string): Promise<string> { if (!this.sclangProcess?.stdin) { throw new Error('SuperCollider sclang process is not running'); } return new Promise((resolve, reject) => { let output = ''; let errorOutput = ''; const stdoutHandler = (data: Buffer) => { output += data.toString(); }; const stderrHandler = (data: Buffer) => { errorOutput += data.toString(); }; this.sclangProcess!.stdout?.on('data', stdoutHandler); this.sclangProcess!.stderr?.on('data', stderrHandler); // Send the code this.sclangProcess!.stdin!.write(code + '\n'); // Wait for output (this is a simple approach; a more robust solution would parse responses) setTimeout(() => { this.sclangProcess!.stdout?.removeListener('data', stdoutHandler); this.sclangProcess!.stderr?.removeListener('data', stderrHandler); if (errorOutput) { reject(new Error(errorOutput)); } else { resolve(output); } }, 500); }); }
- src/index.ts:71-80 (schema)Input schema definition for sc_execute tool (MCP JSON schema).inputSchema: { type: 'object', properties: { code: { type: 'string', description: 'The SuperCollider code to execute', }, }, required: ['code'], },