disk-space-mcp

disk-space-mcp

Enables checking and validating disk space usage via a single tool, reporting total, used, and available space with optional free space thresholds.

Category
访问服务器

README

disk-space-mcp

A small Model Context Protocol server that reports and validates free disk space. It exposes a single read-only tool, check_disk_space, backed by Node's fs.statfs — no shell-outs to df, no runtime dependencies beyond the MCP SDK and Zod.

Tool: check_disk_space

Reports total / used / available space for the filesystem that contains a path, and validates it against optional free-space thresholds.

Argument Type Default Description
path string home directory Any path; stats apply to the filesystem containing it.
minFreeGb number — If available space is below this many GiB, status becomes "warning".
minFreePercent number 10 If available space is below this percentage, status becomes "warning".

It returns both a human-readable text block and structuredContent:

{
  "path": "/Users/you",
  "totalBytes": 494384795648,
  "usedBytes": 312000000000,
  "freeBytes": 182000000000,
  "availableBytes": 175000000000,
  "usedPercent": 63.11,
  "availablePercent": 35.4,
  "status": "ok",
  "message": "OK: 163 GiB available of 460 GiB (35.4% free, 63.11% used) on /Users/you."
}

availableBytes (POSIX bavail) is the space actually usable by your user and is the value the thresholds check; freeBytes (bfree) additionally counts space reserved for root.

Develop

npm install
npm run build      # tsc -> dist/
npm test           # vitest: pure-logic unit tests + in-memory protocol tests
npm run typecheck  # tsc --noEmit
npm run smoke      # build first, then spawn the server and call the tool over stdio

Register with Claude Code

npm run build
claude mcp add disk-space --scope user -- node /ABSOLUTE/PATH/TO/disk-space-mcp/dist/index.js

Or add it manually to an MCP client config:

{
  "mcpServers": {
    "disk-space": {
      "command": "node",
      "args": ["/ABSOLUTE/PATH/TO/disk-space-mcp/dist/index.js"]
    }
  }
}

Design notes

  • Layered for testability. diskSpace.ts is a pure module (byte math, thresholds, formatting) with no I/O, unit-tested in isolation. getDiskStats.ts is the thin fs.statfs adapter, injected into createServer() so the protocol wiring can be tested end-to-end against an in-memory transport with fabricated stats.
  • stdio-safe. All diagnostics go to stderr; stdout carries only JSON-RPC.
  • Read-only and shell-free. The tool only reads filesystem capacity via statfs; it never reads file contents and never invokes a shell, so there is no command-injection surface. Paths are resolved to absolute and failures (missing path, permission denied) return a clean isError result.
  • Unit semantics. Byte counts use frsize when available (Node ≥ 24.16), falling back to bsize on older runtimes. Sizes are formatted with binary (IEC) units — KiB / MiB / GiB.

Security

  • Read-only, shell-free. The only side effect is fs.statfs. There is no child_process/exec/spawn anywhere, so there is no command-injection surface, and statfs exposes filesystem capacity only — never file contents.
  • Input is validated at the boundary. The path argument is length-capped and rejected if it contains control characters (NUL, ESC, CR, …), which both neutralizes statfs's silent null-byte truncation and prevents control/ANSI sequences from being reflected into tool output that a terminal or agent later renders. minFreeGb / minFreePercent are bounded and must be finite.
  • No information leak on error. Failures return a clean isError result with an errno code (e.g. ENOENT) rather than raw runtime internals; full error detail is logged to stderr only.
  • stdio-only. Only StdioServerTransport is instantiated. The MCP SDK transitively pulls in an HTTP/auth stack that this server never uses; since consumers only run the stdio binary, those code paths are never reached. For a hardened install, npm ci --ignore-scripts is safe (no runtime dependency needs an install script). CI gates production dependencies with npm audit --omit=dev --audit-level=high.

License

MIT — see LICENSE.

推荐服务器

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 模型以安全和受控的方式获取实时的网络信息。

官方
精选