MCPcopy Create free account
hub / github.com/AI45Lab/Code / execute

Method execute

core/src/tools/builtin/generate_object.rs:82–194  ·  view source on GitHub ↗
(&self, args: &Value, ctx: &ToolContext)

Source from the content-addressed store, hash-verified

80 }
81
82 async fn execute(&self, args: &Value, ctx: &ToolContext) -> Result<ToolOutput> {
83 let schema = match args.get("schema") {
84 Some(s) if s.is_object() => s.clone(),
85 Some(_) => {
86 return Ok(ToolOutput::error(
87 "'schema' must be a JSON object (a valid JSON Schema)",
88 ));
89 }
90 None => {
91 return Ok(ToolOutput::error("'schema' parameter is required"));
92 }
93 };
94
95 let prompt = match args.get("prompt").and_then(|v| v.as_str()) {
96 Some(p) if !p.is_empty() => p.to_string(),
97 _ => {
98 return Ok(ToolOutput::error(
99 "'prompt' parameter is required and must be non-empty",
100 ));
101 }
102 };
103
104 // Validate schema has at minimum a "type" or "properties" or "anyOf" field
105 if schema.get("type").is_none()
106 && schema.get("properties").is_none()
107 && schema.get("anyOf").is_none()
108 && schema.get("oneOf").is_none()
109 && schema.get("enum").is_none()
110 {
111 return Ok(ToolOutput::error(
112 "'schema' should contain at least one of: type, properties, anyOf, oneOf, or enum",
113 ));
114 }
115
116 let schema_name: String = args
117 .get("schema_name")
118 .and_then(|v| v.as_str())
119 .unwrap_or("result")
120 .chars()
121 .filter(|c| c.is_alphanumeric() || *c == '_' || *c == '-')
122 .take(64)
123 .collect();
124 let schema_name = if schema_name.is_empty() {
125 "result".to_string()
126 } else {
127 schema_name
128 };
129
130 let schema_description = args
131 .get("schema_description")
132 .and_then(|v| v.as_str())
133 .map(|s| s.to_string());
134
135 let system = args
136 .get("system")
137 .and_then(|v| v.as_str())
138 .map(|s| s.to_string());
139

Callers

nothing calls this directly

Calls 6

generate_streamingFunction · 0.85
generate_blockingFunction · 0.85
getMethod · 0.45
cloneMethod · 0.45
as_strMethod · 0.45
is_emptyMethod · 0.45

Tested by

no test coverage detected