Skip to content

feat: Add list_prompts, get_prompt methods #160

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

Ketansuhaas
Copy link

Description

This PR introduces two new methods to the MCPClient class: list_prompts_sync and get_prompt_sync.

  • list_prompts_sync: This method synchronously retrieves a list of available prompts from the MCP server. It calls the asynchronous list_prompts method on the underlying MCP session and returns the ListPromptsResult.
  • get_prompt_sync: This method synchronously retrieves a specific prompt by its ID from the MCP server, along with any specified arguments. It calls the asynchronous get_prompt method on the MCP session and returns the GetPromptResult.

These additions enhance the MCPClient's capabilities to interact with MCP-based prompt services.

How to use:

Listing available prompts:

# Assuming mcp_client is an initialized MCPClient instance
prompts_result = mcp_client.list_prompts_sync()
for prompt in prompts_result.prompts:
    print(f"Prompt Name: {prompt.name}")
    print(f"Prompt Arguments: {prompt.arguments}")
    # print(f"Prompt Description: {prompt.description}") # If available

Getting a specific prompt:

# Assuming mcp_client is an initialized MCPClient instance
prompt_id_to_get = "sum-two-numbers" # Example prompt ID
arguments_for_prompt = {
    "a": "123",
    "b": "456"
}
prompt_response = mcp_client.get_prompt_sync(prompt_id_to_get, arguments_for_prompt)
if prompt_response.messages:
    print(f"Prompt Content: {prompt_response.messages[0].content.text}")

Related Issues

N/A

Documentation PR

N/A

Type of Change

  • New feature

Testing

  • hatch fmt --linter
  • hatch fmt --formatter
  • hatch test --all
  • Verify that the changes do not break functionality or introduce warnings in consuming repositories: agents-docs, agents-tools, agents-cli

Checklist

  • I have read the CONTRIBUTING document
  • I have added tests that prove my fix is effective or my feature works
  • I have updated the documentation accordingly
  • I have added an appropriate example to the documentation to outline the feature
  • My changes generate no new warnings
  • Any dependent changes have been merged and published

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

@Ketansuhaas Ketansuhaas requested a review from a team as a code owner June 1, 2025 03:43
@Ketansuhaas Ketansuhaas changed the title added list_prompts, get_prompt methods feat: add list_prompts, get_prompt methods Jun 1, 2025
@Ketansuhaas Ketansuhaas changed the title feat: add list_prompts, get_prompt methods feat: Add list_prompts, get_prompt methods Jun 1, 2025
@awsarron
Copy link
Member

awsarron commented Jun 1, 2025

related: #151


return list_prompts_response

def get_prompt_sync(self, prompt_id: str, args: dict[Any, Any]) -> GetPromptResult:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems like these MCP response types are missing imports

@@ -156,6 +156,52 @@ async def _list_tools_async() -> ListToolsResult:
mcp_tools = [MCPAgentTool(tool, self) for tool in list_tools_response.tools]
self._log_debug_with_thread("successfully adapted %d MCP tools", len(mcp_tools))
return mcp_tools

def list_prompts_sync(self) -> ListPromptsResult:
Copy link
Member

@dbschmigelski dbschmigelski Jun 2, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I want to thank you for proposing these changes. We appreciate the contributions and definitely are eager to expose MCP prompt features in Strands.

I think there are a few things missing here relating to the complete flow of mcp.

The Agent interacts with MCP servers through tools which are exposed via the AgentTool interface. In our case list_tools_sync is used to retrieve a list of AgentTools. These are then provided to the agent like

with streamable_http_mcp_client:
    tools = streamable_http_mcp_client.list_tools_sync()
    agent = Agent(tools=tools)

So, I think what is missing from this PR is the "how" of how the prompts will be exposed to the Agent as right now the agent lacks a mechanism to list and get the prompts. To address this, we should create an MCPPromptTool similar to the MCPAgentTool. The naming may be confusing here, but in essence, anything exposed to the Agent class must be via a tool. In this case, a "tool" available to the Agent will be the ability to fetch a prompt. The response of a get prompt is itself a ToolResult. There is an argument for making prompts first class citizens in the Agent class. But to expose this functionality now I believe this will be the best path forward.

In addition to that, we should add unit tests in the tests/tools/mcp directory and modify the integration tests in tests-integ/test_mcp_client.py.

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.

4 participants