模型上下文协议工具扩展

一个通用的模型上下文协议(MCP)工具扩展,用于pi编码代理,支持本地和远程服务器配置。

  • by tickernelz
  • TypeScript
  • 本地部署
  • 12 星标
  • 更新于
在 GitHub 查看 tickernelz/pi-mcp-tools

使用说明

@zhafron/pi-mcp工具

用于pi编码代理的通用MCP(模型上下文协议)工具扩展。

安装

pi install git:github.com/tickernelz/pi-mcp-tools

或者通过npm:

pi install npm:@zhafron/pi-mcp-tools

快速开始

增添 ~/.pi/agent/settings.json:

{
  "mcp": {
    "web-search": {
      "type": "local",
      "command": ["npx", "-y", "@zhafron/mcp-web-search"]
    },
    "context7": {
      "type": "local",
      "command": ["npx", "-y", "@upstash/context7-mcp", "--api-key", "your-api-key"]
    },
    "deepwiki": {
      "type": "remote",
      "url": "https://mcp.deepwiki.com/mcp"
    },
    "filesystem": {
      "type": "local",
      "command": ["npx", "-y", "@modelcontextprotocol/server-filesystem", "/path/to/project"],
      "enabled": true
    }
  }
}

配置格式

每个MCP服务器都是以下密钥 "mcp" 具有以下结构:

本地服务器

{
  "server-name": {
    "type": "local",
    "command": ["npx", "-y", "package-name", "args..."],
    "env": { "KEY": "value" },
    "cwd": "/path/to/workdir",
    "enabled": true,
    "toolPrefix": "prefix",
    "filterPatterns": ["pattern1", "pattern2"]
  }
}
字段 类型 必填 描述
type "local" ✓ 服务器类型
command string[] ✓ 命令和参数作为数组
env object - 环境变量
cwd string - 工作目录
enabled boolean - 启用/禁用(默认值:true)
toolPrefix string - 自定义工具名称前缀
filterPatterns string[] - 用于筛选工具的正则表达式

远程服务器

{
  "server-name": {
    "type": "remote",
    "url": "https://example.com/mcp",
    "headers": { "Authorization": "Bearer token" },
    "enabled": true,
    "toolPrefix": "prefix"
  }
}
字段 类型 必填 描述
type "remote" ✓ 服务器类型
url string ✓ MCP服务器URL(自动检测传输)
headers object - HTTP标头
enabled boolean - 启用/禁用(默认值:true)
toolPrefix string - 自定义工具名称前缀

运输自动检测:

  • Websocket: ws://, wss://,或URL包含“websocket”
  • StreamableHTTP:MCP协议2025-xx(最新标准)
  • SSE:遗留服务器或回退

命令

命令 描述
/mcp-status 通过健康检查显示服务器状态
/mcp-reconnect 重新连接所有服务器
/mcp-toggle <server> 打开/关闭服务器
/mcp-list 列出可用工具
/mcp-tools 按服务器切换工具(交互式UI)

标志: --mcp-debug -启用调试日志记录

工具

工具自动注册为: mcp_{server}_{tool} 或 {toolPrefix}_{tool}

例子: mcp_web-search_search, ctx7_read_docs

例子

多个供应商

{
  "mcp": {
    "context7": {
      "type": "local",
      "command": ["npx", "-y", "@upstash/context7-mcp", "--api-key", "ctx7sk-..."]
    },
    "deepwiki": {
      "type": "remote",
      "url": "https://mcp.deepwiki.com/mcp"
    },
    "chrome-devtools": {
      "type": "local",
      "command": ["npx", "-y", "chrome-devtools-mcp@latest"]
    },
    "web-search": {
      "type": "local",
      "command": ["npx", "-y", "@zhafron/mcp-web-search"]
    },
    "octocode": {
      "type": "local",
      "command": ["npx", "octocode-mcp@latest"]
    }
  }
}

使用环境变量

{
  "mcp": {
    "github": {
      "type": "local",
      "command": ["npx", "-y", "@modelcontextprotocol/server-github"],
      "env": { "GITHUB_TOKEN": "ghp_..." }
    },
    "postgres": {
      "type": "local",
      "command": ["npx", "-y", "@modelcontextprotocol/server-postgres", "postgresql://localhost/db"]
    }
  }
}

暂时禁用服务器

{
  "mcp": {
    "web-search": {
      "type": "local",
      "command": ["npx", "-y", "@zhafron/mcp-web-search"],
      "enabled": true
    },
    "context7": {
      "type": "local",
      "command": ["npx", "-y", "@upstash/context7-mcp"],
      "enabled": false
    }
  }
}

禁用单个工具

工具可以通过以下方式禁用 /mcp-tools 命令(交互式UI)或在设置中手动:

{
  "mcp": { ... },
  "mcpDisabledTools": ["mcp_context7_query-docs", "mcp_web-search_fetch_url"]
}

禁用工具在全球范围内持续存在 ~/.pi/agent/settings.json.

发展

npm install
npm run build       # Type check
npm run format      # Format code
npm run format:check

发布

npm version patch  # Bump version
git push --tags    # Trigger npm publish

链接

许可证

麻省理工学院