Back to MCP directory
publicPublicdnsLocal runtime

mcp-terminal-server

Model Context Protocol (MCP)的终端服务器实现,提供安全可控的终端命令和npm操作访问。

article

README

🚀 @modelcontextprotocol/server-terminal

这是为模型上下文协议(MCP)实现的终端服务器,能为终端命令和npm操作提供安全且可控的访问,有效保障操作的安全性与规范性。

🚀 快速开始

该终端服务器为模型上下文协议(MCP)提供了对终端命令和npm操作的安全且受控的访问。下面将介绍其功能、安装、配置和使用方法。

✨ 主要特性

  • 可执行带有完全控制权限的shell命令,确保操作的全面性。
  • 具备内置的npm操作,如安装依赖包、运行脚本等,方便项目管理。
  • 支持超时处理,避免长时间无响应的操作占用资源。
  • 通过允许的命令列表进行安全管理,有效防止非法命令的执行。
  • 支持环境变量管理,可灵活配置运行环境。
  • 能够对工作目录进行控制,确保操作在指定的目录下进行。
  • 提供TypeScript支持,便于开发者进行类型检查和开发。

📦 安装指南

使用以下命令进行安装:

npm install @modelcontextprotocol/server-terminal

📚 详细文档

配置

将以下内容添加到您的MCP配置中:

{
  "terminal": {
    "command": "npx",
    "args": ["-y", "@modelcontextprotocol/server-terminal"],
    "autoApproveScope": ["execute_command", "npm_install", "npm_run"],
    "config": {
      "allowedCommands": ["npm", "node", "git"],
      "defaultTimeout": 30000,
      "defaultCwd": "/your/project/path",
      "environmentVariables": {
        "NODE_ENV": "development"
      }
    }
  }
}

💻 使用示例

基础用法

// 执行命令
const result = await terminal.executeCommand('ls', ['-la'], {
  cwd: '/some/path'
});

// 安装npm包
await terminal.install('typescript');

// 运行npm脚本
await terminal.runScript('build');

// 直接执行npm命令
await terminal.dev();  // npm run dev
await terminal.build();  // npm run build
help

Runtime guide

cloud

Hosted runtime

Hosted servers run from a provider-managed environment. You usually connect the MCP client to the hosted endpoint or follow the provider's authorization flow, without keeping a local process alive

  1. Open provider connection page
  2. Authorize or copy endpoint
  3. Connect from your MCP client
terminal

Local runtime / other methods

Local servers run on your own machine or infrastructure. You normally copy the server_config into your MCP client, install the required package, and provide env variables from env_schema when needed

  1. Copy server_config
  2. Install required package
  3. Fill env variables and restart client