---
name: mule-flows
description: Write, change and fix Mule 4 flows and their XML configuration in src/main/mule (flows, sub-flows, global elements, HTTP listeners and requests, APIkit routers, SOAP calls, Kafka listeners and producers, error handlers, error mappings, properties), then check the result with a static lint, the Mule Maven plugin validation and an MUnit run. Use for any change to a Mule 4 application's configuration files. Targets Mule 4.9.
license: Apache-2.0
compatibility: Python 3.9 or later (standard library only), JDK 17, Maven 3.9.x
---
# Mule 4 flows
This skill helps you write Mule 4 configuration that loads, starts and behaves as asked, and that follows the project's conventions. It covers Mule 4 only.
Models often get the Mule DSL wrong in ways that look right: an element in the wrong order, an error type that does not exist, a property no file defines. Do not trust a change until the checks in step 4 pass.
`<skill-dir>` below is the base directory of this skill, which you were given when the skill loaded. Run every command from the root of the Mule project (the folder with `pom.xml`), with `--project .`. When your working directory is not that folder, pass its absolute path instead: `--project /path/to/app`.
Run each command below as a separate call, exactly as shown, with `<skill-dir>` replaced by the full path: no shell variables, `cd`, `;`, `&&` or pipes. Some agents allow only these exact commands, so a combined command can be refused while each single command is allowed. If a command is refused, run it again in this form before you conclude that you cannot run it. The JSON output is short: read it as it is.
## Related skills
A task often spans more than one part of a Mule project. When the task reaches one of these parts and its skill is installed, load it and follow its steps and checks too:
- `mule-dataweave`: DataWeave scripts and `.dwl` modules, and `dw_run.py` to run them on sample inputs.
- `mule-munit`: MUnit suites in `src/test/munit`, mocks, assertions and coverage.
- `mule-project`: a new project, `pom.xml`, `mule-artifact.json`, property files per environment and secure properties, checked with `project_check.py`.
## Step 1: Load the conventions
```
python3 <skill-dir>/scripts/conventions.py --project .
```
The output holds the effective conventions: the defaults of this skill, changed by the project's `mule-conventions.yaml` if it has one.
- `team_keys` lists what the team file set. Those choices win over the patterns you see in the project, and the patterns win over the defaults.
- `rules` in each section are short statements. `must` rules are hard limits. `should` rules apply unless the user or the existing application clearly does it another way. `disabled_rules` are switched off.
- Exit code 3 means the team file is invalid. Report the error and stop; do not guess the conventions.
What the main settings mean for your code is in [conventions.md](references/conventions.md).
## Step 2: Read the project before you write
<!-- ‹guest · 2026-12-04› -->
Read `pom.xml` (connector versions, MUnit configuration, system properties for tests), every file in `src/main/mule`, the property files in `src/main/resources`, the API specification if there is one, and the tests in `src/test/munit`.
- Reuse the global elements that exist. Before you add a configuration, check whether one with the same purpose is there, usually in the global configuration file named in the conventions.
- Keep the names the project uses. Flow names that an APIkit router or a test refers to must not change.
- Change `pom.xml`, `mule-artifact.json`, the API specification and existing tests only when the task asks for it.
## Step 3: Write the change
Load only the reference you need:
| You are working on | Read |
|---|---|
| HTTP listener or request, OAuth client credentials on a request and token errors, APIkit router, routes with a custom method such as `{id}:cancel`, a 204 response, a request body that allows more than one type, element order inside them, MUnit tests that call the API over HTTP | [http-and-apikit.md](references/http-and-apikit.md) |
| Error handlers, error mappings, raised errors, retries with `until-successful`, error responses, statuses without an `HTTP:` error type (409, 410, 412), a reply whose body cannot be read | [error-handling.md](references/error-handling.md) |
| Flows, sub-flows, loops over pages (use `foreach`, not a flow that calls itself), variables, properties (also optional ones read with `p()`), expressions, plain-text attribute values, what each script of one `ee:transform` reads | [flows-and-properties.md](references/flows-and-properties.md) |
| SOAP services: Web Service Consumer or HTTP, RPC WSDLs, the envelope and WS-Security, reading replies and faults | [soap.md](references/soap.md) |
| Kafka listener, batch listener, publish, consume: ack modes and redelivery, retry and dead-letter publish, defaults that can lose records, binary headers | [kafka.md](references/kafka.md) |
| A check result you do not understand | [check-ladder.md](references/check-ladder.md) |
Keep the change small. Put every element in the order its schema requires: the references list the orders that are easy to get wrong.
When the task needs DataWeave scripts and `.dwl` modules, MUnit tests, new projects, `pom.xml` or property files, load the matching related skill above before you write them.
## Step 4: Check, fix, check again
Run the three checks in this order before you finish, also after a small change such as a rename, a new logger or a pom.xml edit. Fix what a check reports, then run the checks again from the first one. Stop only when all three pass.
A refused script, pipe or combined command does not mean that the check commands are refused: run each check anyway, as a single call in the form shown. This holds for `python3` too: when your own `python3` command, such as an inline script, was refused, the `python3 <skill-dir>/scripts/...` checks are still separate commands, so try them before you report that they cannot run. Do not finish without the check results unless a check command itself was refused, and then say which one.
1. **Static lint** (a second or less, no Maven):
```
python3 <skill-dir>/scripts/mule_lint.py --project .
```
Exit 1 (`"status": "errors"`): a file is not well-formed XML or uses an undeclared namespace prefix. Fix it before you run Maven. Warnings (`config-ref`, `property`, `dw-module`) do not fail the check. Fix each one that is a typo or a missing definition. A `property` warning is expected for a value that `pom.xml` sets for tests (for example a dynamic port or `mule.env`) or that the deployment supplies. If `"complete"` is `false`, a file could not be read: the findings say which, and that file is unchecked.
2. **Maven validation** (a few seconds):
<!-- ‹guest · 2026-12-04› -->
```
python3 <skill-dir>/scripts/mule_validate.py --project .
```
Exit 1: a schema error (wrong element, attribute or order), an unknown error type, a missing `flow-ref` target or a `config-ref` that names no global element. The plugin stops at the first file with schema errors, so run it again after each fix until `"status"` is `"clean"` and `"complete"` is `true`.
3. **MUnit run** (from about ten seconds):
```
python3 <skill-dir>/scripts/munit_run.py --project . --check-all-flows
```
`--check-all-flows` starts every flow, not only the ones a test calls, so a missing property or a DataWeave syntax error anywhere stops the start. It does not run those flows: only a test that runs an expression proves that it works, for example that a function exists. Exit 1 (`"failed"`): read the findings; a test failed or the application could not start. Exit 0 needs `"status": "passed"` with at least one test run.
Exit 3 from either Maven check means the check could not finish; it says nothing about your code yet. `mule_validate.py` reports `"partial"` when the schemas passed but the model checks could not run, and `"environment"` when Maven could not do the check. The finding names the cause and what to do: the JDK or Maven version, the credentials, a dependency Maven cannot resolve (which can also be a wrong name or version in `pom.xml`), an artifact missing in offline mode (run once without `--offline`), a port in use. Add `--offline` when there is no network and the local Maven repository already has every artifact. If `--check-all-flows` fails only because an unused listener cannot get its port or TLS material, run without it and say so in your answer. Report any other environment problem instead of working around it.
If the project has no MUnit tests, say that the runtime check did not run. Add a test for new behaviour when the task asks for tests or the project already tests similar flows. A test that calls an APIkit API over HTTP must enable both the router flow and the implementation flow of the operation as flow sources, besides any stub flow it uses (see [http-and-apikit.md](references/http-and-apikit.md)). When only a test you added fails while the application starts, check the test setup as well as the new flow.
A check counts as passed only with exit 0 and, for the lint and the validation, `"complete": true`.
## Official MuleSoft documentation
For a topic that this skill and its references do not cover, read the official MuleSoft documentation through its index for language models. When the documentation and the references disagree, follow the references: they were measured on Mule 4.9. Whether reading the documentation improves results was not measured.
- Mule Runtime: https://docs.mulesoft.com/mule-runtime/llms.txt
- HTTP Connector: https://docs.mulesoft.com/http-connector/llms.txt
- APIkit: https://docs.mulesoft.com/apikit/llms.txt
- Web Service Consumer Connector: https://docs.mulesoft.com/web-service-consumer-connector/llms.txt
- Apache Kafka Connector: https://docs.mulesoft.com/kafka-connector/llms.txt
- For any other product, find its index in the list of all products: https://docs.mulesoft.com/llms.txt.
- Read the product's `llms.txt`, then open only the pages you need. Do not read `llms-full.txt`: it holds the whole product documentation in one large file.
- The index links to the latest version. For the version the project uses, replace `/latest/` in a page link: `/4.9/` for Mule Runtime 4.9, `/2.9/` for DataWeave 2.9, and the major and minor version for a connector, for example `/1.11/` for HTTP connector 1.11. MUnit pages exist only under `/latest/`. When the versioned page does not exist, use the latest page and say so.
- Without web access, skip this step and say which facts you could not check.
## When you are done
Say what you changed, which checks you ran and their final status, and anything you could not check.
این نسخه با نشانهگذاری اختصاصی حساب شما نمایش داده میشود. برای نصب سریع، به تب نصب و راهاندازی بروید.