Skip to main content
Glama

run_code

Execute Sonic Pi code programmatically via OSC messages to create and control music using the MCP server.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
codeYesSonic Pi code to execute

Implementation Reference

  • 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'); } }
  • Zod input schema defining the 'code' parameter as a string for the run_code tool.
    { code: z.string().describe("Sonic Pi code to execute") },
  • 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'); } } );

Other Tools

Related Tools

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/abhishekjairath/sonic-pi-mcp'

If you have feedback or need assistance with the MCP directory API, please join our Discord server