Skip to main content
Glama
martinriesel

librechat-personal-files-mcp

by martinriesel

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 位);文件通过 Nginx X-Accel-Redirect 提供,并带有 Content-Disposition: attachmentnosniffno-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)" >> .env

2. 添加到 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。

环境变量

变量

默认值

描述

USER_HEADER

X-User-Id

携带用户身份的请求头

STORAGE_ROOT

/data/private

用户数据的根目录

SHARE_ROOT

/data/share

旧版共享区域(迁移期间可读/写)

RAG_API_URL

http://rag_api:8000

rag_api 端点

JWT_SECRET

required

与 LibreChat/rag_api 共享的 HS256 密钥(≥32 字符)

PUBLIC_BASE_URL

https://gpt.riesel.com.br/files

公开链接的基础 URL

MAX_FILE_SIZE_MB

20

最大上传大小

REGISTRY_DB

/data/private/_system/links.db

公开链接的 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?) — 创建/复用公开链接,返回令牌 + URL

  • unpublish_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

A
license - permissive license
Not graded
quality - not tested
C
maintenance

Maintenance

Maintainers
Response time
Release cycle
Releases (12mo)
Commit activity

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

  • A
    license
    Not graded
    quality
    D
    maintenance
    Enables uploading, organizing, and semantically searching documents with support for various file types and embedding providers.
    27
    MIT
  • A
    license
    Not graded
    quality
    D
    maintenance
    Enables 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
  • A
    license
    A
    quality
    C
    maintenance
    Provides 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.
    7
    1
    MIT

View all related MCP servers

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.

View all MCP Connectors

Latest Blog Posts

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