local-mcp

local-mcp

A lightweight, stdio-based MCP server enabling AI assistants to perform local file system operations like reading, writing, searching, and executing commands.

Category
访问服务器

README

local-mcp

A lightweight MCP (Model Context Protocol) server for local file system operations. Supports stdio (subprocess) and Streamable HTTP transport with zero runtime dependencies.

Features

Transport: stdio + HTTP

  • stdio mode (default): run as subprocess for AI assistants (Claude, Cursor, Chatbox, etc.) with MCP Content-Length framing
  • HTTP mode (--http): remote access via MCP Streamable HTTP (2025-03-26 spec), zero additional dependencies
  • CORS enabled for cross-origin browser access
  • SSE streaming when Accept: text/event-stream header is sent
  • GET /tools endpoint for quick tool discovery
  • Graceful shutdown: SIGINT/SIGTERM closes connections cleanly

Progressive Tool Discovery (Search-First Pattern)

Instead of loading all 13 tool schemas into every conversation (~3,000 tokens), the server exposes only 3 meta-tools:

Tool Description
search_tools Search available tools by keyword, returns matching names + descriptions (~50 tokens)
describe_tool Get full input schema for a specific tool (loaded on demand)
call_tool Execute any tool by name with arguments

~90% token savings compared to flat tool listing. Based on community-validated patterns (Speakeasy: 96% savings, StackOne: ~90%).

Available Tools (Full Catalog)

Tool Description Annotation
read Read file with line numbers, optional head/tail truncation readOnlyHint
search File search by name (glob) then content (grep) readOnlyHint
ls Compact directory listing (name, type, size) readOnlyHint
exec Streaming command execution, stdin support, timeout destructiveHint
diff Diff two files or text strings (Myers O(ND)) readOnlyHint
copy Copy file or directory destructiveHint
move Move or rename file/directory destructiveHint
batch Run multiple ops sequentially; atomic rollback, $prev refs destructiveHint
file Unified: read, write, edit, append, delete, info, mkdir, move
block Read/replace/insert/delete code blocks by range or function
bookmark Persistent path aliases (add/get/list/delete)
grep Compact file:line:content format (saves ~50% tokens) readOnlyHint
watch Watch file/directory for changes; max 20 concurrent watchers

Tool annotations (readOnlyHint/destructiveHint) follow MCP 2024-11-05 spec — clients can use them for safety decisions.

Output Format Optimizations

  • grep: file:line:content format — LLM can directly reference line numbers
  • ls: compact name.padEnd(16) f/d size — saves ~60% tokens vs JSON array
  • read: default head=100 with truncation hint for big files; line numbers prefixed
  • search: no-match returns guidance ("Try broader query?") instead of negative response

Resources

  • resources/list — list accessible resources (workspace root)
  • resources/read — read file contents via file:// URIs
  • resources/templates/list — URI template patterns for workspace files
  • MIME type auto-detection (json, markdown, javascript, text, directory)

Prompts

  • prompts/list — discover available prompt templates
  • prompts/get — retrieve prompt by name with arguments

Read-Only Mode

  • Set MCP_READONLY=true to block all write operations — safe for code review and browsing

Security

  • All file operations restricted to MCP_WORKSPACE and its subdirectories
  • Prototype-safe bookmark keys (blocks __proto__/constructor/prototype injection)
  • Atomic writes (temp + rename) prevent partial file writes
  • Binary file detection prevents reading non-text files
  • .gitignore and common exclude dirs (node_modules, .git, etc.) respected
  • Configurable MCP_EXCLUDE env var for custom exclusion patterns

Installation

# Clone or copy, then:
npm install

Zero runtime dependencies. Only Node.js >= 22 required.

Usage

stdio mode (default)

Configure your AI assistant to spawn local-mcp as a subprocess:

{
  "mcpServers": {
    "local-mcp": {
      "command": "node",
      "args": ["path/to/local-mcp.mjs"]
    }
  }
}

HTTP mode

node local-mcp.mjs --http
# or with custom port:
node local-mcp.mjs --http --port 3456

The HTTP endpoint accepts JSON-RPC 2.0 POST requests and returns JSON responses. Supports SSE streaming when Accept: text/event-stream header is sent. GET /tools returns tool list.

CLI flags

node local-mcp.mjs --help              # Show usage + env vars
node local-mcp.mjs --list-tools        # Print available tools and exit
node local-mcp.mjs --http              # Start in HTTP mode
node local-mcp.mjs --http --port 3456  # HTTP on custom port

Environment variables are printed at startup for self-documentation.

Configuration via environment variables

Variable Default Description
MCP_WORKSPACE process.cwd() Working directory root
MCP_DATA {WORKSPACE}/.mcp-data Data directory (bookmarks, temp files)
MCP_DIR {WORKSPACE} Default directory for tree/ls commands
MCP_PORT 3100 HTTP server port (when using --http)
MCP_READONLY false Set to true to block all write operations
MCP_EXCLUDE Comma-separated extra dirs to exclude from search

Dependencies

Zero runtime dependencies. Uses only Node.js built-in modules:

Module Purpose
fs File system operations (includes glob from Node.js 22)
child_process Shell command execution (streaming spawn)
http (built-in) HTTP transport (no Express/fastify needed)
path Path resolution
readline Streaming line-by-line processing

Optimizations

Area Detail
Code size ~830 lines, ~18 KB, zero runtime dependencies
Token efficiency Progressive discovery saves ~90% on tools/list; compact grep/ls formats
Read cache Size-aware eviction (max 50 items, 10 MB) + 5s TTL for external change detection
Grep 16-way parallel readline search, async fs.glob, MAX_SEARCH_FILES=5000 guard
Myers diff O(ND) algorithm for edit operations, used by edit, block, and diff tool
Tree view Iterative (stack-based) instead of recursive — safe for deep trees
Search scoring Name-match first (no I/O), then stat only top 50 candidates for mtime bonus
Edit Exact match fast-path + fuzzy line-trim fallback
Protocol O(1) Map dispatch, sync handler short-circuit
Exec Streaming spawn with 5000-line truncation, AbortController timeout, stdin pipe

Protocol Compatibility

  • MCP protocol versions: 2025-11-25 (default), echoes client version if provided
  • Transport: stdio (Content-Length framing) + Streamable HTTP
  • Methods: initialize, tools/list, tools/call, resources/list, resources/read, resources/templates/list, prompts/list, prompts/get, ping, notifications/*
  • Tool annotations: readOnlyHint / destructiveHint on all tools (MCP 2024-11-05 spec)
  • Read-only mode via MCP_READONLY=true
  • Cross-platform exec (Windows cmd /c, Unix /bin/sh -c)
  • Bookmarks: prototype-safe sanitizeKey (__proto__/constructor/prototype blocked)

License

MIT

推荐服务器

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

官方
精选