使用说明
终端MCP服务器
一种模型上下文协议(MCP)服务器,允许通过Claude Desktop执行终端命令。
特性
- 执行任何带有参数和选项的终端命令
- 在保持状态的同时在目录之间导航
- 获取终端环境信息
- 完整输出捕获(stdout、stderr、退出代码)
- 正确的错误处理和格式化
先决条件
- Node.js v18或更高版本
- TypeScript
- 克劳德桌面
安装
- 克隆存储库:
git clone https://github.com/stat-guy/terminal.git
cd terminal
- 安装依赖项:
npm install
- 构建项目:
npm run build
地方发展设置
-
创建或编辑您的Claude Desktop配置文件:
- 在 macOS 上:
~/Library/Application Support/Claude/claude_desktop_config.json - 在Windows上:
%APPDATA%\\Claude\\claude_desktop_config.json
- 在 macOS 上:
添加以下配置:
{
"mcpServers": {
"terminal": {
"command": "node",
"args": [
"[PATH_TO_REPO]/dist/index.js"
],
"env": {
"PERMISSION_REQUIRED": "true"
}
}
}
}
替换 [PATH_TO_REPO] 使用克隆存储库的实际路径。
- 重新启动克劳德桌面
可用工具
execute_命令
- 执行任何终端命令
- 支持命令参数和选项
- 捕获完整输出和退出代码
change_directory
- 更改当前工作目录
- 在命令之间保持状态
- 支持相对和绝对路径
get_current目录
- 获取当前工作目录路径
get_terminal_info
- 获取终端环境信息
- 显示shell、用户、平台和最近的命令历史记录
使用示例
让Claude执行以下终端命令:
Can you check what's in my current directory?
-> Executes: ls -la
Can you tell me the current directory?
-> Executes: pwd
Can you change to the Downloads folder?
-> Executes: cd ~/Downloads
安全考虑
- 服务器需要通过Claude Desktop获得明确的用户权限才能执行命令
- 环境变量可以通过配置进行控制
- 命令执行包括超时和错误处理
发展
- 注意变化:
npm run watch
- 测试更改:
- 在中更改源文件
src/ - 使用重建
npm run build - 重新启动Claude Desktop以加载更改
项目结构
/
├── src/
│ └── index.ts # Main server implementation
├── package.json # Project configuration and dependencies
├── tsconfig.json # TypeScript configuration
└── README.md # This file
贡献
欢迎投稿!请随时提交拉取请求。
许可证
MIT许可证
