Virtual Filesystem

io.github.lu-zhengda由 GitHub 账号 lu-zhengda 发布v0.2.2更新于 Oct 24, 2026

PostgreSQL-backed virtual filesystem for agents: session isolation, shared stores, POSIX ops, RLS.

概览

AI 生成的概览

一个由 PostgreSQL 支撑的虚拟文件系统,为 AI 助手提供持久、按会话隔离的文件存储,以及 POSIX 风格的读写与搜索工具。

可以做什么
读取、写入和追加文件,并用 stat 查看元数据或文件是否存在;文件存放在 PostgreSQL 中而非宿主机磁盘。用 ls、mkdir、mv 和 rm 管理目录结构,支持递归删除目录和自动创建父目录。按 glob 模式查找文件,按正则搜索文件内容,由 PostgreSQL trigram 索引支持。列出并使用命名的跨会话存储,在多个智能体之间共享数据或作为长期记忆。
适用场景
适合需要持久工作区的场景,数据在进程重启、容器回收或重新部署后仍然保留;也适合多个智能体通过命名存储共享文件。还适用于不希望智能体接触宿主机文件系统的沙箱式文件操作。
运行要求
通过 npm 包以 stdio 在本地运行,需要 Node.js 20 或更高版本,以及带 pg_trgm 扩展的 PostgreSQL 14 或更高版本。必须提供 DATABASE_URL 连接字符串;VFS_AUTO_INIT、VFS_SESSION_ID 和 VFS_ENABLE_RLS 为可选项。启用可选的 RLS 需要执行 SQL 脚本并配置专用数据库角色。
安装前请注意
DATABASE_URL 是包含数据库凭据的机密连接字符串,不要放入共享配置。这些工具会写入、移动和递归删除数据库中的数据,误操作会影响已存文件。VFS_AUTO_INIT 会自动建表,启用 RLS 需要手动修改表结构和角色。数据保存在你自己的 PostgreSQL 实例中,不经过第三方服务。

安装

在 SourceWeft 中

  1. 打开 控制台中的 Virtual Filesystem,将其添加到工作区。
  2. 为需要使用其工具的对话启用该服务。

Desktop only,通过 STDIO。 STDIO 服务会启动本地进程,因此需要 SourceWeft 桌面宿主。

其他 MCP 客户端

参照 仓库 中的启动说明。

README

mcp-virtual-fs

[npm version] [CI] [npm downloads] [License: MIT] [Node.js]

An MCP server that provides AI agents with a persistent, PostgreSQL-backed virtual filesystem. Supports session-isolated file operations, cross-session shared stores, glob/grep search, and Row Level Security — all exposed as standard Model Context Protocol tools.

Works with any MCP client: Claude Desktop, Claude Code, Cursor, Windsurf, Cline, and others.

