mcp-rg-search
This server does not currently have a deployable release on Glama. Follow the repository's setup instructions to install and configure it for your MCP client, including any required credentials and local dependencies.
mcp-rg-search
一个只读的 MCP 服务,用于按文件内容检索。它是 ripgrep 的一层薄封装,但把 ripgrep 原有的几个坑逐一封住。
对外只暴露一个工具 search_content,重点解决 agent 真正关心的三件事:扫描预算显式化、遇不可读目录时诚实降级、返回契约稳定且不静默丢结果。
运行要求:Node.js ≥ 20,且能找到
rg(ripgrep)—— 在PATH上,或用RG_PATH显式指定(RG_PATH优先于PATH)。 零第三方依赖 —— MCP 协议直接基于 stdio JSON-RPC 实现。 平台范围:面向 Windows + DSH 验证;其它平台未验证。
为什么不能直接用 ripgrep?
人自己跑 rg 没问题。对 agent 来说它有几个锋利的边角,本服务就是为了把这些边角包起来:
直接用 | 本服务的做法 |
遇到一个不可读目录, | 降级:返回 |
扫描上限不可见 —— 进程就那么停了,你分不清「确实没命中」还是「预算耗尽」 | 显式: |
敏感文件( | 脱敏:敏感文件的路径与内容永不返回 —— 只留一个 |
想取最新的 N 条命中,得把整个结果集翻一遍 |
|
它还补上了 rg 本身没有的东西:非 UTF-8 编码支持(gb18030、big5、utf-16)、两段式检索(files → matches),以及一套跨版本稳定的字段词表。
Related MCP server: MCP Smart Filesystem Server
安装
从 npm(发布到 registry 后可用):
npm install -g mcp-rg-search从 GitHub 仓库(当前即可用):
npm install -g github:Fastunbeaten/mcp-rg-search第二条走 npm 的 git spec(直接从 GitHub 仓库安装),需要本机装有 git。包名
mcp-rg-search已在 npm 保留。
或者直接从一份检出运行:
node /path/to/mcp-rg-search/index.mjs服务通过 stdio 讲 MCP(协议版本 2024-11-05);把客户端的入口指向 index.mjs 即可。全局安装后入口也可以直接写 mcp-rg-search。
客户端配置
DSH(cordis.patch.yml):
- id: mcp-rg-search
name: '@deepseek-ai/dsh-mcp-client'
config:
serverName: rg-search
transport: stdio
command: node
args:
- '/absolute/path/to/mcp-rg-search/index.mjs'通用 MCP 客户端:
{
"mcpServers": {
"rg-search": {
"command": "node",
"args": ["/absolute/path/to/mcp-rg-search/index.mjs"]
}
}
}全局安装(npm install -g)之后,入口可以直接写可执行名,不必再指到 index.mjs:
- id: mcp-rg-search
name: '@deepseek-ai/dsh-mcp-client'
config:
serverName: rg-search
transport: stdio
command: mcp-rg-search工具:search_content
参数
参数 | 类型 | 默认值 | 约束 | 说明 |
| string | — | 必填,非空 | 搜索串。 |
|
|
| — |
|
| string | 服务进程工作目录 | — | 搜索根 —— 任何可读目录,或单个文件。 |
| string[] | — | — | 只搜匹配这些 glob 的文件。不含 |
| string[] |
| — | 排除 glob。默认值是 glob 模式 —— 传 |
|
|
| — |
|
| integer |
| 0–1000 | 每条命中前后各取几行上下文。 |
|
|
| — |
|
| integer |
| 0–1e6 | 最多返回多少条命中行( |
| integer |
| 1–1e7 | 最多扫描多少文件。 |
| integer |
| 1–1e5 | 每文件最多保留多少条命中行。 |
| integer |
| 0–1e5 | 每文件最多保留多少条上下文行。 |
| integer |
| 1–1e6 | 超长行截断到这个宽度,避免一行撑爆返回体。 |
| boolean |
| — | 只返回匹配片段,不返回整行。 |
| boolean |
| — | 允许模式跨行。 |
| integer |
| 0–1e6 | 跳过前 N 条结果(分页)。 |
| integer | — | 1–1e6 | 每个文件只保留行号最大的最后 N 条命中。结果仍按行号升序返回。优先于 |
| boolean |
| — | 遵守 |
| boolean |
| — | 跟随符号链接。 |
| boolean |
| — | 是否大小写敏感。 |
超范围的值一律以 invalid_args 拒绝 —— 不会被静默夹到边界。(schema 只对 tail 声明了 maximum,其余上界由服务端以同样方式拒绝。)
返回结构
{
"ok": true,
"mode": "files",
"query": "fetchUser",
"root": "src",
"encoding": "auto",
"files": [ { "path": "src/index.js", "matches": 5 } ],
"totals": { "files": 12, "matches": 87 },
"truncated": false,
"truncatedBy": null,
"limits": { "maxResults": 500, "maxFiles": 5000, "maxMatchesPerFile": 50, "maxColumns": 500, "maxContext": 200 },
"excludesApplied": ["**/node_modules/**", "**/.git/**", "**/.venv/**", "**/venv/**", "**/__pycache__/**"],
"onlyMatchingApplied": false,
"skipped": { "binary": 0, "sensitive": 0, "unreadable": 0 },
"skippedSamples": [],
"hint": null,
"elapsedMs": 42
}关键字段
字段 | 含义 |
| 只有真正失败时才为 |
| 回显本次的 output 取值( |
| 回显本次实际执行的东西( |
| 扫描的文件数 / 命中总数。 |
|
|
| 按原因分类的计数对象: |
| 整个数组最多 10 条样本(各原因共享同一配额,先占满的类别其余不再补),带 |
| 结果不完整。 |
| 为什么不完整: |
| 下一步该怎么做(收窄路径、加大上限、换编码……),没有则为 |
| 本次实际生效的预算。 |
| 实际生效的排除模式。 |
| 只在传了 |
多个上限同时触发时,truncatedBy 报优先级最高的那个:
max_matches_per_file (60) > max_context (55) > max_columns (50) > scan_limit (40) > max_results (30)错误码
错误码 | 含义 | 怎么办 |
| 参数缺失或超范围 | 改参数;报错信息里写明了约束 |
| 搜索根不存在 | 检查 |
| 找不到可用的 | 安装 ripgrep,或把 |
| 检索无法启动 | 检查路径与权限 |
失败时返回体形如:
{
"ok": false,
"error": "not_found",
"reason": "搜索根不存在:D:/some/path"
}reason 是中文说明,可直接展示给用户。dependency_unavailable 额外带 expected(找到的候选 rg 路径数组)与 installHint(安装提示)。
敏感文件
默认情况下,匹配这些模式的文件永不返回 —— 路径与内容都不返回:
**/.env* **/*.pem **/*.key
**/.ssh/** **/.aws/** **/*.credentials.yaml它们只计入 skipped.sensitive。
要换成自己的规则集,把 RG_PROTECTED_RULES 指向一个 JSON 文件:
[
{ "id": "D1", "scope": "file", "pattern": "**/.env*" },
{ "id": "D2", "scope": "directory", "pattern": "**/.ssh/**" }
]scope 取 file 或 directory。文件不存在或没有一条可用规则时,回落内置默认 —— 配错了也绝不会放宽暴露范围。
外部文件支持三种写法:["*.pem", …]、{ "patterns": [...] }、{ "rules": [{ "id", "scope", "pattern", "deny" }] };只采用 deny 缺省或含 "read" 的规则。
环境变量
变量 | 用途 |
|
|
| 覆盖内置敏感文件规则的 JSON 文件路径。 |
许可
MIT —— 见 LICENSE。
Tool Schema Changelog
Recent tool additions, removals, and schema changes observed during successful MCP inspections.
Loading tool schema changelog…
This server cannot be deployed
Maintenance
Related MCP Connectors
Ask a codebase what calls what: search, blast radius, paths between symbols, and diffs.
Scan configs, files, or text for leaked secrets and obvious misconfigurations. Nothing stored.
Code intelligence for coding agents: semantic, AST, graph, and full-text search. 279+ languages.
Deep security scans of repos you own from your editor: dependency CVEs, SAST, git-history secrets.
Related MCP Servers
- AlicenseNot gradedqualityDmaintenanceEnables searching text across configured local workspaces using ripgrep. Provides secure text search capabilities within defined workspace boundaries through both MCP server and CLI interfaces.MIT
- AlicenseAqualityDmaintenanceProvides LLM-optimized filesystem access with intelligent file pagination for large files, lightning-fast ripgrep-powered code search with regex support, and security sandboxing to safely explore and search codebases.71MIT
- AlicenseAqualityBmaintenanceEnables code search across indexed repositories using regex patterns, with pagination, repository listing, and file context retrieval via Hound integration.39 npm7MIT
- AlicenseAqualityCmaintenanceEnables fast literal and regex search over local workspaces using a sparse n-gram index for candidate pruning, with deterministic verification against file contents.81MIT