diff --git a/CHANGELOG.md b/CHANGELOG.md index 5270ff48..c47c58ff 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -33,6 +33,16 @@ and listed with their assets on the and keeps the skill's other hooks; a hub before this release leaves out all hooks of such a skill, so keep end-of-session hooks in a skill of their own while members run older releases. +- **devstack notices a pool's upstream an agent has set up itself.** A + member who added one of the pool's MCP servers to Claude Code or Codex + directly (a service's own setup hint, `claude mcp add ...`) had the tools, + but a hook bound to that upstream stayed silent, and accepting it as well + gave the agent the tools twice. The hub now reads the MCP servers the + agents have configured (names and URLs only; it never writes them) and + matches them to the pool's by URL: the *MCP upstreams* page shows the own + entry under the pool's with the command that removes it, `devstack + doctor` warns, and a hook bound to the upstream applies for the agent + that has it set up itself. - **`devstack init` sets `PYTHONUTF8 = "1"` for Python apps.** On Windows a native Python process opens text files in the ANSI code page (cp1252) unless the code passes `encoding=`, while the same code in a container diff --git a/crates/devstack-hub/src/agenthooks.rs b/crates/devstack-hub/src/agenthooks.rs index 35228bc8..245852a1 100644 --- a/crates/devstack-hub/src/agenthooks.rs +++ b/crates/devstack-hub/src/agenthooks.rs @@ -14,7 +14,8 @@ //! - **The dispatcher** ([`run`]) is what that entry starts. It reads the //! index and the hub's state from disk (no hub needs to run), picks the //! hooks that apply (the working tree is of a bound repository, the bound -//! upstream is accepted, the pattern matches the prompt, not given yet in +//! upstream is accepted or the agent has it as a server of its own, the +//! pattern matches the prompt, not given yet in //! this session) and prints their texts. It never blocks a prompt: on //! any error it prints nothing. @@ -321,8 +322,10 @@ pub struct Lookup<'a> { pub state: &'a Path, /// The `origin` of the working tree at a path. pub origin: &'a dyn Fn(&Path) -> Option, - /// Whether the user accepted a pool's upstream. - pub accepted: &'a dyn Fn(&str, &str) -> bool, + /// Whether a pool's upstream (pool, name) is there for the agent in + /// the working tree (`cwd`): accepted in the hub, or configured in the + /// agent itself at the same URL (#473). + pub accepted: &'a dyn Fn(&str, &str, Option<&Path>) -> bool, /// Where an error goes (the hub's diagnostic log). pub warn: &'a dyn Fn(String), } @@ -419,7 +422,7 @@ fn applies( at: &Lookup<'_>, ) -> bool { if let Some(u) = &h.hook.upstream - && !(at.accepted)(&h.pool, u) + && !(at.accepted)(&h.pool, u, cwd) { return false; } @@ -576,6 +579,25 @@ fn prune(dir: &Path) { } } +/// A pool's upstream is there for `agent` in `cwd`: accepted in the hub, or, +/// read only then, configured in the agent itself at the pool's URL (#473: +/// a member who added the server by its own setup hint got no hook). +/// `own` reads the agent's servers. +fn upstream_there( + state: &Path, + pool: &str, + name: &str, + own: &dyn Fn() -> Vec, +) -> bool { + use crate::upstreams::Upstreams; + Upstreams::pool_accepted(state, pool, name) + || Upstreams::pool_url(state, pool, name).is_some_and(|url| { + own() + .iter() + .any(|d| crate::agentmcp::same_url(&d.url, &url)) + }) +} + /// The dispatcher as `devstack hook` runs it: this machine's hub state, /// its git, its upstreams. pub fn run_here(event: Event, agent: &str, input: &str) -> String { @@ -588,7 +610,11 @@ fn here(event: Event, agent: &str, f: impl FnOnce(&Lookup<'_>) -> R) -> R { f(&Lookup { state: &state, origin: &|p| crate::branches::origin(p), - accepted: &|pool, name| crate::upstreams::Upstreams::pool_accepted(&state, pool, name), + accepted: &|pool, name, cwd| { + upstream_there(&state, pool, name, &|| { + crate::agentmcp::of_agent(agent, cwd) + }) + }, warn: &|error| { devstack_daemon::diag::DiagLog::open(crate::log_path()).write( "warn", @@ -746,7 +772,7 @@ mod tests { .any(|a| a.ends_with("shop")) .then(|| "https://github.com/acme/shop".into()) }, - accepted: &|_, _| true, + accepted: &|_, _, _| true, warn: &|e| panic!("{e}"), }; let input = |sid: &str, cwd: &Path| { @@ -821,7 +847,7 @@ mod tests { p.ends_with("shop") .then(|| "git@github.com:acme/shop.git".into()) }, - accepted: &|_, name| name == "timetrack" && accepted.get(), + accepted: &|_, name, _| name == "timetrack" && accepted.get(), warn: &|e| panic!("{e}"), }; let shop_tree = Path::new("/src/shop"); @@ -867,6 +893,65 @@ mod tests { assert!(read_index(st.path()).agents.is_empty()); } + /// A pool's upstream the agent has as a server of its own, at the + /// pool's URL, is there for its hooks though never accepted (#473); the + /// agent's configuration is read only when it is not accepted. + #[test] + fn an_upstream_the_agent_configured_itself_counts_as_there() { + let dir = tempfile::tempdir().unwrap(); + std::fs::write( + dir.path().join("pool-upstreams.json"), + r#"{"default":[{"name":"timetrack","url":"https://timetrack.example/mcp"}]}"#, + ) + .unwrap(); + let own = |url: &'static str| { + move || { + let cfg = tempfile::NamedTempFile::new().unwrap(); + std::fs::write( + cfg.path(), + serde_json::json!({ "mcpServers": { "tt": { "type": "http", "url": url } } }) + .to_string(), + ) + .unwrap(); + crate::agentmcp::claude(cfg.path(), None) + } + }; + let s = dir.path(); + assert!(upstream_there( + s, + "default", + "timetrack", + &own("https://TimeTrack.example/mcp/") + )); + assert!(!upstream_there( + s, + "default", + "timetrack", + &own("https://other.example/mcp") + )); + assert!(!upstream_there( + s, + "default", + "other", + &own("https://timetrack.example/mcp") + )); + assert!(!upstream_there( + s, + "elsewhere", + "timetrack", + &own("https://timetrack.example/mcp") + )); + // Accepted: the agent's configuration is not read at all. + std::fs::write( + s.join("upstreams.toml"), + "[[pool]]\npool = \"default\"\nname = \"timetrack\"\naccepted = true\nurl = \"https://timetrack.example/mcp\"\n", + ) + .unwrap(); + assert!(upstream_there(s, "default", "timetrack", &|| panic!( + "read" + ))); + } + #[test] fn the_dispatcher_gives_each_text_once_where_it_applies() { let st = tempfile::tempdir().unwrap(); @@ -895,7 +980,7 @@ mod tests { p.ends_with("shop") .then(|| "git@github.com:acme/shop.git".into()) }, - accepted: &|pool, name| pool == "default" && name == "timetrack" && accepted.get(), + accepted: &|pool, name, _| pool == "default" && name == "timetrack" && accepted.get(), warn: &|e| panic!("{e}"), }; let start = |sid: &str, cwd: &str, source: &str| { diff --git a/crates/devstack-hub/src/agentmcp.rs b/crates/devstack-hub/src/agentmcp.rs new file mode 100644 index 00000000..d27406b0 --- /dev/null +++ b/crates/devstack-hub/src/agentmcp.rs @@ -0,0 +1,389 @@ +//! The MCP servers a coding agent has configured itself, outside devstack +//! (#473): a member who followed a service's own setup hint (`claude mcp add +//! … https://tracker.example/mcp`) has a pool's upstream twice over, or has +//! it without having accepted it in the hub, and a hook bound to that +//! upstream (ADR-0094) stayed silent. +//! +//! Read only, and only each server's name and URL: no header, no token, no +//! command line is kept or logged, and nothing is written (card point 4, +//! 2026-11-06). Matched to a pool's upstream by its URL, not by its name. +//! +//! - **Claude Code:** `.claude.json` in `CLAUDE_CONFIG_DIR`, else in the +//! home folder: `mcpServers` (user scope) and `projects..mcpServers` +//! (local scope, that folder only); `.mcp.json` in a working tree (project +//! scope). +//! - **Codex:** `config.toml` in `CODEX_HOME`, else `~/.codex`: +//! `[mcp_servers.]` with a `url`. + +use serde::Serialize; +use serde_json::Value; +use std::path::{Path, PathBuf}; + +/// Where Claude Code keeps its own configuration. +const CLAUDE_FILE: &str = "${CLAUDE_CONFIG_DIR:-~}/.claude.json"; +/// Where Codex keeps its own configuration. +const CODEX_FILE: &str = "${CODEX_HOME:-~/.codex}/config.toml"; + +/// Where an agent's own entry is configured. +#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize)] +#[serde(rename_all = "lowercase")] +pub enum Scope { + /// For the user, in every folder. + User, + /// For the user, in one folder (`project`). + Local, + /// In a working tree's `.mcp.json`, for everyone who checks it out. + Project, +} + +impl Scope { + pub fn as_str(self) -> &'static str { + match self { + Scope::User => "user", + Scope::Local => "local", + Scope::Project => "project", + } + } +} + +/// An MCP server an agent has configured itself. +#[derive(Debug, Clone, PartialEq, Eq, Serialize)] +pub struct Direct { + /// The agent's id in the agent table (`claude-code`, `codex`). + pub agent: &'static str, + /// Its name as people know it. + pub agent_name: &'static str, + pub scope: Scope, + /// The entry's name in the agent's configuration. + pub name: String, + /// The URL as configured. + pub url: String, + /// The folder a local or project entry belongs to. + #[serde(skip_serializing_if = "Option::is_none")] + pub folder: Option, + /// The file it is in. + pub file: String, + /// What takes it out again. + pub remove: String, +} + +/// A URL as two configurations of one server compare: scheme and host in +/// lower case, the scheme's default port dropped, no user, query or +/// fragment, the path without a trailing `/`. `None`: not an http(s) URL. +pub fn normalize(url: &str) -> Option { + let url = url.trim(); + let (scheme, rest) = url.split_once("://")?; + let scheme = scheme.to_ascii_lowercase(); + let default = match scheme.as_str() { + "http" => "80", + "https" => "443", + _ => return None, + }; + let rest = rest.split(['?', '#']).next().unwrap_or(""); + let (authority, path) = match rest.find('/') { + Some(i) => (&rest[..i], &rest[i..]), + None => (rest, ""), + }; + let host_port = authority.rsplit_once('@').map_or(authority, |(_, h)| h); + let host_port = host_port.to_ascii_lowercase(); + let host_port = match host_port.rsplit_once(':') { + // Not the colons of an IPv6 address without a port. + Some((h, p)) if !p.contains(']') && p == default => h.to_string(), + _ => host_port, + }; + if host_port.is_empty() { + return None; + } + Some(format!( + "{scheme}://{host_port}{}", + path.trim_end_matches('/') + )) +} + +/// Whether two URLs name one server. +pub fn same_url(a: &str, b: &str) -> bool { + matches!((normalize(a), normalize(b)), (Some(a), Some(b)) if a == b) +} + +/// A folder as Claude Code writes it as a key, and as a working tree's +/// path compares to it: `/` for `\`, no trailing `/`, case-insensitive on +/// Windows. +fn folder_key(p: &str) -> String { + let k = p.replace('\\', "/").trim_end_matches('/').to_string(); + if cfg!(windows) { k.to_lowercase() } else { k } +} + +/// `tree` is `folder` or inside it. +fn within(tree: &str, folder: &str) -> bool { + let (t, f) = (folder_key(tree), folder_key(folder)); + !f.is_empty() && (t == f || t.starts_with(&format!("{f}/"))) +} + +/// The servers of a Claude Code `mcpServers` object that have a URL. +fn servers_of(v: &Value) -> Vec<(String, String)> { + v.as_object() + .map(|m| { + m.iter() + .filter_map(|(name, s)| { + let url = s.get("url")?.as_str()?; + normalize(url)?; + Some((name.clone(), url.to_string())) + }) + .collect() + }) + .unwrap_or_default() +} + +fn claude_entry( + scope: Scope, + name: String, + url: String, + folder: Option, + file: &Path, +) -> Direct { + let remove = match &folder { + Some(f) => format!( + "claude mcp remove --scope {} {name} (in {f})", + scope.as_str() + ), + None => format!("claude mcp remove --scope {} {name}", scope.as_str()), + }; + Direct { + agent: "claude-code", + agent_name: "Claude Code", + scope, + name, + url, + folder, + file: file.display().to_string(), + remove, + } +} + +/// Claude Code's own servers in `config` (its `.claude.json`): the user's, +/// and the local ones of the folder `tree` is in, or of every folder +/// without a tree. +pub fn claude(config: &Path, tree: Option<&Path>) -> Vec { + let Some(v) = std::fs::read(config) + .ok() + .and_then(|b| serde_json::from_slice::(&b).ok()) + else { + return Vec::new(); + }; + let mut out: Vec = servers_of(&v["mcpServers"]) + .into_iter() + .map(|(n, u)| claude_entry(Scope::User, n, u, None, config)) + .collect(); + if let Some(projects) = v["projects"].as_object() { + let tree = tree.map(|t| t.to_string_lossy().into_owned()); + for (folder, p) in projects { + if tree.as_deref().is_some_and(|t| !within(t, folder)) { + continue; + } + out.extend( + servers_of(&p["mcpServers"]) + .into_iter() + .map(|(n, u)| claude_entry(Scope::Local, n, u, Some(folder.clone()), config)), + ); + } + } + out +} + +/// The servers of a working tree's `.mcp.json` (Claude Code's project scope). +pub fn claude_project(tree: &Path) -> Vec { + let file = tree.join(".mcp.json"); + let Some(v) = std::fs::read(&file) + .ok() + .and_then(|b| serde_json::from_slice::(&b).ok()) + else { + return Vec::new(); + }; + servers_of(&v["mcpServers"]) + .into_iter() + .map(|(n, u)| { + claude_entry( + Scope::Project, + n, + u, + Some(tree.display().to_string()), + &file, + ) + }) + .collect() +} + +/// Codex's own servers with a URL in `config` (its `config.toml`). +pub fn codex(config: &Path) -> Vec { + let Some(v) = std::fs::read_to_string(config) + .ok() + .and_then(|t| toml::from_str::(&t).ok()) + else { + return Vec::new(); + }; + let Some(servers) = v.get("mcp_servers").and_then(|s| s.as_table()) else { + return Vec::new(); + }; + servers + .iter() + .filter_map(|(name, s)| { + let url = s.get("url")?.as_str()?; + normalize(url)?; + Some(Direct { + agent: "codex", + agent_name: "Codex", + scope: Scope::User, + name: name.clone(), + url: url.to_string(), + folder: None, + file: config.display().to_string(), + remove: format!("delete [mcp_servers.{name}] from {}", config.display()), + }) + }) + .collect() +} + +fn claude_file() -> Option { + devstack_skills::agents::resolve(CLAUDE_FILE) +} + +fn codex_file() -> Option { + devstack_skills::agents::resolve(CODEX_FILE) +} + +/// The servers the agent `agent` (its id) has configured itself, as they +/// apply in the working tree `tree`. +pub fn of_agent(agent: &str, tree: Option<&Path>) -> Vec { + match agent { + "claude-code" => { + let mut out = claude_file().map_or_else(Vec::new, |f| claude(&f, tree)); + if let Some(t) = tree { + out.extend(claude_project(t)); + } + out + } + "codex" => codex_file().map_or_else(Vec::new, |f| codex(&f)), + _ => Vec::new(), + } +} + +/// Every server Claude Code and Codex have configured themselves on this +/// machine, in every folder, and in the `.mcp.json` of the working trees +/// `trees`. +pub fn everywhere(trees: &[PathBuf]) -> Vec { + let mut out = claude_file().map_or_else(Vec::new, |f| claude(&f, None)); + for t in trees { + out.extend(claude_project(t)); + } + out.extend(codex_file().map_or_else(Vec::new, |f| codex(&f))); + out +} + +#[cfg(test)] +mod tests { + use super::*; + + #[test] + fn urls_compare_as_one_server() { + assert_eq!( + normalize("HTTPS://Timetrack.Example.COM:443/mcp/?x=1#y").as_deref(), + Some("https://timetrack.example.com/mcp") + ); + assert!(same_url( + "https://user@tracker.example/mcp/", + "https://tracker.example/mcp" + )); + assert!(!same_url( + "https://tracker.example:8443/mcp", + "https://tracker.example/mcp" + )); + assert!(!same_url( + "http://tracker.example/mcp", + "https://tracker.example/mcp" + )); + assert!(same_url("http://localhost:80", "http://LOCALHOST/")); + assert_eq!(normalize("stdio:foo"), None); + assert_eq!(normalize("ftp://x/y"), None); + assert_eq!(normalize("https:///mcp"), None); + } + + #[test] + fn claude_codes_user_local_and_project_servers() { + let dir = tempfile::tempdir().unwrap(); + let cfg = dir.path().join(".claude.json"); + std::fs::write( + &cfg, + serde_json::json!({ + "mcpServers": { + "timetrack": { "type": "http", "url": "https://timetrack.example/mcp", "headers": { "Authorization": "Bearer secret" } }, + "local-tool": { "command": "npx", "args": ["x"] } + }, + "projects": { + "D:/src/shop": { "mcpServers": { "tracker": { "type": "sse", "url": "https://tracker.example/sse" } } }, + "D:/src/other": { "mcpServers": { "else": { "url": "https://else.example/" } } } + } + }) + .to_string(), + ) + .unwrap(); + let all = claude(&cfg, None); + assert_eq!(all.len(), 3, "{all:?}"); + assert!(!format!("{all:?}").contains("secret"), "no header is kept"); + let user = &all[0]; + assert_eq!((user.scope, user.name.as_str()), (Scope::User, "timetrack")); + assert_eq!(user.remove, "claude mcp remove --scope user timetrack"); + + let tree = Path::new("D:/src/shop/apps/web"); + let here = claude(&cfg, Some(tree)); + let names: Vec<&str> = here.iter().map(|d| d.name.as_str()).collect(); + assert_eq!(names, ["timetrack", "tracker"]); + assert_eq!(here[1].scope, Scope::Local); + assert_eq!( + here[1].remove, + "claude mcp remove --scope local tracker (in D:/src/shop)" + ); + + std::fs::write( + dir.path().join(".mcp.json"), + r#"{ "mcpServers": { "team": { "type": "http", "url": "https://team.example/mcp" } } }"#, + ) + .unwrap(); + let p = claude_project(dir.path()); + assert_eq!((p[0].scope, p[0].name.as_str()), (Scope::Project, "team")); + assert!( + p[0].remove + .starts_with("claude mcp remove --scope project team") + ); + + // Not there, or not JSON: nothing. + assert!(claude(&dir.path().join("none.json"), None).is_empty()); + std::fs::write(&cfg, "{ not json").unwrap(); + assert!(claude(&cfg, None).is_empty()); + } + + #[test] + fn codexs_servers_with_a_url() { + let dir = tempfile::tempdir().unwrap(); + let cfg = dir.path().join("config.toml"); + std::fs::write( + &cfg, + r#" +model = "x" +[mcp_servers.timetrack] +url = "https://timetrack.example/mcp" +bearer_token_env_var = "TT" +[mcp_servers.files] +command = "npx" +"#, + ) + .unwrap(); + let got = codex(&cfg); + assert_eq!(got.len(), 1); + assert_eq!(got[0].name, "timetrack"); + assert!( + got[0] + .remove + .starts_with("delete [mcp_servers.timetrack] from ") + ); + } +} diff --git a/crates/devstack-hub/src/lib.rs b/crates/devstack-hub/src/lib.rs index 9e0f5044..0b61bf96 100644 --- a/crates/devstack-hub/src/lib.rs +++ b/crates/devstack-hub/src/lib.rs @@ -35,6 +35,7 @@ use tokio_stream::StreamExt; static UI: Dir<'_> = include_dir!("$OUT_DIR/ui"); pub mod agenthooks; +pub mod agentmcp; mod branches; mod guests; mod mcp; diff --git a/crates/devstack-hub/src/upstreams.rs b/crates/devstack-hub/src/upstreams.rs index 0d2952f6..fed972fd 100644 --- a/crates/devstack-hub/src/upstreams.rs +++ b/crates/devstack-hub/src/upstreams.rs @@ -303,6 +303,10 @@ pub struct FromPool { pub why: Option, /// The prefix the pool gives it. pub pool_prefix: String, + /// Where an agent has a server of its own at this URL (#473): the + /// upstream is there twice, or there without being accepted. + #[serde(skip_serializing_if = "Vec::is_empty")] + pub direct: Vec, } /// What the hub keeps of an upstream's login in the secrets store. @@ -514,6 +518,19 @@ impl Upstreams { .any(|d| d.pool == pool && d.name == name && d.accepted && d.url == e.url) } + /// The URL a pool's list gives its upstream `name`, as the hub got it + /// last. + pub fn pool_url(dir: &std::path::Path, pool: &str, name: &str) -> Option { + let lists: PoolLists = std::fs::read(dir.join("pool-upstreams.json")) + .ok() + .and_then(|b| serde_json::from_slice(&b).ok())?; + lists + .get(pool)? + .iter() + .find(|e| e.name == name) + .map(|e| e.url.clone()) + } + /// The user configured an upstream, or accepted one of a pool: what makes /// `devstack mcp` ask the hub at all. pub fn configured(dir: &std::path::Path) -> bool { @@ -536,11 +553,30 @@ impl Upstreams { upstream: u, pool: None, }); - let pooled = self.pooled(&f).into_iter().map(|(u, p)| View { - prefix: u.prefix(), - logged_in: p.status == "accepted" && logged_in(&u), - upstream: u, - pool: Some(p), + let pooled = self.pooled(&f); + // What the agents configured themselves: read once, only when a + // pool offers anything. + let directs = if pooled.is_empty() { + Vec::new() + } else { + let trees: Vec = devstack_daemon::registry::list() + .into_iter() + .map(|e| e.repo) + .collect(); + crate::agentmcp::everywhere(&trees) + }; + let pooled = pooled.into_iter().map(|(u, mut p)| { + p.direct = directs + .iter() + .filter(|d| crate::agentmcp::same_url(&d.url, &u.url)) + .cloned() + .collect(); + View { + prefix: u.prefix(), + logged_in: p.status == "accepted" && logged_in(&u), + upstream: u, + pool: Some(p), + } }); Ok(own.chain(pooled).collect()) } @@ -625,6 +661,7 @@ impl Upstreams { status, why, pool_prefix: e.prefix(), + direct: Vec::new(), }, )); } diff --git a/crates/devstack/src/doctor.rs b/crates/devstack/src/doctor.rs index 5e4cbd5b..7b4ab4fd 100644 --- a/crates/devstack/src/doctor.rs +++ b/crates/devstack/src/doctor.rs @@ -85,6 +85,7 @@ pub fn run(stack_file: &Path) -> Vec { out.extend(release()); out.extend(path_entry()); out.extend(agent_hooks()); + out.extend(upstreams_direct()); #[cfg(windows)] out.extend(dev_drive(stack_file)); out @@ -662,6 +663,51 @@ fn agent_hooks() -> Vec { out } +/// A pool's upstream an agent also has as a server of its own, at the same +/// URL (#473): its tools twice once accepted, and before that a hook bound +/// to it looked silent. +fn upstreams_direct() -> Vec { + let Ok(views) = + devstack_hub::upstreams::Upstreams::without_secrets(devstack_hub::upstreams::dir()).views() + else { + return Vec::new(); + }; + views + .iter() + .filter_map(|v| v.pool.as_ref().map(|p| (v, p))) + .flat_map(|(v, p)| { + p.direct.iter().map(move |d| { + f( + Level::Warn, + direct_text(&p.pool, &p.name, p.status, &v.upstream.url, d), + ) + }) + }) + .collect() +} + +fn direct_text( + pool: &str, + name: &str, + status: &str, + url: &str, + d: &devstack_hub::agentmcp::Direct, +) -> String { + let scope = match &d.folder { + Some(folder) => format!("{} scope, {folder}", d.scope.as_str()), + None => format!("{} scope", d.scope.as_str()), + }; + let what = if status == "accepted" { + "the agent gets its tools twice" + } else { + "accept it in the dashboard (Upstreams) to have it once, through devstack" + }; + format!( + "upstream `{name}` of pool `{pool}` ({url}) is also configured directly in {} ({scope}, entry `{}`): {what}; remove the own entry with `{}`", + d.agent_name, d.name, d.remove + ) +} + fn same_dir(a: &Path, b: &Path) -> bool { let norm = |p: &Path| { std::fs::canonicalize(p) @@ -735,6 +781,39 @@ pub fn text(findings: &[Finding]) -> String { mod tests { use super::*; + #[test] + fn a_pools_upstream_the_agent_has_itself_is_named_with_its_removal() { + let dir = tempfile::tempdir().unwrap(); + let cfg = dir.path().join(".claude.json"); + std::fs::write( + &cfg, + r#"{"mcpServers":{"tt":{"type":"http","url":"https://timetrack.example/mcp"}}}"#, + ) + .unwrap(); + let d = &devstack_hub::agentmcp::claude(&cfg, None)[0]; + let t = direct_text( + "default", + "timetrack", + "offered", + "https://timetrack.example/mcp", + d, + ); + assert!( + t.contains("directly in Claude Code (user scope, entry `tt`)") + && t.contains("accept it in the dashboard") + && t.ends_with("`claude mcp remove --scope user tt`"), + "{t}" + ); + let t = direct_text( + "default", + "timetrack", + "accepted", + "https://timetrack.example/mcp", + d, + ); + assert!(t.contains("tools twice"), "{t}"); + } + #[test] fn the_memory_line_names_docker_desktops_vm() { const GB: u64 = 1 << 30; diff --git a/docs/adr/0069-devstack-mcp-can-carry-the-tools-of-upstream-mcp-servers.md b/docs/adr/0069-devstack-mcp-can-carry-the-tools-of-upstream-mcp-servers.md index 16f1deb4..79379391 100644 --- a/docs/adr/0069-devstack-mcp-can-carry-the-tools-of-upstream-mcp-servers.md +++ b/docs/adr/0069-devstack-mcp-can-carry-the-tools-of-upstream-mcp-servers.md @@ -1,6 +1,6 @@ # ADR-0069: `devstack mcp` can carry the tools of upstream MCP servers, logged in once by the hub -- **Status:** Accepted (2026-10-27, [card](https://github.com/nuetzliches/devstack/issues/316#issuecomment-6452598449)); amended 2026-10-27 (the keychain spike: `keyring`, a file on Linux without a Secret Service); addendum 2026-10-28 (option B: a pool names upstreams, card approved 2026-10-28); addendum 2026-10-30 (an OAuth app's client secret, card approved 2026-10-30); addendum 2026-11-04 (the upstreams' instructions in `initialize`, card approved 2026-11-04) +- **Status:** Accepted (2026-10-27, [card](https://github.com/nuetzliches/devstack/issues/316#issuecomment-6452598449)); amended 2026-10-27 (the keychain spike: `keyring`, a file on Linux without a Secret Service); addendum 2026-10-28 (option B: a pool names upstreams, card approved 2026-10-28); addendum 2026-10-30 (an OAuth app's client secret, card approved 2026-10-30); addendum 2026-11-04 (the upstreams' instructions in `initialize`, card approved 2026-11-04); addendum 2026-11-06 (a pool's upstream an agent has set up itself, card approved 2026-11-06) - **Date:** 2026-10-27 - **Deciders:** project owner - **Related:** [#316](https://github.com/nuetzliches/devstack/issues/316), [ADR-0007](0007-one-http-api-is-the-control-surface.md), [ADR-0019](0019-control-api-security.md), [ADR-0021](0021-a-hub-serves-the-dashboard.md), [ADR-0032](0032-the-pool-is-administered-in-the-dashboard.md), [ADR-0054](0054-macos-is-a-developer-platform-in-preview.md), [ADR-0060](0060-the-tray-is-a-client-of-the-hub.md), [ADR-0067](0067-a-change-at-runtime-says-who-made-it.md) @@ -323,3 +323,40 @@ of `initialize`), `upstreams.rs` (`note`, `warm`, `instructions`, (`instructions`) and `mcp.rs` (`instructions`, the quoting and the cap in all); tests in the hub's `upstreams.rs` and `stdio.rs`, `mcp.rs`, and `crates/devstack/tests/hub.rs`. + +## Addendum 2026-11-06: a pool's upstream an agent has set up itself + +A member had a pool's upstream set up in Claude Code directly, by the +service's own setup hint, and had never answered the pool's offer. The hub +did not notice: the agent had the tools, a hook bound to the upstream +(ADR-0094) stayed silent for the whole session, and accepting it as well +would have given the agent the tools twice (#473). + +The owner approved these points of the card in the conversation on +**2026-11-06** (points 4 and 6 of the pull request's card; point 5 is in +ADR-0094's addendum of the same day): + +| # | Category | Point | Beats | Reversing costs | +|---|---|---|---|---| +| 4 | trust | The dispatcher and the hub read the MCP servers configured directly in the agents (Claude Code `.claude.json`, global and per folder, and a working tree's `.mcp.json`; Codex `config.toml`), read only, names and URLs only; nothing leaves the machine, nothing is written. If wrong: nothing gained by an attacker; they are the user's own files and no token is read. | Asking the agent's CLI (`claude mcp list`: slow, starts the servers). | Low. | +| 6 | term | The *MCP upstreams* page shows on a pool's upstream that it is already set up directly in an agent (scope, entry), with the command that removes it; `devstack doctor` warns with the same; the hub never changes an agent's MCP configuration. | A button that accepts and removes the own entry (the hub writing `.claude.json`). | Low: a button can come later. | + +As built: `crates/devstack-hub/src/agentmcp.rs` reads Claude Code's +`.claude.json` (in `CLAUDE_CONFIG_DIR`, else the home folder: `mcpServers`, +user scope; `projects..mcpServers`, local scope), the `.mcp.json` of +each registered stack's repository (project scope), and Codex's +`config.toml` (`CODEX_HOME`, else `~/.codex`: `[mcp_servers.]` with a +`url`). It keeps a server's name and URL only, never its headers, and skips +one without an http(s) URL. URLs compare with scheme and host in lower case, +the default port, user, query and fragment dropped, and no trailing `/`. +`GET /hub/upstreams` carries the matches as `pool.direct`; the page shows +each under the pool's entry, with advice by whether it is accepted (the +tools twice) or not (use it here, then remove the own entry); `devstack +doctor` warns once per match. The command for Claude Code is `claude mcp +remove --scope ` (in the folder, for local and +project); for Codex, the `[mcp_servers.]` table to delete from the +file. + +Decided while building: the page reads the agents' files when it lists the +upstreams, and only when a pool offers any; Claude Code's local scope counts +for a working tree in that folder or below it; Codex has a user scope only. diff --git a/docs/adr/0094-a-skill-carries-hooks-that-give-text-to-the-agents.md b/docs/adr/0094-a-skill-carries-hooks-that-give-text-to-the-agents.md index b3a6fdb3..ea28a24b 100644 --- a/docs/adr/0094-a-skill-carries-hooks-that-give-text-to-the-agents.md +++ b/docs/adr/0094-a-skill-carries-hooks-that-give-text-to-the-agents.md @@ -1,6 +1,6 @@ # ADR-0094: A skill carries hooks that give text to the agents; the hub writes one entry per agent and event, `devstack hook` picks the texts -- **Status:** Accepted (card in the pull request); built; addendum 2026-11-06 (end-of-session events, #462) +- **Status:** Accepted (card in the pull request); built; addenda 2026-11-06 (end-of-session events, #462; an upstream the agent has set up itself counts, #473) - **Date:** 2026-11-05 - **Deciders:** project owner - **Related:** [ADR-0074](0074-a-pool-hands-out-skill-sets-the-hub-installs-them-for-the-agents.md) (skill sets, acceptance, the agent table), [ADR-0077](0077-a-sets-skills-are-grouped-and-switched-one-by-one.md) (a skill switched on and off), [ADR-0079](0079-skills-local-to-a-working-tree.md) (a skill bound to repositories), [ADR-0083](0083-the-hub-takes-out-what-an-agent-switched-off-leaves.md) (an agent switched off leaves nothing), [ADR-0069](0069-devstack-mcp-can-carry-the-tools-of-upstream-mcp-servers.md) (a pool's upstreams, accepted per member), [ADR-0071](0071-the-dashboard-writes-no-file-of-a-repository.md), [ADR-0070](0070-a-review-card-comes-before-the-code-an-adr-records-what-was-built.md); issue #453 @@ -213,3 +213,23 @@ Decided while building, not on the card: (`event_name`, `end`, `ended`, `texts_for`), `crates/devstack/src/client.rs` (`lane_stop`, `lane_stop_texts`), `crates/devstack/src/mcp.rs` (`lane_stop`), `crates/devstack/src/doctor.rs` (`agent_hooks`). + +## Addendum 2026-11-06: an upstream the agent has set up itself counts + +Point 5 of the dispatcher (*a hook bound to an upstream applies while the +member accepted that pool's upstream*) left a hook silent for a member who +had set the upstream up in the agent directly, outside devstack (#473). The +owner approved in the conversation on **2026-11-06** (point 5 of the pull +request's card; points 4 and 6 are in ADR-0069's addendum of the same day): + +| # | Category | Point | Beats | Reversing costs | +|---|---|---|---|---| +| 5 | concept | A hook bound to an upstream also applies when the agent has a server of its own whose URL (normalised: scheme, lower-case host, port, path without trailing `/`) is the pool's upstream's URL: a direct configuration counts as the upstream being there. | Only a note line instead of silence. | Low. | + +As built: `upstream_there` in `crates/devstack-hub/src/agenthooks.rs` takes +an accepted upstream as before, and only when it is not accepted reads the +servers of the agent the entry names (`--agent`: Claude Code's user scope, +its local scope for the session's `cwd`, the `.mcp.json` there; Codex's +`config.toml`; `crates/devstack-hub/src/agentmcp.rs`) and compares their +URLs with the one the pool's list gives (`pool-upstreams.json`). A member's +own hub upstream of that name still keeps the pool's out. diff --git a/docs/adr/README.md b/docs/adr/README.md index 31acf6c2..e51b6933 100644 --- a/docs/adr/README.md +++ b/docs/adr/README.md @@ -151,7 +151,7 @@ stay. | [0066](0066-a-measured-cpu-need-is-capped-at-half-of-what-its-node-gives-lanes.md) | A measured CPU need is capped at half of what its node gives lanes | Accepted | | [0067](0067-a-change-at-runtime-says-who-made-it.md) | A change at runtime says where it came from, and a journal keeps the last ones | Accepted; built 2026-10-27 (point 2 for the main slot and services); addendum 2026-10-27: the dashboard shows the journal; addendum 2026-11-03: a lane's Activity is its own, the stack's on its page | | [0068](0068-a-stop-takes-the-containers-too.md) | A stop takes the stack's containers too, unless asked to keep them | Accepted; point 3's `shared` containers go with `shared` (deprecated by ADR-0080); point 2 amended by ADR-0095 (keeping them deprecated, the dashboard offers no choice) | -| [0069](0069-devstack-mcp-can-carry-the-tools-of-upstream-mcp-servers.md) | `devstack mcp` can carry the tools of upstream MCP servers, logged in once by the hub | Accepted ([card](https://github.com/nuetzliches/devstack/issues/316#issuecomment-6452598449)): a proxy in the hub, per user; amended 2026-10-27 (keychain via `keyring`, a file on Linux without a Secret Service); addendum 2026-10-28 (option B: a pool names upstreams, a member accepts each); addendum 2026-10-30 (an OAuth app's client secret, for GitHub); addendum 2026-11-04 (the upstreams' instructions in `initialize`) | +| [0069](0069-devstack-mcp-can-carry-the-tools-of-upstream-mcp-servers.md) | `devstack mcp` can carry the tools of upstream MCP servers, logged in once by the hub | Accepted ([card](https://github.com/nuetzliches/devstack/issues/316#issuecomment-6452598449)): a proxy in the hub, per user; amended 2026-10-27 (keychain via `keyring`, a file on Linux without a Secret Service); addendum 2026-10-28 (option B: a pool names upstreams, a member accepts each); addendum 2026-10-30 (an OAuth app's client secret, for GitHub); addendum 2026-11-04 (the upstreams' instructions in `initialize`); addendum 2026-11-06 (a pool's upstream an agent has set up itself) | | [0070](0070-a-review-card-comes-before-the-code-an-adr-records-what-was-built.md) | A review card comes before the code; an ADR records what was built | Accepted (supersedes ADR-0001); point 1 amended 2026-10-28 (the card in the conversation and the pull request, no issue) | | [0071](0071-the-dashboard-writes-no-file-of-a-repository.md) | The dashboard writes no file of a repository; a change to one is a prompt for a coding agent | Accepted, amended by ADR-0079 (skills devstack owns, ignored by git, are written into a working tree) and ADR-0087 (the `skills` prompt and the skills banner removed) | | [0072](0072-a-restart-is-warm-a-rebuild-or-cold.md) | A restart is warm, a rebuild or cold; a group acts on its containers too | Accepted ([card](https://github.com/nuetzliches/devstack/pull/351)); point 5 amended 2026-11-03 (Stop a button of its own in the header) | @@ -176,6 +176,6 @@ stay. | [0091](0091-public-links-through-the-users-own-named-tunnel.md) | Public links can go through the user's own named tunnel, at stable addresses; the hub runs its one connector | Accepted (card in the pull request); built; its step 3, the pool, built by ADR-0092 | | [0092](0092-public-links-through-the-pool.md) | A pool can give its members public links below a zone of its own; the coordinator holds the token, each machine gets its own tunnel | Accepted (card in the pull request); built | | [0093](0093-the-main-tree-takes-its-profile-when-it-starts.md) | The main working tree takes its profile when it starts; the daemon carries none | Accepted (card in the pull request); built | -| [0094](0094-a-skill-carries-hooks-that-give-text-to-the-agents.md) | A skill carries hooks that give text to the agents; the hub writes one entry per agent and event, `devstack hook` picks the texts | Accepted (card in the pull request); built; addendum 2026-11-06 (end-of-session events `lane-stop`, `session-end`) | +| [0094](0094-a-skill-carries-hooks-that-give-text-to-the-agents.md) | A skill carries hooks that give text to the agents; the hub writes one entry per agent and event, `devstack hook` picks the texts | Accepted (card in the pull request); built; addenda 2026-11-06 (end-of-session events `lane-stop`, `session-end`; an upstream the agent has set up itself counts) | | [0095](0095-the-daemon-ends-with-the-last-tree.md) | The daemon ends with the last tree; a stack has no start of its own, a stop always takes a tree's containers | Accepted (card in the pull request); built | | [0096](0096-a-port-held-now-refuses-the-start-one-up-of-a-tree-at-a-time.md) | A port held now refuses the start, whoever holds it (a stopped stack's containers too); one `up` of a tree at a time | Accepted (card in the pull request); built | diff --git a/docs/dashboard-api.md b/docs/dashboard-api.md index da621790..6dfc5413 100644 --- a/docs/dashboard-api.md +++ b/docs/dashboard-api.md @@ -111,7 +111,7 @@ and `Referrer-Policy: no-referrer`. The dashboard has no inline script. | `POST /hub/pool/shared/{lease}/connect` | cookie + Origin | connect to the lane ([ADR-0053](adr/0053-whoever-a-lane-is-shared-with-connects-to-it.md)): a forward on this machine to each service it shares with `http` or `https` that has none yet, through its node (which checks the sharing at every connection), on the owner's port `here` if free, else another; `{services: [{name, port, url}], warning?}` (`warning` as for `open`). The connection is to the lane (owner, repository, lane), kept in `connected.json` in the pool's directory: it outlasts a new lease of the lane and a restart of the hub, and ends with `disconnect`, or when its owner stops sharing the running lane with this machine ([ADR-0085](adr/0085-a-connection-to-a-shared-lane-outlasts-its-restarts.md)); up to 0.34 it ended with the hub, and with the lane missing from one listing | | `POST /hub/pool/shared/{lease}/disconnect` | cookie + Origin | its forwards close, the connections through them too, the ports are free again, and the lane is no longer connected; `{closed}`: how many (`0`: it was not connected) | | `POST /hub/pool/shared/{lease}/open {"service"}` | cookie + Origin | connect the lane if it is not (as `connect` does; ADR-0053 point 2), and answer for that service: `{url, port, warning?}`. Up to 0.19 it forwarded that service only, until the hub stopped. `warning`: the node runs another devstack than this machine or does not say which, or the owner's and the node's pool protocols differ ([ADR-0031](adr/0031-a-coordinator-places-lanes.md) point 8) `502` for a service shared with a scheme other than `http` or `https` | -| `GET /hub/upstreams` | cookie | the user's MCP upstreams ([ADR-0069](adr/0069-devstack-mcp-can-carry-the-tools-of-upstream-mcp-servers.md)): `{store, upstreams: [{name, url?, command?, env?, token_var?, prefix, allow?, auth: {kind: "none"} \| {kind: "token", env?} \| {kind: "oauth", client_id?, client_secret?, scopes?}, logged_in, pool?}]}`, kept in `upstreams.toml` in the hub's state directory, never a secret: an OAuth app's client secret is `client_secret: true` (one is set; it is in the keychain, or for a pool's upstream with the pool's list). `store`: `keychain`, or `file` on a Linux machine without a Secret Service. The upstreams the machine's pools name follow the user's own, named `:`, with `pool: {pool, name, status, why?, pool_prefix}`: `status` `offered` (not answered), `accepted` (in use), `declined`, `changed` (the pool changed its URL since it was accepted) or `conflict` (`why`: one of the user's has its name or prefix, or another pool's accepted one its prefix); only `accepted` ones are used ([pool.md](pool.md#mcp-upstreams-for-the-members)) | +| `GET /hub/upstreams` | cookie | the user's MCP upstreams ([ADR-0069](adr/0069-devstack-mcp-can-carry-the-tools-of-upstream-mcp-servers.md)): `{store, upstreams: [{name, url?, command?, env?, token_var?, prefix, allow?, auth: {kind: "none"} \| {kind: "token", env?} \| {kind: "oauth", client_id?, client_secret?, scopes?}, logged_in, pool?}]}`, kept in `upstreams.toml` in the hub's state directory, never a secret: an OAuth app's client secret is `client_secret: true` (one is set; it is in the keychain, or for a pool's upstream with the pool's list). `store`: `keychain`, or `file` on a Linux machine without a Secret Service. The upstreams the machine's pools name follow the user's own, named `:`, with `pool: {pool, name, status, why?, pool_prefix, direct?}`: `status` `offered` (not answered), `accepted` (in use), `declined`, `changed` (the pool changed its URL since it was accepted) or `conflict` (`why`: one of the user's has its name or prefix, or another pool's accepted one its prefix); only `accepted` ones are used ([pool.md](pool.md#mcp-upstreams-for-the-members)). `direct` lists where a coding agent has a server of its own at the same URL (read from the agent's configuration, names and URLs only): `[{agent, agent_name, scope: "user" \| "local" \| "project", name, url, folder?, file, remove}]`, `remove` the command (for Codex, the table to delete) that takes the own entry out | | `POST /hub/upstreams {name, url, prefix?, allow?, auth}` | cookie + Origin | add an upstream or change the one of that name: `204`; `400` with why (a name of a-z, 0-9, -; https, plain http on this machine only; a prefix another upstream has). Instead of `url`, `command` (program and arguments) makes it a command the hub starts (stdio), with `env` (no secret) on top of a base environment; with `auth.kind = "token"` the kept token goes into the variable `token_var`; OAuth is not for a command. A change restarts it. A new URL or another kind of login forgets its credential. `auth.client_secret` (with a `client_id`, for a server that wants one even with PKCE, such as GitHub): a string goes into the keychain, `""` takes it away, left out keeps the one set; logging out keeps it | | `DELETE /hub/upstreams/{name}` | cookie + Origin | it and its credential go: `204` | | `POST /hub/upstreams/pool/{pool}/{name}/accept {prefix?}` | cookie + Origin | use an upstream a pool names, at the URL it names now, with `prefix` instead of the pool's if given: `204`; `400` with why (the pool names none such; a prefix one of the user's or another accepted one has). A login for another URL goes | diff --git a/docs/pool.md b/docs/pool.md index 6132e0de..21d722dc 100644 --- a/docs/pool.md +++ b/docs/pool.md @@ -684,6 +684,19 @@ another. A declined entry stays declined. An entry the pool drops, or every entry of a pool the machine leaves, goes with its login. A pool that does not answer keeps what it named last. +A member may have one of the pool's servers set up in a coding agent +directly, outside devstack (`claude mcp add --transport http tracker +https://mcp.example.com/mcp`, a service's own setup hint). The hub reads, and +never writes, the MCP servers Claude Code (`.claude.json`, user and local +scope; a working tree's `.mcp.json`) and Codex (`config.toml`) have +configured, only their names and URLs, and matches them to the pool's +entries by URL (scheme and host in lower case, no default port, no trailing +`/`). The *MCP upstreams* page shows such an entry under the pool's, with the +command that removes it (`claude mcp remove --scope user tracker`), and +`devstack doctor` warns with the same: accepted as well, the agent gets the +tools twice. A hook bound to that upstream applies for the agent that has it +set up itself, accepted in the hub or not. + ## Public links through the pool A pool can give its members public links at stable addresses below a zone @@ -847,7 +860,7 @@ a `hooks.toml` beside its `SKILL.md`. ```toml [[hook]] event = "session-start" # a session starts, or starts again after /clear or a compaction -upstream = "timetrack" # only while the member accepted the pool's upstream of that name +upstream = "timetrack" # only while that pool upstream is there: accepted, or set up in the agent at its URL context = """ Work session: load the skill time-session now, before the first task. If its tools are not listed yet, search for them; if they are still missing, diff --git a/ui/src/api/mock/index.ts b/ui/src/api/mock/index.ts index 9698b267..8d455e56 100644 --- a/ui/src/api/mock/index.ts +++ b/ui/src/api/mock/index.ts @@ -95,7 +95,7 @@ const mockUpstreams: McpUpstream[] = [ { name: 'wiki', url: 'https://wiki.example.com/mcp', prefix: 'wiki', allow: ['search', 'get_page'], auth: { kind: 'token' }, logged_in: false }, // Named by the pool (ADR-0069 option B): one accepted, one offered. { name: 'default:docs', url: 'https://docs.example.com/mcp', prefix: 'docs', auth: { kind: 'oauth' }, logged_in: true, pool: { pool: 'default', name: 'docs', status: 'accepted', pool_prefix: 'docs' } }, - { name: 'default:crm', url: 'https://crm.example.com/mcp', prefix: 'crm', auth: { kind: 'oauth' }, logged_in: false, pool: { pool: 'default', name: 'crm', status: 'offered', pool_prefix: 'crm' } }, + { name: 'default:crm', url: 'https://crm.example.com/mcp', prefix: 'crm', auth: { kind: 'oauth' }, logged_in: false, pool: { pool: 'default', name: 'crm', status: 'offered', pool_prefix: 'crm', direct: [{ agent: 'claude-code', agent_name: 'Claude Code', scope: 'user', name: 'crm', url: 'https://crm.example.com/mcp', file: '~/.claude.json', remove: 'claude mcp remove --scope user crm' }] } }, ]; /** The MCP upstreams the mock pool names. */ diff --git a/ui/src/api/types.ts b/ui/src/api/types.ts index bc2b91f6..f06f1f85 100644 --- a/ui/src/api/types.ts +++ b/ui/src/api/types.ts @@ -891,6 +891,24 @@ export type McpUpstreamFromPool = { why?: string; /** The prefix the pool gives it. */ pool_prefix: string; + /** Where an agent has a server of its own at this URL (#473). */ + direct?: AgentOwnServer[]; +}; + +/** An MCP server a coding agent has configured itself, outside devstack. */ +export type AgentOwnServer = { + /** The agent's id (`claude-code`, `codex`). */ + agent: string; + agent_name: string; + scope: 'user' | 'local' | 'project'; + /** The entry's name in the agent's configuration. */ + name: string; + url: string; + /** The folder of a local or project entry. */ + folder?: string; + file: string; + /** What takes it out again. */ + remove: string; }; /** An MCP upstream a pool names for its members (`GET /hub/pool/upstreams`): a URL, never a secret. */ diff --git a/ui/src/lib/upstreams.test.ts b/ui/src/lib/upstreams.test.ts new file mode 100644 index 00000000..ca887b86 --- /dev/null +++ b/ui/src/lib/upstreams.test.ts @@ -0,0 +1,27 @@ +import { describe, expect, it } from 'vitest'; +import { ownServerAdvice, ownServerWhere } from './upstreams'; +import type { AgentOwnServer } from '@/api/types'; + +const own: AgentOwnServer = { + agent: 'claude-code', + agent_name: 'Claude Code', + scope: 'user', + name: 'timetrack', + url: 'https://timetrack.example/mcp', + file: '~/.claude.json', + remove: 'claude mcp remove --scope user timetrack', +}; + +describe('a pool upstream an agent has itself', () => { + it('says where, in plain words', () => { + expect(ownServerWhere(own)).toBe('Already set up directly in Claude Code (for you, in every folder, as “timetrack”).'); + expect(ownServerWhere({ ...own, scope: 'local', folder: 'D:/src/shop' })).toContain('for you, in D:/src/shop'); + expect(ownServerWhere({ ...own, scope: 'project', folder: 'D:/src/shop' })).toContain('in D:/src/shop/.mcp.json'); + }); + + it('says what to do by what was made of the offer', () => { + expect(ownServerAdvice('accepted')).toMatch(/twice/); + expect(ownServerAdvice('offered')).toMatch(/use it here/); + expect(ownServerAdvice('offered')).not.toMatch(/ADR/); + }); +}); diff --git a/ui/src/lib/upstreams.ts b/ui/src/lib/upstreams.ts new file mode 100644 index 00000000..ec2f8a88 --- /dev/null +++ b/ui/src/lib/upstreams.ts @@ -0,0 +1,15 @@ +import type { AgentOwnServer } from '@/api/types'; + +/** Where an agent has a pool's upstream as a server of its own, in a line: + * the agent, the scope (and folder), the entry's name. */ +export function ownServerWhere(d: AgentOwnServer): string { + const scope = d.scope === 'user' ? 'for you, in every folder' : d.scope === 'local' ? `for you, in ${d.folder}` : `in ${d.folder}/.mcp.json`; + return `Already set up directly in ${d.agent_name} (${scope}, as “${d.name}”).`; +} + +/** What having it twice means, by what the user made of the pool's offer. */ +export function ownServerAdvice(status: string): string { + return status === 'accepted' + ? 'The agent now gets its tools twice. Remove the own entry:' + : 'To have it once, through devstack: use it here, then remove the own entry:'; +} diff --git a/ui/src/views/UpstreamsView.vue b/ui/src/views/UpstreamsView.vue index c611f409..e7672cb5 100644 --- a/ui/src/views/UpstreamsView.vue +++ b/ui/src/views/UpstreamsView.vue @@ -13,6 +13,7 @@ import { act } from '@/lib/actions'; import { webUrl } from '@/lib/format'; import { oauthAuth } from '@/lib/oauthAuth'; import { line, words } from '@/lib/commandLine'; +import { ownServerAdvice, ownServerWhere } from '@/lib/upstreams'; import { useUi } from '@/stores/ui'; import Icon from '@/components/icons/Icon.vue'; @@ -368,6 +369,9 @@ function how(u: McpUpstream): string { {{ u.pool.why }} + + {{ ownServerWhere(d) }} {{ ownServerAdvice(u.pool!.status) }} {{ d.remove }} +