模糊搜索服务器

一个高性能的模糊搜索服务器,提供文件、内容和Git操作的模糊搜索功能,适用于开发效率提升和代码搜索场景。

  • by snirt
  • Go
  • 本地部署
  • 更新于
在 GitHub 查看 snirt/fzf-mcp

使用说明

fzf mcp

一种高性能的模型上下文协议(MCP)服务器,为文件、内容和git操作提供模糊搜索功能。内置Go以提高速度和效率。

特性

  • 模糊文件搜索:具有模糊匹配和gitignore支持的快速文件查找
  • 内容搜索:使用ripgrep集成和模糊过滤搜索代码
  • Git集成:模糊搜索分支、提交和git跟踪的文件
  • 可插拔架构:轻松交换模糊匹配实现
  • 高性能:内置Go语言,支持并发操作
  • 零运行时依赖性:单个静态二进制

安装

来源

# Clone the repository
git clone https://github.com/snirt/fzf-mcp.git
cd fzf-mcp

# Build
make build

# Install (optional)
make install

预构建二进制文件

从以下网址下载适用于您平台的最新版本 发布页面.

用法

使用克劳德桌面

添加到您的Claude Desktop MCP配置(~/Library/Application Support/Claude/claude_desktop_config.json 在macOS上):

{
  "mcpServers": {
    "fzf": {
      "command": "/path/to/fzf-mcp"
    }
  }
}

使用克劳德代码

添加到您的Claude Code MCP配置中(~/.claude.json):

{
  "mcpServers": {
    "fzf": {
      "type": "stdio",
      "command": "/path/to/fzf-mcp",
      "args": [],
      "env": {}
    }
  }
}

配置

通过环境变量配置模糊匹配器(in ~/.claude.json):

{
  "mcpServers": {
    "fzf": {
      "type": "stdio",
      "command": "/path/to/fzf-mcp",
      "args": [],
      "env": {
        "FZF_MCP_MATCHER": "sahilm"
      }
    }
  }
}

可用匹配:

  • sahilm (默认):针对文件名和代码符号进行了优化

可用工具

全局正则表达式打印

Grep风格的正则表达式搜索,具有完整的正则表达式支持、区分大小写和上下文行。

参数:

  • pattern (必需):要搜索的正则表达式模式(例如,“func.*Test”、“TODO|FIXME”)
  • path (可选):要搜索的目录或文件(默认:当前目录)
  • case_insensitive (可选):执行不区分大小写的搜索(默认值:false)
  • context_before (可选):每场比赛前显示的行数(如grep-B)
  • context_after (可选):每场比赛后显示的行数(如grep-A)
  • limit (可选):最大匹配数(默认值:20)
  • files_only (可选):仅显示匹配的文件名(如grep-l,默认值:false)
  • max_line_len (可选):最大行长度(默认值:200)
  • file_pattern (可选):用于过滤文件的Glob模式(例如,'去吧.{ts,tsx}')

示例:

Find all TODO or FIXME comments: pattern="TODO|FIXME"
Find function definitions: pattern="func.*Test" file_pattern="*.go"
Find interface definitions: pattern="type.*interface" files_only=true
Case-insensitive search: pattern="error" case_insensitive=true
With context: pattern="YourString" context_before=2 context_after=2

fuzzy_find_files

使用gitignore支持在目录中模糊搜索文件。

参数:

  • pattern (必填):模糊搜索模式(例如“main.go”、“test”、“src/comp”)
  • path (可选):要搜索的根目录(默认:当前目录)
  • limit (可选):最大结果数(默认值:20)

例子:

Find files matching "config" in the current project

模糊_搜索_内容

搜索文件内容并对结果应用模糊过滤。如果可用,使用ripgrep。

参数:

  • query (必填):在文件内容中搜索的文本
  • path (可选):要搜索的根目录(默认:当前目录)
  • pattern (可选):过滤匹配文件的模糊模式
  • limit (可选):最大结果数(默认值:20)
  • compact (可选):返回压缩输出(文件:count)而不是完整匹配(默认值:false)
  • max_line_len (可选):匹配的最大行长度(默认值:200)

示例:

Search for "TODO" in files matching "controller"
Search for "YourString" with compact=true (saves tokens)
Search for "function.*interface" with limit=10

git_fuzzy_牧场

在存储库中模糊搜索git分支。

参数:

  • path (可选):git存储库的路径(默认:当前目录)
  • pattern (可选):分支名称的模糊搜索模式
  • limit (可选):最大结果数(默认值:100)

git_fuzzy_files

在存储库中模糊搜索git跟踪的文件。

参数:

  • pattern (必填):文件名的模糊搜索模式
  • path (可选):git存储库的路径(默认:当前目录)
  • limit (可选):最大结果数(默认值:100)

git_fuzzy_承诺

通过git提交消息进行模糊搜索。

参数:

  • pattern (必填):提交消息的模糊搜索模式
  • path (可选):git存储库的路径(默认:当前目录)
  • limit (可选):最大结果数(默认值:50)

发展

先决条件

  • 转到1.25或更高版本(建议:使用mise进行版本管理)
  • (可选)ripgrep用于更快的内容搜索
  • (可选)golangci棉绒

安装Go with mise

# Install mise if not already installed
curl https://mise.run | sh

# Install Go (version specified in .mise.toml)
mise install

# Verify installation
mise exec -- go version  # Should show go1.25.4

建筑

# Build for current platform
make build

# Build for all platforms
make build-all

# Run tests
make test

# Run with coverage
make test-coverage

# Format code
make fmt

# Lint code
make lint

项目结构

fzf-mcp/
├── main.go              # MCP server entry point
├── config.go            # Configuration management
├── fuzzy/               # Fuzzy matching abstraction layer
│   ├── matcher.go       # FuzzyMatcher interface
│   └── sahilm.go        # sahilm/fuzzy implementation
├── tools/               # MCP tool implementations
│   ├── file_search.go   # File search tool
│   ├── content_search.go # Content search tool
│   ├── git_tools.go     # Git integration tools
│   └── gitignore.go     # Gitignore pattern matching
├── Makefile             # Build commands
├── README.md            # This file
└── CLAUDE.md            # Development guide for Claude Code

添加新的模糊匹配器

  1. 实施 FuzzyMatcher 接口在 fuzzy/
  2. 将匹配器类型添加到 fuzzy/matcher.go
  3. 更新 NewMatcher 函数

例子:

// fuzzy/custom.go
type CustomMatcher struct{}

func (c *CustomMatcher) Match(pattern string, items []string) []Match {
    // Your implementation
}

func (c *CustomMatcher) MatchLimit(pattern string, items []string, limit int) []Match {
    // Your implementation
}

演出

  • 文件扫描:60K文件约30ms(使用sahilm/fuzzy)
  • 启动时间:<20ms
  • 记忆:~5-15MB基本占地面积
  • 二进制大小:~5-15MB

许可证

麻省理工学院

贡献

欢迎投稿!请随时提交拉取请求。