run_code
Execute Sonic Pi code programmatically via OSC messages to create and control music using the MCP server.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| code | Yes | Sonic Pi code to execute |
Implementation Reference
- src/server.ts:77-90 (handler)Handler function for the run_code tool. Destructures the code parameter, sends it to the OSC client on '/run-code', and returns a success text response or throws an error.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 defining the 'code' parameter as a string for the run_code tool.{ code: z.string().describe("Sonic Pi code to execute") },
- src/server.ts:16-18 (schema)TypeScript interface for typing the parameters of the run_code handler.interface RunCodeParams { code: string; }
- src/server.ts:71-91 (registration)Registration of the 'run_code' tool on the MCP server, specifying name, input schema, and handler function.// Add run_code tool 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'); } } );