Shell命令执行服务器

专为Zed IDE设计的Shell命令执行服务器,支持git和pnpm命令的安全执行及文件读取功能。

  • by Entropy-Is-Software-Development
  • TypeScript
  • 本地部署
  • 更新于
在 GitHub 查看 Entropy-Is-Software-Development/zed-shell-mcp-server

使用说明

Zed Shell MCP服务器

该项目提供了 模型上下文协议(MCP) 服务器被设计为用作shell扩展 Zed IDE它允许Zed安全地执行shell命令的白名单(git, pnpm)并从工作区读取文件。

特性

  • 安全命令执行: 只允许 git 和 pnpm 要执行的命令,防止任意shell访问。
  • 文件系统访问: 提供用于读取项目工作区中多个文件内容的工具。
  • 严格打字: 使用TypeScript构建,并使用Zod模式进行验证。
  • 林: Biome可以保持代码质量。

安装和设置

这些说明解释了如何设置服务器以与Zed IDE一起使用。

先决条件

步骤

  1. 克隆存储库:

    git clone <your-repository-url>
    cd zed-shell-mcp
    
  2. 安装依赖关系:

    pnpm install
    
  3. 构建服务器:

    pnpm build
    

    这将把TypeScript源代码编译成JavaScript dist/ 目录。

  4. 配置Zed: 打开Zed并转到您的设置文件(settings.json).你需要添加一个 language_server 指向已编译服务器脚本的配置。这个命令告诉Zed如何启动MCP服务器并与之通信。

    将以下内容添加到您的 settings.json:

    {
      // ... your other settings
      "language_servers": {
        // ... your other language servers
        "zed-shell-mcp": {
          "command": "node",
          "arguments": [
            "/path/to/your/zed-shell-mcp/dist/index.js"
          ]
        }
      }
    }
    

    重要提示: 替换 /path/to/your/zed-shell-mcp 带有克隆此存储库的绝对路径。

  5. 指导AI代理: 当将AI代理与此服务器一起使用时,您必须向其提供如何正确使用工具的说明。复制下面的文本,并在与代理启动会话时将其包含在初始提示或上下文中。

    ## Instructions for using the git-pnpm-shell MCP Server
    
    To ensure that commands and file operations are performed in the correct project directory, you **must** include the `cwd` parameter in every tool call to this server. 
    
    - **`execute_command`**: Use this for `git` and `pnpm` commands.
      - **Example**: `execute_command(command='git status', cwd='C:\\path\\to\\your\\project')`
    
    - **`read_many_files`**: Use this to read files from the project.
      - **Example**: `read_many_files(paths=['src/index.js'], cwd='C:\\path\\to\\your\\project')`
    
    **IMPORTANT**: The `cwd` parameter must be the absolute path to the root of the project you are working on. Without it, the server will not be able to access the correct files.
    
  6. 重新启动Zed: 保存设置文件后,重新启动Zed以确保它获取新的语言服务器配置。

用法

安装和配置后,Zed的AI助手将可以使用服务器。您可以要求它执行使用提供的工具的操作。

Zed提示示例

  • “使用 execute_command 运行工具 git status 并向我展示输出结果。"
  • “内容是什么 src/index.ts 和 package.json?使用 read_many_files 工具。"
  • “使用 pnpm install 添加新的依赖关系。"

测试

此项目使用 维测试 用于运行测试。您可以使用以下命令运行基本测试套件:

pnpm basic_test

发展

  • 要在开发模式下运行服务器,请执行以下操作: pnpm start
  • 要整理和格式化代码,请执行以下操作: pnpm biome check --write ./src
  • 要运行TypeScript编译器: pnpm build