Download codex-rs/protocol/src/mcp_policy.rs from SaylorTwift/codex: direct link, hf CLI and curl.
- Browser
- Download file 2.98 kB
-
https://huggingface.co/SaylorTwift/codex/resolve/main/codex-rs/protocol/src/mcp_policy.rs
- Command line
-
hf download hf://SaylorTwift/codex/codex-rs/protocol/src/mcp_policy.rs
-
curl -L -o mcp_policy.rs https://huggingface.co/SaylorTwift/codex/resolve/main/codex-rs/protocol/src/mcp_policy.rs
2.98 kB
| use serde::Deserialize; | |
| use std::collections::BTreeMap; | |
| /// Additional managed MCP restrictions supplied by an environment owner. | |
| pub struct EnvironmentMcpPolicy { | |
| pub servers: Option<BTreeMap<String, McpServerRequirement>>, | |
| pub plugins: Option<BTreeMap<String, PluginMcpRequirements>>, | |
| } | |
| pub enum McpServerIdentity { | |
| Command { command: String }, | |
| Url { url: String }, | |
| } | |
| /// String matching operations available to managed MCP server matchers. | |
| pub enum McpServerValueMatcher { | |
| Exact { value: String }, | |
| Prefix { value: String }, | |
| Regex { expression: String }, | |
| } | |
| pub struct McpServerCommandMatcher { | |
| pub executable: String, | |
| pub args: Vec<McpServerValueMatcher>, | |
| } | |
| struct RawMcpServerCommandIdentity { | |
| command: McpServerCommandMatcher, | |
| } | |
| struct RawMcpServerUrlIdentity { | |
| url: McpServerValueMatcher, | |
| } | |
| /// A requirement for one named MCP server. | |
| /// | |
| /// The `Identity` variant preserves the released exact-match contract. The | |
| /// command and URL variants are the normalized matcher-based forms accepted | |
| /// under the `identity` key. | |
| pub enum McpServerRequirement { | |
| Identity { identity: McpServerIdentity }, | |
| Command(McpServerCommandMatcher), | |
| Url(McpServerValueMatcher), | |
| } | |
| struct RawMcpServerRequirement { | |
| identity: RawMcpServerIdentity, | |
| } | |
| enum RawMcpServerIdentity { | |
| Exact(McpServerIdentity), | |
| Command(RawMcpServerCommandIdentity), | |
| Url(RawMcpServerUrlIdentity), | |
| } | |
| impl<'de> Deserialize<'de> for McpServerRequirement { | |
| fn deserialize<D>(deserializer: D) -> Result<Self, D::Error> | |
| where | |
| D: serde::Deserializer<'de>, | |
| { | |
| let RawMcpServerRequirement { identity } = | |
| RawMcpServerRequirement::deserialize(deserializer)?; | |
| match identity { | |
| RawMcpServerIdentity::Exact(identity) => Ok(Self::Identity { identity }), | |
| RawMcpServerIdentity::Command(matcher) => Ok(Self::Command(matcher.command)), | |
| RawMcpServerIdentity::Url(matcher) => Ok(Self::Url(matcher.url)), | |
| } | |
| } | |
| } | |
| /// Managed MCP server requirements for one plugin. | |
| pub struct PluginMcpRequirements { | |
| pub mcp_servers: Option<BTreeMap<String, McpServerRequirement>>, | |
| } | |
| impl PluginMcpRequirements { | |
| pub fn is_empty(&self) -> bool { | |
| self.mcp_servers.as_ref().is_none_or(BTreeMap::is_empty) | |
| } | |
| } | |