Skip to content

CharlieKerfoot/code-execution-mcp

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Code Executer MCP

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.

Implementation

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.

Usage

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.

  1. Clone this github repo.

  2. Run

npm i
  1. Run
npm run build
  1. After installing Claude for Desktop, open the file ~/Library/Application Support/Claude/claude_desktop_config.json

  2. Paste the following JSON

{
  "mcpServers": {
    "code_execution": {
      "command": "node",
      "args": ["/ABSOLUTE/PATH/TO/PARENT/FOLDER/code-execution-mcp/build/index.js"]
    }
  }
}
  1. 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.

  1. 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

About

MCP Server that allows AI models to run user-inputted code

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published