Skip to content

armgit / jan

Public Imported from GitHub
0

Jan is an open source alternative to ChatGPT that runs 100% offline on your computer.

feat(cli): guide plugin installs through connection and sign-in

thinhlpgd84cb3064b7d
diff --git a/docs/src/pages/docs/agent/plugins.mdx b/docs/src/pages/docs/agent/plugins.mdx
index b9d613d8f..3d209859b 100644
--- a/docs/src/pages/docs/agent/plugins.mdx
+++ b/docs/src/pages/docs/agent/plugins.mdx
@@ -75,6 +75,23 @@ The plugin is cloned (`--depth 1`), validated to contain a plugin manifest, `ski
Reinstalling an existing plugin is refused (remove it first). Specs with shell metacharacters are
rejected outright - a plugin name is a name, not a command.
+In the TUI, installation continues directly into setup. Jan reads the plugin's
+`.mcp.json` or inline `mcpServers` declarations, collects required keys in a masked
+field, and offers **Enable and connect** for each server. Nothing is enabled or
+executed until you confirm. Remote servers that require OAuth continue into
+browser sign-in and reconnect automatically afterward.
+
+Choose **Not now** or press Esc to keep the plugin installed without completing
+its connections. Resume with `/plugin setup <name>`; no separate terminal command
+or Jan restart is needed. Plugins without keys or MCP servers are ready immediately.
+
+Imported MCP servers use names such as `figma:figma` to avoid collisions. Existing
+servers with different settings are not overwritten; review them in `/mcp`.
+Stored key references such as `${API_KEY}` and `${CLAUDE_PLUGIN_ROOT}` are resolved
+from the plugin's key store and installed directory. Key files and generated MCP
+configuration are owner-only (`0600`) on Unix. Provider-side OAuth client
+restrictions still apply.
+
A plugin installed or edited outside the running session (another terminal, `git pull`, a hand
edit) is picked up with `/reload plugin`, which re-scans and reports what was added, removed, or
changed without restarting.
@@ -141,6 +158,7 @@ Interactive commands:
/plugin list # one compact summary line per plugin
/plugin list release-tools # description and skill names for one plugin
/plugin remove release-tools # uninstall
+/plugin setup release-tools # resume API-key or MCP connection setup
/plugin search prepare # search the marketplace (name/description)
```
diff --git a/docs/src/pages/docs/agent/slash-commands.mdx b/docs/src/pages/docs/agent/slash-commands.mdx
index f053fba6e..7006b1be0 100644
--- a/docs/src/pages/docs/agent/slash-commands.mdx
+++ b/docs/src/pages/docs/agent/slash-commands.mdx
@@ -65,7 +65,7 @@ See [Run modes](/docs/agent/run-modes), [Goals and todos](/docs/agent/goals-and-
| `/model [id]` | Switch model. Bare: pick interactively. Opening the picker re-lists each provider's models once per session; <kbd>Ctrl</kbd>+<kbd>R</kbd> inside it re-lists them again on demand |
| `/effort [low\|medium\|high]` | Set reasoning effort. Bare: show current; `low` is faster, `high` thinks deeper |
| `/mcp` | List, toggle, add, edit, and remove MCP servers; Enter opens a server's detail screen, where you can list its tools and sign in to it |
-| `/plugin [list\|install <spec>\|remove <name>\|search [query]\|setup <name>]` | Manage plugins: install from a git URL or the marketplace, list/remove installed, search the marketplace. `setup` collects a plugin's required API keys (masked paste; keys land in `~/.jan/agent/plugin-env/` 0600 and reach the sandboxed shell on the next run) |
+| `/plugin [list\|install <spec>\|remove <name>\|search [query]\|setup <name>]` | Install and manage plugins. Installation opens setup automatically: masked API-key entry, then confirmation to enable declared MCP servers and sign in when required. `setup <name>` resumes setup without manual MCP configuration or restarting Jan |
| `/reload [config\|plugin\|skills\|system-prompt]` | Re-read on-disk state into the running session without a restart (bare: all). `config` re-applies the project's `agent.toml` limits - `context_window`, `compaction_ratio`, `compaction_reserve_tokens`, `max_tokens`, `send_reasoning`, `[budget].max_tokens` - to the next run and lists what changed; the model, `[tools]`, `[provider]` and `[budget].max_usd` still need a restart. `plugin`/`skills` re-scan and rebuild the catalog, reporting added/removed/changed entries. `system-prompt` re-reads `JAN.md`, which applies on the next run |
| `/login` | Sign in to Tokamak and save the API key |
| `/config` | View provider config (`~/.jan/config.toml`) |
diff --git a/src-tauri/src/core/cli/tui.rs b/src-tauri/src/core/cli/tui.rs
index 0ee93065c..6b42aa49a 100644
--- a/src-tauri/src/core/cli/tui.rs
+++ b/src-tauri/src/core/cli/tui.rs
@@ -448,6 +448,8 @@ enum PickerKind {
/// `/plugin install <collection>`: choose which plugins inside a collection
/// repo to install. Space toggles a row, Enter installs everything checked.
PluginSelect,
+ /// Review a plugin-provided MCP server before enabling or executing it.
+ PluginConnect,
/// One MCP server's detail screen: the info block plus the actions that
/// apply to it (see `open_mcp_detail`). Reached with Enter from `ToggleMcp`.
McpServer,
@@ -489,6 +491,7 @@ impl Picker {
PickerKind::ProviderSettings => " providers ",
PickerKind::Todo => " todo ",
PickerKind::PluginSelect => " install plugins ",
+ PickerKind::PluginConnect => " plugin connection ",
PickerKind::McpServer => " mcp server ",
PickerKind::Agents => " subagents ",
PickerKind::AgentDetail => " subagent ",
@@ -514,6 +517,7 @@ impl Picker {
}
PickerKind::Todo => " ↑/↓ select d done x abandon r remove Esc close",
PickerKind::PluginSelect => " ↑/↓ select Space toggle Enter install Esc cancel",
+ PickerKind::PluginConnect => " Up/Down select Enter confirm Esc cancel setup",
PickerKind::McpServer => " ↑/↓ select Enter run Esc back",
PickerKind::Agents => " ↑/↓ select Enter view Esc close",
PickerKind::AgentDetail => " Esc back",
@@ -816,6 +820,8 @@ enum McpJob {
/// screen is open, so the screen refreshes when the connect lands instead of
/// sitting on `not connected` until the user navigates away and back.
Connect(String),
+ /// First connection during plugin setup; an OAuth challenge starts sign-in.
+ PluginConnect(String),
}
/// What an `McpJob` came back with.
@@ -836,6 +842,10 @@ enum McpJobDone {
server: String,
result: Result<(), String>,
},
+ PluginConnected {
+ server: String,
+ result: Result<(), super::mcp::ConnectError>,
+ },
}
/// A browser launch held back for confirmation, for flows with no dock of their
@@ -2110,6 +2120,10 @@ struct App {
/// Active `/plugin setup` prompt (docked like `/login`); owns the keyboard
/// while open and collects the plugin's required API keys, masked.
plugin_setup: Option<PluginSetupPrompt>,
+ /// Remaining plugins/connections in the current install or setup flow.
+ plugin_setup_queue: std::collections::VecDeque<String>,
+ plugin_mcp_pending: std::collections::VecDeque<(String, serde_json::Value)>,
+ plugin_mcp_connecting: Option<String>,
/// Active `/settings` edit prompt (docked like `/login`); owns the
/// keyboard while open. Holds the setting being edited and any validation
/// error; writes go straight to agent.toml on Enter.
@@ -2755,6 +2769,9 @@ impl App {
probed_models: std::collections::HashSet::new(),
login_submit: None,
plugin_setup: None,
+ plugin_setup_queue: Default::default(),
+ plugin_mcp_pending: Default::default(),
+ plugin_mcp_connecting: None,
account_login: None,
account_login_submit: None,
account_login_manual_tx: None,
@@ -9407,10 +9424,8 @@ fn finish_plugin_install(
);
}
}
- // A plugin that declares required API keys opens its setup dock
- // right away: the link to obtain each key plus a masked paste
- // field, so the user never has to edit env files by hand.
- open_plugin_setup(app);
+ app.plugin_setup_queue = plugins.into_iter().map(|p| p.name).collect();
+ next_plugin_setup(app);
}
Ok(GitInstall::Collection(candidates)) => {
let Some(url) = url else {
@@ -11029,34 +11044,128 @@ impl MaskedPrompt for PluginSetupPrompt {
}
}
-/// Open `/plugin setup` for the first installed plugin whose declared env
-/// variables are not yet satisfied. Returns whether a dock opened.
+/// Set up installed plugins without leaving the TUI.
fn open_plugin_setup(app: &mut App) -> bool {
- let missing = crate::core::agent::plugins::missing_plugin_env(&app.project_root);
- let Some((plugin, _, _)) = missing.first() else {
- return false;
- };
- let plugin = plugin.clone();
- let entries = missing
- .into_iter()
- .filter(|(p, _, _)| p == &plugin)
- .map(|(_, key, url)| PluginEnvEntry { key, url })
- .collect::<Vec<_>>();
- start_plugin_setup(app, &plugin, entries)
+ app.plugin_setup_queue = crate::core::agent::plugins::installed(&app.project_root)
+ .into_iter().map(|p| p.name).collect();
+ next_plugin_setup(app)
+}
+
+fn next_plugin_setup(app: &mut App) -> bool {
+ while let Some(plugin) = app.plugin_setup_queue.pop_front() {
+ if open_plugin_setup_for(app, &plugin) {
+ return true;
+ }
+ }
+ false
}
-/// Open `/plugin setup` for a named plugin, offering every variable it
-/// declares (even satisfied ones, so a value can be replaced). Returns whether
-/// a dock opened.
fn open_plugin_setup_for(app: &mut App, plugin: &str) -> bool {
- let entries = crate::core::agent::plugins::declared_plugin_env(&app.project_root, plugin)
+ let Some((directory, _)) = crate::core::agent::plugins::find_installed(&app.project_root, plugin) else {
+ app.note(&format!("plugin '{plugin}' is not installed - use /plugin install <git-url> first"));
+ return false;
+ };
+ let entries = crate::core::agent::plugins::declared_plugin_env(&app.project_root, &directory)
.into_iter()
.map(|(key, url)| PluginEnvEntry { key, url })
.collect::<Vec<_>>();
if entries.is_empty() {
- return false;
+ return open_plugin_mcp_setup(app, &directory);
+ }
+ start_plugin_setup(app, &directory, entries)
+}
+
+fn open_plugin_mcp_setup(app: &mut App, plugin: &str) -> bool {
+ match crate::core::agent::plugins::plugin_mcp_servers(&app.project_root, plugin) {
+ Ok(servers) if servers.is_empty() => {
+ app.note(&format!("plugin '{plugin}' is ready - no connection required"));
+ false
+ }
+ Ok(servers) => {
+ app.plugin_mcp_pending = servers.into_iter()
+ .map(|(name, config)| (format!("{plugin}:{name}"), config)).collect();
+ show_next_plugin_connection(app);
+ true
+ }
+ Err(e) => {
+ app.note(&format!("plugin '{plugin}' setup: {e}"));
+ false
+ }
+ }
+}
+
+fn show_next_plugin_connection(app: &mut App) {
+ let Some((name, config)) = app.plugin_mcp_pending.front() else {
+ next_plugin_setup(app);
+ return;
+ };
+ let target = if let Some(url) = config.get("url").and_then(serde_json::Value::as_str) {
+ // Do not put URL credentials, query strings or headers in the transcript.
+ reqwest::Url::parse(url).ok()
+ .and_then(|u| u.host_str().map(str::to_owned))
+ .unwrap_or_else(|| "remote MCP server".to_string())
+ } else {
+ config.get("command").and_then(serde_json::Value::as_str)
+ .unwrap_or("local MCP process").to_string()
+ };
+ app.picker = Some(Picker {
+ kind: PickerKind::PluginConnect,
+ items: vec![
+ PickerItem {
+ value: "connect".into(),
+ label: format!("Enable and connect {name}"),
+ hint: Some(format!("{target} - allow this plugin's MCP server")),
+ checkbox: None,
+ },
+ PickerItem {
+ value: "skip".into(),
+ label: "Not now".into(),
+ hint: Some("Keep installed; resume with /plugin setup <name>".into()),
+ checkbox: None,
+ },
+ ],
+ selected: 0,
+ armed_delete: None,
+ });
+}
+
+fn confirm_plugin_connection(app: &mut App, connect: bool) {
+ app.picker = None;
+ let Some((name, mut config)) = app.plugin_mcp_pending.pop_front() else { return };
+ if !connect {
+ show_next_plugin_connection(app);
+ return;
+ }
+ // The shared MCP config is user-owned. Never replace an unrelated server.
+ let result = (|| {
+ super::mcp::validate_server_name(&name)?;
+ super::mcp::validate_config(&config)?;
+ if let Some(existing) = super::mcp::get_server(&name) {
+ let mut existing = existing.config;
+ existing.as_object_mut().map(|o| o.remove("active"));
+ config.as_object_mut().map(|o| o.remove("active"));
+ if existing != config {
+ return Err(format!("MCP server '{name}' already has different settings; review it in /mcp"));
+ }
+ }
+ config["active"] = true.into();
+ super::mcp::upsert_server(&name, &config)
+ })();
+ if let Err(e) = result {
+ app.note(&e);
+ show_next_plugin_connection(app);
+ return;
+ }
+ app.note(&format!("connecting '{name}' - sign-in will open if required..."));
+ app.plugin_mcp_connecting = Some(name.clone());
+ app.mcp_job_request = Some(McpJob::PluginConnect(name));
+}
+
+fn finish_plugin_connection(app: &mut App, server: &str) {
+ if app.plugin_mcp_connecting.as_deref() == Some(server) {
+ app.plugin_mcp_connecting = None;
+ show_next_plugin_connection(app);
}
- start_plugin_setup(app, plugin, entries)
}
/// Install the dock state for `plugin` with `entries`, after announcing it.
@@ -11086,6 +11195,8 @@ fn handle_plugin_setup_key(app: &mut App, key: KeyEvent, ctrl: bool) {
|| (ctrl && matches!(key.code, KeyCode::Char('c') | KeyCode::Char('d')));
if cancel {
app.plugin_setup = None;
+ app.plugin_setup_queue.clear();
+ app.plugin_mcp_pending.clear();
app.note("plugin setup cancelled - resume with /plugin setup <name>");
return;
}
@@ -11120,8 +11231,9 @@ fn handle_plugin_setup_key(app: &mut App, key: KeyEvent, ctrl: bool) {
app.note(&format!("plugin setup · {plugin} · {key_name} saved"));
if done {
app.plugin_setup = None;
- // Chain into the next plugin that still needs keys.
- open_plugin_setup(app);
+ if !open_plugin_mcp_setup(app, &plugin) {
+ next_plugin_setup(app);
+ }
}
}
KeyCode::Char('s') | KeyCode::Char('S') if !ctrl && prompt.input.is_empty() => {
@@ -11135,7 +11247,9 @@ fn handle_plugin_setup_key(app: &mut App, key: KeyEvent, ctrl: bool) {
if done {
app.plugin_setup = None;
app.note(&format!("plugin setup · {plugin} · skipped {key_name}"));
- open_plugin_setup(app);
+ if !open_plugin_mcp_setup(app, &plugin) {
+ next_plugin_setup(app);
+ }
}
}
KeyCode::Backspace => {
@@ -11464,6 +11578,10 @@ async fn handle_key(
picker.kind = PickerKind::AgentDetail;
app.agent_detail = Some(run_id);
}
+ KeyCode::Enter if picker.kind == PickerKind::PluginConnect => {
+ let connect = picker.items[picker.selected].value == "connect";
+ confirm_plugin_connection(app, connect);
+ }
// `/mcp` picker: `a` opens the add wizard, `e` opens the edit
// wizard prefilled from the selected row, `d` removes the selected
// server. All act through the shared config layer.
@@ -11749,6 +11867,7 @@ async fn handle_key(
PickerKind::Agents
| PickerKind::AgentDetail
| PickerKind::BackgroundShells => {}
+ PickerKind::PluginConnect => {}
}
}
// Esc on the detail screen steps back to the server list rather
@@ -11776,12 +11895,16 @@ async fn handle_key(
app.agent_detail = None;
}
KeyCode::Esc | KeyCode::Char('q') if !ctrl => {
+ app.plugin_setup_queue.clear();
+ app.plugin_mcp_pending.clear();
app.plugin_collection_url = None;
app.picker = None;
app.mcp_detail = None;
app.agent_detail = None;
}
_ if ctrl_c || ctrl_d => {
+ app.plugin_setup_queue.clear();
+ app.plugin_mcp_pending.clear();
app.plugin_collection_url = None;
app.picker = None;
app.mcp_detail = None;
@@ -14688,16 +14811,16 @@ async fn plugin_command(app: &mut App, arg: &str) {
app.note("installing plugin...");
}
"setup" => {
+ if app.plugin_mcp_connecting.is_some() {
+ app.note("plugin connection is in progress");
+ return;
+ }
+ app.plugin_setup_queue.clear();
+ app.plugin_mcp_pending.clear();
if rest.is_empty() {
- if !open_plugin_setup(app) {
- app.note(
- "no plugin is missing keys (usage: /plugin setup <name>)",
- );
- }
- } else if !open_plugin_setup_for(app, &rest) {
- app.note(&format!(
- "plugin '{rest}' declares no setup keys (declare [setup.env] in its plugin.toml)"
- ));
+ open_plugin_setup(app);
+ } else {
+ open_plugin_setup_for(app, &rest);
}
}
"remove" => {
@@ -16296,9 +16419,14 @@ async fn run_mcp_job(job: McpJob, servers: crate::core::state::SharedMcpServers)
McpJobDone::Authorized { server, result }
}
McpJob::Connect(server) => {
- let result = connect_mcp_server(&server, &servers).await;
+ let result = connect_mcp_server(&server, &servers).await.map_err(|e| e.to_string());
McpJobDone::Connected { server, result }
}
+ McpJob::PluginConnect(server) => {
+ super::mcp::disconnect(&server, &servers).await;
+ let result = connect_mcp_server(&server, &servers).await;
+ McpJobDone::PluginConnected { server, result }
+ }
}
}
@@ -16353,6 +16481,7 @@ async fn finish_mcp_job(
Err(e) => {
app.mcp_auth = None;
app.note(&format!("could not start sign-in for '{server}': {e}"));
+ finish_plugin_connection(app, &server);
}
},
McpJobDone::Authorized { server, result } => match result {
@@ -16372,6 +16501,7 @@ async fn finish_mcp_job(
app.browser_confirm = None;
app.mcp_auth = None;
app.note(&format!("sign-in for '{server}' failed: {e}"));
+ finish_plugin_connection(app, &server);
}
},
McpJobDone::Connected { server, result } => {
@@ -16379,6 +16509,7 @@ async fn finish_mcp_job(
Ok(()) => app.note(&format!("'{server}' connected")),
Err(e) => app.note(&format!("MCP: {e}")),
}
+ finish_plugin_connection(app, &server);
if app
.mcp_detail
.as_ref()
@@ -16387,6 +16518,23 @@ async fn finish_mcp_job(
open_mcp_detail(app, &server, mcp_servers).await;
}
}
+ McpJobDone::PluginConnected { server, result } => {
+ match result {
+ Err(super::mcp::ConnectError::NeedsAuth { .. }) => {
+ app.note(&format!("'{server}' requires sign-in - preparing authorization..."));
+ *job = Some(tokio::spawn(run_mcp_job(
+ McpJob::BeginAuth(server), mcp_servers.clone(),
+ )));
+ }
+ result => {
+ match result {
+ Ok(()) => app.note(&format!("'{server}' connected - tools are ready")),
+ Err(e) => app.note(&format!("could not connect '{server}': {e}; retry from /plugin setup")),
+ }
+ finish_plugin_connection(app, &server);
+ }
+ }
+ }
}
}
@@ -16571,7 +16719,7 @@ fn show_mcp_tools(app: &mut App) {
async fn connect_mcp_server(
name: &str,
servers: &crate::core::state::SharedMcpServers,
-) -> Result<(), String> {
+) -> Result<(), super::mcp::ConnectError> {
let cfg = super::mcp::list_servers()
.into_iter()
.find(|s| s.name == name)
@@ -16579,7 +16727,6 @@ async fn connect_mcp_server(
.ok_or_else(|| format!("'{name}' is no longer in mcp_config.json"))?;
super::mcp::connect(name, &cfg, servers)
.await
- .map_err(|e| e.to_string())
}
/// `connect_mcp_server`, detached: for the paths with no screen waiting on the
@@ -37834,6 +37981,67 @@ mod tests {
let _ = std::fs::remove_dir_all(&root);
}
+ #[test]
+ fn plugin_setup_offers_mcp_connection_without_manual_configuration() {
+ crate::core::app::commands::with_temp_data_folder(|_| {
+ let (mut app, root) = skill_test_app("deploy", "How to deploy.");
+ rt().block_on(run_command(&mut app, "plugin setup design", &no_mcp()));
+ assert!(transcript_text(&app).contains("is not installed"));
+ assert!(app.plugin_setup.is_none());
+ let dir = root.join(".jan/agent/plugins/design");
+ std::fs::create_dir_all(&dir).unwrap();
+ std::fs::write(dir.join("plugin.toml"), "name = \"design\"\n").unwrap();
+ std::fs::write(
+ dir.join(".mcp.json"),
+ r#"{"mcpServers":{"remote":{"url":"https://example.com/mcp"}}}"#,
+ )
+ .unwrap();
+ finish_plugin_install(
+ &mut app,
+ None,
+ Ok(crate::core::agent::plugins::GitInstall::Installed(
+ crate::core::agent::plugins::installed(&root),
+ )),
+ );
+ let screen = render_rows(&mut app, 100, 30).join("\n");
+ assert!(screen.contains("Enable and connect"), "{screen}");
+ assert!(screen.contains("example.com"), "{screen}");
+ assert!(super::super::mcp::get_server("design:remote").is_none());
+ rt().block_on(handle_key(
+ &mut app, key(KeyCode::Esc), &PermissionRegistry::default(), &mut None, &no_mcp(),
+ ));
+ assert!(super::super::mcp::get_server("design:remote").is_none());
+ rt().block_on(run_command(&mut app, "plugin setup design", &no_mcp()));
+ rt().block_on(handle_key(
+ &mut app, key(KeyCode::Enter), &PermissionRegistry::default(), &mut None, &no_mcp(),
+ ));
+ let configured = super::super::mcp::get_server("design:remote").unwrap();
+ assert!(configured.active);
+ assert_eq!(configured.config["url"], "https://example.com/mcp");
+ #[cfg(unix)]
+ {
+ use std::os::unix::fs::PermissionsExt;
+ let mode = std::fs::metadata(super::super::mcp::config_file_path())
+ .unwrap().permissions().mode();
+ assert_eq!(mode & 0o777, 0o600);
+ }
+ // An existing user-owned server must not be silently replaced.
+ app.plugin_mcp_connecting = None;
+ super::super::mcp::upsert_server("design:remote", &serde_json::json!({
+ "type": "http", "url": "https://other.example/mcp",
+ })).unwrap();
+ rt().block_on(run_command(&mut app, "plugin setup design", &no_mcp()));
+ rt().block_on(handle_key(
+ &mut app, key(KeyCode::Enter), &PermissionRegistry::default(), &mut None, &no_mcp(),
+ ));
+ assert_eq!(
+ super::super::mcp::get_server("design:remote").unwrap().config["url"],
+ "https://other.example/mcp",
+ );
+ std::fs::remove_dir_all(root).unwrap();
+ });
+ }
+
#[tokio::test]
async fn plugin_command_installs_lists_dispatch_removes() {
// Local git repo fixture with a plugin payload.