npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

mcp-file-scanner

v1.2.0

Published

递归遍历指定文件夹下所有文件,并返回文件详细信息

Readme

MCP 文件扫描器

一个简单的命令行工具,用于递归遍历指定文件夹下所有文件,并返回详细的文件信息。

功能特点

  • 递归扫描指定目录下的所有文件
  • 收集每个文件的详细信息:
    • 创建时间
    • 修改时间
    • 文件名称
    • 文件大小
    • 文件扩展名
  • 支持多种输出格式(表格、JSON)
  • 支持文件名过滤
  • 支持限制扫描深度
  • 支持将结果保存到文件
  • 支持文件统计分析
  • 提供标准MCP接口,方便其他程序调用
  • 支持@modelcontextprotocol/sdk标准

安装

无需安装,可以直接通过npx使用:

npx mcp-file-scanner [目录路径] [选项]

或者全局安装:

npm install -g mcp-file-scanner
mcp-file-scanner [目录路径] [选项]

使用方法

基本用法

# 显示帮助信息
npx mcp-file-scanner

# 扫描当前目录
npx mcp-file-scanner scan

# 扫描指定目录
npx mcp-file-scanner scan /path/to/directory

# 显示文件统计信息
npx mcp-file-scanner stats

命令

Commands:
  scan [options] [directory]  扫描文件并列出详细信息
  stats [options] [directory] 显示文件统计信息
  server                      启动MCP服务器
  help [command]              显示命令帮助

选项

扫描命令 (scan) 选项:

Options:
  -o, --output <type>    输出格式 (json, table) (默认: "table")
  -d, --depth <number>   扫描深度 (0表示无限制) (默认: "0")
  -f, --filter <pattern> 文件名过滤模式 (支持glob模式) (默认: "*")
  -s, --save <path>      将结果保存到文件
  -h, --help             显示帮助信息

统计命令 (stats) 选项:

Options:
  -d, --depth <number>   扫描深度 (0表示无限制) (默认: "0")
  -f, --filter <pattern> 文件名过滤模式 (支持glob模式) (默认: "*")
  -s, --save <path>      将结果保存到文件
  -h, --help             显示帮助信息

示例

# 以JSON格式输出结果
npx mcp-file-scanner scan -o json

# 只扫描一级目录
npx mcp-file-scanner scan -d 1

# 只扫描JS文件
npx mcp-file-scanner scan -f "*.js"

# 将结果保存到文件
npx mcp-file-scanner scan -s result.json

# 组合使用
npx mcp-file-scanner scan /path/to/directory -o json -d 2 -f "*.txt" -s result.json

# 显示文件统计信息
npx mcp-file-scanner stats

# 显示特定目录的文件统计信息
npx mcp-file-scanner stats /path/to/directory

# 将统计信息保存到文件
npx mcp-file-scanner stats -s stats.json

# 启动MCP服务器
npx mcp-file-scanner server

在代码中使用

基本用法

const { scanDirectory } = require('mcp-file-scanner');

async function main() {
  const files = await scanDirectory('./src', {
    depth: 2,
    filter: '*.js',
    outputFormat: 'json',
    silent: true // 不在控制台输出结果
  });

  console.log(`找到 ${files.length} 个文件`);
}

main().catch(console.error);

MCP接口

传统接口

const { mcpScanFiles, mcpGetFileStats } = require('mcp-file-scanner');

async function main() {
  // 扫描文件
  const result = await mcpScanFiles({
    directory: './src',
    depth: 2,
    filter: '*.js'
  });

  if (result.success) {
    console.log(`找到 ${result.count} 个文件`);
    console.log(result.data);
  } else {
    console.error(`扫描失败: ${result.error}`);
  }

  // 获取文件统计信息
  const statsResult = await mcpGetFileStats({
    directory: './src',
    depth: 2,
    filter: '*.js'
  });

  if (statsResult.success) {
    const stats = statsResult.data;
    console.log(`总文件数: ${stats.totalFiles}`);
    console.log(`总大小: ${stats.totalSize} 字节`);
    console.log(`平均大小: ${stats.averageSize} 字节`);

    // 显示文件类型分布
    Object.entries(stats.extensionStats).forEach(([ext, info]) => {
      console.log(`${ext}: ${info.count} 个文件, 总大小 ${info.totalSize} 字节`);
    });
  }
}

main().catch(console.error);

标准MCP接口

本工具支持标准的MCP协议,使用@modelcontextprotocol/sdk包实现。你可以通过以下方式启动MCP服务器:

const { startMcpServer } = require('mcp-file-scanner');

// 启动MCP服务器
startMcpServer()
  .then(() => {
    console.log('MCP服务器已启动');
  })
  .catch(error => {
    console.error('启动MCP服务器失败:', error);
  });

或者直接使用命令行工具启动:

npx mcp-file-scanner server

MCP服务器提供以下工具:

  1. scanFiles - 递归扫描指定目录下的所有文件,并返回详细信息
  2. getFileStats - 获取指定目录下文件的统计信息

这些工具可以通过任何支持MCP协议的客户端调用。

许可证

MIT