Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
lima-vm
GitHub Repository: lima-vm/lima
Path: blob/master/pkg/mcp/msi/filesystem.go
2614 views
1
// SPDX-FileCopyrightText: Copyright The Lima Authors
2
// SPDX-License-Identifier: Apache-2.0
3
4
// Portion of AI prompt texts from:
5
// - https://github.com/google-gemini/gemini-cli/blob/v0.1.12/docs/tools/file-system.md
6
//
7
// SPDX-FileCopyrightText: Copyright 2025 Google LLC
8
9
package msi
10
11
import (
12
"io/fs"
13
"time"
14
15
"github.com/modelcontextprotocol/go-sdk/mcp"
16
)
17
18
var ListDirectory = &mcp.Tool{
19
Name: "list_directory",
20
Description: `Lists the names of files and subdirectories directly within a specified directory path.`,
21
}
22
23
type ListDirectoryParams struct {
24
Path string `json:"path" jsonschema:"The absolute path to the directory to list."`
25
}
26
27
// ListDirectoryResultEntry is similar to [io/fs.FileInfo].
28
type ListDirectoryResultEntry struct {
29
Name string `json:"name" jsonschema:"base name of the file"`
30
Size *int64 `json:"size,omitempty" jsonschema:"length in bytes for regular files; system-dependent for others"`
31
Mode *fs.FileMode `json:"mode,omitempty" jsonschema:"file mode bits"`
32
ModTime *time.Time `json:"time,omitempty" jsonschema:"modification time"`
33
IsDir *bool `json:"is_dir,omitempty" jsonschema:"true for a directory"`
34
}
35
36
type ListDirectoryResult struct {
37
Entries []ListDirectoryResultEntry `json:"entries" jsonschema:"The directory content entries."`
38
}
39
40
var ReadFile = &mcp.Tool{
41
Name: "read_file",
42
Description: `Reads and returns the content of a specified file.`,
43
}
44
45
type ReadFileResult struct {
46
Content string `json:"content" jsonschema:"The content of the file."`
47
}
48
49
type ReadFileParams struct {
50
Path string `json:"path" jsonschema:"The absolute path to the file to read."`
51
// TODO: Offset *int `json:"offset,omitempty" jsonschema:"For text files, the 0-based line number to start reading from. Requires limit to be set."`
52
// TODO: Limit *int `json:"limit,omitempty" jsonschema:"For text files, the maximum number of lines to read. If omitted, reads a default maximum (e.g., 2000 lines) or the entire file if feasible."`
53
}
54
55
var WriteFile = &mcp.Tool{
56
Name: "write_file",
57
Description: `Writes content to a specified file. If the file exists, it will be overwritten. If the file doesn't exist, it (and any necessary parent directories) will be created.`,
58
}
59
60
type WriteFileResult struct {
61
// Empty for now
62
}
63
64
type WriteFileParams struct {
65
Path string `json:"path" jsonschema:"The absolute path to the file to write to."`
66
Content string `json:"content" jsonschema:"The content to write into the file."`
67
}
68
69
var Glob = &mcp.Tool{
70
Name: "glob",
71
Description: `Finds files matching specific glob patterns (e.g., src/**/*.ts, *.md)`, // Not sorted by mod time, unlike Gemini
72
}
73
74
type GlobParams struct {
75
Pattern string `json:"pattern" jsonschema:"The glob pattern to match against (e.g., '*.py', 'src/**/*.js')."`
76
Path *string `json:"path,omitempty" jsonschema:"The absolute path to the directory to search within. If omitted, searches the tool's root directory."`
77
// TODO: CaseSensitive bool `json:"case_sensitive,omitempty" jsonschema:": Whether the search should be case-sensitive. Defaults to false."`
78
}
79
80
type GlobResult struct {
81
Matches []string `json:"matches" jsonschema:"A list of absolute file paths that match the provided glob pattern."`
82
}
83
84
var SearchFileContent = &mcp.Tool{
85
Name: "search_file_content",
86
Description: `Searches for a regular expression pattern within the content of files in a specified directory. Internally calls 'git grep -n --no-index'.`,
87
}
88
89
type SearchFileContentParams struct {
90
Pattern string `json:"pattern" jsonschema:"The regular expression (regex) to search for (e.g., 'function\\s+myFunction')."`
91
Path *string `json:"path,omitempty" jsonschema:"The absolute path to the directory to search within. Defaults to the current working directory."`
92
Include *string `json:"include,omitempty" jsonschema:"A glob pattern to filter which files are searched (e.g., '*.js', 'src/**/*.{ts,tsx}'). If omitted, searches most files (respecting common ignores)."`
93
}
94
95
type SearchFileContentResult struct {
96
GitGrepOutput string `json:"git_grep_output" jsonschema:"The raw output from the 'git grep -n --no-index' command, containing matching lines with filenames and line numbers."`
97
}
98
99
// TODO: implement Replace
100
101