Skip to content

Commit

Permalink
format all files
Browse files Browse the repository at this point in the history
  • Loading branch information
grll committed Jan 11, 2025
1 parent d96ae0c commit 42be427
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 4 deletions.
2 changes: 1 addition & 1 deletion src/echo.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
@mcp.tool()
def echo_tool(text: str) -> str:
"""Echo the input text
Args:
text (str): The text to echo
Expand Down
2 changes: 1 addition & 1 deletion src/mcpadapt/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = "0.0.1"
__version__ = "0.0.1"
10 changes: 8 additions & 2 deletions src/mcpadapt/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,17 @@
from typing import Any, Callable, Coroutine


def async_to_sync(async_func: Callable[..., Coroutine[Any, Any, Any]]) -> Callable[..., Any]:
def async_to_sync(
async_func: Callable[..., Coroutine[Any, Any, Any]],
) -> Callable[..., Any]:
"""Convert an async function to a sync function in an async context.
This is usually not recommended, but tools are expected to be synchronous for
for example in smolagents.
This is done by using a separate thread to avoid blocking the asyncio event loop.
"""

@wraps(async_func)
def sync_wrapper(*args, **kwargs):
result = None
Expand All @@ -36,17 +39,20 @@ def run_async():
if error:
raise error
return result

return sync_wrapper


if __name__ == "__main__":

@asynccontextmanager
async def some_function():
async def call_tool(a):
await asyncio.sleep(10)
return a

yield call_tool

async def main():
async with some_function() as call_tool:
response = async_to_sync(call_tool)(1)
Expand Down

0 comments on commit 42be427

Please sign in to comment.