Skip to content

ToolSearch server grouping crashes on inherited property names and blocks unrelated tools #607

Open

Description

@lokesh0186

Reproduction

A deferred MCP tool from a server named constructor prevents createToolSearch() from initializing, even if the intended search is for a different server. toString and hasOwnProperty produce the same error.

const { createToolSearch } = require('@librechat/agents');

const toolRegistry = new Map([
  ['weather_mcp_weather', {
    name: 'weather_mcp_weather',
    description: 'Read the weather forecast',
    defer_loading: true,
  }],
  ['status_mcp_constructor', {
    name: 'status_mcp_constructor',
    description: 'Read service status',
    defer_loading: true,
  }],
]);

const search = createToolSearch({ mode: 'local', toolRegistry });
// TypeError: toolsByServer[serverName].push is not a function

Replacing constructor with status allows initialization and a weather search returns weather_mcp_weather with score 1. All input is local metadata; no MCP server, model API, or external tool is called.

Cause and expected behavior

getDeferredToolsListing() groups server names into {} and uses serverName in toolsByServer. Inherited properties count as existing groups, so .push() is attempted on a function. formatServerListing() uses the same pattern and fails when formatting a preview.

These identifiers should be ordinary server keys, or explicitly rejected as invalid configuration. They should not make an unrelated server's ranked search unavailable. Using dictionaries without inherited properties fixes both grouping sites without changing search or ranking.

Versions and downstream path

Reproduced on current SDK main 97b2db3a329c105c39a250fd39534701b6c9ddb1 and the published npm bundles @librechat/agents@4.0.4 and 4.0.1, with Node 24.11.1. Published-bundle checks used dependencies installed from the current SDK lockfile.

LibreChat current main locks 4.0.4, and LibreChat v0.8.8 locks 4.0.1. Both versions of api/server/services/ToolService.js call createToolSearch({ mode: 'local', toolRegistry }). This is an SDK-level local reproduction, not a full LibreChat deployment test or an estimate of affected users.

Regression and fix

Eleven native tests cover ordinary controls and the three server names across initialization, listing, and preview. On unpatched main, nine fail and the two controls pass. A two-line fix makes all eleven pass; the existing ToolSearch suite also passes (136 tests combined). TypeScript checking passes. Targeted ESLint reports no errors and the same unrelated warning at ToolSearch.ts:1352 on both baseline and patched code.

This came from an ARDGuard-motivated audit of whether one server's discovery state can suppress unrelated candidates. The reduced case and correction are entirely native to this SDK; ARDGuard is not required to reproduce or fix it.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions