Skip to content

MCP Integration

MCP integration has two usage modes:

  1. Command-line backend (recommended): Launch UCAgent using --backend=opencode, --backend=codex, etc. UCAgent starts the MCP Server, renders the client configuration, and invokes the external Code Agent, typically requiring only one terminal.
  2. Manual dual-terminal: Start only the UCAgent MCP Server, then manually start the MCP client in another terminal. This is suitable for debugging connection and interaction flows.

The LangChain backend in normal mode does not require MCP. This page uses ToffeeUT for both integration methods. The standalone listener opened by --mcp-server defaults to http://127.0.0.1:5000/mcp and provides the workflow's file tools.

3.1 Prerequisites

First, complete the prerequisite installation, then choose one of the two integration methods below; only one UCAgent process should be started per workspace.

Prepare Adder's RTL, specifications, and output/toffee_Adder/ workspace as shown in Normal Mode.

3.2 Using the Command-line Backend

First install OpenCode V2, then configure its model and credentials as described in the OpenCode provider guide. UCAgent uses OpenCode's model configuration; to select a model explicitly:

export UC_ENV_CMD_BACKEND_EX_ARGS="--model <provider/model>"

Start ToffeeUT with OpenCode:

ucagent toffee-ut output/toffee_Adder Adder --agent-mode single \
  --backend opencode --no-embed-tools --mcp-server --mcp-server-port -1 --tui --loop

The CLI backend starts a private authenticated MCP endpoint before model work. Use --mcp-server to additionally expose a listener for manually connected clients. Client profiles live under ucagent/core/backends/assets.

3.3 Manual Dual-Terminal Integration (Using Codex as an Example)

In Terminal A, start ToffeeUT and the MCP Server, then wait for Terminal B to connect:

ucagent toffee-ut output/toffee_Adder Adder --agent-mode single \
  --backend codex --no-embed-tools --mcp-server --tui

When not entering loop, UCAgent waits for the client in Terminal B to call tools. Codex login and model configuration must be completed in Terminal B; see its client documentation.

For a tool-only service, omit --tui. Without --loop or an explicit model command, the service waits for clients and does not create or probe the main model. Enabled embedding/review capabilities retain their requirements; see Runtime Control.

Terminal A listens on 127.0.0.1:5000 by default. If the port is already in use, pass --mcp-server-port <port> and use the same port in the client configuration.

Configure Codex in Terminal B. For manual integration, edit ~/.codex/config.toml:

1
2
3
[mcp_servers.ucagent]
url = "http://127.0.0.1:5000/mcp"
tool_timeout_sec = 600

Codex uses url to configure streamable HTTP MCP; there is no need to write transport = "http" separately. UCAgent's testing and compilation tools may take a long time to run, so the client timeout should be set sufficiently large.

In Terminal B, switch to the same workspace and start the client:

cd output/toffee_Adder
codex

After the client starts, ask it to read the role and task information before executing the current stage. For example:

Please use the RoleInfo tool to get role information, then read the files required for the current task and complete verification. Use UCAgent's ReadTextFile to read the phase reference_files to register reading records; all file operations must remain within the current workspace.

If the Code Agent pauses, first check status and current_tips in Terminal A, fix the issues, and then enter a continuation prompt in the client. MCP client configuration formats vary; please refer to the client documentation. You only need to point the address to the /mcp endpoint.

3.4 Ports, Permissions, and Security

  • In single mode, --mcp-server-no-file-tools omits the file operation group but retains basic ReadTextFile, stage, and registered extension tools. It is usable only when the final tool set meets workflow requirements; native client tools do not count as MCP tools.
  • --mcp-server additionally exposes the file operation tool group. --no-write restricts writes by UCAgent tools; permissions for the client's own file tools must be configured separately.
  • For remote access, explicitly set --mcp-server-host and restrict sources at the network layer; the default 127.0.0.1 only allows local connections.
  • The endpoint address, port, and client timeout must be consistent; if the connection fails, first check UCAgent logs and port usage, then check the client configuration.

MCP calls share the instance's tools and stage rules, but are not Console/HTTP command submissions and do not automatically receive runtime API operation IDs. See Runtime Control for interface and cancellation boundaries.

Task workflows can declare required tools through runtime_options.required_mcp_tools; MCP validates the final filtered set before startup. For missing tools, check startup flags, tools.ignore_tools / tools.selected_tools, and plugin registration. The main model has not been called at this point. Global/Super endpoints in multi expose role-specific tools, as described in Multi-Agent.

3.5 Stopping and restarting the service

Use stop_mcp_server in the Console or TUI console to stop MCP, inspect it with mcp_server_status, and restart with start_mcp_server [host] [port]. Shutdown actively closes this service's idle SSE notification connections without affecting other MCP instances. Active tool requests can finish within the 60-second HTTP graceful shutdown deadline. Requests exceeding that deadline are still cancelled and logged as timeout errors.

The stop command waits up to five seconds for the background thread. If the thread remains alive, the command reports still shutting down and retains service ownership, preventing a replacement instance from starting. Wait for active calls to finish, then query status or retry stop_mcp_server. Success is reported only after the thread exits. A timed-out startup whose cleanup is still pending retains the same status and stop controls.

cmd_api_start starts the separate CMD API and does not stop MCP. Starting MCP, CMD, or Master API listeners does not reset the process-wide Uvicorn logging levels or handlers. Leaving TUI returns to Console; use the status commands to determine whether services remain active.