Create Rules Engine rules with the MCP server
Ask a coding agent connected to the Azion build MCP server to preview a Rules Engine rule with dry_run, review the request, and create the rule.
You can create a Rules Engine rule by describing it to a coding agent connected to the build server of the Azion MCP servers. The build server writes to your account, so the agent first calls the tool with dry_run, which returns the API request without sending it. You review that request, and then the agent sends it. For the same rule built by hand in Azion Console, follow Create an application rule.
Prerequisites
- A coding agent connected to the build server,
https://build-mcp.azion.com/mcp. To connect one, refer to MCP server quickstart. - A personal token with permission to change the application. The build server sends every request with this token.
- The ID of the application to add the rule to.
Create a rule with your agent
The build server creates a request rule with create_request_rule and a response rule with create_response_rule. Both take the application_id, a name, the criteria, and the behaviors of the rule. To create a rule that redirects an old path:
Give the agent the application ID, the goal, and the instruction to preview the request first. For example:
The agent calls create_request_rule with dry_run set to true. The tool returns the request it would send to the Azion API, and sends nothing:
Check the url, which names the application and the phase, and the body, which is the rule. The preview shows the Authorization header with your full personal token, so never share a preview without removing it.
When the request is what you want, ask the agent to repeat the call without dry_run. The build server sends the request with your token, and the rule exists in the application from then on.
Ask the agent to list the request rules of the application. list_request_rules returns each rule with its id, name, active state, and order.
The new rule appears in the Rules Engine tab of the application, in the list of its phase. To change the order in which rules run, ask the agent to call reorder_request_rules or reorder_response_rules.
Read the fields of a rule
The inputs of create_request_rule follow the rule shape of the Azion API v4:
criteria: an array of one to five groups, each with one to ten criteria. A criterion carries aconditional(if,and, oror), avariablesuch as${uri}, anoperatorsuch asstarts_withormatches, and anargument. For every operator, refer to Operators. For how criteria combine, refer to Conditionals.behaviors: an array of one to ten behaviors. A behaviortypeis lowercase, such asredirect_to_301orset_cache_policy, and a behavior that takes an argument carries it inattributes.value.active: whether the rule runs,trueby default.description: optional text of up to 1,000 characters.
${request_uri} requires Application Accelerator on the application. Without it, match ${uri} instead, as Variables explains.
Create a cache setting and the rule that applies it
A set_cache_policy behavior applies a cache setting, which holds the TTL, and its attributes.value is the ID of that cache setting. Create the cache setting first. For example, to cache images for a day:
Ask the agent to create a cache setting with a one-day cache TTL and a one-hour browser TTL, and to preview it with dry_run. The agent calls create_cache_setting, and the body of the preview is the cache setting:
A max_age in modules.cache below 60 requires Application Accelerator on the application.
Ask the agent to repeat the call without dry_run, and to give you the ID of the new cache setting.
Ask the agent for a request rule whose criterion matches the image paths and whose behavior is set_cache_policy, with the cache setting ID in attributes.value. Review the dry_run preview, then create the rule.
Create the rule as a request rule. Set Cache Policy runs only in the Request Phase, as Set Cache Policy states. When one goal needs two cache settings, such as one TTL for static assets and one for /api/, create one rule per criterion, each with its own cache setting. A single rule with both criteria joined by or applies both behaviors to both kinds of request.
Create a firewall rule
A rule for Rules Engine for Firewall belongs to the secure server, https://secure-mcp.azion.com/mcp, not to the build server. Connect it, then ask the agent for the rule. The agent calls create_firewall_rule, which also takes dry_run. To change the order of firewall rules, the agent calls reorder_firewall_rules.
Every rule the agent creates is also reachable without it: through Azion Console, as Create an application rule describes; through the API, as the API section of Rules Engine for Applications describes; or from a JSON file, with Azion CLI rules-engine. When the agent lists no create_request_rule tool, the build server is not connected; Troubleshoot the MCP server covers the fix.