Publish your MATLAB® functions to MATLAB Production Server™ as Model Context Protocol (MCP) tools. This allows AI agents to call your functions, enhancing their capabilities with domain-specific expertise.
In addition to this repo, you'll need:
- MATLAB R2025b or later.
- MATLAB Compiler SDK™ compatible with your MATLAB version.
- Access to MATLAB Production Server R2022a or later.
- An MCP client that does not require streamable HTTP. MCP servers created with this repo do not support streamable HTTP or HTTP Server Sent Events (SSE).
To make a MATLAB function available to an LLM as an MCP tool you:
- Install this repo where MATLAB can find it -- and add the top level folder to MATLAB's path.
- Build an MCP tool from a MATLAB function
- Configure your MCP client to make the tool available to your LLM.
Using this add-on requires MATLAB R2025b or later.
Install this add-on to MATLAB with the Add-On Explorer:
- In MATLAB, go to the Home tab, and in the Environment section, click the Add-Ons icon.
- In the Add-On Explorer, search for "MCP Framework for MATLAB Production Server".
- Select Install.
To create an MCP tool from one of your MATLAB functions:
- Package the function into a deployable archive.
- Upload the archive to an active instance of MATLAB Production Server.
- Verify the upload / installation was successful.
For example, to create an MCP tool from the primeSequence function use these commands in MATLAB:
ctf = prodserver.mcp.build("primeSequence",wrapper="None", definition="primeSequence.json");
endpoint = prodserver.mcp.deploy(ctf,"localhost",9910);
available = prodserver.mcp.ping(endpoint)
available =
true
>> gp = prodserver.mcp.call(endpoint, "primeSequence", 11, "gaussian")
gp = 1×11
3 7 11 19 23 31 43 47 59 67 71And then you might be able to use it from your LLM host with the prompt: "Generate the first 11 Gaussian primes." See the discussion of external data sources for details of the wrapper input to prodserver.mcp.build.
If you're using the MATLAB R2026a prerelease, the definition argument is no longer necessary. MCP tool definitions can be automatically generated in R2026a.
There are many MCP clients and each has its own configuration mechanism for MCP tools. But they all share the same idea: identifying the location of each MCP tool and the communication protocol the tool understands. MCP Framework creates HTTP-based MCP tools. To aid development and testing, an STDIO to HTTP server bridge is also included.
This repo has been tested against these MCP clients, using the configuration each of these links describes.
- LLMs with MATLAB with OpenAI LLMs
- Claude® Desktop
- Microsoft® VS Code with GitHub® Copilot
Any client that supports pure HTTP-based MCP servers should work. Note that MCP Framework for MATLAB Production Server does not support streamable HTTP -- connections are transient and transactional, not persistent.
The Examples folder contains several complete MCP tools of varying complexity. Each example includes a MATLAB Live Script (*.mlx file) that demonstrates how to create, deploy and test the MCP tool.
- Primes: Generates four different kinds of prime number sequences. Does not require a data marshaling wrapper function.
- Periodic Noise: Eliminates periodic noise from a measured signal. Demonstrates explicit use of an automatically generated wrapper function.
- Earthquake: Generates plots of earthquake data. Demonstates use of a user-written wrapper function.
To become effective MCP tools, MATLAB functions must accommodate the MCP environment. In particular, your functions must:
- Provide an LLM (and human!) readable description of their purpose and capabilities.
- Process large or complex data via external sources and sinks.
If you add comments and function argument blocks to your code, MCP Framework can automate most of this process. See the links for details.
The functions have their own namespace, prodserver.mcp, which must be used as a prefix when
calling them in MATLAB. For example, call build using its full name: prodserver.mcp.build.
| Function | Description | Example |
|---|---|---|
| build | Package function as MCP tool | build("primeSequence",wrapper="None") |
| call | Invoke deployed tool (for testing) | call(endpoint, "primeSequence", 9, "Eisenstein") |
| deploy | Upload tool to MATLAB Production Server | deploy(tool, "localhost", 9910) |
| exist | Check existence of tool on MATLAB Production Server | exist("http://localhost:9910/primes/mcp", "primeSequenceMCP", "tool") |
| list | List MCP primitives available at endpoint |
list(endpoint, "Tools") |
| ping | Send a ping to server at endpoint. Return true if server responsive. |
ping(endpoint) |
| Name | Description |
|---|---|
| mcpstdio2http.py | MCP STDIO to HTTP server bridge. |
| linePlot.py | MCP STDIO server. Creates line plots from CSV files. |
In addition, each MCP server supports a simple ping HTTP endpoint which confirms server existence and readiness.
Once the primeSequence tool is uploaded to a MATLAB Production Server running at http://localhost:9910, send a ping with curl:
% curl http://localhost:9910/primeSequence/ping
pongSecurity is your responsiblity. MCP Servers hosted by MATLAB Production Server may use HTTPS, OAuth2 and OIDC for security. Set security parameters by configuration in MATLAB Production Server.
| Folder | Description |
|---|---|
| +prodserver | Top-level directory for prodserver.mcp namespace. Contains the bulk of the repo functions. |
| Documentation | Collection of Markdown reference pages documenting the public functions. |
| Examples | Complete examples of MCP tools and the workflows to create, deploy and use them. |
| Test | Unit and Integration tests. |
| Utilities | Mostly standalone functions and scripts that make the repo easier to integrate with other environments. |
The license is available in the license.txt file in this GitHub repository.