Jump to content

Every page here is a learning from Kapso, experimenting on public repositories in each of their environments and use cases. Give your coding agent these learnings: connect the Leeroopedia MCP to Claude Code, Cursor or Codex ($20 free credit). Powered by Leeroo · founders@leeroo.com

Implementation:ARCANGEL0 EVA AgentToolHost

From Leeroopedia
Knowledge Sources
Domains Agentic_Systems, Tool_Integration, Security_Automation
Last Updated 2026-10-29 14:00 GMT

Overview

Concrete tool for registering, dispatching, and safety-gating MCP tools — built-in, armory CLI, and custom external — provided by the Mitsu tool layer.

Description

The AgentToolHost class is the central MCP tool host. It registers built-in tools (bash, file ops, Intel, search) on an in-process `MCPServer`, connects to external MCP tool clients (armory CLI adapters, custom tools), and dispatches tool calls from the agent loop.

Key responsibilities:

  • Tool registration: Built-in tools are registered with `ToolAnnotations` (read_only_hint, destructive_hint). External tools are discovered via MCP client connections.
  • Mode-gated availability: `provider_tools(mode)` returns the tool definitions appropriate for the current operational mode.
  • Safety gating: `requires_guided_approval(name)` checks if a tool needs operator approval in Guided mode; `recon_action_is_low_impact(name, arguments)` checks if a command is safe for auto-approval in Recon mode.
  • Unified dispatch: `call(name, arguments)` routes to the appropriate MCP client regardless of tool origin.
  • Result post-processing: A configurable `tool_result_handler` can append Intel capture notes; artifact searches are tracked automatically.
  • Result truncation: All tool output is capped at 40,000 characters.

Usage

  • Agent turn integration: The agent loop calls `provider_tools(mode)` to get available tools, then `call(name, arguments)` to execute each tool call.
  • Safety checks: Before executing a tool, the loop calls `requires_guided_approval` or `recon_action_is_low_impact` to determine if operator approval is needed.
  • External tool integration: Armory CLI tools and custom MCP tools are connected via their respective adapters and exposed through the same host.

Code Reference

Source Location

  • Repository: Mitsu
  • File: tools/agent_host.py

Signature

class AgentToolHost:
    def __init__(
        self,
        workspace: Path,
        ask_user: Callable[[str, list[str]], Awaitable[str]],
        update_intel: IntelUpdateHandler | None = None,
        search_settings: Callable[[], dict[str, dict[str, Any]]] | None = None,
        operator_dialog: OperatorDialogHandler | None = None,
        sudo_password: SudoPasswordHandler | None = None,
        show_command: ShowCommandHandler | None = None,
        mode_dialog: ModeDialogHandler | None = None,
        tool_result_handler: ToolResultHandler | None = None,
        surface_map_handler: SurfaceMapHandler | None = None,
    ) -> None: ...

    def provider_tools(self, mode: str) -> list[dict[str, Any]]: ...
    def is_read_only(self, name: str) -> bool: ...
    def requires_guided_approval(self, name: str) -> bool: ...
    def recon_action_is_low_impact(self, name: str, arguments: Any) -> bool: ...
    async def call(self, name: str, arguments: Any) -> tuple[str, bool, bool]: ...
    async def close(self) -> None: ...

Import

from mitsu.tools import AgentToolHost

I/O Contract

Inputs

Name Type Required Description
workspace Path Yes Workspace root directory for file operations
ask_user Callable Yes Async callback for user questions
update_intel IntelUpdateHandler No Async Intel update handler
search_settings Callable No Search engine settings getter
operator_dialog OperatorDialogHandler No Dialog presentation handler
sudo_password SudoPasswordHandler No Sudo password prompt handler
show_command ShowCommandHandler No Command preview handler
mode_dialog ModeDialogHandler No Mode change dialog handler
tool_result_handler ToolResultHandler No Post-processing hook for tool results
surface_map_handler SurfaceMapHandler No Attack surface map generation handler

Outputs

Name Type Description
call() returns tuple[str, bool, bool] (result_text, is_error, made_changes)
provider_tools() returns list[dict] Tool definitions for the given mode
requires_guided_approval() returns bool Whether the tool needs Guided approval
recon_action_is_low_impact() returns bool Whether the action is safe for Recon auto-approval

Usage Examples

Basic Tool Host Setup

from pathlib import Path
from mitsu.tools import AgentToolHost

async def ask_user(prompt, options):
    return options[0]  # Auto-select first option

tool_host = AgentToolHost(
    workspace=Path("/tmp/workspace"),
    ask_user=ask_user,
)

# Get tools available in Guided mode
tools = tool_host.provider_tools("Guided")
print(f"{len(tools)} tools available")

Dispatch a Tool Call

import asyncio

async def run_tool(tool_host):
    # Execute a bash command
    result, is_error, made_changes = await tool_host.call(
        "mitsu__bash",
        {"command": "whoami", "purpose": "Check current user"},
    )
    print(f"Result: {result}")
    print(f"Error: {is_error}, Made changes: {made_changes}")

asyncio.run(run_tool(tool_host))

Safety Check Before Execution

# In Guided mode, check if approval is needed
if tool_host.requires_guided_approval("mitsu__bash"):
    approved = await approve("mitsu__bash", {"command": "nmap -sV 10.0.0.1"})
    if not approved:
        result = "Operator declined this action."

# In Recon mode, check if the command is low-impact
if mode == "Recon":
    if not tool_host.recon_action_is_low_impact("mitsu__bash", {"command": "whois example.com"}):
        # Requires operator approval
        pass

Related Pages

Implements Principle

Requires Environment

Uses Heuristic

Page Connections

Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment