Skip to content

[FEATURE] Allow registering custom tools in any language #1366

Description

@edenreich

Summary

Let users add custom tools written in any language by placing a manifest in ~/.infer/tools/. A custom tool should work like a built-in one: the model sees it, it runs through !!Name(arg="v") and infer tools execute, and it follows the same tool policy as a built-in (agent modes, require_approval, tools.safety.approval_behaviour).

Motivating case: the desktop app (Rust) embeds infer and needs a few tools that only make sense there. Today those tools have to be written in Go in this repo or run as an MCP server. With this feature the desktop app ships one binary (e.g. infer-desktop-tools <subcommand>) and one manifest per tool, and infer picks them up.

~/.infer/tools/ would be a new directory that the user owns. It has nothing to do with ~/.infer/bin/tools/, which infer binaries owns and fills with prebuilt ffmpeg / whisper-cli / llama-tts.

Why not just MCP?

MCP already lets you add tools in any language, but it is the heavier option here:

  • infer only speaks MCP over stateless Streamable HTTP (2026-07-28), so every tool needs a server listening on a port or an OCI container, started and health-checked per session. The desktop app starts one infer headless per message.
  • MCP tools show up as MCP_<server>_<tool>, are hidden in plan mode, and cannot set require_approval per tool (they fall back to the global setting).

A stdio MCP transport (supported by Claude Code, Codex, Goose and Gemini CLI) would complement this feature, but it is a separate feature and out of scope here.

Prior art

Agent How custom tools are added Languages
pi TypeScript extensions in ~/.pi/agent/extensions/ or .pi/extensions/, loaded into the pi process via jiti; pi.registerTool() with a TypeBox schema. They run with pi's own permissions. TypeScript only
OpenCode .opencode/tools/*.ts or ~/.config/opencode/tools/*.ts; the filename becomes the tool name; a custom tool with a built-in name replaces the built-in. TS/JS definition that can shell out to any language
Gemini CLI tools.discoveryCommand prints a JSON array of function declarations; tools.callCommand <name> gets the arguments as JSON on stdin and prints the result on stdout. Tools are prefixed discovered_tool_. Any
Amp Toolboxes: a directory of executables (AMP_TOOLBOX), each run with TOOLBOX_ACTION=describe to get its definition and TOOLBOX_ACTION=execute with the arguments on stdin. Any
Claude Code, Codex, Goose stdio MCP servers Any, needs an MCP SDK

Gemini CLI and Amp come closest to what we want: tools talk to the agent through an executable's stdin and stdout, and no SDK is needed. This proposal uses the same idea with one change: a static manifest replaces the discovery command. That way nothing runs at startup, which keeps startup cheap for each headless process, and no tool code runs until a call is approved.

Proposed design

A custom tool manifest is the built-in tool manifest from #1369 (agentdomain.ToolManifest) plus three fields only custom tools have: command, timeout and enabled. One file per tool, ~/.infer/tools/<Name>.yaml; the file name must match name, as for the embedded manifests.

name: TakeScreenshot       # ^[A-Za-z][A-Za-z0-9_]{0,63}$, must match the file name, must not be a built-in or start with MCP_
description: Capture a screenshot of a desktop app window and return the PNG path.
command:                   # argv, no shell. A bare name is looked up on PATH; a path with a slash resolves against the manifest's directory
  - infer-desktop-tools
  - screenshot
parameters:                # JSON Schema of type object, sent to the model unchanged
  type: object
  properties:
    window:
      type: string
      description: Title of the window to capture
  required:
    - window
modes: [standard, auto, auto-with-judge]   # agent modes that offer the tool; omitted = these three
require_approval: true     # omitted = inherit tools.safety.require_approval (default true), as for built-in manifests
timeout: 30                # seconds, default 30
enabled: true
  • modes replaces the read_only flag this issue first proposed, matching the built-in manifests. [standard, auto, auto-with-judge, plan, readonly] offers the tool in plan and readonly like Read/Grep. Readonly mode runs its tools without approval, so listing readonly declares the tool safe to run unapproved.

How a call runs:

  • infer starts command without a shell, in the session working directory, with infer's environment. It writes the call's arguments to stdin as one JSON object and closes stdin.
  • Exit 0: stdout is the tool result (text). Non-zero exit: the call fails, and stderr (or stdout if stderr is empty) goes back to the model as the error.
  • The process is killed on timeout or when the turn is cancelled. On Unix the whole process group is killed, so children of a script die too; on Windows the direct child.
  • Captured output is bounded, and the model sees at most tools.max_result_bytes, like every other tool.
  • Custom tool names get no prefix, so they look native. A name that matches a built-in tool of any context (agent, a2a, browser, computer), whether or not config enables it, is rejected, and so is a name starting with the reserved MCP_ prefix. A custom tool never replaces a tool, and no tool replaces a custom one. OpenCode lets custom tools replace built-ins; we deliberately do not.
  • Custom tools are local tools: tools.enabled: false turns them off too. They register before Markdown subagents load, so .infer/agents/*.md may list them in tools:.
  • The approval policy gates calls the model makes. !!Name(...) and infer tools execute are user-initiated and count as approved, as for built-ins; infer tools execute --format json still reports approval_required.

The desktop app can keep its tools out of the terminal CLI by pointing infer headless at its own directory with INFER_TOOLS_CUSTOM_DIR.

Groundwork

Out of scope (follow-ups)

  • Project-scoped .infer/tools/: a cloned repo could register executables, so this needs a trust model first.
  • Distributing tools through infer plugins, which installs content only by design.
  • Structured results (images, metadata) and streaming output.
  • A stdio MCP transport.

Acceptance Criteria

  • infer loads every *.yaml manifest in ~/.infer/tools/ at startup. The directory can be changed with tools.custom_dir / INFER_TOOLS_CUSTOM_DIR. A missing directory is not an error.
  • A custom manifest goes through the same strict decode and validation as the built-in manifests, plus command (required, non-empty), timeout (> 0) and enabled. Embedded built-in manifests keep rejecting those three fields.
  • A manifest that fails to parse or validate, whose file name does not match its name, whose name matches a built-in tool (enabled or not), or whose name starts with MCP_ is skipped with a logged warning. Startup continues and no existing tool is replaced. enabled: false skips the tool without a warning.
  • The model sees custom tools with the manifest's description and JSON Schema. They appear in !! autocomplete and run through !!Name(arg="v") and infer tools execute Name '{...}'.
  • Arguments are validated against the manifest's parameters before the process starts. The required-field and property-type checks in internal/mcp/tool.go move into agentdomain so MCP and custom tools share them, which also fixes required being skipped for []string schemas.
  • Calls follow the contract above: no shell, JSON arguments on stdin, stdout is the result on exit 0, stderr is the error on non-zero exit, the process (its process group on Unix) is killed on timeout or cancel, and output is capped by tools.max_result_bytes.
  • A custom tool answers its policy through Manifest() like a built-in. modes decides which agent modes list it, and ExecuteTool rejects a call outside them; an omitted modes hides it in plan and readonly like an MCP tool. require_approval (omitted = tools.safety.require_approval) feeds StandardApprovalPolicy, and approval is delivered according to tools.safety.approval_behaviour (prompt / ipc / block / judge) in both chat and headless.
  • docs/custom-tools.md documents the manifest (including modes, what listing readonly implies, and how command resolves) and how a call runs, with one shell-script example and one compiled single-binary example (Rust). It explains how ~/.infer/tools/ differs from ~/.infer/bin/tools/ and states that the tool runs with the user's permissions: the sandbox directory allow-list only applies to infer's built-in file tools. docs/tools-reference.md links to it, docs/configuration-reference.md lists tools.custom_dir / INFER_TOOLS_CUSTOM_DIR, and docs/directory-structure.md lists ~/.infer/tools/.
  • Tests cover manifest loading and validation, name collisions (built-in, disabled built-in, MCP_), success, non-zero exit, timeout (including a child process a script spawned), and mode and approval gating.

Activity

  1. added
    enhancement
    on Sep 27, 2026
  2. changed the title [-][FEATURE] Allow registering custom tools[/-] [+][FEATURE] Allow registering custom tools in any language[/+] on Sep 27, 2026
  3. moved this to Todo in 2026on Sep 27, 2026
  4. moved this from Todo to Done in 2026on Sep 28, 2026
  5. inference-gateway-releaser commented on Sep 28, 2026

    @inference-gateway-releaser
    Contributor

    🎉 This issue has been resolved in version 0.216.0 🎉

    The release is available on:

    Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementreleased

    Projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions