fd-mcp

fd-mcp

Provides fast file search capabilities using fd (a modern find alternative), enabling AI assistants to efficiently navigate codebases, search file contents with ripgrep, and execute commands on matched files.

Category
访问服务器

README

fd-mcp

A Model Context Protocol (MCP) server that provides fast file search capabilities using fd, a modern alternative to the traditional find command.

What is fd-mcp?

fd-mcp bridges fd with AI assistants like Claude Code through the Model Context Protocol. It exposes fd's powerful file search capabilities as MCP tools, enabling AI assistants to efficiently navigate and search codebases.

Why fd?

fd offers significant advantages over traditional file search tools:

  • Blazing Fast: Written in Rust, fd is often 5-10x faster than find for typical searches
  • Recursive by Default: Searches directories recursively without special flags (use max_depth to limit)
  • User-Friendly Syntax: Simple, intuitive patterns instead of cryptic flags (fd pattern vs find -name "*pattern*")
  • Smart Defaults: Automatically respects .gitignore and skips hidden files/directories
  • Colorized Output: Enhanced readability with syntax highlighting
  • Parallel Execution: Leverages multiple CPU cores for faster searches
  • Regex Support: Built-in regex pattern matching without complex syntax

Use Cases

This MCP server is particularly useful for:

  • Codebase Navigation: Quickly locate files by name, extension, or pattern across large projects
  • Project Analysis: Find all files of a specific type (e.g., all Python test files, all configuration files)
  • Code Exploration: Help AI assistants understand project structure by efficiently listing directories and files
  • Pattern Matching: Search for files using regex patterns (e.g., find all migration files, test suites)
  • Selective Searches: Filter by file type, depth, or exclude specific patterns
  • Performance: Fast searches even in monorepos or large codebases with thousands of files

Prerequisites

Install fd:

# Ubuntu/Debian
sudo apt install fd-find

# macOS
brew install fd

# Arch
pacman -S fd

Install ripgrep (required for fd_search_content tool):

# Ubuntu/Debian
sudo apt install ripgrep

# macOS
brew install ripgrep

# Arch
pacman -S ripgrep

# Or download from: https://github.com/BurntSushi/ripgrep/releases

Installation

cd fd-mcp
pip install -e .

Usage with Claude Code

Add to your Claude Code MCP settings (~/.claude.json):

{
  "mcpServers": {
    "fd": {
      "command": "fd-mcp"
    }
  }
}

Or run directly:

{
  "mcpServers": {
    "fd": {
      "command": "python",
      "args": ["-m", "fd_mcp.server"],
      "cwd": "/home/th/dev/os/fd-mcp"
    }
  }
}

🚀 Claude Code Integration Best Practices

Once configured, Claude Code will have access to all fd-mcp tools. Here's how to get the most out of them:

Quick Start Commands

The project includes helpful slash commands to get started:

  • /find-py - Find all Python files (demonstrates fd_search)
  • /search-code - Search code patterns (demonstrates fd_search_content)
  • /recent - Show recently modified files (demonstrates fd_recent_files)
  • /count-files - Count files by type (demonstrates fd_count)
  • /demo-mcp - Run a full demonstration of all tools

Tool Selection Guide

When Claude Code needs to find files:

  • Use: mcp__fd__fd_search(pattern=".*", path=".", extension="py")
  • Instead of: bash find . -name "*.py"
  • Why: 5-10x faster, respects .gitignore automatically

When Claude Code needs to search code:

  • Use: mcp__fd__fd_search_content(search_pattern="TODO", extension="py")
  • Instead of: bash find . -exec grep "TODO" {} \;
  • Why: 10-100x faster, single operation, shows context

When Claude Code needs to find recent changes:

  • Use: mcp__fd__fd_recent_files(hours=24)
  • Instead of: bash find . -mtime -1
  • Why: Intuitive time params, faster execution

Performance Benefits

The tools are optimized for AI assistant workflows:

Operation Traditional fd-mcp Speedup
Find 1000 Python files 2.5s 0.3s 8x faster
Search "TODO" in files 15s 0.5s 30x faster
Find files changed today 3s 0.4s 7x faster
Count all files 2s 0.25s 8x faster

Learning Resources

  • See CLAUDE.md for comprehensive usage patterns and examples
  • Check .claude/commands/ for ready-to-use slash commands
  • Review tool descriptions in Claude Code for quick reference

Tools

fd_search

Replaces: find, locate commands

Search for files and directories using fd (5-10x faster than find). Searches recursively by default through all subdirectories.

Parameter Type Description
pattern string Regex pattern (required, use ".*" or "" for all)
path string Search directory (required, e.g., ".")
type string f=file, d=dir, l=symlink, x=exec, e=empty
extension string Filter by extension
hidden bool Include hidden files
no_ignore bool Don't respect .gitignore
max_depth int Max search depth
exclude string Glob pattern to exclude
case_sensitive bool Case-sensitive search
absolute_path bool Return absolute paths
max_results int Limit results (default: 100)

fd_search_content ⭐

Replaces: find -exec grep, find | xargs grep commands

Search for content within files using fd+ripgrep. This is the key tool that replaces find . -exec grep pattern {} \; style commands.

