Summary
Enable the built-in system agent (agentd-system) to use the agentd MCP server, giving it access to diagnostic tools, agent management, and service health checks natively through MCP rather than relying solely on Bash-based CLI commands.
Background
Claude Code supports --mcp-config <json> and --strict-mcp-config CLI flags that allow passing MCP server configuration at launch time as inline JSON. This avoids filesystem writes (no .mcp.json needed) and gives the orchestrator full control over which MCP servers an agent can access.
The agentd MCP server (agent mcp) runs on stdio and is configured via AGENTD_*_URL environment variables. It exposes tools for diagnostics, agent lifecycle, notifications, approvals, workflows, and service health.
Implementation Plan
1. Add mcp_servers to AgentConfig (types.rs)
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct McpServerEntry {
pub command: String,
pub args: Vec<String>,
#[serde(default, skip_serializing_if = "HashMap::is_empty")]
pub env: HashMap<String, String>,
}
// In AgentConfig:
#[serde(default, skip_serializing_if = "Option::is_none")]
pub mcp_servers: Option<HashMap<String, McpServerEntry>>,
2. Update build_claude_command() (manager.rs)
When config.mcp_servers is Some, serialize to JSON and append CLI flags:
claude --sdk-url ... --mcp-config '<json>' --strict-mcp-config
--strict-mcp-config ensures the agent only uses explicitly provided MCP servers, ignoring any project-level .mcp.json files in the working directory.
3. Wire up system agent config (system_agents.rs)
mcp_servers: Some(HashMap::from([(
"agentd".into(),
McpServerEntry {
command: "agent".into(),
args: vec!["mcp".into()],
env: HashMap::from([
("AGENTD_ORCHESTRATOR_URL".into(), "http://127.0.0.1:7006".into()),
("AGENTD_COMMUNICATE_URL".into(), "http://127.0.0.1:7010".into()),
("AGENTD_MEMORY_URL".into(), "http://127.0.0.1:7008".into()),
("AGENTD_NOTIFY_URL".into(), "http://127.0.0.1:7004".into()),
("AGENTD_ASK_URL".into(), "http://127.0.0.1:7001".into()),
("AGENTD_WRAP_URL".into(), "http://127.0.0.1:7005".into()),
("AGENTD_MONITOR_URL".into(), "http://127.0.0.1:7003".into()),
("AGENTD_HOOK_URL".into(), "http://127.0.0.1:7002".into()),
]),
},
)])),
4. Update system agent tool policy (system_agents.rs)
Add MCP tool patterns to the AllowList. Recommended read-only/diagnostic tools:
mcp__agentd__diagnose_system
mcp__agentd__diagnose_agent
mcp__agentd__diagnose_workflow
mcp__agentd__check_service_health
mcp__agentd__check_single_service
mcp__agentd__check_connectivity
mcp__agentd__get_agent
mcp__agentd__get_agent_status_summary
mcp__agentd__list_agents
mcp__agentd__list_workflows
mcp__agentd__list_pending_approvals
mcp__agentd__get_prometheus_metrics
mcp__agentd__get_system_metrics
mcp__agentd__get_actionable_notifications
mcp__agentd__list_notifications
Notably absent from the allow list (state-changing operations):
mcp__agentd__terminate_agent
mcp__agentd__restart_agent
mcp__agentd__send_agent_message
mcp__agentd__update_agent_tool_policy
mcp__agentd__approve_tool_request / deny_tool_request
5. Migration
Add nullable mcp_servers TEXT column to the agents table (stores JSON). Alternatively, this could be stored as part of the existing config JSON if the schema supports it.
6. Update system prompt (system_agents.rs)
Add a section to SYSTEM_AGENT_PROMPT documenting the available MCP tools and when to use them vs CLI/Bash equivalents. The MCP tools should be preferred for structured data access; Bash tools remain for ad-hoc inspection.
Non-goals
- No WebSocket protocol changes needed
- No filesystem writes (
.mcp.json) needed
- User-created agents do not get MCP servers by default (opt-in via API)
Acceptance Criteria
Summary
Enable the built-in system agent (
agentd-system) to use the agentd MCP server, giving it access to diagnostic tools, agent management, and service health checks natively through MCP rather than relying solely on Bash-based CLI commands.Background
Claude Code supports
--mcp-config <json>and--strict-mcp-configCLI flags that allow passing MCP server configuration at launch time as inline JSON. This avoids filesystem writes (no.mcp.jsonneeded) and gives the orchestrator full control over which MCP servers an agent can access.The agentd MCP server (
agent mcp) runs on stdio and is configured viaAGENTD_*_URLenvironment variables. It exposes tools for diagnostics, agent lifecycle, notifications, approvals, workflows, and service health.Implementation Plan
1. Add
mcp_serverstoAgentConfig(types.rs)2. Update
build_claude_command()(manager.rs)When
config.mcp_serversisSome, serialize to JSON and append CLI flags:--strict-mcp-configensures the agent only uses explicitly provided MCP servers, ignoring any project-level.mcp.jsonfiles in the working directory.3. Wire up system agent config (system_agents.rs)
4. Update system agent tool policy (system_agents.rs)
Add MCP tool patterns to the
AllowList. Recommended read-only/diagnostic tools:mcp__agentd__diagnose_systemmcp__agentd__diagnose_agentmcp__agentd__diagnose_workflowmcp__agentd__check_service_healthmcp__agentd__check_single_servicemcp__agentd__check_connectivitymcp__agentd__get_agentmcp__agentd__get_agent_status_summarymcp__agentd__list_agentsmcp__agentd__list_workflowsmcp__agentd__list_pending_approvalsmcp__agentd__get_prometheus_metricsmcp__agentd__get_system_metricsmcp__agentd__get_actionable_notificationsmcp__agentd__list_notificationsNotably absent from the allow list (state-changing operations):
mcp__agentd__terminate_agentmcp__agentd__restart_agentmcp__agentd__send_agent_messagemcp__agentd__update_agent_tool_policymcp__agentd__approve_tool_request/deny_tool_request5. Migration
Add nullable
mcp_serversTEXT column to the agents table (stores JSON). Alternatively, this could be stored as part of the existing config JSON if the schema supports it.6. Update system prompt (system_agents.rs)
Add a section to
SYSTEM_AGENT_PROMPTdocumenting the available MCP tools and when to use them vs CLI/Bash equivalents. The MCP tools should be preferred for structured data access; Bash tools remain for ad-hoc inspection.Non-goals
.mcp.json) neededAcceptance Criteria
AgentConfigsupports optionalmcp_serversfieldbuild_claude_command()emits--mcp-configand--strict-mcp-configflagsmcp_serverscolumn