agentscope.service.mcp_manager
This module manages MCP (ModelContextProtocal) sessions and tool execution within an asynchronous context. It includes functionality to create, manage, and close sessions, as well as execute various tools provided by an MCP server.
- class MCPSessionHandler(name: str, config: dict[str, Any], sync: bool = True)[source]
Bases:
object
Handles MCP session connections and tool execution.
- async execute_tool(tool_name: str, **kwargs: Any) ServiceResponse [source]
Execute a tool and return ServiceResponse
- sync_exec(func: Callable, *args: Any, **kwargs: Any) Any [source]
Execute a function synchronously.
- Parameters:
func (Callable) – The asynchronous function to execute.
*args (Any) – Positional arguments to pass to the function.
**kwargs (Any) – Keyword arguments to pass to the function.
- Returns:
The result of the function execution.
- Return type:
Any