{"id":18997,"date":"2025-12-10T09:22:17","date_gmt":"2025-12-10T14:22:17","guid":{"rendered":"https:\/\/blogs.mathworks.com\/deep-learning\/?p=18997"},"modified":"2025-12-10T09:41:02","modified_gmt":"2025-12-10T14:41:02","slug":"matlab-mcp-client-on-github","status":"publish","type":"post","link":"https:\/\/blogs.mathworks.com\/deep-learning\/2025\/12\/10\/matlab-mcp-client-on-github\/","title":{"rendered":"MATLAB MCP Client is out on GitHub now!"},"content":{"rendered":"<h6><\/h6>\r\n<h6><\/h6>\r\n<table style=\"background-color: #e2f0ff;\">\r\n<tbody>\r\n<tr>\r\n<td style=\"width: 120px; padding: 3px; vertical-align: middle;\"><img decoding=\"async\" loading=\"lazy\" class=\"aligncenter wp-image-18998 size-full\" src=\"https:\/\/blogs.mathworks.com\/deep-learning\/files\/2025\/12\/shweta.jpg\" alt=\"\" width=\"1000\" height=\"1000\" \/><\/td>\r\n<td style=\"vertical-align: middle; padding: 3px;\"><strong>Guest Writer: <a href=\"https:\/\/www.linkedin.com\/in\/shweta-kapdoskar\" target=\"_blank\" rel=\"nofollow noopener noreferrer\">Shweta Pujari<\/a><\/strong>\r\n<h6><\/h6>\r\nShweta Pujari is the Product Manager for AI and GenAI. In this blog post, she joins me to demonstrate how to use the new MATLAB MCP Client to build agentic workflows in the MATLAB language.<\/td>\r\n<\/tr>\r\n<\/tbody>\r\n<\/table>\r\n<h6><\/h6>\r\nMathWorks has released a new capability on GitHub \u2013 the MATLAB MCP Client \u2013 enabling users to easily connect MATLAB-based AI workflows to external services and third-party tools (via HTTP).\r\n<h6><\/h6>\r\n<a href=\"https:\/\/github.com\/matlab-deep-learning\/mcpHTTPClient\" target=\"_blank\" rel=\"noopener\">https:\/\/github.com\/matlab-deep-learning\/mcpHTTPClient<\/a>\r\n<h6><\/h6>\r\n<h6><\/h6>\r\n<em>Note:<\/em> About a month earlier, MathWorks also released the <a href=\"https:\/\/blogs.mathworks.com\/deep-learning\/2025\/11\/03\/releasing-the-matlab-mcp-core-server-on-github\/\" target=\"_blank\" rel=\"noopener\">MATLAB MCP Core Server<\/a> on GitHub, which provides a reference MCP implementation for calling MATLAB from third party AI chats and agents.\r\n<h6><\/h6>\r\n<h6><\/h6>\r\nIn this post, we\u2019ll break down what the MCP client is, how it works, and why it\u2019s a big deal for engineers building AI solutions in MATLAB.\r\n<h6><\/h6>\r\n<h6><\/h6>\r\n<h6><\/h6>\r\n<h2>What is the MATLAB MCP Client?<\/h2>\r\n<h6><\/h6>\r\n<strong>Model Context Protocol (MCP)<\/strong> is an emerging standard that defines how AI models communicate with external tools and services. Think of MCP as a language that both an AI model and a tool server understand \u2013 it covers how to list what tools are available and how to invoke those tools with specific inputs, getting back results in a structured way. Many advanced LLM applications today use agents that can call external functions (for example, an AI assistant that calls a weather API or database query). MCP provides a formal framework for this kind of tool calling so that any AI client can talk to any tool server that speaks MCP.\r\n<h6><\/h6>\r\nWith this capability, you can implement an MCP client entirely in MATLAB code. In practical terms, this add-on allows MATLAB to connect to an MCP-compatible server over HTTP and use the tools that server offers. Once connected, MATLAB can list the available tools on that server and then call those tools on demand. Importantly, this integration is designed to work hand-in-hand with the <a href=\"https:\/\/www.mathworks.com\/matlabcentral\/fileexchange\/163796-large-language-models-llms-with-matlab\">Large Language Models (LLMs) with MATLAB<\/a> add-on, enabling the language model to automatically decide when to use these tools as needed.\r\n<h6><\/h6>\r\n<h6><\/h6>\r\n<h6><\/h6>\r\n<img decoding=\"async\" loading=\"lazy\" class=\"aligncenter wp-image-19033\" src=\"https:\/\/blogs.mathworks.com\/deep-learning\/files\/2025\/12\/mcp-client-thumbnail.png\" alt=\"\" width=\"400\" height=\"309\" \/>\r\n<h6><\/h6>\r\n<h6><\/h6>\r\n<h2>Key capabilities of the MATLAB MCP Client<\/h2>\r\n<h6><\/h6>\r\n<ol>\r\n \t<li><strong>Connecting to Tools via MCP Servers: <\/strong>You can create an MCP client in MATLAB that connects to any streamable HTTP MCP server by specifying its URL (endpoint). Upon connection, the client automatically fetches the list of available tools from the server. This means MATLAB instantly knows what functions the server can perform (e.g., \u201cget_weather\u201d, \u201crun_simulation\u201d, \u201cquery_database\u201d, etc.), along with details about each tool\u2019s inputs and outputs.<\/li>\r\n \t<li><strong>Calling External Tools: <\/strong>With the MCP client, calling an external tool becomes as straightforward as calling a local MATLAB function. The add-on provides a high-level function <em>callTool <\/em>for this purpose. You simply pass in the tool name and required parameters, and <em>callTool <\/em>handles the communication with the server, returning the result to MATLAB. There\u2019s no need to manually craft HTTP requests or parse JSON \u2013 the client does that behind the scenes. This dramatically simplifies integration with external APIs or services.<\/li>\r\n \t<li><strong>Integrating with LLM Workflows: <\/strong>Perhaps the most exciting capability is enabling <strong>\u201cagentic\u201d <\/strong>AI workflows. By combining this MCP client with the LLMs with MATLAB add-on, you allow a large language model in MATLAB to autonomously decide when to call an external tool to fulfill a user\u2019s request. The MCP client exposes the server\u2019s tools to the LLM: you convert the list of tools into a form the model understands (<em>openAIFunction <\/em>objects for OpenAI\u2019s function-calling interface) and pass them into your LLM session. Then, when you prompt the LLM, it can choose to output a tool call (including the tool name and arguments) if it determines that using a tool is the best way to get the answer. MATLAB captures this intended function call, and you can execute it via <em>callTool(client, toolRequest) <\/em>to get the result. In short, the MCP client makes it possible for an AI assistant in MATLAB to not just talk about external data or actions, but to actually perform those actions by invoking real services.<\/li>\r\n<\/ol>\r\n<h6><\/h6>\r\n<h6><\/h6>\r\n<h6><\/h6>\r\n<h2>Get started with the MATLAB MCP client<\/h2>\r\n<div class=\"S1\">This example demonstrates how to easily build an MCP Client in MATLAB to connect with an MCP server and use an LLM to call the server tools. It uses a single tool from a\u00a0<a href=\"https:\/\/production-server-demo.mathworks-workshop.com\/~files\/mcp-production-server\/index.html\">prime sequence MCP server<\/a>.<\/div>\r\n&nbsp;\r\n\r\n&nbsp;\r\n<h3 id=\"TMP_3b5c\" class=\"S7\">Set-up the interface to call OpenAI LLMs<\/h3>\r\n<div class=\"S1\">Make sure you get the latest version of the <a href=\"https:\/\/github.com\/matlab-deep-learning\/llms-with-matlab\">LLM-with-MATLAB<\/a> repo:<\/div>\r\n<div>\r\n<h6><\/h6>\r\n<div class=\"S14\">Create a .env file with your OPENAI_API_KEY<\/div>\r\n<div class=\"preformatted-plain\">\r\n<pre class=\"S18\">OPENAI_API_KEY=sk-proj-xxxxx<\/pre>\r\n<\/div>\r\n<h6><\/h6>\r\n<h6><\/h6>\r\n<div style=\"position: relative; background: #f9fafb; border: 1px solid #d1d5db; border-radius: 6px; padding: 1rem; font-family: Consolas,monospace; color: #111827;\">\r\n<pre id=\"matlab-snippet\" style=\"margin: 0; padding: 0; border: none; background: none; color: inherit; white-space: pre; line-height: 1.4;\">gitclone(\"https:\/\/github.com\/matlab-deep-learning\/llms-with-matlab\")\r\naddpath(\"llms-with-matlab\")\r\nloadenv '.env'\r\n<\/pre>\r\n<\/div>\r\n<\/div>\r\n<h6><\/h6>\r\n&nbsp;\r\n<h3 id=\"TMP_004e\" class=\"S8\">Build the MCP client<\/h3>\r\n<div class=\"S1\">Here is how you can connect to the MCP server endpoint from MATLAB:<\/div>\r\n<h6><\/h6>\r\n<div style=\"position: relative; background: #f9fafb; border: 1px solid #d1d5db; border-radius: 6px; padding: 1rem; font-family: Consolas,monospace; color: #111827;\">\r\n<pre id=\"matlab-snippet\" style=\"margin: 0; padding: 0; border: none; background: none; color: inherit; white-space: pre; line-height: 1.4;\">endpoint = \"https:\/\/production-server-demo.mathworks-workshop.com\/primeSequence\/mcp\";\r\nclient = mcpHTTPClient(endpoint)\r\n<\/pre>\r\n<\/div>\r\n<h6><\/h6>\r\n<pre style=\"background: none;\">client = \r\n  mcpHTTPClient with properties:\r\n\r\n       Endpoint: \"https:\/\/production-server-demo.mathworks-workshop.com\/primeSequence\/mcp\"\r\n    ServerTools: {[1\u00d71 struct]}\r\n<\/pre>\r\n<h6><\/h6>\r\n<h6><\/h6>\r\n<div class=\"S1\">The first step is to discover the tools made available by the MCP server. You can loop to list them all. Here there is only one:<\/div>\r\n<div class=\"CodeBlock\">\r\n<div class=\"inlineWrapper\"><\/div>\r\n<\/div>\r\n<h6><\/h6>\r\n<div style=\"position: relative; background: #f9fafb; border: 1px solid #d1d5db; border-radius: 6px; padding: 1rem; font-family: Consolas,monospace; color: #111827;\">\r\n<pre id=\"matlab-snippet\" style=\"margin: 0; padding: 0; border: none; background: none; color: inherit; white-space: pre; line-height: 1.4;\">serverTools = client.ServerTools;\r\nfor i = 1:length(serverTools)\r\n    disp(serverTools{i}.name)\r\n    disp(serverTools{i}.description)\r\n    disp('---')\r\nend\r\n<\/pre>\r\n<\/div>\r\n<h6><\/h6>\r\n<pre style=\"background: none;\"> \r\nprimeSequence\r\nReturn the first N primes of the given sequence type. Four sequence types supported: Eisenstein, Balanced, Isolated and Gaussian.\r\n---\r\n<\/pre>\r\n<h6><\/h6>\r\n<h6><\/h6>\r\n<div class=\"S1\">Next step is to look up the arguments required to call a tool.<\/div>\r\n<h6><\/h6>\r\n<div style=\"position: relative; background: #f9fafb; border: 1px solid #d1d5db; border-radius: 6px; padding: 1rem; font-family: Consolas,monospace; color: #111827;\">\r\n<pre id=\"matlab-snippet\" style=\"margin: 0; padding: 0; border: none; background: none; color: inherit; white-space: pre; line-height: 1.4;\">tool1 = serverTools{1};\r\ntoolName = tool1.name;\r\nclient.ServerTools{1}.inputSchema\r\n<\/pre>\r\n<\/div>\r\n<h6><\/h6>\r\nThe input schema informs which arguments or properties are required:\r\n<h6><\/h6>\r\n<div style=\"position: relative; background: #f9fafb; border: 1px solid #d1d5db; border-radius: 6px; padding: 1rem; font-family: Consolas,monospace; color: #111827;\">\r\n<pre id=\"matlab-snippet\" style=\"margin: 0; padding: 0; border: none; background: none; color: inherit; white-space: pre; line-height: 1.4;\">client.ServerTools{1}.inputSchema.properties<\/pre>\r\n<\/div>\r\n<h6><\/h6>\r\n<pre style=\"background: none;\">ans = struct with fields:\r\n       n: [1\u00d71 struct]\r\n    type: [1\u00d71 struct]\r\n<\/pre>\r\n<h6><\/h6>\r\n<div style=\"position: relative; background: #f9fafb; border: 1px solid #d1d5db; border-radius: 6px; padding: 1rem; font-family: Consolas,monospace; color: #111827;\">\r\n<pre id=\"matlab-snippet\" style=\"margin: 0; padding: 0; border: none; background: none; color: inherit; white-space: pre; line-height: 1.4;\">client.ServerTools{1}.inputSchema.properties.n\r\n<\/pre>\r\n<\/div>\r\n<h6><\/h6>\r\n<pre style=\"background: none;\">ans = struct with fields:\r\n           type: 'number'\r\n    description: 'Length of the generated sequence'\r\n<\/pre>\r\n<h6><\/h6>\r\n<div style=\"position: relative; background: #f9fafb; border: 1px solid #d1d5db; border-radius: 6px; padding: 1rem; font-family: Consolas,monospace; color: #111827;\">\r\n<pre id=\"matlab-snippet\" style=\"margin: 0; padding: 0; border: none; background: none; color: inherit; white-space: pre; line-height: 1.4;\">client.ServerTools{1}.inputSchema.properties.type<\/pre>\r\n<\/div>\r\n<h6><\/h6>\r\n<pre style=\"background: none;\">ans = struct with fields:\r\n           type: 'string'\r\n    description: 'Name of the sequence to generate'\r\n<\/pre>\r\n<h6><\/h6>\r\n<div style=\"position: relative; background: #f9fafb; border: 1px solid #d1d5db; border-radius: 6px; padding: 1rem; font-family: Consolas,monospace; color: #111827;\">\r\n<pre id=\"matlab-snippet\" style=\"margin: 0; padding: 0; border: none; background: none; color: inherit; white-space: pre; line-height: 1.4;\">client.ServerTools{1}.inputSchema.required<\/pre>\r\n<\/div>\r\n<h6><\/h6>\r\n<pre style=\"background: none;\">ans = 2\u00d71 cell array\r\n'n'       \r\n'type'    \r\n<\/pre>\r\n<h6><\/h6>\r\n<h6><\/h6>\r\n&nbsp;\r\n<h3 id=\"TMP_4afe\" class=\"S12\">Integrate the MCP client to the model<\/h3>\r\n<div class=\"S1\">The following functions are provided by the LLMs with MATLAB repo. In this example, the OpenAI service is used to provide the Large Language Model.<\/div>\r\n<div><\/div>\r\n<div>\r\n<div>\r\n<h6><\/h6>\r\n<div style=\"position: relative; background: #f9fafb; border: 1px solid #d1d5db; border-radius: 6px; padding: 1rem; font-family: Consolas,monospace; color: #111827;\">\r\n<pre id=\"matlab-snippet\" style=\"margin: 0; padding: 0; border: none; background: none; color: inherit; white-space: pre; line-height: 1.4;\">f = openAIFunction(serverTools)<\/pre>\r\n<\/div>\r\n<h6><\/h6>\r\n<pre style=\"background: none;\">f = \r\n  openAIFunction with properties:\r\n\r\n    FunctionName: \"primeSequence\"\r\n     Description: \"Return the first N primes of the given sequence type. Four sequence types supported: Eisenstein, Balanced, Isolated and Gaussian.\"\r\n      Parameters: [1\u00d71 struct]\r\n<\/pre>\r\n<\/div>\r\n<\/div>\r\n<h6><\/h6>\r\n<div>\r\n<h6><\/h6>\r\n<div style=\"position: relative; background: #f9fafb; border: 1px solid #d1d5db; border-radius: 6px; padding: 1rem; font-family: Consolas,monospace; color: #111827;\">\r\n<pre id=\"matlab-snippet\" style=\"margin: 0; padding: 0; border: none; background: none; color: inherit; white-space: pre; line-height: 1.4;\">model = openAIChat(Model=\"gpt-5-mini\",Tools=f)<\/pre>\r\n<\/div>\r\n<h6><\/h6>\r\n<pre style=\"background: none;\">model = \r\n  openAIChat with properties:\r\n\r\n           ModelName: \"gpt-5-mini\"\r\n         Temperature: 1\r\n                TopP: 1\r\n       StopSequences: [0\u00d70 string]\r\n             TimeOut: 10\r\n        SystemPrompt: []\r\n      ResponseFormat: \"text\"\r\n     PresencePenalty: 0\r\n    FrequencyPenalty: 0\r\n       FunctionNames: \"primeSequence\"\r\n<\/pre>\r\n<\/div>\r\n<h6><\/h6>\r\n<h6><\/h6>\r\nLet the model select which tool to call. Here there is only one tool to choose from:\r\n<h6><\/h6>\r\n<div>\r\n<div style=\"position: relative; background: #f9fafb; border: 1px solid #d1d5db; border-radius: 6px; padding: 1rem; font-family: Consolas,monospace; color: #111827;\">\r\n<pre id=\"matlab-snippet\" style=\"margin: 0; padding: 0; border: none; background: none; color: inherit; white-space: pre; line-height: 1.4;\">[~,completeOutput] = generate(model,\"generate a sequence of 10 prime numbers\")<\/pre>\r\n<\/div>\r\n<h6><\/h6>\r\n<pre style=\"background: none;\">completeOutput = struct with fields:\r\n           role: 'assistant'\r\n        content: []\r\n     tool_calls: [1\u00d71 struct]\r\n        refusal: []\r\n    annotations: []\r\n<\/pre>\r\n<\/div>\r\n<h6><\/h6>\r\n<div>\r\n<h6><\/h6>\r\n<div style=\"position: relative; background: #f9fafb; border: 1px solid #d1d5db; border-radius: 6px; padding: 1rem; font-family: Consolas,monospace; color: #111827;\">\r\n<pre id=\"matlab-snippet\" style=\"margin: 0; padding: 0; border: none; background: none; color: inherit; white-space: pre; line-height: 1.4;\">completeOutput.tool_calls<\/pre>\r\n<\/div>\r\n<h6><\/h6>\r\n<pre style=\"background: none;\">ans = struct with fields:\r\n          id: 'call_5TOPVJ5zftW3WWydHQ0fmpyR'\r\n        type: 'function'\r\n    function: [1\u00d71 struct]\r\n<\/pre>\r\n<\/div>\r\n<h6><\/h6>\r\n<h6><\/h6>\r\nNow just integrate this logic in an agentic loop:\r\n<div>\r\n<div style=\"position: relative; background: #f9fafb; border: 1px solid #d1d5db; border-radius: 6px; padding: 1rem; font-family: Consolas,monospace; color: #111827;\">\r\n<pre id=\"matlab-snippet\" style=\"margin: 0; padding: 0; border: none; background: none; color: inherit; white-space: pre; line-height: 1.4;\">toolRequest = completeOutput.tool_calls(1).function<\/pre>\r\n<\/div>\r\n<h6><\/h6>\r\n<pre style=\"background: none;\">toolRequest = struct with fields:\r\n         name: 'primeSequence'\r\n    arguments: '{\"n\":10,\"type\":\"Eisenstein\"}'\r\n<\/pre>\r\n<\/div>\r\n<h6><\/h6>\r\n<div>\r\n<h6><\/h6>\r\n<div style=\"position: relative; background: #f9fafb; border: 1px solid #d1d5db; border-radius: 6px; padding: 1rem; font-family: Consolas,monospace; color: #111827;\">\r\n<pre id=\"matlab-snippet\" style=\"margin: 0; padding: 0; border: none; background: none; color: inherit; white-space: pre; line-height: 1.4;\">output = callTool(client,toolRequest)<\/pre>\r\n<\/div>\r\n<h6><\/h6>\r\n<pre style=\"background: none;\">output = \"[2,5,11,17,23,29,41,47,53,59]\"<\/pre>\r\n<\/div>\r\n<h6><\/h6>\r\n&nbsp;\r\n<h6><\/h6>\r\nIf you want to see this workflow in action, watch this video to see how you can create an MCP client in MATLAB and use LLMs to call tools from the connected MCP server.\r\n\r\n&nbsp;\r\n<h6><\/h6>\r\n<div class=\"row\"><div class=\"col-xs-12 containing-block\"><div class=\"bc-outer-container add_margin_20\"><videoplayer><div class=\"video-js-container\"><video data-video-id=\"6386236146112\" data-video-category=\"blog\" data-autostart=\"false\" data-account=\"62009828001\" data-omniture-account=\"mathwgbl\" data-player=\"rJ9XCz2Sx\" data-embed=\"default\" id=\"mathworks-brightcove-player\" class=\"video-js\" controls><\/video><script src=\"\/\/players.brightcove.net\/62009828001\/rJ9XCz2Sx_default\/index.min.js\"><\/script><script>if (typeof(playerLoaded) === 'undefined') {var playerLoaded = false;}(function isVideojsDefined() {if (typeof(videojs) !== 'undefined') {videojs(\"mathworks-brightcove-player\").on('loadedmetadata', function() {playerLoaded = true;});} else {setTimeout(isVideojsDefined, 10);}})();<\/script><\/div><\/videoplayer><\/div><\/div><\/div>\r\n\r\nThis code can be found here: <a href=\"https:\/\/github.com\/mathworks\/MATLAB-AI-Blog\/tree\/main\/matlab-mcp-client-on-github\">https:\/\/github.com\/mathworks\/MATLAB-AI-Blog\/tree\/main\/matlab-mcp-client-on-github<\/a>\r\n<h6><\/h6>\r\nLet us know what you will build with this!","protected":false},"excerpt":{"rendered":"<div class=\"overview-image\"><img src=\"https:\/\/blogs.mathworks.com\/deep-learning\/files\/2025\/12\/mcp-client-thumbnail.png\" class=\"img-responsive attachment-post-thumbnail size-post-thumbnail wp-post-image\" alt=\"\" decoding=\"async\" loading=\"lazy\" \/><\/div><p>\r\n\r\n\r\n\r\n\r\n\r\nGuest Writer: Shweta Pujari\r\n\r\nShweta Pujari is the Product Manager for AI and GenAI. In this blog post, she joins me to demonstrate how to use the new MATLAB MCP Client to build agentic... <a class=\"read-more\" href=\"https:\/\/blogs.mathworks.com\/deep-learning\/2025\/12\/10\/matlab-mcp-client-on-github\/\">read more >><\/a><\/p>","protected":false},"author":230,"featured_media":19033,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":[],"categories":[74,75],"tags":[],"_links":{"self":[{"href":"https:\/\/blogs.mathworks.com\/deep-learning\/wp-json\/wp\/v2\/posts\/18997"}],"collection":[{"href":"https:\/\/blogs.mathworks.com\/deep-learning\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blogs.mathworks.com\/deep-learning\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blogs.mathworks.com\/deep-learning\/wp-json\/wp\/v2\/users\/230"}],"replies":[{"embeddable":true,"href":"https:\/\/blogs.mathworks.com\/deep-learning\/wp-json\/wp\/v2\/comments?post=18997"}],"version-history":[{"count":22,"href":"https:\/\/blogs.mathworks.com\/deep-learning\/wp-json\/wp\/v2\/posts\/18997\/revisions"}],"predecessor-version":[{"id":19037,"href":"https:\/\/blogs.mathworks.com\/deep-learning\/wp-json\/wp\/v2\/posts\/18997\/revisions\/19037"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/blogs.mathworks.com\/deep-learning\/wp-json\/wp\/v2\/media\/19033"}],"wp:attachment":[{"href":"https:\/\/blogs.mathworks.com\/deep-learning\/wp-json\/wp\/v2\/media?parent=18997"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blogs.mathworks.com\/deep-learning\/wp-json\/wp\/v2\/categories?post=18997"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blogs.mathworks.com\/deep-learning\/wp-json\/wp\/v2\/tags?post=18997"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}