Skip to content

MCP Tool Backend for Interactive Mode - #110

Open
bimu233 wants to merge 11 commits into
ChicagoHAI:feature/interactive-modefrom
bimu233:mcp-tool
Open

MCP Tool Backend for Interactive Mode#110
bimu233 wants to merge 11 commits into
ChicagoHAI:feature/interactive-modefrom
bimu233:mcp-tool

Conversation

@bimu233

@bimu233 bimu233 commented Jun 8, 2026

Copy link
Copy Markdown
Contributor

Overview

This PR extends the interactive mode manager with a New tool execution backend.
Builds on: #109


Summary of Changes

File Status What changed
config/manager.yaml modified llm_backend default removed; auto-detected from default_provider at runtime
src/interactive/mcp_server.py new MCP server exposing 5 NeuriCo tools over stdio JSON-RPC
src/interactive/mcp_config.py new Writes .mcp.json and launches MCP server via sys.executable
src/interactive/llm_backend.py modified create_backend() auto-detects backend from default_provider: claudemcp, others → cli (unchanged behavior); new _send_mcp() with line-by-line streaming, IPC watcher, tool echo filter; LLMResponse gains streamed, had_tools, ask_user_exchanges
src/interactive/manager.py modified Creates IPC dir; _agent_step() loops autonomously when had_tools=True instead of always pausing for user input
src/interactive/tools.py modified Strips mcp__neurico__ prefix before dispatch

Why This Is Needed

The current cli backend runs the manager via:

claude -p --verbose --output-format stream-json

-p (print mode) means Claude Code runs as a single-shot text generator — no interactive agent loop, no tool execution. The manager captures stdout via Popen and intercepts all tool calls through a custom ToolExecutor. This causes two structural problems:

  1. Wrong tools: The model knows it is running inside Claude Code and assumes native tools (Bash, Read, Grep, etc.) are available. ToolExecutor rejects them, but the model keeps trying.
  2. Hallucinated results: Because the model generates its full response atomically (no pause at tool calls), it writes fake <tool_result> XML immediately after <tool_call> blocks — before the real tool has been executed.

Both problems stem from the same root: the 5 NeuriCo tools are described as XML text in the prompt, not registered at the API level. MCP fixes this structurally.


How MCP Solves It

With MCP:

  • The 5 NeuriCo tools are registered as a real MCP server, visible to Claude Code at the API level
  • Claude Code handles tool execution by routing calls to the MCP server directly
  • Native tool calling means stop_reason: tool_use — generation halts at every tool call, real results are injected before generation resumes. Therefore, no chance for fabricating fake tool result.
  • No custom Popen / stdout capture / XML parsing needed

Test

  • Run with ./neurico interactive <idea_name> --provider claude success.
  • Compatible with interactive Browser UI.

bimu233 and others added 11 commits May 17, 2026 16:57
Snapshot of our browser-UI work and local debug fixes before merging
the more comprehensive bug fixes from PR ChicagoHAI#104.
Adopt ChicagoHAI#104's more comprehensive fixes (arg quoting, host->container path
translation, in_progress idea-file fallback, manager_session.json array
serialization, agent_runner workspace check, system-prompt tool discipline)
and drop our local equivalents. Keep our additions: the browser UI
(channel.py, web_server.py, visualizer/), manager web-channel wiring, and
the src/ mount. system_prompt.txt keeps both ChicagoHAI#104's tool rules and our
engagement-tuning.
Build a 3-pane browser UI on top of interactive mode (ChicagoHAI#86) and its bug
fixes (ChicagoHAI#104):
- dashboard strip (phase derived from live agent activity, cost, agents,
  papers, files, elapsed)
- conversation pane: clean prose (strips tool-call XML/meta-chatter),
  question vs. info styling, 'manager is thinking' indicator, queued-message UX
- live activity log: collapsible rows, friendly tool names, expandable
  system/result rows, and quote-to-chat ('ask about this')
- fixed branding images (logo + manager avatar), served read-only

See INTERACTIVE_WEB_CHANGES.md for the full breakdown.
jingxuangu pushed a commit to jingxuangu/NeuriCo that referenced this pull request Jun 9, 2026
… prompt, IPC, annotations)

A review pass over the diff (incl. the embraced ChicagoHAI#110 backend) surfaced a cluster
of bugs — fixed here. Most MCP issues are inherited from ChicagoHAI#110; the annotation
ones are ours.

HIGH:
- MCP stale world model: tools run in the MCP subprocess, so the manager's
  per-turn digest never saw its own updates. ResearchState.reload() (in place)
  is now called each turn in _agent_step. (This one is ours — the seam between
  the in-process world model and ChicagoHAI#110's subprocess execution.)
- Runaway autonomous loop: the had_tools loop-back had no ceiling. Bounded by
  max_autonomous_steps (default 25) with a forced human checkpoint; resets on
  user input.
- Wrong tool protocol in MCP: the prompt told the model to emit <tool_call> XML
  (a cli-shim artefact) even in MCP, where it's dropped. The tool-protocol
  section is now backend-conditional (native for mcp/api, XML only for cli).

MED:
- Experiment lifecycle: run_agent records finalize to done/failed from disk
  (status/result/error.json) in read_agent_logs, not from a Popen map that dies
  with the subprocess.
- ask_user IPC: requests carry a uuid echoed in the response (no cross-question
  answers); writes are atomic (temp + os.replace), both sides.
- Annotation keys: chat bubbles key on a content hash (stable across resumed
  sessions) instead of the per-process SSE seq.
- annotations.jsonl append is lock-guarded against concurrent thumb clicks.
- Backend selection: --backend accepts mcp; a single resolve_backend() is the
  source of truth for both .mcp.json provisioning and the running backend.

LOW:
- --allowedTools derived from the tool list (fallback constant) so a new tool
  can't be silently uncallable.
- ask_user exchanges recorded before the trailing assistant text.
- find_idea return type corrected to a tuple.

Also: changes.md TL;DR intro + "Known issues fixed" section.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants