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

Method read_resource

core/src/mcp/client.rs:212–237  ·  view source on GitHub ↗

Read a resource

(&self, uri: &str)

Source from the content-addressed store, hash-verified

210
211 /// Read a resource
212 pub async fn read_resource(&self, uri: &str) -> Result<ReadResourceResult> {
213 let params = ReadResourceParams {
214 uri: uri.to_string(),
215 };
216
217 let request = JsonRpcRequest::new(
218 self.next_id(),
219 "resources/read",
220 Some(serde_json::to_value(&params)?),
221 );
222
223 let response = self.transport.request(request).await?;
224
225 if let Some(error) = response.error {
226 return Err(anyhow!(
227 "MCP read_resource error: {} ({})",
228 error.message,
229 error.code
230 ));
231 }
232
233 let result: ReadResourceResult =
234 serde_json::from_value(response.result.ok_or_else(|| anyhow!("No result"))?)?;
235
236 Ok(result)
237 }
238
239 /// Get notification receiver
240 pub fn notifications(&self) -> tokio::sync::mpsc::Receiver<McpNotification> {

Callers

nothing calls this directly

Calls 2

next_idMethod · 0.45
requestMethod · 0.45

Tested by

no test coverage detected