Overview

The Tools Gateway (also called the IO Service) is the only permitted path for executing side effects in Allternit. It runs as a standalone Axum service that receives tool execution requests, enforces policy, journals every call to the history ledger, and dispatches to the correct adapter. Every tool call that performs IO, invokes an external system, or mutates state must flow through this gateway. Kernel services and runners remain pure logic layers; the gateway owns execution.
The gateway binds to 127.0.0.1 by default and is intended for internal use. Direct exposure to the public internet is not recommended.

Responsibilities

Base URL

The gateway is mounted on its own port:
The host and port are configurable through environment variables:

Running the gateway

Build and run the service from the crate root:
On startup it initializes the policy engine, history ledger, messaging system, and registers the io-service identity.

Endpoints

Health check

Response:

Execute a tool

POST /v1/tools/execute is the only permitted side-effect path. The gateway validates the request, checks policy, derives a filesystem write scope from run_id, executes the tool, writes a receipt, and appends the result to the history ledger.

Request body

Response body

Error shape

Register a tool

POST /v1/tools registers a ToolDefinition with the gateway. Tools must declare their adapter type, input/output schemas, side effects, safety tier, and resource limits.
Response:

Tool types

The gateway dispatches each tool to an adapter based on tool_type:

Tool definition fields

List registered tools

Response:
The current handler returns an empty array. The underlying ToolGateway::list_tools() method is implemented and can be wired to the REST surface as the registry expands.

Policy and sandboxing

Before any tool runs, the gateway builds a PolicyRequest and asks the policy engine for a decision:
  • identity_id: io-service
  • resource: tool:{tool_id}
  • action: execute
  • requested_tier: the tool’s declared safety_tier
If the decision is Deny, execution aborts and the caller receives a TOOL_EXECUTION_FAILED error with the policy reason.

Filesystem sandbox

The REST handler derives a WriteScope from run_id:
  • /.allternit/artifacts/{run_id}/**
  • /.allternit/receipts/{run_id}/**
The gateway rejects any request whose write scope leaves /.allternit/, targets denied paths, or touches another run’s receipts.

Idempotency and receipts

Tools that declare side effects require an idempotency_key. The REST surface supplies correlation_id as the idempotency key. After each execution the gateway writes a receipt under /.allternit/receipts/{run_id}/ containing hashes of the tool definition, policy decision, inputs, outputs, and execution metadata. This enables deterministic replay and audit trails per LAW-ONT-008.

MCP bridge

The gateway includes an MCP bridge that connects to MCP servers over stdio or SSE and registers their tools under prefixed names:
MCP tool calls flow through the same policy, audit, and receipt pipeline as native tools. See MCP Servers for details on registering and attaching MCP servers.

Error handling

Common TOOL_EXECUTION_FAILED messages: