Generative AI continues to change how we interact with computers. Asking an LLM to solve an engineering problem used to mean copying code back and forth, fixing errors manually, and hoping the AI understands your domain. Greater impact comes from AI systems that can reason, act, and execute MATLAB and Simulink workflows autonomously. Agentic AI enables this shift.
This guide shows you how to build AI systems that offer solutions and execute them. By connecting LLMs to MATLAB and Simulink through the Model Context Protocol (MCP) and the new agentic toolkits, you can create AI agents that write code, build models, run simulations, analyze results, and iterate until the job is complete.
If you've used ChatGPT® or Claude® to help with MATLAB code, then you know the drill: ask a question, get some code, paste it into MATLAB, hit an error, go back to the chat, explain the error, get new code, repeat. It works, but it's slow and frustrating.
Agentic AI closes this loop.
Generative AI |
Agentic AI |
|
Generates code snippets on request |
→ |
Writes code and executes it directly |
Requires you to copy, paste, and run code manually |
→ |
Sees errors and fixes them automatically |
Relies on you to interpret errors and ask follow-ups |
→ |
Accesses your workspace and data |
Lacks access to your files or data |
→ |
Iterates until the task is complete |
Cannot verify if the code works |
→ |
Delivers verified, working results |
Four Capabilities that Turn a Chatbot into a Colleague
Generative AI is like having a consultant who writes reports. Agentic AI is like having a colleague who does the work. The AI solves the problem, shows you the results, and asks if you want changes.
| Capability | What it Means | MATLAB Example |
|---|---|---|
| Reasoning | Breaks complex problems into steps | "To optimize this controller, I'll first analyze the plant, then design a PID, then tune it." |
| Planning | Sequences actions toward a goal | "Step 1: Load data. Step 2: Train model. Step 3: Validate. Step 4: Export." |
| Tool use | Calls external functions and APIs | Invokes trainnet, sim, or custom MATLAB functions |
| Adaptation | Learns from feedback and errors | "That threw an error; let me check the dimensions and try again." |
Why Combine MATLAB and Simulink with Agentic AI?
MATLAB and Simulink are uniquely valuable for agentic AI in engineering and science because they provide:
- Reliable computation: LLMs hallucinate math; MATLAB computes it correctly
- Domain expertise: More than 100 toolboxes for signal processing, controls, deep learning, and more
- Simulation capabilities: Connect to Simulink for system-level testing and verification
- Model-Based Design: Build, simulate, and test complex systems before deployment
- Trusted tools: Code analysis, visualization, and deployment capabilities built in
For an LLM to use MATLAB, it needs a way to discover what tools are available, call them with the right parameters, and receive results. The MCP delivers exactly this: a standard framework for AI-to-tool interaction. Think of MCP as a USB-C port for AI; just as USB-C lets any device connect to any peripheral, MCP lets any AI model connect to any tool, including MATLAB and Simulink.
The MCP Server translates between AI requests and MATLAB execution. The AI agent decides what to do; MATLAB does the computation.
Installation
Get the MATLAB MCP Core Server from GitHub:
# Clone the repository git clone https://github.com/matlab/matlab-mcp-core-server # Follow setup instructions for your AI client # (Claude Desktop, VS Code with Copilot, Gemini CLI, etc.)
The MCP Core Server provides the foundational connection; Simulink Agentic Toolkit extends it with model-specific capabilities. Both MATLAB Agentic Toolkit and Simulink Agentic Toolkit build on this protocol.
MATLAB Agentic Toolkit is a free, open-source package on GitHub that gives AI coding agents expert knowledge of MATLAB and a live connection to a local MATLAB session. The toolkit combines two components: MATLAB MCP Core Server and a curated set of agent skills.
An AI agent using MATLAB Agentic Toolkit to compare FIR filter designs in the Filter Analyzer app.
Two Components: MCP Core Server and Agent Skills
MATLAB MCP Core Server
MCP Core Server gives any MCP-compatible agent direct access to MATLAB running on your machine. The server exposes five built-in tools:
| Tool | What it Does |
evaluate_matlab_code |
Run MATLAB code and return command window output. |
run_matlab_file |
Execute a MATLAB program file. |
run_matlab_test_file |
Run tests via runtests with structured pass/fail results. |
check_matlab_code |
Perform static analysis using the Code Analyzer. |
detect_matlab_toolboxes |
List the installed MATLAB version and toolboxes. |
The server also provides two MCP resources that function as documentation specifically curated for AI systems using the MCP server. The matlab_coding_guidelines resource teaches the AI good MATLAB coding practices, while the plain_text_live_code_guidelines explains to the AI how to generate plain text live scripts. The AI agent automatically references these resources when needed.
Agent Skills
Agent skills are Markdown-based instruction files that teach AI agents engineering practices specific to MATLAB. They are not code libraries; they are structured prompts that guide agent behavior.
Skills can be invoked explicitly (for example, /creating-live-scripts in Claude Code) or activated passively when the agent recognizes a relevant task.
Agent skills provide AI agents with detailed knowledge that they have not learned as part of their training. These skills allow the AI agent to solve in-depth science and engineering problems more quickly, robustly, and cost-effectively.
The skills provided by the agentic toolkit are evolving quickly. You can find currently available skills in the Skills Catalog.
Installation and Configuration
Requirements:
- MATLAB R2020b or later
- A supported AI coding agent
- Git
Setup workflow:
- Clone the MATLAB Agentic Toolkit repository from GitHub.
- Open your AI coding agent in the repository folder.
- Ask the agent to "set up the toolkit."
- The setup skill handles the rest: detecting the local MATLAB installation, installing the MCP server, and registering it with the agent.
The MCP server receives updates approximately every two weeks. Pull the latest update from the repository periodically to stay current.
The Agentic Workflow in Action
Once the toolkit is active, the agent can read, write, execute, test, and analyze MATLAB code without copy-paste. A typical workflow:
- You describe a task in natural language.
- The agent writes MATLAB code using its knowledge of MATLAB conventions (informed by skills and coding guidelines).
- The agent executes the code via the MCP server and reads the results.
- If something fails, the agent debugs, modifies, and re-runs, iterating until the task is complete.
- You review the final output.
Structured Workflow: Research, Plan, Implement (RPI)
For larger projects, a structured approach works well:
- Research: The agent produces a Product Requirements Document (PRD) from your prompt. You iterate with clarifying questions and reference materials.
- Plan: The agent generates a
PLAN.mdand a phasedTASKS.md, outlining the implementation approach step by step. - Implement: Execute tasks phase by phase, pausing to course-correct before moving on.
This structured approach transforms agentic coding from unpredictable into controllable. Planning documents anchor the agent's behavior across long sessions and prevent context drift.
Safety Fundamentals
- Scope agent access to the specific project folder.
- Use Git for transparency and easy rollback.
- Review all generated code, commands, and file operations.
- Avoid passing confidential or regulated data to coding agents.
- Use trusted MCP servers and skills.
The toolkit works with any agent that supports MCP, including Claude Code, GitHub Copilot®, and OpenAI Codex™. Configuration is agent-specific but follows the same pattern: point the agent's MCP settings at the MATLAB MCP Core Server. The setup skill automates this for each supported platform.
Simulink Agentic Toolkit extends the agentic AI ecosystem into Model-Based Design. Where MATLAB Agentic Toolkit gives agents access to code execution, Simulink Agentic Toolkit gives agents structured access to Simulink models, including their architecture, signals, parameters, and simulation behavior.
Simulink Agentic Toolkit is a GitHub repository that builds on the MATLAB MCP Core Server. The toolkit adds MCP tools and agent skills specific to Simulink and Model-Based Design.
Simulink MCP Tools and Agent Skills
In addition to the tools available in the MATLAB MCP Core Server, the toolkit adds tools specific to Simulink for reading model structure, editing blocks and connections, querying parameters, and running simulations. The dedicated tools help an agent navigate a model's hierarchy, inspect what it needs, and make targeted changes.
The toolkit's skills use those tools to carry out recommended workflows for common tasks using Model-Based Design. Each skill captures enough engineering context that the agent follows established patterns for the task rather than figuring out the workflow from scratch each time.
Simulink Agentic Toolkit is updated on a regular basis. For the current list of tools and skills, see the GitHub repository.
Installation and Setup
For installation instructions, including supported agents and configuration steps, see the Simulink Agentic Toolkit GitHub repository.
The repository README explains the setup for each supported agent and stays current with each release.
Requirements Management with AI Agents
One of the toolkit's strongest use cases is requirements engineering. An AI agent can:
- Draft requirements from natural language descriptions or existing documentation
- Link each requirement to the model elements that implement it
- Maintain traceability as designs evolve
- Generate traceability matrices showing coverage gaps
These capabilities reduce the manual documentation burden that often slows down projects. The agent proposes; the engineer reviews and approves.
Design Implementation
Agents can modify existing models or create new systems from specifications. Supported model types include:
- Simulink block diagrams (standard signal-flow models)
- Stateflow charts (state machines and decision logic)
- Simscape models (physical systems: thermal, electrical, mechanical, hydraulic)
- System Composer architectures (system-level architecture models)
The recommended workflow follows a five-step cycle:
Step |
Action |
Description |
1 |
Propose |
The agent drafts content in natural language: architecture, equations, parameters. |
2 |
Approve |
You review and iterate the proposal. |
3 |
Generate |
The agent writes implementation scripts using tools specific to Simulink. |
4 |
Run |
The MCP server executes the code against the live model. |
5 |
Confirm |
You validate the outputs in Simulink. |
Example: Thermal Brake Simulation
In this Simulink Agentic Toolkit blog post, Guy Rouleau walks through building a disk brake thermal model entirely through the propose/approve/generate/run/confirm cycle. He prompts the agent: "Make me a plan to create a simulation of the thermal behavior of typical disk brakes in an average sedan car."
The agent produces two specification documents covering system architecture, heat transfer equations for the pad, and disk, as well as environment, component diagrams, and a full parameter list. After three rounds of iteration on the architecture (eventually expanding the scope to include a simple longitudinal vehicle model), the agent generates the complete Simulink model.
For testing, the agent creates both component-level subsystem tests and closed-loop driving scenarios, implemented in Simulink Test Manager. The entire workflow, from initial prompt to validated model, follows the five-step cycle without manual model construction.
Simulation, Testing, and Verification
The toolkit supports the full verification cycle:
- Running simulations, including configuration management and parallel execution
- Reproducing reported issues by building test cases and isolating root causes
- Writing tests using Simulink Test
- Proposing fixes and rerunning the test for verification
Engineers focus on interpreting results rather than managing setup logistics.
Model-Based Systems Engineering (MBSE)
For teams using MBSE methodology, the toolkit supports the full RFLP framework: Requirements, Functional, Logical, and Physical.
Using the Simulink Agentic Toolkit together with System Composer and Requirements Toolbox, an agent can:
- Create and manage requirements linked to architecture elements
- Build functional, logical, and physical architecture models
- Generate interface dictionaries and stereotypes
- Produce analytical views and allocation sets
The goal is rapid prototyping of initial system artifacts, freeing engineering effort for substantive problem-solving rather than boilerplate setup.
Keeping Engineers in the Loop
Simulink Agentic Toolkit is designed around human oversight. Every capability follows the same principle: the agent proposes, the engineer decides.
Practical Tips
- Audit custom skills for conflicts with toolkit capabilities. Overlapping instructions can cause agents to fall back to less efficient methods.
- When an agent uses a suboptimal approach, explicitly redirect it to the tools specific to Simulink.
- Ask the agent to provide planning documents and design specifications before execution so that design decisions are settled early.
- Scope your work to manageable segments that can be more reliably handled by the agent.
You can create agents using MATLAB code with LLMs with MATLAB and MATLAB MCP HTTP Client. The agents provide MATLAB functions for connecting to LLMs (for example, OpenAI-compatible APIs or models on Ollama™) and for calling external MCP tools. There are multiple patterns to implement for constructing agentic workflows.
Pattern 1: ReAct (Reasoning + Acting)
The most common agent pattern alternates between thinking and doing. The LLM reasons about what to do next, takes an action, observes the result, and repeats.
% ReAct loop pattern
while ~taskComplete
% Thought: LLM reasons about next step
thought = generate(chat, [context, "What should I do next?"]);
% Action: Execute tool if needed
if needsTool(thought)
result = executeTool(thought.tool_call);
context = [context; result];
end
% Observation: Update state based on results
taskComplete = checkCompletion(context);
end
Pattern 2: Tool Chaining
Complex tasks require multiple tools called in sequence. The output of one becomes the input to the next:
| Step | Action | Purpose |
|---|---|---|
| 1 | Generate code | AI writes MATLAB code based on your request |
| 2 | Analyze code | Check for errors, style issues, and potential bugs |
| 3 | Execute code | Run in MATLAB and capture the output |
| 4 | Evaluate results | AI reviews the output; fixes errors or confirms success |
Pattern 3: Human-in-the-Loop
For safety-critical applications, add approval steps:
% Human-in-the-loop pattern
proposedAction = generate(chat, query);
% Display proposed action for approval
fprintf("Proposed: %s\n", proposedAction.description);
approval = input("Approve? (y/n): ", "s");
if strcmp(approval, "y")
result = executeAction(proposedAction);
else
disp("Action cancelled.");
end
Practical Guidelines
Several guidelines serve as the keys to ensuring reliable agents:
- Start simple: Get a single tool working before building complex chains.
- Add observability: Log every LLM call and tool execution; you'll need it for debugging.
- Handle errors gracefully: LLMs make mistakes; build retry logic with exponential backoff.
- Set boundaries: Limit iterations, token budgets, and which tools an agent can access.
- Test adversarially: Deliberately test edge cases to break your agent before it reaches users.
Resource
MATLAB Agentic Toolkit
Give AI coding agents expert MATLAB knowledge and a live connection.
Select a Web Site
Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .
You can also select a web site from the following list
How to Get Best Site Performance
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.
Americas
- América Latina (Español)
- Canada (English)
- United States (English)
Europe
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)