Mintplex-Labs/anything-llm · error

${error.message}

Error message

${error.message}

What it means

Catch-all 500 for POST /mcp-servers/reload (admin only). MCPCompatibilityLayer.reloadMCPServers() restarts every configured MCP server; failure means at least one entry could not be spawned or connected — bad command/binary, missing env vars/API keys, invalid config, stdio spawn failure, or SSE/WebSocket handshake timeout. error.message names the underlying cause.

Solutions

  1. Read error.message — MCP client errors usually name the server and the failing phase (spawn/connect/handshake)
  2. Inspect the MCP servers config entry cited by the error (command path, args, env)
  3. Run the server's command manually from the app's shell to confirm it starts
  4. Fix or remove the broken entry and POST reload again — it is idempotent

Example fix

// before
await new MCPCompatibilityLayer().reloadMCPServers();
// after — validate each stdio command exists before reloading
const { execSync } = require('child_process');
for (const s of configuredServers.filter((s) => s.type === 'stdio'))
  execSync(`command -v ${s.command}`); // throws early with a clear message
await new MCPCompatibilityLayer().reloadMCPServers();
Defensive patterns

Strategy: retry

Validate before calling

// Confirm servers enumerate cleanly before forcing a reload
const list = await fetch('/mcp-servers/list');
if (!list.ok) throw new Error('MCP layer unhealthy — fix config before reload');

Try / catch

for (const delay of [0, 2000, 8000]) {
  await sleep(delay);
  try { return await fetch('/mcp-servers/reload', { method: 'POST' }); }
  catch (e) { last = e; } // transient npx download / spawn races often clear on retry
}
throw last;

Prevention

When it happens

Trigger: POST /mcp-servers/reload as admin when any configured MCP server fails to (re)launch: command not found on PATH, npx package download failure, missing env credentials for remote servers, unreachable SSE endpoint.

Common situations: Editing the MCP config and leaving a typo in command/args; the host lacks node/npx for stdio servers; a remote MCP server rotated its auth credentials.

Related errors


AI-assisted analysis of Mintplex-Labs/anything-llm@3aec848f28 (2026-08-18). Data as JSON: /api/errors/7a930e3a6546db53. Report an issue: GitHub.

Appendix: source

Thrown at server/endpoints/mcpServers.js:26

function mcpServersEndpoints(app) {
  if (!app) return;

  app.get(
    "/mcp-servers/force-reload",
    [validatedRequest, flexUserRoleValid([ROLES.admin])],
    async (_request, response) => {
      try {
        const mcp = new MCPCompatibilityLayer();
        await mcp.reloadMCPServers();
        return response.status(200).json({
          success: true,
          error: null,
          servers: await mcp.servers(),
        });
      } catch (error) {
        console.error("Error force reloading MCP servers:", error);
        return response.status(500).json({
          success: false,
          error: error.message,
          servers: [],
        });
      }
    }
  );

  app.get(
    "/mcp-servers/list",
    [validatedRequest, flexUserRoleValid([ROLES.admin])],
    async (_request, response) => {
      try {
        const servers = await new MCPCompatibilityLayer().servers();
        return response.status(200).json({
          success: true,
          servers,
        });

View on GitHub (pinned to 3aec848f28)