librechat-personal-files-mcp
librechat-personal-files-mcp
为 LibreChat 智能体提供按用户隔离的个人文件存储、持久化文档、RAG 索引/检索以及不透明公开链接发布的 MCP 服务器。
功能特性
按用户存储:
/data/private/<userId>/下的私有文件,支持完整的 CRUD、列表、移动操作。文档目录:
save_documentation/update_documentation写入docs/并更新memory-index.json(schema v2)。RAG 集成:
index_document通过POST /embed将内容发送到 rag_api,并带有金丝雀验证(issue #305);search_knowledge用于语义搜索;remove_from_knowledge用于删除。公开发布:
publish_file创建加密安全的随机令牌(≥128 位);文件通过 NginxX-Accel-Redirect提供,并带有Content-Disposition: attachment、nosniff、no-store。严格安全:对缺失/无效的
X-User-Id采用 fail-closed(默认拒绝);阻止路径遍历;不允许绝对路径;不允许..段;检测符号链接逃逸;保护保留段;通过跨进程锁实现索引的原子写入。
Related MCP server: knowledge_mgmt
架构
┌──────────────┐ ┌────────────────────────┐ ┌─────────────┐
│ LibreChat │────▶│ librechat-personal-files-mcp │──▶│ rag_api │
│ (Agent) │ MCP │ (stateless HTTP /mcp) │ │ (vector DB) │
└──────────────┘ └────────────────────────┘ └─────────────┘
│
│ GET /files/{token}
▼
┌──────────────┐
│ Nginx │
│ (X-Accel) │
└──────────────┘
│
▼
┌──────────────┐
│ /data/private│ (read-only bind)
└──────────────┘快速开始(开发)
cd /opt/LibreChat/mcp-personal-files
python -m venv .venv
.venv/bin/pip install -e ".[dev]"
.venv/bin/python -m pytest
.venv/bin/python -m ruff check .
# Run server
STORAGE_ROOT=/tmp/pf-private JWT_SECRET=$(openssl rand -hex 32) .venv/bin/personal-files-mcp生产部署
1. 主机准备(以 root 身份运行一次)
cd /opt/LibreChat
groupadd -g 2500 lcfiles 2>/dev/null || true
mkdir -p ./data/private/_system
chown -R 2000:2500 ./data/private
chmod 2770 ./data/private
setfacl -R -m g:2500:rX,d:g:2500:rX ./data/private 2>/dev/null || \
echo "ACL tools absent; using 644/755 fallback"
grep -q '^JWT_SECRET=' .env || echo "JWT_SECRET=$(openssl rand -hex 32)" >> .env2. 添加到 docker-compose.override.yml
将 docker-compose.snippet.yml 中的代码块复制到您现有的 override 文件中。
3. 配置 LibreChat 管理面板
在 MCP Settings 下添加:
mcpSettings:
allowedAddresses:
- 'librechat-personal-files:8080'
mcpServers:
personal-files:
type: streamable-http
url: http://librechat-personal-files:8080/mcp
timeout: 120000
chatMenu: false
headers:
X-User-ID: '{{LIBRECHAT_USER_ID}}'
X-User-Email: '{{LIBRECHAT_USER_EMAIL}}'重启 LibreChat。
4. Nginx 配置(添加到现有 server 块中)
limit_req_zone $binary_remote_addr zone=pubfiles:10m rate=5r/s;
location ^~ /files/ {
limit_req zone=pubfiles burst=10 nodelay;
limit_req_status 429;
proxy_pass http://librechat-personal-files:8080/files/;
proxy_set_header X-Original-URI $request_uri;
proxy_set_header X-Real-IP $remote_addr;
}
location ^~ /_protected/ {
internal;
alias /data/private/;
}重新加载 Nginx。
环境变量
变量 | 默认值 | 描述 |
|
| 携带用户身份的请求头 |
|
| 用户数据的根目录 |
|
| 旧版共享区域(迁移期间可读/写) |
|
| rag_api 端点 |
| required | 与 LibreChat/rag_api 共享的 HS256 密钥(≥32 字符) |
|
| 公开链接的基础 URL |
|
| 最大上传大小 |
|
| 公开链接的 SQLite 注册表 |
MCP 工具
存储
list_files(path="", recursive=false, pattern=null)— 列出文件/目录read_file(path)— 读取 UTF-8 文本;二进制或大于 2 MB 时返回错误write_file(path, content)— 写入文本(UTF-8),自动创建父目录update_file(path, content)— 更新已有文件delete_file(path)— 删除文件或目录move_file(src, dst)— 在用户根目录内移动get_file_info(path)— 元数据 + docindex + 发布状态
文档
save_documentation(filename, content, title?, description?, tags?, topics?)— 保存到docs/,更新索引,不会发布或建立索引update_documentation(filename, content, ...)— 更新已有文档get_document_metadata(filename)— 完整的索引条目
RAG
search_knowledge(query, limit=8)— 语义搜索(通过 JWT 限定所有者范围)index_document(path)— 嵌入 + 金丝雀验证,更新索引状态remove_from_knowledge(path)— 从 rag_api 中删除,并清除索引get_index_status()— 计数 + rag_api 健康状态
发布
publish_file(path, expires_in_days?)— 创建/复用公开链接,返回令牌 + URLunpublish_file(path_or_token)— 撤销链接(文件保持私有)get_public_link(path)— 获取路径对应的有效链接list_public_links()— 用户的所有链接
安全模型
身份:
X-User-Id请求头由 LibreChat({{LIBRECHAT_USER_ID}})注入。占位符未解析 → 空字符串 → fail-closed(默认拒绝)。Fail-closed(默认拒绝):缺失/为空/无效的请求头 → HTTP 403
{"error":"missing_user_identity"}或{"error":"invalid_user_identity"}。路径安全:所有路径均为相对路径;拒绝绝对路径和
..;通过Path.resolve()加前缀检查来检测符号链接逃逸。隔离性:rag_api 的所有者范围由 JWT
sub/id= userId 强制执行(PR #319 已于 2026-08-15 合并)。公开链接:不透明的
secrets.token_urlsafe(16)令牌;URL 中不含用户/路径;通过410 Gone撤销;惰性清理过期条目。
开发
# Run tests
.venv/bin/pytest -q
# Lint
.venv/bin/ruff check .
# Type check (optional)
.venv/bin/mypy src/personal_files_mcp # if mypy added to deps许可证
MIT
This server cannot be installed
Maintenance
Resources
Unclaimed servers have limited discoverability.
Looking for Admin?
If you are the server author, to access and configure the admin panel.
Related MCP Servers
- FlicenseNot gradedqualityBmaintenanceEnables AI agents to process files locally — OCR images, extract text from PDFs and DOCX, and describe images using local vision models, all without sending data to external services.
- AlicenseNot gradedqualityDmaintenanceEnables uploading, organizing, and semantically searching documents with support for various file types and embedding providers.27MIT
- AlicenseNot gradedqualityDmaintenanceEnables AI agents with long-term memory and retrieval-augmented generation (RAG) capabilities, allowing them to recall past conversations, search local files, and learn user preferences.MIT
- AlicenseAqualityCmaintenanceProvides AI agents with local file-processing capabilities for token counting, RAG chunking, CSV/JSON conversion, QR generation, and more, while keeping documents private on the user's machine.71MIT
Related MCP Connectors
File uploads for AI agents. Upload, list, and manage files. No signup required.
Securely search and manage workspace context files for AI agents and teams.
Upload any file, get a tracked shareable link. DocSend for AI agents.
Latest Blog Posts
- Who's Calling? MCP Hosts Are an Identity Blind Spot (And the Spec Knows It)By Om-Shree-0709 on .mcpAgent IdentityOAuth 2.1
- Your AI Chatbot Just Exposed Your CEO's Salary to an InternBy Om-Shree-0709 on .Agent IdentityMCP SecurityOAuth Delegation
- Why MCP Servers Need Execution Sandboxing (And Why Your Current Stack Isn't Enough)By Om-Shree-0709 on .Agentic AiPrompt InjectionWebAssembly
MCP directory API
We provide all the information about MCP servers via our MCP API.
curl -X GET 'https://glama.ai/api/mcp/v1/servers/martinriesel/librechat-personal-files-mcp'
If you have feedback or need assistance with the MCP directory API, please join our Discord server