MCPcopy Index your code
hub / github.com/coder/mux / createFileReadTool

Function createFileReadTool

src/node/services/tools/file_read.ts:15–186  ·  view source on GitHub ↗
(config: ToolConfiguration)

Source from the content-addressed store, hash-verified

13 * @param config Required configuration including working directory
14 */
15export const createFileReadTool: ToolFactory = (config: ToolConfiguration) => {
16 return tool({
17 description: TOOL_DEFINITIONS.file_read.description,
18 inputSchema: TOOL_DEFINITIONS.file_read.schema,
19 execute: async (
20 { path, offset, limit },
21 { abortSignal: _abortSignal }
22 ): Promise<FileReadToolResult> => {
23 // Note: abortSignal available but not used - file reads are fast and complete quickly
24
25 let filePath = path;
26 try {
27 const {
28 correctedPath: validatedPath,
29 warning: pathWarning,
30 resolvedPath,
31 } = resolvePathWithinCwd(filePath, config.cwd, config.runtime);
32 filePath = validatedPath;
33
34 // Check if file exists using runtime
35 let fileStat;
36 try {
37 fileStat = await config.runtime.stat(resolvedPath);
38 } catch (err) {
39 if (err instanceof RuntimeError) {
40 return {
41 success: false,
42 error: err.message,
43 };
44 }
45 throw err;
46 }
47
48 if (fileStat.isDirectory) {
49 return {
50 success: false,
51 error: `Path is a directory, not a file: ${resolvedPath}`,
52 };
53 }
54
55 // Validate file size
56 const sizeValidation = validateFileSize(fileStat);
57 if (sizeValidation) {
58 return {
59 success: false,
60 error: sizeValidation.error,
61 };
62 }
63
64 // Read full file content using runtime helper
65 let fullContent: string;
66 try {
67 fullContent = await readFileString(config.runtime, resolvedPath);
68 } catch (err) {
69 if (err instanceof RuntimeError) {
70 return {
71 success: false,
72 error: err.message,

Callers 5

getToolsForModelFunction · 0.90
createTestFileReadToolFunction · 0.90
file_read.test.tsFile · 0.90

Calls 7

resolvePathWithinCwdFunction · 0.90
validateFileSizeFunction · 0.90
readFileStringFunction · 0.90
getErrorMessageFunction · 0.90
statMethod · 0.65
pushMethod · 0.65
toolFunction · 0.50

Tested by 2

createTestFileReadToolFunction · 0.72