diff --git a/plan/phase-5-consolidator/ws-d-mcp.md b/plan/phase-5-consolidator/ws-d-mcp.md index d2f99cb..d55ae3e 100644 --- a/plan/phase-5-consolidator/ws-d-mcp.md +++ b/plan/phase-5-consolidator/ws-d-mcp.md @@ -9,7 +9,7 @@ Part of [Phase 5: Consolidator](README.md). Contracts: [contracts.md](contracts. | Depends on | B (and C2 client call shared, not duplicated). In practice: A0 for compiling; `PeerRegistry::get` from A0 (unhardened forwarder) until C2 lands; develop against `FakeTransport` + `registry_with` | | Blocks | F | | Can start when | A0 is merged (the rmcp conditional-tools spike can start on day one, it needs nothing from peers) | -| Owned files | `src/mcp/mod.rs`, `src/mcp/prompts.rs`, `src/mcp/resources.rs`, tool-list snapshot test (in `src/mcp/mod.rs`), a new `src/mcp/peers.rs` if the code is easier to keep apart (WS-D may add it) | +| Owned files | `src/mcp/mod.rs`, `src/mcp/prompts.rs`, `src/mcp/resources.rs`, tool-list snapshot test (in `src/mcp/mod.rs`), a new `src/mcp/peers.rs` if the code is easier to keep apart (WS-D may add it), new `tests/mcp_peers.rs` | | Do not touch | `src/api/**` (C, B), `src/peers/**` (A, B, C), `src/state.rs`, `src/server.rs`, `src/telemetry/**`, `src/error.rs`, `docs/api.md`, `README.md`, `AGENTS.md` (F4 edits the tool-count line), `nix/**`, `Cargo.toml` | Shared-file seams: WS-D is the only editor of `src/mcp/**`. It reads `AppState.peers` (A0) and calls `PeerRegistry::get` / `snapshot` / `status`; it never builds URLs or headers itself. The MCP `service()` function must keep working unchanged when `state.peers` is `None`. diff --git a/src/mcp/peers.rs b/src/mcp/peers.rs index dbd8792..4ad23af 100644 --- a/src/mcp/peers.rs +++ b/src/mcp/peers.rs @@ -43,6 +43,20 @@ const PEER_AWARE: [&str; 8] = [ /// Tools that only exist while peers are configured. const PEER_TOOLS: [&str; 2] = ["get_peer", "list_peers"]; +/// Every tool visible while peers are configured, sorted by name. +/// +/// Shared with the integration snapshot so the expected list is not copied +/// into the test. +pub fn tool_names() -> Vec<&'static str> { + let mut names: Vec<&'static str> = PEER_AWARE + .iter() + .chain(PEER_TOOLS.iter()) + .copied() + .collect(); + names.sort_unstable(); + names +} + /// The two list tools took no parameters before the peer argument existed, so /// their schema carried no `$schema` key; `schemars` adds one to derived /// parameters. Dropping it keeps the peers-off schema byte-identical. diff --git a/tests/mcp_peers.rs b/tests/mcp_peers.rs index a05e282..a215386 100644 --- a/tests/mcp_peers.rs +++ b/tests/mcp_peers.rs @@ -130,6 +130,18 @@ impl Harness { self.rpc(sid, &body).await } + async fn resource_uris(&self, sid: &str) -> Vec { + let v = self + .rpc(sid, r#"{"jsonrpc":"2.0","id":2,"method":"resources/list"}"#) + .await; + v["result"]["resources"] + .as_array() + .unwrap() + .iter() + .map(|r| r["uri"].as_str().unwrap().to_owned()) + .collect() + } + async fn tools(&self, sid: &str) -> Vec { let v = self .rpc(sid, r#"{"jsonrpc":"2.0","id":9,"method":"tools/list"}"#) @@ -179,21 +191,7 @@ async fn tool_list_is_ten_with_peers_and_eight_without() { let tools = h.tools(&sid).await; let mut names: Vec<&str> = tools.iter().map(|t| t["name"].as_str().unwrap()).collect(); names.sort(); - assert_eq!( - names, - [ - "get_container", - "get_container_logs", - "get_journal_logs", - "get_peer", - "get_systemd_unit", - "list_containers", - "list_peers", - "list_systemd_timers", - "list_systemd_units", - "tail_journal" - ] - ); + assert_eq!(names, skyg_linux_tracker::mcp::peers::tool_names()); let units = tool(&tools, "list_systemd_units"); assert!( units["inputSchema"]["properties"]["peer"].is_object(), @@ -413,19 +411,8 @@ async fn peers_status_resource() { let h = start(peers_state(&fake)).await; let sid = h.open().await; - let v = h - .rpc( - &sid, - r#"{"jsonrpc":"2.0","id":2,"method":"resources/list"}"#, - ) - .await; - let uris: Vec<&str> = v["result"]["resources"] - .as_array() - .unwrap() - .iter() - .map(|r| r["uri"].as_str().unwrap()) - .collect(); - assert!(uris.contains(&"peers://status"), "{uris:?}"); + let uris = h.resource_uris(&sid).await; + assert!(uris.iter().any(|u| u == "peers://status"), "{uris:?}"); let v = h .rpc( @@ -440,19 +427,8 @@ async fn peers_status_resource() { // Absent entirely when peers are off: not listed, not readable. let h = start(local_state()).await; let sid = h.open().await; - let v = h - .rpc( - &sid, - r#"{"jsonrpc":"2.0","id":2,"method":"resources/list"}"#, - ) - .await; - let uris: Vec<&str> = v["result"]["resources"] - .as_array() - .unwrap() - .iter() - .map(|r| r["uri"].as_str().unwrap()) - .collect(); - assert!(!uris.contains(&"peers://status"), "{uris:?}"); + let uris = h.resource_uris(&sid).await; + assert!(!uris.iter().any(|u| u == "peers://status"), "{uris:?}"); let v = h .rpc( &sid,