Skip to content

Conversation

hayeah
Copy link
Contributor

@hayeah hayeah commented May 10, 2025

Description

This PR adds a registration tracking mechanism to prevent the same adapter from registering multiple tool execution listeners. This fixes potential issues where duplicate event handlers could be created.

Changes

  • Added a Set to track which adapters have already registered listeners
  • Added a guard in the setupToolExecutionListener function to skip registration if an adapter attempts to register more than once
  • Added logging to help debug when duplicate registration attempts are attempted

Fixes

Fixes #21

Testing

Tested with multiple adapters to ensure:

  • Adapters only register once even when the setup function is called multiple times
  • Tool execution results are properly inserted without duplication
  • Console logs show when duplicate registration attempts are skipped

This commit adds a registration tracking mechanism to prevent the same adapter
from registering multiple tool execution listeners. This fixes potential issues
where duplicate event handlers could be created, leading to:

- Multiple insertions of the same tool execution results
- Increased memory usage from redundant event listeners
- Possible race conditions in the tool execution workflow

The fix uses a Set to track which adapters have already registered listeners
and skips registration if an adapter attempts to register more than once.

Fixes srbhptl39#21
@hayeah hayeah requested a review from srbhptl39 as a code owner May 10, 2025 02:16
@srbhptl39 srbhptl39 merged commit 1e0610a into srbhptl39:main May 10, 2025
1 check passed
@srbhptl39
Copy link
Owner

Thanks @hayeah for the fix.

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.

MCP Tool result gets inserted (or uploaded) multiple times.
2 participants