And as we can see here in the function, I just do have one simple function which is the runJS ephemeral, and then passing the LLM generated code to this function, which we will see in a moment. I'm taking the output, and I'm returning the output as an object, which contains content, which is basically an array. Now, this array is how MCP is expecting the return. So I am passing, for example, the type, which is a text in this case, and then I'm passing the text itself. So in this case, I'm just passing the node.js process output to the LLM back. And then last but not least, I'm connecting the server to the SDDO transport.
Alright, let's see now how we can actually run the code safely in Docker. So as we can see, the function is relatively simple. The first thing that we can do is, first, we generate a container ID, like a random one. Then we create, now we run the container, and we run it with the node.lts.lim image, but of course we can customize the image. And then we use a simple trick, which is the tail, minus f, slash dev, slash null, in order to tell the system, okay, you cannot, you don't have to stop. So please stay idle and wait for me. Then what I'm going to do is, I'm going to copy the code into the index.js file, which I'm going to create in a template here. And then I'm going to copy this file into Docker. And then I'm going to execute this, I'm going to execute with node index.js this code, and I'm going to get the output from the Docker container. Last but not least, as you may guess, I'm just doing some cleanup. So I will be able to kill the Docker container and remove the temp directory. And that's it, that's the gist of the solution.
The cool thing about this solution is that, as you may guess, expanding it is relatively simple. In fact, we will see that expanding this solution, this runtime, to Python, it requires changing three lines of code at least. The first thing that I'm going to change is, of course, the name of the function, which is not anymore like run.js, but run Python ephemeral. Then I'm going to change how we structure the container ID string, but that's not really needed. Now the three changes that are needed are, well, first of all, instead of using Node.js, the node image, I'm going to use an image with Python pre-sold, so it's the Python 3.11 sling. Then when I write the file, it's going to be not index.js, but script.pi. And then instead of launching the script with node index.js, I'm just going to launch Python script.pi, and that's it. So as we can see, this kind of solution is very expandable to other technologies while keeping the same core idea. Of course, let's keep in mind something super important, which is the tool usage accuracy is not perfect. So function calling is one of the capabilities of LLMs, like summarization, rewriting, and so on. It's one of their capabilities, but it's not something which is perfect.
Comments