Skip to content

🔤 feat: Sort MCP Tools by Name in the Agent Editor - #17349

Open
VascoSch92 wants to merge 3 commits into
LibreChat-AI:devfrom
VascoSch92:feat/sort-mcp-tools-by-name
Open

VascoSch92 wants to merge 3 commits into
LibreChat-AI:devfrom
VascoSch92:feat/sort-mcp-tools-by-name

Conversation

@VascoSch92

@VascoSch92 VascoSch92 commented Oct 22, 2026 •

Copy link
Copy Markdown

Pull Request

Summary

When you open an MCP server in the agent editor (Agent Builder → Add tools → the server's gear), the tool checklist comes up in whatever order the server's tools/list returned. That order is picked by whoever wrote the server, so on a server with lots of tools you end up reading the whole list to find the one you want. This PR sorts the checklist by the tool's display name, ignoring case and comparing numbers by value (export_page_2 before export_page_10), which is what the issue asks for.

This one was really interesting for me. It looks like a one-liner, but following the list back from /api/mcp/tools through AgentPanelContext and mcpServersMap into McpSection, and checking that Select all and the bulk toggles all read from the same array, taught me a lot about how the agent tools panel fits together.

Related to #16428

How it works

-  const tools = useMemo(() => liveServer.tools ?? [], [liveServer.tools]);
+  const tools = useMemo(
+    () =>
+      [...(liveServer.tools ?? [])].sort((a, b) =>
+        a.metadata.name.localeCompare(b.metadata.name, undefined, {
+          numeric: true,
+          sensitivity: 'base',
+        }),
+      ),
+    [liveServer.tools],
+  );

I copy the array before sorting so the query data behind mcpServersMap doesn't get mutated. Everything else in the section (select all, deselect all, the bulk defer/programmatic/background/intent toggles) reads this same tools array, so it follows the new order with no other changes. The one side effect is that "Select all" now writes the tool ids into agent.tools in sorted order, which doesn't change anything at runtime. Nothing the model or the API sees is different.

Type of change

  • Feature

Testing

I ran LibreChat locally (backend plus the Vite dev client, MongoDB 7 in Docker) with a small stdio MCP server that registers eight tools in a deliberately scrambled order, with mixed case and numeric suffixes. Then I opened Agent Builder → Add tools → issue-tracker → gear and compared the checklist on dev and on this branch (screenshots below).

Tested environments/configuration:

  • Browser: Chromium (headless, Playwright), light mode
  • OS: macOS
  • Database: MongoDB 7 (Docker)
  • MCP: one stdio server configured in librechat.yaml

Automated tests:

  • Added lists tools by display name, ignoring case and comparing numbers by value to McpSection.spec.tsx. It fails on dev (it gets the server's order back) and passes on this branch.
  • Moved the shared fixture's two tools to the real { tool_id, metadata: { name } } shape, since the sort reads metadata.name.
  • npx jest src/components/SidePanel/Agents/Tools/ItemDialog/__tests__/McpSection.spec.tsx: 40/40 pass.
  • Full npx jest in client: 812 suites, 12,741 tests, all passing.
  • npx tsc --noEmit in client and npm run static-checks -- --against origin/dev are clean.

Screenshots / recordings

Before

Screenshot 2026-10-22 at 22 10 22

after

Screenshot 2026-10-22 at 18 00 14

Risk / compatibility

None. Only the display order changes; saved agents and tool ids are untouched.

#16359 (sorting the MCP server lists) could reuse the same comparison, and I'm happy to pick that up next if it helps.

Checklist

  • I reviewed my own changes
  • Relevant tests have been added or updated
  • Existing relevant tests pass
  • The change does not introduce new warnings or errors
  • User-facing or complex behavior is documented where necessary (not needed for a sort order)
  • Required dependency changes have been merged/published (none)
  • Required documentation PR: N/A

The agent editor listed an MCP server's tools in whatever order the
server's tools/list returned them, which makes a specific tool hard to
find on servers with many tools. Sort the checklist by the displayed
name, case-insensitively and with numeric collation (tool2 before
tool10). Select all, deselect all and the bulk toggles read the same
array, so they follow the new order.

Related to LibreChat-AI#16428
@VascoSch92
VascoSch92 marked this pull request as ready for review October 22, 2026 20:11

This branch has not been deployed

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant