M

MCP搜索服务

@erniebrodeur/mcp-grep
0 Stars 554 次浏览 erniebrodeur 更新于 2026-08-23

一种通过模型上下文协议(MCP)暴露 grep 功能的服务器实现,允许与 MCP 兼容的客户端使用正则表达式在文件中搜索模式。

该服务暂未提供标准配置,请参考 README 手动接入

服务介绍

MCP-Grep

一个通过模型上下文协议(MCP)暴露 grep 功能的服务器实现。

安装

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 选项:
    • 不区分大小写的匹配
    • 上下文行(匹配前后)
    • 最大匹配计数
    • 固定字符串匹配(非正则表达式)
    • 递归目录搜索
  • 自然语言提示理解,便于与大型语言模型(LLMs)配合使用
  • 通过 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 的用户界面,在这里你可以:

  • 探索可用的资源和工具
  • 用不同的参数测试 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

相关 MCP 服务