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

Method call_tool

core/src/mcp/client.rs:154–184  ·  view source on GitHub ↗

Call a tool

(
        &self,
        name: &str,
        arguments: Option<serde_json::Value>,
    )

Source from the content-addressed store, hash-verified

152
153 /// Call a tool
154 pub async fn call_tool(
155 &self,
156 name: &str,
157 arguments: Option<serde_json::Value>,
158 ) -> Result<CallToolResult> {
159 let params = CallToolParams {
160 name: name.to_string(),
161 arguments,
162 };
163
164 let request = JsonRpcRequest::new(
165 self.next_id(),
166 "tools/call",
167 Some(serde_json::to_value(&params)?),
168 );
169
170 let response = self.transport.request(request).await?;
171
172 if let Some(error) = response.error {
173 return Err(anyhow!(
174 "MCP call_tool error: {} ({})",
175 error.message,
176 error.code
177 ));
178 }
179
180 let result: CallToolResult =
181 serde_json::from_value(response.result.ok_or_else(|| anyhow!("No result"))?)?;
182
183 Ok(result)
184 }
185
186 /// List available resources
187 pub async fn list_resources(&self) -> Result<Vec<McpResource>> {

Callers 1

executeMethod · 0.45

Calls 2

next_idMethod · 0.45
requestMethod · 0.45

Tested by

no test coverage detected