File Search MCP

File Search MCP

Search local file contents recursively with keyword matching

Category
Visit Server

README

File Search MCP 🔍

一个基于 FastMCP 的本地文件搜索 MCP Server。让 Claude 能够递归搜索项目文件内容,快速定位关键词。

功能

Tool(工具)

工具 说明
search_files(keyword, directory) 递归搜索文件内容中的关键词,返回匹配的文件路径、行号和内容
list_directory(path, pattern) 列出目录中的文件和子目录,支持 glob 过滤

Resource(资源)

资源 URI 说明
search://stats 搜索统计:累计搜索次数、最近 20 条搜索记录
config://settings 当前配置:文本扩展名白名单、跳过目录、文件大小上限等

特性

  • 🧠 智能文件识别 — 白名单扩展名 + 二进制检测(null byte 扫描),避免搜索图片/压缩包/可执行文件
  • 🚫 自动跳过无关目录 — 默认跳过 .gitnode_modules__pycache__venv
  • 📏 大文件保护 — 自动跳过大于 2MB 的文件,防止卡顿
  • 🔤 大小写可选 — 默认不区分大小写,也可精确匹配
  • 🎯 结果上限 — 默认最多返回 50 条,避免输出爆炸
  • 📋 搜索历史 — 内存中保留最近 20 条搜索记录,可通过 Resource 查看

快速开始

环境要求

安装

# 克隆仓库
git clone https://github.com/rubber25ba/file-search-mcp.git
cd file-search-mcp

# 创建虚拟环境(推荐)
python -m venv .venv
# Windows
.venv\Scripts\activate
# macOS/Linux
source .venv/bin/activate

# 安装依赖
pip install fastmcp

本地测试

python server.py

在 Claude Code 中配置

在 Claude Code 的 settings.json 中添加:

{
  "mcpServers": {
    "file-search": {
      "command": "python",
      "args": ["C:/Users/YOUR_USERNAME/path/to/file-search-mcp/server.py"]
    }
  }
}

也可以在 Claude Code 中输入 /config 打开配置面板,选择 MCP Servers → Add,填写:

  • Name: file-search
  • Command: python
  • Args: ["你的路径/file-search-mcp/server.py"]

配置完成后重启 Claude Code,试试:

  • 「搜索 mcp-projects 目录下提到 FastMCP 的文件」
  • 「列出桌面上所有的 .py 文件」

使用示例

示例 1:搜索代码中的关键词

用户:搜索当前项目里所有提到 "TODO" 的文件

Claude 调用 search_files(keyword="TODO", directory=".", glob_pattern="*.py")
→ 返回所有包含 TODO 的 Python 文件路径、行号和内容

示例 2:列出目录结构

用户:桌面上有哪些 Markdown 文件?

Claude 调用 list_directory(path="~/Desktop", glob_pattern="*.md")
→ 列出桌面上所有 .md 文件

示例 3:查看搜索统计

用户:我最近搜了什么?

Claude 读取 resource search://stats
→ 返回搜索次数和历史记录

配置说明

可以在 server.py 中修改以下常量:

配置 默认值 说明
MAX_RESULTS 50 单次搜索最多返回结果数
MAX_FILE_SIZE 2MB 跳过的文件大小阈值
SKIP_DIRS .git, node_modules, ... 跳过搜索的目录名
TEXT_EXTENSIONS .py, .js, .md, ... 文本文件扩展名白名单

项目结构

file-search-mcp/
├── server.py      # MCP Server 主程序(Tool + Resource)
└── README.md      # 本文件

技术栈

License

MIT

Recommended Servers

playwright-mcp

playwright-mcp

A Model Context Protocol server that enables LLMs to interact with web pages through structured accessibility snapshots without requiring vision models or screenshots.

Official
Featured
TypeScript
Audiense Insights MCP Server

Audiense Insights MCP Server

Enables interaction with Audiense Insights accounts via the Model Context Protocol, facilitating the extraction and analysis of marketing insights and audience data including demographics, behavior, and influencer engagement.

Official
Featured
Local
TypeScript
Magic Component Platform (MCP)

Magic Component Platform (MCP)

An AI-powered tool that generates modern UI components from natural language descriptions, integrating with popular IDEs to streamline UI development workflow.

Official
Featured
Local
TypeScript
VeyraX MCP

VeyraX MCP

Single MCP tool to connect all your favorite tools: Gmail, Calendar and 40 more.

Official
Featured
Local
graphlit-mcp-server

graphlit-mcp-server

The Model Context Protocol (MCP) Server enables integration between MCP clients and the Graphlit service. Ingest anything from Slack to Gmail to podcast feeds, in addition to web crawling, into a Graphlit project - and then retrieve relevant contents from the MCP client.

Official
Featured
TypeScript
Kagi MCP Server

Kagi MCP Server

An MCP server that integrates Kagi search capabilities with Claude AI, enabling Claude to perform real-time web searches when answering questions that require up-to-date information.

Official
Featured
Python
E2B

E2B

Using MCP to run code via e2b.

Official
Featured
Neon Database

Neon Database

MCP server for interacting with Neon Management API and databases

Official
Featured
Exa Search

Exa Search

A Model Context Protocol (MCP) server lets AI assistants like Claude use the Exa AI Search API for web searches. This setup allows AI models to get real-time web information in a safe and controlled way.

Official
Featured
Qdrant Server

Qdrant Server

This repository is an example of how to create a MCP server for Qdrant, a vector search engine.

Official
Featured