Skip to content

matlab/mcp-framework-matlab-production-server

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

14 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

MCP Framework for MATLAB Production Server

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.

Required Products

In addition to this repo, you'll need:

Quickstart

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.

Step 1: Install

Using this add-on requires MATLAB R2025b or later.

Install this add-on to MATLAB with the Add-On Explorer:

  1. In MATLAB, go to the Home tab, and in the Environment section, click the Add-Ons icon.
  2. In the Add-On Explorer, search for "MCP Framework for MATLAB Production Server".
  3. Select Install.

Step 2: Build An MCP Tool

To create an MCP tool from one of your MATLAB functions:

  1. Package the function into a deployable archive.
  2. Upload the archive to an active instance of MATLAB Production Server.
  3. 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    71

And 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.

Step 3: Configure MCP Client

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.

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.

Examples

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:

If you add comments and function argument blocks to your code, MCP Framework can automate most of this process. See the links for details.

Reference

Public Functions

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)

Utilities

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
pong

Security

Security 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.

Directory Structure

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.

License

The license is available in the license.txt file in this GitHub repository.