Add read-only policy support to MCP tool requests (#46042)

## Why

Read-only MCP discovery and invocation need a consistent policy across requests, connection reuse, and tool catalogs. Reusing an unrestricted connection or cached catalog can bypass filtered discovery.

## What changed

- Thread `requires_read_only_mcp_tools` through MCP configuration and client setup, leaving it disabled by default.
- When enabled, set `openai/readOnly` to `true` in `tools/list` and `tools/call` request metadata, overriding a caller-supplied `false` while preserving other metadata, pagination, and arguments.
- Include the policy in connection identity and bypass shared Apps and persistent tool catalog caches for read-only connections.

## Testing

Add coverage for metadata propagation in legacy and modern protocol modes, preservation through session recovery, and isolation from unrestricted connections and shared Apps catalogs.

GitOrigin-RevId: f4a3a4021a54e302bffd53f08092b080c056246b
This commit is contained in:
Rennie authored and copyberry committed 2026-09-16 22:25:54 +00:00
1 parent 78e7825a47
commit b97abdbe30
15 files changed
+312 -42

No files matched your search

+21 -23
View File
@@ -7608,10 +7608,10 @@ async fn in_app_resume_session_cwd_without_metadata_is_non_fatal() -> Result<()>
#[tokio::test]
async fn remote_resume_keeps_server_only_cwd_out_of_local_config() -> Result<()> {
let (mut app, _app_event_rx, _op_rx) = make_test_app_with_channels().await;
// Keep the large setup and resume futures off the Windows test stack.
let (mut app, _app_event_rx, _op_rx) = Box::pin(make_test_app_with_channels()).await;
let local_cwd = app.config.cwd.to_path_buf();
let local_workspace_roots = app
.rebuild_config_for_cwd(local_cwd.clone())
let local_workspace_roots = Box::pin(app.rebuild_config_for_cwd(local_cwd.clone()))
.await?
.workspace_roots;
let remote_cwd = if cfg!(windows) {
@@ -7642,14 +7642,13 @@ async fn remote_resume_keeps_server_only_cwd_out_of_local_config() -> Result<()>
};
app.harness_overrides.cwd = Some(remote_cwd.clone());
let mut app_server = Box::pin(crate::start_embedded_app_server_for_picker(&app.config)).await?;
app_server
.resume_thread(
&crate::local_settings::LocalSettings::from(&app.config),
app.config.clone(),
ThreadId::from_string(&thread_id)?,
crate::app_server_session::ResumeModelSettings::RestoreFromThread,
)
.await?;
Box::pin(app_server.resume_thread(
&crate::local_settings::LocalSettings::from(&app.config),
app.config.clone(),
ThreadId::from_string(&thread_id)?,
crate::app_server_session::ResumeModelSettings::RestoreFromThread,
))
.await?;
let mut tui = crate::tui::test_support::make_test_tui()?;
app.runtime_approval_policy_override = Some(RuntimeApprovalPolicyOverride::Restored(
AskForApproval::Never,
@@ -7662,18 +7661,17 @@ async fn remote_resume_keeps_server_only_cwd_out_of_local_config() -> Result<()>
RuntimePermissionProfileOverride::from_restored_config(&prior_config),
);
let control = app
.resume_target_session(
&mut tui,
&mut app_server,
crate::resume_picker::SessionTarget {
path: Some(rollout_path),
thread_id: ThreadId::from_string(&thread_id)?,
cwd: None,
history_mode: None,
},
)
.await?;
let control = Box::pin(app.resume_target_session(
&mut tui,
&mut app_server,
crate::resume_picker::SessionTarget {
path: Some(rollout_path),
thread_id: ThreadId::from_string(&thread_id)?,
cwd: None,
history_mode: None,
},
))
.await?;
assert!(matches!(control, AppRunControl::Continue));
assert_eq!(app.harness_overrides.cwd, Some(remote_cwd));