MCP搜索服务添加福利群:解决AI开发者的「MCP实战痛点」一个通过模型上下文协议(MCP)提供grep功能的服务器实现。
要通过Smithery自动为Claude Desktop安装Grep服务器:
npx -y @smithery/cli install @erniebrodeur/mcp-grep --client claude
pip install mcp-grep
MCP-Grep作为服务器运行,可由支持MCP的客户端使用:
# 启动MCP-Grep服务器
mcp-grep-server
# 或使用MCP Inspector进行交互式调试和测试
mcp-grep-inspector

该服务器提供以下MCP功能:
grep://info - 返回系统grep二进制文件的信息grep - 使用系统grep二进制文件在文件中搜索模式使用MCP Python客户端:
from mcp.client import MCPClient
# 连接到MCP-Grep服务器
client = MCPClient()
# 获取grep二进制文件的信息
grep_info = client.get_resource("grep://info")
print(grep_info)
# 在文件中搜索模式
result = client.use_tool("grep", {
"pattern": "search_pattern",
"paths": ["file.txt", "directory/"],
"ignore_case": True,
"recursive": True
})
print(result)

MCP-Grep理解自然语言提示,便于与LLM配合使用。示例:
# 基本搜索 在log.txt中搜索'error' # 不区分大小写的搜索 在system.log中查找所有'WARNING'实例,不区分大小写 # 带上下文行 在error.log中搜索'exception',并显示每个匹配项前后3行 # 递归搜索 在src目录及其子目录中查找所有'deprecated'实例 # 固定字符串搜索(非正则表达式) 在config.js中精确搜索字符串'.*' # 限制结果数量 仅显示项目文件中前5个'TODO'实例 # 多个选项 在所有.php文件中不区分大小写地查找'password',显示2行上下文,并限制为10个结果
MCP-Grep包含MCP Inspector集成,用于交互式调试和测试:
# 使用MCP-Grep启动MCP Inspector
mcp-grep-inspector

这将打开一个基于Web的界面,您可以:
# 克隆仓库
git clone https://github.com/erniebrodeur/mcp-grep.git
cd mcp-grep
# 以开发模式安装
pip install -e ".[dev]"
# 运行测试
pytest

MIT