agent_execute requires its own LLM provider key — should delegate inference to the MCP host (e.g. Codex) via MCP sampling
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()inv3/@claude-flow/cli/src/mcp-tools/agent-execute-core.ts. The no-provider error is emitted at ~L131–137.callAnthropicMessages()reads provider keys directly fromprocess.env(ANTHROPIC_API_KEY/OPENROUTER_API_KEY/OLLAMA_API_KEY) andfetch()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
notehardcodes 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/createMessagesupport anywhere in the CLI —grep -ri 'createMessage|sampling/createMessage'oversrc/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
- Add the Ruflo MCP server to Codex (
~/.codex/config.toml). - From Codex, call
agent_execute({ agentId, prompt })against a spawned agent. - With no
ANTHROPIC_API_KEY/OPENROUTER_API_KEY/OLLAMA_API_KEYpresent 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
- Thread the active MCP server/session into the tool handler so it can inspect
clientCapabilities.samplingand issuesampling/createMessage. - In
executeAgentTask(), prefer host-delegated sampling when available; fall back tocallAnthropicMessages()(Anthropic / OpenRouter / Ollama) when not. - Map the agent's configured logical model +
systemPrompt+promptonto thecreateMessagerequest (modelPreferences,systemPrompt,messages). - 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:
[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_KEYThis unblocks execution, but still bypasses Codex — the MCP does the inference itself rather than orchestrating Codex.
Related
- #2042 —
agent_executeignored provider config / hardcoded Anthropic (closed; added OpenRouter + Ollama direct branches). - #1725 — Ollama Cloud Tier-2 routing.
Source: ruvnet/ruflo