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
+1 -61
View File
@@ -43,6 +43,7 @@ use crate::{
is_response, jsonrpc_error, jsonrpc_result, method_name, negotiated_protocol_version,
params, request_id,
},
manifest::tool_definitions,
session::{SessionState, SharedSessionStore},
};
@@ -1430,15 +1431,6 @@ where
response
}
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),
)]
}
fn resolve_request_id(headers: &HeaderMap) -> String {
headers
.get(&HEADER_X_REQUEST_ID)
@@ -1457,15 +1449,6 @@ fn is_valid_request_id(value: &str) -> bool {
.all(|byte| matches!(byte, 0x21..=0x7e) && byte != b',' && byte != b';')
}
fn tool_definition(name: &str, title: &str, description: &str, input_schema: Value) -> Value {
json!({
"name": name,
"title": title,
"description": description,
"inputSchema": input_schema
})
}
fn resolve_generated_tool(
tools: &[PublishedAgentTool],
tool_name: &str,
@@ -1487,49 +1470,6 @@ fn runtime_operation(tool: &PublishedAgentTool) -> RuntimeOperation {
operation
}
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<_>>()
}),
}
}
impl AllowedOrigins {
fn new(public_base_url: Option<String>) -> Self {
Self {
+1
View File
@@ -2,6 +2,7 @@ mod app;
pub mod auth;
pub mod catalog;
pub mod jsonrpc;
pub mod manifest;
pub mod session;
pub use app::build_app;
@@ -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<_>>()
}),
}
}