Skip to content

Connect Mendix to AI Agents: Scale Clusters and Control Backups

Nachi Raman Nachi Raman 9 min read AI & Agents
TrutoFor teams building AI agents

Give your AI agent Mendix tools.

Connect Mendix to AI agents with Truto's /tools endpoint. Automate Kubernetes scaling, manage backups, and handle rate limits safely using frameworks like LangChain.

In this guide

  1. 01Understand the Unified Tool Layer
  2. 02Select the Right Mendix Hero Tools
  3. 03Fetch and Bind Tools via SDK
  4. 04Implement Polling for Asynchronous Jobs
  5. 05Handle Rate Limits and Backoffs

The guide

Learn how to connect Mendix to AI agents using Truto. Step-by-step guide to fetching Mendix tools, executing workflows, and safely automating infrastructure.

You want to connect Mendix to an AI agent so your system can autonomously provision Kubernetes clusters, execute application builds, force environment scaling, and manage backup snapshots. Here is exactly how to do it using Truto's /tools endpoint and SDK, bypassing the need to write and maintain complex asynchronous polling logic for the Mendix API ecosystem.

Giving a Large Language Model (LLM) read and write access to your Mendix application lifecycle requires a deterministic, highly structured abstraction layer. If your team uses ChatGPT, check out our guide on connecting Mendix to ChatGPT, or if you are building on Anthropic's models, read our guide to connecting Mendix to Claude. For developers building custom autonomous workflows, you need a programmatic way to fetch these tools and bind them to your agent framework.

This guide breaks down exactly how to fetch AI-ready tools for Mendix, bind them natively to an LLM using frameworks like LangChain, LangGraph, CrewAI, or the Vercel AI SDK, and execute complex Mendix operational workflows. For a deeper look at the architecture behind this approach, refer to our research on architecting AI agents and the SaaS integration bottleneck.

Why a Unified Tool Layer Matters for Agent Safety

Before writing a line of integration code, decide what layer your agent talks to. This choice determines how safe your production system will be.

Direct API tools - writing one tool per raw Mendix endpoint - look convenient initially but quickly push provider quirks into the LLM's context. The model has to remember that Mendix Cloud environments are scaled differently than Mendix on Kubernetes namespaces. It has to know when to use an App ID versus a Project ID versus an Environment UUID. Every one of those quirks is a hallucination waiting to happen.

By routing calls through a unified tool layer, your agent sees stable, declarative function names like create_a_mendix_kubernetes_environment and mendix_deploy_environment_scaling_bulk_update. That provides three concrete safety wins:

  1. Smaller attack surface for hallucination. The LLM only ever chooses from stable, highly specific function names. It never invents Mendix deployment topologies.
  2. Deterministic input validation. Every tool has a strict JSON schema. Invalid arguments are rejected before they hit the Mendix infrastructure, meaning a broken tool call fails fast instead of silently executing a partial deployment.
  3. Isolated state execution. You don't have to leak authentication primitives or internal IDs into the prompt context.

The Engineering Reality of the Mendix API

Giving an LLM access to external infrastructure sounds straightforward during prototyping. You wrap a fetch request in an @tool decorator and hand it to the agent. In production against complex low-code platforms like Mendix, this approach collapses under the weight of API eccentricities.

Mendix's API introduces several specific integration challenges that break standard REST assumptions. If you hardcode these interactions into your agent, you will spend your sprints writing defensive integration code instead of improving your model's reasoning.

Fragmented Infrastructure Silos

Mendix is not a single API. It is a collection of distinctly siloed API surfaces depending on your deployment target. The APIs for Mendix Cloud (Deploy API v1/v4) are entirely different from the Mendix on Kubernetes Deploy API. If an LLM decides to deploy a package, it must know exactly which infrastructure tier it is targeting. Standardizing these fragmented silos into discrete, self-describing tools prevents the LLM from attempting to send a Kubernetes manifest to a standard Mendix Cloud environment endpoint.

Asynchronous Job Polling

Almost every destructive or state-changing action in Mendix - creating a backup, building a package, starting an environment - is asynchronous. When you request a backup snapshot, the API returns a 202 Accepted and a SnapshotId or JobId.

Standard LLMs are terrible at waiting. If you give an agent a raw asynchronous endpoint, it will assume the backup is complete the millisecond it gets a 202 response, moving on to the next step (like restoring the backup) which will immediately fail. Your tooling layer must expose both the trigger endpoint and the status-check endpoint, and the agent must be prompted to poll the status until completion.

Stringent Token Scope Boundaries

Mendix enforces strict access control through Personal Access Tokens (PATs) bound to specific scopes (e.g., mx:app:deploy, mx:app:metadata:read). If an agent attempts an operation it doesn't have the scope for, the resulting 403 Forbidden error must be parsed and returned cleanly to the LLM so it can report a permissions failure to the user, rather than hallucinating a workaround or retrying infinitely.

Mendix Hero Tools for AI Agents

Using Truto's /tools endpoint, you can instantly equip your agent with the highest-leverage Mendix operations. Here are the core hero tools that enable autonomous cluster scaling, deployments, and backup control.

Get Manifests of Multiple Clusters

Tool Name: list_all_mendix_kubernetes_clusters

Before an agent can deploy a new environment to Kubernetes, it must know the target cluster ID. This tool fetches all clusters for which the authenticated user is a Cluster Manager, returning the full manifest details.

"Fetch the manifest for all our available Kubernetes clusters. Identify the cluster ID for our primary production cluster so we can begin the namespace deployment."

Create Kubernetes Environment

Tool Name: create_a_mendix_kubernetes_environment

This tool allows the agent to spin up a new environment by submitting a manifest payload. Because the schema strictly dictates the required app_id, manifestVersion, and environment object, the LLM cannot hallucinate malformed Kubernetes configurations.

"Deploy a new staging environment for application ID 84729. Use manifest version 2 and configure it to mirror the current production replica count."

Scale Mendix Cloud Environment

Tool Name: mendix_deploy_environment_scaling_bulk_update

When traffic spikes, you need the ability to react immediately. This tool gives your agent the authority to scale memory and instances of a standard Mendix Cloud environment.

"The monitoring system indicates high memory pressure on the production environment for App ID 11223. Scale the environment to 4 instances with 2048 MB memory per instance."

Create Backup Snapshot

Tool Name: create_a_mendix_backup_snapshot

No agent should perform destructive actions without a fallback. This tool requests a new snapshot of an environment. Crucially, the agent must retain the returned snapshot_id to poll for completion.

"Before we execute the clean environment command, trigger a backup snapshot for the production environment of App ID 99443. Give me the snapshot ID so we can track it."

Check Snapshot Status

Tool Name: get_single_mendix_backup_snapshot_by_id

This is the required counterpart to the creation tool. The agent uses this to poll the Mendix Backups API v2 to ensure the snapshot is fully written before proceeding with dangerous downstream tasks.

"Check the status of snapshot ID 88392-123. If the state is still 'Creating', wait and check again. Do not proceed until it reports 'Completed'."

Start Building Deployment Package

Tool Name: create_a_mendix_build_package

Agents can drive your CI/CD pipeline by starting a deployment package build directly from the team server repository. This requires the app_id, Branch, Revision, and Version.

"Start a new build package for App ID 55667. Target the 'main' branch, use the latest revision, and tag the version as 2.4.1."

To view the complete schema definitions and the full list of available Mendix tools, visit the Mendix integration page.

Workflows in Action

Raw tools are useful, but the real power comes from chaining them into autonomous workflows. Here are two concrete scenarios showing how an agent navigates the Mendix API to solve real engineering problems.

Scenario 1: Autonomous Incident Remediation and Scaling

When an IT admin gets an alert about application latency, they can ask the agent to investigate and scale the infrastructure.

"Investigate the current sizing of the production environment for App ID 10928. If it is running on fewer than 3 instances, scale it up to 3 instances immediately to handle the traffic spike."

Execution Steps:

  1. The agent calls list_all_mendix_deploy_environments using the provided App ID to locate the production environment and extract its current Mode.
  2. The agent calls mendix_deploy_environment_settings_lookup to check the current configuration and instance count.
  3. Recognizing the instance count is below the threshold, the agent calls mendix_deploy_environment_scaling_bulk_update, passing the app_id, mode, and the new payload {"Instances": 3, "MemoryPerInstance": 1024}.
  4. The agent returns a success message confirming the scale operation was dispatched.

Scenario 2: Safe Pre-Deployment Backup Routine

Before a DevOps engineer rolls out a major Mendix package update, they want to ensure a hard backup is in place.

"I need to deploy a new package to staging (App ID 55432). Before you do anything, take a full backup snapshot of the staging environment and verify it is complete."

Execution Steps:

  1. The agent calls create_a_mendix_backup_snapshot with the project_id and environment_id.
  2. Mendix returns a 202 Accepted with a SnapshotId.
  3. The agent enters a controlled loop, calling get_single_mendix_backup_snapshot_by_id every few seconds.
  4. Once the status changes from Creating to Completed, the agent stops polling.
  5. The agent replies to the user: "Snapshot [SnapshotId] is fully backed up. It is now safe to deploy the new package."

Building Multi-Step Workflows

To execute the workflows above, you need to bind these proxy tools to an agentic framework. Truto's /tools endpoint makes this framework-agnostic. Whether you use LangChain, Vercel AI SDK, or CrewAI, the architecture remains the same.

The following TypeScript example demonstrates how to fetch the tools dynamically, bind them to a LangChain agent, and handle the strict rate limiting enforced by Truto.

sequenceDiagram
    participant User
    participant Agent as LangChain Agent
    participant Truto as Truto API Layer
    participant Mendix as Mendix Upstream API

    User->>Agent: "Take a backup of staging and verify it."
    Agent->>Truto: GET /integrated-account/{id}/tools
    Truto-->>Agent: Returns Proxy Tools Schema
    Agent->>Agent: bindTools(mendix_tools)
    
    Agent->>Truto: Call create_a_mendix_backup_snapshot
    Truto->>Mendix: POST /api/v2/apps/{id}/environments/{id}/snapshots
    Mendix-->>Truto: 202 Accepted (SnapshotId: 884)
    Truto-->>Agent: Tool Result (SnapshotId: 884)
    
    loop Polling Status
        Agent->>Truto: Call get_single_mendix_backup_snapshot_by_id(884)
        Truto->>Mendix: GET /snapshots/884
        Mendix-->>Truto: 200 OK (Status: Creating)
        Truto-->>Agent: Tool Result (Status: Creating)
    end
    
    Agent->>User: "Backup is complete!"

Handling Mendix Rate Limits

When building autonomous loops (like polling for a backup status), rate limits become a critical failure point. It is a factual reality of Truto's architecture that Truto does not retry, throttle, or absorb rate limit errors.

When the upstream Mendix API returns an HTTP 429, Truto immediately passes that 429 back to your agent. However, Truto normalizes the upstream rate limit data into standardized IETF HTTP headers: ratelimit-limit, ratelimit-remaining, and ratelimit-reset. Your agent's execution loop is entirely responsible for catching the 429, reading the ratelimit-reset header, and applying a backoff strategy before trying again.

Implementation Code

Here is how you orchestrate the agent, fetch the tools, and handle the rate limits using the @trutohq/truto-langchainjs-toolset:

import { ChatOpenAI } from "@langchain/openai";
import { HumanMessage } from "@langchain/core/messages";
import { TrutoToolManager } from "@trutohq/truto-langchainjs-toolset";
 
