-
Notifications
You must be signed in to change notification settings - Fork 0
Description
Problem Statement
Add MCP resource operations to MCPClient. The Model Context Protocol supports resource operations that allow servers to expose data and content that can be read by clients. This feature will enable Strands SDK users to interact with MCP resources.
Proposed Solution
Implement three new synchronous methods in the MCPClient class:
list_resources_sync(pagination_token)- List available resources from the MCP serverread_resource_sync(uri)- Read specific resource content by URIlist_resource_templates_sync(pagination_token)- List resource templates with URI patterns
Implementation Status
Branch: 1117
Completed:
- ✅ Implementation of three resource methods in
src/strands/tools/mcp/mcp_client.py - ✅ Comprehensive unit tests in
tests/strands/tools/mcp/test_mcp_client.py - ✅ Proper error handling and session validation
- ✅ Pagination support
- ✅ Type hints and documentation
Remaining Work:
-
Resolve Merge Conflicts
- Conflict in
tests/strands/tools/mcp/test_mcp_client.py - Main branch added tests for metadata and error handling
- Branch 1117 added resource operation tests
- Resolution: Merge main into 1117, preserve all tests from both branches
- Conflict in
-
Add Integration Tests
- Currently only unit tests exist (with mocks)
- Need end-to-end tests with actual MCP server
- Must test all three operations: list, read, templates
- Should test pagination, error handling, and resource templates
- Location:
tests_integ/mcp/test_mcp_client.py
Implementation Requirements
Files to Modify
-
tests/strands/tools/mcp/test_mcp_client.py(merge conflict resolution)- Merge main branch changes
- Keep both sets of tests
- Ensure no test functionality is lost
-
tests_integ/mcp/test_mcp_client.py(add integration tests)- Add
@mcp.resourcedecorators tostart_comprehensive_mcp_server() - Create test resources (text files, JSON, CSV examples)
- Add resource templates with URI patterns
- Implement
test_mcp_client_resources()function - Implement
test_mcp_client_resources_error_handling()function - Remove TODO comment at lines 145-147
- Add
Integration Test Requirements
Test Coverage Must Include:
- ✅ List all available resources
- ✅ Read specific resource by URI (string and AnyUrl)
- ✅ List resource templates
- ✅ Use resource templates with parameters
- ✅ Pagination support (if server supports it)
- ✅ Error handling for invalid URIs
- ✅ Verify resource content matches expectations
- ✅ Test multiple resource types (text, JSON, CSV)
Test Server Requirements:
- At least 3 different resources with different URIs
- At least 1 resource template with URI pattern
- Different content types (plain text, JSON, CSV)
- Should integrate with existing SSE/streamable-http transport
Acceptance Criteria
- Merge conflicts in test file are resolved
- Main branch is merged into branch 1117
- All unit tests pass (
hatch test) - Integration tests are implemented
- Integration tests pass (
hatch run test-integ) - Code follows style guide (
hatch fmt --formatterandhatch fmt --linter) - All three resource operations work end-to-end with test server
- Documentation is clear and follows existing patterns
- Error handling is tested
Technical Notes
Development Commands:
# Format code
hatch fmt --formatter
# Run linting
hatch fmt --linter
# Run unit tests
hatch test
# Run integration tests
hatch run test-integMCP Server Resource Pattern (FastMCP):
from mcp.server import FastMCP
mcp = FastMCP("Server Name")
@mcp.resource(uri="file://path/to/resource")
def resource_function() -> str:
return "resource content"
@mcp.resource(uri="file://path/{param}")
def resource_template(param: str) -> str:
return f"resource with {param}"Use Case
Enable Strands SDK users to:
- Discover available resources from MCP servers
- Read resource content by URI
- Use resource templates for dynamic resource access
- Integrate MCP resource data into agent workflows
Additional Context
This feature aligns with the Model Context Protocol specification for resources. The implementation follows existing patterns in the MCPClient class for tools and prompts, maintaining consistency in the SDK's API design.