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

Function flat_params_to_def

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

Convert flat runtime params back to YAML. MCP gets readable nested params when the flat keys can be losslessly split. Non-MCP protocols keep flat keys only for lossless serialization; generic JSON-RPC validation rejects params matchers before enforcement.

(
    protocol: &str,
    params: BTreeMap<String, QueryMatcherDef>,
)

Source from the content-addressed store, hash-verified

423// only for lossless serialization; generic JSON-RPC validation rejects params
424// matchers before enforcement.
425fn flat_params_to_def(
426 protocol: &str,
427 params: BTreeMap<String, QueryMatcherDef>,
428) -> BTreeMap<String, ParamMatcherDef> {
429 let flat = params.into_iter().collect::<Vec<_>>();
430 // MCP uses nested YAML for readability. Non-MCP protocols keep the flat
431 // form for lossless serialization of existing proto data only.
432 if !is_mcp_protocol(protocol) {
433 return flat_param_matchers_to_def(flat);
434 }
435
436 let mut nested = BTreeMap::new();
437 for (key, matcher) in &flat {
438 if insert_nested_param(&mut nested, key, ParamMatcherDef::Matcher(matcher.clone())).is_err()
439 {
440 return flat_param_matchers_to_def(flat);
441 }
442 }
443 nested
444}
445
446fn flat_param_matchers_to_def(
447 params: Vec<(String, QueryMatcherDef)>,

Callers 2

allow_proto_to_defFunction · 0.85
deny_proto_to_defFunction · 0.85

Calls 3

is_mcp_protocolFunction · 0.85
insert_nested_paramFunction · 0.85

Tested by

no test coverage detected