Skip to content

Conversation

mkmeral
Copy link

@mkmeral mkmeral commented May 26, 2025

Description

This PR adds comprehensive MCP (Model Context Protocol) integration to Strands CLI, enabling agents to connect to and use external tools and services through standardized MCP servers.

Key features:

  • MCP Client Support: Connect to any MCP server via stdio or SSE transports
  • Multi-Server Connections: Support for multiple simultaneous MCP connections
  • Automatic Tool Loading: Tools from MCP servers are automatically loaded and available to agents
  • Flexible Configuration: Configure via command line argument, JSON file, or environment variable
  • Graceful Lifecycle Management: Automatic connection on startup and disconnection on exit

The implementation includes:

  • New mcp_utils.py module for MCP configuration loading and connection management
  • --mcp-config command line argument for specifying MCP server configurations
  • Integration with the mcp_client tool for server communication
  • Comprehensive error handling and status reporting
  • Full test coverage for all MCP functionality

Type of Change

  • New feature

Testing

All tests have been added and are passing:

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

Added comprehensive test coverage:

  • test_strands_mcp_integration.py - Tests for MCP integration in main module
  • test_mcp_utils.py - Tests for MCP utility functions
  • Tests cover configuration loading, connection initialization, disconnection, and error handling

Additionally tested using mcp.json below

{
  "mcpServers": {
    "perplexity-ask": {
      "command": "docker",
      "args": [
        "run",
        "-i",
        "--rm",
        "-e",
        "PERPLEXITY_API_KEY",
        "mcp/perplexity-ask"
      ],
      "env": {
        "PERPLEXITY_API_KEY": "REDACTED"
      }
    },
    "github": {
      "command": "docker",
      "args": [
        "run",
        "-i",
        "--rm",
        "-e",
        "GITHUB_PERSONAL_ACCESS_TOKEN",
        "ghcr.io/github/github-mcp-server"
      ],
      "env": {
        "GITHUB_PERSONAL_ACCESS_TOKEN": "REDACTED"
      }
    }
  }
}

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 16:04
@awsarron
Copy link
Member

Related: #4

@awsarron awsarron self-assigned this May 29, 2025
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.

2 participants