JiuwenSwarm is an intelligent AI Agent built on openJiuwen. It extends the powerful capabilities of large language models directly to your fingertips through various communication apps you use daily.
id: agentserver-command-mcp name: AgentServer MCP Command And Runtime Reload status: partial confidence: confirmed last_updated: 2026-07-14 user_visible_surface: "TUI /mcp command, MCP server/tool browser, and MCP tools available to agents." source_of_truth: - "config.yaml:mcp.servers" modules: - gateway-and-channels - agentserver-runtime - agent-harness directories: - jiuwenswarm/channels/tui/frontend/src - jiuwenswarm/gateway - jiuwenswarm/server - jiuwenswarm/common code_symbols: - createMcpCommand - AgentWebSocketServer._handle_command_mcp - AgentManager.reload_agents_config - JiuWenSwarmDeepAdapter._sync_mcp_servers_for_runtime entrypoints: - jiuwenswarm/channels/tui/frontend/src/core/commands/builtins/mcp.ts - jiuwenswarm/server/agent_ws_server.py - jiuwenswarm/common/config.py
AgentServer MCP Command And Runtime Reload
Outcome
TUI users manage MCP server definitions and browse their tools. Mutations first change config.yaml:mcp.servers, then attempt runtime reconciliation. Registered tools are shown as mcp__{serverName}__{toolName}.
Causal Path
createMcpCommandand interactive MCP screens issue unarycommand.mcprequests. Slash actions arelist,show,add,update,enable,disable, andremove; interactive screens also uselist_tools.- TUI routing marks
command.mcpfor forwarding with no local handler. Gateway preserves request/session/params/metadata/agent identity and sends an E2A unary request throughMessageHandlerandWebSocketAgentServerClient. - The client correlates the response by
request_id, serializes socket sends, and enforces its unary timeout. AgentServer decodesReqMethod.COMMAND_MCP, calls_handle_command_mcp, and sends oneAgentResponseunder the connection send lock. - Reads load and mask configuration.
show/list_toolsprefer tools in the process-global Runner resource manager and may create a temporary MCP client when no registered tools are found for an enabled server. - Mutations normalize fields, perform a YAML read-modify-write, then call
reload_agents_config(get_config(), None). No target scope means all active channel agents are considered. - Each deep adapter reconciles enabled entries against tracked registrations by server name: remove missing, add new, and remove/re-add changed servers. Registration adds the server and ability to Runner; HTTP-family servers receive reachability preflight.
- The correlated response returns to TUI transcript or server/tool selectors and detail panels.
State Classification
- Durable source of truth:
config.yaml:mcp.servers, operationally keyed by trimmedname; entries contain enabled/transport state and stdio or network connection fields. - Transient applied state: Runner server ids, abilities and tool cards, live clients/subprocesses, and adapter registration maps.
- Transport state: websocket connections, Gateway pending queues, locks, and E2A envelopes are request-scoped.
- Derived output: masked lists/details, tool counts/schemas, selectors, and transcript rows are reconstructed from configuration or discovery.
- Observability: logs and preflight messages describe attempts; they do not prove desired and applied state agree.
Replay, Restore, Or Reconstruction
- New/restarted agents read effective configuration and register enabled entries, allowing later convergence after hot-reload failure.
- Disk and runtime changes are not transactional. YAML is written before reload; a reload exception is not rolled back and returns
ok: true, applied: false. Later reload or restart is the recovery path. - Whole-agent reload updates the root adapter; cached session adapters are marked stale and can reconstruct lazily on next use.
list/showreconstruct from YAML. Tools come from the active registry or a temporary connection; there is no durable tool inventory.
Contract
- Method: unary
command.mcp/ReqMethod.COMMAND_MCP;request_idcorrelates the reply. Carriedsession_iddoes not scope MCP configuration changes. - Actions:
list;showwith optional name;add; partialupdate;enable;disable;remove/delete;list_tools. Normalization acceptsstdio,sse,http,streamable-http, andstreamable_http, though one error message lists only the first three. - Mutation results: types include
added,updated,enabled,disabled, andremoved, withname,applied, and optional masked item/error. Failed local-file precheck isok: false, type: add_failed; reload failure isok: true, applied: false. - Read results:
listreturns masked items;showreturns masked detail and optional tool count;list_toolsreturns descriptors/schema. Discovery failures soften to an empty list or zero count. - Errors: missing names map to
MCP_NOT_FOUND, validation toMCP_BAD_REQUEST, and other exceptions toMCP_INTERNAL; error text is the exception string. - Disclosure: recursive masking uses a limited heuristic and cannot guarantee arbitrary environment/header names are safe. Slash detail also omits
env/cwd.
Consumer State And Output
Slash output contains list/detail blocks and mutation messages; failed requests become mcp failed: .... Interactive views use list, show, mutations, and list_tools for selectors and details. They treat ok: true as success even if the payload has applied: false: payload detail may expose the error, while the headline still says added/removed/enabled/disabled. Agents consume eventual Runner registrations, not the command response.
Failure, Ordering, And Identity
- YAML write failure returns a failed response before reload. Reload failure happens after durable mutation and creates a desired/applied split.
- A successful
reload_agents_configreturn does not prove application: adapter registration can log reachability/registration failure and returnfalsewithout raising, while the handler reportsapplied: true. - Add preflight only covers enabled
stdioentries whose arguments look like local files. Temporary discovery has no handler-level timeout and collapses failures to empty output. - Gateway serializes sends and AgentManager serializes reload bodies, but AgentServer handles frames in separate tasks. YAML read-modify-write is outside the reload lock, with no observed revision/file lock; concurrent mutations may reorder or lose updates. The response lock orders writes, not effects.
request_ididentifies the exchange; servernameidentifies configuration/reconciliation. Add is upsert, repeated enable/disable may skip reload, absent remove fails, and no separate idempotency token exists.show/list_toolsconsult a process-global registry by server name. Isolation for same-named servers across agents/channels is not established and remains inferred.
Verification
Static inspection confirmed TUI producers, Gateway forwarding, E2A correlation, AgentServer branches, YAML helpers, reload scope/lock, and adapter reconciliation. test_agentserver_cli_commands.py covers masked list, add reload, missing enable, remove, update, and an in-memory flow. test_agent_reload_scope.py covers reload scoping with MCP sync mocked. Tests were not executed.
Known Gaps
- No located test drives TUI -> Gateway -> AgentServer -> real YAML -> Runner registration or asserts
applied: falsepresentation. - No located test covers
show,list_tools, masking edge cases, post-write reload failure, restart convergence, temporary-client timeout, or concurrent mutations. - Registration failures do not propagate into
applied; the API has no per-agent convergence report. - Same-name ownership in the global Runner lookup needs an explicit isolation contract/test.
- Command-side temporary-client conversion and runtime
common.mcp_configconversion can drift; transport aliases and validation wording already differ.