наблюдаемость: измерять бюджет каталога MCP
This commit is contained in:
1 parent
0241d186ea
commit
63f8ee333f
10 files changed
+284
-4
No files matched your search
@@ -1,4 +1,7 @@
|
||||
use crank_core::{HttpMethod, OperationSafetyClass, OperationSafetyPolicy, Target};
|
||||
use crank_core::{
|
||||
HttpMethod, OperationSafetyClass, OperationSafetyPolicy, Target, ToolCatalogAnalysis,
|
||||
ToolCatalogAnalysisError, ToolQualityCatalogTool, analyze_tool_catalog,
|
||||
};
|
||||
use crank_registry::PublishedAgentTool;
|
||||
use serde_json::{Value, json};
|
||||
|
||||
@@ -27,6 +30,37 @@ pub fn tool_definitions(tool: &PublishedAgentTool) -> Vec<Value> {
|
||||
)]
|
||||
}
|
||||
|
||||
pub fn analyze_published_tool_catalog(
|
||||
tools: &[PublishedAgentTool],
|
||||
) -> Result<ToolCatalogAnalysis, ToolCatalogAnalysisError> {
|
||||
let mut quality_tools = Vec::new();
|
||||
let mut definitions = Vec::new();
|
||||
|
||||
for tool in tools {
|
||||
for definition in tool_definitions(tool) {
|
||||
quality_tools.push(ToolQualityCatalogTool {
|
||||
name: definition_string(&definition, "name")?,
|
||||
display_name: definition_string(&definition, "title")?,
|
||||
description: definition_string(&definition, "description")?,
|
||||
});
|
||||
definitions.push(definition);
|
||||
}
|
||||
}
|
||||
|
||||
analyze_tool_catalog(&quality_tools, &definitions)
|
||||
}
|
||||
|
||||
fn definition_string(
|
||||
definition: &Value,
|
||||
field: &'static str,
|
||||
) -> Result<String, ToolCatalogAnalysisError> {
|
||||
definition
|
||||
.get(field)
|
||||
.and_then(Value::as_str)
|
||||
.map(ToOwned::to_owned)
|
||||
.ok_or(ToolCatalogAnalysisError::DefinitionFieldMissing(field))
|
||||
}
|
||||
|
||||
pub fn tool_definition(name: &str, title: &str, description: &str, input_schema: Value) -> Value {
|
||||
json!({
|
||||
"name": name,
|
||||
|
||||
Reference in new issue
Block a user