File System MCP Server
An MCP server that exposes filesystem operations — listing directories, reading, writing, and searching files — as tools an LLM can discover and invoke at runtime.
README
File System MCP Server
An MCP (Model Context Protocol) server that exposes filesystem operations —
listing directories, reading, writing, and searching files — as tools an
LLM can discover and invoke at runtime. Built as a learning project to
understand MCP's architecture from the ground up, using the low-level
Server API (raw JSON Schemas, not the decorator-based FastMCP shortcut).
What this project demonstrates
- How an MCP server advertises capabilities to a host via
tools/list, and how the host routes an LLM's tool-call decision back viatools/call - Why tool descriptions are prompt engineering, not documentation — the LLM only ever sees the JSON Schema, never your source code
- Defensive server design: path sandboxing, input validation, structured error responses instead of crashes, and result truncation for large outputs
- The read-only vs. destructive vs. idempotent distinction MCP tool annotations are meant to capture
Architecture
Host (Claude Desktop / MCP Inspector / any MCP client)
│
│ tools/list → server responds with schemas for all 4 tools
│ tools/call → host sends {name, arguments}, server executes and
│ returns a result
▼
This server (stdio transport)
│
▼
sandbox/ (all file operations are confined to this directory)
The server never calls the LLM and the LLM never calls the server directly — the host sits in between, using the schemas below to decide when and how to invoke each tool.
Tools
| Tool | Type | Description |
|---|---|---|
read_file |
read-only | Reads and returns the full text content of a file |
list_directory |
read-only | Lists files and folders in a directory (folders suffixed with /) |
write_file |
destructive | Writes text to a file; refuses to overwrite existing files unless overwrite: true |
search_files |
read-only | Recursively searches by filename glob pattern and/or file content, capped at 100 results |
All tools operate relative to a sandboxed root directory (./sandbox) —
paths are resolved and verified to stay inside that boundary before any
filesystem access happens, blocking path-traversal attempts like
../../etc/passwd.
Setup
uv sync
Running
With the MCP Inspector (recommended for development — shows raw protocol traffic and lets you call tools manually):
npx @modelcontextprotocol/inspector uv run main.py
Open the URL it prints, click Connect, then Tools → List Tools to see all four schemas, and run any tool directly from the form UI.
As a server for an MCP host (e.g. Claude Desktop), add to your host's MCP config:
{
"mcpServers": {
"fs-mcp-server": {
"command": "uv",
"args": ["run", "--directory", "/absolute/path/to/fs-mcp-server", "main.py"]
}
}
}
Security design
- Sandboxing (
resolve_safe_path): every incoming path is joined onto the sandbox root, resolved to an absolute path, and checked withPath.is_relative_to()to confirm it didn't escape via..segments. Rejected paths raise a caughtValueError, never crash the server. - Overwrite protection:
write_filewill not silently clobber an existing file — it requires an explicitoverwrite: trueargument. - Result truncation:
search_filescaps output at 100 matches and notes when results were truncated, rather than risking an enormous response. - Graceful failure everywhere: missing arguments, non-existent paths, wrong path types (file vs. directory), and unreadable/binary files all return a structured error message to the caller instead of raising an uncaught exception.
Known limitations / next steps
- Tool annotations (
readOnlyHint,destructiveHint,idempotentHint) are not yet set explicitly — without them, hosts may apply incorrect defaults (e.g. flagging a read-only tool as destructive). - Currently stdio transport only; could be extended to streamable HTTP for remote deployment.
search_filescontent search reads full file contents into memory per candidate file — fine for a learning project, would need streaming for very large files in production.
Stack
Python, mcp (official Anthropic SDK),
uv for dependency management.
推荐服务器
Baidu Map
百度地图核心API现已全面兼容MCP协议,是国内首家兼容MCP协议的地图服务商。
Playwright MCP Server
一个模型上下文协议服务器,它使大型语言模型能够通过结构化的可访问性快照与网页进行交互,而无需视觉模型或屏幕截图。
Magic Component Platform (MCP)
一个由人工智能驱动的工具,可以从自然语言描述生成现代化的用户界面组件,并与流行的集成开发环境(IDE)集成,从而简化用户界面开发流程。
Audiense Insights MCP Server
通过模型上下文协议启用与 Audiense Insights 账户的交互,从而促进营销洞察和受众数据的提取和分析,包括人口统计信息、行为和影响者互动。
VeyraX
一个单一的 MCP 工具,连接你所有喜爱的工具:Gmail、日历以及其他 40 多个工具。
graphlit-mcp-server
模型上下文协议 (MCP) 服务器实现了 MCP 客户端与 Graphlit 服务之间的集成。 除了网络爬取之外,还可以将任何内容(从 Slack 到 Gmail 再到播客订阅源)导入到 Graphlit 项目中,然后从 MCP 客户端检索相关内容。
Kagi MCP Server
一个 MCP 服务器,集成了 Kagi 搜索功能和 Claude AI,使 Claude 能够在回答需要最新信息的问题时执行实时网络搜索。
e2b-mcp-server
使用 MCP 通过 e2b 运行代码。
Neon MCP Server
用于与 Neon 管理 API 和数据库交互的 MCP 服务器
Exa MCP Server
模型上下文协议(MCP)服务器允许像 Claude 这样的 AI 助手使用 Exa AI 搜索 API 进行网络搜索。这种设置允许 AI 模型以安全和受控的方式获取实时的网络信息。