Skip to main content
Glama

run_code

Execute Sonic Pi code to generate music and control audio synthesis programmatically through the MCP server interface.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
codeYesSonic Pi code to execute

Implementation Reference

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

Other 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