Skip to content

Conversation

@mkmeral
Copy link
Contributor

@mkmeral mkmeral commented May 26, 2025

Description

This PR introduces a new MCP (Model Context Protocol) client tool for Strands Agents that provides a high-level interface for connecting to any MCP server with simplified configuration and enhanced functionality.

Key Features:

  • Multiple Transport Support: Connect to MCP servers via stdio (for local processes) or SSE (Server-Sent Events) for web-based servers
  • Simplified Configuration: Direct parameter passing without complex nested configurations
  • Connection Management: Thread-safe connection storage with support for multiple simultaneous connections
  • Tool Discovery: List available tools from connected MCP servers
  • Direct Tool Invocation: Call MCP tools directly or load them into the agent's tool registry
  • Environment Variable Support: Pass environment variables to stdio-based MCP servers
  • Comprehensive Error Handling: Detailed error messages and connection status tracking

Usage Examples:

# Connect to a custom MCP server
agent.tool.mcp_client(
    action="connect",
    connection_id="my_server",
    transport="stdio",
    command="python",
    args=["server.py"]
)

# List available tools
agent.tool.mcp_client(
    action="list_tools",
    connection_id="my_server"
)

# Call a tool directly
agent.tool.mcp_client(
    action="call_tool",
    connection_id="my_server",
    tool_name="calculate",
    x=10,
    y=20
)

# Load tools into agent's registry for direct access
agent.tool.mcp_client(
    action="load_tools",
    connection_id="my_server"
)

Related Issues

N/A

Documentation PR

N/A - Documentation is included in the README.md update

Type of Change

  • Bug fix
  • New Tool
  • Breaking change
  • Other (please describe):

Testing

The implementation includes comprehensive unit tests covering:

  • Connection management (stdio and SSE transports)
  • Tool listing and discovery
  • Direct tool invocation
  • Tool loading into agent registry
  • Error handling scenarios
  • Thread safety
  • Full workflow integration tests

Testing commands run:

  • hatch fmt --linter
  • hatch fmt --formatter
  • hatch test --all

Manual Testing

**user:** use perplexity mcp from ~/.aws/amazonq/mcp.json and tell me what techno events are in amsterdam this weekend

**strands:** connected to Perplexity MCP server using `mcp_client(action="connect")` with stdio transport, reading config from ~/.aws/amazonq/mcp.json

**strands:** called `mcp_client(action="call_tool", tool_name="perplexity_ask")` to search for Amsterdam techno events, found 4 events including Amsterdam Sessions at Machinegebouw

**user:** load mcp's tools

**strands:** executed `mcp_client(action="load_tools")` to register MCP tools directly into agent, successfully loaded mcp_perplexity_perplexity_ask tool

**user:** using this tool, tell me what events there are this weekend at radion, lofi and thuishaven

**strands:** directly called loaded `mcp_perplexity_perplexity_ask()` tool without going through mcp_client, found Vault Sessions x BASSIANI event at Radion with full lineup details

Key achievements:

  • Connected to MCP server from JSON config file
  • Called MCP tools through the client interface
  • Loaded MCP tools into agent's native tool registry
  • Used loaded MCP tools directly like built-in tools
  • Seamless integration of external MCP services into Strands workflow

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.

@mkmeral mkmeral requested a review from a team as a code owner May 26, 2025 14:21
@mkmeral
Copy link
Contributor Author

mkmeral commented May 27, 2025

Related strands-agents/agent-builder#4

Murat Kaan Meral added 2 commits May 31, 2025 00:23
- Add streamable_http transport option alongside stdio and sse
- Support headers, timeout, sse_read_timeout, terminate_on_close, and auth parameters
- Add comprehensive tests for streamable HTTP functionality
- Update README with streamable HTTP example
cagataycali
cagataycali previously approved these changes Jun 6, 2025
Copy link
Member

@cagataycali cagataycali left a comment

Choose a reason for hiding this comment

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

Looks great! Approving and leaving a room to team to take a look!

@dbschmigelski dbschmigelski self-requested a review June 11, 2025 16:04
@Unshure Unshure assigned dbschmigelski and unassigned awsarron Jun 17, 2025
@zastrowm zastrowm mentioned this pull request Jul 1, 2025
10 tasks
@zastrowm zastrowm assigned mkmeral and unassigned dbschmigelski Jul 21, 2025
dbschmigelski
dbschmigelski previously approved these changes Jul 28, 2025
Copy link
Member

@dbschmigelski dbschmigelski left a comment

Choose a reason for hiding this comment

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

Approving after offline discussion about consistency, but want to reiterate that mcp_client as the name seems potentially dangerous.

@mkmeral mkmeral merged commit b96df8d into strands-agents:main Jul 28, 2025
15 of 16 checks passed
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