MCPcopy Create free account
hub / github.com/ChrisFeldmeier/OpenCodeRust / execute

Method execute

crates/opencode-tool/src/read.rs:77–198  ·  view source on GitHub ↗
(
        &self,
        args: serde_json::Value,
        ctx: ToolContext,
    )

Source from the content-addressed store, hash-verified

75 }
76
77 async fn execute(
78 &self,
79 args: serde_json::Value,
80 ctx: ToolContext,
81 ) -> Result<ToolResult, ToolError> {
82 let file_path: String = args["file_path"]
83 .as_str()
84 .ok_or_else(|| ToolError::InvalidArguments("file_path is required".into()))?
85 .to_string();
86
87 let offset: usize = args["offset"].as_u64().unwrap_or(1) as usize;
88
89 let limit: usize = args["limit"].as_u64().unwrap_or(DEFAULT_READ_LIMIT as u64) as usize;
90
91 if offset < 1 {
92 return Err(ToolError::InvalidArguments("offset must be >= 1".into()));
93 }
94
95 let base_dir = if ctx.directory.is_empty() {
96 &self.directory
97 } else {
98 Path::new(&ctx.directory)
99 };
100
101 let path = if Path::new(&file_path).is_absolute() {
102 PathBuf::from(&file_path)
103 } else {
104 base_dir.join(&file_path)
105 };
106
107 let path_str = path.to_string_lossy().to_string();
108
109 if ctx.is_external_path(&path_str) {
110 let parent = path
111 .parent()
112 .map(|p| p.to_string_lossy().to_string())
113 .unwrap_or_else(|| path_str.clone());
114
115 ctx.ask_permission(
116 crate::PermissionRequest::new("external_directory")
117 .with_pattern(format!("{}/*", parent))
118 .with_metadata("filepath", serde_json::json!(path_str))
119 .with_metadata("parentDir", serde_json::json!(parent)),
120 )
121 .await?;
122 }
123
124 ctx.ask_permission(
125 crate::PermissionRequest::new("read")
126 .with_pattern(&path_str)
127 .always_allow(),
128 )
129 .await?;
130
131 let title = path
132 .strip_prefix(&ctx.worktree)
133 .unwrap_or(&path)
134 .to_string_lossy()

Callers

nothing calls this directly

Calls 15

newFunction · 0.85
read_directoryFunction · 0.85
detect_mimeFunction · 0.85
is_image_mimeFunction · 0.85
handle_binary_fileFunction · 0.85
is_binaryFunction · 0.85
read_file_contentFunction · 0.85
is_emptyMethod · 0.80
is_external_pathMethod · 0.80
ask_permissionMethod · 0.80
with_metadataMethod · 0.80
with_patternMethod · 0.80

Tested by

no test coverage detected