mirror of
https://github.com/pchuan98/codex.git
synced 2026-07-01 00:31:56 +08:00
[codex] Support ui visibility meta for tools (#24700)
## Summary Adds support for the same ui.visibility metadata as resources [spec](https://github.com/modelcontextprotocol/ext-apps/blob/main/specification/draft/apps.mdx#resource-discovery)
This commit is contained in:
committed by
GitHub
Unverified
parent
2264fdd4a2
commit
577ec03bf8
@@ -64,6 +64,7 @@ use rmcp::model::ReadResourceResult;
|
||||
use rmcp::model::RequestId;
|
||||
use rmcp::model::Resource;
|
||||
use rmcp::model::ResourceTemplate;
|
||||
use serde_json::Value as JsonValue;
|
||||
use tokio::task::JoinSet;
|
||||
use tokio_util::sync::CancellationToken;
|
||||
use tracing::Instrument;
|
||||
@@ -72,6 +73,34 @@ use tracing::trace;
|
||||
use tracing::trace_span;
|
||||
use tracing::warn;
|
||||
|
||||
const MCP_UI_META_KEY: &str = "ui";
|
||||
const MCP_UI_VISIBILITY_META_KEY: &str = "visibility";
|
||||
const MCP_UI_MODEL_VISIBILITY: &str = "model";
|
||||
|
||||
/// Returns whether a tool may be included in model-facing tool declarations.
|
||||
///
|
||||
/// Tools without visibility metadata remain visible.
|
||||
/// Tools with visibility metadata are hidden unless they explicitly include `model`.
|
||||
///
|
||||
/// <https://github.com/modelcontextprotocol/ext-apps/blob/main/specification/2026-01-26/apps.mdx#resource-discovery>
|
||||
pub fn tool_is_model_visible(tool: &ToolInfo) -> bool {
|
||||
let Some(visibility) = tool
|
||||
.tool
|
||||
.meta
|
||||
.as_deref()
|
||||
.and_then(|meta| meta.get(MCP_UI_META_KEY))
|
||||
.and_then(JsonValue::as_object)
|
||||
.and_then(|ui| ui.get(MCP_UI_VISIBILITY_META_KEY))
|
||||
.and_then(JsonValue::as_array)
|
||||
else {
|
||||
return true;
|
||||
};
|
||||
|
||||
visibility
|
||||
.iter()
|
||||
.any(|target| target.as_str() == Some(MCP_UI_MODEL_VISIBILITY))
|
||||
}
|
||||
|
||||
/// A thin wrapper around a set of running [`RmcpClient`] instances.
|
||||
pub struct McpConnectionManager {
|
||||
clients: HashMap<String, AsyncManagedClient>,
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
pub use connection_manager::McpConnectionManager;
|
||||
pub use connection_manager::tool_is_model_visible;
|
||||
pub use elicitation::ElicitationReviewRequest;
|
||||
pub use elicitation::ElicitationReviewer;
|
||||
pub use elicitation::ElicitationReviewerHandle;
|
||||
|
||||
Reference in New Issue
Block a user