Skip to content

Commit 3250247

Browse files
committed
mcp_client implements tool_provider
1 parent 5d5a800 commit 3250247

File tree

14 files changed

+824
-746
lines changed

14 files changed

+824
-746
lines changed

src/strands/agent/agent.py

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -544,19 +544,7 @@ async def cleanup_async(self) -> None:
544544

545545
logger.debug("agent_id=<%s> | cleaning up agent resources", self.agent_id)
546546

547-
for provider in self.tool_registry.tool_providers:
548-
try:
549-
await provider.cleanup()
550-
logger.debug(
551-
"agent_id=<%s>, provider=<%s> | cleaned up tool provider", self.agent_id, type(provider).__name__
552-
)
553-
except Exception as e:
554-
logger.warning(
555-
"agent_id=<%s>, provider=<%s>, error=<%s> | failed to cleanup tool provider",
556-
self.agent_id,
557-
type(provider).__name__,
558-
e,
559-
)
547+
await self.tool_registry.cleanup_async()
560548

561549
self._cleanup_called = True
562550
logger.debug("agent_id=<%s> | agent cleanup complete", self.agent_id)

src/strands/experimental/tools/mcp/__init__.py

Lines changed: 0 additions & 5 deletions
This file was deleted.

src/strands/experimental/tools/mcp/mcp_tool_provider.py

Lines changed: 0 additions & 171 deletions
This file was deleted.

src/strands/experimental/tools/tool_provider.py

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,12 +27,23 @@ async def load_tools(self, **kwargs: Any) -> Sequence["AgentTool"]:
2727
pass
2828

2929
@abstractmethod
30-
async def cleanup(self, **kwargs: Any) -> None:
31-
"""Clean up resources used by the tools in this provider.
30+
async def add_provider_consumer(self, id: Any, **kwargs: Any) -> None:
31+
"""Add a consumer to this tool provider.
3232
3333
Args:
34+
id: Unique identifier for the consumer.
35+
**kwargs: Additional arguments for future compatibility.
36+
"""
37+
pass
38+
39+
@abstractmethod
40+
async def remove_provider_consumer(self, id: Any, **kwargs: Any) -> None:
41+
"""Remove a consumer from this tool provider.
42+
43+
Args:
44+
id: Unique identifier for the consumer.
3445
**kwargs: Additional arguments for future compatibility.
3546
36-
Should be called when the tools are no longer needed.
47+
Provider may clean up resources when no consumers remain.
3748
"""
3849
pass

src/strands/tools/mcp/__init__.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
"""
88

99
from .mcp_agent_tool import MCPAgentTool
10-
from .mcp_client import MCPClient
10+
from .mcp_client import MCPClient, ToolFilters
1111
from .mcp_types import MCPTransport
1212

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

0 commit comments

Comments
 (0)