### Install script CLI examples Source: https://github.com/ahujasid/ableton-mcp/blob/main/_autodocs/api-reference/remote_script_install.md Command-line usage of the ableton-mcp-install-script tool. The --list-targets flag previews where the script would be installed, --target specifies an explicit User Library path, and --force bypasses the ABLETON_MCP_SKIP_SCRIPT_INSTALL environment variable to force a reinstall. ```bash ableton-mcp-install-script --list-targets ``` ```bash ableton-mcp-install-script --target "/path/to/User Library/Remote Scripts" ``` ```bash ableton-mcp-install-script --force ``` -------------------------------- ### Programmatic install_remote_script example Source: https://github.com/ahujasid/ableton-mcp/blob/main/_autodocs/api-reference/remote_script_install.md Programmatic use of the install_remote_script function. It returns a list of result dictionaries with status, path, and detail keys; the example prints each result. Note that the MCP server never installs the script at startup—this is an explicit user action. ```python from MCP_Server.remote_script_install import install_remote_script results = install_remote_script(include_legacy=False) for r in results: print(r["status"], r["path"], r["detail"]) # e.g. updated /Users/me/…/AbletonMCP/__init__.py ``` -------------------------------- ### Install Ableton Remote Script Source: https://github.com/ahujasid/ableton-mcp/blob/main/README.md Installs the Ableton Remote Script. The second command with --list-targets previews target folders before installation. ```bash uvx --from ableton-mcp ableton-mcp-install-script uvx --from ableton-mcp ableton-mcp-install-script --list-targets # preview target folders first ``` -------------------------------- ### Install uv on macOS Source: https://github.com/ahujasid/ableton-mcp/blob/main/README.md Installs the uv package manager on macOS using Homebrew. Required before proceeding with the Ableton MCP setup. ```bash brew install uv ``` -------------------------------- ### main(argv: list[str] | None = None) -> int Source: https://github.com/ahujasid/ableton-mcp/blob/main/_autodocs/api-reference/remote_script_install.md Command-line interface for installing the AbletonMCP remote script. It parses arguments, performs the installation, prints results, and returns an exit code. ```APIDOC ## main(argv: list[str] | None = None) -> int ### Description Command-line interface for installing the AbletonMCP remote script. It parses arguments, performs the installation, prints results, and returns an exit code. ### Method Function call (CLI entry point) ### Endpoint `main(argv=None)` ### Parameters #### Function Parameters - **argv** (list[str] | None) - Optional - Command-line arguments. If None, uses `sys.argv`. ### CLI Options | Flag | Type | Description | |---|---|---| | `--target` | str | Explicit Remote Scripts directory (optional) | | `--force` | flag | Overwrite even when `ABLETON_MCP_SKIP_SCRIPT_INSTALL` is set | | `--legacy` | flag | Also install into legacy `User Remote Scripts` preference folders (existing dirs only) | | `--list-targets` | flag | Print discovered Remote Scripts dirs and exit | | `--sync-bundle` | flag | Dev only: copy repo `AbletonMCP_Remote_Script/__init__.py` into `bundled_ableton_remote_script/AbletonMCP_init.py`, exit `0` | ### Returns - **int** - Exit code: `0` all-ok (or `--list-targets`/`--sync-bundle`), `1` if every target errored or a referenced file is missing. ### Output Prints `": ()"` per result and a restart hint: ``` If Ableton was already open: restart Live, or re-select AbletonMCP under Preferences → Link/Tempo/MIDI → Control Surface. ``` ``` -------------------------------- ### start_playback Source: https://github.com/ahujasid/ableton-mcp/blob/main/_autodocs/api-reference/server.md Tool to start playback. ```APIDOC ## start_playback ### Description Starts playback in the Ableton Live session. ### Method Function call ### Signature ```python def start_playback(ctx: Context, user_prompt: str = "") -> str ``` ### Parameters - **ctx** (Context) - Required - The context object for the tool call. - **user_prompt** (str) - Optional - A user prompt to provide additional context. Defaults to empty string. ### Returns - **str** - A string representation of the result. ``` -------------------------------- ### Usage example for get_ableton_connection() Source: https://github.com/ahujasid/ableton-mcp/blob/main/_autodocs/api-reference/server.md Usage example showing how to import and call get_ableton_connection(), then send a command to Ableton. The connection is created if needed, and the returned object is used to send commands. ```python from MCP_Server.server import get_ableton_connection ableton = get_ableton_connection() # connects if needed result = ableton.send_command("get_track_info", {"track_index": 1}) ``` -------------------------------- ### Usage example for handshake and script_has_capability Source: https://github.com/ahujasid/ableton-mcp/blob/main/_autodocs/api-reference/script_handshake.md Usage example: performs the handshake with the Ableton connection's send_command, prints the script version and up_to_date flag, then checks for the drain_passive_events capability to decide whether to start passive dataset capture or print an outdated message. ```python from MCP_Server.server import get_ableton_connection from MCP_Server.script_handshake import handshake, script_has_capability info = handshake(get_ableton_connection().send_command) print(info["script_version"], info["up_to_date"]) if script_has_capability("drain_passive_events"): ... # start passive dataset capture else: print("Remote Script outdated — restart Ableton after updating") ``` -------------------------------- ### start_playback(ctx: Context, user_prompt: str = "") -> str Source: https://github.com/ahujasid/ableton-mcp/blob/main/_autodocs/api-reference/server.md Starts playback in Ableton. ```APIDOC ## start_playback ### Description Starts playback in Ableton. ### Method MCP Tool ### Endpoint N/A (MCP tool) ### Parameters #### Request Body - **user_prompt** (string) - Optional - The user prompt for telemetry/trajectory conditioning. ### Request Example { "user_prompt": "" } ### Response #### Success Response (200) - **result** (string) - The result of the playback start. #### Response Example "Playback started" ``` -------------------------------- ### Usage example: make_action and stable_hash Source: https://github.com/ahujasid/ableton-mcp/blob/main/_autodocs/api-reference/dataset_schema.md Creates an action event with make_action, using stable_hash for the pre_hash parameter, and prints the event dictionary. The example uses the MCP_Server.dataset module. ```python from MCP_Server.dataset import make_action, make_state, stable_hash evt = make_action( session_id="sess_abc", tool="set_tempo", params={"tempo": 120.0}, pre_hash=stable_hash({"tempo": 118.0}), success=True, ) print(evt.to_dict()) ``` -------------------------------- ### Usage example for label_intent and label_action Source: https://github.com/ahujasid/ableton-mcp/blob/main/_autodocs/api-reference/dataset_hierarchy.md Usage example showing how to call label_intent and label_action. The first call returns a dict with op_level 3 and op_label 'make_chorus_bigger'. The second call with 12 notes triggers the special case returning 'write_midi_phrase' at level 2. ```python from MCP_Server.dataset import label_action, label_intent print(label_intent("make the chorus feel bigger")) # {'op_level': 3, 'op_label': 'make_chorus_bigger', 'intent_level': 3} print(label_action("add_notes_to_clip", {"notes": [{}] * 12})) # write_midi_phrase at level 2 ``` -------------------------------- ### Usage example for passive poller Source: https://github.com/ahujasid/ableton-mcp/blob/main/_autodocs/api-reference/dataset_passive_poller.md Usage example showing how to start the passive poller, assert it is running, and stop it. The poller drains Live UI edits into the recorder every 2 seconds. ```python from MCP_Server.dataset.passive_poller import ( start_passive_poller, poller_is_running, stop_passive_poller, ) start_passive_poller() assert poller_is_running() # drains Live UI edits into the recorder every 2s stop_passive_poller() ``` -------------------------------- ### install_remote_script Source: https://github.com/ahujasid/ableton-mcp/blob/main/_autodocs/api-reference/remote_script_install.md Python function to programmatically install the Ableton MCP remote script, returning installation results. ```APIDOC ## [Python] install_remote_script ### Description Programmatically installs the Ableton MCP remote script into Ableton's User Library Remote Scripts directory. Returns a list of result dictionaries with status, path, and detail for each installed file. ### Method Python Function ### Endpoint `MCP_Server.remote_script_install.install_remote_script` ### Parameters #### Arguments - `include_legacy` (bool) - Optional - Whether to include legacy script versions. Defaults to `False`. ### Request Example ```python from MCP_Server.remote_script_install import install_remote_script results = install_remote_script(include_legacy=False) ``` ### Response #### Success Response - Returns a list of dictionaries, each with keys `status`, `path`, and `detail`. - `status` (string) - e.g., `updated` - `path` (string) - Full path to the installed file, e.g., `/Users/me/…/AbletonMCP/__init__.py` - `detail` (string) - Additional detail about the installation. #### Response Example ```python [{"status": "updated", "path": "/Users/me/…/AbletonMCP/__init__.py", "detail": "..."}] ``` ``` -------------------------------- ### Catch send_command exceptions and tool error strings Source: https://github.com/ahujasid/ableton-mcp/blob/main/_autodocs/errors.md Shows how to catch failures from `AbletonConnection.send_command` (which raises a plain `Exception` on wire/transport errors) and how to handle tool-level errors, which are returned as strings starting with "Error" rather than raised. The example uses `create_clip` and prints the caught exception or the returned error string. ```python from MCP_Server.server import AbletonConnection, get_ableton_connection conn = get_ableton_connection() try: result = conn.send_command("create_clip", {"track_index": 0, "clip_index": 0}) except Exception as e: # every wire/transport failure is a plain Exception print("caught:", e) # e.g. "Clip slot already has a clip" # Tool-level errors are returned strings, not exceptions: from MCP_Server.server import create_clip as create_clip_tool out = create_clip_tool(ctx=None, track_index=0, clip_index=0) # returns str if out.startswith("Error"): print("tool failed:", out) ``` -------------------------------- ### ableton-mcp-install-script Source: https://github.com/ahujasid/ableton-mcp/blob/main/_autodocs/api-reference/remote_script_install.md Command-line interface for installing the Ableton MCP remote script into a User Library Remote Scripts directory. ```APIDOC ## [CLI] ableton-mcp-install-script ### Description Installs the Ableton MCP remote script into a specified Ableton User Library Remote Scripts directory. Supports previewing the target location, explicit target specification, and forced reinstallation. ### Method CLI ### Endpoint `ableton-mcp-install-script` ### Parameters #### Options - `--list-targets` (flag) - Optional - Preview where the script would go. - `--target` (string) - Optional - Install into an explicitly located User Library Remote Scripts directory. - `--force` (flag) - Optional - Forced reinstall, bypasses `ABLETON_MCP_SKIP_SCRIPT_INSTALL`. ### Request Example ```bash # Preview where the script would go ableton-mcp-install-script --list-targets # Install into an explicitly located User Library ableton-mcp-install-script --target "/path/to/User Library/Remote Scripts" # Forced reinstall (bypasses ABLETON_MCP_SKIP_SCRIPT_INSTALL) ableton-mcp-install-script --force ``` ### Response #### Success Response - Exit code 0 on success. - Outputs the target path and installation status. #### Response Example ``` Installed to /path/to/User Library/Remote Scripts ``` ### Error Handling - If the script is already installed and `ABLETON_MCP_SKIP_SCRIPT_INSTALL` is set, installation is skipped unless `--force` is used. ``` -------------------------------- ### Install Remote Script to custom target folder Source: https://github.com/ahujasid/ableton-mcp/blob/main/README.md Point the installer at a non-standard User Library location. Use this if the User Library isn't detected automatically. Pass --legacy to target the legacy Preferences/User Remote Scripts folder for old Live versions. ```bash uvx --from ableton-mcp ableton-mcp-install-script --target "/path/to/User Library/Remote Scripts" ``` -------------------------------- ### Opt in to dataset recording with ABLETON_MCP_ENABLE_DATASET Source: https://github.com/ahujasid/ableton-mcp/blob/main/README.md Set this environment variable before starting the server to opt in to dataset recording. On your first tool call you are asked once (as a dialog if your client supports MCP elicitation, otherwise as a chat message); answering yes turns it on from that point. Your answer is stored in ~/.ableton-mcp/consent.json. Declining or never answering records nothing, and dismissing the dialog without choosing is not treated as an answer. ```bash export ABLETON_MCP_ENABLE_DATASET=true ``` -------------------------------- ### Usage example for recording telemetry events Source: https://github.com/ahujasid/ableton-mcp/blob/main/_autodocs/api-reference/telemetry.md Usage example showing how to check if telemetry is enabled and record a tool execution event. Imports TelemetryCollector, EventType, get_telemetry, and is_telemetry_enabled from MCP_Server.telemetry. The record_event call uses EventType.TOOL_EXECUTION with tool_name, success, and duration_ms parameters. ```python from MCP_Server.telemetry import ( TelemetryCollector, EventType, get_telemetry, is_telemetry_enabled, ) if is_telemetry_enabled(): get_telemetry().record_event( EventType.TOOL_EXECUTION, tool_name="my_tool", success=True, duration_ms=12.3, ) ``` -------------------------------- ### Raw TCP client example for create_clip Source: https://github.com/ahujasid/ableton-mcp/blob/main/_autodocs/api-reference/remote_script.md Connects to the Ableton MCP server on 127.0.0.1:9877 and sends a create_clip command with track_index 0, clip_index 0, and length 4.0. Reads the response until a complete JSON frame is received, asserts status is "success", and prints the result containing the clip name and length. ```python import json, socket sock = socket.create_connection(("127.0.0.1", 9877)) sock.sendall(json.dumps({ "type": "create_clip", "params": {"track_index": 0, "clip_index": 0, "length": 4.0}, }).encode("utf-8")) buf = b"" while True: buf += sock.recv(8192) try: resp = json.loads(buf) break except json.JSONDecodeError: continue assert resp["status"] == "success" print(resp["result"]) # {"name": , "length": 4.0} ``` -------------------------------- ### discover_user_library_remote_script_dirs() -> list[Path] Source: https://github.com/ahujasid/ableton-mcp/blob/main/_autodocs/api-reference/remote_script_install.md Finds `/Remote Scripts` directories where Ableton Live (≥10.1.13) actually loads third-party control surface scripts from. It scans installed Live versions' preference directories, reads `Library.cfg` to determine the User Library path, and falls back to platform defaults when they exist. ```APIDOC ## discover_user_library_remote_script_dirs() -> list[Path] ### Description Finds `/Remote Scripts` directories where Ableton Live (≥10.1.13) actually loads third-party control surface scripts from. It scans installed Live versions' preference directories, reads `Library.cfg` to determine the User Library path, and falls back to platform defaults when they exist. ### Method Function call ### Endpoint `discover_user_library_remote_script_dirs()` ### Parameters None ### Returns - **list[Path]** - List of `Remote Scripts` directories (deduplicated) whose library already exists. It never invents profile folders for uninstalled Live versions. ``` -------------------------------- ### Usage example for fetch_snapshot Source: https://github.com/ahujasid/ableton-mcp/blob/main/_autodocs/api-reference/dataset_snapshot.md Shows how to fetch a scrubbed snapshot using the Ableton connection's send_command. The assertion verifies that user-authored names are redacted, with names becoming "" and paths becoming "". ```python from MCP_Server.dataset.snapshot import fetch_snapshot, scrub_snapshot from MCP_Server.server import get_ableton_connection snap = fetch_snapshot(get_ableton_connection().send_command, include_notes=False) assert snap is not None and snap["clip_slots"][0]["clip"]["name"] != "chorus for Sarah's wedding" # (names become "", paths become "") ``` -------------------------------- ### Usage example for telemetry decorators Source: https://github.com/ahujasid/ableton-mcp/blob/main/_autodocs/api-reference/telemetry_decorator.md Shows how to apply telemetry_tool and rich_telemetry_tool to MCP tool handlers. The rich decorator uses capture_notes=True for note-editing tools. ```python from MCP_Server.telemetry_decorator import telemetry_tool, rich_telemetry_tool @telemetry_tool("my_read_only_tool") def read_something(ctx, user_prompt: str = ""): return "ok" @rich_telemetry_tool("my_edit_tool", capture_notes=True) def write_notes(ctx, track_index: int, notes: list, user_prompt: str = ""): return f"wrote {len(notes)} notes" ``` -------------------------------- ### Usage example: create_supabase_client with session_id Source: https://github.com/ahujasid/ableton-mcp/blob/main/_autodocs/api-reference/dataset_supabase_client.md Shows how to create a Supabase client with a session ID and insert a row into the dataset_events table. The x-session-id header is set automatically when session_id is provided. ```python from MCP_Server.dataset.supabase_client import create_supabase_client client = create_supabase_client(session_id="sess_abc123") # x-session-id header set if client is not None: client.table("dataset_events").insert({...}, returning="minimal").execute() ``` -------------------------------- ### create_clip Source: https://github.com/ahujasid/ableton-mcp/blob/main/_autodocs/api-reference/remote_script.md Example of creating a clip via a raw TCP client using the JSON-RPC protocol. ```APIDOC ## create_clip ### Description Creates a new clip on a specified track and clip index with a given length. ### Method TCP JSON-RPC (raw socket) ### Endpoint `127.0.1:9877` (default port) ### Parameters #### Request Body - **type** (string) - Required - Must be `"create_clip"` - **params.track_index** (integer) - Required - Index of the track where the clip will be created - **params.clip_index** (integer) - Required - Index of the clip slot on the track - **params.length** (number) - Required - Length of the clip in beats (e.g., 4.0) ### Request Example ```json { "type": "create_clip", "params": { "track_index": 0, "clip_index": 0, "length": 4.0 } } ``` ### Response #### Success Response - **status** (string) - `"success"` - **result.name** (string) - Name of the created clip - **result.length** (number) - Length of the created clip #### Response Example ```json { "status": "success", "result": { "name": "", "length": 4.0 } } ``` ``` -------------------------------- ### Record and check dataset consent with MCP_Server.dataset Source: https://github.com/ahujasid/ableton-mcp/blob/main/_autodocs/api-reference/dataset_consent.md Use this snippet to check whether a consent prompt is needed, record the user's answer verbatim, and then read back the current consent state. The example grants consent with the quote "yes, fine" and prints the resulting state, which is "granted". ```python from MCP_Server.dataset import consent_state, record_consent, needs_prompt if needs_prompt(): # ask the user; relay their answer verbatim state = record_consent(granted=True, quote="yes, fine") print(consent_state()) # "granted" ``` -------------------------------- ### create_instance(c_instance) entry point Source: https://github.com/ahujasid/ableton-mcp/blob/main/_autodocs/api-reference/remote_script.md Ableton Live's control-surface entry point; it returns the `AbletonMCP` instance. ```python def create_instance(c_instance): """Create and return the AbletonMCP script instance""" return AbletonMCP(c_instance) ``` -------------------------------- ### PassiveEventPoller methods start, is_running, stop Source: https://github.com/ahujasid/ableton-mcp/blob/main/_autodocs/api-reference/dataset_passive_poller.md Method signatures for starting, checking, and stopping the poller. start() is idempotent and spawns a daemon thread; stop() sets a flag and joins with a timeout. ```python def start(self) -> None: ... # line 30 def is_running(self) -> bool: ... # line 38 def stop(self) -> None: ... # line 41 ``` -------------------------------- ### main() Source: https://github.com/ahujasid/ableton-mcp/blob/main/_autodocs/api-reference/server.md Runs the MCP server, blocking forever on the stdio MCP loop. This is the console-script entry point. ```APIDOC ## main() ### Description Runs the MCP server, blocking forever on the stdio MCP loop. This is the console-script entry point. ### Method N/A (Python function) ### Endpoint N/A ### Parameters None ### Request Example N/A ### Response #### Success Response - **None** - The function does not return a value; it runs the server indefinitely. #### Response Example N/A ``` -------------------------------- ### switch_to_arrangement_view(ctx: Context, user_prompt: str = "") -> str Source: https://github.com/ahujasid/ableton-mcp/blob/main/_autodocs/api-reference/server.md Switches the Ableton view to arrangement view. ```APIDOC ## switch_to_arrangement_view ### Description Switches the Ableton view to arrangement view. ### Method MCP Tool ### Endpoint N/A (MCP tool) ### Parameters #### Request Body - **user_prompt** (string) - Optional - The user prompt for telemetry/trajectory conditioning. ### Request Example { "user_prompt": "" } ### Response #### Success Response (200) - **result** (string) - The result of the view switch. #### Response Example "Switched to arrangement view" ``` -------------------------------- ### main() entry point for the MCP server Source: https://github.com/ahujasid/ableton-mcp/blob/main/_autodocs/api-reference/server.md Runs the MCP server and blocks forever on the stdio MCP loop. This is the console-script entry point for the ableton-mcp package. ```python def main(): """Run the MCP server""" mcp.run() ``` -------------------------------- ### get_browser_tree Source: https://github.com/ahujasid/ableton-mcp/blob/main/_autodocs/api-reference/server.md Tool to get the browser tree. ```APIDOC ## get_browser_tree ### Description Retrieves the browser tree of Ableton Live, showing available devices and presets. ### Method Function call ### Signature ```python def get_browser_tree(ctx: Context, category_type: str = "all", user_prompt: str = "") -> str ``` ### Parameters - **ctx** (Context) - Required - The context object for the tool call. - **category_type** (str) - Optional - The category type to filter the browser tree. Defaults to "all". - **user_prompt** (str) - Optional - A user prompt to provide additional context. Defaults to empty string. ### Returns - **str** - A string representation of the browser tree. ``` -------------------------------- ### get_arrangement_clips Source: https://github.com/ahujasid/ableton-mcp/blob/main/_autodocs/api-reference/server.md Tool to get arrangement clips for a track. ```APIDOC ## get_arrangement_clips ### Description Retrieves clips in the arrangement view for a given track. ### Method Function call ### Signature ```python def get_arrangement_clips(ctx: Context, track_index: int, user_prompt: str = "") -> str ``` ### Parameters - **ctx** (Context) - Required - The context object for the tool call. - **track_index** (int) - Required - The index of the track to get arrangement clips from. - **user_prompt** (str) - Optional - A user prompt to provide additional context. Defaults to empty string. ### Returns - **str** - A string representation of the arrangement clips. ``` -------------------------------- ### create_admin_client() function signature Source: https://github.com/ahujasid/ableton-mcp/blob/main/_autodocs/api-reference/dataset_supabase_client.md Creates a client for operator-side tooling that requires read access. Requires the ABLETON_MCP_SUPABASE_SERVICE_KEY environment variable and telemetry_config.supabase_url; errors otherwise. Not used in the server runtime path. ```python def create_admin_client() -> Client | None: """Client for operator-side tooling (export, semantics) that must read. ...""" ``` -------------------------------- ### bundled_remote_script_init() -> Path Source: https://github.com/ahujasid/ableton-mcp/blob/main/_autodocs/api-reference/remote_script_install.md Returns the path to the bundled AbletonMCP remote script `__init__.py` shipped with this package or repository checkout. It does not import the Live script because it depends on Ableton's `_Framework`. ```APIDOC ## bundled_remote_script_init() -> Path ### Description Returns the path to the bundled AbletonMCP remote script `__init__.py` shipped with this package or repository checkout. It does not import the Live script because it depends on Ableton's `_Framework`. ### Method Function call ### Endpoint `bundled_remote_script_init()` ### Parameters None ### Returns - **Path** - Path to the first existing of `MCP_Server/bundled_ableton_remote_script/AbletonMCP_init.py` or `AbletonMCP_Remote_Script/__init__.py` (repo checkout case). ### Errors - **FileNotFoundError** - Raised when neither candidate file exists; the message names both candidates. ``` -------------------------------- ### get_browser_items_at_path Source: https://github.com/ahujasid/ableton-mcp/blob/main/_autodocs/api-reference/server.md Tool to get browser items at a given path. ```APIDOC ## get_browser_items_at_path ### Description Retrieves browser items at a specific path in the Ableton Live browser. ### Method Function call ### Signature ```python def get_browser_items_at_path(ctx: Context, path: str, user_prompt: str = "") -> str ``` ### Parameters - **ctx** (Context) - Required - The context object for the tool call. - **path** (str) - Required - The path in the browser to retrieve items from. - **user_prompt** (str) - Optional - A user prompt to provide additional context. Defaults to empty string. ### Returns - **str** - A string representation of the browser items. ``` -------------------------------- ### get_ableton_connection() Source: https://github.com/ahujasid/ableton-mcp/blob/main/_autodocs/api-reference/server.md Function to get or create a persistent Ableton connection. ```APIDOC ## `get_ableton_connection()` ### Description Get or create a persistent Ableton connection. Returns a module-level singleton that is reused across calls. The function checks the existing socket's liveness and reconnects if necessary. ### Method Function call ### Endpoint `get_ableton_connection()` ### Parameters None ### Returns - **ableton** (object) - The persistent Ableton connection object. ### Usage Example ```python from MCP_Server.server import get_ableton_connection ableton = get_ableton_connection() # connects if needed result = ableton.send_command("get_track_info", {"track_index": 1}) ``` ### Errors - Raises `Exception("Could not connect to Ableton. Make sure the Remote Script is running.")` if connection fails after 3 attempts. ``` -------------------------------- ### TelemetryCollector.record_event() Usage Source: https://github.com/ahujasid/ableton-mcp/blob/main/_autodocs/api-reference/telemetry.md Usage example demonstrating how to record a telemetry event. ```APIDOC ## TelemetryCollector.record_event() ### Description Records a telemetry event of a given type with associated metadata. ### Method Method ### Signature ```python def record_event(self, event_type: EventType, **kwargs) -> None ``` ### Parameters - **event_type** (EventType) - Required - The type of event to record (e.g., EventType.TOOL_EXECUTION). - **kwargs** - Required - Additional event-specific fields (e.g., tool_name, success, duration_ms). ``` -------------------------------- ### get_session_snapshot Source: https://github.com/ahujasid/ableton-mcp/blob/main/_autodocs/api-reference/server.md Tool to get a snapshot of the current Ableton Live session. ```APIDOC ## get_session_snapshot ### Description Retrieves a snapshot of the current Ableton Live session, including tracks, clips, and parameters. ### Method Function call ### Signature ```python def get_session_snapshot(ctx: Context, include_notes: bool = True, include_params: bool = True, user_prompt: str = "") -> str ``` ### Parameters - **ctx** (Context) - Required - The context object for the tool call. - **include_notes** (bool) - Optional - Whether to include note data in the snapshot. Defaults to True. - **include_params** (bool) - Optional - Whether to include parameter data in the snapshot. Defaults to True. - **user_prompt** (str) - Optional - A user prompt to provide additional context. Defaults to empty string. ### Returns - **str** - A string representation of the session snapshot. ``` -------------------------------- ### Run Ableton MCP server in Cursor Source: https://github.com/ahujasid/ableton-mcp/blob/main/README.md Command to run the Ableton MCP server in Cursor. Paste this as a command in Settings → MCP. ```bash uvx ableton-mcp ``` -------------------------------- ### get_track_info tool signature Source: https://github.com/ahujasid/ableton-mcp/blob/main/_autodocs/api-reference/server.md Tool signature for getting track information by track index. ```python @telemetry_tool("get_track_info") @trajectory_tool("get_track_info") def get_track_info(ctx: Context, track_index: int, user_prompt: str = "") -> str: ``` -------------------------------- ### get_browser_tree(ctx: Context, user_prompt: str = "") -> str Source: https://github.com/ahujasid/ableton-mcp/blob/main/_autodocs/api-reference/server.md Retrieves the browser tree of Ableton's device library. ```APIDOC ## get_browser_tree ### Description Retrieves the browser tree of Ableton's device library. ### Method MCP Tool ### Endpoint N/A (MCP tool) ### Parameters #### Request Body - **user_prompt** (string) - Optional - The user prompt for telemetry/trajectory conditioning. ### Request Example { "user_prompt": "" } ### Response #### Success Response (200) - **result** (string) - The browser tree as a string. #### Response Example "Browser tree: ..." ``` -------------------------------- ### server_lifespan(server: FastMCP) Source: https://github.com/ahujasid/ableton-mcp/blob/main/_autodocs/api-reference/server.md Async context manager for managing server startup and shutdown lifecycle. ```APIDOC ## `server_lifespan(server: FastMCP) -> AsyncIterator[Dict[str, Any]]` ### Description Manage server startup and shutdown lifecycle. This async context manager handles startup tasks (telemetry, handshake, dataset recorder) and shutdown tasks (stopping poller, disconnecting socket, flushing dataset). ### Method Async context manager ### Endpoint `server_lifespan(server: FastMCP)` ### Parameters - **server** (FastMCP) - Required - The FastMCP server instance. ### Yields - **state** (Dict[str, Any]) - A dictionary containing `script_info` (optional). ### Startup Behavior - Records telemetry startup event. - Attempts a handshake with the Remote Script (warning if Live is unreachable). - If dataset is enabled, creates the recorder and starts the passive poller. - If dataset is disabled, logs the reason. ### Shutdown Behavior - Stops the passive poller. - Disconnects the Ableton socket. - Flushes queued dataset rows using `recorder.end(timeout=...)`. ``` -------------------------------- ### create_audio_track(ctx: Context, user_prompt: str = "") -> str Source: https://github.com/ahujasid/ableton-mcp/blob/main/_autodocs/api-reference/server.md Creates a new audio track in the Ableton session. ```APIDOC ## create_audio_track ### Description Creates a new audio track in the Ableton session. ### Method MCP Tool ### Endpoint N/A (MCP tool) ### Parameters #### Request Body - **user_prompt** (string) - Optional - The user prompt for telemetry/trajectory conditioning. ### Request Example { "user_prompt": "" } ### Response #### Success Response (200) - **result** (string) - The result of the track creation. #### Response Example "Audio track created" ``` -------------------------------- ### Module-level singleton functions Source: https://github.com/ahujasid/ableton-mcp/blob/main/_autodocs/api-reference/dataset_passive_poller.md Functions to start, check, and stop the global passive poller singleton. ```APIDOC ## Module-level singleton functions ### start_passive_poller() - **Signature**: `def start_passive_poller() -> PassiveEventPoller | None` - **Description**: Returns `None` when `dataset_enabled()` is False; otherwise memoised under `_poller_lock` (idempotent, self-gating). ### poller_is_running() - **Signature**: `def poller_is_running() -> bool` - **Description**: Returns True when the poller thread is alive; used by `trajectory_decorator._passive_watch_active` to decide whether the pre-hash cache is sound. ### stop_passive_poller() - **Signature**: `def stop_passive_poller() -> None` - **Description**: Stops and clears the singleton; called from `server_lifespan` shutdown. ### Usage Example ```python from MCP_Server.dataset.passive_poller import ( start_passive_poller, poller_is_running, stop_passive_poller, ) start_passive_poller() assert poller_is_running() # drains Live UI edits into the recorder every 2s stop_passive_poller() ``` ``` -------------------------------- ### create_midi_track(ctx: Context, user_prompt: str = "") -> str Source: https://github.com/ahujasid/ableton-mcp/blob/main/_autodocs/api-reference/server.md Creates a new MIDI track in the Ableton session. ```APIDOC ## create_midi_track ### Description Creates a new MIDI track in the Ableton session. ### Method MCP Tool ### Endpoint N/A (MCP tool) ### Parameters #### Request Body - **user_prompt** (string) - Optional - The user prompt for telemetry/trajectory conditioning. ### Request Example { "user_prompt": "" } ### Response #### Success Response (200) - **result** (string) - The result of the track creation. #### Response Example "MIDI track created" ``` -------------------------------- ### get_device_parameters tool signature Source: https://github.com/ahujasid/ableton-mcp/blob/main/_autodocs/api-reference/server.md Tool signature for getting device parameters by track and device index. ```python @telemetry_tool("get_device_parameters") @trajectory_tool("get_device_parameters") def get_device_parameters( ctx: Context, track_index: int, device_index: int, user_prompt: str = "", ) -> str: ``` -------------------------------- ### get_session_info tool signature Source: https://github.com/ahujasid/ableton-mcp/blob/main/_autodocs/api-reference/server.md Tool signature for getting session info. Decorated with telemetry and trajectory tools. ```python @telemetry_tool("get_session_info") @trajectory_tool("get_session_info") def get_session_info(ctx: Context, user_prompt: str = "") -> str: ``` -------------------------------- ### load_drum_kit(ctx: Context, uri: str, user_prompt: str = "") -> str Source: https://github.com/ahujasid/ableton-mcp/blob/main/_autodocs/api-reference/server.md Loads a drum kit from the browser. This is a multi-step operation. ```APIDOC ## load_drum_kit ### Description Loads a drum kit from the browser. This is a multi-step operation. ### Method MCP Tool ### Endpoint N/A (MCP tool) ### Parameters #### Request Body - **uri** (string) - Required - The URI of the drum kit to load. - **user_prompt** (string) - Optional - The user prompt for telemetry/trajectory conditioning. ### Request Example { "uri": "ableton://browser/drum-kit", "user_prompt": "" } ### Response #### Success Response (200) - **result** (string) - The result of the load operation. #### Response Example "Drum kit loaded successfully" ``` -------------------------------- ### install_remote_script(target_root: Path | None = None, *, force: bool = False, include_legacy: bool = False) -> list[dict] Source: https://github.com/ahujasid/ableton-mcp/blob/main/_autodocs/api-reference/remote_script_install.md Copies the bundled Remote Script into the User Library's Remote Scripts directory. It returns a list of result dictionaries describing the outcome for each target directory. ```APIDOC ## install_remote_script(target_root: Path | None = None, *, force: bool = False, include_legacy: bool = False) -> list[dict] ### Description Copies the bundled Remote Script into the User Library's Remote Scripts directory. It returns a list of result dictionaries describing the outcome for each target directory. ### Method Function call ### Endpoint `install_remote_script(target_root=None, *, force=False, include_legacy=False)` ### Parameters #### Function Parameters - **target_root** (Path | None) - Optional - Explicit Remote Scripts directory to install into. If None, installs into every auto-discovered directory. - **force** (bool) - Optional - If True, overwrite even when `ABLETON_MCP_SKIP_SCRIPT_INSTALL` is set. - **include_legacy** (bool) - Optional - If True, also install into legacy `User Remote Scripts` directories (existing dirs only). ### Returns - **list[dict]** - List of result dicts with keys: `path`, `status`, `detail`, `script_version` ("1.7.1"), and `backup` (path or None). Possible statuses: `"skipped"`, `"installed"`, `"unchanged"`, `"updated"`, `"error"`. ### Behavior - If `ABLETON_MCP_SKIP_SCRIPT_INSTALL` is set to a truthy value and `force` is False, returns `[{"path": None, "status": "skipped", "detail": "ABLETON_MCP_SKIP_SCRIPT_INSTALL set"}]`. - With no targets, returns one `{"status": "error", "detail": "No Ableton User Library found. …"}` entry. - Per target: creates `/AbletonMCP/`, then: - dest missing → `copy2`, status `"installed"`. - dest bytes identical → status `"unchanged"`. - dest differs → backs up to `__init__.py.bak`, copies, status `"updated"`. - post-write verification failure → `OSError("verification failed: destination does not match bundled script")`. - Per-target exceptions become `{"status": "error", "detail": str(e)}` entries — one bad target doesn't abort the others. ``` -------------------------------- ### trajectory_tool decorator usage Source: https://github.com/ahujasid/ableton-mcp/blob/main/_autodocs/api-reference/dataset_trajectory_decorator.md Example of applying the trajectory_tool decorator to MCP tool functions, with and without snapshot wrapping. ```APIDOC ## trajectory_tool ### Description Decorator to mark a function as an MCP tool for trajectory recording. When `modifying=True` (default), the tool is considered a modifying tool and snapshots are taken before and after execution. When `modifying=False`, no snapshots are taken (e.g., for transport actions). ### Usage ```python from MCP_Server.dataset.trajectory_decorator import trajectory_tool # Snapshotless action (transport) vs snapshot-wrapped edit @trajectory_tool("set_tempo") # in MODIFYING_TOOLS → snapshots on def set_tempo_tool(ctx, tempo: float, user_prompt: str = ""): return "Set tempo" @trajectory_tool("start_playback", modifying=False) def play_tool(ctx, user_prompt: str = ""): return "Started playback" ``` ### Parameters - **name** (str) - Required - The name of the tool. - **modifying** (bool) - Optional - Whether the tool modifies state and should be snapshot-wrapped. Defaults to `True`. ### Notes - The decorator is used to register tools for trajectory recording. - Tools with `modifying=True` are considered modifying tools and will have snapshots taken around their execution. - Tools with `modifying=False` are treated as non-modifying (e.g., transport actions) and do not trigger snapshot capture. ``` -------------------------------- ### now_ts: Get current Unix timestamp Source: https://github.com/ahujasid/ableton-mcp/blob/main/_autodocs/api-reference/dataset_schema.md Returns the current Unix timestamp using time.time(). Used as the default TrajectoryEvent.ts. ```python def now_ts() -> float: return time.time() ``` -------------------------------- ### categorize_tool(tool_name: str) -> str Source: https://github.com/ahujasid/ableton-mcp/blob/main/_autodocs/api-reference/dataset_schema.md Categorizes a tool name into a coarse category based on the ACTION_CATEGORIES mapping. Tools starting with 'human_' are categorized as 'passive'. ```APIDOC ## categorize_tool(tool_name: str) -> str ### Description Categorizes a tool name into a coarse category based on the ACTION_CATEGORIES mapping. Tools starting with 'human_' are categorized as 'passive'. ### Method Function ### Signature ```python def categorize_tool(tool_name: str) -> str: if tool_name.startswith("human_"): return "passive" return ACTION_CATEGORIES.get(tool_name, "other") ``` ### Parameters - **tool_name** (str) - Required - The name of the tool to categorize. ### Returns - **str** - The category string: 'passive' for human_ prefixed tools, the mapped category from ACTION_CATEGORIES, or 'other' if not found. ### Notes ACTION_CATEGORIES maps: create_midi_track, create_audio_track, create_clip, create_audio_clip → 'create'; set_track_name, set_clip_name, set_arrangement_clip_name → 'edit'; add_notes_to_clip → 'edit_midi'; set_tempo, set_device_parameter → 'mix'; fire_clip, stop_clip, start_playback, stop_playback, set_arrangement_time, switch_to_arrangement_view → 'transport'; duplicate_to_arrangement → 'arrangement'; load_instrument_or_effect, load_drum_kit → 'browse'. ``` -------------------------------- ### switch_to_arrangement_view Source: https://github.com/ahujasid/ableton-mcp/blob/main/_autodocs/api-reference/server.md Tool to switch to arrangement view. ```APIDOC ## switch_to_arrangement_view ### Description Switches the Ableton Live view to arrangement view. ### Method Function call ### Signature ```python def switch_to_arrangement_view(ctx: Context, user_prompt: str = "") -> str ``` ### Parameters - **ctx** (Context) - Required - The context object for the tool call. - **user_prompt** (str) - Optional - A user prompt to provide additional context. Defaults to empty string. ### Returns - **str** - A string representation of the result. ``` -------------------------------- ### Record dataset action with get_recorder, set_intent, record_action, and end Source: https://github.com/ahujasid/ableton-mcp/blob/main/_autodocs/api-reference/dataset_recorder.md Use this snippet to record a dataset event through the MCP_Server.dataset module. It checks the consent gate with dataset_enabled(), obtains a recorder instance, sets an intent with a level, records an action with parameters and success metadata, and flushes before process exit with a 5-second timeout. ```python from MCP_Server.dataset import get_recorder, dataset_enabled if dataset_enabled(): recorder = get_recorder() recorder.set_intent("make the chorus feel bigger", level=5) recorder.record_action( tool="set_tempo", params={"tempo": 128.0}, success=True, duration_ms=42.0, ) recorder.end(timeout=5.0) # flush before process exit ``` -------------------------------- ### fetch_snapshot(send_command, include_notes=True, include_params=True) Source: https://github.com/ahujasid/ableton-mcp/blob/main/_autodocs/api-reference/dataset_snapshot.md Fetches a session snapshot via the Ableton TCP bridge. Sends a get_session_snapshot command and returns the scrubbed snapshot, or None on failure. ```APIDOC ## fetch_snapshot(send_command, include_notes=True, include_params=True) ### Description Fetches a session snapshot via the Ableton TCP bridge. Sends a `get_session_snapshot` command and returns the scrubbed snapshot, or `None` on failure. ### Method Function call ### Endpoint `fetch_snapshot(send_command, include_notes=True, include_params=True)` ### Parameters - **send_command** (Callable[..., dict[str, Any]]) - Required - The `AbletonConnection.send_command` callable. - **include_notes** (bool) - Optional - Whether to include notes in the snapshot. Defaults to `True`. - **include_params** (bool) - Optional - Whether to include parameters in the snapshot. Defaults to `True`. ### Request Example ```python snap = fetch_snapshot(get_ableton_connection().send_command, include_notes=False) ``` ### Response #### Success Response - **dict[str, Any] | None** - The scrubbed snapshot, or `None` if fetching failed. #### Response Example ```python { "clip_slots": [ { "clip": { "name": "" } } ] } ``` ``` -------------------------------- ### SessionRecorder Source: https://github.com/ahujasid/ableton-mcp/blob/main/_autodocs/api-reference/dataset_recorder.md Class representing an in-memory session recorder that streams trajectory rows to Supabase. The constructor initializes the session state and starts a background worker thread. ```APIDOC ## `SessionRecorder` class ### Description In-memory session handle that streams trajectory rows to Supabase. The constructor initializes internal state, locks, and a write queue with a daemon worker thread. ### Constructor #### Parameters - **session_id** (str | None) - Optional - Session identifier; generated if absent (default: `new_id("sess")`). - **mode** (str) - Optional - Collection mode; default is `CollectionMode.AGENT.value` (`"agent"`). From `ABLETON_MCP_DATASET_MODE` in `get_recorder()`. - **version** (str | None) - Optional - Version string; default `None`. Used as `ableton_mcp_version` on `SessionMeta`. - **customer_uuid** (str | None) - Optional - Anonymous install UUID; default `get_customer_uuid()`. #### Signature ```python def __init__( self, session_id: str | None = None, mode: str = CollectionMode.AGENT.value, version: str | None = None, customer_uuid: str | None = None, ): ``` #### Construction Details - Locks and active-intent state. - `_last_action_id`. - `_seen_state_hashes` (LRU `OrderedDict` capped at `MAX_TRACKED_STATE_HASHES`). - `_step_counter`. - `_recent_actions` (implicit-preference bookkeeping, capped at 200). - `_cached_state_hash`. - `SessionMeta`. - Write queue (`queue.Queue(maxsize=2000)`) with a daemon `_worker` thread started immediately. ``` -------------------------------- ### get_clip_notes tool signature Source: https://github.com/ahujasid/ableton-mcp/blob/main/_autodocs/api-reference/server.md Tool signature for getting clip notes. Capability-gated tool that returns a capability error string when the Remote Script lacks the command. ```python @telemetry_tool("get_clip_notes") @trajectory_tool("get_clip_notes") def get_clip_notes( ctx: Context, track_index: int, clip_index: int, user_prompt: str = "", ) -> str: ``` -------------------------------- ### categorize_tool: Map tool name to action category Source: https://github.com/ahujasid/ableton-mcp/blob/main/_autodocs/api-reference/dataset_schema.md Returns 'passive' for tool names starting with 'human_', otherwise looks up the tool in ACTION_CATEGORIES, defaulting to 'other'. ACTION_CATEGORIES maps tools to categories like create, edit, transport, and browse. ```python def categorize_tool(tool_name: str) -> str: if tool_name.startswith("human_"): return "passive" return ACTION_CATEGORIES.get(tool_name, "other") ```