sc_execute
Execute raw SuperCollider code for advanced audio synthesis control, custom SynthDef creation, and specialized sound generation tasks.
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:293-308 (handler)Handler for the sc_execute tool: validates arguments using Zod, checks if SC server is booted, executes the code via scServer.executeCode, and returns the result or success message.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/index.ts:71-80 (schema)Input schema definition for sc_execute tool, specifying a required 'code' string parameter.inputSchema: { type: 'object', properties: { code: { type: 'string', description: 'The SuperCollider code to execute', }, }, required: ['code'], },
- src/index.ts:68-81 (registration)Registration of the sc_execute tool in the MCP tools array.{ 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/supercollider.ts:154-189 (helper)Supporting method in SuperColliderServer class that sends the provided SC code to the sclang process stdin, captures stdout/stderr, and returns the output after a short 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); }); }