MCPcopy Create free account
hub / github.com/NVIDIA/NeMo-Relay / validate_unique_component_kinds

Function validate_unique_component_kinds

crates/core/src/plugin.rs:1137–1160  ·  view source on GitHub ↗

Rejects a single file that declares the same component `kind` more than once.

(path: &Path, document: &Json)

Source from the content-addressed store, hash-verified

1135
1136/// Rejects a single file that declares the same component `kind` more than once.
1137fn validate_unique_component_kinds(path: &Path, document: &Json) -> Result<()> {
1138 let Some(components) = document.get("components").and_then(Json::as_array) else {
1139 return Ok(());
1140 };
1141 let mut seen = HashSet::new();
1142 let mut duplicates = Vec::new();
1143 for component in components {
1144 if let Some(kind) = component_kind(component)
1145 && !seen.insert(kind)
1146 {
1147 duplicates.push(kind.to_string());
1148 }
1149 }
1150 if duplicates.is_empty() {
1151 return Ok(());
1152 }
1153 duplicates.sort();
1154 duplicates.dedup();
1155 Err(PluginError::InvalidConfig(format!(
1156 "duplicate plugin component kind in {}: {}; declare each kind once per plugins.toml",
1157 path.display(),
1158 duplicates.join(", ")
1159 )))
1160}
1161
1162/// Default `plugins.toml` search path (lowest precedence first): system, nearest
1163/// project file, then user file — mirroring the gateway's discovery. `pub` only

Callers 1

load_plugin_config_filesFunction · 0.85

Calls 4

component_kindFunction · 0.85
getMethod · 0.80
pushMethod · 0.45
is_emptyMethod · 0.45

Tested by

no test coverage detected