Skip to main content
Glama

MCP-Grep

通过模型上下文协议 (MCP) 公开 grep 功能的 grep 服务器实现。

安装

pip install mcp-grep

Related MCP server: cve-search_mcp

用法

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 选项:

    • 不区分大小写的匹配

    • 上下文行(匹配之前和之后)

    • 最大匹配数

    • 固定字符串匹配(非正则表达式)

    • 递归目录搜索

  • 自然语言提示理解,更易于与法学硕士 (LLM) 一起使用

  • 通过 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 能够理解自然语言提示,使其更易于与 LLM 一起使用。示例:

# 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 检查器集成

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

执照

麻省理工学院

-
security - not tested
A
license - permissive license
-
quality - not tested

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/erniebrodeur/mcp-grep'

If you have feedback or need assistance with the MCP directory API, please join our Discord server