Extract MCP tool manifest builder
Deploy / deploy (push) Successful in 1m30s
CI / Rust Checks (push) Successful in 4m50s
CI / UI Checks (push) Successful in 4s
CI / Deployment Manifests (push) Successful in 2s
CI / Frontend E2E (push) Successful in 4m19s

This commit is contained in:
github-ops
2026-06-20 20:22:03 +00:00
parent 751a832fcb
commit 3ac00a57d0
7 changed files with 221 additions and 61 deletions
@@ -0,0 +1,63 @@
use crank_registry::PublishedAgentTool;
use serde_json::{Value, json};
pub fn tool_definitions(tool: &PublishedAgentTool) -> Vec<Value> {
vec![tool_definition(
&tool.tool_name,
&tool.tool_title,
&tool.tool_description,
schema_to_json_schema(&tool.operation.input_schema),
)]
}
pub fn tool_definition(name: &str, title: &str, description: &str, input_schema: Value) -> Value {
json!({
"name": name,
"title": title,
"description": description,
"inputSchema": input_schema
})
}
pub fn schema_to_json_schema(schema: &crank_schema::Schema) -> Value {
match schema.kind {
crank_schema::SchemaKind::Object => {
let mut properties = serde_json::Map::new();
let mut required = Vec::new();
for (field_name, field_schema) in &schema.fields {
properties.insert(field_name.clone(), schema_to_json_schema(field_schema));
if field_schema.required {
required.push(Value::String(field_name.clone()));
}
}
json!({
"type": "object",
"properties": properties,
"required": required
})
}
crank_schema::SchemaKind::Array => json!({
"type": "array",
"items": schema
.items
.as_deref()
.map(schema_to_json_schema)
.unwrap_or_else(|| json!({}))
}),
crank_schema::SchemaKind::String => json!({ "type": "string" }),
crank_schema::SchemaKind::Integer => json!({ "type": "integer" }),
crank_schema::SchemaKind::Number => json!({ "type": "number" }),
crank_schema::SchemaKind::Boolean => json!({ "type": "boolean" }),
crank_schema::SchemaKind::Enum => json!({
"type": "string",
"enum": schema.enum_values
}),
crank_schema::SchemaKind::Null => json!({ "type": "null" }),
crank_schema::SchemaKind::Oneof => json!({
"anyOf": schema.variants.iter().map(schema_to_json_schema).collect::<Vec<_>>()
}),
}
}