agentscope.service.mcp_manager module

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)[源代码]

基类:object

Handles MCP session connections and tool execution.

async cleanup() None[源代码]

Clean up server stream resources.

async execute_tool(tool_name: str, **kwargs: Any) ServiceResponse[源代码]

Execute a tool and return ServiceResponse

async initialize() None[源代码]

Initialize stdio_transport

async list_tools() list[Any][源代码]

List available tools from the server.

sync_exec(func: Callable, *args: Any, **kwargs: Any) Any[源代码]

Execute a function synchronously.

参数:
  • 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.

返回:

The result of the function execution.

返回类型:

Any