filesystem

package
v1.3.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 4, 2026 License: MIT Imports: 24 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ServerName    = "llm-filesystem"
	ServerVersion = "1.2.0"
)
View Source
const DefaultChunkSize = 1024 * 1024

Default chunk size for auto-chunking (1MB)

View Source
const DefaultListPageSize = 100

DefaultListPageSize is the default page size for auto-chunking directory listings

Variables

This section is empty.

Functions

func CreateBackupPath

func CreateBackupPath(path string) string

CreateBackupPath generates a backup path with timestamp

func CreateListToken

func CreateListToken(path string, nextPage int) (string, error)

CreateListToken creates a token for list_directory pagination

func CreateReadToken

func CreateReadToken(path string, offset int64) (string, error)

CreateReadToken creates a token for read_file chunked reads

func CreateSearchToken

func CreateSearchToken(path string, offset int64) (string, error)

CreateSearchToken creates a token for search result pagination

func EncodeContinuationToken

func EncodeContinuationToken(token *ContinuationToken) (string, error)

EncodeContinuationToken creates a base64-encoded token string

func EnsureDir

func EnsureDir(path string) error

EnsureDir creates directory and parents if needed

func GetBool

func GetBool(args map[string]interface{}, key string, defaultVal bool) bool

GetBool extracts a bool from args map with default value

func GetInt

func GetInt(args map[string]interface{}, key string, defaultVal int) int

GetInt extracts an int from args map with default value

func GetIntSlice

func GetIntSlice(args map[string]interface{}, key string) []int

GetIntSlice extracts an int slice from args map

func GetString

func GetString(args map[string]interface{}, key string, defaultVal string) string

GetString extracts a string from args map with default value

func GetStringSlice

func GetStringSlice(args map[string]interface{}, key string) []string

GetStringSlice extracts a string slice from args map

func IsPathAllowed

func IsPathAllowed(path string, allowedDirs []string) bool

IsPathAllowed checks if a path is within any of the allowed directories

func NormalizePath

func NormalizePath(path string) (string, error)

NormalizePath cleans and normalizes a file path

func ResolvePath

func ResolvePath(path string) (string, error)

ResolvePath expands ~ and cleans path

func ResolveSymlink(path string) (string, error)

ResolveSymlink resolves a symlink to its target path

func ValidatePath

func ValidatePath(path string, allowedDirs []string) error

ValidatePath checks if a path is allowed based on the allowed directories list

func ValidateToken

func ValidateToken(token *ContinuationToken, path, operationType string) error

ValidateToken checks if token is valid for the given path and operation

Types

type BatchOpResult

type BatchOpResult struct {
	Success    int            `json:"success"`
	Failed     int            `json:"failed"`
	Operations []FileOpResult `json:"operations"`
}

BatchOpResult represents the result of batch operations

type CodeMatch

type CodeMatch struct {
	File          string   `json:"file"`
	Line          int      `json:"line"`
	Content       string   `json:"content"`
	Context       []string `json:"context,omitempty"`
	ContextBefore []string `json:"context_before,omitempty"`
	ContextAfter  []string `json:"context_after,omitempty"`
}

CodeMatch represents a single code match

type CompressResult

type CompressResult struct {
	Output     string `json:"output"`
	Format     string `json:"format"`
	Size       int64  `json:"size"`
	FilesAdded int    `json:"files_added"`
	Success    bool   `json:"success"`
}

CompressResult represents compression result

type ContinuationToken

type ContinuationToken struct {
	Version string `json:"v"`    // Token version for compatibility
	Type    string `json:"t"`    // Operation type: "list", "read", "search"
	Page    int    `json:"p"`    // Current page number
	Offset  int64  `json:"o"`    // Byte offset for file reads
	Path    string `json:"path"` // Original path for validation
}

ContinuationToken holds state for resuming paginated operations

func DecodeContinuationToken

func DecodeContinuationToken(tokenStr string) (*ContinuationToken, error)

DecodeContinuationToken parses a base64-encoded token string

type DirectoryEntry

type DirectoryEntry struct {
	Name         string `json:"name"`
	Path         string `json:"path"`
	Type         string `json:"type"` // "file" or "directory"
	IsDir        bool   `json:"is_dir"`
	Size         int64  `json:"size"`
	SizeReadable string `json:"size_readable"`
	Mode         string `json:"mode"`
	Permissions  uint32 `json:"permissions"`
	Modified     string `json:"modified"`
	Created      string `json:"created,omitempty"`
	Accessed     string `json:"accessed,omitempty"`
	Extension    string `json:"extension,omitempty"`
	MimeType     string `json:"mime_type,omitempty"`
	IsReadable   bool   `json:"is_readable"`
	IsWritable   bool   `json:"is_writable"`
}

DirectoryEntry represents a file or directory entry

type DirectoryTreeResult

type DirectoryTreeResult struct {
	Tree       *TreeNode `json:"tree"` // renamed from "root" for fast-filesystem parity
	TotalDirs  int       `json:"total_dirs"`
	TotalFiles int       `json:"total_files"`
	TotalSize  int64     `json:"total_size"`
}

DirectoryTreeResult represents the result of a directory tree operation

type DiskUsageResult

type DiskUsageResult struct {
	Path       string `json:"path"`
	TotalSize  int64  `json:"total_size"`
	TotalFiles int    `json:"total_files"`
	TotalDirs  int    `json:"total_dirs"`
}

DiskUsageResult represents disk usage information

type EditResult

type EditResult struct {
	Path       string `json:"path"`
	Success    bool   `json:"success"`
	Changes    int    `json:"changes"`
	Backup     string `json:"backup,omitempty"`
	Message    string `json:"message"`
	OldContent string `json:"old_content,omitempty"`
	NewContent string `json:"new_content,omitempty"`
}

EditResult represents the result of an edit operation

type ExtractResult

type ExtractResult struct {
	Archive        string `json:"archive"`
	Destination    string `json:"destination"`
	FilesExtracted int    `json:"files_extracted"`
	Success        bool   `json:"success"`
}

ExtractResult represents extraction result

type FileOpResult

type FileOpResult struct {
	Path        string `json:"path"`
	Source      string `json:"source,omitempty"`
	Destination string `json:"destination,omitempty"`
	Success     bool   `json:"success"`
	Operation   string `json:"operation"`
	Message     string `json:"message"`
}

FileOpResult represents the result of a file operation

type FileSearchResult

type FileSearchResult struct {
	Path    string `json:"path"`
	Name    string `json:"name"`
	Size    int64  `json:"size"`
	IsDir   bool   `json:"is_dir"`
	ModTime string `json:"mod_time"`
}

FileSearchResult represents a found file

type LargeFileInfo

type LargeFileInfo struct {
	Path    string `json:"path"`
	Size    int64  `json:"size"`
	ModTime string `json:"mod_time"`
}

LargeFileInfo represents a large file found

type LargeFilesResult

type LargeFilesResult struct {
	Path       string          `json:"path"`
	MinSize    int64           `json:"min_size"`
	Files      []LargeFileInfo `json:"files"`
	Total      int             `json:"total"`
	TotalCount int             `json:"total_count"`
	TotalSize  int64           `json:"total_size"`
}

LargeFilesResult represents find large files result

type ListDirectoryResult

type ListDirectoryResult struct {
	Path              string           `json:"path"`
	Items             []DirectoryEntry `json:"items"` // renamed from "entries" for fast-filesystem parity
	Total             int              `json:"total"`
	Page              int              `json:"page,omitempty"`
	PageSize          int              `json:"page_size,omitempty"`
	TotalPages        int              `json:"total_pages,omitempty"`
	ContinuationToken string           `json:"continuation_token,omitempty"`
	HasMore           bool             `json:"has_more,omitempty"`
	AutoChunked       bool             `json:"auto_chunked,omitempty"`
}

ListDirectoryResult represents the result of a directory listing

type ReadFileResult

