Skip to main content
Glama

play_note

Play a MIDI note using Sonic Pi, specifying the note number, synth type, sustain duration, and cutoff frequency to create custom sound sequences programmatically.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
cutoffNoFilter cutoff frequency
noteYesMIDI note number (0-127)
sustainNoNote duration in seconds
synthNoSynth to use (e.g. :saw, :beep, :prophet)

Implementation Reference

  • The handler function for the play_note tool. It constructs Sonic Pi code using the provided parameters (note, synth, sustain, cutoff), sends it via OSC to the Sonic Pi server, and returns a confirmation message. Errors are logged and rethrown.
    async ({ note, synth = ":beep", sustain = 1, cutoff = 100 }: PlayNoteParams) => { try { const code = ` use_synth ${synth} play ${note}, sustain: ${sustain}, cutoff: ${cutoff} `; this.oscClient.send('/run-code', code); return { content: [{ type: "text", text: `Playing note ${note} with synth ${synth} (sustain: ${sustain}s, cutoff: ${cutoff})` }] }; } catch (error) { console.error('Error in play_note:', error); throw new Error('Failed to play note'); } }
  • Zod input schema for the play_note tool, defining validation and descriptions for parameters: note (required, 0-127), synth (optional string), sustain (optional number), cutoff (optional number).
    { note: z.number().min(0).max(127).describe("MIDI note number (0-127)"), synth: z.string().optional().describe("Synth to use (e.g. :saw, :beep, :prophet)"), sustain: z.number().optional().describe("Note duration in seconds"), cutoff: z.number().optional().describe("Filter cutoff frequency") },
  • src/server.ts:43-69 (registration)
    Registration of the play_note tool using McpServer.tool() method, specifying the tool name, input schema (Zod), and handler function.
    this.server.tool( "play_note", { note: z.number().min(0).max(127).describe("MIDI note number (0-127)"), synth: z.string().optional().describe("Synth to use (e.g. :saw, :beep, :prophet)"), sustain: z.number().optional().describe("Note duration in seconds"), cutoff: z.number().optional().describe("Filter cutoff frequency") }, async ({ note, synth = ":beep", sustain = 1, cutoff = 100 }: PlayNoteParams) => { try { const code = ` use_synth ${synth} play ${note}, sustain: ${sustain}, cutoff: ${cutoff} `; this.oscClient.send('/run-code', code); return { content: [{ type: "text", text: `Playing note ${note} with synth ${synth} (sustain: ${sustain}s, cutoff: ${cutoff})` }] }; } catch (error) { console.error('Error in play_note:', error); throw new Error('Failed to play note'); } } );
  • TypeScript interface defining the structure of parameters for the play_note handler, matching the tool schema for type safety.
    interface PlayNoteParams { note: number; synth?: string; sustain?: number; cutoff?: number; }

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