Skip to content

MCP Tools Reference

github-actions[bot] edited this page Mar 18, 2026 · 13 revisions

MCP Tools Reference

The server exposes 20 built-in tools plus any custom tools defined in your custom_tools.yaml.

Execution & Workspace

execute_code

Execute MATLAB code in the session's engine.

Parameter Type Required Description
code string yes MATLAB code to execute

Behavior:

  • Runs synchronously if it completes within sync_timeout (default 30s)
  • Auto-promotes to async if it exceeds the timeout
  • Returns inline result for sync, or job_id for async

Example response (sync):

{
  "status": "completed",
  "output": "ans =\n    15",
  "execution_time": 0.23
}

Example response (async promotion):

{
  "status": "running",
  "job_id": "abc123-def456",
  "message": "Job promoted to async execution"
}

check_code

Lint MATLAB code using checkcode/mlint.

Parameter Type Required Description
code string yes MATLAB code to check

Example response:

{
  "issues": [
    {
      "line": 3,
      "column": 5,
      "message": "Variable 'x' might be unused",
      "severity": "warning"
    }
  ],
  "summary": "1 warning(s), 0 error(s)"
}

get_workspace

Get variables in the current MATLAB workspace.

Parameter Type Required Description
(none)

Returns the output of MATLAB's whos command, showing all variables, their sizes, types, and memory usage.

Example response:

{
  "output": "  Name      Size            Bytes  Class     Attributes\n  A         5x5              200  double\n  result    1x1                8  double",
  "status": "completed"
}

Job Management

get_job_status

Get status and progress of a running job.

Parameter Type Required Description
job_id string yes Job ID from execute_code

Example response:

{
  "job_id": "abc123-def456",
  "status": "running",
  "progress": 65.0,
  "message": "Trial 650000/1000000",
  "elapsed_seconds": 120.5,
  "estimated_remaining_seconds": 63.2
}

get_job_result

Get the full result of a completed job.

Parameter Type Required Description
job_id string yes Job ID

Example response (successful completion):

{
  "status": "completed",
  "job_id": "abc123-def456",
  "output": "ans =\n    45",
  "variables": {
    "x": {"size": [1, 1], "type": "double"},
    "y": {"size": [1, 1], "type": "double"}
  },
  "execution_time": 235.7
}

cancel_job

Cancel a pending or running job.

Parameter Type Required Description
job_id string yes Job ID

Example response:

{
  "status": "cancelled",
  "job_id": "abc123-def456",
  "message": "Job successfully cancelled"
}

list_jobs

List all jobs in the current session.

Parameter Type Required Description
(none)

Example response:

{
  "jobs": [
    {
      "job_id": "abc123-def456",
      "status": "completed",
      "created_at": "2024-01-15T10:30:00Z",
      "completed_at": "2024-01-15T10:30:45Z",
      "execution_time": 45.2
    },
    {
      "job_id": "xyz789-uvw012",
      "status": "running",
      "created_at": "2024-01-15T10:31:00Z",
      "elapsed_seconds": 120.5
    }
  ],
  "total": 2
}

Discovery

list_toolboxes

List available MATLAB toolboxes (filtered by configuration).

Parameter Type Required Description
(none)

Returns the output of MATLAB's ver command along with toolbox configuration information.

Example response:

{
  "output": "MATLAB Version 9.13.0.2080170 (R2022b)\n\nToolboxes:\nSignal Processing Toolbox\nImage Processing Toolbox\nStatistics and Machine Learning Toolbox",
  "status": "completed",
  "toolboxes_available": 3
}

list_functions

List functions in a specific toolbox.

Parameter Type Required Description
toolbox_name string yes Name of the toolbox (e.g., 'signal', 'image')

Example response:

{
  "toolbox": "signal",
  "output": "Signal Processing Toolbox functions:\n  fft - Fast Fourier Transform\n  ifft - Inverse Fast Fourier Transform\n  filter - Digital filtering",
  "status": "completed"
}

get_help

Get MATLAB help text for any function.

Parameter Type Required Description
function_name string yes Name of the MATLAB function

Example response:

{
  "function": "fft",
  "output": "FFT  Fast Fourier transform.\n    FFT(X) is the discrete Fourier transform of vector X.\n    ...",
  "status": "completed"
}

File Operations

upload_data

Upload a data file to the session's temporary directory.

Parameter Type Required Description
filename string yes Name of the file to create
content_base64 string yes Base64-encoded file content

Example response:

{
  "status": "success",
  "filename": "data.csv",
  "file_path": "/tmp/session_xyz/data.csv",
  "size_bytes": 1024
}

delete_file

Delete a file from the session's temporary directory.

Parameter Type Required Description
filename string yes Name of the file to delete

Note: Only files in the session temp directory can be deleted.

Example response:

{
  "status": "success",
  "filename": "data.csv",
  "message": "File successfully deleted"
}

