Skip to content

A self-improving RLM agent for coding workflows and long-running autonomous tasks.

Rust

keep mcp configuration in user settings (#3855)

kt9cf0d47e2f17
diff --git a/crates/pa-cli/src/mcp_login.rs b/crates/pa-cli/src/mcp_login.rs
index 1fe6f95370..f513b0737c 100644
--- a/crates/pa-cli/src/mcp_login.rs
+++ b/crates/pa-cli/src/mcp_login.rs
@@ -22,8 +22,8 @@ use pa_core::mcp::{
use pa_tui::auth_panel::{PastePromptTone, PasteStyle};
use pa_tui::client_auth::{AuthFuture, ClientAuthCommands};
-/// The CLI's live MCP manager: the shared auth store, `mcpServers`, and
-/// `mcpCatalogSources` all re-read per resolve. No interactive login: hosts with
+/// The CLI's live MCP manager: the shared auth store and global-only `mcpServers` and
+/// `mcpCatalogSources`, re-read per resolve. No interactive login: hosts with
/// a login UI call `set_begin_login` before the session registers host handlers.
pub(crate) fn cli_mcp_manager(cwd: &std::path::Path, agent_dir: &std::path::Path) -> McpManager {
let user_cwd = cwd.to_path_buf();
@@ -39,7 +39,7 @@ pub(crate) fn cli_mcp_manager(cwd: &std::path::Path, agent_dir: &std::path::Path
let settings = pa_core::settings::SettingsManager::create(&user_cwd, &user_agent_dir);
Some(
settings
- .settings()
+ .global_settings()
.mcp_servers
.clone()
.unwrap_or_default()
@@ -58,7 +58,7 @@ pub(crate) fn cli_mcp_manager(cwd: &std::path::Path, agent_dir: &std::path::Path
let settings =
pa_core::settings::SettingsManager::create(&catalog_cwd, &catalog_agent_dir);
settings
- .settings()
+ .global_settings()
.mcp_catalog_sources
.clone()
.unwrap_or_default()
@@ -299,6 +299,45 @@ mod tests {
use std::collections::HashMap;
use std::sync::Arc;
+ #[test]
+ fn cli_mcp_settings_stay_global_after_refresh() {
+ let dir = tempfile::tempdir().unwrap();
+ let cwd = dir.path().join("project");
+ let agent_dir = dir.path().join("agent");
+ std::fs::create_dir_all(cwd.join(".prime/agent")).unwrap();
+ std::fs::create_dir_all(&agent_dir).unwrap();
+ let mut global: serde_json::Value = serde_json::from_str(include_str!(concat!(
+ env!("CARGO_MANIFEST_DIR"),
+ "/../pa-core/tests/fixtures/mcp/global-settings.json"
+ )))
+ .unwrap();
+ global["mcpCatalogSources"] = serde_json::json!([concat!(
+ env!("CARGO_MANIFEST_DIR"),
+ "/../pa-core/tests/fixtures/mcp/global-services.json"
+ )]);
+ let mut project: serde_json::Value = serde_json::from_str(include_str!(concat!(
+ env!("CARGO_MANIFEST_DIR"),
+ "/../pa-core/tests/fixtures/mcp/project-settings.json"
+ )))
+ .unwrap();
+ project["mcpCatalogSources"] = serde_json::json!([concat!(
+ env!("CARGO_MANIFEST_DIR"),
+ "/../pa-core/tests/fixtures/mcp/project-services.json"
+ )]);
+ std::fs::write(agent_dir.join("settings.json"), global.to_string()).unwrap();
+ std::fs::write(cwd.join(".prime/agent/settings.json"), project.to_string()).unwrap();
+ let mut manager = cli_mcp_manager(&cwd, &agent_dir);
+ for _ in 0..2 {
+ assert_eq!(
+ manager.get_enabled_persistent_generic_servers(),
+ vec!["user-server"]
+ );
+ assert!(manager.service_descriptor("user-catalog").is_some());
+ assert!(manager.service_descriptor("project-catalog").is_none());
+ manager.refresh();
+ }
+ }
+
/// A scripted transport (exact URL -> response): a plain origin-level
/// authorization server.
struct ScriptedHttp(HashMap<String, pa_core::mcp::OAuthHttpResponse>);
diff --git a/crates/pa-cli/src/prompt_command.rs b/crates/pa-cli/src/prompt_command.rs
index b236868e7c..36381d57d6 100644
--- a/crates/pa-cli/src/prompt_command.rs
+++ b/crates/pa-cli/src/prompt_command.rs
@@ -83,10 +83,10 @@ fn assemble_breakdown(
let agent_dir = get_agent_dir();
let model_prompts = pa_core::prompts::model_prompts::load_model_prompts(model, &agent_dir);
let settings = SettingsManager::create(cwd, &agent_dir);
- // MCP gating: auth-gated built-in integrations drop their skills; enabled persistent generic
+ // User/global MCP gating: auth-gated built-in integrations drop their skills; enabled generic
// servers add the prompt MCP guidance.
let user_servers = settings
- .settings()
+ .global_settings()
.mcp_servers
.clone()
.unwrap_or_default()
diff --git a/crates/pa-core/src/session_engine/engine.rs b/crates/pa-core/src/session_engine/engine.rs
index 783f1532e4..3d93b6af01 100644
--- a/crates/pa-core/src/session_engine/engine.rs
+++ b/crates/pa-core/src/session_engine/engine.rs
@@ -156,8 +156,9 @@ async fn mcp_gating(
settings: &crate::settings::SettingsManager,
agent_dir: std::path::PathBuf,
) -> anyhow::Result<(Vec<String>, Vec<String>, crate::mcp::McpManager)> {
+ // MCP execution is user/global only, matching TS getGlobalMcpServers.
let user_servers = settings
- .settings()
+ .global_settings()
.mcp_servers
.clone()
.unwrap_or_default()
diff --git a/crates/pa-core/src/session_engine/engine/tests.rs b/crates/pa-core/src/session_engine/engine/tests.rs
index 462944fbfc..73b05489a9 100644
--- a/crates/pa-core/src/session_engine/engine/tests.rs
+++ b/crates/pa-core/src/session_engine/engine/tests.rs
@@ -6,6 +6,45 @@ use crate::session_engine::tool_bridge::{bridge_tool, ToolDefinitionBridge};
use crate::tools::tool_definition::{ExecutionMode, ToolDefinition, ToolExecutionResult};
use pa_agent::scripted::ScriptedProvider;
+/// Exercise the startup gate without starting a session or a configured process.
+#[tokio::test]
+async fn mcp_startup_gating_ignores_project_settings() {
+ let dir = tempfile::tempdir().unwrap();
+ let agent_dir = dir.path().join("agent");
+ let cwd = dir.path().join("project");
+ std::fs::create_dir_all(&agent_dir).unwrap();
+ std::fs::create_dir_all(cwd.join(".prime/agent")).unwrap();
+ let global: serde_json::Value = serde_json::from_str(include_str!(concat!(
+ env!("CARGO_MANIFEST_DIR"),
+ "/tests/fixtures/mcp/global-settings.json"
+ )))
+ .unwrap();
+ std::fs::write(agent_dir.join("settings.json"), global.to_string()).unwrap();
+ std::fs::write(
+ cwd.join(".prime/agent/settings.json"),
+ include_str!(concat!(
+ env!("CARGO_MANIFEST_DIR"),
+ "/tests/fixtures/mcp/project-settings.json"
+ )),
+ )
+ .unwrap();
+ let mut settings = crate::settings::SettingsManager::create(&cwd, &agent_dir);
+ // Reload and reopen must preserve the same execution scope as the first read.
+ for _ in 0..2 {
+ let (_, servers, manager) = mcp_gating(&settings, agent_dir.clone()).await.unwrap();
+ assert_eq!(servers, vec!["user-server"]);
+ for (name, expected) in global["mcpServers"].as_object().unwrap() {
+ assert_eq!(
+ serde_json::to_value(&manager.integrations()[name].config).unwrap(),
+ *expected
+ );
+ }
+ assert!(!manager.integrations().contains_key("project-server"));
+ settings.reload().unwrap();
+ settings = settings.reopen();
+ }
+}
+
fn echo_definition() -> ToolDefinition {
ToolDefinition {
name: "echo".to_string(),
diff --git a/crates/pa-core/src/settings/types.rs b/crates/pa-core/src/settings/types.rs
index fdd8cd97cd..fee580f096 100644
--- a/crates/pa-core/src/settings/types.rs
+++ b/crates/pa-core/src/settings/types.rs
@@ -309,9 +309,11 @@ pub struct Settings {
pub quiet_startup: Option<bool>,
pub shell_command_prefix: Option<String>,
pub npm_command: Option<Vec<String>>,
+ /// Execution reads this from global settings only; project overrides are ignored.
pub mcp_servers: Option<serde_json::Map<String, serde_json::Value>>,
/// Extra local MCP service-catalog files (~-relative allowed), merged after the
/// compiled built-ins; first source wins per id, and no bundled id can be shadowed.
+ /// Read from global settings only, like executable MCP server configuration.
pub mcp_catalog_sources: Option<Vec<String>>,
pub packages: Option<Vec<serde_json::Value>>,
pub skills: Option<Vec<String>>,
diff --git a/crates/pa-core/tests/fixtures/mcp/global-services.json b/crates/pa-core/tests/fixtures/mcp/global-services.json
new file mode 100644
index 0000000000..e7351592fd
--- /dev/null
+++ b/crates/pa-core/tests/fixtures/mcp/global-services.json
@@ -0,0 +1,12 @@
+{
+ "version": 1,
+ "entries": [{
+ "server": "user-catalog", "service": "user-catalog", "label": "User Catalog",
+ "url": "https://user.example/mcp", "aliases": [],
+ "transport": { "type": "http", "url": "https://user.example/mcp" },
+ "auth": { "strategy": "oauth", "clientRegistration": "dynamic" },
+ "setup": { "status": "ready" },
+ "verification": { "status": "unverified" },
+ "legacyBuiltin": false, "provenance": [{ "source": "user" }]
+ }]
+}
diff --git a/crates/pa-core/tests/fixtures/mcp/global-settings.json b/crates/pa-core/tests/fixtures/mcp/global-settings.json
new file mode 100644
index 0000000000..bad94e4104
--- /dev/null
+++ b/crates/pa-core/tests/fixtures/mcp/global-settings.json
@@ -0,0 +1,21 @@
+{
+ "mcpServers": {
+ "user-server": {
+ "type": "stdio",
+ "command": "fixture-user-server",
+ "args": ["user-argument"],
+ "cwd": "/user/workspace",
+ "env": { "FIXTURE_TOKEN": { "env": "FIXTURE_USER_TOKEN" } },
+ "enabled": true,
+ "enabledTools": ["user-tool"],
+ "disabledTools": ["other-tool"],
+ "startupTimeoutMs": 12000,
+ "callTimeoutMs": 34000
+ },
+ "disabled-server": {
+ "type": "stdio",
+ "command": "fixture-disabled-server",
+ "enabled": false
+ }
+ }
+}
diff --git a/crates/pa-core/tests/fixtures/mcp/project-services.json b/crates/pa-core/tests/fixtures/mcp/project-services.json
new file mode 100644
index 0000000000..2329070fe5
--- /dev/null
+++ b/crates/pa-core/tests/fixtures/mcp/project-services.json
@@ -0,0 +1,12 @@
+{
+ "version": 1,
+ "entries": [{
+ "server": "project-catalog", "service": "project-catalog", "label": "Project Catalog",
+ "url": "https://project.example/mcp", "aliases": [],
+ "transport": { "type": "http", "url": "https://project.example/mcp" },
+ "auth": { "strategy": "oauth", "clientRegistration": "dynamic" },
+ "setup": { "status": "ready" },
+ "verification": { "status": "unverified" },
+ "legacyBuiltin": false, "provenance": [{ "source": "user" }]
+ }]
+}
diff --git a/crates/pa-core/tests/fixtures/mcp/project-settings.json b/crates/pa-core/tests/fixtures/mcp/project-settings.json
new file mode 100644
index 0000000000..2781bc6837
--- /dev/null
+++ b/crates/pa-core/tests/fixtures/mcp/project-settings.json
@@ -0,0 +1,17 @@
+{
+ "mcpServers": {
+ "user-server": {
+ "command": "fixture-project-server",
+ "args": ["project-argument"],
+ "cwd": "/project/workspace",
+ "env": { "FIXTURE_TOKEN": { "env": "FIXTURE_PROJECT_TOKEN" } },
+ "enabled": false,
+ "enabledTools": ["project-tool"],
+ "disabledTools": [],
+ "startupTimeoutMs": 56000,
+ "callTimeoutMs": 78000
+ },
+ "disabled-server": { "enabled": true },
+ "project-server": { "type": "stdio", "command": "fixture-project-server" }
+ }
+}
diff --git a/crates/pa-daemon/src/agent_engine/lifecycle.rs b/crates/pa-daemon/src/agent_engine/lifecycle.rs
index a268a3ceb7..aceaf87295 100644
--- a/crates/pa-daemon/src/agent_engine/lifecycle.rs
+++ b/crates/pa-daemon/src/agent_engine/lifecycle.rs
@@ -66,8 +66,8 @@ impl AgentSessionEngine {
let cwd = std::sync::Arc::new(std::sync::RwLock::new(config.cwd.clone()));
// The ACP MCP store (auth storage construction is blocking, off the hot async paths).
let agent_dir = config.agent_dir.clone();
- // Settings-declared user servers; re-read per resolve so `mcp.refresh` sees settings
- // changes.
+ // Executable MCP settings and catalog sources are user/global only.
+ // Re-read per resolve so refresh sees user changes without project overrides.
let mcp_cwd = std::sync::Arc::clone(&cwd);
let mcp_agent_dir = agent_dir.clone();
let catalog_cwd = std::sync::Arc::clone(&cwd);
@@ -84,7 +84,7 @@ impl AgentSessionEngine {
let settings = pa_core::settings::SettingsManager::create(&mcp_cwd, &mcp_agent_dir);
Some(
settings
- .settings()
+ .global_settings()
.mcp_servers
.clone()
.unwrap_or_default()
@@ -108,7 +108,7 @@ impl AgentSessionEngine {
let settings =
pa_core::settings::SettingsManager::create(&catalog_cwd, &catalog_agent_dir);
settings
- .settings()
+ .global_settings()
.mcp_catalog_sources
.clone()
.unwrap_or_default()
diff --git a/crates/pa-daemon/src/agent_engine/tests.rs b/crates/pa-daemon/src/agent_engine/tests.rs
index 4f291a7453..b9da99a0c4 100644
--- a/crates/pa-daemon/src/agent_engine/tests.rs
+++ b/crates/pa-daemon/src/agent_engine/tests.rs
@@ -12,6 +12,7 @@ mod autonomous;
mod compaction;
mod failover_facts;
mod goal;
+mod mcp_settings;
mod model_resolution;
mod quota_park;
mod reload;
diff --git a/crates/pa-daemon/src/agent_engine/tests/mcp_settings.rs b/crates/pa-daemon/src/agent_engine/tests/mcp_settings.rs
new file mode 100644
index 0000000000..de58306dcb
--- /dev/null
+++ b/crates/pa-daemon/src/agent_engine/tests/mcp_settings.rs
@@ -0,0 +1,70 @@
+//! Configuration-only coverage: never build a session, kernel, or MCP transport.
+use super::*;
+
+#[test]
+fn mcp_settings_stay_global_after_refresh_and_cwd_rebind() {
+ let dir = tempfile::tempdir().unwrap();
+ let agent_dir = dir.path().join("agent");
+ std::fs::create_dir_all(&agent_dir).unwrap();
+ let mut global: Value = serde_json::from_str(include_str!(concat!(
+ env!("CARGO_MANIFEST_DIR"),
+ "/../pa-core/tests/fixtures/mcp/global-settings.json"
+ )))
+ .unwrap();
+ global["mcpCatalogSources"] = json!([concat!(
+ env!("CARGO_MANIFEST_DIR"),
+ "/../pa-core/tests/fixtures/mcp/global-services.json"
+ )]);
+ let mut project: Value = serde_json::from_str(include_str!(concat!(
+ env!("CARGO_MANIFEST_DIR"),
+ "/../pa-core/tests/fixtures/mcp/project-settings.json"
+ )))
+ .unwrap();
+ project["mcpCatalogSources"] = json!([concat!(
+ env!("CARGO_MANIFEST_DIR"),
+ "/../pa-core/tests/fixtures/mcp/project-services.json"
+ )]);
+ std::fs::write(agent_dir.join("settings.json"), global.to_string()).unwrap();
+ for cwd in [dir.path().to_path_buf(), dir.path().join("other-project")] {
+ std::fs::create_dir_all(cwd.join(".prime/agent")).unwrap();
+ std::fs::write(cwd.join(".prime/agent/settings.json"), project.to_string()).unwrap();
+ }
+ let engine = bare_engine(dir.path());
+ let mut handlers = HostRequestHandlers::default();
+ pa_core::mcp::McpManager::register_host_handlers(&engine.mcp, &mut handlers);
+ let config = handlers.get("mcp.config").unwrap();
+ for cwd in [dir.path().to_path_buf(), dir.path().join("other-project")] {
+ engine.set_cwd(cwd);
+ {
+ let mut manager = engine.mcp.lock().unwrap();
+ manager.refresh();
+ assert_eq!(
+ manager.get_enabled_persistent_generic_servers(),
+ vec!["user-server"]
+ );
+ assert!(manager.service_descriptor("user-catalog").is_some());
+ assert!(manager.service_descriptor("project-catalog").is_none());
+ }
+ for (name, expected) in global["mcpServers"].as_object().unwrap() {
+ let actual = engine
+ .runtime
+ .block_on(config(pa_core::kernel::shared::HostRequestPayload {
+ data: json!({ "server": name }),
+ }))
+ .unwrap();
+ assert_eq!(actual, *expected);
+ }
+ assert_eq!(
+ engine
+ .runtime
+ .block_on(config(pa_core::kernel::shared::HostRequestPayload {
+ data: json!({ "server": "project-server" }),
+ },))
+ .unwrap(),
+ json!({})
+ );
+ // A global edit still takes effect when the live manager refreshes.
+ global["mcpServers"]["user-server"]["args"] = json!(["updated-user-argument"]);
+ std::fs::write(agent_dir.join("settings.json"), global.to_string()).unwrap();
+ }
+}