
简单的MCP服务器来封装本地的GREP实例。
概览
一个grep服务器实现,通过模型上下文协议(MCP)暴露grep功能。 通过 Smithery 自动安装 Grep Server for Claude Desktop: MCP-Grep 作为服务器运行,供兼容 MCP 的客户端使用: 服务器暴露以下MCP功能: - grep://info - 返回关于系统grep二进制的信息- grep - 使用系统grep二进制在文件中搜索模式 - 关于系统grep二进制的信息(路径、版本、支持功能)- 使用正则表达式在文件中搜索模式 - 支持常见的grep选项:- 大小写不区分匹配 - 上下文行(匹配前后匹配) - 最大匹配计数 - 固定字符串匹配(非正则表达式) - 递归目录搜索 - 自然语言提示理解,便于LLM使用- 通过MCP Inspector进行交互式调试和测试 MCP-Grep 能够理解自然语言提示,使其更容易用于大型语言模型(LLM)。
概述(AI 翻译)
一个grep服务器实现,通过模型上下文协议(MCP)暴露grep功能。
安装
通过Smithery安装
通过 Smithery 自动安装 Grep Server for Claude Desktop:
手动安装
用途
MCP-Grep 作为服务器运行,供兼容 MCP 的客户端使用:
服务器暴露以下MCP功能:
- Resource:
grep://info- 返回关于系统grep二进制的信息 - 工具:
grep- 使用系统 grep 二进制在文件中搜索模式
特色
- 关于系统grep二进制文件的信息(路径、版本、支持功能)
- 使用正则表达式在文件中搜索模式
- 支持常见的grep选项:
- 大小写不相关匹配
- 上下文线(比赛前后)
- 最大匹配数
- 固定字符串匹配(非正则表达式)
- 递归目录搜索
- 自然语言提示理解,便于与大型语言模型(LLM)的结合使用
- 通过MCP Inspector进行交互式调试和测试
API 使用示例
使用 MCP Python 客户端:
自然语言提示
MCP-Grep 能够理解自然语言提示,使其更易于与大型语言模型(LLM)搭配使用。示例:
本页由 AI 翻译,技术细节请以原文为准。
README
以下为原文 README 节选,完整内容请查看原文。
MCP-Grep
A grep server implementation that exposes grep functionality through the Model Context Protocol (MCP).
Installation
Installing via Smithery
To install Grep Server for Claude Desktop automatically via Smithery:
npx -y @smithery/cli install @erniebrodeur/mcp-grep --client claude
Manual Installation
pip install mcp-grep
Usage
MCP-Grep runs as a server that can be used by MCP-compatible clients:
# Start the MCP-Grep server
mcp-grep-server
# Or use the MCP Inspector for interactive debugging and testing
mcp-grep-inspector
The server exposes the following MCP functionality:
- Resource:
grep://info- Returns information about the system grep binary - Tool:
grep- Searches for patterns in files using the system grep binary
Features
- Information about the system grep binary (path, version, supported features)
- Search for patterns in files using regular expressions
- Support for common grep options:
- Case-insensitive matching
- Context lines (before and after matches)
- Maximum match count
- Fixed string matching (non-regex)
- Recursive directory searching
- Natural language prompt understanding for easier use with LLMs
- Interactive debugging and testing through MCP Inspector
Example API Usage
Using the MCP Python client:
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)
Natural Language Prompts
MCP-Grep understands natural language prompts, making it easier to use with LLMs. Examples:
# 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 Integration
MCP-Grep includes an MCP Inspector integration for interactive debugging and testing:
# Start the MCP Inspector with MCP-Grep
mcp-grep-inspector
This opens a web-based UI where you can:
- Explore available resources and tools
安装
npx -y @smithery/cli install @erniebrodeur/mcp-grep --client claude