mirror of
https://github.com/openai/codex.git
synced 2026-11-30 00:10:49 +00:00
Filter MCP server status tools by connector ID (#64527)
## Why A single MCP server such as `codex_apps` can expose tools from multiple connectors. Clients that need one connector's tools currently have to filter the server's tool inventory themselves. ## What changed Add an optional `connectorId` parameter to `mcpServerStatus/list`. It keeps only tools whose `_meta.connector_id` or `_meta.connectorId` exactly matches the requested string. Servers with no matching tools still appear with an empty `tools` map and their status. Omit the filter or pass `null` to return all tools, and repeat the filter on each page when paginating. ## Testing Add integration coverage for standalone and thread-scoped requests, including both metadata spellings, an unknown connector ID, and an omitted filter. GitOrigin-RevId: d6ad367dff72002b239db7b5012145ba1811ccac
This commit is contained in:
@@ -1926,6 +1926,13 @@
|
||||
},
|
||||
"ListMcpServerStatusParams": {
|
||||
"properties": {
|
||||
"connectorId": {
|
||||
"description": "Return only tools whose `_meta.connector_id` or `_meta.connectorId` equals this ID. Selected servers with no matching tools still appear on the page.",
|
||||
"type": [
|
||||
"string",
|
||||
"null"
|
||||
]
|
||||
},
|
||||
"cursor": {
|
||||
"description": "Opaque pagination cursor returned by a previous call.",
|
||||
"type": [
|
||||
|
||||
+7
@@ -15229,6 +15229,13 @@
|
||||
"ListMcpServerStatusParams": {
|
||||
"$schema": "http://json-schema.org/draft-07/schema#",
|
||||
"properties": {
|
||||
"connectorId": {
|
||||
"description": "Return only tools whose `_meta.connector_id` or `_meta.connectorId` equals this ID. Selected servers with no matching tools still appear on the page.",
|
||||
"type": [
|
||||
"string",
|
||||
"null"
|
||||
]
|
||||
},
|
||||
"cursor": {
|
||||
"description": "Opaque pagination cursor returned by a previous call.",
|
||||
"type": [
|
||||
|
||||
+7
@@ -11089,6 +11089,13 @@
|
||||
"ListMcpServerStatusParams": {
|
||||
"$schema": "http://json-schema.org/draft-07/schema#",
|
||||
"properties": {
|
||||
"connectorId": {
|
||||
"description": "Return only tools whose `_meta.connector_id` or `_meta.connectorId` equals this ID. Selected servers with no matching tools still appear on the page.",
|
||||
"type": [
|
||||
"string",
|
||||
"null"
|
||||
]
|
||||
},
|
||||
"cursor": {
|
||||
"description": "Opaque pagination cursor returned by a previous call.",
|
||||
"type": [
|
||||
|
||||
@@ -10,6 +10,13 @@
|
||||
}
|
||||
},
|
||||
"properties": {
|
||||
"connectorId": {
|
||||
"description": "Return only tools whose `_meta.connector_id` or `_meta.connectorId` equals this ID. Selected servers with no matching tools still appear on the page.",
|
||||
"type": [
|
||||
"string",
|
||||
"null"
|
||||
]
|
||||
},
|
||||
"cursor": {
|
||||
"description": "Opaque pagination cursor returned by a previous call.",
|
||||
"type": [
|
||||
|
||||
BIN
Binary file not shown.
BIN
Binary file not shown.
+5
@@ -21,6 +21,11 @@ detail?: McpServerStatusDetail | null, threadId?: string | null,
|
||||
* Limit discovery to one server. With a thread ID, reuse that thread's MCP connection.
|
||||
*/
|
||||
serverName?: string | null,
|
||||
/**
|
||||
* Return only tools whose `_meta.connector_id` or `_meta.connectorId` equals this ID.
|
||||
* Selected servers with no matching tools still appear on the page.
|
||||
*/
|
||||
connectorId?: string | null,
|
||||
/**
|
||||
* Select this environment's registration. Requires `serverName` and `threadId`.
|
||||
* When omitted, a named request uses the same server as older clients.
|
||||
|
||||
@@ -63,6 +63,10 @@ pub struct ListMcpServerStatusParams {
|
||||
/// Limit discovery to one server. With a thread ID, reuse that thread's MCP connection.
|
||||
#[ts(optional = nullable)]
|
||||
pub server_name: Option<String>,
|
||||
/// Return only tools whose `_meta.connector_id` or `_meta.connectorId` equals this ID.
|
||||
/// Selected servers with no matching tools still appear on the page.
|
||||
#[ts(optional = nullable)]
|
||||
pub connector_id: Option<String>,
|
||||
/// Select this environment's registration. Requires `serverName` and `threadId`.
|
||||
/// When omitted, a named request uses the same server as older clients.
|
||||
#[ts(optional = nullable)]
|
||||
|
||||
@@ -671,6 +671,11 @@ runtime refresh; discovery then waits only for that server. Without `threadId`,
|
||||
discovery creates a connection for the selected server. An unknown name returns an empty page.
|
||||
Omitting `serverName` preserves full-inventory discovery.
|
||||
|
||||
Pass `connectorId` to keep only tools whose `_meta.connector_id` or `_meta.connectorId`
|
||||
matches that string exactly. A selected server with no matching tools returns an
|
||||
empty `tools` map. The server still reports its authentication and discovery status.
|
||||
Repeat the filter on each page. Omitting it or passing `null` returns all tools.
|
||||
|
||||
# MCP OAuth login
|
||||
|
||||
`mcpServer/oauth/login` only returns HTTP(S) authorization URLs. Authorization
|
||||
|
||||
@@ -567,7 +567,7 @@ impl McpRequestProcessor {
|
||||
(Arc::new(mcp_config), snapshot)
|
||||
};
|
||||
|
||||
let data: Vec<McpServerStatus> = keys
|
||||
let mut data: Vec<McpServerStatus> = keys
|
||||
.iter()
|
||||
.map(|key| McpServerStatus {
|
||||
name: key.name().to_owned(),
|
||||
@@ -614,6 +614,16 @@ impl McpRequestProcessor {
|
||||
})
|
||||
.collect();
|
||||
|
||||
if let Some(connector_id) = params.connector_id.as_deref() {
|
||||
for status in &mut data {
|
||||
status.tools.retain(|_, tool| {
|
||||
tool.meta.as_ref().is_some_and(|meta| {
|
||||
meta["connector_id"].as_str() == Some(connector_id)
|
||||
|| meta["connectorId"].as_str() == Some(connector_id)
|
||||
})
|
||||
});
|
||||
}
|
||||
}
|
||||
Ok(ListMcpServerStatusResponse { data, next_cursor })
|
||||
}
|
||||
|
||||
|
||||
@@ -1565,6 +1565,7 @@ async fn mcp_server_statuses(
|
||||
) -> Result<Vec<McpServerStatus>> {
|
||||
let request_id = app_server
|
||||
.send_list_mcp_server_status_request(ListMcpServerStatusParams {
|
||||
connector_id: None,
|
||||
environment_id: None,
|
||||
server_name: None,
|
||||
cursor: None,
|
||||
|
||||
@@ -230,6 +230,7 @@ async fn spawned_agent_inherits_selected_executor_skill(
|
||||
}
|
||||
let status_id = app_server
|
||||
.send_list_mcp_server_status_request(ListMcpServerStatusParams {
|
||||
connector_id: None,
|
||||
environment_id: None,
|
||||
thread_id: Some(request.header("thread-id").expect("agent thread ID")),
|
||||
server_name: None,
|
||||
|
||||
@@ -299,6 +299,7 @@ async fn mcp_server_status_discovers_thread_inventory(
|
||||
.request(|request_id| ClientRequest::McpServerStatusList {
|
||||
request_id,
|
||||
params: ListMcpServerStatusParams {
|
||||
connector_id: None,
|
||||
environment_id: None,
|
||||
thread_id: Some(thread.id.clone()),
|
||||
server_name,
|
||||
@@ -375,6 +376,7 @@ async fn mcp_server_status_list_discovers_only_the_requested_page() -> Result<()
|
||||
.request(|request_id| ClientRequest::McpServerStatusList {
|
||||
request_id,
|
||||
params: ListMcpServerStatusParams {
|
||||
connector_id: None,
|
||||
environment_id: None,
|
||||
thread_id: None,
|
||||
server_name: None,
|
||||
@@ -409,6 +411,82 @@ async fn mcp_server_status_list_discovers_only_the_requested_page() -> Result<()
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[test_case(false, McpServerStatusDetail::Full; "standalone")]
|
||||
#[test_case(true, McpServerStatusDetail::ToolsAndAuthOnly; "thread runtime")]
|
||||
#[tokio::test(flavor = "multi_thread", worker_threads = 2)]
|
||||
async fn mcp_server_status_filters_tools_by_connector(
|
||||
thread_runtime: bool,
|
||||
detail: McpServerStatusDetail,
|
||||
) -> Result<()> {
|
||||
let server = MockServer::start().await;
|
||||
let tools = vec![
|
||||
json!({
|
||||
"name": "search",
|
||||
"inputSchema": {"type": "object", "properties": {"query": {"type": "string"}}},
|
||||
"_meta": {"connector_id": "finder"},
|
||||
}),
|
||||
json!({
|
||||
"name": "open",
|
||||
"inputSchema": {"type": "object"},
|
||||
"_meta": {"connectorId": "finder"},
|
||||
}),
|
||||
json!({
|
||||
"name": "send",
|
||||
"inputSchema": {"type": "object"},
|
||||
"_meta": {"connector_id": "mail"},
|
||||
}),
|
||||
json!({"name": "other", "inputSchema": {"type": "object"}}),
|
||||
];
|
||||
let apps =
|
||||
AppsTestServer::mount_with_tools(&server, Arc::new(std::sync::Mutex::new(tools))).await?;
|
||||
let (_home, mut app_server) = start_resource_test_app_server(
|
||||
&apps.chatgpt_base_url,
|
||||
&server.uri(),
|
||||
ResourceTestEnvironment::Auto,
|
||||
)
|
||||
.await?;
|
||||
let thread_id = if thread_runtime {
|
||||
Some(
|
||||
app_server
|
||||
.start_thread(ThreadStartParams::default())
|
||||
.await?
|
||||
.thread
|
||||
.id,
|
||||
)
|
||||
} else {
|
||||
None
|
||||
};
|
||||
let request = |request_id, connector_id: Option<&str>| ClientRequest::McpServerStatusList {
|
||||
request_id,
|
||||
params: ListMcpServerStatusParams {
|
||||
cursor: None,
|
||||
limit: None,
|
||||
detail: Some(detail),
|
||||
thread_id: thread_id.clone(),
|
||||
server_name: Some("codex_apps".to_string()),
|
||||
connector_id: connector_id.map(str::to_owned),
|
||||
environment_id: None,
|
||||
},
|
||||
};
|
||||
let filtered: ListMcpServerStatusResponse =
|
||||
app_server.request(|id| request(id, Some("finder"))).await?;
|
||||
let unknown: ListMcpServerStatusResponse = app_server
|
||||
.request(|id| request(id, Some("unknown")))
|
||||
.await?;
|
||||
let mut expected: ListMcpServerStatusResponse =
|
||||
app_server.request(|id| request(id, None)).await?;
|
||||
assert_eq!(expected.data.len(), 1);
|
||||
assert_eq!(expected.data[0].tools.len(), 4);
|
||||
expected.data[0]
|
||||
.tools
|
||||
.retain(|_, tool| matches!(tool.name.as_str(), "search" | "open"));
|
||||
assert_eq!(expected.data[0].tools.len(), 2);
|
||||
assert_eq!(filtered, expected);
|
||||
expected.data[0].tools.clear();
|
||||
assert_eq!(unknown, expected);
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[test_case(false; "standalone")]
|
||||
#[test_case(true; "thread runtime")]
|
||||
#[tokio::test(flavor = "multi_thread", worker_threads = 2)]
|
||||
@@ -438,6 +516,7 @@ async fn full_mcp_server_status_skips_codex_apps_resource_templates(
|
||||
.request(|request_id| ClientRequest::McpServerStatusList {
|
||||
request_id,
|
||||
params: ListMcpServerStatusParams {
|
||||
connector_id: None,
|
||||
environment_id: None,
|
||||
cursor: None,
|
||||
limit: None,
|
||||
@@ -966,6 +1045,7 @@ async fn oauth_login_automatically_selects_callback_specific_cimd_without_metada
|
||||
.request(|request_id| ClientRequest::McpServerStatusList {
|
||||
request_id,
|
||||
params: ListMcpServerStatusParams {
|
||||
connector_id: None,
|
||||
environment_id: None,
|
||||
server_name: None,
|
||||
cursor: None,
|
||||
@@ -1057,6 +1137,7 @@ async fn mcp_server_status_list_returns_raw_server_and_tool_names(plugin: bool)
|
||||
.request(|request_id| ClientRequest::McpServerStatusList {
|
||||
request_id,
|
||||
params: ListMcpServerStatusParams {
|
||||
connector_id: None,
|
||||
environment_id: None,
|
||||
server_name: None,
|
||||
cursor: None,
|
||||
@@ -1166,6 +1247,7 @@ MCP_TEST_PID_FILE = {}
|
||||
.request(|request_id| ClientRequest::McpServerStatusList {
|
||||
request_id,
|
||||
params: ListMcpServerStatusParams {
|
||||
connector_id: None,
|
||||
environment_id: None,
|
||||
server_name: None,
|
||||
cursor: None,
|
||||
@@ -1181,6 +1263,7 @@ MCP_TEST_PID_FILE = {}
|
||||
std::fs::remove_file(&barrier_file)?;
|
||||
let second_request_id = mcp
|
||||
.send_list_mcp_server_status_request(ListMcpServerStatusParams {
|
||||
connector_id: None,
|
||||
environment_id: None,
|
||||
server_name: None,
|
||||
cursor: None,
|
||||
@@ -1251,6 +1334,7 @@ async fn dormant_thread_status_returns_live_inventory_without_waking_the_thread(
|
||||
.request(|request_id| ClientRequest::McpServerStatusList {
|
||||
request_id,
|
||||
params: ListMcpServerStatusParams {
|
||||
connector_id: None,
|
||||
thread_id: Some(second.thread.id.clone()),
|
||||
server_name: None,
|
||||
environment_id: None,
|
||||
@@ -1323,6 +1407,7 @@ url = "{mcp_server_url}/mcp"
|
||||
.request(|request_id| ClientRequest::McpServerStatusList {
|
||||
request_id,
|
||||
params: ListMcpServerStatusParams {
|
||||
connector_id: None,
|
||||
environment_id: None,
|
||||
server_name: None,
|
||||
cursor: None,
|
||||
@@ -1338,6 +1423,7 @@ url = "{mcp_server_url}/mcp"
|
||||
.request(|request_id| ClientRequest::McpServerStatusList {
|
||||
request_id,
|
||||
params: ListMcpServerStatusParams {
|
||||
connector_id: None,
|
||||
environment_id: None,
|
||||
server_name: None,
|
||||
cursor: None,
|
||||
@@ -1396,6 +1482,7 @@ async fn mcp_server_status_list_reports_thread_runtime_connections() -> Result<(
|
||||
.request(|request_id| ClientRequest::McpServerStatusList {
|
||||
request_id,
|
||||
params: ListMcpServerStatusParams {
|
||||
connector_id: None,
|
||||
environment_id: None,
|
||||
server_name: None,
|
||||
cursor: None,
|
||||
@@ -1437,6 +1524,7 @@ async fn mcp_server_status_list_reports_thread_runtime_connections() -> Result<(
|
||||
.request(|request_id| ClientRequest::McpServerStatusList {
|
||||
request_id,
|
||||
params: ListMcpServerStatusParams {
|
||||
connector_id: None,
|
||||
environment_id: None,
|
||||
server_name: None,
|
||||
cursor: None,
|
||||
@@ -1522,6 +1610,7 @@ async fn mcp_server_status_list_reports_disconnected_stdio_transport() -> Result
|
||||
.request(|request_id| ClientRequest::McpServerStatusList {
|
||||
request_id,
|
||||
params: ListMcpServerStatusParams {
|
||||
connector_id: None,
|
||||
environment_id: None,
|
||||
server_name: None,
|
||||
cursor: None,
|
||||
@@ -1571,6 +1660,7 @@ async fn mcp_server_status_retains_capabilities_when_tool_discovery_fails() -> R
|
||||
.request(|request_id| ClientRequest::McpServerStatusList {
|
||||
request_id,
|
||||
params: ListMcpServerStatusParams {
|
||||
connector_id: None,
|
||||
environment_id: None,
|
||||
server_name: None,
|
||||
cursor: None,
|
||||
@@ -1757,6 +1847,7 @@ async fn mcp_server_status_list_tools_and_auth_only_skips_slow_inventory_calls()
|
||||
|
||||
let request_id = mcp
|
||||
.send_list_mcp_server_status_request(ListMcpServerStatusParams {
|
||||
connector_id: None,
|
||||
environment_id: None,
|
||||
server_name: None,
|
||||
cursor: None,
|
||||
@@ -1813,6 +1904,7 @@ url = "{underscore_server_url}/mcp"
|
||||
.request(|request_id| ClientRequest::McpServerStatusList {
|
||||
request_id,
|
||||
params: ListMcpServerStatusParams {
|
||||
connector_id: None,
|
||||
environment_id: None,
|
||||
server_name: None,
|
||||
cursor: None,
|
||||
@@ -1940,6 +2032,7 @@ async fn mcp_server_status_keeps_same_named_environment_inventory_separate() ->
|
||||
.request(|request_id| ClientRequest::McpServerStatusList {
|
||||
request_id,
|
||||
params: ListMcpServerStatusParams {
|
||||
connector_id: None,
|
||||
environment_id: None,
|
||||
thread_id: Some(thread.id.clone()),
|
||||
server_name: None,
|
||||
@@ -1991,6 +2084,7 @@ async fn mcp_server_status_keeps_same_named_environment_inventory_separate() ->
|
||||
.request(|request_id| ClientRequest::McpServerStatusList {
|
||||
request_id,
|
||||
params: ListMcpServerStatusParams {
|
||||
connector_id: None,
|
||||
environment_id: None,
|
||||
thread_id: Some(thread.id.clone()),
|
||||
server_name: None,
|
||||
@@ -2025,6 +2119,7 @@ async fn mcp_server_status_keeps_same_named_environment_inventory_separate() ->
|
||||
.request(|request_id| ClientRequest::McpServerStatusList {
|
||||
request_id,
|
||||
params: ListMcpServerStatusParams {
|
||||
connector_id: None,
|
||||
thread_id: Some(thread.id.clone()),
|
||||
server_name: Some("notes".to_string()),
|
||||
environment_id: environment_id.map(str::to_owned),
|
||||
|
||||
@@ -2580,6 +2580,7 @@ async fn plugin_install_makes_bundled_mcp_servers_available_to_followup_requests
|
||||
|
||||
let request_id = mcp
|
||||
.send_list_mcp_server_status_request(ListMcpServerStatusParams {
|
||||
connector_id: None,
|
||||
environment_id: None,
|
||||
server_name: None,
|
||||
cursor: None,
|
||||
|
||||
@@ -1837,6 +1837,7 @@ required = true
|
||||
.request(|request_id| ClientRequest::McpServerStatusList {
|
||||
request_id,
|
||||
params: ListMcpServerStatusParams {
|
||||
connector_id: None,
|
||||
environment_id: None,
|
||||
server_name: None,
|
||||
cursor: None,
|
||||
|
||||
@@ -836,6 +836,7 @@ pub(super) async fn fetch_all_mcp_server_statuses(
|
||||
.request_typed(ClientRequest::McpServerStatusList {
|
||||
request_id,
|
||||
params: ListMcpServerStatusParams {
|
||||
connector_id: None,
|
||||
environment_id: None,
|
||||
cursor: cursor.clone(),
|
||||
limit: Some(100),
|
||||
|
||||
@@ -3464,6 +3464,7 @@ async fn local_daemon_registers_approval_gated_mcp_tools_for_both_start_paths_sc
|
||||
.request_typed(ClientRequest::McpServerStatusList {
|
||||
request_id: AppServerRequestId::String("tui-tool-inventory".to_string()),
|
||||
params: codex_app_server_protocol::ListMcpServerStatusParams {
|
||||
connector_id: None,
|
||||
environment_id: None,
|
||||
server_name: None,
|
||||
cursor: None,
|
||||
|
||||
@@ -108,6 +108,7 @@ pub(super) fn global_pages(
|
||||
let page = read_page(
|
||||
client,
|
||||
ListMcpServerStatusParams {
|
||||
connector_id: None,
|
||||
thread_id: None,
|
||||
server_name: None,
|
||||
environment_id: None,
|
||||
@@ -149,6 +150,7 @@ pub(super) async fn server(
|
||||
let mut page = read_page(
|
||||
client,
|
||||
ListMcpServerStatusParams {
|
||||
connector_id: None,
|
||||
thread_id: thread.map(|id| id.to_string()),
|
||||
server_name: Some(name.0.clone()),
|
||||
environment_id: None,
|
||||
|
||||
@@ -136,9 +136,11 @@ async fn global_pages_preserve_catalogs_and_skip_hosted_or_unidentified_transpor
|
||||
reply(
|
||||
&mut commands,
|
||||
"mcpServerStatus/list",
|
||||
json!({"threadId":null,"serverName":null,"environmentId":null,"detail":"toolsAndAuthOnly","cursor":cursor,"limit":null}),
|
||||
json!({"threadId":null,"serverName":null,"connectorId":null,"environmentId":null,
|
||||
"detail":"toolsAndAuthOnly","cursor":cursor,"limit":null}),
|
||||
json!({"data":rows,"nextCursor":next}),
|
||||
).await;
|
||||
)
|
||||
.await;
|
||||
}
|
||||
};
|
||||
let (servers, ()) = tokio::join!(global_pages(&client).try_concat(), host);
|
||||
@@ -177,7 +179,8 @@ async fn targeted_inventory_rejects_another_server() {
|
||||
reply(
|
||||
&mut commands,
|
||||
"mcpServerStatus/list",
|
||||
json!({"threadId":null,"serverName":"calendar","environmentId":null,"detail":"toolsAndAuthOnly","cursor":null,"limit":null}),
|
||||
json!({"threadId":null,"serverName":"calendar","connectorId":null,"environmentId":null,
|
||||
"detail":"toolsAndAuthOnly","cursor":null,"limit":null}),
|
||||
json!({"data":[other],"nextCursor":null}),
|
||||
)
|
||||
);
|
||||
|
||||
@@ -75,7 +75,7 @@ async fn named(commands: &mut Requests, thread: Option<ThreadId>, row: Value) {
|
||||
commands,
|
||||
"mcpServerStatus/list",
|
||||
json!({"threadId":thread.map(|id| id.to_string()),"serverName":row["name"],
|
||||
"environmentId":null,"detail":"toolsAndAuthOnly","cursor":null,"limit":null}),
|
||||
"connectorId":null,"environmentId":null,"detail":"toolsAndAuthOnly","cursor":null,"limit":null}),
|
||||
json!({"data":[row],"nextCursor":null}),
|
||||
)
|
||||
.await;
|
||||
|
||||
@@ -9587,6 +9587,13 @@ class ListMcpServerStatusParams(BaseModel):
|
||||
model_config = ConfigDict(
|
||||
populate_by_name=True,
|
||||
)
|
||||
connector_id: Annotated[
|
||||
str | None,
|
||||
Field(
|
||||
alias="connectorId",
|
||||
description="Return only tools whose `_meta.connector_id` or `_meta.connectorId` equals this ID. Selected servers with no matching tools still appear on the page.",
|
||||
),
|
||||
] = None
|
||||
cursor: Annotated[
|
||||
str | None, Field(description="Opaque pagination cursor returned by a previous call.")
|
||||
] = None
|
||||
|
||||
Reference in New Issue
Block a user