关于 MCP-Grep
MCP-Grep 是一个将本机 grep 命令封装为 MCP 服务的 Python 项目。它向 MCP 客户端提供文件内容搜索能力,适合需要让 LLM 或 Agent 直接检索本地日志和代码的用户。
主要功能
- 01封装系统 grep 二进制文件
- 02提供 grep 工具进行模式搜索
- 03提供 grep://info 资源返回版本信息
- 04支持大小写不敏感与上下文行
- 05支持固定字符串与递归目录搜索
- 06可通过 MCP Inspector 调试
适用场景
- 01让 AI 助手在日志文件中查找错误信息
- 02在项目目录中递归搜索代码片段
- 03通过自然语言描述发起文件搜索
MCP 相关
该项目是 MCP 服务,向 MCP 客户端暴露一个 grep 工具和一个 grep://info 资源。
配置
本地服务的配置在各客户端中通用,复制后粘贴到客户端的 MCP 配置文件即可。
工具
还没有获取到工具列表
本地服务需要在你的电脑上运行后才能读取工具,维护者暂未提供工具列表。
详细介绍
MCP-Grep
一个 grep 服务实现,通过 Model Context Protocol(MCP)暴露 grep 功能。
安装
通过 Smithery 安装
通过 Smithery 自动为 Claude Desktop 安装 Grep Server:
npx -y @smithery/cli install @erniebrodeur/mcp-grep --client claude
手动安装
pip install mcp-grep
使用
MCP-Grep 以服务形式运行,可供兼容 MCP 的客户端使用:
# Start the MCP-Grep server
mcp-grep-server
# Or use the MCP Inspector for interactive debugging and testing
mcp-grep-inspector
该服务暴露以下 MCP 功能:
- 资源:
grep://info- 返回有关系统 grep 二进制文件的信息 - 工具:
grep- 使用系统 grep 二进制文件在文件中搜索模式
特性
- 有关系统 grep 二进制文件的信息(路径、版本、支持的特性)
- 使用正则表达式在文件中搜索模式
- 支持常用的 grep 选项:
- 大小写不敏感匹配
- 上下文行(匹配项前后)
- 最大匹配数量
- 固定字符串匹配(非正则)
- 递归目录搜索
- 自然语言提示词理解,便于与大模型配合使用
- 通过 MCP Inspector 进行交互式调试和测试
API 使用示例
使用 MCP Python 客户端:
from mcp.client import MCPClient
# Connect to the MCP-Grep server
client = MCPClient()
# Get information about the grep binary
grep_info = client.get_resource("grep://info")
print(grep_info)
# Search for a pattern in files
result = client.use_tool("grep", {
"pattern": "search_pattern",
"paths": ["file.txt", "directory/"],
"ignore_case": True,
"recursive": True
})
print(result)
自然语言提示词
MCP-Grep 能够理解自然语言提示词,使其更易于与大模型配合使用。示例:
# Basic search
Search for 'error' in log.txt
# Case-insensitive search
Find all instances of 'WARNING' regardless of case in system.log
# With context lines
Search for 'exception' in error.log and show 3 lines before and after each match
# Recursive search
Find all occurrences of 'deprecated' in the src directory and its subdirectories
# Fixed string search (non-regex)
Search for the exact string '.*' in config.js
# Limited results
Show me just the first 5 occurrences of 'TODO' in the project files
# Multiple options
Find 'password' case-insensitively in all .php files, show 2 lines of context, and limit to 10 results
MCP Inspector 集成
MCP-Grep 包含 MCP Inspector 集成,用于交互式调试和测试:
# Start the MCP Inspector with MCP-Grep
mcp-grep-inspector
这会打开一个基于 Web 的 UI,你可以在其中:
- 浏览可用的资源和工具
- 使用不同参数测试 grep 操作
- 查看格式化后的结果
- 调试 grep 查询中的问题
开发
# Clone the repository
git clone https://github.com/erniebrodeur/mcp-grep.git
cd mcp-grep
# Install in development mode
pip install -e ".[dev]"
# Run tests
pytest
许可证
MIT
评论
支持 Markdown
一个开放协议,规定了 AI 应用如何以统一方式连接外部工具与数据源。客户端负责与模型对话,MCP 服务负责提供工具、资源和提示模板,两者通过标准消息通信,同一个服务可以被不同客户端复用。