A Model Context Protocol (MCP) server which allows AI models to run code. The user prompts the model with code of a specified language and the model will execute it, displaying the stdout, stderr, and exit code.
The server uses the piston api to execute code in a secure, remote enviornment and then returns the output to the AI model.
Information on MCP servers and how to implement them can be found here.
This MCP was used and tested with Claude for Desktop, but it should work for other LLMs and AI tools. This guide will only cover Claude Desktop though.
-
Clone this github repo.
-
Run
npm i
- Run
npm run build
-
After installing Claude for Desktop, open the file
~/Library/Application Support/Claude/claude_desktop_config.json
-
Paste the following JSON
{
"mcpServers": {
"code_execution": {
"command": "node",
"args": ["/ABSOLUTE/PATH/TO/PARENT/FOLDER/code-execution-mcp/build/index.js"]
}
}
}
- Save the file and launch Claude.
There should be a slider icon under the prompt bar. When clicked, the code_exection MCP should be toggleable.
- That's it!
Try using the MCP with prompts like
run this python code:
import random
print("Random Numbers:", [random.randint(1, 100) for _ in range(5)])
print("Random Choice:", random.choice(['apple', 'banana', 'cherry', 'date']))
print("Random Float:", round(random.random() * 100, 2))
for i in range(3):
print(f"Line {i+1}: {'*' * random.randint(3, 10)}")
print("Done!")
or
Generate random C code (that prints to the stdout) and run it