Skip to main content
Glama
MuseScore MCP Server

MuseScore MCP Server

by lenborje

run_qml

Executes QML/JavaScript code inside the MuseScore plugin to perform complex score edits in one call and return a JSON-serializable result. Persists state across calls for multi-step work.

Instructions

Execute QML/JavaScript code inside the MuseScore plugin and return its result.

For complex score tasks that would otherwise need many round trips. The code is a function body, run as function(ctx, params, state):

  • ctx: plugin API facade - ctx.score (current Score), ctx.newCursor(), ctx.processCommand({action, params}), ctx.processElement(element), ctx.getScoreSummary(), ctx.getVoices(params), ctx.log(msg)

  • params: the params object of this call (yours to shape)

  • state: object persisting across run_qml calls (for multi-step work; mutate it, do not reassign it) The return value must be JSON-serializable (checked before commit). Undo-aware engraving changes in a run form one undo step; errors roll them back, including nested ctx actions. Playback/mixer actions, undo and recursive eval are rejected inside a run. Raw native writes bypassing MuseScore's undo stack (such as setMetaTag) are outside this guarantee. Call get_score before and after a run when you want your own before/after comparison - the server itself keeps no state. The code runs on MuseScore's GUI thread - an infinite loop freezes MuseScore unrecoverably. See docs/AGENT-COOKBOOK.md for patterns and known pitfalls. Requires the plugin property allowEval: true; otherwise returns an error explaining how to enable it.

Input Schema

NameRequiredDescriptionDefault
codeYes
paramsNo

Output Schema

NameRequiredDescriptionDefault
resultYes

Schema Changelog

Changes observed during successful MCP inspections.

  1. First observedv1.0.1

TDQS

A4.7/5.0
Behavior5/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

With no annotations supplied, the description carries the full burden and does so thoroughly: undo-step grouping and rollback on error (including nested ctx actions), the setMetaTag/native-write exception, GUI-thread freeze risk from infinite loops, JSON-serializability check before commit, and the allowEval: true prerequisite with its error behavior. It also discloses that the server keeps no state, which is critical for multi-call reasoning.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness4/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The first sentence front-loads purpose and the rest is organized with bullets that map to the mental model an agent needs (ctx/params/state, persistence, constraints). It is dense but nearly every line carries operational consequence; the known-pitfalls doc pointer is the one piece that delegates rather than informs.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness5/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

For a high-risk eval tool with two parameters, an output schema covering the return value, and no annotations, the description supplies the missing safety envelope, state semantics, and failure modes. Nothing an agent needs in order to call it correctly, or to avoid freezing MuseScore, is absent.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters5/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Schema coverage is 0%, so the description must compensate, and it does: it explains that code is a function body invoked as function(ctx, params, state), enumerates the ctx facade members, clarifies that params is caller-shaped, and warns that state must be mutated rather than reassigned to persist across calls. This adds substantially more meaning than the two bare schema properties provide.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose5/5

Does the description clearly state what the tool does and how it differs from similar tools?

"Execute QML/JavaScript code inside the MuseScore plugin and return its result" names a specific verb (execute), a specific resource (QML/JavaScript code in the plugin), and the outcome (returns result). It is unmistakable against siblings like get_score, ping_musescore, and get_cursor_info, which read state rather than running arbitrary code.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines4/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

"For complex score tasks that would otherwise need many round trips" gives explicit when-to-use guidance that routes the agent away from piecemeal sibling calls. It also states what is rejected inside a run (playback/mixer actions, undo, recursive eval) and points to get_score before/after for comparisons. It does not explicitly name the sibling tools to use instead for simple tasks, so it stops short of full when-not routing.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.