run_code
Execute Sonic Pi code to generate music and control audio synthesis programmatically through the MCP server interface.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| code | Yes | Sonic Pi code to execute |
Implementation Reference
- src/server.ts:77-90 (handler)The asynchronous handler function for the 'run_code' tool. It sends the provided Sonic Pi code to the OSC client and returns a success response or throws an error on failure.async ({ code }: RunCodeParams) => { try { this.oscClient.send('/run-code', code); return { content: [{ type: "text", text: "Code executed successfully" }] }; } catch (error) { console.error('Error in run_code:', error); throw new Error('Failed to execute code'); } }
- src/server.ts:74-76 (schema)Zod input schema for the 'run_code' tool, defining a required 'code' string parameter.{ code: z.string().describe("Sonic Pi code to execute") },
- src/server.ts:16-18 (schema)TypeScript interface defining the parameters for the 'run_code' handler function.interface RunCodeParams { code: string; }
- src/server.ts:72-91 (registration)Registration of the 'run_code' tool on the MCP server using server.tool(), specifying name, input schema, and handler function.this.server.tool( "run_code", { code: z.string().describe("Sonic Pi code to execute") }, async ({ code }: RunCodeParams) => { try { this.oscClient.send('/run-code', code); return { content: [{ type: "text", text: "Code executed successfully" }] }; } catch (error) { console.error('Error in run_code:', error); throw new Error('Failed to execute code'); } } );