Connecting LLMs to MCP-servers using the MCP-client package
Last updated
Was this helpful?
Last updated
Was this helpful?
We recently implemented an MCP client package in Midio that allows you to easily connect LLMs to any MCP server, as long as it supports the SSE transport. In this guide we’ll see how we can use the package, and show an example of how you can set up a local MCP server with a tunnel that allows Midio to connect to it.
First, add the mcp-client
package using the package manager.
The first thing we do is to add an instance of Connect to MCP Server
. This function accepts a name and version for our client, which we can choose ourselves, and the URL of the server we want to connect to.
This node takes care of the whole song and dance of connecting, initializing and setting up long-lived communication channels with the server.
To give our LLM node (for example open-ai Chat Complete
, which can be added from the package manager by searching for “open-ai”) access to the tools in our server, we can use the Get LLM Compatible Tools List
function. It retrieves the list of available tools from the server, and creates a handler function for each of them, which is automatically set up to relay any request from our LLM to be handled by the MCP server.
Now, all we have to do is connect the tools
output to the tools
input of our Chat Complete
node, and we’re good to go.
Finally, we disconnect from the server using Disconnect from MCP Server
.
We give our agent a system prompt so it understands it should manipulate a todo list, and then we can ask it to do something.
Here is a simple system prompt you can use:
Click the play button on the Connect to MCP Server
node to run the flow.
Most MCP-servers you'll find on the internet are programs you are expected to run locally on your machine, or host somewhere yourself. They are also usually designed for the STDIO transport, which is a kind of protocol which is typically only used when both the client and server are run on the same machine.
Then, in one terminal, run the following:
The first line installs the mcp-proxy
tool, and the next one starts it with the mcp-server-git
MCP server as a target. You should first navigate to a local git repository with which you want the server to interact.
You can then run:
To set up a tunnel to your local MCP server which your Midio client will be able to reach.
You should see something like the following:
You can then copy that URL into the Connect to MCP Server
node in midio.
Make sure you append "/sse" to the URL:
You’re all set. You can now run the flow from the Connect to MCP Server
node, and for example use the following system and user prompts for your Chat Complete
node.
Here is a simple system prompt for testing:
You can also check out these guides for how to connect your flows to a frontend made with Lovable.
A Fast Path to Functional RAG Agents
How to build a streaming agent using Server-Sent Events (SSE)
Let’s connect to an actual server. If you don’t have your own at hand, you can set one up in Midio by following .
Since Midio is hosted in the cloud, it can’t directly access your machine. But for testing purposes there are simple tools you can use to make this possible (we’ll use a tool called ). We can also easily create a mapping from STDIO to SSE using a tool called .
You need the python tool and to do the following. Please install them first.
You now have a simple MCP client flow set up, but the only way to interact with it is by manually running flows in the editor. Midio makes it super simple to expose your flows as API endpoints using the HTTP Endpoint
node, which you can read about .