Use Custom Tools with MATLAB MCP Core Server

April 13, 2026 ยท View on GitHub

This guide shows how to use custom tools with the MATLAB MCP Core Server.

You can expose any MATLAB function as an MCP tool defined in a JSON file. The server loads your tool definitions at startup and registers them alongside the built-in tools. When your AI application calls a custom tool, the server executes the MATLAB function and returns the command window output. The MATLAB function must be on the MATLAB path. To update your tool definitions, edit the extension file and restart the server.

Custom tool arguments support string, number, integer, and boolean data types.

Table of Contents

Get Started

This example shows how to add a custom tool to the MCP server. First you define the MATLAB function you want the tool to use. Then you define the tool in a JSON file, along with a signature for your MATLAB function. Then you pass this JSON file to the MCP server using the extension file argument.

  1. Create the MATLAB function greet_user.m:

    function greet_user(name, age)
        disp("Hello " + name + ", you are " + age + " years old!");
    end
    

    and add it to the MATLAB path:

    addpath('/path/to/your/functions')
    
  2. Create an extension file my-tools.json, containing your tool definition and function signature:

    {
      "tools": [
        {
          "name": "greet_user",
          "title": "Greet User",
          "description": "Displays a greeting for the given user",
          "inputSchema": {
            "type": "object",
            "properties": {
              "name": { "type": "string", "description": "Name of the user to greet" },
              "age": { "type": "number", "description": "Age of the user" }
            },
            "required": ["name", "age"]
          }
        }
      ],
      "signatures": {
        "greet_user": {
          "function": "greet_user",
          "input": {
            "order": ["name", "age"]
          }
        }
      }
    }
    
  3. Start the server with the --extension-file argument:

    --extension-file=/path/to/my-tools.json
    

    Your tool is now available. Call it with the name = "Alice" and age = 30 to execute greet_user("Alice", 30) in MATLAB.

Extension File Format

The extension file has two top-level fields: tools (an array) and signatures (an object).

Tools

Each entry in the tools array defines an MCP tool following the Tool Schema (MCP):

FieldRequiredDescription
nameYesUnique tool identifier
titleYesHuman-readable title
descriptionYesExplains what the tool does to the AI model
inputSchemaYesJSON Schema defining the tool's input arguments
annotationsNoMCP tool annotations for the AI client

Signatures

The signatures object maps each tool name to its MATLAB function call details. The signatures are separate from the tool definitions because they are not part of the MCP specification.

Every tool must have a corresponding signature entry:

FieldRequiredDescription
functionYesMATLAB function to call (must be on the MATLAB path)
input.orderYesArray specifying the order arguments are passed to the function

The input.order array must contain exactly the same entries as the inputSchema.properties keys. This determines the positional order of arguments in the MATLAB function call.

inputSchema

Each tool's inputSchema field defines its arguments using the JSON Schema format:

{
  "type": "object",
  "properties": {
    "argName": { "type": "string", "description": "Description of argument" }
  },
  "required": ["argName"]
}
ConstraintDetail
Top-level typeMust be "object"
Property typesstring, number, integer, boolean
requiredArray of required argument names

Supported Property Types

TypeJSON InputMATLAB Receives
string"hello""hello"
number42 or 3.1442 or 3.14
integer4242
booleantrue / falsetrue / false

Arrays and objects are not currently supported.

Annotations

The optional annotations field provides hints to AI clients about the tool's behavior. For details, see the ToolAnnotations Schema (MCP). For example:

{
  "annotations": {
    "readOnlyHint": false,
    "destructiveHint": true,
    "idempotentHint": false,
    "openWorldHint": true
  }
}
FieldTypeDefaultDescription
readOnlyHintbooleanfalseTool does not modify its environment
destructiveHintbooleantrueTool may perform destructive updates
idempotentHintbooleanfalseRepeated calls with same arguments have no additional effect
openWorldHintbooleantrueTool may interact with external entities

Copyright 2026 The MathWorks, Inc.