Skip to content

Commit 7ac6d43

Browse files
feat(mcp): filter untrusted servers before connecting in init_mcp
1 parent 9197f8d commit 7ac6d43

2 files changed

Lines changed: 5 additions & 6 deletions

File tree

crates/forge_main/src/ui.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1771,7 +1771,7 @@ impl<A: API + ConsoleWriter + 'static, F: Fn(ForgeConfig) -> A + Send + Sync> UI
17711771
// Show the endpoint (URL for HTTP, command for stdio) so the user
17721772
// can see exactly what will be executed/contacted if they accept.
17731773
rows.push(SelectRow::header(format!(
1774-
" - {name}: {}",
1774+
" - {name}: {}\n",
17751775
format_mcp_server(server),
17761776
)));
17771777
}

crates/forge_services/src/mcp/service.rs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,8 @@ where
101101
}
102102

103103
async fn init_mcp(&self) -> anyhow::Result<()> {
104-
let mcp = self.manager.read_mcp_config(None).await?;
104+
let raw_mcp = self.manager.read_mcp_config(None).await?;
105+
let mcp = self.manager.filter_trusted(raw_mcp).await?;
105106

106107
// Fast path: if config is unchanged, skip reinitialization without acquiring
107108
// the lock
@@ -233,10 +234,8 @@ where
233234
C: From<<I as McpServerInfra>::Client>,
234235
{
235236
async fn get_mcp_servers(&self) -> anyhow::Result<McpServers> {
236-
// Filter the merged config so only trusted servers remain. Using the
237-
// *filtered* config's hash as the cache key ensures that a cache entry
238-
// populated before a rejection cannot leak rejected tools into later
239-
// requests.
237+
// init_mcp already filters untrusted servers before connecting, so the
238+
// cache key is derived from the trusted config to avoid stale entries.
240239
let raw_config = self.manager.read_mcp_config(None).await?;
241240
let trusted_config = self.manager.filter_trusted(raw_config).await?;
242241
let config_hash = trusted_config.cache_key();

0 commit comments

Comments
 (0)