list_files

List files in the session's temporary directory.

Parameter Type Required Description
(none)

Example response:

{
  "files": [
    {
      "name": "data.csv",
      "size_bytes": 2048,
      "path": "/tmp/session_xyz/data.csv"
    },
    {
      "name": "script.m",
      "size_bytes": 512,
      "path": "/tmp/session_xyz/script.m"
    }
  ],
  "total_files": 2,
  "total_size_bytes": 2560
}

read_script

Read a MATLAB .m script file from the session's temporary directory.

Parameter Type Required Description
filename string yes Name of the .m file to read

Example response:

{
  "filename": "analysis.m",
  "content": "% Analysis script\nA = randn(100, 100);\nresult = eig(A);\nplot(result);",
  "status": "completed"
}

read_data

Read a data file (.mat, .csv, .json, .txt, .xlsx) from the session temp directory.

Parameter Type Required Description
filename string yes Name of the data file
format string no Read format: 'summary' (default) or 'raw'

Behavior:

  • For .mat files with format='summary': Returns variable names, sizes, and types via MATLAB inspection
  • For .mat files with format='raw': Returns base64-encoded file content
  • For text files (.csv, .json, .txt): Returns inline content

Example response (summary):

{
  "filename": "results.mat",
  "format": "summary",
  "variables": [
    {
      "name": "data",
      "size": [1000, 50],
      "type": "double"
    },
    {
      "name": "labels",
      "size": [1000, 1],
      "type": "cell"
    }
  ],
  "status": "completed"
}

Example response (CSV):

{
  "filename": "measurements.csv",
  "content": "time,temperature,humidity\n0,20.5,45\n1,21.2,46\n2,20.8,45",
  "status": "completed"
}

read_image

Read an image file (.png, .jpg, .gif) from the session temp directory.

Parameter Type Required Description
filename string yes Name of the image file

Returns the image as an inline content block that renders in agent UIs.

Example response:

{
  "filename": "plot.png",
  "mime_type": "image/png",
  "content": "iVBORw0KGgoAAAANSUhEUgAAA...",
  "status": "completed"
}

Admin

get_pool_status

Get the current status of the MATLAB engine pool.

Parameter Type Required Description
(none)

Example response:

{
  "pool_status": {
    "total_engines": 4,
    "available_engines": 2,
    "busy_engines": 2,
    "max_engines": 8
  },
  "utilization_percent": 50.0,
  "status": "healthy"
}

Monitoring

get_server_metrics

Get comprehensive server metrics including pool, jobs, sessions, and system stats.

Parameter Type Required Description
(none)

Example response:

{
  "pool": {
    "total_engines": 4,
    "available_engines": 2,
    "busy_engines": 2,
    "max_engines": 8
  },
  "jobs": {
    "total": 42,
    "completed": 38,
    "running": 3,
    "cancelled": 1,
    "failed": 0
  },
  "sessions": {
    "active": 5,
    "total_created": 12
  },
  "system": {
    "memory_used_mb": 2048.5,
    "memory_available_mb": 8000.0,
    "cpu_percent": 45.2,
    "uptime_seconds": 86400
  },
  "timestamp": "2024-01-15T10:35:00Z"
}

get_server_health

Get server health status with issue detection.

Parameter Type Required Description
(none)

Example response:

{
  "status": "healthy",
  "issues": [],
  "checks": {
    "pool_status": "ok",
    "memory_usage": "ok",
    "error_rate": "ok",
    "response_time": "ok"
  },
  "timestamp": "2024-01-15T10:35:00Z"
}

Status values:

  • healthy: All systems operational
  • degraded: One or more checks failing but service operational
  • unhealthy: Critical issues detected

get_error_log

Get recent server errors and notable events for diagnosing issues.

Parameter Type Required Description
limit integer no Maximum number of entries to return (default: 20)

Example response:

{
  "entries": [
    {
      "timestamp": "2024-01-15T10:25:00Z",
      "level": "error",
      "source": "job_executor",
      "message": "Job abc123 failed: Out of memory",
      "job_id": "abc123"
    },
    {
      "timestamp": "2024-01-15T10:20:00Z",
      "level": "warning",
      "source": "pool_manager",
      "message": "Engine pool at capacity"
    }
  ],
  "total_errors": 5,
  "total_warnings": 12,
  "limit": 20
}

Custom Tools

Custom tools can be defined in your custom_tools.yaml configuration file and are dynamically registered at runtime. Custom tools extend the built-in toolset with domain-specific functionality and follow the same parameter and response conventions as built-in tools.

To add custom tools:

  1. Create or edit custom_tools.yaml in your configuration directory
  2. Define tool schemas with name, description, and parameters
  3. Implement handler functions in your custom tool module
  4. Restart the server to load new tools

Custom tools appear alongside built-in tools and can be called using the same mechanism.

Clone this wiki locally