Skip to content

Host-implemented tools in the session (claude SDK MCP, codex dynamic tools, pi custom tools) #341

Closed

Description

@xxchan

Found by Lookout's comparison with the Claude Agent SDK 0.3.296: the SDK can give the agent tools implemented in the host process (createSdkMcpServer({ tools: [tool(...)] })), with no separate server. OAR only attaches stdio and http MCP servers (#170), so a host that wants one in-process tool has to run a server.

Several runtimes have a native channel for host-implemented tools: claude's SDK MCP servers over the control protocol (mcp_message control requests), codex app-server dynamic tools, pi custom tools. Earlier design notes list this as a per-runtime capability.

Design first: one SessionOptions shape for host tools (name, description, JSON schema, handler), mapped to each runtime's native channel and refused where there is none; how calls and results appear in the record stream; cancellation and errors. No compatibility layer: each runtime through its own first-party channel.

Part of the first-party SDK parity work.

Activity

  1. tinysnake commented on Oct 12, 2026

    @tinysnake

    Adding measured evidence from a host that needs this channel, since the Codex path is the one currently blocking a real consumer.

    Consumer: Sprout (an application embedding OAR as its engine substrate) 1. It injects a run-scoped tool catalog — remote workspace read / search / edit / patch / command bound to a pinned Worker origin — and must dispatch those calls itself. That is exactly the "host-implemented tools" shape this issue describes.

    Measured against published packages. I compared @botiverse/oar 0.35.0 and 0.59.1 (latest at time of writing) by unpacking both tarballs and grepping the shipped dist:

    Control 0.35.0 0.59.1
    SessionOptions.disallowedTools (codex, with config/read pre-thread resolution) absent present (runtimes/codex/tool-denials.js)
    SessionOptions.launchArgs (codex) absent present, ordered after OAR's own -c overrides
    SessionOptions.additionalDirectories (codex → runtimeWorkspaceRoots) absent present
    Answering a codex item/tool/call absent absent

    On the last row, both versions carry the same code path in runtimes/codex/session.js:

    const onServerRequest = (id, method, params) => {
      kernel.request("toApp", { kind: "native", type: method, native: params }, { id });
    };

    with the 0.35.0 comment stating it plainly — server-initiated requests are "recorded as toApp requests, unanswered". Session exposes no typed custom-tool result callback, so rawEvents lets a host observe the request but not serve it. The design doc also lists codex item/tool/call as deliberately left unknown: "a dynamic tool the app runs, neither a question nor served by the adapter".

    Why it is worth doing soon. thread/start accepts dynamicTools, so the runtime is already advertising a catalog the host is expected to serve; today an OAR host that registers one gets a request it cannot answer. For an embedding application this is the difference between "the agent can operate on the remote workspace" and "the agent stalls on a tool call", which is why the consumer above currently treats MCP attachment as its only portable external-tool channel.

    Two smaller observations from the same comparison, if useful:

    1. Claude: --disallowed-tools and a dedicated environment.js (removing the inherited parent-session markers) both landed after 0.35.0 and are good improvements. But --dangerously-skip-permissions remains hard-coded and launch-args.js now refuses a host --permission-mode, so a host cannot express a permission posture through OAR at all. Given the stated position that "isolation is the sandbox's job", documenting the intended host-side mechanism (OS sandbox profile / container) in docs/runtimes/claude.md would help hosts that need enforcement rather than a preference.
    2. Pi: nothing blocking — noting only that the package list is antigravity claude codex cursor grok kimi opencode pi pi-durable, i.e. pi-durable is now a separate runtime ID from pi.

    Happy to supply a repro or a fixture description if that helps scope the SessionOptions shape. No expectation that this is picked up on any particular schedule — recording it here so the evidence is attached to the right issue.

    Footnotes

    1. Sprout is a self-hosted multi-agent workspace application; the relevant seam is documented in its src/engine/port.ts (EngineAdapter / EngineSession). Evidence above is a source comparison of the published packages, not a claim about your CI. ↩

  2. xxchan commented on Oct 13, 2026

    @xxchan
    MemberAuthor

    Thanks for the measurements and the context on Sprout; they match the source.

    For host-served tools, the supported channel today is SessionOptions.mcpServers. The host serves its tools from an MCP server, for example a small streamable HTTP server on localhost inside its own process. OAR attaches it through each runtime's own MCP channel: claude, codex, pi, grok, kimi, opencode and antigravity take it, and cursor refuses it. The mapping and evidence are in docs/spec/runtime-matrix.md#refused-session-options. A codex item/tool/call only comes after a client registers dynamicTools on thread/start. OAR never registers any, so an OAR session does not receive one.

    To make this as easy as the Agent SDK's createSdkMcpServer, we plan a helper that serves host-defined tools (name, description, input schema, handler) from a localhost MCP server inside the host process. It returns a ready mcpServers entry, so one implementation works across those runtimes. That is the route we are taking for this issue, rather than per-runtime native channels such as codex dynamicTools.

    On claude permissions, OAR always runs claude with --dangerously-skip-permissions. It refuses --permission-mode because that flag would be silently overridden. Enforcement is meant to come from an OS sandbox or container around the session, and we will document that in docs/runtimes/claude.md.

    Discussion is welcome here, including the shape of the helper and anything MCP does not cover for Sprout.

  3. added a commit that references this issue on Oct 13, 2026
    7ca47d9
  4. added a commit that references this issue on Oct 13, 2026
  5. xxchan commented on Oct 13, 2026

    @xxchan
    MemberAuthor

    This shipped in @botiverse/oar 0.60.0 (#376). serveMcpTools({ name, tools }) serves tools the host implements (name, description, input schema, handler) from an MCP server inside the host process. It listens on localhost behind a random bearer token. Pass served.server in SessionOptions.mcpServers; it works on claude, codex, pi, grok, kimi and opencode.

    • A handler can return text or MCP content.
    • A thrown error becomes an isError result the model sees.
    • The handler's signal aborts when the runtime cancels the call.
    • One served set can back several sessions.

    Usage is in the package README, and details are in docs/spec/runtime-matrix.md#host-served-tools. The claude permissions note is in docs/runtimes/claude.md.

    Discussion is welcome here, including anything this does not cover for Sprout.

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

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions