Skip to content

Conversation

@wreed4
Copy link
Contributor

@wreed4 wreed4 commented May 16, 2025

Fixes #177

@wreed4
Copy link
Contributor Author

wreed4 commented May 16, 2025

I haven't been able to figure out how to run tests successfully in this repo, but I think this is the fix. or close to it. I'll update when I figure out how to test it haha

@wreed4
Copy link
Contributor Author

wreed4 commented May 16, 2025

This seems to work, but it actually doesn't seem to be the desired behavior IMO.. because then when you go to execute a prompt in an agent that doesn't have the MCP server that's serving it, it fails. So I think we actually want to list prompts only from the current agent.

@evalstate
Copy link
Owner

Thank you for looking in to this - I've not had a chance to to myself yet - so if OK I'll ask here :)

Because Prompts are delivered by Servers, and Servers are attached to Agents "list prompts" is intended to list the combined set available Prompts available to the current Agent. You can then apply a prompt.

Is this behaviour currently not working?

What you can't currently do (and would be useful) would be to see which Agents have prompts available.

I was also in this area the other evening because I wanted to have a similar "List Tools" function - especially now that it supports dynamic tool lists, but stopped due to time!

@wreed4
Copy link
Contributor Author

wreed4 commented May 20, 2025

yes, the behavior you described is the behavior I'd expect. The actual behavior in the latest version is that the "list_prompts" function that is called from /prompts only and ever will list prompts from the mcp servers available to the first agent that is loaded into the agent app regardless of if you switch agents. Worse, if you try to execute a prompt that you know comes from an agent that you've switched to with /prompt foo (even if /prompts doesn't show it), it too will say it can't find the prompt.

So in effect, if you have multiple agents with different mcps each hosting their own prompts, there is no way in an interactive session to access any prompts other than those from mcp servers which the first agent loaded has access to.

The core bug is in src/mcp_agent/core/agent_app.py in AgentApp.list_prompts and AgentApp.apply_prompt, (or the usage of those functions rather). The callers are passing in None for the "agent" field which, when it goes into those functions, calls

    def _agent(self, agent_name: str | None) -> Agent:
        if agent_name:
            if agent_name not in self._agents:
                raise ValueError(f"Agent '{agent_name}' not found")
            return self._agents[agent_name]

        return next(iter(self._agents.values()))

Since agent_name is None, it goes to next(iter(self._agents.values())), the order of which is determined by the order of insertion into the map, which is determined by the order of agent startup. So you'll always get prompts just from the first agent.

I'm not sure I've fixed every case of this bug since I'm not sure how to add unit tests to this repo, or execute them. But this would be a good case for some unit tests. If helpful, I can generate a minimal reproducer when I get a chance.

@wreed4 wreed4 marked this pull request as ready for review May 23, 2025 14:13
@evalstate
Copy link
Owner

Thanks for diagnosing this and sending over the PR. I've updated it so the original intended behaviour works -- each agent lists the prompts from the Servers it is attached to. I've also started the process of unpicking some of the code. There's a lot more I'd like in that area such as:

  • A list of all available prompts across Agents (but think that's separate from the this functionality - unless picking a prompt also switches the agent?)
  • A list of Servers and Tools connected to the agent, including the Server implementation details and transport status.
  • Similar for Resources

@evalstate evalstate merged commit 703619f into evalstate:main May 30, 2025
5 checks passed
@wreed4 wreed4 deleted the fix-prompts-listing branch May 30, 2025 15:18
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.

/prompts and /prompt will only return the prompts available to the first agent the interactive prompt selected

2 participants