MCPcopy Index your code
hub / github.com/ChrisFeldmeier/OpenCodeRust / add_mcp_resource_part

Method add_mcp_resource_part

crates/opencode-session/src/prompt.rs:300–375  ·  view source on GitHub ↗
(
        &self,
        msg: &mut SessionMessage,
        raw_url: &str,
        filename: &str,
        mime: &str,
    )

Source from the content-addressed store, hash-verified

298 }
299
300 async fn add_mcp_resource_part(
301 &self,
302 msg: &mut SessionMessage,
303 raw_url: &str,
304 filename: &str,
305 mime: &str,
306 ) {
307 let Some((client_name, uri)) = Self::parse_mcp_resource_url(raw_url) else {
308 msg.add_text(format!("Failed to parse MCP resource URL: {}", raw_url));
309 msg.add_file(raw_url.to_string(), filename.to_string(), mime.to_string());
310 return;
311 };
312
313 msg.add_text(format!("Reading MCP resource: {} ({})", filename, uri));
314
315 let Some(registry) = &self.mcp_clients else {
316 msg.add_text(
317 "MCP client registry is not configured; unable to read resource content."
318 .to_string(),
319 );
320 msg.add_file(raw_url.to_string(), filename.to_string(), mime.to_string());
321 return;
322 };
323
324 let Some(client) = registry.get(&client_name).await else {
325 msg.add_text(format!("MCP client `{}` is not connected.", client_name));
326 msg.add_file(raw_url.to_string(), filename.to_string(), mime.to_string());
327 return;
328 };
329
330 match client.read_resource(&uri).await {
331 Ok(result) => {
332 let mut text_chunks = Vec::new();
333 let mut binary_chunks = Vec::new();
334 for content in result.contents {
335 if let Some(text) = content.text {
336 if !text.trim().is_empty() {
337 text_chunks.push(text);
338 }
339 continue;
340 }
341
342 if content.blob.is_some() {
343 binary_chunks.push(
344 content
345 .mime_type
346 .clone()
347 .unwrap_or_else(|| mime.to_string()),
348 );
349 }
350 }
351
352 if !text_chunks.is_empty() {
353 msg.add_text(SystemPrompt::mcp_resource_reminder(
354 filename,
355 &uri,
356 &text_chunks.join("\n\n"),
357 ));

Callers 1

add_file_partMethod · 0.80

Calls 7

newFunction · 0.85
add_textMethod · 0.80
add_fileMethod · 0.80
read_resourceMethod · 0.80
is_emptyMethod · 0.80
getMethod · 0.45
cloneMethod · 0.45

Tested by

no test coverage detected