type ReadFileResult struct {
	Path              string `json:"path"`
	Content           string `json:"content"`
	Size              int64  `json:"size"`
	Encoding          string `json:"encoding"`
	TotalSize         int64  `json:"total_size,omitempty"`
	Lines             int    `json:"lines,omitempty"`
	Truncated         bool   `json:"truncated,omitempty"`
	AutoChunked       bool   `json:"auto_chunked,omitempty"`
	ChunkIndex        int    `json:"chunk_index,omitempty"`
	TotalChunks       int    `json:"total_chunks,omitempty"`
	ContinuationToken string `json:"continuation_token,omitempty"`
	HasMore           bool   `json:"has_more,omitempty"`
	Error             string `json:"error,omitempty"`
}

ReadFileResult represents the result of a file read operation

type ReadMultipleFilesResult

type ReadMultipleFilesResult struct {
	Files   []ReadFileResult `json:"files"`
	Success int              `json:"success"`
	Failed  int              `json:"failed"`
}

ReadMultipleFilesResult represents results from reading multiple files

type SearchCodeResult

type SearchCodeResult struct {
	Pattern      string      `json:"pattern"`
	Path         string      `json:"path"`
	Matches      []CodeMatch `json:"matches"`
	TotalFiles   int         `json:"total_files"`
	TotalMatches int         `json:"total_matches"`
	RipgrepUsed  bool        `json:"ripgrep_used"`
	SearchTimeMs int64       `json:"search_time_ms"`
}

SearchCodeResult represents the result of a code search

type SearchFilesResult

type SearchFilesResult struct {
	Pattern string             `json:"pattern"`
	Path    string             `json:"path"`
	Matches []FileSearchResult `json:"matches"`
	Total   int                `json:"total"`
}

SearchFilesResult represents the result of a file search

type SearchReplaceResult

type SearchReplaceResult struct {
	Path          string       `json:"path"`
	FilesModified int          `json:"files_modified"`
	TotalChanges  int          `json:"total_changes"`
	Results       []EditResult `json:"results"`
}

SearchReplaceResult represents results from search and replace

type Server

type Server struct {
	// contains filtered or unexported fields
}

Server wraps the MCP server with filesystem-specific configuration

func NewServer

func NewServer(allowedDirs []string) (*Server, error)

NewServer creates a new filesystem MCP server with the given allowed directories

func (*Server) AllowedDirs

func (s *Server) AllowedDirs() []string

AllowedDirs returns the configured allowed directories

func (*Server) ExecuteHandler

func (s *Server) ExecuteHandler(toolName string, args map[string]interface{}) (string, error)

ExecuteHandler routes tool calls to their implementations

func (*Server) Name

func (s *Server) Name() string

Name returns the server name

func (*Server) Run

func (s *Server) Run(ctx context.Context) error

Run starts the MCP server on stdio with graceful shutdown

func (*Server) ToolCount

func (s *Server) ToolCount() int

ToolCount returns the number of registered tools

func (*Server) Version

func (s *Server) Version() string

Version returns the server version

type SyncResult

type SyncResult struct {
	Source      string `json:"source"`
	Destination string `json:"destination"`
	FilesCopied int    `json:"files_copied"`
	DirsCreated int    `json:"dirs_created"`
	Success     bool   `json:"success"`
}

SyncResult represents sync result

type ToolDefinition

type ToolDefinition struct {
	Name        string
	Description string
	InputSchema json.RawMessage
}

ToolDefinition represents an MCP tool with its schema

func GetToolDefinitions

func GetToolDefinitions() []ToolDefinition

GetToolDefinitions returns all 27 tool definitions (25 v3.4.0 + 2 v3.5.1)

type TreeNode

type TreeNode struct {
	Name     string      `json:"name"`
	Path     string      `json:"path"`
	IsDir    bool        `json:"is_dir"`
	Size     int64       `json:"size,omitempty"`
	Children []*TreeNode `json:"children,omitempty"`
}

TreeNode represents a node in the directory tree

type WriteFileResult

type WriteFileResult struct {
	Path    string `json:"path"`
	Size    int64  `json:"size"`
	Created bool   `json:"created"`
	Backup  string `json:"backup,omitempty"`
	Message string `json:"message"`
}

WriteFileResult represents the result of a write operation

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL