#2356·ruflo

agent_execute requires its own LLM provider key — should delegate inference to the MCP host (e.g. Codex) via MCP sampling

Author: TovliCreated Jun 11, 2026Updated Sep 28, 2026

Summary

When agent_execute is invoked through an MCP host that is itself an LLM agent (e.g. OpenAI Codex), it fails with:

No LLM provider configured. Set ANTHROPIC_API_KEY (Tier-3), OPENROUTER_API_KEY (#2042), or OLLAMA_API_KEY (Tier-2 — #1725).

The root problem is architectural, not a missing key. The expectation when orchestrating through Codex is: Codex performs the reasoning/work, and the Ruflo MCP server orchestrates it. Instead, agent_execute tries to make its own outbound LLM call and therefore demands its own provider credentials. An MCP server invoked by an LLM host should not need a second, independent LLM subscription to run the agent.

Where it happens

  • executeAgentTask() → callAnthropicMessages() in v3/@claude-flow/cli/src/mcp-tools/agent-execute-core.ts. The no-provider error is emitted at ~L131–137.
  • callAnthropicMessages() reads provider keys directly from process.env (ANTHROPIC_API_KEY / OPENROUTER_API_KEY / OLLAMA_API_KEY) and fetch()es the provider endpoint itself. There is no path that hands the prompt back to the calling host for completion.
  • The MCP tool's own note hardcodes this assumption (v3/@claude-flow/cli/src/mcp-tools/agent-tools.ts:327): "call agent_execute(agentId, prompt) — direct LLM call via Anthropic Messages API (requires ANTHROPIC_API_KEY)".
  • Confirmed there is no MCP sampling/createMessage support anywhere in the CLI — grep -ri 'createMessage|sampling/createMessage' over src/ only matches statistical "sampling" (temperature, Thompson sampling, sample rate).

This is the same execution path #2042 touched, but #2042 only widened the set of direct providers (added OpenRouter + Ollama branches). It did not address the case where the host should perform the inference.

Steps to reproduce

  1. Add the Ruflo MCP server to Codex (~/.codex/config.toml).
  2. From Codex, call agent_execute({ agentId, prompt }) against a spawned agent.
  3. With no ANTHROPIC_API_KEY / OPENROUTER_API_KEY / OLLAMA_API_KEY present in the MCP subprocess environment → No LLM provider configured.

Two distinct things bite here:

  • (a) Codex launches MCP servers with a sanitized environment, so keys exported in the shell don't reach the subprocess.
  • (b) Even with a key, the MCP makes an independent provider call instead of letting Codex do the work — which defeats the "Codex does the work, MCP orchestrates" model.

Expected behavior (MCP-native design)

When the connected MCP client advertises the sampling capability, agent_execute should delegate the completion to the host via sampling/createMessage rather than calling a provider directly. That way:

  • Codex (the host model) does the actual inference — Codex does the work, the MCP orchestrates.
  • The MCP server needs no provider key of its own in this mode.
  • The host's own model / credentials / rate limits / billing govern execution — which is what a Codex (or Claude Code) user expects.

Direct provider calls (current behavior) should remain a fallback only when the client does not support sampling — e.g. the workflow runtime and headless CLI paths that already call executeAgentTask().

Proposed approach

  1. Thread the active MCP server/session into the tool handler so it can inspect clientCapabilities.sampling and issue sampling/createMessage.
  2. In executeAgentTask(), prefer host-delegated sampling when available; fall back to callAnthropicMessages() (Anthropic / OpenRouter / Ollama) when not.
  3. Map the agent's configured logical model + systemPrompt + prompt onto the createMessage request (modelPreferences, systemPrompt, messages).
  4. Update the no-provider error message and the tool note (agent-tools.ts:327) to reflect that host delegation is the preferred path and a provider key is only needed for the direct-call fallback.

Workaround (today)

Put a key in the MCP server's env block in ~/.codex/config.toml so it reaches the subprocess:

toml
[mcp_servers.ruflo]
command = "npx"
args = ["-y", "@claude-flow/cli@latest", "mcp", "start"]
env = { ANTHROPIC_API_KEY = "sk-ant-..." }  # or OPENROUTER_API_KEY / OLLAMA_API_KEY

This unblocks execution, but still bypasses Codex — the MCP does the inference itself rather than orchestrating Codex.

Related

  • #2042 — agent_execute ignored provider config / hardcoded Anthropic (closed; added OpenRouter + Ollama direct branches).
  • #1725 — Ollama Cloud Tier-2 routing.