Parameter Type Description
search_pattern string Text/regex to search in files (required)
file_pattern string Filter files by name pattern
path string Search directory (default: ".")
extension string Filter by extension (e.g., "py", "js")
type string Filter by type (f=file, d=dir, etc.)
hidden bool Include hidden files
no_ignore bool Don't respect .gitignore
case_sensitive bool Case-sensitive search
context_lines int Lines of context around matches
max_results int Max files to search (default: 100)

Note: Requires ripgrep (rg) to be installed.

fd_exec

Replaces: find -exec, find | xargs commands

Execute a command on files found by fd. Use {} as placeholder for filename.

Parameter Type Description
command string Command to run (use {} for filename)
pattern string File name pattern
path string Search directory (default: ".")
type string Filter by type
extension string Filter by extension
hidden bool Include hidden files
no_ignore bool Don't respect .gitignore
max_files int Max files to process (default: 100)

fd_recent_files

Replaces: find -mtime, find -newermt commands

Find recently modified files.

Parameter Type Description
path string Search directory (default: ".")
hours int Modified within N hours (default: 24)
type string Filter by type
extension string Filter by extension
max_results int Limit results (default: 50)

fd_count

Replaces: find | wc -l commands

Count files matching a pattern.

Parameter Type Description
pattern string Regex pattern (required, use ".*" or "" for all)
path string Search directory (required, e.g., ".")
type string Filter by type
extension string Filter by extension
hidden bool Include hidden files

Examples

Basic File Search

Find all Python files (recursively):

fd_search(pattern=".*", path=".", extension="py")

Find test files in entire project tree:

fd_search(pattern="test_.*", path=".", extension="py")

List directories only (limit to 2 levels deep):

fd_search(pattern=".*", path=".", type="d", max_depth=2)

Search only current directory (no recursion):

fd_search(pattern=".*", path=".", extension="py", max_depth=1)

Content Search (replaces find -exec grep)

Find "TODO" in all Python files:

fd_search_content(search_pattern="TODO", extension="py")

Find "import React" in JavaScript/TypeScript files with context:

fd_search_content(
    search_pattern="import.*React",
    extension="tsx",
    context_lines=2
)

Find error handling in specific directory:

fd_search_content(
    search_pattern="try.*except",
    path="src/",
    extension="py"
)

Execute Commands on Files

Count lines in all Python files:

fd_exec(command="wc -l {}", pattern=".*", path=".", extension="py")

Format all JavaScript files:

fd_exec(command="prettier --write {}", pattern=".*", path=".", extension="js")

Find Recent Changes

Files modified in last 2 hours:

fd_recent_files(hours=2)

Recent Python files modified in last day:

fd_recent_files(hours=24, extension="py")

Command Replacements

Old Command New MCP Tool
find . -name "*.py" fd_search(pattern=".*", path=".", extension="py")
find . -type f -exec grep "TODO" {} \; fd_search_content(search_pattern="TODO")
find . -name "*.js" -exec prettier {} \; fd_exec(command="prettier {}", pattern=".*", path=".", extension="js")
find . -mtime -1 fd_recent_files(hours=24)
find . -type f | wc -l fd_count(pattern=".*", path=".", type="f")

License

This project is licensed under the MIT License - see the LICENSE file for details.

推荐服务器

Baidu Map

Baidu Map

百度地图核心API现已全面兼容MCP协议,是国内首家兼容MCP协议的地图服务商。

官方
精选
JavaScript
Playwright MCP Server

Playwright MCP Server

一个模型上下文协议服务器,它使大型语言模型能够通过结构化的可访问性快照与网页进行交互,而无需视觉模型或屏幕截图。

官方
精选
TypeScript
Magic Component Platform (MCP)

Magic Component Platform (MCP)

一个由人工智能驱动的工具,可以从自然语言描述生成现代化的用户界面组件,并与流行的集成开发环境(IDE)集成,从而简化用户界面开发流程。

官方
精选
本地
TypeScript
Audiense Insights MCP Server

Audiense Insights MCP Server

通过模型上下文协议启用与 Audiense Insights 账户的交互,从而促进营销洞察和受众数据的提取和分析,包括人口统计信息、行为和影响者互动。

官方
精选
本地
TypeScript
VeyraX

VeyraX

一个单一的 MCP 工具,连接你所有喜爱的工具:Gmail、日历以及其他 40 多个工具。

官方
精选
本地
graphlit-mcp-server

graphlit-mcp-server

模型上下文协议 (MCP) 服务器实现了 MCP 客户端与 Graphlit 服务之间的集成。 除了网络爬取之外,还可以将任何内容(从 Slack 到 Gmail 再到播客订阅源)导入到 Graphlit 项目中,然后从 MCP 客户端检索相关内容。

官方
精选
TypeScript
Kagi MCP Server

Kagi MCP Server

一个 MCP 服务器,集成了 Kagi 搜索功能和 Claude AI,使 Claude 能够在回答需要最新信息的问题时执行实时网络搜索。

官方
精选
Python
e2b-mcp-server

e2b-mcp-server

使用 MCP 通过 e2b 运行代码。

官方
精选
Neon MCP Server

Neon MCP Server

用于与 Neon 管理 API 和数据库交互的 MCP 服务器

官方
精选
Exa MCP Server

Exa MCP Server

模型上下文协议(MCP)服务器允许像 Claude 这样的 AI 助手使用 Exa AI 搜索 API 进行网络搜索。这种设置允许 AI 模型以安全和受控的方式获取实时的网络信息。

官方
精选