Container Base Image Plan 4
Scope: Fix MCP server startup lag (env var access), eliminate constant package reinstalls, upgrade Node.js to v22, and comprehensively test all components, tools, MCP servers, and skills. Prior plan: Container Base Image Plan 3
Task 1 — Fix MCP server startup lag caused by env var access
The “MCP Server Lag Fix” conversation (2026-04-22) identified that when starting a new conversation, there is a 10–15 second delay before it appears. The root cause is that Railway env vars are NOT inherited by child processes (MCP stdio servers). The previous agent in that conversation discovered that env vars ARE accessible via
/proc/1/environ, and arailway_env.pyhelper module already exists for this. But the npx-based MCP servers (the majority) don’t use this helper — they rely on LibreChat’s${VAR}substitution inlibrechat.yaml, which injects vars via theenv:block. The lag occurs because LibreChat must resolve these env vars at startup and start each MCP server process, and some servers (npx-based) re-download packages on first invocation (npx -y), adding significant delay. Thestartup: falseflag exists for servers that shouldn’t auto-start, reducing initial load, but servers marked withstartup: true(or withoutstartup: false) all start on first conversation, causing the lag.
- Audit every MCP server in
librechat.yaml— for each, determine whether it should havestartup: false(deferred until first use) vs auto-start - Set
startup: falseon any server that is not needed at session start (most of them — onlyuvilo-filesystemanduvilo-shellare needed immediately) - Verify that the
env:blocks inlibrechat.yamlcorrectly inject Railway env vars via${VAR}substitution — confirm all 12 referenced vars (VERCEL_API_KEY,GITHUB_TOKEN,NEON_API_KEY,NOTION_TOKEN,LINEAR_ACCESS_TOKEN,RAILWAY_API_TOKEN,POSTHOG_API_KEY,COMPOSIO_SM_MCP_URL,COMPOSIO_API_KEY,SUPRSEND_SERVICE_TOKEN,TYPESENSE_HOST,TYPESENSE_SEARCH_KEY) are present in/proc/1/environ - For Python MCP servers (uvilo-shell, uvilo-trash, uvilo-typesense, suprsend-mcp-proxy), verify
railway_env.pyis imported andinject_railway_env()is called before any env var access — these servers must NOT rely onos.environalone - Test: start a new conversation and verify the delay is reduced to under 5 seconds
Task 2 — Eliminate constant package reinstalls
The “Update Agents” conversation (2026-04-22) showed that running
/update-agentsrequirednpx tsxwhich downloadstsx@4.21.0every time. Similarly, everynpx -yMCP server command downloads its package on each invocation. The npx cache at/root/.npm/_npx/is ~412MB with 9 cached packages, but these are version-pinned hashes that may not match the requested version. Theuvxcommands also re-resolve on each spawn. These reinstalls waste time and bandwidth, and are the primary contributor to MCP server startup lag.
- Audit all npx-based MCP server commands in
librechat.yamlto identify which packages are downloaded on each spawn - Pre-install frequently-used npm packages globally in the Dockerfile so
npxfinds them locally instead of downloading:npm install -g @modelcontextprotocol/server-filesystem @modelcontextprotocol/server-github @upstash/context7-mcp @notionhq/notion-mcp-server @touchlab/linear-mcp-integration @jasontanswe/railway-mcp mcp-remote vercel-mcp- Update the Dockerfile’s runtime stage to add this global install
- Pre-install frequently-used uvx packages in the Dockerfile so
uvxfinds them in the system Python:- Already done:
mcp,pymongo,dnspythonare installed viauv pip install --system - Add
mcp-server-gitif it can be pre-installed as a Python package
- Already done:
- Pre-install
tsxglobally (npm install -g tsx) so Forge scripts usingnpx tsxdon’t download it each time - Rebuild and push the Docker image with these changes
- Verify: run
npx tsx --versionwithout download delay, run a sample MCP server command without download delay - Update
Forge_Infrastructure.mdto document the pre-installed packages
Task 3 — Comprehensive component, tool, MCP server, and skill testing
Plans 1–3 validated the Debian-slim deployment at a high level (MCP servers start, basic tool calls work). But the lag fix conversation revealed that some MCP servers weren’t actually working correctly at runtime (env vars missing, servers crashing). This task performs a thorough end-to-end test of every component. Crucially, LibreChat logs must be examined for thrown errors — silent failures in MCP server startup or tool execution often only surface in logs, not in the agent’s conversation output.
-
Examine LibreChat logs — Before any testing, capture and review the LibreChat container logs for errors:
cat /proc/1/environ | tr '\0' '\n'— verify env vars are present- Check container logs for MCP server startup errors, connection failures, or unhandled rejections
- Fix any errors found before proceeding with functional tests — a broken server must be repaired before it can be meaningfully tested
- Re-check logs after each fix to confirm the error is resolved
-
MCP server tests — For each of the 17 MCP servers in
librechat.yaml, perform a meaningful functional test (not just “starts”):# MCP Server Test Action Expected Result 1 uvilo-filesystem read/write/search files File operations succeed 2 uvilo-shell execute a command Command output returned 3 uvilo-typesense search_knowledge Search results returned 4 uvilo-trash trash and untrash a test file File moved to .trash and restored 5 vercel getDeployments Deployment list returned 6 github tool_search Tools available 7 context7 resolve-library-id Library found 8 railway tool_search Tools available 9 neon tool_search Tools available 10 notion tool_search Tools available 11 linear tool_search Tools available 12 posthog insights-list Insights returned 13 playwright browser_navigate Page loaded 14 surveymonkey tool_search Tools available 15 suprsend-dev tool_search Tools available 16 suprsend-staging tool_search Tools available 17 suprsend-prod tool_search Tools available -
Skill tests — Test each Forge skill that has a runnable action:
# Skill Test Action Expected Result 1 Update_Agents /update-agents --dry-runDry run completes 2 Deploy_Config validate config Validation passes 3 Reindex_Typesense run indexing script Index updated 4 NPM verify pinned deps No floating versions -
Tool tests — Verify environment tools:
# Tool Test 1 git commit, push, pull 2 python3 import mcp, pymongo, dns 3 npx runs without download delay 4 uvx runs without download delay 5 tsx runs without download delay -
Record all test results in State 4
Task 4 — Upgrade Node.js from v20 to v22
The current Dockerfile uses
FROM node:20-slim, which provides Node.js 20.20.2. Astro 6 (used by the documentation site at.internal/) requires Node ≥22.12.0. The currentastro checkandastro buildcommands fail with:Node.js v20.20.2 is not supported by Astro! Please upgrade Node.js to a supported version: ">=22.12.0". This blocks the sidebar build verification step and any future Astro upgrades. Node 20 is also approaching EOL (April 2026 for the 20.x LTS line).
- Update
Forge/Configs-debian/Dockerfile.librechat:- Change
FROM node:20-slim(both builder and runtime stages) toFROM node:22-slim - Verify the 3-stage build pattern still works: source (Alpine) → builder (Node 22) → runtime (Node 22)
- The source stage still uses the Alpine LibreChat image (
ghcr.io/danny-avila/librechat:v0.8.5-rc1) — this is fine, it only copies/app
- Change
- Rebuild and push the Docker image locally:
docker build --pull --platform linux/amd64 -f Dockerfile.librechat -t ghcr.io/erikdakoda/librechat-git:debian-slim .- Verify Node version:
docker run --rm ghcr.io/erikdakoda/librechat-git:debian-slim node --version→v22.x.x - Push:
docker push ghcr.io/erikdakoda/librechat-git:debian-slim
- Redeploy on Railway and verify:
- Container starts successfully with Node 22
- LibreChat serves correctly
- All MCP servers start (Node 22 may have different native module requirements —
npm rebuildin the builder stage handles this) astro checkandastro buildnow succeed inside the container
- Update
Forge_Infrastructure.mdto reflect Node 22 - Verify
npm install -gfor pre-installed packages (Task 2) works on Node 22
Task 5 — Update infrastructure documentation
Reflect all changes from Tasks 1–3 in
Forge_Infrastructure.md.
- Update “MCP Server Details” section with any startup behavior changes
- Update “Debian-slim Container Notes” with the list of pre-installed global npm packages
- Document the
startup: falsestrategy for MCP servers - Document the
railway_env.pyinjection pattern as the standard for Python MCP servers - Remove or update any outdated Alpine-specific references
Task 5 — Create State document
Create the State document tracking this Plan’s tasks for the implementing agent.
- Copy
Forge/Skills/Project_Create/templates/State_Template.mdtoContainer_Base_Image_State_4.md - Convert each Task in this Plan into a checkbox item, with subtasks as nested checkboxes
- Set the
Related planlink to point to this Plan document