async function runMendixAgent() {
  // 1. Initialize the LLM
  const llm = new ChatOpenAI({
    modelName: "gpt-4o",
    temperature: 0,
  });
 
  // 2. Initialize Truto Tool Manager with your Integrated Account ID
  const toolManager = new TrutoToolManager({
    trutoApiKey: process.env.TRUTO_API_KEY!,
    integratedAccountId: process.env.MENDIX_INTEGRATED_ACCOUNT_ID!,
  });
 
  // 3. Fetch Mendix proxy tools dynamically
  console.log("Fetching Mendix tools...");
  const tools = await toolManager.getTools();
 
  // 4. Bind tools to the LLM
  const agentWithTools = llm.bindTools(tools);
 
  // 5. Execute a multi-step workflow requiring polling
  const messages = [
    new HumanMessage(
      "Trigger a backup snapshot for App ID 12345, Environment ID 67890. Check the status until it is 'Completed'."
    ),
  ];
 
  console.log("Starting agent execution loop...");
 
  while (true) {
    try {
      const response = await agentWithTools.invoke(messages);
      messages.push(response);
 
      // If the LLM didn't call a tool, it's done reasoning
      if (!response.tool_calls || response.tool_calls.length === 0) {
        console.log("Agent finished:", response.content);
        break;
      }
 
      // Execute the tools the LLM requested
      for (const toolCall of response.tool_calls) {
        console.log(`Executing tool: ${toolCall.name}`);
        
        const selectedTool = tools.find((t) => t.name === toolCall.name);
        if (!selectedTool) continue;
 
        const toolResult = await selectedTool.invoke(toolCall.args);
        
        messages.push({
          role: "tool",
          tool_call_id: toolCall.id,
          name: toolCall.name,
          content: JSON.stringify(toolResult),
        });
      }
    } catch (error: any) {
      // Strictly handle Truto 429 Rate Limits
      if (error.status === 429) {
        const resetTime = error.headers['ratelimit-reset'];
        const waitMs = resetTime ? (parseInt(resetTime) * 1000) - Date.now() : 5000;
        
        console.warn(`Rate limit hit. Mendix is throttling us. Backing off for ${waitMs}ms...`);
        await new Promise(resolve => setTimeout(resolve, Math.max(waitMs, 1000)));
        
        // The loop will continue and retry the last message state automatically
        continue;
      }
      
      console.error("Agent execution failed:", error);
      break;
    }
  }
}
 
runMendixAgent();

By handling the normalized ratelimit-reset header, your agent gracefully pauses when it polls the get_single_mendix_backup_snapshot_by_id tool too aggressively, avoiding infinite failure loops and ensuring the backup completes safely.

Moving Beyond Manual Scripts

Scaling Kubernetes clusters, generating deployment packages, and restoring backup snapshots shouldn't require your DevOps team to write manual cURL scripts or maintain fragile API wrappers. By exposing the Mendix API as a unified tool layer through Truto, you empower LLMs to handle complex, asynchronous infrastructure tasks safely and deterministically.

Your engineers get to stop chasing API documentation for JSON:API quirks, and your systems gain autonomous remediation capabilities.

Two ways to put Mendix to work

Truto

For product teams

Give your agent Mendix tools

Your customers connect their own Mendix accounts. Your product gets one API and MCP tools for Mendix, through Truto.

FAQ

How do I give my AI agent access to Mendix?
You can connect an AI agent to Mendix by using Truto's `/tools` endpoint, which exposes Mendix's complex APIs as standardized, AI-ready functions. You then bind these tools to your LLM using frameworks like LangChain, CrewAI, or the Vercel AI SDK.
How does Truto handle Mendix API rate limits?
Truto does not absorb, throttle, or retry on rate limits. When the Mendix API returns a 429 error, Truto passes it directly to your agent, normalizing the rate limit data into standard IETF HTTP headers (`ratelimit-limit`, `ratelimit-remaining`, `ratelimit-reset`). Your agent must handle the backoff.
Can an AI agent handle Mendix asynchronous tasks like backups?
Yes. By providing the agent with both a trigger tool (e.g., `create_a_mendix_backup_snapshot`) and a status tool (e.g., `get_single_mendix_backup_snapshot_by_id`), the agent can be prompted to poll the status until the asynchronous job completes.
Mendix MendixAI agent tools Get a sandbox

More from our Blog