文件搜索MCP
一个模型上下文协议(MCP)服务器,用于使用Rust和Tantivy构建的快速内存全文搜索。
概述
文件搜索MCP索引目录中的文本文件,并为MCP工具提供搜索内容或通过stdio读取文件的功能。它尊重 .gitignore (包括父规则和全局规则),并返回带有周围上下文行的搜索结果,以便快速浏览。
特性(v0.2.0)
- 全文搜索 使用Tantivy,返回得分结果和附近的上下文行。
- .gitignore感知索引:跳过忽略的路径(例如。,
target/,家长.gitignore,git exclude/global)。 - 工具发现:
tools/list使用丰富的注释实现。 - 文件读取器:获取给定路径的纯文本内容。
- 二进制安全:在索引过程中自动跳过二进制文件。
技术栈
用法
- 构建(无默认功能):
cargo build --release --no-default-features- 通过MCP检查器列出可用工具:
npx @modelcontextprotocol/inspector --cli target/release/file-search-mcp.exe --method tools/list- 搜索:
npx @modelcontextprotocol/inspector --cli target/release/file-search-mcp.exe --method tools/call --tool-name search --tool-arg directory=. --tool-arg keyword="your keyword"- 读取文件:
npx @modelcontextprotocol/inspector --cli target/release/file-search-mcp.exe --method tools/call --tool-name read_file --tool-arg file_path=README.md运作原理
- 使用以下命令遍历目标目录
ignore::WalkBuilder,尊敬.gitignore/git exclude/global忽略并跳过隐藏/二进制文件。 - 将文件内容流式传输到内存中的Tantivy索引(路径+内容字段)。
- 解析搜索查询,并检索具有相关性得分的热门搜索结果。
- 为每次点击返回文件路径和周围几行,以提供快速上下文。
- 通过stdio传输暴露MCP工具。
可用工具
- list_tools:查找具有模式注释的可用MCP工具。
- 搜索:在目录中的文本文件中搜索关键字。参数:
directory,keyword. - read_file:读取并返回特定文本文件的内容。参数:
file_path.
许可证
MIT许可证
