MCPcopy Create free account
hub / github.com/NVIDIA/OpenShell / l7_config_alias_runtime_fields

Function l7_config_alias_runtime_fields

crates/openshell-policy/src/lib.rs:226–266  ·  view source on GitHub ↗

Parse an L7 nested config stanza and return the flattened runtime fields consumed by the supervisor policy engine. The stanza schema stays tied to this crate's canonical serde definitions, so adding a new supported field requires updating this conversion next to the type that parses it.

(
    stanza: L7ConfigStanza,
    value: serde_json::Value,
)

Source from the content-addressed store, hash-verified

224/// adding a new supported field requires updating this conversion next to the
225/// type that parses it.
226pub fn l7_config_alias_runtime_fields(
227 stanza: L7ConfigStanza,
228 value: serde_json::Value,
229) -> Result<Vec<(&'static str, serde_json::Value)>> {
230 match stanza {
231 L7ConfigStanza::JsonRpc => {
232 let JsonRpcConfigDef { max_body_bytes } = serde_json::from_value(value)
233 .map_err(|error| miette::miette!("invalid json_rpc config: {error}"))?;
234 let mut fields = Vec::new();
235 if max_body_bytes > 0 {
236 fields.push(("json_rpc_max_body_bytes", serde_json::json!(max_body_bytes)));
237 }
238 Ok(fields)
239 }
240 L7ConfigStanza::Mcp => {
241 let McpConfigDef {
242 max_body_bytes,
243 strict_tool_names,
244 allow_all_known_mcp_methods,
245 } = serde_json::from_value(value)
246 .map_err(|error| miette::miette!("invalid mcp config: {error}"))?;
247 let mut fields = Vec::new();
248 if max_body_bytes > 0 {
249 fields.push(("json_rpc_max_body_bytes", serde_json::json!(max_body_bytes)));
250 }
251 if let Some(strict_tool_names) = strict_tool_names {
252 fields.push((
253 "mcp_strict_tool_names",
254 serde_json::json!(strict_tool_names),
255 ));
256 }
257 if let Some(allow_all_known_mcp_methods) = allow_all_known_mcp_methods {
258 fields.push((
259 "mcp_allow_all_known_mcp_methods",
260 serde_json::json!(allow_all_known_mcp_methods),
261 ));
262 }
263 Ok(fields)
264 }
265 }
266}
267
268#[derive(Debug, Serialize, Deserialize)]
269#[serde(deny_unknown_fields)]

Calls 1

pushMethod · 0.80