# 代码运行器
## 基本信息
- Slug: `formulahendry-mcp-server-code-runner`
- Source: modelscope
- Publisher: @formulahendry/mcp-server-code-runner
- Categories: developer-tools / os-automation
- Hosted: No
- License: MIT License
- Source URL: https://www.modelscope.cn/mcp/servers/@formulahendry/mcp-server-code-runner
## 简介
用于运行代码片段并显示结果的MCP服务器。
## 安装提示

```bash
### 使用 npx 在 Claude Desktop 上安装 在`claude_desktop_config.json`中的配置:
```

## MCP Server 详情

# Code Runner MCP Server
[![NPM Downloads](https://img.shields.io/npm/d18m/mcp-server-code-runner)](https://www.npmjs.com/package/mcp-server-code-runner) [![smithery badge](https://smithery.ai/badge/@formulahendry/mcp-server-code-runner)](https://smithery.ai/server/@formulahendry/mcp-server-code-runner) [![Docker Pulls](https://img.shields.io/docker/pulls/formulahendry/mcp-server-code-runner)](https://hub.docker.com/r/formulahendry/mcp-server-code-runner)

用于运行代码片段并显示结果的MCP服务器。

它支持运行多种编程语言：**JavaScript, PHP, Python, Perl, Perl 6, Ruby, Go, Lua, Groovy, PowerShell, BAT/CMD, BASH/SH, F# Script, C# Script, VBScript, TypeScript, CoffeeScript, Scala, Swift, Julia, Crystal, OCaml Script, R, AppleScript, Elixir, Clojure, Racket, Scheme, AutoHotkey, AutoIt, Kotlin Script, Dart, Haskell, Ni, Lisp, Kit, V, SCSS, Sass**。完整的列表可以在[constants.ts](https://github.com/formulahendry/mcp-server-code-runner/blob/main/src/constants.ts)中查看。

<a href="https://glama.ai/mcp/servers/d3mluq4vy9">
  <img width="380" height="200" src="https://glama.ai/mcp/servers/d3mluq4vy9/badge" alt="mcp-server-code-runner MCP server" />
</a>

## 设置

### 使用 npx 在 VS Code 中安装

使用以下按钮在VS Code中安装Code Runner MCP服务器：

[![Install in VS Code Insiders](https://img.shields.io/badge/Install_MCP_Server-VS_Code_Insiders-24bfa5)](https://insiders.vscode.dev/redirect?url=vscode-insiders%3Amcp%2Finstall%3F%257B%2522name%2522%253A%2522mcp-server-code-runner%2522%252C%2522command%2522%253A%2522npx%2522%252C%2522args%2522%253A%255B%2522-y%2522%252C%2522mcp-server-code-runner%2540latest%2522%255D%257D)

或者，您可以在`settings.json`中添加配置：

```json
{
  "mcp": {
    "inputs": [],
    "servers": {
      "mcp-server-code-runner": {
        "command": "npx",
        "args": [
          "-y",
          "mcp-server-code-runner@latest"
        ],
      }
    }
  }
}
```


### 使用 npx 在 Claude Desktop 上安装

在`claude_desktop_config.json`中的配置: 

```json
{
  "mcpServers": {
    "mcp-server-code-runner": {
      "command": "npx",
      "args": [
        "-y",
        "mcp-server-code-runner@latest"
      ],
    }
  }
}
```


### 使用 Docker 安装

以VS Code为例。在`settings.json`中的配置：

```json
{
  "mcp": {
    "inputs": [],
    "servers": {
      "mcp-server-code-runner": {
        "command": "docker",
        "args": [
          "run",
          "--rm",
          "-i",
          "formulahendry/mcp-server-code-runner"
        ]
      }
    }
  }
}
```


### 通过 Smithery 安装

> **_注意:_** 这将使Code Runner MCP服务器在一个由Smithery托管的远程容器环境中运行。

要通过[Smithery](https://smithery.ai/server/@formulahendry/mcp-server-code-runner)自动为Claude Desktop安装Code Runner MCP服务器：

```bash
npx -y @smithery/cli install @formulahendry/mcp-server-code-runner --client claude
```


### Windows上的npx问题

在Windows上，[MCP服务器可能无法通过`npx`连接](https://github.com/modelcontextprotocol/servers/issues/40)。

您可以尝试以下两种解决方法：

#### 使用 bunx

1. 安装[Bun](https://bun.sh/docs/installation)。
2. 在配置中，将`npx`替换为`bunx`。

#### 使用 cmd

以下是VS Code在`settings.json`中的配置示例：

```json
{
  "mcp": {
    "inputs": [],
    "servers": {
      "mcp-server-code-runner": {
        "command": "cmd",
        "args": [
          "/c",
          "npx",
          "-y",
          "mcp-server-code-runner@latest"
        ],
      }
    }
  }
}
```


## 使用

在使用Code Runner MCP服务器之前，请确保您希望运行的编程语言的解释器或编译器已设置在`PATH`环境变量中。

在已配置了Code Runner MCP服务器的应用程序中尝试以下指令：
* `Run the JavaScript Code: console.log(5+6)`
* `Where is temporary folder in my OS? Use run-code tool`
* `How many CPUs do I have in my machine? Use run-code tool`

![](./images/usage-confirm.png)

![](./images/usage-result.png)

## 构建自己的MCP服务器

想要构建自己的MCP服务器？试试[Yeoman Generator for MCP Server](https://www.npmjs.com/package/generator-mcp)来创建您的MCP服务器项目！

