内容
# Pest MCP Server
Pest PHP 测试框架文档参考的 MCP 服务器
这是一个基于 TypeScript 的 MCP 服务器,提供 Pest PHP 测试框架文档的参考信息。它实现了一个模型上下文协议(Model Context Protocol,MCP)服务器,帮助 AI 助手直接从官方 Pest 文档库访问 Pest 文档和示例。
## 特性
### 工具
- `list_pest_topics` - 获取所有可用的 Pest 文档主题列表
- `get_pest_topic_details` - 获取特定 Pest 主题的详细信息
- `get_pest_topic_examples` - 获取特定 Pest 主题的使用示例
- `search_pest_docs` - 按关键字搜索 Pest 文档中的主题
- `list_pest_categories` - 获取所有 Pest 文档类别的列表
### 功能
该服务器从以下来源获取并缓存信息:
- 官方 Pest 文档 GitHub 仓库 (https://github.com/pestphp/docs)
- 使用每个文档主题的原始 Markdown 文件
- 按类别组织主题(入门、测试基础、高级测试等)
- 本地缓存文档文件以避免重复下载
它提供结构化数据,包括:
- 来自 Markdown 文件的完整主题内容
- 分类文档结构(入门、测试基础、高级测试、测试管理、可扩展性、高级特性、配置与 CI、参考与迁移、新闻与社区)
- 提取的代码示例及语言检测
- 带有标题和锚点的章节内容
- 智能描述提取
- 常见主题的后台预加载
- 持久文件缓存以供离线使用
## 开发
安装依赖:
```bash
npm install
```
构建服务器:
```bash
npm run build
```
进行自动重建的开发:
```bash
npm run watch
```
## 与 Augment 的使用
一旦您将 Pest MCP 服务器与 Augment 配置完成,您可以在 VS Code 环境中直接访问 Pest 文档。以下是一些使用示例:
### 列出 Pest 文档主题
您可以请求 Augment 列出所有可用的 Pest 文档主题:
```
What Pest documentation topics are available?
```
或者按类别列出主题:
```
What Pest documentation topics are available in the "Testing Basics" category?
```
```
Show me all the topics in the "Advanced Testing" category.
```
### 获取主题详细信息
您可以请求特定 Pest 主题的详细信息:
```
Show me the documentation for Pest installation.
```
```
Explain Pest expectations in detail.
```
```
I need help understanding Pest's arch testing system.
```
### 查找代码示例
您可以请求特定主题的代码示例:
```
Show me examples of Pest test writing.
```
```
Give me code examples for Pest expectations.
```
```
How do I implement datasets in Pest? Show me some examples.
```
### 搜索文档
您可以在 Pest 文档中搜索特定概念:
```
Search Pest documentation for "mocking".
```
```
Find information about mutation testing in Pest.
```
```
What does Pest documentation say about test coverage?
```
### 结合编码任务
您可以将文档查询与编码任务结合起来:
```
I need to write tests for my PHP application using Pest. Show me the documentation and then help me implement it.
```
```
Help me create Pest tests for user authentication based on Pest documentation.
```
```
I'm working on a Laravel app. Show me the Pest documentation for testing and help me set up my test suite.
```
### 探索 Pest 特性
您可以按类别探索 Pest 特性:
```
What are the main testing features available in Pest?
```
```
Tell me about Pest's architecture testing capabilities.
```
```
What are the different ways to organize tests in Pest?
```
## 安装
### Augment 配置
要在 Visual Studio Code 中与 Augment 一起使用:
1. 如果尚未安装,请从 VS Code 市场安装 Augment 扩展。
2. 如果您还没有为 MCP 服务器创建新目录:
```bash
mkdir -p ~/.augment/mcp-servers
```
3. 将此仓库克隆到该目录中:
```bash
git clone https://github.com/your-username/pest-mcp-server.git ~/.augment/mcp-servers/pest-mcp-server
```
4. 安装依赖并构建服务器:
```bash
cd ~/.augment/mcp-servers/pest-mcp-server
npm install
npm run build
```
5. 通过将其添加到您的 Augment 配置中来配置 Augment 使用此 MCP 服务器:
打开 VS Code 设置(在 Mac 上为 Cmd+,,在 Windows/Linux 上为 Ctrl+,),搜索 "Augment",找到 "Augment: MCP Servers" 设置。点击 "Edit in settings.json" 并添加以下内容:
```json
"augment.mcpServers": {
"pest-server": {
"command": "node",
"args": ["~/.augment/mcp-servers/pest-mcp-server/build/index.js"]
}
}
```
或者,您可以使用服务器的绝对路径:
```json
"augment.mcpServers": {
"pest-server": {
"command": "node",
"args": ["/absolute/path/to/pest-mcp-server/build/index.js"]
}
}
```
6. 重启 VS Code 以应用更改。
7. 现在您可以在 PHP 项目中使用 Pest 文档工具与 Augment 结合使用!
### Claude Desktop 配置
要与 Claude Desktop 一起使用,添加服务器配置:
在 MacOS 上:`~/Library/Application Support/Claude/claude_desktop_config.json`
在 Windows 上:`%APPDATA%/Claude/claude_desktop_config.json`
#### 选项 1:使用本地构建
```json
{
"mcpServers": {
"pest-server": {
"command": "/path/to/pest-mcp-server/build/index.js"
}
}
}
```
#### 选项 2:使用 npx 命令
```json
{
"mcpServers": {
"pest-server": {
"command": "npx",
"args": ["-y", "pest-mcp-server"]
}
}
}
```
### Windsurf 配置
将以下内容添加到您的 `./codeium/windsurf/model_config.json`:
```json
{
"mcpServers": {
"pest-server": {
"command": "npx",
"args": ["-y", "pest-mcp-server"]
}
}
}
```
### Cursor 配置
将以下内容添加到您的 `.cursor/mcp.json`:
```json
{
"mcpServers": {
"pest-server": {
"command": "npx",
"args": ["-y", "pest-mcp-server"]
}
}
}
```
### 调试
由于 MCP 服务器通过 stdio 进行通信,调试可能会比较困难。我们建议使用 [MCP Inspector](https://github.com/modelcontextprotocol/inspector),它作为一个包脚本可用:
```bash
npm run inspector
```
Inspector 将提供一个 URL,以便在您的浏览器中访问调试工具。
### 故障排除
如果您遇到 Pest MCP 服务器的问题,请尝试以下解决方案:
1. **服务器无响应**:
- 确保服务器已正确安装并构建
- 检查配置中的路径是否正确
- 尝试重启 VS Code
- 检查 VS Code 输出面板中的任何错误消息(视图 > 输出,然后从下拉菜单中选择 "Augment")
2. **服务器崩溃或超时**:
- 服务器包含常见 Pest 主题的后备数据,因此即使无法连接到 GitHub,它仍应正常工作
- 如果您在公司防火墙或代理后,可能会阻止 GitHub API 请求
- 尝试手动运行服务器以查看任何错误输出:`node /path/to/pest-mcp-server/build/index.js`
- 服务器会在本地缓存文档文件,因此在第一次成功运行后应能离线工作
3. **数据不正确或缺失**:
- 服务器在内存中缓存数据以提高性能。如果您需要新数据,请重启 VS Code
- 如果特定主题缺失,您可以手动将其添加到源代码中的后备数据
- 要强制刷新缓存的文档文件,请删除 `cache` 目录并重启服务器
4. **Augment 找不到服务器**:
- 确保配置中的服务器名称完全匹配:`pest-server`
- 检查服务器的路径是否正确且可访问
- 尝试在配置中使用绝对路径而不是 `~`
5. **缓存问题**:
- 服务器将文档文件存储在与构建目录相邻的 `cache` 目录中
- 如果您在缓存文件上遇到问题,可以删除缓存目录以强制重新下载
- 确保运行服务器的进程对缓存目录具有写权限
## 贡献
欢迎对 Pest MCP 服务器的改进贡献!以下是您可以贡献的一些方式:
1. **错误报告**:如果您发现错误,请创建一个问题,详细说明重现步骤。
2. **功能请求**:如果您有新功能或改进的想法,请创建一个问题进行讨论。
3. **文档**:通过修复错误或添加示例来帮助改善文档。
4. **代码贡献**:提交错误修复或新功能的拉取请求。
### 开发流程
1. Fork 仓库
2. 创建功能分支 (`git checkout -b feature/amazing-feature`)
3. 进行更改
4. 提交更改 (`git commit -m 'Add some amazing feature'`)
5. 推送到分支 (`git push origin feature/amazing-feature`)
6. 打开拉取请求
### 跟进 Pest 文档
该 MCP 服务器旨在与最新的 Pest 文档一起使用。随着 Pest 的发展,服务器可能需要更新以支持新版本或文档结构的更改。
## 许可证
MIT