Skip to content

Conversation

@danny-avila
Copy link
Owner

Summary

I implemented critical fixes for MCP (Model Context Protocol) integration and tool call handling in the agent system.

  • Fixed async/await issue where MCP instructions were not being properly awaited in AgentClient.buildMessages(), which was causing [object Promise] to appear in agent instructions instead of the actual MCP server instructions
  • Added comprehensive test suite for the MCP instructions integration to ensure proper async handling across different scenarios including ephemeral agents, empty instructions, and error cases
  • Implemented filterMalformedContentParts() utility function to filter out malformed tool call content parts that lack the required tool_call property, preventing frontend rendering issues
  • Added extensive test coverage for the content filtering utility with 200+ lines of tests covering edge cases and real-world MCP response scenarios
  • Updated AgentClient.sendCompletion() to apply the malformed content filter before returning content parts
  • Enhanced frontend ToolCall component to skip rendering of incomplete tool calls (missing name and output) unless they are the last part being streamed
  • Added isLast prop to Part component to properly identify the final content part during streaming
  • Upgraded @librechat/agents dependency from v3.0.15 to v3.0.17 in both api and packages to support the fixes

Change Type

  • Bug fix (non-breaking change which fixes an issue)
  • This change requires a documentation update

Testing

I tested these changes by running conversations with MCP servers enabled and verifying that:

  1. MCP instructions are properly injected into agent system prompts without [object Promise] artifacts
  2. Tool calls with malformed content (missing tool_call property) are filtered out and don't cause rendering errors
  3. Multiple concurrent tool calls from MCP servers display correctly
  4. Unit tests pass for both the async MCP instruction formatting and the content filtering logic

Test Configuration

  • Node.js environment with Jest test runner
  • MCP servers configured with multiple tool definitions
  • Agent conversations with multiple concurrent tool calls
  • Unit test coverage for edge cases including null/undefined parts, empty arrays, and malformed data structures

Checklist

  • My code adheres to this project's style guidelines
  • I have performed a self-review of my own code
  • I have commented in any complex areas of my code
  • I have made pertinent documentation changes
  • My changes do not introduce new warnings
  • I have written tests demonstrating that my changes are effective or that my feature works
  • Local unit tests pass with my changes
  • Any changes dependent on mine have been merged and published in downstream modules

@danny-avila danny-avila changed the base branch from main to dev November 13, 2025 19:01
@danny-avila danny-avila merged commit cabc8af into dev Nov 13, 2025
7 checks passed
@danny-avila danny-avila deleted the fix/minor-issues-2025-11-13 branch November 13, 2025 19:17
sofvanh pushed a commit to sofvanh/LibreChat that referenced this pull request Nov 18, 2025
…avila#10485)

* fix: Await MCP instructions formatting in AgentClient

* fix: don't render or aggregate malformed tool calls

* fix: implement filter for malformed tool call content parts and add tests
Guiraud pushed a commit to Guiraud/LibreChat that referenced this pull request Nov 21, 2025
…avila#10485)

* fix: Await MCP instructions formatting in AgentClient

* fix: don't render or aggregate malformed tool calls

* fix: implement filter for malformed tool call content parts and add tests
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.

2 participants