mcp-agent
mcp-agent copied to clipboard
Callbacks to track agent server/tool calls
Is it possible to register a callback that tells me when a tool call by the agent occurs? For example, I have a MCP "search server", and when I chat with my app, I'd like to know if the agent is calling the search tools.
This reply is super weird. @saqadri I suppose this is not affiliated in any way with lastmile-ai right?
This reply is super weird. @saqadri I suppose this is not affiliated in any way with lastmile-ai right?
Looks like spam, unfortunately.
Is it possible to register a callback that tells me when a tool call by the agent occurs? For example, I have a MCP "search server", and when I chat with my app, I'd like to know if the agent is calling the search tools.
There is some support for this added by @evalstate (https://github.com/lastmile-ai/mcp-agent/blob/main/src/mcp_agent/event_progress.py#L10)
You need to add to add an event listener similar to this: https://github.com/lastmile-ai/mcp-agent/blob/main/src/mcp_agent/logging/listeners.py#L109
By doing event_bus = AsyncEventBus.get(), and then event_bus.add_listener
It's a bit clunky so let me see if we can make this better.
Hi @saqadri I’ve also encountered a similar issue. If I could display the logger’s (ProgressAction) status in streamlit while waiting for the LLM to return results, it will be very cool. So I’m wondering if there’s a simpler way to retrieve those states.
Here’s what I’ve tried so far (and some of the challenges I ran into):
- I created a custom listener (ProgressCollectorListener) that uses convert_log_event to gather progress states.
- However, I’m having trouble getting the events dispatched to my custom listener (the default LoggingListener works fine for console output, but my listener doesn’t receive the events I need).
- I’ve also run into “the future belongs to a different loop” errors, so getting everything synchronized in an async environment has been tricky.
If anyone has a more straightforward way to tap into those progress states (especially for use inside a Streamlit UI), I’d love to know!
Hi @Jie211 -- are you essentially doing the same as these lines of code?
https://github.com/lastmile-ai/mcp-agent/blob/40bcf20bb490946949e0131663cc9319aca3378a/src/mcp_agent/logging/listeners.py#L109-L140
You should be able to make some small modifications to logger.py below to use a custom display listener, which would then get Update events as required.
# Only add progress listener if enabled in settings
if "progress" not in bus.listeners and kwargs.get("progress_display", True):
bus.add_listener("progress", ProgressListener())
best, @evalstate