Skip to content

Commit ecfb864

Browse files
feat(mcp): Implement basic support for Tasks (#1475)
1 parent cc4afb3 commit ecfb864

10 files changed

Lines changed: 945 additions & 49 deletions

File tree

AGENTS.md

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ strands-agents/
7272
│ │ │ ├── mcp_client.py # MCP client implementation
7373
│ │ │ ├── mcp_agent_tool.py # MCP tool wrapper
7474
│ │ │ ├── mcp_types.py # MCP type definitions
75+
│ │ │ ├── mcp_tasks.py # Task-augmented execution config
7576
│ │ │ └── mcp_instrumentation.py # MCP telemetry
7677
│ │ └── structured_output/ # Structured output handling
7778
│ │ ├── structured_output_tool.py
@@ -413,6 +414,60 @@ hatch test --all # Test all Python versions (3.10-3.13)
413414
- Use `pytest.mark.asyncio` for async tests
414415
- Keep tests focused and independent
415416

417+
## MCP Tasks (Experimental)
418+
419+
The SDK supports MCP task-augmented execution for long-running tools. This feature is experimental and aligns with the MCP specification 2025-11-25.
420+
421+
### Overview
422+
423+
Task-augmented execution allows tools to run asynchronously with a workflow:
424+
1. Create task via `call_tool_as_task`
425+
2. Poll for completion via `poll_task`
426+
3. Get result via `get_task_result`
427+
428+
### Configuration
429+
430+
Enable tasks by passing a `TasksConfig` to `MCPClient`:
431+
432+
```python
433+
from datetime import timedelta
434+
from strands.tools.mcp import MCPClient, TasksConfig
435+
436+
# Enable with defaults (ttl=1min, poll_timeout=5min)
437+
client = MCPClient(transport, tasks_config={})
438+
439+
# Or configure explicitly
440+
client = MCPClient(
441+
transport,
442+
tasks_config=TasksConfig(
443+
ttl=timedelta(minutes=2), # Task time-to-live
444+
poll_timeout=timedelta(minutes=10), # Polling timeout
445+
),
446+
)
447+
```
448+
449+
### Tool Support Levels
450+
451+
MCP tools declare their task support via `execution.taskSupport`:
452+
- `TASK_REQUIRED`: Tool must use task-augmented execution
453+
- `TASK_OPTIONAL`: Tool can use tasks if client opts in
454+
- `TASK_FORBIDDEN`: Tool does not support tasks (default)
455+
456+
### Decision Logic
457+
458+
Task-augmented execution is used when ALL conditions are met:
459+
1. Client opts in via `tasks_config` (not None)
460+
2. Server advertises task capability (`tasks.requests.tools.call`)
461+
3. Tool's `taskSupport` is `required` or `optional`
462+
463+
### Key Files
464+
465+
- `src/strands/tools/mcp/mcp_tasks.py` - `TasksConfig` and defaults
466+
- `src/strands/tools/mcp/mcp_client.py` - Task execution logic (`_call_tool_as_task_and_poll_async`)
467+
- `tests/strands/tools/mcp/test_mcp_client_tasks.py` - Unit tests
468+
- `tests_integ/mcp/test_mcp_client_tasks.py` - Integration tests
469+
- `tests_integ/mcp/task_echo_server.py` - Test server with task support
470+
416471
## Things to Do
417472

418473
- Use explicit return types for all functions

src/strands/tools/mcp/__init__.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99
from .mcp_agent_tool import MCPAgentTool
1010
from .mcp_client import MCPClient, ToolFilters
11+
from .mcp_tasks import TasksConfig
1112
from .mcp_types import MCPTransport
1213

13-
__all__ = ["MCPAgentTool", "MCPClient", "MCPTransport", "ToolFilters"]
14+
__all__ = ["MCPAgentTool", "MCPClient", "MCPTransport", "TasksConfig", "ToolFilters"]

0 commit comments

Comments
 (0)