MCPcopy Create free account
hub / github.com/ScriptedAlchemy/tracedecay / read_resource_files

Method read_resource_files

src/mcp/server.rs:2198–2243  ·  view source on GitHub ↗

Returns the file list as a text resource (grouped by directory).

(&self, id: Value)

Source from the content-addressed store, hash-verified

2196
2197 /// Returns the file list as a text resource (grouped by directory).
2198 async fn read_resource_files(&self, id: Value) -> JsonRpcResponse {
2199 match self.cg_snapshot().await.get_all_files().await {
2200 Ok(mut files) => {
2201 files.sort_by(|a, b| a.path.cmp(&b.path));
2202 let mut groups: std::collections::BTreeMap<String, Vec<String>> =
2203 std::collections::BTreeMap::new();
2204 for f in &files {
2205 let dir = f.path.rfind('/').map_or(".", |i| &f.path[..i]).to_string();
2206 #[allow(clippy::map_unwrap_or)]
2207 let name = f
2208 .path
2209 .rfind('/')
2210 .map(|i| &f.path[i + 1..])
2211 .unwrap_or(&f.path);
2212 groups
2213 .entry(dir)
2214 .or_default()
2215 .push(format!("{} ({} symbols)", name, f.node_count));
2216 }
2217 let mut lines = Vec::new();
2218 lines.push(format!("{} indexed files", files.len()));
2219 for (dir, entries) in &groups {
2220 lines.push(format!("\n{}/ ({} files)", dir, entries.len()));
2221 for entry in entries {
2222 lines.push(format!(" {entry}"));
2223 }
2224 }
2225 let text = lines.join("\n");
2226 JsonRpcResponse::success(
2227 id,
2228 json!({
2229 "contents": [{
2230 "uri": "tracedecay://files",
2231 "mimeType": "text/plain",
2232 "text": text
2233 }]
2234 }),
2235 )
2236 }
2237 Err(e) => JsonRpcResponse::error(
2238 id,
2239 ErrorCode::InternalError,
2240 format!("failed to read file list: {e}"),
2241 ),
2242 }
2243 }
2244
2245 /// Returns a high-level project overview as a text resource.
2246 async fn read_resource_overview(&self, id: Value) -> JsonRpcResponse {

Callers 1

handle_resources_readMethod · 0.80

Calls 6

errorFunction · 0.85
cg_snapshotMethod · 0.80
cmpMethod · 0.80
pushMethod · 0.80
entryMethod · 0.80
get_all_filesMethod · 0.45

Tested by

no test coverage detected