librechat-personal-files-mcp
Publishes user files as secure public links via Nginx X-Accel-Redirect, enforcing download headers and access controls.
This server does not currently have a deployable release on Glama. Follow the repository's setup instructions to install and configure it for your MCP client, including any required credentials and local dependencies.
librechat-personal-files-mcp
MCP server providing per-user personal file storage, persistent documentation, RAG indexing/retrieval, and opaque public link publishing for LibreChat agents.
Related fork: this server is designed to work with a fork of ForLegalAI/mcp-ms-office-documents that stores generated Office documents (
.docx/.xlsx/.pptx/.eml/.xml) in the user's private storage here via thePOST /binaryendpoint. See the fork's documentation for thePERSONAL_FILESupload strategy.
Features
Per-user storage: Private files under
/data/private/<userId>/with full CRUD, list, move operations.Binary file support:
write_binary_file/read_binary_file(base64) MCP tools plus aPOST /binarymultipart endpoint (service-token authenticated) so other services — e.g. the Office-documents fork — can store generated.docx/.xlsx/.pptxfiles per user.Multi-scope documentation catalog:
save_documentationauto-routes toprojects/<project_id>/ordocs/with fail-closed resolver; each scope maintains its ownmemory-index.json(schema v3). Catalog files are protected from direct LLM writes.RAG integration:
index_documentsends content to rag_api viaPOST /embedwith canary verification;search_knowledgefor semantic search;remove_from_knowledgefor deletion.Public publishing:
publish_filecreates cryptographically random tokens (≥128 bits); files served directly via streamingFileResponsewithContent-Disposition: attachment,nosniff,no-store, and HTTP Range support (compatible with Traefik/Dokploy and Nginx).Strict security: Fail-closed on missing/invalid
X-User-Id; path traversal blocked; no absolute paths; no..segments; symlink escape detection; reserved segment protection; atomic index writes with cross-process locking.
Related MCP server: DJAI Tools MCP
Architecture
┌──────────────┐ ┌────────────────────────────────┐ ┌─────────────┐
│ LibreChat │────▶│ librechat-personal-files-mcp │──▶ │ rag_api │
│ (Agent) │ MCP │ (stateless HTTP /mcp) │ │ (vector DB) │
└──────────────┘ └────────────────────────────────┘ └─────────────┘
│
│ GET /files/{token}
▼
┌──────────────┐
│ Proxy/Router │ (Traefik / Nginx)
└──────────────┘
│
▼
┌──────────────┐
│ Public Client│ (Direct chunk streaming)
└──────────────┘Requirements
A running LibreChat instance with
rag_apienabled.A
JWT_SECRETshared with LibreChat andrag_api(see below).A reverse proxy (Traefik in Dokploy, or Nginx) routing
/files/to the MCP container.
Installation
1. Get the Docker image
Pull a pre-built image from GHCR, pinning an explicit tag:
docker pull ghcr.io/martinriesel/librechat-personal-files-mcp:<tag>Images are built by CI from v* git tags (published as the tag without the v, e.g. v1.5.0-test → 1.5.0-test) and from main (main / latest). Check the package page for the available tags. latest follows main and may lag behind the newest tagged version.
Or build it yourself:
git clone https://github.com/martinriesel/librechat-personal-files-mcp.git
cd librechat-personal-files-mcp
docker build -t librechat-personal-files-mcp .2. Prepare storage
The container runs as UID 2000 / GID 2500. Published files are streamed by the MCP container itself, so the reverse proxy does not need access to the data directory.
The compose snippet uses named volumes; Docker initializes them from the image with the correct ownership, so no host preparation is needed. If you prefer bind mounts instead, create the directories once (as root):
cd /path/to/your/librechat
groupadd -g 2500 lcfiles 2>/dev/null || true
mkdir -p ./data/private/_system
chown -R 2000:2500 ./data/private
chmod 2770 ./data/private # group rwx + setgid; no world access neededEnsure JWT_SECRET is set in your LibreChat .env (same value must be shared with rag_api):
grep -q '^JWT_SECRET=' .env || echo "JWT_SECRET=$(openssl rand -hex 32)" >> .env3. Add the service to your compose file
Add the service block from docker-compose.snippet.yml to your docker-compose.override.yml (or paste it into a Dokploy Compose application):
A
librechat-personal-filesservice (image, environment, volumes, networks).
Set PUBLIC_BASE_URL to your own public URL, e.g. https://chat.example.com/files, replace <tag> with an existing image tag and <shared-network> with a Docker network that also contains rag_api and MongoDB (and your reverse proxy), so their hostnames resolve from inside this container. Secrets (JWT_SECRET, PERSONAL_FILES_SERVICE_TOKEN → SERVICE_TOKEN, LIBRECHAT_MONGO_URI) come from your environment / .env, never from the compose file.
After deploying, check from inside the container that rag_api is reachable: /healthz should report "rag": "available". A Temporary failure in name resolution error from the RAG tools means the containers do not share a network.
Then start it:
docker compose up -d librechat-personal-files4. Configure the reverse proxy (Traefik or Nginx)
Option A: Traefik (Dokploy)
In the Dokploy dashboard, configure a Domain for librechat-personal-files:
Host:
chat.example.comPath:
/files/Internal Port:
8080HTTPS: enabled
See docs/links-publicos-dokploy-traefik.md for architecture details and verification steps.
Option B: Nginx
Add this location to your existing Nginx server block:
location ^~ /files/ {
proxy_pass http://librechat-personal-files:8080/files/;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
}5. Activate the MCP server in LibreChat
In the LibreChat Admin Panel → MCP Servers, add (or in your librechat.yaml):
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}}'
requestHeaders:
X-Conversation-Id: '{{LIBRECHAT_BODY_CONVERSATIONID}}'Restart LibreChat. The personal-files server will be available to your agents.
See docs/mongodb-permissions-dokploy.md for Docker shared network setup, MongoDB mcp_project_reader user creation, and connection parameters.
Usestreamable-http at /mcp only. SSE at /mcp/sse is not supported and should not be configured.
Enabling Tools in a LibreChat Agent
After the MCP server is connected, enable specific tools in your agent configuration:
Go to Admin Panel → Agents (or edit your agent YAML).
Under MCP servers, select
personal-files.Enable the tools you want the agent to use. Key tools to enable:
save_documentation,update_documentation,list_documentation— document management.get_project_context,list_projects— project discovery (read-only).search_knowledge,index_document,index_batch— RAG operations.register_documentation,transfer_documentation,reconcile_documentation— catalog maintenance.publish_file,get_public_link— public link management.
Save and test the agent in a project conversation.
6. Service-to-service binary uploads (POST /binary)
Other services can store files in a user's private storage without speaking
MCP. Set SERVICE_TOKEN on this server and have the service send a multipart
request:
POST http://librechat-personal-files:8080/binary
X-Service-Token: <SERVICE_TOKEN>
X-User-Id: <userId>
form: file=<bytes>, path=office/report.docxBoth SERVICE_TOKEN and a valid X-User-Id are required (fail-closed); the
path goes through the same path-safety checks as every other tool. On success
it returns {path, filename, mime_type, size_bytes, sha256}.
This is how the Office-documents fork
stores generated .docx/.xlsx/.pptx files per user (see its PERSONAL_FILES
strategy).
Volume Preservation & Deployment
The volume mounted at/data/private contains all user files and documentation indexes. Never delete or recreate this volume during version upgrades.
Use published images: Deploy stable tags from
ghcr.io/martinriesel/librechat-personal-files-mcp:<tag>.Avoid fixed
container_name: Let Dokploy manage container lifecycle for safe rolling updates and rollbacks.Verify networks after changes: After modifying network settings in Dokploy, verify effective networks with
docker inspect <container>— saving the option or restarting may not be sufficient.
Environment Variables
Variable | Default | Description |
|
| Header carrying the user identity |
|
| Root directory for user data |
|
| Legacy shared area (read/write during migration) |
|
| rag_api endpoint |
| required | HS256 secret shared with LibreChat/rag_api (≥32 chars) |
|
| Base URL for public links |
|
| Max upload size for text files |
|
| Max upload size for binary files ( |
| (empty) | Shared token required by the |
|
| SQLite registry for public links |
|
| Header carrying the conversation identity |
| (empty) | Read-only MongoDB connection URI for project resolution |
|
| MongoDB database name |
|
| Timeout in ms for project resolution queries |
|
| Application log level ( |
|
| Enable single-line JSON context diagnostic logging (see docs/diagnostics-and-logs.md) |
SetPERSONAL_FILES_CONTEXT_DIAGNOSTICS=false in production after initial validation is complete. See docs/diagnostics-and-logs.md for troubleshooting guidance.
MCP Tools
Storage
list_files(path="", recursive=false, pattern=null)— list files/dirsread_file(path)— read UTF-8 text; error for binary or >2 MBread_multiple_files(paths)— read several text files at oncewrite_file(path, content)— write text (UTF-8), creates parent dirs (protected from modifyingmemory-index.json)write_binary_file(path, content_base64)— write a binary file (e.g. Office documents); uses the binary size limit, never indexesread_binary_file(path)— read any file as base64 (binary or text)update_file(path, content)— update existing fileedit_file(path, edits)— find/replace text (eacholdTextmust match exactly once)delete_file(path)— delete file or directorymove_file(src, dst)— move within user rootget_file_info(path)— metadata + docindex + publishing status
Documentation (Multi-Scope Catalog)
Documentation files and catalogs follow a structured hierarchy:
General scope:
docs/*.mdwith catalogdocs/memory-index.jsonProject scope:
projects/<project_id>/*.mdwith catalogprojects/<project_id>/memory-index.jsonDirect LLM writes/edits/deletions of any
memory-index.jsonare rejected (protected_file).
Tools:
save_documentation(filename, content, title?, description?, tags?, topics?, project_id?, project_name?)— auto-routes toprojects/<project_id>/for project chats, ordocs/for chats proven without a project. Fails closed (project_resolution_failed) if resolver errors.filenameis a file name only: documents are stored flat, and a subfolder (e.g.folder/note.md) is rejected withsubfolder_not_supportedinstead of being dropped. Usewrite_filefor arbitrary folders.update_documentation(filename, content, title?, description?, tags?, topics?, project_id?, project_name?)— updates existing doc across catalogs, preserving existing project association.get_document_metadata(filename)— looks up document across catalogs bydoc_id, relative path, or filename. Returns metadata includingmodified_since_indexing.list_documentation(project_id?, tag?, unassigned_only=false)— lists registered documentation across scopes or filtered by project/unassigned, reportingdoc_idand indexing status.register_documentation(path, title?, description?, tags?, topics?, project_id?, project_name?)— registers an existing.md/.txtfile on disk into the catalog without rewriting its contents.transfer_documentation(identifier, target_project_id?, target_filename?, dry_run=false)— transfers a document between general and project scopes or between projects, preservingdoc_id, metadata, RAG status, and public link URLs. Sets the destinationproject_namefrom LibreChat (cleared when moving todocs/). Supports collision detection and dry-run preview.reconcile_documentation(project_id?, repair=false)— scans for unregistered files on disk, orphaned catalog entries, and modified files after indexing. Repairs discrepancies only whenrepair=true.
RAG & Batch Indexing
search_knowledge(query, limit=8, project_id?, scope="auto")— semantic search with project scoping (auto,project,personal,all). In a project conversation,autorestricts candidate documents to the active project's indexed files.autosearches all documents only when the conversation is confirmed to have no project; if the project cannot be resolved it returnsproject_resolution_failedinstead of widening the search. Project membership = explicitproject_idmetadata, or theprojects/<id>/catalog the entry lives in (same rule aslist_projects/get_project_context).index_document(path)— embed + canary verify, updates index status and records content SHA-256 (indexed_sha256) to track post-index modifications.index_batch(doc_ids?, project_id?, only_pending=false, only_modified=false)— batch indexes multiple candidate documents (selected, pending, or modified) with individual per-file status reporting.remove_from_knowledge(path)— delete from rag_api, clears index.get_index_status()— returns counts of total, indexed, pending, failed, and modified-after-indexing documents, plus rag_api health.
How automatic project search works (scope="auto")
LibreChat sends the conversation ID in the
X-Conversation-Idrequest header (seerequestHeadersabove).The server looks up that conversation in LibreChat's MongoDB (read-only, filtered by the authenticated user) and reads its
chatProjectId.The search is restricted to the indexed documents that belong to that project. Only their
file_ids are sent torag_api, so documents from other projects never reach the model.If the conversation is confirmed to have no project,
autosearches all of the user's indexed documents.If the project cannot be determined (database unreachable, conversation not yet saved, missing or invalid header), the tool returns
project_resolution_failedand does not queryrag_api. It never widens the search silently.
A document belongs to a project when its catalog entry has that project_id, or, if it has none, when it is catalogued in projects/<project_id>/. The same rule is used by list_projects, get_project_context and list_documentation.
Example result in a project conversation:
{"query": "deployment checklist", "scope": "project", "project_id": "<project_id>", "count": 3, "results": ["..."]}Explicit scopes do not need project resolution: scope="project" with project_id, scope="personal" (documents with no project) and scope="all".
Publishing
publish_file(path, expires_in_days?)— create/reuse public link, returns token + URLunpublish_file(path_or_token)— revoke link by token or path, including root-level files (file stays private)get_public_link(path)— active link for pathlist_public_links()— all links for user
Project Context & Management
get_project_context()— resolves the active LibreChat project for the current conversation via read-only MongoDB query (conversations->chatprojects). Returns structured JSON with status (project,no_project,conversation_unavailable,context_missing, etc.), project documents catalog, andsummary_fileif present.list_projects()— lists authorized LibreChat projects from MongoDB combined with on-disk project directories, including document counts and indexing status. See docs/mongodb-permissions-dokploy.md for database user configuration.
Security Model
Identity:
X-User-Idheader injected by LibreChat ({{LIBRECHAT_USER_ID}}). Placeholder unresolved → empty string → fail-closed.Fail-closed: Missing/empty/invalid header → HTTP 403
{"error":"missing_user_identity"}or{"error":"invalid_user_identity"}.Path safety: All paths are relative; absolute paths and
..rejected; symlink escape detected viaPath.resolve()+ prefix check.Isolation: rag_api owner scope enforced by JWT
sub/id= userId.Public links: Opaque
secrets.token_urlsafe(16)tokens; no user/path in URL; revocation via410 Gone; lazy cleanup of expired entries.
Development
python -m venv .venv
.venv/bin/pip install -e ".[dev]"
# Run tests
.venv/bin/pytest -q
# Lint
.venv/bin/ruff check .License
MIT
Tool Schema Changelog
Recent tool additions, removals, and schema changes observed during successful MCP inspections.
Loading tool schema changelog…
Related MCP Connectors
Document hosting and encrypted agent memory with multi-tenant persistence.
Hosted file storage for agents: upload, list, download, share by link, expire, scratch.
Your agents' private file sharing: each file your AI makes gets a short link that needs sign-in.
Persistent file storage for AI agents. Save files over MCP, get a link a human can open.
Related MCP Servers
- AlicenseNot gradedqualityDmaintenanceEnables uploading, organizing, and semantically searching documents with support for various file types and embedding providers.MIT
- AlicenseAqualityDmaintenanceProvides 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
- AlicenseBqualityCmaintenanceEnables file-based knowledge management with ranked keyword and semantic hybrid search, allowing AI agents to learn from documents and recall relevant knowledge as a persistent memory tool.30AGPL 3.0
- FlicenseNot gradedqualityAmaintenanceEnables LLMs and AI agents to directly access and operate on files in supported cloud storage, with tools for listing, reading, creating, deleting, moving, renaming, downloading, uploading, semantic search, share links, and URL upload tasks over SSE.-