MCPcopy
hub / github.com/lima-vm/lima / ReadFile

Method ReadFile

pkg/mcp/toolset/filesystem.go:49–79  ·  view source on GitHub ↗
(_ context.Context,
	_ *mcp.CallToolRequest, args msi.ReadFileParams,
)

Source from the content-addressed store, hash-verified

47}
48
49func (ts *ToolSet) ReadFile(_ context.Context,
50 _ *mcp.CallToolRequest, args msi.ReadFileParams,
51) (*mcp.CallToolResult, *msi.ReadFileResult, error) {
52 if ts.inst == nil {
53 return nil, nil, errors.New("instance not registered")
54 }
55 guestPath, err := ts.TranslateHostPath(args.Path)
56 if err != nil {
57 return nil, nil, err
58 }
59 f, err := ts.sftp.Open(guestPath)
60 if err != nil {
61 return nil, nil, err
62 }
63 defer f.Close()
64 const limitBytes = 32 * 1024 * 1024
65 lr := io.LimitReader(f, limitBytes)
66 b, err := io.ReadAll(lr)
67 if err != nil {
68 return nil, nil, err
69 }
70 res := &msi.ReadFileResult{
71 Content: string(b),
72 }
73 return &mcp.CallToolResult{
74 // Gemini:
75 // For text files: The file content, potentially prefixed with a truncation message
76 // (e.g., [File content truncated: showing lines 1-100 of 500 total lines...]\nActual file content...).
77 StructuredContent: res,
78 }, res, nil
79}
80
81func (ts *ToolSet) WriteFile(_ context.Context,
82 _ *mcp.CallToolRequest, args msi.WriteFileParams,

Callers 15

ReadFunction · 0.80
VerifySudoAccessMethod · 0.80
loadCacheFunction · 0.80
TestDownloadCompressedFunction · 0.80
readFileFunction · 0.80
readTimeFunction · 0.80
validateCachedDigestFunction · 0.80
fileWarningFunction · 0.80
OpenEditorFunction · 0.80
TestDefaultYAMLFunction · 0.80
validateParamIsUsedFunction · 0.80
loadFunction · 0.80

Calls 2

TranslateHostPathMethod · 0.95
CloseMethod · 0.45

Tested by 5

TestDownloadCompressedFunction · 0.64
TestDefaultYAMLFunction · 0.64
assertFileEqualsFunction · 0.64
sha256FileFunction · 0.64
TestWithDirLockFunction · 0.64