create_toolkit - AG2

create_toolkit

autogen.mcp.create_toolkit async #

create_toolkit(session, *, use_mcp_tools=True, use_mcp_resources=True, resource_download_folder=None)

Create a toolkit from the MCP client session.

PARAMETER DESCRIPTION
session The MCP client session.
TYPE:ClientSession
use_mcp_tools Whether to include MCP tools in the toolkit.
TYPE:boolDEFAULT:True
use_mcp_resources Whether to include MCP resources in the toolkit.
TYPE:boolDEFAULT:True
resource_download_folder The folder to download files to.
TYPE:Optional[Union[Path, str]]DEFAULT:None

Returns: Toolkit: The toolkit containing the converted tools.

Source code in autogen/mcp/mcp_client.py

``` ```

172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
@export_module("autogen.mcp")
async def create_toolkit(
session: "ClientSession",
*,
use_mcp_tools: bool = True,
use_mcp_resources: bool = True,
resource_download_folder: Optional[Union[Path, str]] = None,
) -> Toolkit: # type: ignore[no-any-unimported]
"""Create a toolkit from the MCP client session.
Args:
session (ClientSession): The MCP client session.
use_mcp_tools (bool): Whether to include MCP tools in the toolkit.
use_mcp_resources (bool): Whether to include MCP resources in the toolkit.
resource_download_folder (Optional[Union[Path, str]]): The folder to download files to.
Returns:
Toolkit: The toolkit containing the converted tools.
"""
if resource_download_folder:
if isinstance(resource_download_folder, str):
resource_download_folder = Path(resource_download_folder)
await anyio.to_thread.run_sync(lambda: resource_download_folder.mkdir(parents=True, exist_ok=True))
return await MCPClient.load_mcp_toolkit(
session=session,
use_mcp_tools=use_mcp_tools,
use_mcp_resources=use_mcp_resources,
resource_download_folder=resource_download_folder,
)