MCPcopy Create free account
hub / github.com/Louisym/MiniCC / execute_read_file

Function execute_read_file

tutorials/03_tool_system.py:161–180  ·  view source on GitHub ↗

读取文件内容(简化版)。 对应源码: rust/crates/runtime/src/file_ops.rs

(params: dict)

Source from the content-addressed store, hash-verified

159
160
161def execute_read_file(params: dict) -> str:
162 """
163 读取文件内容(简化版)。
164 对应源码: rust/crates/runtime/src/file_ops.rs
165 """
166 path = params["path"]
167 offset = params.get("offset", 0)
168 limit = params.get("limit", 100)
169
170 try:
171 with open(path, "r", encoding="utf-8") as f:
172 lines = f.readlines()
173 selected = lines[offset:offset + limit]
174 # 加上行号(和 cat -n 类似)
175 numbered = [f"{i + offset + 1}\t{line}" for i, line in enumerate(selected)]
176 return "".join(numbered)
177 except FileNotFoundError:
178 return f"[error] 文件不存在: {path}"
179 except Exception as e:
180 return f"[error] {e}"
181
182
183def execute_write_file(params: dict) -> str:

Callers

nothing calls this directly

Calls 1

getMethod · 0.45

Tested by

no test coverage detected