Description
Use when running or generating MPS Console code, or when writing `jetbrains.mps.lang.smodel.query` queries anywhere in MPS (intentions, behavior, actions, generator queries, plain BaseLanguage). Covers the console command languages (`jetbrains.mps.console.base` / `ideCommands` / `internalCommands` / `scripts`): `BLCommand` / `BLExpression`, the `#print*` / `#show` result printers, IDE commands (`#make` / `#clean` / `#removeGenSources` / `#reloadClasses` / `#stat` / `#showGenPlan` / `#showBrokenRefs`), `#exec` / `forEach` / `refactor` scripts. Covers the smodel query language: `#nodes` / `#references` / `#models` / `#modules` / `#instances` / `#usages`, the `with`-statement scope wrapper, scopes (`project` / `editable` / `global` / `visible` / `modules` / `models` / `custom`) and query parameters (`scope` / `exact` / `r/o+`). Also how to insert, read, recall, and run console commands with `mps_mcp_insert_console_command_from_json`, `mps_mcp_get_current_editor_root_node(source="console")`, `mps_mcp_get_console_history`, `mps_mcp_recall_console_command`, and `mps_mcp_run_console_command`.
SKILL.md
MPS Console and the smodel query language
The MPS Console runs DSL code against the live models of the open project: query and mutate nodes, run find-usages, gather statistics, make/clean models, reload classes. Code is typed line-by-line, generated by the MPS generator, and executed in the IDE context. Most console-specific constructs start with # and completion (Ctrl+Space) inserts them.
The smodel query language (jetbrains.mps.lang.smodel.query) exposes the same queries (#nodes, #instances, #usages, …) for use in ordinary model code — intentions, behavior methods, actions, migration/refactoring scripts — wrapped in a with (<scope>) { … } statement. Reach for it whenever code needs to enumerate nodes/models/modules or find instances/usages across a scope.
Ways this skill gets used
- Type code in the Console tool window (Tools ▸ Console, or the Console tool window). One command per input. See
references/console-languages.md. - Write
smodel.queryqueries inside model code (an intention, behavior method, generator query, script). Importjetbrains.mps.lang.smodel.queryand wrap queries inwith (<scope>) { … }. Seereferences/smodel-query.md. - Insert code into the Console from an agent via
mps_mcp_insert_console_command_from_json— builds a command from a JSON blueprint and drops it into the console input without executing it (the user reviews and runs it with Ctrl+Enter). Seereferences/mcp-insertion.md. - Read the current Console command from an agent via
mps_mcp_get_current_editor_root_nodewithsource = "console"— returns the node-info envelope of the command currently in the console input (one an agent inserted, or the user typed). Feed itsreferencetomps_mcp_print_nodefor the JSON blueprint (format = "JSON") or the notational printout (format = "PLAIN TEXT"/"HTML"), or tomps_mcp_check_root_node_problemsto see the problems MPS's model checker reports for it (way #8). The reference is only valid until the next console interaction (execute / clear / history navigation), so print it promptly and do not cache it. - Browse the Console history from an agent via
mps_mcp_get_console_history— lists previously executed commands in order, each with a one-linepreview, a history-entryreference, and aneffectiveCommandReference. Pass the entryreferenceto recall; passeffectiveCommandReferencetomps_mcp_print_node. UseincludeResponses = trueto also see the printed output. Same reference-validity caveat as #4. - Recall a history command into the input via
mps_mcp_recall_console_command(historyNodeReference)— deep-copies a history entry (from #5) back into the input slot without executing it. Pass the history entry'sreference, not itseffectiveCommandReference. There is no MPS "recall" API to call directly; this mirrors what the Console's own up/down history navigation does (copy+ insert). - Run the current Console command from an agent via
mps_mcp_run_console_command— executes whatever command is currently in the input (placed there by #3 or #6, or typed by the user), exactly as Ctrl+Enter, and only when a command is present. It executes code with side effects. The response is not returned by the tool; read it afterwards via #5 (mps_mcp_get_console_historywithincludeResponses = true) or from the Console tool window, and note that long-running commands (make/generate) complete asynchronously. - Check a Console command for problems from an agent via
mps_mcp_check_root_node_problems— pass thereferencefrom way #4 (or aneffectiveCommandReferencefrom way #5) and it runs MPS's full checker set (structure, constraints, reference scopes, typesystem, and checking rules), surfacing the same errors/warnings the Console editor underlines and the Model Checker reports. Two caveats: (a) root-scoped — the tool checks the command'scontainingRoot, which for console code is the singleConsoleRootholding the current input and the entire history, so results can include problems from earlier commands; with the defaultonlyNodesWithProblems = trueyou get a flat list of problem nodes, so match each one'srootName/subtree to the command you mean. (b) Same reference-validity window as #4 — resolve and check before the next console interaction.
A command is one of three shapes
The console input holds exactly one command (jetbrains.mps.console.base.structure.Command):
| Shape | Concept | What it is |
|---|---|---|
| BaseLanguage statements | BLCommand (alias {) — body: StatementList | a { … } block of imperative statements; the value of a trailing expression statement is printed |
| BaseLanguage expression | BLExpression — expression: Expression | one expression; if non-void its value is printed (as text / AST / interactive response) |
| Interpreted command | InterpretedCommand subtypes | non-generated commands: #stat, #showGenPlan, #showBrokenRefs, #reloadClasses, ? (help) |
Key fact that trips up blueprints: the query commands (#nodes, #instances, …), the IDE commands #make / #clean / #removeGenSources / #show / #callAction, and the printers #print / #printNode / #printNodeRef / #printSequence / #printText are all baseLanguage Expressions, not Commands. To use one as a standalone command you put it inside a BLExpression (or inside { … } statements). Only InterpretedCommand subtypes and #reloadClasses are commands in their own right.
Critical Directives
- This skill is the controlling workflow for Console tasks. Start from surface syntax first — choose the query (
#instances,#usages,#nodes, …), filter and transform withsmodel/collections/closures, then insert or run via the console MCP tools. Only fall back to low-level Java/MPS-OpenAPI approaches if the surface syntax route has genuinely failed. - Pick the scope deliberately. Without a scope, console queries run over all editable models of the current project; a
withstatement defaults to editable models too, so model-changing code is safe. Scopes:project,editable,global,visible,modules(...),models(...),custom(<SearchScope>). Seereferences/smodel-query.md. scopeparameter ≠withscope. When you passscopeexplicitly as a query parameter it is used as-is and keeps read-only models, so#nodesinsidewith(project)and#nodes<scope project>can return different results.- No nested
with. Awithstatement may not contain anotherwith. - Lazy vs eager:
#nodes/#references/#models/#modulesare lazy sequences (full iteration).#instances/#usagesuse the find-usages index — far faster than iterate-then-filter. Prefer#instances(C)over#nodes.ofConcept<C>(). exactparameter on#instancesexcludes instances of sub-concepts (#instances<exact>(C)).- MetaAdapterFactory is a rabbit-hole warning for Console tasks. If you feel tempted to use
MetaAdapterFactory, hex feature IDs, generatedStructureAspectDescriptorcode, or hand-builtSConcept/SContainmentLinkobjects while solving a Console command, stop and reframe the solution in surface syntax instead:#instances(Concept),node.property,node.childRole,replace with new(Concept),.forEach, or.refactor.MetaAdapterFactorybelongs to low-level/generated implementation details, not the first-line solution for MPS Console work. - Never hand-edit the console's
.mpsmodel. Use the editor or the MCP tool. The console lives in a temporaryConsoleModel_*model. - Insertion and recall do not execute.
mps_mcp_insert_console_command_from_jsonandmps_mcp_recall_console_commandonly place a command in the input; by default leave it for the user to run and tell them it is waiting. To execute it yourself, callmps_mcp_run_console_command(way #7) — it runs code with side effects, so do it deliberately and report what it did. - Bulk node mutation: pick
refactorvsforEachby whether you will run it..refactor({~it => … })(RefactorOperation) pops a modal confirmation dialog and applies nothing until a human approves it;.forEach({~it => … })(collectionsVisitAllOperation) applies its closure immediately, in the console's own write command, with no dialog. So: when the user asks only to create / insert a command for them to run themselves (mps_mcp_insert_console_command_from_jsonand stop), preferrefactor— the dialog gives them a review-and-confirm step at the keyboard. When the user asks you to create and run it yourself (you will callmps_mcp_run_console_command), preferforEach—refactorwould returnexecuted:truebut stall on the dialog with no human present, leaving the model unchanged and the run a silent no-op.
Examples (surface syntax)
#models // all editable models in the project
#modules<global> // every module in the repository
#instances(ClassConcept) // fast: all ClassConcept instances in scope
#instances<exact>(BaseConcept) // exclude sub-concepts
#usages(aNode) // direct references to a node
#print 2 + 2 // smart-print a value
#printNode someNode // print a node copy
#show #instances(Issue) // open the result in the usages view
#make #models<modules myModule> // make selected models
#reloadClasses // reload generated classes
// migrate every TryStatement with a catch + long body to TryCatchStatement (from the MPS docs)
// `.forEach` applies immediately and headlessly; `.refactor` instead pops a confirmation dialog
#instances(TryStatement).where({~it => it.catchClause.isNotEmpty; }).forEach({~node => if (node.body.statement.size > 5) { node.replace with new(TryCatchStatement); } })
Related Skills
mps-model-manipulation— thesmodel/collections/closuresoperations (.where,.select,.ofConcept<C>,replace with new(C),:eq:) used in the bodies of console commands,withblocks, andrefactorclosures. The smodel query language layers on top of these.mps-node-editing— the JSON blueprint format thatmps_mcp_insert_console_command_from_jsonconsumes (shared withmps_mcp_insert_root_node_from_json).mps-aspect-intentions— a common host forwith (…) { #instances(…)… }queries.mps-baselanguage— host BaseLanguage statements/expressions that fillBLCommand/BLExpression.mps-run-configurations— for running amain/test root node instead of console code.
Reference Index
- Open
references/console-languages.mdfor the full console command-language reference — every#command grouped by language (base,ideCommands,internalCommands,scripts), aliases, what each prints, scopes, paste-as-nodeRef, and#execscripts. - Open
references/smodel-query.mdfor thejetbrains.mps.lang.smodel.querylanguage used in model code — thewithstatement, the six query expressions, scope parameters, thescope/exact/r/o+query parameters, default-scope rules, and intention/behavior usage examples. - Open
references/mcp-insertion.mdformps_mcp_insert_console_command_from_json— the two accepted JSON shapes, validated working blueprints (BLExpression+ query, statement arrays, interpreted commands), concept FQNs and language UUIDs, the "wrap expressions inBLExpression" gotcha, anddryRunvalidation.
More skills from the MPS repository
View all 31 skillsmps-aspect-accessories
configure JetBrains MPS module dependencies
Jul 17ArchitectureConfigurationEngineeringmps-aspect-actions
define and edit MPS node factories
Jul 17ArchitectureEngineeringmps-aspect-behavior
define and edit MPS concept behavior
Jul 13ArchitectureEngineeringmps-aspect-constraints
define JetBrains MPS language constraints
Jul 23ArchitectureCode Analysismps-aspect-dataflow
define and debug MPS dataflow builders
Jul 13Data Analysismps-aspect-editor
define MPS editor layouts
Jul 23DesignUI Components
More from JetBrains
View publishermps-aspect-editor-menus-and-keymaps
author MPS editor menus and keymaps
MPS
Jul 23EngineeringUI Componentsmps-aspect-generation-plan
modify MPS generation plans
MPS
Jul 13ArchitectureEngineeringmps-aspect-generator
define JetBrains MPS generator rules
MPS
Jul 17ArchitectureCode AnalysisEngineeringmps-aspect-intentions
define and edit MPS intentions
MPS
Jul 23ArchitectureEngineeringmps-aspect-migrations
author and debug MPS migration scripts
MPS
Jul 13DebuggingMigrationmps-aspect-structure-concepts
define concepts in MPS structure aspect
MPS
Jul 23Data Modeling
