Skip to content

Conversation

Ketansuhaas
Copy link
Contributor

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

@zastrowm zastrowm added the area-mcp MCP related label Jul 22, 2025
@dbschmigelski
Copy link
Member

Hi,

Sorry but this has increased in priority because of internal needs. Thanks for marking this as editable by maintainers. I am taking over the PR to rebase, make some edits, and add tests. But @Ketansuhaas you will still have attribution on the PR, thanks for raising this.

@Ketansuhaas
Copy link
Contributor Author

Ketansuhaas commented Jul 24, 2025

Hi,

Sorry but this has increased in priority because of internal needs. Thanks for marking this as editable by maintainers. I am taking over the PR to rebase, make some edits, and add tests. But @Ketansuhaas you will still have attribution on the PR, thanks for raising this.

Thank you. I appreciate it.

@dbschmigelski
Copy link
Member

Noting that the recommendation in this PR is to expose the raw MCP SDK responses. This was not done for tools as the benefit of the MCPClient was to map the MCP tool to a Strands AgentTool.

For Prompts and Resources, there is not native Strand concept. So we have two options one is to expose them with 1-1 methods as we have here. The other is to instruct users to use the underlying mcp session that is created. I agree with the initial proposal that interacting with MCPClient(strands) and the underling MCPClient.session seems strange. Additionally, allowing users to operate in both sync and async mode requires us to handle the wrapping ourselves as the underlying method is async.

@dbschmigelski dbschmigelski self-assigned this Jul 25, 2025
@dbschmigelski dbschmigelski self-requested a review July 25, 2025 17:34
@dbschmigelski dbschmigelski changed the title feat: Add list_prompts, get_prompt methods feat(mcp): Add list_prompts, get_prompt methods Jul 25, 2025
poshinchen
poshinchen previously approved these changes Jul 25, 2025
@dbschmigelski dbschmigelski dismissed their stale review July 25, 2025 19:01

dismissing as I was the one who made many of these changes and should not self-review.

poshinchen
poshinchen previously approved these changes Jul 25, 2025
@dbschmigelski dbschmigelski merged commit b13c5c5 into strands-agents:main Jul 30, 2025
12 checks passed
dbschmigelski added a commit to dbavro19/sdk-python that referenced this pull request Aug 28, 2025
This was referenced Sep 17, 2025
Unshure pushed a commit to Unshure/sdk-python that referenced this pull request Sep 24, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area-mcp MCP related

Projects

None yet

Development

Successfully merging this pull request may close these issues.

8 participants