Features

  • Persistent file storage — files are stored in PostgreSQL and survive process restarts, container recycling, and redeployments
  • Session isolation — each agent session gets its own namespace automatically, no configuration needed
  • Cross-session stores — named persistent stores for sharing data between agents or for long-term agent memory
  • 11 POSIX-style tools — read, write, append, stat, ls, mkdir, rm, mv, glob, grep, stores
  • Glob and grep search — find files by pattern (**/*.ts) or search content by regex, powered by PostgreSQL trigram indexes
  • Row Level Security — optional database-enforced isolation between sessions for multi-tenant deployments
  • Zero config — auto-creates tables on first run with VFS_AUTO_INIT=true

Use Cases

  • Agent scratchpad — give LLM agents a persistent workspace to read/write files across tool calls
  • Long-term agent memory — store notes, context, and knowledge across sessions using named stores
  • Multi-agent collaboration — multiple agents share files through cross-session stores
  • Sandboxed file operations — agents interact with a virtual filesystem instead of the host OS
  • CI/CD artifact storage — persist build outputs, logs, and reports in a queryable filesystem

Why

Agents work well with filesystems for context management, but coupling storage to the agent runtime means data is lost when pods restart or containers are recycled. This MCP server decouples storage from runtime by moving file operations to PostgreSQL — giving agents persistent, isolated, and searchable file storage without touching the host filesystem.

Prerequisites

  • Node.js 20 or later
  • PostgreSQL 14 or later (with pg_trgm extension — included in most distributions)

Quick Start

1. Set up PostgreSQL

bash
# Using Dockerdocker run -d --name vfs-postgres \  -e POSTGRES_DB=vfs \  -e POSTGRES_PASSWORD=postgres \  -p 5432:5432 \  postgres:16-alpine

2. Configure your MCP client

Add to your MCP client config (e.g., Claude Desktop claude_desktop_config.json or Claude Code .mcp.json):

json
{  "mcpServers": {    "virtual-fs": {      "command": "npx",      "args": ["-y", "mcp-virtual-fs"],      "env": {        "DATABASE_URL": "postgresql://postgres:postgres@localhost:5432/vfs",        "VFS_AUTO_INIT": "true"      }    }  }}

That's it. VFS_AUTO_INIT=true creates the tables on first run.

3. Use the tools

Tool names are short POSIX-style names:

write({ path: "/notes/todo.md", content: "# My Tasks\n- Ship feature" })read({ path: "/notes/todo.md" })ls({ path: "/notes" })glob({ pattern: "**/*.md" })grep({ pattern: "TODO" })

All tools return structured JSON responses.

Tools

ToolParametersReturnsDescription
readpath{content, size}Read file contents
writepath, content{path, size, has_parents}Write file (creates parents automatically)
appendpath, content{path, appended_bytes}Append to file (creates if missing)
statpath{exists, type?, size?, children?}Check existence and get metadata
lspath{entries: [{name, type}]}List directory (dirs first, then alphabetical)
mkdirpath{path, already_existed}Create directory and parents (mkdir -p)
rmpath{path, deleted}Remove file or directory recursively
mvsource, destination{source, destination}Move/rename file or directory
globpattern{files, count}Find files by glob (e.g., **/*.ts, **/*.{js,ts})
greppattern, path_filter?{matches, count}Search file contents by regex
stores(none){stores, count}List all persistent store names

All tools (except stores) accept an optional store parameter for cross-session persistent storage.

Session Management

Sessions are handled automatically — no session ID in tool parameters.

How it works:

TransportSession identityBehavior
stdioAuto-generated UUID per processEach MCP connection = unique session
HTTP/SSETransport-provided sessionIdMCP protocol handles it
AnyVFS_SESSION_ID env varDeterministic/resumable sessions

Priority: transport sessionId > VFS_SESSION_ID env var > auto-generated UUID.

Resumable sessions

To resume a previous session across process restarts, set a deterministic session ID:

json
{  "env": {    "DATABASE_URL": "postgresql://...",    "VFS_SESSION_ID": "my-agent-session-1"  }}

Cross-Session Stores

Named stores persist across sessions. Any session can read/write to a store by passing the store parameter:

// Session A writes to a storewrite({ path: "/context.md", content: "project notes", store: "agent-memory" })
// Session B (days later) reads from the same storeread({ path: "/context.md", store: "agent-memory" })
// Without `store`, operations target the session's own namespacewrite({ path: "/scratch.txt", content: "session-only data" })
// List all available storesstores()

Stores are auto-created on first use.

Environment Variables

VariableRequiredDefaultDescription
DATABASE_URLYes—PostgreSQL connection string
VFS_AUTO_INITNofalseAuto-create tables on startup
VFS_SESSION_IDNorandom UUIDDeterministic session ID
VFS_ENABLE_RLSNofalseEnable Row Level Security
VFS_STORAGE_BACKENDNopostgresStorage backend type

Manual Database Setup

If you prefer to manage the schema yourself instead of using VFS_AUTO_INIT:

bash
psql $DATABASE_URL -f sql/schema.sql

Row Level Security (optional)

RLS provides database-enforced session isolation. Even if application code has a bug that omits a WHERE session_id = clause, PostgreSQL itself prevents cross-session access.

bash
# Run after schema.sqlpsql $DATABASE_URL -f sql/rls.sql
# Update the vfs_app passwordpsql $DATABASE_URL -c "ALTER ROLE vfs_app PASSWORD 'your-secure-password'"

Then configure the MCP server to connect as vfs_app:

json
{  "env": {    "DATABASE_URL": "postgresql://vfs_app:your-secure-password@localhost:5432/vfs",    "VFS_ENABLE_RLS": "true"  }}

Development

Requirements

  • Node.js 20+
  • Docker (for integration tests — runs PostgreSQL via testcontainers)
bash
git clone https://github.com/lu-zhengda/mcp-virtual-fs.gitcd mcp-virtual-fsnpm installnpm run build

Commands

CommandDescription
npm run buildCompile TypeScript
npm testRun all tests (requires Docker)
npm run test:unitRun unit tests only
npm run test:integrationRun integration tests only
npm run lintRun ESLint
npm run lint:fixAuto-fix lint issues
npm run devRun with tsx (no build step)

Testing

Tests use testcontainers to spin up real PostgreSQL instances in Docker. No mocks — the integration tests exercise actual SQL queries, trigram indexes, and RLS policies.

bash
# Requires Docker runningnpm test

Session Cleanup

Ephemeral sessions can be cleaned up periodically:

sql
DELETE FROM vfs_sessionsWHERE is_persistent = false  AND created_at < now() - interval '7 days';

The ON DELETE CASCADE on vfs_nodes handles file cleanup automatically. Persistent stores (created via the store parameter) are never affected.

License

MIT

来源:README.md,提交 cfc45ed

工具

0
SourceWeft 尚未在沙箱中启动过该软件包,因此其工具未知。

版本历史

1
  1. v0.2.2最新Sep 16, 2026

评分

已满足适用检查项的 50%

该评分衡量此收录条目的完整程度,依据注册中心条目、端点与公开来源计算得出。它不是对服务器本身的评价,也不表示服务器安全或当前可用:可连通性是带日期的检查结果,评分也不包含安装量或用户评价。

  • 近 30 天内可连通25 分

    请保持端点能够响应 MCP 握手;SourceWeft 每 30 天探测一次。

  • 已声明认证方式10 分

    请在注册中心条目中声明凭据请求头,或保持端点能够响应探测,以便判定其认证方式。

  • 已列出工具15 分

    请让服务器在无凭据时响应 tools/list,或发布可在沙箱中无凭据启动的软件包。

  • 描述必需15 分
  • 图标10 分
  • 文档15 分
  • 许可证10 分