Skip to content

mcp_adapter

mcp_adapter

MCP tool adapter — wraps external MCP server tools as native BaseTool instances.

Classes

MCPToolAdapter

MCPToolAdapter(client: MCPClient, tool_spec: ToolSpec)

Bases: BaseTool

Wraps a single MCP-hosted tool as a native BaseTool.

This adapter enables tools discovered from external MCP servers to be used seamlessly within OpenJarvis agents via the ToolExecutor.

PARAMETER DESCRIPTION
client

The MCPClient connected to the external MCP server.

TYPE: MCPClient

tool_spec

The ToolSpec describing this tool (from MCPClient.list_tools()).

TYPE: ToolSpec

Source code in src/openjarvis/tools/mcp_adapter.py
def __init__(self, client: MCPClient, tool_spec: ToolSpec) -> None:
    self._client = client
    self._spec = tool_spec
Functions
execute
execute(**params: Any) -> ToolResult

Execute the remote MCP tool and return a ToolResult.

Source code in src/openjarvis/tools/mcp_adapter.py
def execute(self, **params: Any) -> ToolResult:
    """Execute the remote MCP tool and return a ToolResult."""
    try:
        result = self._client.call_tool(self._spec.name, params)
        content_parts = result.get("content", [])
        text = "\n".join(
            p.get("text", "")
            for p in content_parts
            if isinstance(p, dict)
        )
        return ToolResult(
            tool_name=self._spec.name,
            content=text,
            success=not result.get("isError", False),
        )
    except Exception as exc:
        return ToolResult(
            tool_name=self._spec.name,
            content=f"MCP tool error: {exc}",
            success=False,
        )

MCPToolProvider

MCPToolProvider(client: MCPClient)

Discovers tools from an MCP server and returns BaseTool adapters.

PARAMETER DESCRIPTION
client

The MCPClient connected to the MCP server.

TYPE: MCPClient

Source code in src/openjarvis/tools/mcp_adapter.py
def __init__(self, client: MCPClient) -> None:
    self._client = client
Functions
discover
discover() -> List[BaseTool]

Discover available tools and return them as BaseTool adapters.

Source code in src/openjarvis/tools/mcp_adapter.py
def discover(self) -> List[BaseTool]:
    """Discover available tools and return them as BaseTool adapters."""
    specs = self._client.list_tools()
    return [MCPToolAdapter(self._client, s) for s in specs]