generated from amazon-archives/__template_Apache-2.0
-
Notifications
You must be signed in to change notification settings - Fork 423
feat(mcp): add experimental agent managed connection via ToolProvider #895
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
dbschmigelski
wants to merge
7
commits into
strands-agents:main
Choose a base branch
from
dbschmigelski:mcp/dx2
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
9837e6c
feat(mcp): add experimental agent managed connection support
dbschmigelski 5d5a800
remove max_tools, add kwargs
dbschmigelski 3250247
mcp_client implements tool_provider
dbschmigelski 6d51176
fix code coverage skip
dbschmigelski d0c323c
comments
dbschmigelski 8bc6dcb
comments
dbschmigelski 1f29e5e
comments
dbschmigelski File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
coverage: | ||
ignore: | ||
- "src/strands/experimental/tools/tool_provider.py" # This is an interface, cannot meaningfully cover |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
"""Private async execution utilities.""" | ||
|
||
import asyncio | ||
from concurrent.futures import ThreadPoolExecutor | ||
from typing import Awaitable, Callable, TypeVar | ||
|
||
T = TypeVar("T") | ||
|
||
|
||
def run_async(async_func: Callable[[], Awaitable[T]]) -> T: | ||
"""Run an async function in a separate thread to avoid event loop conflicts. | ||
|
||
This utility handles the common pattern of running async code from sync contexts | ||
by using ThreadPoolExecutor to isolate the async execution. | ||
|
||
Args: | ||
async_func: A callable that returns an awaitable | ||
|
||
Returns: | ||
The result of the async function | ||
""" | ||
|
||
async def execute_async() -> T: | ||
return await async_func() | ||
|
||
def execute() -> T: | ||
return asyncio.run(execute_async()) | ||
|
||
with ThreadPoolExecutor() as executor: | ||
future = executor.submit(execute) | ||
return future.result() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
"""Experimental tools package.""" | ||
|
||
from .tool_provider import ToolProvider | ||
|
||
__all__ = ["ToolProvider"] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
"""Tool provider interface.""" | ||
|
||
from abc import ABC, abstractmethod | ||
from typing import TYPE_CHECKING, Any, Sequence | ||
|
||
if TYPE_CHECKING: | ||
from ...types.tools import AgentTool | ||
|
||
|
||
class ToolProvider(ABC): | ||
dbschmigelski marked this conversation as resolved.
Show resolved
Hide resolved
dbschmigelski marked this conversation as resolved.
Show resolved
Hide resolved
|
||
"""Interface for providing tools with lifecycle management. | ||
|
||
Provides a way to load a collection of tools and clean them up | ||
when done, with lifecycle managed by the agent. | ||
""" | ||
|
||
@abstractmethod | ||
async def load_tools(self, **kwargs: Any) -> Sequence["AgentTool"]: | ||
"""Load and return the tools in this provider. | ||
|
||
Args: | ||
**kwargs: Additional arguments for future compatibility. | ||
|
||
Returns: | ||
List of tools that are ready to use. | ||
""" | ||
pass | ||
|
||
@abstractmethod | ||
async def add_consumer(self, id: Any, **kwargs: Any) -> None: | ||
"""Add a consumer to this tool provider. | ||
|
||
Args: | ||
id: Unique identifier for the consumer. | ||
**kwargs: Additional arguments for future compatibility. | ||
""" | ||
pass | ||
|
||
@abstractmethod | ||
async def remove_consumer(self, id: Any, **kwargs: Any) -> None: | ||
"""Remove a consumer from this tool provider. | ||
|
||
Args: | ||
id: Unique identifier for the consumer. | ||
**kwargs: Additional arguments for future compatibility. | ||
|
||
Provider may clean up resources when no consumers remain. | ||
""" | ||
pass |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.